2011-06-30 11:07:54 -04:00
|
|
|
#!/bin/bash
|
2009-02-17 17:40:11 -05:00
|
|
|
# pacdiff : a simple pacnew/pacorig/pacsave updater
|
2007-02-23 03:03:50 -05:00
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Aaron Griffin <aaronmgriffin@gmail.com>
|
2012-12-19 18:57:35 -05:00
|
|
|
# Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org>
|
2007-02-23 03:03:50 -05:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-02-23 03:03:50 -05:00
|
|
|
#
|
|
|
|
|
2011-12-06 16:29:32 -05:00
|
|
|
declare -r myname='pacdiff'
|
2011-12-12 16:36:57 -05:00
|
|
|
declare -r myver='@PACKAGE_VERSION@'
|
2011-12-06 16:29:32 -05:00
|
|
|
|
2007-02-23 03:03:50 -05:00
|
|
|
diffprog=${DIFFPROG:-vimdiff}
|
2009-10-21 17:46:47 -04:00
|
|
|
diffsearchpath=${DIFFSEARCHPATH:-/etc}
|
2009-02-17 17:40:11 -05:00
|
|
|
locate=0
|
2013-03-04 03:42:34 -05:00
|
|
|
USE_COLOR='y'
|
2009-02-17 17:40:11 -05:00
|
|
|
|
2013-03-04 03:42:34 -05:00
|
|
|
m4_include(../scripts/library/output_format.sh)
|
|
|
|
|
|
|
|
m4_include(../scripts/library/term_colors.sh)
|
2012-12-19 17:20:13 -05:00
|
|
|
|
2009-02-17 17:40:11 -05:00
|
|
|
usage() {
|
2011-12-06 16:29:32 -05:00
|
|
|
echo "$myname : a simple pacnew/pacorig/pacsave updater"
|
|
|
|
echo "Usage : $myname [-l]"
|
|
|
|
echo " -l/--locate makes $myname use locate rather than find"
|
2009-10-21 17:46:47 -04:00
|
|
|
echo " DIFFPROG variable allows to override the default vimdiff"
|
|
|
|
echo " DIFFSEARCHPATH allows to override the default /etc path"
|
2011-12-06 16:29:32 -05:00
|
|
|
echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname"
|
2009-02-17 17:40:11 -05:00
|
|
|
}
|
|
|
|
|
2011-12-12 16:36:57 -05:00
|
|
|
version() {
|
|
|
|
printf "%s %s\n" "$myname" "$myver"
|
|
|
|
echo 'Copyright (C) 2007 Aaron Griffin <aaronmgriffin@gmail.com>'
|
2012-12-19 18:57:35 -05:00
|
|
|
echo 'Copyright (C) 2013 Pacman Development Team <pacman-dev@archlinux.org>'
|
2011-12-12 16:36:57 -05:00
|
|
|
}
|
|
|
|
|
2009-02-17 17:40:11 -05:00
|
|
|
cmd() {
|
|
|
|
if [ $locate -eq 1 ]; then
|
|
|
|
locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave
|
|
|
|
else
|
2009-10-21 17:46:47 -04:00
|
|
|
find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0
|
2009-02-17 17:40:11 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
case $1 in
|
|
|
|
-l|--locate)
|
|
|
|
locate=1;;
|
2011-12-12 16:36:57 -05:00
|
|
|
-V|--version)
|
|
|
|
version; exit 0;;
|
|
|
|
-h|--help)
|
2009-02-17 17:40:11 -05:00
|
|
|
usage; exit 0;;
|
2011-12-12 16:36:57 -05:00
|
|
|
*)
|
|
|
|
usage; exit 1;;
|
2009-02-17 17:40:11 -05:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
# see http://mywiki.wooledge.org/BashFAQ/020
|
|
|
|
while IFS= read -u 3 -r -d '' pacfile; do
|
|
|
|
file="${pacfile%.pac*}"
|
2012-12-19 17:20:13 -05:00
|
|
|
file_type="pac${pacfile##*.pac}"
|
|
|
|
|
2013-03-04 03:42:34 -05:00
|
|
|
msg "%s file found for %s" "$file_type" "$file"
|
2009-02-17 17:40:11 -05:00
|
|
|
if [ ! -f "$file" ]; then
|
2013-03-04 03:42:34 -05:00
|
|
|
warning "$file does not exist"
|
2012-12-19 17:21:06 -05:00
|
|
|
rm -iv "$pacfile"
|
2009-02-17 17:40:11 -05:00
|
|
|
continue
|
|
|
|
fi
|
2012-12-19 17:21:56 -05:00
|
|
|
|
|
|
|
if cmp -s "$pacfile" "$file"; then
|
2013-03-04 03:42:34 -05:00
|
|
|
msg2 "Files are identical, removing..."
|
2012-12-19 17:21:06 -05:00
|
|
|
rm -v "$pacfile"
|
2009-02-17 17:40:11 -05:00
|
|
|
else
|
2013-03-04 03:42:34 -05:00
|
|
|
ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s: [v/s/r/o] " "$file_type" "$file_type"
|
2009-02-17 17:40:11 -05:00
|
|
|
while read c; do
|
|
|
|
case $c in
|
2012-12-19 17:21:06 -05:00
|
|
|
r|R) rm -v "$pacfile"; break ;;
|
2012-12-19 17:22:22 -05:00
|
|
|
o|O) mv -v "$pacfile" "$file"; break ;;
|
2009-02-17 17:40:11 -05:00
|
|
|
v|V)
|
|
|
|
$diffprog "$pacfile" "$file"
|
2012-12-19 17:21:06 -05:00
|
|
|
rm -iv "$pacfile"; break ;;
|
2009-02-17 17:40:11 -05:00
|
|
|
s|S) break ;;
|
2013-03-04 03:42:34 -05:00
|
|
|
*) ask "Invalid answer. Try again: [v/s/r/o] "; continue ;;
|
2009-02-17 17:40:11 -05:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done 3< <(cmd)
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 noet:
|