]> wolfpit.net Git - tool/Arch-pacman/.git/blob - contrib/pacdiff.sh.in
pacdiff: Add quit to found pacnew options
[tool/Arch-pacman/.git] / contrib / pacdiff.sh.in
1 #!/bin/bash
2 # pacdiff : a simple pacnew/pacorig/pacsave updater
3 #
4 # Copyright (c) 2007 Aaron Griffin <aaronmgriffin@gmail.com>
5 # Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 declare -r myname='pacdiff'
22 declare -r myver='@PACKAGE_VERSION@'
23
24 diffprog=${DIFFPROG:-vimdiff}
25 diffsearchpath=${DIFFSEARCHPATH:-/etc}
26 locate=0
27 USE_COLOR='y'
28
29 m4_include(../scripts/library/output_format.sh)
30
31 m4_include(../scripts/library/term_colors.sh)
32
33 usage() {
34 echo "$myname : a simple pacnew/pacorig/pacsave updater"
35 echo "Usage : $myname [-l]"
36 echo " -l/--locate makes $myname use locate rather than find"
37 echo " DIFFPROG variable allows to override the default vimdiff"
38 echo " DIFFSEARCHPATH allows to override the default /etc path"
39 echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname"
40 }
41
42 version() {
43 printf "%s %s\n" "$myname" "$myver"
44 echo 'Copyright (C) 2007 Aaron Griffin <aaronmgriffin@gmail.com>'
45 echo 'Copyright (C) 2013 Pacman Development Team <pacman-dev@archlinux.org>'
46 }
47
48 cmd() {
49 if [ $locate -eq 1 ]; then
50 locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave
51 else
52 find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0
53 fi
54 }
55
56 if [ $# -gt 0 ]; then
57 case $1 in
58 -l|--locate)
59 locate=1;;
60 -V|--version)
61 version; exit 0;;
62 -h|--help)
63 usage; exit 0;;
64 *)
65 usage; exit 1;;
66 esac
67 fi
68
69 # see http://mywiki.wooledge.org/BashFAQ/020
70 while IFS= read -u 3 -r -d '' pacfile; do
71 file="${pacfile%.pac*}"
72 file_type="pac${pacfile##*.pac}"
73
74 msg "%s file found for %s" "$file_type" "$file"
75 if [ ! -f "$file" ]; then
76 warning "$file does not exist"
77 rm -iv "$pacfile"
78 continue
79 fi
80
81 if cmp -s "$pacfile" "$file"; then
82 msg2 "Files are identical, removing..."
83 rm -v "$pacfile"
84 else
85 ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type"
86 while read c; do
87 case $c in
88 q|Q) exit 0;;
89 r|R) rm -v "$pacfile"; break ;;
90 o|O) mv -v "$pacfile" "$file"; break ;;
91 v|V)
92 $diffprog "$pacfile" "$file"
93 rm -iv "$pacfile"; break ;;
94 s|S) break ;;
95 *) ask "Invalid answer. Try again: [v/s/r/o/q] "; continue ;;
96 esac
97 done
98 fi
99 done 3< <(cmd)
100
101 exit 0
102
103 # vim: set ts=2 sw=2 noet: