0a8bd8
#!/bin/bash
0a8bd8
#
0a8bd8
# Copyright (C) 2010 Red Hat, Inc.
0a8bd8
# Authors:
0a8bd8
# Thomas Woerner <twoerner@redhat.com>
0a8bd8
#
0a8bd8
# This program is free software; you can redistribute it and/or modify
0a8bd8
# it under the terms of the GNU General Public License as published by
0a8bd8
# the Free Software Foundation; either version 2 of the License, or
0a8bd8
# (at your option) any later version.
0a8bd8
#
0a8bd8
# This program is distributed in the hope that it will be useful,
0a8bd8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
0a8bd8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a8bd8
# GNU General Public License for more details.
0a8bd8
#
0a8bd8
# You should have received a copy of the GNU General Public License
0a8bd8
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
0a8bd8
#
0a8bd8
0a8bd8
version=$1
0a8bd8
[ -z "$version" ] && { echo "Usage: $0 <version>"; exit 1; }
0a8bd8
0a8bd8
# files to be removed without the main SDL-<version>/ prefix
0a8bd8
declare -a REMOVE
0a8bd8
REMOVE[${#REMOVE[*]}]="symbian.zip"
0a8bd8
0a8bd8
# no changes below this line should be needed
0a8bd8
0a8bd8
orig="SDL-${version}"
0a8bd8
orig_tgz="${orig}.tar.gz"
0a8bd8
repackaged="${orig}_repackaged"
0a8bd8
repackaged_tar="${repackaged}.tar"
0a8bd8
repackaged_tgz="${repackaged_tar}.gz"
0a8bd8
0a8bd8
# pre checks
0a8bd8
[ ! -f "${orig_tgz}" ] && { echo "ERROR: ${orig_tgz} does not exist"; exit 1; }
0a8bd8
[ -f "${repackaged_tgz}" ] && { echo "ERROR: ${repackaged_tgz} already exist"; exit 1; }
0a8bd8
0a8bd8
# repackage
0a8bd8
failure=0
0a8bd8
gzip -dc "${orig_tgz}" > "${repackaged_tar}"
0a8bd8
for file in "${REMOVE[@]}"; do
0a8bd8
    tar -f "${repackaged_tar}" --delete "${orig}/${file}" >> repackage.log
0a8bd8
    [ $? != 0 ] && { echo "ERROR: Could not remove file ${orig}/${file} from archive."; failure=1; } || echo "Removed ${orig}/${file} from archive."
0a8bd8
done
0a8bd8
[ $failure != 0 ] && { echo "See repackage.log for details."; exit 1; }
0a8bd8
gzip -9 -n "${repackaged_tar}"
0a8bd8
0a8bd8
# post checks
0a8bd8
RET=0
0a8bd8
for file in "${REMOVE[@]}"; do
0a8bd8
    found=$(tar -ztvf "${repackaged_tgz}" | grep "${file}")
0a8bd8
    [ -n "$found" ] && { echo "ERROR: file ${file} is still in the repackaged archive."; RET=1; }
0a8bd8
done
0a8bd8
0a8bd8
[ $RET == 0 ] && echo "Sucessfully repackaged ${orig}: ${repackaged_tgz}"
0a8bd8
0a8bd8
exit $RET