-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_run_and_halt.sh
More file actions
executable file
·61 lines (53 loc) · 1.53 KB
/
check_run_and_halt.sh
File metadata and controls
executable file
·61 lines (53 loc) · 1.53 KB
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
#!/usr/bin/env bash
#
# Do control checks with remote server before running the run script run_and_halt.sh
#
# Add to crontab
# $ crontab -e
# $ crontab -l
# SHELL=/bin/bash
# @reboot seep 60 && /home/hackorama/epical/check_run_and_halt.sh > /home/hackorama/.epical/epical.log 2>&1 &
#
# Check run logs
# $ tail -f ~/.epical/epical.log
INSTALL_ROOT=$HOME/epical
function check_disable() {
# First check if refresh is disabled and exit without refresh and halt
if wget -q --tries=2 --timeout=5 -O /dev/null "$CONTROL_URL"/disable
then
echo "CONTROL CHECK: Refresh disabled, device will not be halted"
echo "Exiting, device will not be halted"
exit
else
echo "CONTROL CHECK: No refresh disable"
fi
}
function check_upgrade() {
# Check for any new upgrade release package and deploy before refresh
if wget -q --tries=2 --timeout=5 -O "$INSTALL_ROOT"/../epical.tar "$CONTROL_URL"/epical.tar
then
echo "CONTROL CHECK: Found package"
echo "Deploying to $INSTALL_ROOT/.. ..."
cd "$INSTALL_ROOT"/.. || exit
tar -xf epical.tar
cd - || exit
else
echo "CONTROL CHECK: No package to deploy"
fi
}
function check() {
CONTROL_URL=$(grep CONTROL_SERVER_URL "$INSTALL_ROOT"/epical/config.py | cut -d '=' -f 2 | xargs)
echo "CONTROL CHECK: Server $CONTROL_URL"
if wget -q --tries=2 --timeout=5 -O /dev/null "$CONTROL_URL"
then
check_upgrade
check_disable
else
echo "CONTROL CHECK: Server down, no checks"
fi
}
function run() {
check
. "$INSTALL_ROOT"/run_and_halt.sh
}
run