]> git.donarmstrong.com Git - bin.git/commitdiff
support no inotifywait
authorDon Armstrong <don@donarmstrong.com>
Wed, 17 May 2017 21:43:48 +0000 (14:43 -0700)
committerDon Armstrong <don@donarmstrong.com>
Wed, 17 May 2017 21:44:28 +0000 (14:44 -0700)
run_when_changed

index 85c4c3479a48238865c41f0547aa3d8fd5c624fd..8ad3a27fbdce180b37f38fa61a12f2ea379afe98 100755 (executable)
@@ -1,14 +1,29 @@
 #!/bin/sh
 
-WATCH_FILE="$1"
+WATCH_FULL_FILE="$1"
 shift 1;
 
-WATCH_DIR=`dirname "$WATCH_FILE"`
-WATCH_FILE=`basename "$WATCH_FILE"`
+if ! [ -e "$WATCH_FULL_FILE" ]; then
+    echo "No such file or directory $WATCH_FULL_FILE";
+fi;
 
-inotifywait -m -e close_write,moved_to,create $WATCH_DIR |
-    while read -r directory events filename; do
-        if [ "x$filename" = "x$WATCH_FILE" ]; then
+WATCH_DIR=`dirname "$WATCH_FULL_FILE"`
+WATCH_FILE=`basename "$WATCH_FULL_FILE"`
+
+if which inotifywait > /dev/null 2>&1; then
+    inotifywait -m -e close_write,moved_to,create $WATCH_DIR |
+        while read -r directory events filename; do
+            if [ "x$filename" = "x$WATCH_FILE" ]; then
+                ( exec "$@" );
+            fi;
+        done;
+else
+    CURR_TIME=$(stat -c '%Y' "$WATCH_FULL_FILE");
+    while sleep 1; do
+        NEW_TIME=$(stat -c '%Y' "$WATCH_FULL_FILE");
+        if [ "x$NEW_TIME" != "x$CURR_TIME" ]; then
+            CURR_TIME=$NEW_TIME
             ( exec "$@" );
         fi;
     done;
+fi;