pacman: list all unknown targets on removal operation
[pacman-ng.git] / contrib / pacdiff.in
blob79cf809d605d8618d1a719fef5cd28af88062e61
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'
22 diffprog=${DIFFPROG:-vimdiff}
23 diffsearchpath=${DIFFSEARCHPATH:-/etc}
24 locate=0
26 usage() {
27 echo "$myname : a simple pacnew/pacorig/pacsave updater"
28 echo "Usage : $myname [-l]"
29 echo " -l/--locate makes $myname use locate rather than find"
30 echo " DIFFPROG variable allows to override the default vimdiff"
31 echo " DIFFSEARCHPATH allows to override the default /etc path"
32 echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname"
35 cmd() {
36 if [ $locate -eq 1 ]; then
37 locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave
38 else
39 find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0
43 if [ $# -gt 0 ]; then
44 case $1 in
45 -l|--locate)
46 locate=1;;
48 usage; exit 0;;
49 esac
52 # see http://mywiki.wooledge.org/BashFAQ/020
53 while IFS= read -u 3 -r -d '' pacfile; do
54 file="${pacfile%.pac*}"
55 echo "File: $file"
56 if [ ! -f "$file" ]; then
57 echo " $file does not exist"
58 rm -i "$pacfile"
59 continue
61 check="$(cmp "$pacfile" "$file")"
62 if [ -z "${check}" ]; then
63 echo " Files are identical, removing..."
64 rm "$pacfile"
65 else
66 echo -n " File differences found. (V)iew, (S)kip, (R)emove: [v/s/r] "
67 while read c; do
68 case $c in
69 r|R) rm "$pacfile"; break ;;
70 v|V)
71 $diffprog "$pacfile" "$file"
72 rm -i "$pacfile"; break ;;
73 s|S) break ;;
74 *) echo -n " Invalid answer. Try again: [v/s/r] "; continue ;;
75 esac
76 done
78 done 3< <(cmd)
80 exit 0
82 # vim: set ts=2 sw=2 noet: