otaylor / rpms / SDL

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