diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/tool/ifchange |
Fresh start
Diffstat (limited to 'jni/ruby/tool/ifchange')
-rwxr-xr-x | jni/ruby/tool/ifchange | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/jni/ruby/tool/ifchange b/jni/ruby/tool/ifchange new file mode 100755 index 0000000..488e9db --- /dev/null +++ b/jni/ruby/tool/ifchange @@ -0,0 +1,61 @@ +#!/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 + +if [ -f "$target" -a ! -${empty:+f}${empty:-s} "$temp" ] || cmp "$target" "$temp" >/dev/null 2>&1; then + echo "$target unchanged" + rm -f "$temp" +else + echo "$target updated" + [ 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 |