3 # pkgdelta - create delta files for use with pacman and repo-add
6 # Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 # gettext initialization
27 export TEXTDOMAIN
='pacman'
28 export TEXTDOMAINDIR
='@localedir@'
30 myver
='@PACKAGE_VERSION@'
34 # ensure we have a sane umask set
40 printf "==> ${mesg}\n" "$@" >&1
45 printf "==> $(gettext "WARNING
:") ${mesg}\n" "$@" >&2
50 printf "==> $(gettext "ERROR
:") ${mesg}\n" "$@" >&2
53 # print usage instructions
55 printf "pkgdelta (pacman) %s\n\n" "$myver"
56 printf "$(gettext "Usage
: pkgdelta
[-q] <package1
> <package2
>\n")"
58 pkgdelta will create a delta
file between two packages.
\n\
59 This delta
file can
then be added to a database using repo-add.
\n\n")"
60 echo "$(gettext "Example
: pkgdelta pacman-3.0
.0.pkg.
tar.gz pacman-3.0
.1.pkg.
tar.gz
")"
64 printf "pkgdelta (pacman) %s\n\n" "$myver"
66 Copyright
(c
) 2009 Xavier Chantry
<shiningxc@gmail.com
>.
\n\n\
67 This is free software
; see the
source for copying conditions.
\n\
68 There is NO WARRANTY
, to the extent permitted by law.
\n")"
73 pkgname
= pkgver
= arch
=
75 # IFS (field separator) is only the newline character
79 for line
in $
(bsdtar
-xOf "$1" .PKGINFO
2>/dev
/null |
80 grep -v "^#" |
sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
82 if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then
88 error
"$(gettext "Invalid package
file '%s'.
")" "$1"
92 # $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
98 oldname oldver oldarch \
99 newname newver newarch \
102 read_pkginfo
"$oldfile" ||
return 1
106 read_pkginfo
"$newfile" ||
return 1
111 if [[ $oldname != $newname ]]; then
112 error
"$(gettext "The package names don
't match : '%s
' and '%s
'")" "$oldname" "$newname"
116 if [[ $oldarch != $newarch ]]; then
117 error "$(gettext "The package architectures don't match
: '%s' and
'%s'")" "$oldarch" "$newarch"
121 if [[ $oldver == $newver ]]; then
122 error
"$(gettext "Both packages have the same version
: '%s'")" "$newver"
126 msg
"$(gettext "Generating delta from version
%s to version
%s
")" "$oldver" "$newver"
127 deltafile
="$(dirname $newfile)/$pkgname-${oldver}_to_${newver}-$arch.delta"
130 xdelta3
-q -f -s "$oldfile" "$newfile" "$deltafile" || ret
=$?
132 error
"$(gettext "Delta could not be created.
")"
135 msg
"$(gettext "Generated delta
: '%s'")" "$deltafile"
136 (( QUIET
)) && echo "$deltafile"
142 -q|
--quiet) QUIET
=1; shift ;;
145 if (( $# != 2 )); then
150 if [[ ! -f $1 ]]; then
151 error
"$(gettext "File
'%s' does not exist
")" "$1"
155 if [[ ! -f $2 ]]; then
156 error
"$(gettext "File
'%s' does not exist
")" "$2"
160 if ! type xdelta3
&>/dev
/null
; then
161 error
"$(gettext "Cannot
find the xdelta3 binary
! Is xdelta3 installed?
")"
165 create_xdelta
"$1" "$2"