-
Notifications
You must be signed in to change notification settings - Fork 2
/
opendoor
executable file
·69 lines (57 loc) · 1.41 KB
/
opendoor
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
69
#!/bin/bash
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
# shellcheck disable=SC2120
help () {
# if arguments, print them
[ $# == 0 ] || echo "$*"
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") a|b
opens doors, you must specifiy which door to open
Available options:
-h, --help display this help and exit
EOF
# if args, exit 1 else exit 0
[ $# == 0 ] || exit 1
exit 0
}
msg() {
echo >&2 -e "${1-}"
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}
# getopt short options go together, long options have commas
TEMP=$(getopt -o h --long help -n "$0" -- "$@")
#shellcheck disable=SC2181
if [ $? != 0 ] ; then
die "something wrong with getopt"
fi
eval set -- "$TEMP"
while true ; do
case "$1" in
-h|--help) help; exit 0; shift ;;
--) shift ; break ;;
*) die "issue parsing args, unexpected argument '$0'!" ;;
esac
done
targetDoor=${1:-}
shift || true
if [ "$targetDoor" != "a" ] && [ "$targetDoor" != "b" ]; then
die "target door valeu of '$targetDoor' is not valid, valid optins are 'a', or 'b'"
fi
reboot () {
door=$1
ip=$2
mosquitto_pub -t "i3/doors/${door}/cmd" -m "{\"cmd\":\"opendoor\", \"doorip\":\"${ip}\"}" -h 10.13.0.22
}
if [[ "$targetDoor" = "a" ]]; then
reboot a-side-main 10.13.107.15
fi
if [[ "$targetDoor" = "b" ]]; then
reboot b-side-office 10.13.107.167
fi