aboutsummaryrefslogtreecommitdiff
path: root/lock
blob: 22191fe3d7900a1a061c96c02c9e6d5f9386ba0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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