]>
wolfpit.net Git - tool/Arch-pacman/.git/blob - contrib/pacdiff.sh.in
2 # pacdiff : a simple pacnew/pacorig/pacsave updater
4 # Copyright (c) 2007 Aaron Griffin <aaronmgriffin@gmail.com>
5 # Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org>
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.
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.
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/>.
23 declare -r myname
='pacdiff'
24 declare -r myver
='@PACKAGE_VERSION@'
26 diffprog
=${DIFFPROG:-vimdiff}
27 diffsearchpath
=${DIFFSEARCHPATH:-/etc}
30 declare -i USE_FIND
=0 USE_LOCATE
=0 USE_PACDB
=0
32 m4_include
(..
/scripts
/library
/output_format.sh
)
36 $myname is a simple pacnew/pacorig/pacsave updater.
38 Usage: $myname [-l | -f | -p] [--nocolor]
40 Search Options: select one, default: pacmandb
41 -l/--locate scan using locate
42 -f/--find scan using find
43 -p/--pacmandb scan active config files from pacman db
46 --nocolor remove colors from output
49 DIFFPROG override the merge program: (default: vimdiff)
50 DIFFSEARCHPATH override the search path. (only when using find)
53 Example: DIFFPROG=meld DIFFSEARCHPATH="/boot /etc /usr" $myname
59 printf "%s %s\n" "$myname" "$myver"
60 echo 'Copyright (C) 2007 Aaron Griffin <aaronmgriffin@gmail.com>'
61 echo 'Copyright (C) 2013 Pacman Development Team <pacman-dev@archlinux.org>'
65 [[ -f "$1" ]] && printf '%s\0' "$1"
68 print_existing_pacsave
(){
69 for f
in "${1}"?
(.
+([0-9])); do
70 [[ -f $f ]] && printf '%s\0' "$f"
75 if (( USE_LOCATE
)); then
76 locate -0 -e -b \
*.pacnew \
*.pacorig \
*.pacsave
'*.pacsave.[0-9]*'
77 elif (( USE_FIND
)); then
78 find $diffsearchpath \
( -name \
*.pacnew
-o -name \
*.pacorig
-o -name \
*.pacsave
-o -name '*.pacsave.[0-9]*' \
) -print0
79 elif (( USE_PACDB
)); then
82 if (/^$/) { nextfile }
85 }' "${pac_db}"/*/files
| while read -r bkup
; do
86 print_existing
"/$bkup.pacnew"
87 print_existing
"/$bkup.pacorig"
88 print_existing_pacsave
"/$bkup.pacsave"
93 while [[ -n "$1" ]]; do
113 m4_include
(..
/scripts
/library
/term_colors.sh
)
115 case $(( USE_FIND + USE_LOCATE + USE_PACDB )) in
116 0) USE_PACDB
=1;; # set the default search option
117 [^
1]) error
"Only one search option may be used at a time"
121 if (( USE_PACDB
)); then
122 if [[ ! -r @sysconfdir@
/pacman.conf
]]; then
123 error
"unable to read @sysconfdir@/pacman.conf"
127 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
128 pac_db
="${DBPath:-@localstatedir@/lib/pacman/}local"
129 if [[ ! -d "${pac_db}" ]]; then
130 error
"unable to read pacman db %s".
"${pac_db}"
135 # see http://mywiki.wooledge.org/BashFAQ/020
136 while IFS
= read -u 3 -r -d '' pacfile
; do
137 file="${pacfile%.pac*}"
138 file_type
="pac${pacfile##*.pac}"
140 # add matches for pacsave.N to oldsaves array, do not prompt
141 if [[ $file_type = pacsave.
+([0-9]) ]]; then
142 oldsaves
+=("$pacfile")
146 msg
"%s file found for %s" "$file_type" "$file"
147 if [ ! -f "$file" ]; then
148 warning
"$file does not exist"
153 if cmp -s "$pacfile" "$file"; then
154 msg2
"Files are identical, removing..."
157 ask
"(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type"
161 r
|R
) rm -v "$pacfile"; break ;;
162 o
|O
) mv -v "$pacfile" "$file"; break ;;
164 $diffprog "$pacfile" "$file"
165 rm -iv "$pacfile"; break ;;
167 *) ask
"Invalid answer. Try again: [v/s/r/o/q] "; continue ;;
173 (( ${#oldsaves[@]} )) && warning
"Ignoring %s" "${oldsaves[@]}"
177 # vim: set ts=2 sw=2 noet: