-
Notifications
You must be signed in to change notification settings - Fork 1
/
climb
executable file
·68 lines (56 loc) · 1.15 KB
/
climb
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
handle_one () {
disk="$1"
mount="$2"
rest=" $mount ( $disk )"
resolved=$(readlink -f "$disk")
if [ -L "$disk" ]
then
if grep -qs "${resolved}" /proc/mounts 2>&1 >/dev/null
then
echo " + already mounted:${rest}"
else
echo " ^ mounting to:${rest}"
mkdir -p $mount
sudo mount $disk $mount
fi
else
echo " ? not present:${rest}"
fi
}
handle () {
cat mountains | grep -vE '^ *(#.*)?$' | xargs --max-lines=1 --max-procs=1 --replace=A bash -c 'handle_one A'
}
export -f handle_one
set -o errexit -o pipefail
DAEMON=false
PERIOD=60
USAGE_TEXT="\
Usage: $0 [-dp]
-d loop continuously as a daemon
-p approximate loop period in seconds [${PERIOD}]
-h display this help and exit
"
usage() {
echo "${USAGE_TEXT}"
}
while getopts dp:h flag
do
case "${flag}" in
d) DAEMON=true;;
p) PERIOD=${OPTARG};;
h) usage; exit 0;;
*) echo; usage; exit 1;;
esac
done
trap "kill 0" INT
if [ "${DAEMON}" = "false" ]
then
handle
else
while true
do
handle
sleep ${PERIOD}
done
fi