mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
35957b7690
* tool/ifchange: do not exit by -e even if tput failed. [ruby-core:71143] [Bug #11611] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
79 lines
1.7 KiB
Bash
Executable file
79 lines
1.7 KiB
Bash
Executable file
#!/bin/sh
|
||
# usage: ifchange target temporary
|
||
|
||
set -e
|
||
timestamp=
|
||
keepsuffix=
|
||
empty=
|
||
until [ $# -eq 0 ]; do
|
||
case "$1" in
|
||
--timestamp)
|
||
timestamp=.
|
||
;;
|
||
--timestamp=*)
|
||
timestamp=`expr \( "$1" : '[^=]*=\(.*\)' \)`
|
||
;;
|
||
--keep)
|
||
keepsuffix=.old
|
||
;;
|
||
--keep=*)
|
||
keepsuffix=`expr \( "$1" : '[^=]*=\(.*\)' \)`
|
||
;;
|
||
--empty)
|
||
empty=yes
|
||
;;
|
||
*)
|
||
break
|
||
;;
|
||
esac
|
||
shift
|
||
done
|
||
|
||
target="$1"
|
||
temp="$2"
|
||
if [ "$temp" = - ]; then
|
||
temp="tmpdata$$.tmp~"
|
||
cat > "$temp" || exit $?
|
||
trap 'rm -f "$temp"' 0
|
||
fi
|
||
|
||
msg_begin= msg_unchanged= msg_updated= msg_reset=
|
||
if [ -t 1 ]; then
|
||
msg_begin="`tput smso 2>/dev/null`" || :
|
||
case "$msg_begin" in
|
||
""*m)
|
||
msg_begin="`echo "$msg_begin" | sed 's/[0-9]*m$//'`"
|
||
if [ ${TEST_COLORS:+set} ]; then
|
||
msg_unchanged=`expr ":$TEST_COLORS:" : ".*:pass=\([^:]*\):"`
|
||
msg_updated=`expr ":$TEST_COLORS:" : ".*:fail=\([^:]*\):"`
|
||
fi
|
||
msg_unchanged="${msg_begin}${msg_unchanged:-32;1}m"
|
||
msg_updated="${msg_begin}${msg_updated:-31;1}m"
|
||
msg_reset="${msg_begin}m"
|
||
;;
|
||
esac
|
||
unset msg_begin
|
||
fi
|
||
|
||
if [ -f "$target" -a ! -${empty:+f}${empty:-s} "$temp" ] || cmp "$target" "$temp" >/dev/null 2>&1; then
|
||
echo "$target ${msg_unchanged}unchanged${msg_reset}"
|
||
rm -f "$temp"
|
||
else
|
||
echo "$target ${msg_updated}updated${msg_reset}"
|
||
[ x"${keepsuffix}" = x ] || mv -f "$target" "${target}${keepsuffix}"
|
||
mv -f "$temp" "$target"
|
||
fi
|
||
|
||
if [ -n "${timestamp}" ]; then
|
||
if [ x"${timestamp}" = x. ]; then
|
||
case "$target" in
|
||
*/*)
|
||
timestamp=`dirname "$target"`/.time.`basename "$target"`
|
||
;;
|
||
*)
|
||
timestamp=.time."$target"
|
||
;;
|
||
esac
|
||
fi
|
||
: > "$timestamp"
|
||
fi
|