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