2008-01-25 13:22:32 +03:00
|
|
|
#!/bin/sh
|
|
|
|
# usage: ifchange target temporary
|
|
|
|
|
2009-03-16 06:30:01 +03:00
|
|
|
timestamp=
|
|
|
|
until [ "$0" = 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--timestamp)
|
|
|
|
timestamp=.
|
|
|
|
;;
|
|
|
|
--timestamp=*)
|
2009-05-05 06:33:02 +04:00
|
|
|
timestamp=`expr \( "$1" : '[^=]*=\(.*\)' \)`
|
2009-03-16 06:30:01 +03:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
2008-10-17 14:46:23 +04:00
|
|
|
shift
|
2009-03-16 06:30:01 +03:00
|
|
|
done
|
|
|
|
|
2008-01-25 13:22:32 +03:00
|
|
|
target="$1"
|
|
|
|
temp="$2"
|
|
|
|
if [ "$temp" = - ]; then
|
|
|
|
temp="tmpdata$$.tmp~"
|
|
|
|
cat > "$temp" || exit $?
|
|
|
|
trap 'rm -f "$temp"' 0
|
|
|
|
fi
|
2009-03-16 06:30:01 +03:00
|
|
|
|
2008-01-25 13:22:32 +03:00
|
|
|
if cmp "$target" "$temp" >/dev/null 2>&1; then
|
|
|
|
echo "$target unchanged"
|
2008-01-29 11:05:26 +03:00
|
|
|
rm -f "$temp"
|
2008-01-25 13:22:32 +03:00
|
|
|
else
|
|
|
|
echo "$target updated"
|
|
|
|
mv -f "$temp" "$target"
|
|
|
|
fi
|
2009-03-16 06:30:01 +03: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 14:46:23 +04:00
|
|
|
fi
|