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