-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·56 lines (44 loc) · 1.27 KB
/
install.sh
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
#!/bin/bash
# Run query-adsb.sh every 3 min each day from 06:00 ... 21:50
set -euo pipefail
_trap()
{
local status="$1"
local lineno="$2"
local line=$(sed -n "$lineno p" "$0")
sed $'s/\\\\033/\033/g' <<-EOF >&2
\033[1;37;41m*** FAILED ***\033[m
[=\033[1;37m$status\033[m] \033[36m$0($lineno)\033[m: \033[1;37m$line\033[m
EOF
}
trap '_trap $? $LINENO' ERR
# query-adsb.sh needs `jq`
dpkg -l jq &>/dev/null ||
{
echo "jq not installed." >&2
exit 1
}
if [ -f "$HOME/hems-lookout.conf" ]; then
source "$HOME/hems-lookout.conf"
fi
# If HEMS_LOOKOUT_FCM_AUTH not set, try setting to found file
if [[ ! ${HEMS_LOOKOUT_FCM_AUTH:-} ]]; then
if [ -f "$HOME/hems-lookout-fcm.json" ]; then
HEMS_LOOKOUT_FCM_AUTH="$HOME/hems-lookout-fcm.json"
fi
fi
[[ ${HEMS_LOOKOUT_FCM_AUTH:-} ]] ||
{
echo "Unable to determine firebase credentials. Cannot continue." >&2
exit 1
}
readonly SCRIPTDIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
# Setup venv
python3 -m venv "$SCRIPTDIR/.venv"
"$SCRIPTDIR/.venv/bin/python" -m pip install --upgrade pip
"$SCRIPTDIR/.venv/bin/python" -m pip install --requirement "$SCRIPTDIR/requirements.txt"
# Adjust crontab
crontab < <(
crontab -l | sed '/hems-lookout/d' || true # An empty crontab would error out
echo "*/3 7-22 * * * '$SCRIPTDIR/query-adsb.sh'"
)