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