]>
Commit | Line | Data |
---|---|---|
9efd10cd | 1 | #!/bin/bash |
dce7aa85 | 2 | # pacdiff : a simple pacnew/pacorig/pacsave updater |
1dbe2781 AG |
3 | # |
4 | # Copyright (c) 2007 Aaron Griffin <aaronmgriffin@gmail.com> | |
23f93118 | 5 | # Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org> |
1dbe2781 AG |
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 | |
9781d0d6 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1dbe2781 AG |
19 | # |
20 | ||
1038e669 | 21 | declare -r myname='pacdiff' |
a77e638c | 22 | declare -r myver='@PACKAGE_VERSION@' |
1038e669 | 23 | |
1dbe2781 | 24 | diffprog=${DIFFPROG:-vimdiff} |
6ed7d001 | 25 | diffsearchpath=${DIFFSEARCHPATH:-/etc} |
dce7aa85 | 26 | locate=0 |
f8ed8620 | 27 | USE_COLOR='y' |
dce7aa85 | 28 | |
f8ed8620 WG |
29 | m4_include(../scripts/library/output_format.sh) |
30 | ||
31 | m4_include(../scripts/library/term_colors.sh) | |
dd3762ed | 32 | |
dce7aa85 | 33 | usage() { |
1038e669 LF |
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" | |
6ed7d001 HB |
37 | echo " DIFFPROG variable allows to override the default vimdiff" |
38 | echo " DIFFSEARCHPATH allows to override the default /etc path" | |
1038e669 | 39 | echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname" |
dce7aa85 XC |
40 | } |
41 | ||
a77e638c LF |
42 | version() { |
43 | printf "%s %s\n" "$myname" "$myver" | |
44 | echo 'Copyright (C) 2007 Aaron Griffin <aaronmgriffin@gmail.com>' | |
23f93118 | 45 | echo 'Copyright (C) 2013 Pacman Development Team <pacman-dev@archlinux.org>' |
a77e638c LF |
46 | } |
47 | ||
dce7aa85 XC |
48 | cmd() { |
49 | if [ $locate -eq 1 ]; then | |
50 | locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave | |
51 | else | |
6ed7d001 | 52 | find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 |
dce7aa85 XC |
53 | fi |
54 | } | |
55 | ||
56 | if [ $# -gt 0 ]; then | |
57 | case $1 in | |
58 | -l|--locate) | |
59 | locate=1;; | |
a77e638c LF |
60 | -V|--version) |
61 | version; exit 0;; | |
62 | -h|--help) | |
dce7aa85 | 63 | usage; exit 0;; |
a77e638c LF |
64 | *) |
65 | usage; exit 1;; | |
dce7aa85 XC |
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*}" | |
dd3762ed FP |
72 | file_type="pac${pacfile##*.pac}" |
73 | ||
f8ed8620 | 74 | msg "%s file found for %s" "$file_type" "$file" |
dce7aa85 | 75 | if [ ! -f "$file" ]; then |
f8ed8620 | 76 | warning "$file does not exist" |
6a804d55 | 77 | rm -iv "$pacfile" |
dce7aa85 XC |
78 | continue |
79 | fi | |
495460d7 FP |
80 | |
81 | if cmp -s "$pacfile" "$file"; then | |
f8ed8620 | 82 | msg2 "Files are identical, removing..." |
6a804d55 | 83 | rm -v "$pacfile" |
dce7aa85 | 84 | else |
9108bfe0 | 85 | ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type" |
dce7aa85 XC |
86 | while read c; do |
87 | case $c in | |
9108bfe0 | 88 | q|Q) exit 0;; |
6a804d55 | 89 | r|R) rm -v "$pacfile"; break ;; |
163ba401 | 90 | o|O) mv -v "$pacfile" "$file"; break ;; |
dce7aa85 XC |
91 | v|V) |
92 | $diffprog "$pacfile" "$file" | |
6a804d55 | 93 | rm -iv "$pacfile"; break ;; |
dce7aa85 | 94 | s|S) break ;; |
9108bfe0 | 95 | *) ask "Invalid answer. Try again: [v/s/r/o/q] "; continue ;; |
dce7aa85 XC |
96 | esac |
97 | done | |
98 | fi | |
99 | done 3< <(cmd) | |
100 | ||
101 | exit 0 | |
102 | ||
103 | # vim: set ts=2 sw=2 noet: |