mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-05 17:15:02 -05:00
9f6a67fee7
Conflicts: scripts/pacman-key.sh.in
220 lines
5.4 KiB
Bash
220 lines
5.4 KiB
Bash
#!/bin/bash
|
|
#
|
|
# pkgdelta - create delta files for use with pacman and repo-add
|
|
# @configure_input@
|
|
#
|
|
# Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
# bash options
|
|
set -o errexit
|
|
|
|
# gettext initialization
|
|
export TEXTDOMAIN='pacman-scripts'
|
|
export TEXTDOMAINDIR='@localedir@'
|
|
|
|
declare -r myver='@PACKAGE_VERSION@'
|
|
|
|
QUIET=0
|
|
|
|
# minimal of package before deltas are generated (bytes)
|
|
min_pkg_size=$((1024*1024))
|
|
|
|
# percent of new package above which the delta will be discarded
|
|
max_delta_size=70
|
|
|
|
|
|
# ensure we have a sane umask set
|
|
umask 0022
|
|
|
|
m4_include(library/parseopts.sh)
|
|
m4_include(library/output_format.sh)
|
|
|
|
# print usage instructions
|
|
usage() {
|
|
printf "pkgdelta (pacman) %s\n\n" "$myver"
|
|
printf -- "$(gettext "Usage: pkgdelta [options] <package1> <package2>\n")"
|
|
printf -- "$(gettext "\
|
|
pkgdelta will create a delta file between two packages.\n\
|
|
This delta file can then be added to a database using repo-add.\n\n")"
|
|
printf -- "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")\n"
|
|
echo
|
|
printf -- "$(gettext "Options:\n")"
|
|
printf -- "$(gettext " -q, --quiet minimize output\n")"
|
|
printf -- "$(gettext " --min-pkg-size minimum package size before deltas are generated (bytes)\n")"
|
|
printf -- "$(gettext " --max-delta-size percent of package size above which deltas will be discarded\n")"
|
|
}
|
|
|
|
version() {
|
|
printf "pkgdelta (pacman) %s\n\n" "$myver"
|
|
printf -- "$(gettext "\
|
|
Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>.\n\n\
|
|
This is free software; see the source for copying conditions.\n\
|
|
There is NO WARRANTY, to the extent permitted by law.\n")"
|
|
}
|
|
|
|
isnumeric() {
|
|
[[ $1 != *[!0-9]* ]]
|
|
}
|
|
|
|
read_pkginfo()
|
|
{
|
|
pkgname= pkgver= arch=
|
|
local OLDIFS=$IFS
|
|
# IFS (field separator) is only the newline character
|
|
IFS="
|
|
"
|
|
local line var val
|
|
for line in $(bsdtar -xOqf "$1" .PKGINFO 2>/dev/null |
|
|
grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
|
|
eval "$line"
|
|
if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then
|
|
IFS=$OLDIFS
|
|
return 0
|
|
fi
|
|
done
|
|
IFS=$OLDIFS
|
|
error "$(gettext "Invalid package file '%s'.")" "$1"
|
|
return 1
|
|
}
|
|
|
|
# $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
|
|
create_xdelta()
|
|
{
|
|
local oldfile=$1
|
|
local newfile=$2
|
|
local \
|
|
oldname oldver oldarch \
|
|
newname newver newarch \
|
|
deltafile
|
|
|
|
read_pkginfo "$oldfile" || return 1
|
|
oldname="$pkgname"
|
|
oldver="$pkgver"
|
|
oldarch="$arch"
|
|
read_pkginfo "$newfile" || return 1
|
|
newname="$pkgname"
|
|
newver="$pkgver"
|
|
newarch="$arch"
|
|
|
|
pkgsize="$(@SIZECMD@ -L "$newfile")"
|
|
|
|
if ((pkgsize < min_pkg_size)); then
|
|
msg "$(gettext "Skipping delta creation for small package: %s - size %s")" "$newname" "$pkgsize"
|
|
return 0
|
|
fi
|
|
|
|
if [[ $oldname != "$newname" ]]; then
|
|
error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname"
|
|
return 1
|
|
fi
|
|
|
|
if [[ $oldarch != "$newarch" ]]; then
|
|
error "$(gettext "The package architectures don't match : '%s' and '%s'")" "$oldarch" "$newarch"
|
|
return 1
|
|
fi
|
|
|
|
if [[ $oldver == "$newver" ]]; then
|
|
error "$(gettext "Both packages have the same version : '%s'")" "$newver"
|
|
return 1
|
|
fi
|
|
|
|
msg "$(gettext "Generating delta from version %s to version %s")" "$oldver" "$newver"
|
|
deltafile=$(dirname "$newfile")/$pkgname-${oldver}_to_${newver}-$arch.delta
|
|
local ret=0
|
|
|
|
xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$?
|
|
if (( ret )); then
|
|
error "$(gettext "Delta could not be created.")"
|
|
return 1
|
|
fi
|
|
|
|
deltasize="$(@SIZECMD@ -L "$deltafile")"
|
|
|
|
if ((max_delta_size * pkgsize / 100 < deltasize)); then
|
|
msg "$(gettext "Delta package larger than maximum size. Removing.")"
|
|
rm -f "$deltafile"
|
|
return 0
|
|
fi
|
|
|
|
msg "$(gettext "Generated delta : '%s'")" "$deltafile"
|
|
(( QUIET )) && echo "$deltafile"
|
|
|
|
return 0
|
|
}
|
|
|
|
OPT_SHORT='hqV'
|
|
OPT_LONG=('help' 'quiet' 'max-delta-size:' 'min-pkg-size:')
|
|
if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
|
|
exit 1
|
|
fi
|
|
set -- "${OPTRET[@]}"
|
|
unset OPT_SHORT OPT_LONG OPTRET
|
|
|
|
# parse arguments
|
|
while :; do
|
|
case $1 in
|
|
-h|--help)
|
|
usage
|
|
exit 0 ;;
|
|
-V|--version)
|
|
version
|
|
exit 0 ;;
|
|
-q|--quiet)
|
|
QUIET=1;;
|
|
--min-pkg-size)
|
|
if ! isnumeric "$2"; then
|
|
echo "invalid argument '$2' for option -- '$1'"
|
|
exit 1
|
|
fi
|
|
min_pkg_size=$2
|
|
shift ;;
|
|
--max-delta-size)
|
|
arg=$(echo "$2" | awk '{print $1 * 100}')
|
|
if ! isnumeric "$arg" || (($arg > 200)); then
|
|
echo "invalid argument '$2' for option -- '$1'"
|
|
exit 1
|
|
fi
|
|
max_delta_size=$arg
|
|
shift ;;
|
|
--)
|
|
shift
|
|
break 2 ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if (( $# != 2 )); then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
for i in "$@"; do
|
|
if [[ ! -f $i ]]; then
|
|
error "$(gettext "File '%s' does not exist")" "$i"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
if ! type xdelta3 &>/dev/null; then
|
|
error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
|
|
exit 1
|
|
fi
|
|
|
|
create_xdelta "${args[@]}"
|
|
|
|
# vim: set ts=2 sw=2 noet:
|