-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathinstall.sh
executable file
·221 lines (190 loc) · 6.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
GREEN='\033[0;32m'
BLUE='\033[1;34m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
NORMAL='\033[0;39m'
PURPLE='\033[0;35m'
INSTALLATION_PATH="/opt/myspeed"
while getopts "d:" o > /dev/null 2>&1; do
# shellcheck disable=SC2220
case "${o}" in
d) INSTALLATION_PATH=${OPTARG} ;;
esac
done
if [ $EUID -ne 0 ]; then
echo -e "$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-"
echo -e "$RED✗ ABORTED"
echo -e "$NORMAL The installation is currently running via a user without root privileges. However, this is required. Please log in with a Root Account to continue."
echo -e "$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-$RED-$NORMAL-"
exit
fi
echo -e "$GREEN ---------$BLUE Automatic Installation$GREEN ---------"
echo -e "$BLUE MySpeed$YELLOW is now being installed."
if [ "$1" == "--beta" ]; then
echo -e "$YELLOW Version:$BLUE MySpeed$PURPLE Beta"
else
echo -e "$YELLOW Version:$BLUE MySpeed Release"
fi
echo -e "$YELLOW Location:$BLUE $INSTALLATION_PATH"
echo -e "$GREEN Installation will start in 5 seconds..."
echo -e "$GREEN ----------------------------------------------"
sleep 10
clear
if [ -d "$INSTALLATION_PATH" ]; then
clear
echo -e "$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-"
echo -e ""
echo -e "$YELLOW⚠ WARNING"
echo -e "$NORMAL MySpeed is already installed on this system."
echo -e ""
echo -e "$GREENℹ Info:$NORMAL Latest update will be installed..."
echo -e ""
echo -e "$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-$YELLOW-$NORMAL-"
sleep 5
fi
if command -v systemctl &> /dev/null && systemctl --all --type service | grep -n "myspeed.service"; then
clear
echo -e "$YELLOWℹ MySpeed Service is being stopped..."
systemctl stop myspeed
fi
clear
echo -e ""
echo -e "$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-"
echo -e ""
echo -e "$BLUE🔎 STATUS MESSAGE"
echo -e "$NORMAL Searching for updates for Linux system..."
echo -e ""
echo -e "$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-"
echo -e ""
apt-get update -y
clear
echo -e "$GREENℹ Info:$NORMAL Installation is now being prepared. This may take a moment..."
sleep 5
function check() {
clear
echo -e "$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-"
echo -e "$BLUE🔎 STATUS MESSAGE"
echo -e "$NORMAL Checking if $1 is present..."
echo -e "$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-$BLUE-$NORMAL-"
echo -e ""
if ! command -v "$1" &> /dev/null
then
echo -e "$YELLOWℹ \"$1\" is not installed.$NORMAL Installation will proceed..."
sleep 2
echo -e "$PURPLEℹ Installing..."
apt-get install "$1" -y
fi
}
check "wget"
check "unzip"
check "curl"
clear
echo -e "$BLUE🔎 STATUS MESSAGE"
echo -e "$NORMAL Checking if node is present..."
if ! command -v node &> /dev/null
then
echo -e "$YELLOWℹ \"node\" is not installed.$NORMAL Installation will proceed..."
sleep 2
clear
echo -e "$PURPLEℹ Downloading...$NORMAL"
curl -sSL https://deb.nodesource.com/setup_20.x | bash
clear
echo -e "$PURPLEℹ Installing...$NORMAL"
apt-get install nodejs -y
fi
clear
if [ "$1" == "--beta" ]; then
RELEASE_URL=https://github.com/gnmyt/myspeed/archive/refs/heads/development.zip
else
RELEASE_URL=$(curl -s https://api.github.com/repos/gnmyt/myspeed/releases/latest | grep browser_download_url | cut -d '"' -f 4)
fi
echo -e "$GREEN✓ Preparation completed:$NORMAL Installation of MySpeed will now commence..."
sleep 3
clear
if [ ! -d "$INSTALLATION_PATH" ]
then
clear
echo -e "$BLUEℹ Info: $NORMAL MySpeed will be installed under directory $INSTALLATION_PATH. Creating the folder now."
sleep 2
mkdir "$INSTALLATION_PATH"
fi
cd "$INSTALLATION_PATH"
clear
echo -e "$BLUEℹ Info: $NORMAL The current MySpeed instance is being downloaded. Please wait..."
sleep 2
wget "$RELEASE_URL"
echo -e "$BLUEℹ Info: $NORMAL Download completed. Unpacking..."
sleep 2
if [ "$1" == "--beta" ]; then
unzip -qo development.zip
rm -R server client docs cli
mv myspeed-*/* .
rm development.zip
rm -R myspeed-development
else
unzip -qo MySpeed*.zip
rm MySpeed-*.zip
fi
clear
echo -e "$BLUEℹ Info: $NORMAL Necessary dependencies are being installed..."
sleep 2
rm -rf "$INSTALLATION_PATH/node_modules"
npm install --force
if [ "$1" == "--beta" ]; then
clear
echo -e "$BLUEℹ Info: $NORMAL Web interface is being compiled..."
sleep 2
cd client && npm install --
force
cd .. && npm run build
cp -r client/build .
rm -rf client/build
fi
clear
echo -e "$BLUE🔎 STATUS MESSAGE"
echo -e "$NORMAL Registering MySpeed as a background service..."
echo -e ""
echo -e ""
sleep 2
if command -v systemctl &> /dev/null && ! systemctl --all --type service | grep -n "myspeed.service"; then
cat << EOF >> /etc/systemd/system/myspeed.service
[Unit]
Description=MySpeed
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/node server
Restart=always
User=root
Environment=NODE_ENV=production
WorkingDirectory=$INSTALLATION_PATH
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
echo -e "$NORMALℹ MySpeed will be added to autostart..."
sleep 1
systemctl enable myspeed
echo -e "$NORMALℹ MySpeed service is starting..."
sleep 1
systemctl start myspeed
fi
clear
if ! command -v systemctl &> /dev/null; then
echo -e "$YELLOW⚠ Warning: $NORMAL Your Linux system currently does not support starting MySpeed in the background. \"systemd\" is required for this purpose."
echo -e "$BLUEℹ Info: $NORMAL If you have installed \"systemd\", you can restart the installation. It will be set up automatically."
sleep 5
else
echo -e "$GREENℹ MySpeed is being restarted..."
sleep 2
systemctl restart myspeed
fi
clear
echo -e "$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-"
echo -e "$GREEN✓ Installation completed: $NORMAL MySpeed has been installed under $INSTALLATION_PATH."
echo -e "You can access the web interface in your browser at$BLUE http://$(curl -s ifconfig.me):5216$NORMAL."
if [ -d "$INSTALLATION_PATH" ]; then
echo -e "$BLUEℹ Info:$NORMAL If the update was not successful, please restart MySpeed:$BLUE systemctl restart myspeed"
fi
echo -e "$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-$GREEN-$NORMAL-"