summaryrefslogtreecommitdiffstats
path: root/lock.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lock.sh')
-rw-r--r--lock.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/lock.sh b/lock.sh
new file mode 100644
index 0000000..a67e019
--- /dev/null
+++ b/lock.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+cd $1
+
+set -o noclobber
+{ > status_waiting; }
+if [ "$?" != "0" ]
+then
+ echo "Some other thread is alreay waiting. Exit."
+
+ set +o noclobber
+ cd -
+ exit 1
+else
+
+ { > status_running; }
+ while [ "$?" != "0" ]
+ do
+ echo "Some other thread is already building. Waiting 5 sec!"
+ sleep 5
+ { > status_running; }
+ done
+ rm status_waiting
+
+ set +o noclobber
+ cd -
+ exit 0
+fi