pacman/package.c: show checksums with -Sii
[pacman-ng.git] / contrib / pacdiff.in
blobbfafda2643c84d6a6a226b2a7d0e22e819d85d23
1 #!/bin/bash
2 # pacdiff : a simple pacnew/pacorig/pacsave updater
4 # Copyright (c) 2007 Aaron Griffin <aaronmgriffin@gmail.com>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 declare -r myname='pacdiff'
21 declare -r myver='@PACKAGE_VERSION@'
23 diffprog=${DIFFPROG:-vimdiff}
24 diffsearchpath=${DIFFSEARCHPATH:-/etc}
25 locate=0
27 usage() {
28 echo "$myname : a simple pacnew/pacorig/pacsave updater"
29 echo "Usage : $myname [-l]"
30 echo " -l/--locate makes $myname use locate rather than find"
31 echo " DIFFPROG variable allows to override the default vimdiff"
32 echo " DIFFSEARCHPATH allows to override the default /etc path"
33 echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname"
36 version() {
37 printf "%s %s\n" "$myname" "$myver"
38 echo 'Copyright (C) 2007 Aaron Griffin <aaronmgriffin@gmail.com>'
41 cmd() {
42 if [ $locate -eq 1 ]; then
43 locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave
44 else
45 find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0
49 if [ $# -gt 0 ]; then
50 case $1 in
51 -l|--locate)
52 locate=1;;
53 -V|--version)
54 version; exit 0;;
55 -h|--help)
56 usage; exit 0;;
58 usage; exit 1;;
59 esac
62 # see http://mywiki.wooledge.org/BashFAQ/020
63 while IFS= read -u 3 -r -d '' pacfile; do
64 file="${pacfile%.pac*}"
65 echo "File: $file"
66 if [ ! -f "$file" ]; then
67 echo " $file does not exist"
68 rm -i "$pacfile"
69 continue
71 check="$(cmp "$pacfile" "$file")"
72 if [ -z "${check}" ]; then
73 echo " Files are identical, removing..."
74 rm "$pacfile"
75 else
76 echo -n " File differences found. (V)iew, (S)kip, (R)emove: [v/s/r] "
77 while read c; do
78 case $c in
79 r|R) rm "$pacfile"; break ;;
80 v|V)
81 $diffprog "$pacfile" "$file"
82 rm -i "$pacfile"; break ;;
83 s|S) break ;;
84 *) echo -n " Invalid answer. Try again: [v/s/r] "; continue ;;
85 esac
86 done
88 done 3< <(cmd)
90 exit 0
92 # vim: set ts=2 sw=2 noet: