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/>.
25 # gettext initialization
26 export TEXTDOMAIN
='pacman-scripts'
27 export TEXTDOMAINDIR
='@localedir@'
29 myver
='@PACKAGE_VERSION@'
33 # minimal of package before deltas are generated (bytes)
34 min_pkg_size
=$
((1024*1024))
36 # percent of new package above which the delta will be discarded
40 # ensure we have a sane umask set
43 m4_include
(library
/output_format.sh
)
45 # print usage instructions
47 printf "pkgdelta (pacman) %s\n\n" "$myver"
48 printf -- "$(gettext "Usage
: pkgdelta
[options
] <package1
> <package2
>\n")"
49 printf -- "$(gettext "\
50 pkgdelta will create a delta
file between two packages.
\n\
51 This delta
file can
then be added to a database using repo-add.
\n\n")"
52 printf -- "$(gettext "Example
: pkgdelta pacman-3.0
.0.pkg.
tar.gz pacman-3.0
.1.pkg.
tar.gz
")\n"
54 printf -- "$(gettext "Options
:\n")"
55 printf -- " -q ""$(gettext "quiet
\n")"
56 printf -- " --min-pkg-size ""$(gettext "minimal of package before deltas are generated
(bytes
)\n")"
57 printf -- " --max-delta-size ""$(gettext "percent of new package above
which the delta will be discarded
\n")"
61 printf "pkgdelta (pacman) %s\n\n" "$myver"
62 printf -- "$(gettext "\
63 Copyright
(c
) 2009 Xavier Chantry
<shiningxc@gmail.com
>.
\n\n\
64 This is free software
; see the
source for copying conditions.
\n\
65 There is NO WARRANTY
, to the extent permitted by law.
\n")"
74 pkgname
= pkgver
= arch
=
76 # IFS (field separator) is only the newline character
80 for line
in $
(bsdtar
-xOqf "$1" .PKGINFO
2>/dev
/null |
81 grep -v "^#" |
sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
83 if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then
89 error
"$(gettext "Invalid package
file '%s'.
")" "$1"
93 # $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
99 oldname oldver oldarch \
100 newname newver newarch \
103 read_pkginfo
"$oldfile" ||
return 1
107 read_pkginfo
"$newfile" ||
return 1
112 pkgsize
="$(@SIZECMD@ -L "$newfile")"
114 if ((pkgsize
< min_pkg_size
)); then
115 msg
"$(gettext "Skipping delta creation
for small package
: %s
- size
%s
")" "$newname" "$pkgsize"
119 if [[ $oldname != "$newname" ]]; then
120 error
"$(gettext "The package names don
't match : '%s
' and '%s
'")" "$oldname" "$newname"
124 if [[ $oldarch != "$newarch" ]]; then
125 error "$(gettext "The package architectures don't match
: '%s' and
'%s'")" "$oldarch" "$newarch"
129 if [[ $oldver == "$newver" ]]; then
130 error
"$(gettext "Both packages have the same version
: '%s'")" "$newver"
134 msg
"$(gettext "Generating delta from version
%s to version
%s
")" "$oldver" "$newver"
135 deltafile
="$(dirname $newfile)/$pkgname-${oldver}_to_${newver}-$arch.delta"
138 xdelta3
-q -f -s "$oldfile" "$newfile" "$deltafile" || ret
=$?
140 error
"$(gettext "Delta could not be created.
")"
144 deltasize
="$(@SIZECMD@ -L "$deltafile")"
146 if ((max_delta_size
* pkgsize
/ 100 < deltasize
)); then
147 msg
"$(gettext "Delta package larger than maximum size. Removing.
")"
152 msg
"$(gettext "Generated delta
: '%s'")" "$deltafile"
153 (( QUIET
)) && echo "$deltafile"
163 -h|
--help) usage
; exit 0 ;;
164 -V|
--version) version
; exit 0 ;;
165 -q|
--quiet) QUIET
=1;;
167 if ! isnumeric
"$2"; then
168 echo "invalid argument '$2' for option -- '$1'"
175 arg
=$
(echo "$2" |
awk '{print $1 * 100}')
176 if ! isnumeric
"$arg" ||
(($arg > 200)); then
177 echo "invalid argument '$2' for option -- '$1'"
183 --) shift; args
+=("$@"); break 2 ;;
184 -*) echo "invalid option -- '$1'"; usage
; exit 1 ;;
190 if (( ${#args[@]} != 2 )); then
195 for i
in "${args[@]}"; do
196 if [[ ! -f $i ]]; then
197 error
"$(gettext "File
'%s' does not exist
")" "$i"
202 if ! type xdelta3
&>/dev
/null
; then
203 error
"$(gettext "Cannot
find the xdelta3 binary
! Is xdelta3 installed?
")"
207 create_xdelta
"${args[@]}"
209 # vim: set ts=2 sw=2 noet: