exit-post-hook-unlock.sh: exit gracefully if LOCKDIR does not exist
[experiments/hook-lock.git] / enter-pre-hook-lock.sh
1 #!/bin/sh
2 #
3 # Acquire a lock to protect a "pre" hook against concurrent executions.
4 #
5 # Copyright (C) 2018  Antonio Ospite <ao2@ao2.it>
6 # SPDX-License-Identifier: WTFPL
7 #
8 # This program is free software. It comes without any warranty, to
9 # the extent permitted by applicable law. You can redistribute it
10 # and/or modify it under the terms of the Do What The Fuck You Want
11 # To Public License, Version 2, as published by Sam Hocevar. See
12 # http://sam.zoy.org/wtfpl/COPYING for more details.
13
14 set -e
15
16 LOCKDIR=/run/lock/mylockdir
17 mkdir "$LOCKDIR" 2>/dev/null || { echo "The enter script had been launched. But the exit script has not." 1>&2; exit 1; }
18 echo $PPID > "$LOCKDIR/pid"
19
20 # Do stuff here