[pacman-dev] [PATCH 4/5] Add create-xdelta script to create deltas.
Xavier Chantry
shiningxc at gmail.com
Wed Feb 25 13:43:50 EST 2009
This should obsolete the delta support in makepkg. Having a separate script
should be more flexible.
Example usage:
$ create-xdelta repo/tzdata-2009a-1-x86_64.pkg.tar.gz repo/tzdata-2009b-1-x86_64.pkg.tar.gz
==> Generating delta from version 2009a-1 to version 2009b-1
==> Generated delta : 'repo/tzdata-2009a-1_to_2009b-1-x86_64.delta'
Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
---
scripts/.gitignore | 1 +
scripts/Makefile.am | 7 ++-
scripts/create-xdelta.sh.in | 143 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+), 2 deletions(-)
create mode 100644 scripts/create-xdelta.sh.in
diff --git a/scripts/.gitignore b/scripts/.gitignore
index f2f19fd..43ad30f 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -3,3 +3,4 @@ pacman-optimize
rankmirrors
repo-add
repo-remove
+create-xdelta
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index d6d9bb9..3ccf478 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -9,13 +9,15 @@ OURSCRIPTS = \
makepkg \
pacman-optimize \
rankmirrors \
- repo-add
+ repo-add \
+ create-xdelta
EXTRA_DIST = \
makepkg.sh.in \
pacman-optimize.sh.in \
rankmirrors.py.in \
- repo-add.sh.in
+ repo-add.sh.in \
+ create-xdelta.sh.in
# Files that should be removed, but which Automake does not know.
MOSTLYCLEANFILES = $(bin_SCRIPTS) *.tmp
@@ -63,5 +65,6 @@ repo-add: $(srcdir)/repo-add.sh.in
repo-remove: $(srcdir)/repo-add.sh.in
rm -f repo-remove
$(LN_S) repo-add repo-remove
+create-xdelta: $(srcdir)/create-xdelta.sh.in
# vim:set ts=2 sw=2 noet:
diff --git a/scripts/create-xdelta.sh.in b/scripts/create-xdelta.sh.in
new file mode 100644
index 0000000..58ad11f
--- /dev/null
+++ b/scripts/create-xdelta.sh.in
@@ -0,0 +1,143 @@
+#!/bin/bash -e
+#
+# create-xdelta - create delta files for use with pacman and repo-add
+# @configure_input@
+#
+# Copyright (c) 2009 Xavier Chantry <shiningxc at 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/>.
+#
+
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+myver='@PACKAGE_VERSION@'
+
+# ensure we have a sane umask set
+umask 0022
+
+msg() {
+ local mesg=$1; shift
+ printf "==> ${mesg}\n" "$@" >&1
+}
+
+warning() {
+ local mesg=$1; shift
+ printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
+}
+
+error() {
+ local mesg=$1; shift
+ printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
+}
+
+# print usage instructions
+usage() {
+ printf "create-xdelta (pacman) %s\n\n" "$myver"
+ printf "$(gettext "Usage: create-xdelta <package1> <package2 ...\n")"
+ printf "$(gettext "\
+ create-xdelta will create a delta file between two packages\n\
+This delta file can then be added to a database using repo-add.\n\n")"
+ echo "$(gettext "Example: create-xdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")"
+}
+
+version() {
+ printf "create-xdelta (pacman) %s\n\n" "$myver"
+ printf "$(gettext "\
+Copyright (c) 2009 Xavier Chantry <shiningxc at 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")"
+}
+
+read_pkginfo()
+{
+ unset pkgname pkgver arch
+ local OLDIFS="$IFS"
+ # IFS (field separator) is only the newline character
+ IFS="
+"
+ local line var val
+ for line in $(bsdtar -xOf "$1" .PKGINFO 2>/dev/null |
+ grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
+ eval "$line"
+ done
+ IFS=$OLDIFS
+ if [ -z "$pkgname" ]; then
+ error "$(gettext "Invalid package '%s'")" "$1"
+ return 1
+ fi
+ return 0
+}
+
+# $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"
+
+ 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 -ne 0 ]; then
+ error "$(gettext "Delta could not be created.")"
+ return 1
+ else
+ msg "$(gettext "Generated delta : '%s'")" "$deltafile"
+ fi
+ return 0
+}
+
+if [ $# -ne 2 ]; then
+ usage
+ exit 0
+fi
+
+
+if [ ! "$(type -p xdelta3)" ]; then
+ error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
+ exit 1
+fi
+
+create_xdelta $1 $2
--
1.6.1.3
More information about the pacman-dev
mailing list