lvm-backup/lock.sh

47 lines
688 B
Bash
Raw Permalink Normal View History

2017-08-24 23:28:28 +02:00
#!/bin/bash
LOCKDIR="/tmp/snapshotslocks/"
[ ! -d "$LOCKDIR" ] && mkdir -p "$LOCKDIR"
createlock() {
LOCKNAME=$1
[ -f "$LOCKDIR/$LOCKNAME.lock" ] && exit 1
touch "$LOCKDIR/$LOCKNAME.lock"
exit 0
}
deletelock() {
LOCKNAME=$1
[ ! -f "$LOCKDIR/$LOCKNAME.lock" ] && exit 1
rm "$LOCKDIR/$LOCKNAME.lock"
exit 0
}
haslock() {
if ls $LOCKDIR/* 1> /dev/null 2>&1; then
exit 0
else
exit 1
fi
}
case $1 in
lock)
createlock $2
;;
unlock)
deletelock $2
;;
haslock)
haslock
;;
show)
ls $LOCKDIR
;;
*)
echo "What is $1" >&2
exit 1
esac