2008-01-25 05:22:32 -05:00
|
|
|
#!/bin/sh
|
|
|
|
# usage: ifchange target temporary
|
|
|
|
|
2008-10-17 06:46:23 -04:00
|
|
|
unset timestamp
|
|
|
|
if [ "$1" = --timestamp ]; then
|
|
|
|
timestamp=yes
|
|
|
|
shift
|
|
|
|
fi
|
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
|
|
|
|
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"
|
|
|
|
mv -f "$temp" "$target"
|
|
|
|
fi
|
2008-10-17 06:46:23 -04:00
|
|
|
if [ $timestamp ]; then
|
|
|
|
touch `dirname "$target"`/.time.`basename "$target"`
|
|
|
|
fi
|