-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
107 lines (85 loc) · 2.89 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
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
#!/bin/bash
# Move the service_names.txt amd checkbox_states files if they exist
echo Preparing for install...
if [ -s SimplePiStats/config.ini ]; then
sudo mv SimplePiStats/config.ini /
fi
if [ -s SimplePiStats/.checkbox_states.json ]; then
sudo mv SimplePiStats/.checkbox_states.json /
fi
if [ -s SimplePiStats/docker_ports.json ]; then
sudo mv SimplePiStats/docker_ports.json /
fi
if [ -d SimplePiStats/static/custom_css ]; then
sudo mv SimplePiStats/static/custom_css /
fi
if [ -d SimplePiStats/custom_js ]; then
sudo mv SimplePiStats/custom_js /
fi
if [ -d SimplePiStats/service_icons ]; then
sudo mv SimplePiStats/service_icons /
fi
# Remove previous installation
if [ -d SimplePiStats ]; then
rm -rf SimplePiStats
fi
# Clone the latest version of the repo
echo Cloning from repo...
git clone https://github.com/purpledalek/SimplePiStats.git SimplePiStats > /dev/null 2>&1
cd SimplePiStats || return
# Install dependencies
echo Installing dependencies...
# Create Venv
python -m venv venv
# Get into venv
source venv/bin/activate
pip install -r requirements.txt > /dev/null 2>&1
# Get out of venv
deactivate
# Update service file with correct paths
echo Setting up file structure...
sed -i "s|WorkingDirectory=.*|WorkingDirectory=$(pwd)/|; s|User=.*|User=$(whoami)|; s|ExecStart=/path/to/file/|ExecStart=$(pwd)/|;" SimplePiStats.service
# Remove existing service file and directory
echo Setting up service and relocating files...
if [ -f /lib/systemd/system/SimplePiStats.service ]; then
sudo systemctl stop SimplePiStats
sudo rm -f /lib/systemd/system/SimplePiStats.service
fi
# Copying the updated service file
sudo cp SimplePiStats.service /lib/systemd/system/SimplePiStats.service
if [ -d /custom_js ]; then
sudo mv /custom_js/ .
fi
if [ -f /docker_ports.json ]; then
sudo mv /docker_ports.json .
fi
if [ -d /custom_css ]; then
sudo mv /custom_css/* ./static/custom_css/
sudo rmdir /custom_css
fi
if [ -d /service_icons ]; then
sudo mv /service_icons/* ./service_icons/
sudo rmdir /service_icons
fi
if [ -f /.checkbox_states.json ]; then
rm -rf .checkbox_states.json
sudo mv /.checkbox_states.json .
fi
if [ -f /config.ini ]; then
rm -rf config.ini
sudo mv /config.ini .
fi
# Remove unnecessary local files
echo Cleaning up...
rm non-venv_update.sh install.sh non-venv_install.sh readme.md SimplePiStats.service non-venv_SimplePiStats.service requirements.txt .gitignore
rm -rf .git
# Enable the service
sudo systemctl enable SimplePiStats
shaFromGH=$( git ls-remote https://github.com/purpledalek/SimplePiStats.git main | cut -f 1)
sed -i "1 s|lastSha=.*|lastSha=$shaFromGH|" update.sh
echo Install complete!
# (re)start the service and show logs once install complete
echo Starting service... Please wait...
sudo systemctl daemon-reload
sudo systemctl enable SimplePiStats
sudo systemctl restart SimplePiStats && timeout 10 journalctl -u SimplePiStats --since "0 seconds ago" -f --output=cat