-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify.sh
executable file
·86 lines (80 loc) · 2.45 KB
/
verify.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
step=1
prog_name="rc.local"
KASAROS_PATH="/root/kasarOs"
CLIENT_DIR="$KASAROS_PATH/client"
LOGS_PATH="$KASAROS_PATH/network/logs.txt"
CONFIG_PATH="/boot/efi/src/config.json"
client=$(jq -r '.client' $CONFIG_PATH)
provider_id=$(jq -r '.provider_id' $CONFIG_PATH)
node_id=$(jq -r '.node_id' $CONFIG_PATH)
action=""
postState() {
URL="http://179.61.246.59:8080/node/setState?provider_id=$provider_id&node_id=$node_id"
DATA="\"$1\""
echo $DATA
curl -X POST -H "Content-Type: application/json" -d "$DATA" "$URL"
}
getAction() {
URL="http://179.61.246.59:8080/node/getAction?provider_id=$provider_id"
DATA="{
\"NodeID\": $node_id,
\"Action\": \"\",
\"Command\": \"\",
\"Response\": \"\"
}"
action=$(curl -X POST -H "Content-Type: application/json" -d "$DATA" "$URL")
}
check_script() {
if ! pgrep -f prog_name >/dev/null; then
if [ "$step" -eq 1 ]; then
sleep 5
elif [ "$step" -eq 2 ]; then
./start.sh > /root/logs 2>&1 &
else
sudo docker logs -f $client &>> $LOGS_PATH & nohup $KASAROS_PATH/myOsiris > $KASAROS_PATH/nohup.out 2>&1 &
fi
fi
}
while true; do
if pgrep -f "rc.local" >/dev/null; then
step=1
prog_name="start.sh"
elif pgrep -f "start.sh" >/dev/null; then
step=2
prog_name="myOsiris"
elif pgrep -f "myOsiris" >/dev/null; then
step=3
else
sleep 5
check_script
fi
getAction
if [ "$action" = "\"shutdown\"" ]; then
postState "Shut down"
sudo poweroff
elif [ "$action" = "\"reboot\"" ]; then
postState "Rebooting"
sudo reboot
elif [ "$action" = "\"hardReset\"" ] || [ "$action" = "\"reset\"" ]; then
if command -v docker >/dev/null 2>&1; then
sudo docker stop $(docker ps -aq) > /dev/null 2>&1 || true
sudo docker rm $(docker ps -aq) > /dev/null 2>&1 || true
fi
sudo rm -rf /root/kasarOs
if [ -d "/root/juno" ]; then
rm -rf /root/juno
fi
if [ -d "/root/pathfinder" ]; then
rm -rf /root/pathfinder
fi
cd /root/
git clone https://github.com/KasarLabs/kasarOs && cd kasarOs && git checkout roc-dev
if ! cmp -s "/root/kasarOs/rc.local" "/etc/rc.local"; then
cp "/root/kasarOs/rc.local" "/etc/rc.local"
fi
postState "Rebooting"
sudo reboot
fi
sleep 20
done