Files
django-dav-events/bin/diff-screenshots.sh

136 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
function print_help() {
bn=`basename $0`
cat <<E-O-H
Usage: $bn DIR1 DIR2
E-O-H
}
function ask_yesno() {
local prompt="Yes or No?"
local text=""
local default=""
local answer=""
local retval=""
while test $# -gt 0 ; do
case "$1" in
-y)
default="yes"
shift
;;
-n)
default="no"
shift
;;
*)
prompt="$*"
break
;;
esac
done
text="$prompt (y/n)"
if test "X${default}" = "Xyes" ; then
text="$text [y]"
elif test "X${default}" = "Xno" ; then
text="$text [n]"
fi
text="$text "
while : ; do
read -p "$text" -n 1 answer
case "$answer" in
y|Y|t|T|1)
echo ""
retval=0
;;
n|N|f|F|0)
echo ""
retval=1
;;
'')
if test "X${default}" = "Xyes" ; then
retval=0
elif test "X${default}" = "Xno" ; then
retval=1
else
echo "Please press the <y>-Key or the <n>-Key!" >&2
echo "Or press Ctrl-C to abort." >&2
echo ""
continue
fi
;;
*)
echo ""
echo "What? $answer?" >&2
echo "Please press the <y>-Key or the <n>-Key!" >&2
echo "Or press Ctrl-C to abort." >&2
echo ""
continue
;;
esac
break
done
return $retval
}
ORIGINAL_DIR=""
MODIFIED_DIR=""
if test $# -le 1 ; then
set -- -h
fi
while test $# -gt 0 ; do
case "$1" in
-h|--help)
print_help
exit 0
;;
*)
ORIGINAL_DIR="$1"
MODIFIED_DIR="$2"
break
;;
esac
done
ORIGINAL_DIR=`echo "$ORIGINAL_DIR" | sed -e 's:/*$::'`
MODIFIED_DIR=`echo "$MODIFIED_DIR" | sed -e 's:/*$::'`
original_files=`find "$ORIGINAL_DIR" -type f`
for original in $original_files ; do
relpath="${original#${ORIGINAL_DIR}/}"
reldir=`dirname "$relpath"`
basename=`basename "$relpath"`
basename_pattern=`echo "$basename" | sed -E -e 's:^[0-9]{8}-[0-9]{6}.[0-9]{6}-:*-*.*-:'`
modified_pattern="${MODIFIED_DIR}/${reldir}/${basename_pattern}"
modified=`echo $modified_pattern`
if ! test -e "$modified" ; then
echo "Only in ${ORIGINAL_DIR}: $relpath" >&2
else
if ! cmp --quiet "$original" "$modified" ; then
echo "File differ: $relpath" >&2
prompt="Display changes?"
if ask_yesno -n "$prompt" ; then
compare "$original" "$modified" miff:- | display
fi
fi
fi
done
find "$MODIFIED_DIR" -type f | while read modified ; do
relpath="${modified#${MODIFIED_DIR}/}"
reldir=`dirname "$relpath"`
basename=`basename "$relpath"`
basename_pattern=`echo "$basename" | sed -E -e 's:^[0-9]{8}-[0-9]{6}.[0-9]{6}-:*-*.*-:'`
original_pattern="${ORIGINAL_DIR}/${reldir}/${basename_pattern}"
original=`echo $original_pattern`
if ! test -e "$original" ; then
echo "Only in ${MODIFIED_DIR}: $relpath" >&2
fi
done