This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
install-cloud.sh
290 lines (235 loc) · 7.85 KB
/
install-cloud.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
clear;
echo "#-----------------------------#"
echo "# _____ _____ __ __ #"
echo "# / ____/ ____| \/ | #"
echo "# | (___| (___ | \ / | #"
echo "# \___ \\\\___ \| |\/| | #"
echo "# ____) |___) | | | | #"
echo "# |_____/_____/|_| |_| #"
echo "#-----------------------------#"
echo "# Satisfactory Server Manager #"
echo "#-----------------------------#"
#Colors settings
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
PLATFORM="$(uname -s)"
TEMP_DIR=$(mktemp -d /tmp/XXXXX)
INSTALL_DIR="/opt/SSM"
SSM_SERVICENAME="SSM.service"
SSM_SERVICEFILE="/etc/systemd/system/SSM.service"
if [ ! "${PLATFORM}" == "Linux" ]; then
echo -e "${RED}Error: Install Script Only Works On Linux Platforms!${NC}"
exit 1
fi
function _spinner() {
# $1 start/stop
#
# on start: $2 display message
# on stop : $2 process exit status
# $3 spinner function pid (supplied from stop_spinner)
local on_success="DONE"
local on_fail="FAIL"
local white="\e[1;37m"
local green="\e[1;32m"
local red="\e[1;31m"
local nc="\e[0m"
case $1 in
start)
# calculate the column where spinner and status msg will be displayed
let column=$(tput cols)-${#2}-8
# display message and position the cursor in $column column
echo -ne ${2}
printf "%${column}s"
# start spinner
i=1
sp='\|/-'
delay=${SPINNER_DELAY:-0.15}
while :
do
printf "\b${sp:i++%${#sp}:1}"
sleep $delay
done
;;
stop)
if [[ -z ${3} ]]; then
echo "spinner is not running.."
exit 1
fi
kill $3 > /dev/null 2>&1
# inform the user uppon success or failure
echo -en "\b["
if [[ $2 -eq 0 ]]; then
echo -en "${green}${on_success}${nc}"
else
echo -en "${red}${on_fail}${nc}"
fi
echo -e "]"
;;
*)
echo "invalid argument, try {start/stop}"
exit 1
;;
esac
}
function start_spinner {
# $1 : msg to display
_spinner "start" "${1}" &
# set global spinner pid
_sp_pid=$!
disown
}
function stop_spinner {
# $1 : command exit status
_spinner "stop" $1 $_sp_pid
unset _sp_pid
}
start_spinner "${YELLOW}Updating System${NC}"
apt-get -qq update -y >/dev/null 2>&1
apt-get -qq upgrade -y >/dev/null 2>&1
stop_spinner $?
start_spinner "${YELLOW}Updating Timezone${NC}"
ln -fs /usr/share/zoneinfo/Europe/London /etc/localtime
apt-get -qq install -y tzdata >/dev/null 2>&1
dpkg-reconfigure --frontend noninteractive tzdata >/dev/null 2>&1
stop_spinner $?
start_spinner "${YELLOW}Installing Prereqs${NC}"
apt-get -qq install apt-utils curl wget jq binutils software-properties-common libcap2-bin -y >/dev/null 2>&1
apt-get -qq update -y >/dev/null 2>&1
stop_spinner $?
read -r -p "Do you want to install MongoDB? [y/N]: " response </dev/tty
case $response in
[yY]*)
start_spinner "${YELLOW}Installing MongoDB 5.0${NC}"
apt-get install gnupg > /dev/null
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - > /dev/null 2>&1
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list > /dev/null 2>&1
apt-get update > /dev/null;
apt-get install -y mongodb-org mongodb-org-shell > /dev/null;
systemctl daemon-reload > /dev/null 2>&1
systemctl enable mongod > /dev/null 2>&1
service mongod start > /dev/null 2>&1
echo -e "";
echo -e "Waiting for MongoDB to start...";
sleep 10
cat >/etc/mongosetup.js <<EOL
db.system.users.remove({});
db.system.version.remove({});
db.system.version.insert({"_id": "authSchema", "currentVersion": 3});
EOL
mongo /etc/mongosetup.js > /dev/null 2>&1
service mongod restart > /dev/null 2>&1
echo "Restarting MongoDB..."
sleep 5
cat > /etc/mongosetup_ssm.js <<EOL
db = db.getSiblingDB('ssm');
db.createUser({"user": "ssm", "pwd": "#SSMPa$£", "roles": ["readWrite", "dbAdmin"]});
EOL
mongo /etc/mongosetup_ssm.js > /dev/null 2>&1
stop_spinner $?
;;
*)
echo -e "${RED}MongoDB install skipped...${NC}"
start_spinner "${YELLOW}Installing MongoDB Tools...${NC}"
wget https://repo.mongodb.org/apt/ubuntu/dists/focal/mongodb-org/5.0/multiverse/binary-amd64/mongodb-org-database-tools-extra_5.0.6_amd64.deb > /dev/null 2>&1;
dpkg -i mongodb-org-database-tools-extra_5.0.6_amd64.deb > /dev/null 2>&1;
rm -rf mongodb-org-database-tools-extra_5.0.6_amd64.deb > /dev/null 2>&1
stop_spinner $?
;;
esac
if [ -d "${INSTALL_DIR}" ]; then
read -r -p "Do you want to update SSM? [y/N]: " response </dev/tty
case $response in
[yY]*)
;;
*)
echo -e "${RED}Update Skipped.. Exiting ${NC}"
exit 1
;;
esac
else
mkdir -p ${INSTALL_DIR} >/dev/null 2>&1
fi
SSM_SERVICE=$(
systemctl list-units --full -all | grep -Fq "${SSM_SERVICENAME}"
echo $?
)
if [ -f "${SSM_SERVICEFILE}" ]; then
if [ ${SSM_SERVICE} -eq 0 ]; then
start_spinner "${YELLOW}Stopping SSM Service${NC}"
systemctl stop ${SSM_SERVICENAME}
stop_spinner $?
fi
fi
start_spinner "${YELLOW}Downloading SSM Binaries${NC}"
curl --silent "https://api.github.com/repos/mrhid6/satisfactoryservermanager/releases/latest" >${TEMP_DIR}/SSM_releases.json
SSM_VER=$(cat ${TEMP_DIR}/SSM_releases.json | jq -r ".tag_name")
SSM_URL=$(cat ${TEMP_DIR}/SSM_releases.json | jq -r ".assets[].browser_download_url" | grep -i "Linux" | sort | head -1)
rm -r ${INSTALL_DIR}/* >/dev/null 2>&1
wget -q "${SSM_URL}" -O "${INSTALL_DIR}/SSM.tar.gz"
tar xzf "${INSTALL_DIR}/SSM.tar.gz" -C "${INSTALL_DIR}"
rm "${INSTALL_DIR}/SSM.tar.gz" >/dev/null 2>&1
rm "${INSTALL_DIR}/build.log" >/dev/null 2>&1
echo ${SSM_VER} >"${INSTALL_DIR}/version.txt"
stop_spinner $?
start_spinner "${YELLOW}Creating SSM User account${NC}"
if id "ssm" &>/dev/null; then
usermod -u 9999 ssm >/dev/null 2>&1
groupmod -g 9999 ssm >/dev/null 2>&1
chown -R ssm:ssm /home/ssm >/dev/null 2>&1
chown -R ssm:ssm /opt/SSM >/dev/null 2>&1
else
useradd -m ssm -u 9999 -s /bin/bash >/dev/null 2>&1
fi
chmod -R 777 ${INSTALL_DIR} >/dev/null 2>&1
chown -R ssm:ssm ${INSTALL_DIR} >/dev/null 2>&1
if [ -d "/SSMAgents" ]; then
chown -R ssm:ssm /SSMAgents >/dev/null 2>&1
chmod -R 755 /SSMAgents >/dev/null 2>&1
else
mkdir /SSMAgents >/dev/null 2>&1
chown -R ssm:ssm /SSMAgents >/dev/null 2>&1
chmod -R 755 /SSMAgents >/dev/null 2>&1
fi
stop_spinner $?
setcap cap_net_bind_service=+ep $(readlink -f /opt/SSM/SatisfactoryServerManager)
ENV_SYSTEMD=$(pidof systemd | wc -l)
ENV_SYSTEMCTL=$(which systemctl | wc -l)
if [[ ${ENV_SYSTEMD} -eq 0 ]] && [[ ${ENV_SYSTEMCTL} -eq 0 ]]; then
echo -e "${RED}Error: Cant install service on this system!${NC}"
exit 3
fi
if [ ${SSM_SERVICE} -eq 0 ]; then
start_spinner "${YELLOW}Removing Old SSM Service${NC}"
systemctl disable ${SSM_SERVICENAME} >/dev/null 2>&1
rm -r "${SSM_SERVICEFILE}" >/dev/null 2>&1
systemctl daemon-reload >/dev/null 2>&1
stop_spinner $?
fi
start_spinner "${YELLOW}Creating SSM Service${NC}"
cat >>${SSM_SERVICEFILE} <<EOL
[Unit]
Description=SatisfactoryServerManager Daemon
After=network.target
[Service]
User=ssm
Group=ssm
Type=simple
WorkingDirectory=/opt/SSM
ExecStart=/opt/SSM/SatisfactoryServerManager
TimeoutStopSec=20
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOL
stop_spinner $?
start_spinner "${YELLOW}Starting SSM Service${NC}"
systemctl daemon-reload >/dev/null 2>&1
systemctl enable ${SSM_SERVICENAME} >/dev/null 2>&1
systemctl start ${SSM_SERVICENAME} >/dev/null 2>&1
stop_spinner $?