1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-16 06:15:08 -05:00
pacman/contrib/pacdiff.in
Lukas Fleischer a77e638c77 contrib/*: Support the "--help" and "--version" options
Add "--help"/"-h" and "--version"/"-V" support to all contrib scripts.
Also, update scripts that used "-v" as a short option for "--version"
and use "-V" for the sake of consistency.

Additionally:

* Move version and usage messages to separate convenience functions in
  all scripts.

* Add a workaround to paccache to support "--help" and "--version". This
  should be replaced by a proper POSIX-compliant command line parser
  that supports long options in a future patch.

* Add a "$myver" variable to all scripts and use it whenever we refer to
  the program version (e.g. in version messages). Also, use the pacman
  version number everywhere instead of using a different versioning
  scheme for each contrib script. This is achieved by adding a
  "PACKAGE_VERSION" placeholder that is replaced by sed(1) when the
  script is built.

* Ensure we always return with exit status 0 if "--help" is used and
  return with exit status 1 if we display the usage message due to
  invalid arguments.

* Add "AUTOMAKE_OPTIONS = std-options" and add all scripts to
  "bin_SCRIPTS" to make `make installcheck` check that installed scripts
  actually support the "--help" and "--version" options.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-12-23 14:49:46 -06:00

93 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# pacdiff : a simple pacnew/pacorig/pacsave updater
#
# Copyright (c) 2007 Aaron Griffin <aaronmgriffin@gmail.com>
#
# 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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
declare -r myname='pacdiff'
declare -r myver='@PACKAGE_VERSION@'
diffprog=${DIFFPROG:-vimdiff}
diffsearchpath=${DIFFSEARCHPATH:-/etc}
locate=0
usage() {
echo "$myname : a simple pacnew/pacorig/pacsave updater"
echo "Usage : $myname [-l]"
echo " -l/--locate makes $myname use locate rather than find"
echo " DIFFPROG variable allows to override the default vimdiff"
echo " DIFFSEARCHPATH allows to override the default /etc path"
echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname"
}
version() {
printf "%s %s\n" "$myname" "$myver"
echo 'Copyright (C) 2007 Aaron Griffin <aaronmgriffin@gmail.com>'
}
cmd() {
if [ $locate -eq 1 ]; then
locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave
else
find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0
fi
}
if [ $# -gt 0 ]; then
case $1 in
-l|--locate)
locate=1;;
-V|--version)
version; exit 0;;
-h|--help)
usage; exit 0;;
*)
usage; exit 1;;
esac
fi
# see http://mywiki.wooledge.org/BashFAQ/020
while IFS= read -u 3 -r -d '' pacfile; do
file="${pacfile%.pac*}"
echo "File: $file"
if [ ! -f "$file" ]; then
echo " $file does not exist"
rm -i "$pacfile"
continue
fi
check="$(cmp "$pacfile" "$file")"
if [ -z "${check}" ]; then
echo " Files are identical, removing..."
rm "$pacfile"
else
echo -n " File differences found. (V)iew, (S)kip, (R)emove: [v/s/r] "
while read c; do
case $c in
r|R) rm "$pacfile"; break ;;
v|V)
$diffprog "$pacfile" "$file"
rm -i "$pacfile"; break ;;
s|S) break ;;
*) echo -n " Invalid answer. Try again: [v/s/r] "; continue ;;
esac
done
fi
done 3< <(cmd)
exit 0
# vim: set ts=2 sw=2 noet: