aboutsummaryrefslogtreecommitdiff
path: root/lock.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lock.sh')
-rwxr-xr-xlock.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/lock.sh b/lock.sh
new file mode 100755
index 0000000..22191fe
--- /dev/null
+++ b/lock.sh
@@ -0,0 +1,28 @@
+lock() {
+
+ if [[ -f "$1" ]]; then
+ echo "$1 is not a lock directory."
+ exit 1
+ fi
+
+ if mkdir "$1" &>/dev/null; then
+ echo "lock $1 created" >&2
+ else
+ echo "lock $1 found, waiting for unlock" >&2
+ while true; do
+ sleep 2;
+ if [[ ! -d "$1" ]]; then
+ return
+ fi
+ done
+ fi;
+
+}
+
+if [[ "$#" -eq "1" ]]; then
+ lock "$1"
+else
+ echo "please supply one argument: the lock directory."
+ exit 1
+fi
+