pacman-key: rename --del to --delete
[pacman-ng.git] / scripts / pkgdelta.sh.in
blob46c6f4ff424762409e09d7d824cef382afbe020e
1 #!/bin/bash
3 # pkgdelta - create delta files for use with pacman and repo-add
4 # @configure_input@
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/>.
22 # bash options
23 set -o nounset
24 set -o errexit
26 # gettext initialization
27 export TEXTDOMAIN='pacman-scripts'
28 export TEXTDOMAINDIR='@localedir@'
30 myver='@PACKAGE_VERSION@'
32 QUIET=0
34 # ensure we have a sane umask set
35 umask 0022
37 m4_include(library/output_format.sh)
39 # print usage instructions
40 usage() {
41 printf "pkgdelta (pacman) %s\n\n" "$myver"
42 printf "$(gettext "Usage: pkgdelta [-q] <package1> <package2>\n")"
43 printf "$(gettext "\
44 pkgdelta will create a delta file between two packages.\n\
45 This delta file can then be added to a database using repo-add.\n\n")"
46 echo "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")"
49 version() {
50 printf "pkgdelta (pacman) %s\n\n" "$myver"
51 printf "$(gettext "\
52 Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>.\n\n\
53 This is free software; see the source for copying conditions.\n\
54 There is NO WARRANTY, to the extent permitted by law.\n")"
57 read_pkginfo()
59 pkgname= pkgver= arch=
60 local OLDIFS=$IFS
61 # IFS (field separator) is only the newline character
62 IFS="
64 local line var val
65 for line in $(bsdtar -xOf "$1" .PKGINFO 2>/dev/null |
66 grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
67 eval "$line"
68 if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then
69 IFS=$OLDIFS
70 return 0
72 done
73 IFS=$OLDIFS
74 error "$(gettext "Invalid package file '%s'.")" "$1"
75 return 1
78 # $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
79 create_xdelta()
81 local oldfile=$1
82 local newfile=$2
83 local \
84 oldname oldver oldarch \
85 newname newver newarch \
86 deltafile
88 read_pkginfo "$oldfile" || return 1
89 oldname="$pkgname"
90 oldver="$pkgver"
91 oldarch="$arch"
92 read_pkginfo "$newfile" || return 1
93 newname="$pkgname"
94 newver="$pkgver"
95 newarch="$arch"
97 if [[ $oldname != $newname ]]; then
98 error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname"
99 return 1
102 if [[ $oldarch != $newarch ]]; then
103 error "$(gettext "The package architectures don't match : '%s' and '%s'")" "$oldarch" "$newarch"
104 return 1
107 if [[ $oldver == $newver ]]; then
108 error "$(gettext "Both packages have the same version : '%s'")" "$newver"
109 return 1
112 msg "$(gettext "Generating delta from version %s to version %s")" "$oldver" "$newver"
113 deltafile="$(dirname $newfile)/$pkgname-${oldver}_to_${newver}-$arch.delta"
114 local ret=0
116 xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$?
117 if (( ret )); then
118 error "$(gettext "Delta could not be created.")"
119 return 1
120 else
121 msg "$(gettext "Generated delta : '%s'")" "$deltafile"
122 (( QUIET )) && echo "$deltafile"
124 return 0
127 case "$1" in
128 -q|--quiet) QUIET=1; shift ;;
129 esac
131 if (( $# != 2 )); then
132 usage
133 exit 0
136 if [[ ! -f $1 ]]; then
137 error "$(gettext "File '%s' does not exist")" "$1"
138 exit 0
141 if [[ ! -f $2 ]]; then
142 error "$(gettext "File '%s' does not exist")" "$2"
143 exit 0
146 if ! type xdelta3 &>/dev/null; then
147 error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
148 exit 1
151 create_xdelta "$1" "$2"
153 # vim: set ts=2 sw=2 noet: