forked from briffy/PantherDashboard
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathupdate.sh
executable file
·171 lines (148 loc) · 6.7 KB
/
update.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
sudo apt-get -f install --assume-yes
if test -f /var/dashboard/branch; then
BRANCH=`cat /var/dashboard/branch`
else
BRANCH='main'
fi
if id -nG admin | grep -qw "sudo"; then
rm -rf /tmp/latest.tar.gz
rm -rf /tmp/PantherDashboard-*
mkdir -p /var/dashboard/logs/
echo 'Downloading latest release...' > /var/dashboard/logs/dashboard-update.log
if test -f /var/dashboard/commit-hash; then
VER=`cat /var/dashboard/commit-hash`
wget --no-cache https://codeload.github.com/Panther-X/PantherDashboard/tar.gz/${VER} -O /tmp/latest.tar.gz
else
wget https://raw.githubusercontent.com/Panther-X/PantherDashboard/${BRANCH}/version -O /tmp/dashboard_latest_ver
VER=`cat /tmp/dashboard_latest_ver`
wget --no-cache https://codeload.github.com/Panther-X/PantherDashboard/tar.gz/refs/tags/${VER} -O /tmp/latest.tar.gz
fi
cd /tmp
if test -s latest.tar.gz; then
echo 'Extracting contents...' >> /var/dashboard/logs/dashboard-update.log
tar -xzf latest.tar.gz
cd PantherDashboard-${VER}
apt-get update
# check php7.3-json, need to do it before php-fpm installation
if ! test -s /etc/php/7.3/mods-available/json.ini; then
# Remove it if is corrupt, it will install with php-fpm
apt-get --assume-yes purge php7.3-json
fi
apt-get --assume-yes install nginx php-fpm php7.3-fpm ngrep gawk php-cli logrotate netcat jq
[ -f /etc/monitor-scripts/clear-blockchain.sh ] && rm -f /etc/monitor-scripts/clear-blockchain.sh
mkdir -p /var/dashboard
mkdir -p /var/dashboard/logs
mkdir -p /etc/monitor-scripts
mkdir -p /var/log/packet-forwarder/
# Add the new services
mkdir -p /var/dashboard/services
for f in dashboard/services/*; do
if ! test -s /var/$f; then
cp $f /var/dashboard/services/
fi
done
# Add the new statuses
mkdir -p /var/dashboard/statuses
for f in dashboard/statuses/*; do
if ! test -f /var/$f; then
cp $f /var/dashboard/statuses/
fi
done
# Remove useless files
rm -rf dashboard/services/*
rm -rf dashboard/statuses/*
if test -f /etc/systemd/system/helium-status-check.timer; then
systemctl disable helium-status-check.timer
rm -rf /etc/systemd/system/helium-status-check.timer
fi
if test -f /etc/systemd/system/infoheight-check.timer; then
systemctl disable infoheight-check.timer
systemctl disable infoheight-check.service
rm -rf /etc/systemd/system/infoheight-check.timer
rm -rf /etc/systemd/system/infoheight-check.service
fi
if test -f /etc/systemd/system/fastsync-check.timer; then
systemctl disable fastsync-check.timer
systemctl disable fastsync-check.service
rm -rf /etc/systemd/system/fastsync-check.timer
rm -rf /etc/systemd/system/fastsync-check.service
fi
if test -f /etc/systemd/system/peer-list-check.timer; then
systemctl disable peer-list-check.timer
systemctl disable peer-list-check.service
rm -rf /etc/systemd/system/peer-list-check.timer
rm -rf /etc/systemd/system/peer-list-check.service
fi
if test -f /etc/systemd/system/clear-blockchain-check.timer; then
systemctl disable clear-blockchain-check.timer
systemctl disable clear-blockchain-check.service
rm -rf /etc/systemd/system/clear-blockchain-check.timer
rm -rf /etc/systemd/system/clear-blockchain-check.service
fi
# Remove /etc/ssl/certs/dhparam.pem if it is empty and regenerate it
[ -s /etc/ssl/certs/dhparam.pem ] || rm -f /etc/ssl/certs/dhparam.pem
if ! test -f /etc/ssl/certs/dhparam.pem; then
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
fi
# Remove /etc/ssl/certs/nginx-selfsigned.crt if it is empty and regenerate it
[ -s /etc/ssl/certs/nginx-selfsigned.crt ] || rm -rf /etc/ssl/certs/nginx-selfsigned.crt
if ! test -f /etc/ssl/certs/nginx-selfsigned.crt; then
openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -subj "/C=CN/ST=Panther/L=Panther/O=Panther/CN=localhost" -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
fi
cp monitor-scripts/* /etc/monitor-scripts/
cp -r logrotate.d/* /etc/logrotate.d/
cp nginx/snippets/* /etc/nginx/snippets/
cp nginx/default /etc/nginx/sites-enabled/
# Fix invalid password
[ -s /var/dashboard/.htpasswd ] || cp nginx/.htpasswd /var/dashboard/.htpasswd
rm nginx/.htpasswd
[ -f /etc/sudoers.d/www-data ] && rm -f /etc/sudoers.d/www-data
if ! test -f /etc/sudoers.d/www-data; then
sh -c 'echo www-data ALL=\(ALL\) NOPASSWD: /etc/monitor-scripts/helium-miner-log.sh > /etc/sudoers.d/www-data'
sh -c 'echo www-data ALL=\(ALL\) NOPASSWD: /etc/monitor-scripts/first-load.sh >> /etc/sudoers.d/www-data'
fi
cp -r dashboard/* /var/dashboard/
cp version /var/dashboard/
cp systemd/* /etc/systemd/system/
chmod 755 /etc/monitor-scripts/*
chown root:www-data /var/dashboard/services/*
chown root:www-data /var/dashboard/statuses/*
chmod 775 /var/dashboard/services/*
chmod 775 /var/dashboard/statuses/*
chown root:root /etc/ssl/private/nginx-selfsigned.key
chmod 600 /etc/ssl/private/nginx-selfsigned.key
chown root:root /etc/ssl/certs/nginx-selfsigned.crt
chmod 777 /etc/ssl/certs/nginx-selfsigned.crt
chown root:www-data /var/dashboard/.htpasswd
chmod 775 /var/dashboard/.htpasswd
chown root:www-data /var/dashboard
chmod 775 /var/dashboard
bash /etc/monitor-scripts/pantherx-ver-check.sh
systemctl daemon-reload
echo 'Starting and enabling services...' >> /var/dashboard/logs/dashboard-update.log
FILES="systemd/*.timer"
for f in $FILES;
do
name=$(echo $f | sed 's/.timer//' | sed 's/systemd\///')
systemctl start $name.timer >> /var/dashboard/logs/dashboard-update.log
systemctl enable $name.timer >> /var/dashboard/logs/dashboard-update.log
systemctl start $name.service >> /var/dashboard/logs/dashboard-update.log
systemctl daemon-reload >> /var/dashboard/logs/dashboard-update.log
done
systemctl daemon-reload
systemctl enable packet-forwarder-sniffer.service
systemctl start packet-forwarder-sniffer.service
systemctl enable nginx
systemctl restart nginx
bash /etc/monitor-scripts/pubkeys.sh
echo 'Success.' >> /var/dashboard/logs/dashboard-update.log
echo 'stopped' > /var/dashboard/services/dashboard-update
else
echo 'No installation archive found. No changes made.' >> /var/dashboard/logs/dashboard-update.log
echo 'stopped' > /var/dashboard/services/dashboard-update
fi
else
echo 'Error checking if admin user exists. No changes made.' >> /var/dashboard/logs/dashboard-update.log
echo 'stopped' > /var/dashboard/services/dashboard-update
fi