pacman: list all unknown targets on removal operation
[pacman-ng.git] / scripts / pkgdelta.sh.in
blob22a3cd23bc70500addbb2e44e10738774bd1261e
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 errexit
25 # gettext initialization
26 export TEXTDOMAIN='pacman-scripts'
27 export TEXTDOMAINDIR='@localedir@'
29 declare -r myver='@PACKAGE_VERSION@'
31 QUIET=0
33 # ensure we have a sane umask set
34 umask 0022
36 m4_include(library/output_format.sh)
38 # print usage instructions
39 usage() {
40 printf "pkgdelta (pacman) %s\n\n" "$myver"
41 printf "$(gettext "Usage: pkgdelta [-q] <package1> <package2>\n")"
42 printf "$(gettext "\
43 pkgdelta will create a delta file between two packages.\n\
44 This delta file can then be added to a database using repo-add.\n\n")"
45 echo "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")"
48 version() {
49 printf "pkgdelta (pacman) %s\n\n" "$myver"
50 printf "$(gettext "\
51 Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>.\n\n\
52 This is free software; see the source for copying conditions.\n\
53 There is NO WARRANTY, to the extent permitted by law.\n")"
56 read_pkginfo()
58 pkgname= pkgver= arch=
59 local OLDIFS=$IFS
60 # IFS (field separator) is only the newline character
61 IFS="
63 local line var val
64 for line in $(bsdtar -xOf "$1" .PKGINFO 2>/dev/null |
65 grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do
66 eval "$line"
67 if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then
68 IFS=$OLDIFS
69 return 0
71 done
72 IFS=$OLDIFS
73 error "$(gettext "Invalid package file '%s'.")" "$1"
74 return 1
77 # $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
78 create_xdelta()
80 local oldfile=$1
81 local newfile=$2
82 local \
83 oldname oldver oldarch \
84 newname newver newarch \
85 deltafile
87 read_pkginfo "$oldfile" || return 1
88 oldname="$pkgname"
89 oldver="$pkgver"
90 oldarch="$arch"
91 read_pkginfo "$newfile" || return 1
92 newname="$pkgname"
93 newver="$pkgver"
94 newarch="$arch"
96 if [[ $oldname != "$newname" ]]; then
97 error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname"
98 return 1
101 if [[ $oldarch != "$newarch" ]]; then
102 error "$(gettext "The package architectures don't match : '%s' and '%s'")" "$oldarch" "$newarch"
103 return 1
106 if [[ $oldver == "$newver" ]]; then
107 error "$(gettext "Both packages have the same version : '%s'")" "$newver"
108 return 1
111 msg "$(gettext "Generating delta from version %s to version %s")" "$oldver" "$newver"
112 deltafile="$(dirname $newfile)/$pkgname-${oldver}_to_${newver}-$arch.delta"
113 local ret=0
115 xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$?
116 if (( ret )); then
117 error "$(gettext "Delta could not be created.")"
118 return 1
119 else
120 msg "$(gettext "Generated delta : '%s'")" "$deltafile"
121 (( QUIET )) && echo "$deltafile"
123 return 0
126 case "$1" in
127 -h|--help) usage; exit 0 ;;
128 -V|--version) version; exit 0 ;;
129 -q|--quiet) QUIET=1; shift ;;
130 esac
132 if (( $# != 2 )); then
133 usage
134 exit 1
137 if [[ ! -f $1 ]]; then
138 error "$(gettext "File '%s' does not exist")" "$1"
139 exit 0
142 if [[ ! -f $2 ]]; then
143 error "$(gettext "File '%s' does not exist")" "$2"
144 exit 0
147 if ! type xdelta3 &>/dev/null; then
148 error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
149 exit 1
152 create_xdelta "$1" "$2"
154 # vim: set ts=2 sw=2 noet: