2008-01-25 05:22:32 -05:00
|
|
|
#!/bin/sh
|
|
|
|
# usage: ifchange target temporary
|
|
|
|
|
2013-06-13 08:30:24 -04:00
|
|
|
set -e
|
2009-03-15 23:30:01 -04:00
|
|
|
timestamp=
|
2013-05-15 03:51:32 -04:00
|
|
|
keepsuffix=
|
2009-03-15 23:30:01 -04:00
|
|
|
until [ "$0" = 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--timestamp)
|
|
|
|
timestamp=.
|
|
|
|
;;
|
|
|
|
--timestamp=*)
|
2009-05-04 22:33:02 -04:00
|
|
|
timestamp=`expr \( "$1" : '[^=]*=\(.*\)' \)`
|
2009-03-15 23:30:01 -04:00
|
|
|
;;
|
2013-05-15 03:51:32 -04:00
|
|
|
--keep)
|
|
|
|
keepsuffix=.old
|
|
|
|
;;
|
|
|
|
--keep=*)
|
|
|
|
keepsuffix=`expr \( "$1" : '[^=]*=\(.*\)' \)`
|
|
|
|
;;
|
2009-03-15 23:30:01 -04:00
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
2008-10-17 06:46:23 -04:00
|
|
|
shift
|
2009-03-15 23:30:01 -04:00
|
|
|
done
|
|
|
|
|
2008-01-25 05:22:32 -05:00
|
|
|
target="$1"
|
|
|
|
temp="$2"
|
|
|
|
if [ "$temp" = - ]; then
|
|
|
|
temp="tmpdata$$.tmp~"
|
|
|
|
cat > "$temp" || exit $?
|
|
|
|
trap 'rm -f "$temp"' 0
|
|
|
|
fi
|
2009-03-15 23:30:01 -04:00
|
|
|
|
2008-01-25 05:22:32 -05:00
|
|
|
if cmp "$target" "$temp" >/dev/null 2>&1; then
|
|
|
|
echo "$target unchanged"
|
2008-01-29 03:05:26 -05:00
|
|
|
rm -f "$temp"
|
2008-01-25 05:22:32 -05:00
|
|
|
else
|
|
|
|
echo "$target updated"
|
2013-06-13 08:30:24 -04:00
|
|
|
[ x"${keepsuffix}" = x ] || mv -f "$target" "${target}${keepsuffix}"
|
2008-01-25 05:22:32 -05:00
|
|
|
mv -f "$temp" "$target"
|
|
|
|
fi
|
2009-03-15 23:30:01 -04:00
|
|
|
|
|
|
|
if [ -n "${timestamp}" ]; then
|
|
|
|
if [ x"${timestamp}" = x. ]; then
|
|
|
|
case "$target" in
|
|
|
|
*/*)
|
|
|
|
timestamp=`dirname "$target"`/.time.`basename "$target"`
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
timestamp=.time."$target"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
: > "$timestamp"
|
2008-10-17 06:46:23 -04:00
|
|
|
fi
|