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