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