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 declare -r 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
/parseopts.sh
)
44 m4_include
(library
/output_format.sh
)
46 # print usage instructions
48 printf "pkgdelta (pacman) %s\n\n" "$myver"
49 printf -- "$(gettext "Usage
: pkgdelta
[options
] <package1
> <package2
>\n")"
50 printf -- "$(gettext "\
51 pkgdelta will create a delta
file between two packages.
\n\
52 This delta
file can
then be added to a database using repo-add.
\n\n")"
53 printf -- "$(gettext "Example
: pkgdelta pacman-3.0
.0.pkg.
tar.gz pacman-3.0
.1.pkg.
tar.gz
")\n"
55 printf -- "$(gettext "Options
:\n")"
56 printf -- "$(gettext " -q, --quiet minimize output
\n")"
57 printf -- "$(gettext " --min-pkg-size minimum package size before deltas are generated
\n")"
58 printf -- "$(gettext " --max-delta-size percent of new package above
which the delta will be discarded
\n")"
62 printf "pkgdelta (pacman) %s\n\n" "$myver"
63 printf -- "$(gettext "\
64 Copyright
(c
) 2009 Xavier Chantry
<shiningxc@gmail.com
>.
\n\n\
65 This is free software
; see the
source for copying conditions.
\n\
66 There is NO WARRANTY
, to the extent permitted by law.
\n")"
69 m4_include
(library
/human_to_size.sh
)
77 pkgname
= pkgver
= arch
=
79 # IFS (field separator) is only the newline character
83 for line
in $
(bsdtar
-xOqf "$1" .PKGINFO
2>/dev
/null |
84 grep -v "^#" |
sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
86 if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then
92 error
"$(gettext "Invalid package
file '%s'.
")" "$1"
96 # $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
102 oldname oldver oldarch \
103 newname newver newarch \
106 read_pkginfo
"$oldfile" ||
return 1
110 read_pkginfo
"$newfile" ||
return 1
115 pkgsize
="$(@SIZECMD@ -L "$newfile")"
117 if ((pkgsize
< min_pkg_size
)); then
118 msg
"$(gettext "Skipping delta creation
for small package
: %s
- size
%s
")" "$newname" "$pkgsize"
122 if [[ $oldname != "$newname" ]]; then
123 error
"$(gettext "The package names don
't match : '%s
' and '%s
'")" "$oldname" "$newname"
127 if [[ $oldarch != "$newarch" ]]; then
128 error "$(gettext "The package architectures don't match
: '%s' and
'%s'")" "$oldarch" "$newarch"
132 if [[ $oldver == "$newver" ]]; then
133 error
"$(gettext "Both packages have the same version
: '%s'")" "$newver"
137 msg
"$(gettext "Generating delta from version
%s to version
%s
")" "$oldver" "$newver"
138 deltafile
=$
(dirname "$newfile")/$pkgname-${oldver}_to_
${newver}-$arch.delta
141 xdelta3
-q -f -s "$oldfile" "$newfile" "$deltafile" || ret
=$?
143 error
"$(gettext "Delta could not be created.
")"
147 deltasize
="$(@SIZECMD@ -L "$deltafile")"
149 if ((max_delta_size
* pkgsize
/ 100 < deltasize
)); then
150 msg
"$(gettext "Delta package larger than maximum size. Removing.
")"
155 msg
"$(gettext "Generated delta
: '%s'")" "$deltafile"
156 (( QUIET
)) && echo "$deltafile"
162 OPT_LONG
=('help' 'quiet' 'max-delta-size:' 'min-pkg-size:' 'version')
163 if ! parseopts
"$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
166 set -- "${OPTRET[@]}"
167 unset OPT_SHORT OPT_LONG OPTRET
181 if ! min_pkg_size
=$
(human_to_size
"$2"); then
182 echo "invalid argument '$2' for option -- '$1'"
187 arg
=$
(awk -v val
="$2" 'BEGIN { print val * 100 }')
188 if ! isnumeric
"$arg" ||
(( arg
> 200 )); then
189 echo "invalid argument '$2' for option -- '$1'"
201 if (( $# != 2 )); then
207 if [[ ! -f $i ]]; then
208 error
"$(gettext "File
'%s' does not exist
")" "$i"
213 if ! type xdelta3
&>/dev
/null
; then
214 error
"$(gettext "Cannot
find the xdelta3 binary
! Is xdelta3 installed?
")"
218 create_xdelta
"${args[@]}"
220 # vim: set ts=2 sw=2 noet: