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