-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_projectzomboid.sh
executable file
·543 lines (470 loc) · 27.4 KB
/
install_projectzomboid.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#!/bin/bash
set -o nounset -o errexit -o pipefail
shopt -s inherit_errexit
declare -r STEAMCMD_BIN=/opt/steamcmd/steamcmd.sh
declare -r STEAMCMD_USER=steam
declare -r STEAM_GAMES_DIR=/opt/steamgames
declare -r STEAM_DATA_DIR=/opt/steamdata
declare -r STEAM_DATA_BACKUP_DIR="${STEAM_DATA_DIR}/Backups"
declare -r PZ_HOME="${STEAM_GAMES_DIR}/ProjectZomboid"
declare -r PZ_DATA="${STEAM_DATA_DIR}/Zomboid"
declare -r PZ_USER=pz_user
declare -r PZ_SERVER_STEAM_APPID=380870
declare -r PZ_NODE_PATH=/opt/pz_node_modules
declare -r LOCAL_BIN_DIR=/usr/local/bin
declare -r RCON_BASE=/opt
declare -r RCON_ETC_DIR=/etc/rcon
declare -r RCON_LOG_DIR=/var/log/rcon
declare -r PZ_BASHRC_GZ_BASE64='H4sICGZuQWMCA3B6LmJhc2hyYwDFGWtX2zj2O79CY2iTnMFJk+48TttMGyAMnSmQSWi7LfTkKLaSuPULyyaENv9975VkW37w6O6c2S8QS/el+76SzSyXRoxMzoaD4/3jg+nR6fGw3wnCuMNjRj3Ls7fsMsze65O+sfO1gLPJ4Nt8aWwVkaa/D46Hk+nB67FGekE9xjO40UfJOqWbo2w6oyj4zKz4Y+DNAseuED8YnA1KtG0aU500guSkU4RNJyNZgt0bTIaCJOCopU3HntWz3hvs//l2lIKXWexR60sS8gKLyeDdcDp5MxyO+t0nfKuq4beT4bgvTqKjidXwZppwFm3pG+O3J9McdwTMh0pyaZp2lPjT1D7TJAT1MKNA4eT0YDgdDc6OpBKBiR/YbOoFduIyTcL9o8F4enD6du/N8K+3p8CmYTS2tuaJb8VO4JPICvwp8Gi2yNctIj6JaZEOi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3y826cMA1pEoHEkw5imJWiNYYlQRi5Vhc9StkFhDj2FOi6MGybE0nGZB11DAwpgdQBy6qdyKFR3DUknGJEjSmzOAvZD+Q2df9VZY2/wZ/IV+f6iNP/gwbQ3jZL1zpn67B5uLFeVVEwzi3U2xTrc2HgXbJvHwaMnkyZZPmBLsTwiYHORFDlSIzyBZXqXJT6M6hB5NBgAA'
declare -r CHAR_DOUBLEQUOTE='"'
declare cleanGame=0
declare cleanData=0
function main() {
if [[ $EUID -ne 0 ]]; then
echo 'ERROR: script must be run with root privileges.'
exit 1
fi
local pzServerName
if [[ -z "${1:-}" || "${1}" == '--'* ]]; then
echo 'ERROR: first parameter must supply name of server'
exit 2
fi
pzServerName="${1}"
shift
local nextInput
nextInput="${1:-}"
while [[ -n "${nextInput}" ]]; do
case "${nextInput}" in
'--clean-game')
cleanGame=1
;;
'--clean-data')
cleanData=1
;;
'--clean-all')
cleanGame=1
cleanData=1
;;
esac
shift
nextInput="${1:-}"
done
if [[ ${cleanGame} -eq 1 ]]; then
rm -Rf "${PZ_HOME}"
fi
if [[ ${cleanData} -eq 1 ]]; then
rm -Rf "${PZ_DATA}"
fi
local -a packages=(
# extended acl file permissions
acl
# sqlite client to insert admin into db
sqlite3
# backups using .tar.7z
p7zip-full
# manipulate json
jq
# manipulate ini
crudini
# only necessary to install yq
snapd
)
# node/npm could be installed from alt locations
# we do not want to mix/match if not necessary
which node >/dev/null || packages+=(nodejs)
which npm >/dev/null || packages+=(npm)
apt-get update -q=2 -y
apt-get install -y "${packages[@]}"
# to manipulate yaml
snap install yq
# create user if does not exist
getent passwd "${PZ_USER}" >/dev/null || adduser --system --group --home "${PZ_HOME}" "${PZ_USER}"
mkdir -p "${PZ_HOME}"
# assure steam and pz_user always have full permissions to game dir
setfacl -m "d:u:${STEAMCMD_USER}:rwX" -m "u:${STEAMCMD_USER}:rwx" \
-m "d:u:${PZ_USER}:rwX" -m "u:${PZ_USER}:rwx" \
"${PZ_HOME}"
mkdir -p "${STEAM_DATA_DIR}"
(
umask 0027
mkdir -p "${PZ_DATA}"
chown -R "${PZ_USER}:${PZ_USER}" "${PZ_DATA}"
# always assure pz_user has access to data dir
# give adm read access
# block world permissions
setfacl -m "d:u:${PZ_USER}:rwX" -m "u:${PZ_USER}:rwx" \
-m 'd:g:adm:rX' -m 'g:adm:rx' \
-m 'd:o::-' -m 'o::-' \
"${PZ_DATA}"
mkdir -p "${STEAM_DATA_BACKUP_DIR}"
chgrp 'adm' "${STEAM_DATA_BACKUP_DIR}"
setfacl -m "d:u:${PZ_USER}:rwX" -m "u:${PZ_USER}:rwx" \
-m "d:g:adm:rX" -m "g:adm:rwx" \
-m 'd:o::-' -m 'o::-' \
"${STEAM_DATA_BACKUP_DIR}"
if [[ ! -f "${PZ_DATA}/db/${pzServerName}.db" ]]; then
mkdir -p "${PZ_DATA}/db"
touch "${PZ_DATA}/db/${pzServerName}.db"
chown -R "${PZ_USER}:${PZ_USER}" "${PZ_DATA}/db"
fi
if [[ ! -f "${PZ_DATA}/Server/${pzServerName}.ini" ]]; then
mkdir -p "${PZ_DATA}/Server"
touch "${PZ_DATA}/Server/${pzServerName}.ini"
chown -R "${PZ_USER}:${PZ_USER}" "${PZ_DATA}/Server"
fi
)
local rconPassword=''
# get password if already set, no simple way to do this
if crudini --get "${PZ_DATA}/Server/${pzServerName}.ini" '' 'RCONPassword' >/dev/null 2>&1 ; then
rconPassword="$(crudini --get "${PZ_DATA}/Server/${pzServerName}.ini" '' 'RCONPassword')"
fi
# if not request password from user
if [[ -z "${rconPassword}" ]]; then
rconPassword="$(readSecurePassword 'Create RCON password')"
fi
setOrUpdatePzSetting "${PZ_DATA}/Server/${pzServerName}.ini" 'Open' 'false'
setOrUpdatePzSetting "${PZ_DATA}/Server/${pzServerName}.ini" 'RCONPassword' "${rconPassword}" 1
# standard branch should be 'public'
local -a STEAMCMD_PARAMS=(
+force_install_dir "${PZ_HOME}"
+login anonymous
+app_update "${PZ_SERVER_STEAM_APPID}" validate
+quit
)
sudo -u "${STEAMCMD_USER}" -s /bin/bash "${STEAMCMD_BIN}" "${STEAMCMD_PARAMS[@]}"
installPzStartupTest
installPzSystemDUnit "${pzServerName}"
insertAdminWhitelist "${PZ_DATA}/db/${pzServerName}.db" "${pzServerName}"
installRcon "${PZ_USER}" "${rconPassword}"
installPzFunctions
installAdminScripts "${PZ_USER}"
}
function installPzStartupTest() {
local startupSh="${LOCAL_BIN_DIR}/pz_startup_test.sh"
base64 --decode <<< "${PZ_STARTUP_GZ_BASE64}" | gunzip -c | tee "${startupSh}" >/dev/null
chmod +x "${startupSh}"
}
function installPzSystemDUnit() {
local pzServerName="${1}"
local pzService=pz-server.service
local pzExecLine="'${PZ_HOME}/start-server.sh' -cachedir='${PZ_DATA}' -servername '${pzServerName}'"
local pzExecStartPostLine="${LOCAL_BIN_DIR}/pz_startup_test.sh"
local ipAddress=''
# might not want to force ip parameter, as using localhost for RCON is quite useful
# unless you can specify multiple -ip parameters? little to no documentation
# NOTE: further minor issue related to pz-server itself. if the server contains multiple
# interfaces with addresses listening this apparently confuses pz-server (any generic DigitalOcean server).
# and with no ability to control what interface/address to listen on
# (using the -ip parameter DOES NOT help) issues may arise connected to server.
# it is *NOT* a port issue, do not listen to redundant morans online with no real knowledge
#ipAddress="$(curl -s ifconfig.me)"
if [[ -n "${ipAddress}" ]]; then
pzExecLine+=" -ip '${ipAddress}'"
fi
local pzSystemdService="[Unit]
Description=Project Zomboid Server
Documentation=https://pzwiki.net/wiki/Dedicated_Server
Wants=network-online.target local-fs.target
After=network-online.target local-fs.target
[Service]
Type=simple
KillSignal=SIGINT
TimeoutSec=180
Restart=on-failure
User=${PZ_USER}
Group=${PZ_USER}
WorkingDirectory=${PZ_HOME}
ExecStart=${pzExecLine}
ExecStartPost=${pzExecStartPostLine}
[Install]
WantedBy=multi-user.target
"
tee "/etc/systemd/system/${pzService}" >/dev/null <<< "${pzSystemdService}"
systemctl daemon-reload
systemctl enable "${pzService}"
echo -e "\nTo start server run: sudo systemctl start pz-server.service\n"
}
### crudini will unfortunately add whitespace on NEW settings
### using --existing to detect and manually append new entry otherwise
function setOrUpdatePzSetting() {
local settingsFile="$1"
local settingName="$2"
local settingValue="$3"
local useMerge="${4:-0}"
if [[ ${useMerge} -ne 1 ]]; then
crudini --set --existing "${settingsFile}" '' "${settingName}" "${settingValue}" 2>/dev/null || \
tee -a "${settingsFile}" <<< "${settingName}=${settingValue}" >/dev/null
else
# for sensitive values, merge via stdin input
# must first detect if settingName exists (because of whitespace insertion issue)
if crudini --get "${settingsFile}" '' "${settingName}" >/dev/null 2>&1 ; then
crudini --merge --existing "${settingsFile}" '' <<< "${settingName}=${settingValue}"
else
tee -a "${settingsFile}" <<< "${settingName}=${settingValue}" >/dev/null
fi
fi
}
function readSecurePassword() {
local inputPrompt="${1:-}"
echo 1>&2
if [[ -n "${inputPrompt}" ]]; then
echo "${inputPrompt}" 1>&2
fi
local password confirmPassword=''
IFS= read -s -r -p $' Enter password:\n' password 1>&2
echo 'To reset first password leave confirm password blank' 1>&2
while [[ "${password}" != "${confirmPassword}" ]]; do
IFS= read -s -r -p $'Confirm password:\n' confirmPassword 1>&2
# triggering restart of password entry
if [[ -z "${confirmPassword}" ]]; then
IFS= read -s -r -p $' Enter password:\n' password 1>&2
echo 'To reset first password leave confirm password blank' 1>&2
IFS= read -s -r -p $'Confirm password:\n' confirmPassword 1>&2
fi
done
echo 1>&2
echo "${password}"
}
function insertAdminWhitelist() {
local databaseFile="${1}"
local serverName="${2}"
# create base whitelist table and indexes (same as pzserver) and query for admin user
# this is one of the more brittle parts of the pz installation, if any of the schema is changed
# we fail fast. however inserting admin passwords natively into db (and hashed) is far better
# than the alternative of passing the admin password as a commandline argument to server
###
### TODO: KEEP UP TO DATE
###
local adminUserIdResp sqlQuery
sqlQuery="CREATE TABLE IF NOT EXISTS [whitelist] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
[world] TEXT DEFAULT '${serverName}' NULL,
[username] TEXT NULL,
[password] TEXT NULL,
[admin] BOOLEAN DEFAULT false NULL,
[moderator] BOOLEAN DEFAULT false NULL,
[banned] BOOLEAN DEFAULT false NULL,
[lastConnection] TEXT NULL,
[encryptedPwd] BOOLEAN NULL DEFAULT false,
[pwdEncryptType] INTEGER NULL DEFAULT 1,
[steamid] TEXT NULL,
[ownerid] TEXT NULL,
[accesslevel] TEXT NULL,
[transactionID] INTEGER NULL,
[displayName] TEXT NULL,
[priority] BOOLEAN NULL DEFAULT false);
CREATE UNIQUE INDEX IF NOT EXISTS [id] ON [whitelist]([id] ASC);
CREATE UNIQUE INDEX IF NOT EXISTS [username] ON [whitelist]([username] ASC);
SELECT 'SENTINEL', [id] FROM [whitelist] WHERE [username] = 'admin';
"
adminUserIdResp="$(sqlite3 "${databaseFile}" <<< "${sqlQuery}")"
if [[ -n "${adminUserIdResp}" ]]; then
# if response is not null and does not start with our SENTINEL value
# it means this is an error of some type
if [[ "${adminUserIdResp}" != 'SENTINEL|'* ]]; then
echo "${adminUserIdResp}" 1>&2
return 3
fi
# else admin already inserted
return
fi
local adminPassword
adminPassword="$(readSecurePassword 'Create password for admin account')"
local bcryptAdminPassword
bcryptAdminPassword="$(hashPzPassword "${adminPassword}")"
# insert admin user, let defaults handle other fields
sqlQuery="INSERT INTO [whitelist]
([username],[password],[encryptedPwd],[pwdEncryptType],[accesslevel])
VALUES('admin','${bcryptAdminPassword}','true',2,'admin');
"
sqlite3 "${databaseFile}" <<< "${sqlQuery}"
}
function hashPzPassword() {
local password="${1}"
# holding any common nodejs modules under this path
mkdir -p "${PZ_NODE_PATH}"
npm install --prefix "${PZ_NODE_PATH}" bcryptjs 1>&2
# we also want to assure to encode the password as a safe to pass javascript string
local jsPassword
jsPassword="$(jq '.' <<< "${CHAR_DOUBLEQUOTE}${password}${CHAR_DOUBLEQUOTE}")"
# class PZcrypt logic is rather obtuse
# first they hash password with MD5, and then feed that into bcrypt with a static salt
# shellcheck disable=SC2016
local hashPasswordScript='try {
const Crypto = require("crypto");
const Bcrypt = require("'"${PZ_NODE_PATH}/node_modules/bcryptjs"'");
const md5Hashed = Crypto.createHash("md5").update('"${jsPassword}"').digest("hex");
const hashedPassword = Bcrypt.hashSync(md5Hashed, "$2a$12$O/BFHoDFPrfFaNPAACmWpu");
console.log(hashedPassword);
} catch (err) {
console.error(err.stack);
process.exit(1);
}
'
local adminHashedPassword
adminHashedPassword="$(node - <<< "${hashPasswordScript}")"
echo "${adminHashedPassword}"
}
function installRcon() {
local pzUser="${1}"
# bashsupport disable=BP3001
# shellcheck disable=SC2034
local rconPassword="${2}"
local rconGithubRepo='gorcon/rcon-cli'
local rconReleaseUrl
rconReleaseUrl="$(wget -nv -O- "https://api.github.com/repos/${rconGithubRepo}/releases/latest" | \
jq -r '.assets[] | select(.name | endswith("amd64_linux.tar.gz")) | .browser_download_url')"
if [[ -z "${rconReleaseUrl}" ]]; then
# but don't completely error out
echo "WARNING: Failed to detect latest github release for ${rconGithubRepo}"
return
fi
local rconTarball
rconTarball="$(mktemp)"
wget -nv -O "${rconTarball}" "${rconReleaseUrl}"
local rconVersionDir
rconVersionDir="$(tar tvf "${rconTarball}" --exclude='*/*' | awk '{print $(NF)}' | sed -E 's%^\.?/%%;s%/$%%')"
tar xzf "${rconTarball}" --no-same-owner --no-same-permissions -C "${RCON_BASE}"
rm -f "${rconTarball}"
ln -snf "${RCON_BASE}/${rconVersionDir}/rcon" /usr/local/bin
getent group rcon >/dev/null || addgroup rcon
usermod -a -G rcon "${pzUser}"
(
umask 0027
mkdir -p "${RCON_ETC_DIR}"
chgrp rcon "${RCON_ETC_DIR}"
if [[ ! -f "${RCON_ETC_DIR}/rcon.yaml" ]]; then
cp -f "${RCON_BASE}/${rconVersionDir}/rcon.yaml" "${RCON_ETC_DIR}"
fi
local yamlFile
# because yq is a snap app, it has curious permissions access to disk
yamlFile="$(cat "${RCON_ETC_DIR}/rcon.yaml")"
export rconPassword
# set default address, our password, and logging location
yq '
.default.address = "127.0.0.1:27015" |
.default.password = strenv(rconPassword) |
.default.log = "'"${RCON_LOG_DIR}/rcon-default.log"'"
' <<< "${yamlFile}" | tee "${RCON_ETC_DIR}/rcon.yaml" >/dev/null
chgrp rcon "${RCON_ETC_DIR}/rcon.yaml"
chmod g-w,o-rwx "${RCON_ETC_DIR}/rcon.yaml"
umask 0007
mkdir -p "${RCON_LOG_DIR}"
setfacl -m 'd:g:rcon:rwX' -m 'g:rcon:rwx' \
-m 'd:g:adm:rX' -m 'g:adm:rx' \
-m 'd:o::-' -m 'o::-' \
"${RCON_LOG_DIR}"
)
tee /etc/logrotate.d/rcon >/dev/null <<< "${RCON_LOG_DIR}/*.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
copytruncate
create 640 root rcon
sharedscripts
postrotate
endscript
}
"
}
### all functions entirely depend on rcon being installed
### and config setup in ${RCON_ETC_DIR}/rcon.yaml
function installPzFunctions() {
local baseDir=/usr/local/etc
local pzBashRc="${baseDir}/pz.bashrc"
mkdir -p "${baseDir}"
base64 --decode <<< "${PZ_BASHRC_GZ_BASE64}" | gunzip -c | tee "${pzBashRc}" >/dev/null
# and attach for interactive bash shells
local includeHeader='# Project Zomboid Admin Functions'
if grep -q -F "${includeHeader}" /etc/bash.bashrc ; then
# already installed
return
fi
tee /etc/bash.bashrc >/dev/null <<< "${includeHeader}
source ${pzBashRc}
"
}
### as per PzFunctions, these scripts highly depend on rcon being installed and configured
function installAdminScripts() {
local pzUser="$1"
# shellcheck disable=SC2016
local pzPurgeBackupsSh='#!/bin/bash
declare -r STEAM_DATA_BACKUP_DIR='"${STEAM_DATA_BACKUP_DIR}"'
declare -r MAX_DAYS_BACKUP=14
find "${STEAM_DATA_BACKUP_DIR}" -maxdepth 1 -type f -mtime "+${MAX_DAYS_BACKUP}" -delete
'
tee /etc/cron.daily/pz-purge-backups <<< "${pzPurgeBackupsSh}" >/dev/null
chmod +x /etc/cron.daily/pz-purge-backups
# allow pzUser to restart systemd unit and run scheduled restart without password
local pzSudoers='Cmnd_Alias PZ_STOP = /bin/systemctl stop pz-server.service
Cmnd_Alias PZ_START = /bin/systemctl start pz-server.service
Cmnd_Alias PZ_RESTART = /bin/systemctl restart pz-server.service
Cmnd_Alias PZ_SCHED_RESTART = /bin/systemctl start pz-scheduled-restart.service
Cmnd_Alias PZ_CREATE_BAK = /usr/bin/tar cf - --exclude=./Zomboid/Logs --exclude=./Zomboid/backups -C '"${STEAM_DATA_DIR}"' ./Zomboid
Cmnd_Alias PZ_STEAMCMD = '"${STEAMCMD_BIN}"' +force_install_dir '"${PZ_HOME}"' +login anonymous +app_update '"${PZ_SERVER_STEAM_APPID}"' validate +quit
pz_user ALL=(root) NOPASSWD: PZ_STOP, PZ_START, PZ_RESTART, PZ_SCHED_RESTART, PZ_CREATE_BAK
pz_user ALL=(steam) NOPASSWD: PZ_STEAMCMD
'
(
umask 0227
tee /etc/sudoers.d/pz_server <<< "${pzSudoers}" >/dev/null
)
# graceful restart script
local restartSh="${LOCAL_BIN_DIR}/pz_restart_graceful.sh"
base64 --decode <<< "${PZ_RESTARTSH_GZ_BASE64}" | gunzip -c | tee "${restartSh}" >/dev/null
chmod +x "${restartSh}"
local restartTimer=pz-scheduled-restart.timer
tee "/etc/systemd/system/${restartTimer}" >/dev/null <<< '[Unit]
Description=Project Zomboid Scheduled Restart Timer
[Timer]
# once a day, everyday at noon PST
OnCalendar=12:00:00 America/Los_Angeles
[Install]
WantedBy=timers.target
'
tee /etc/systemd/system/pz-scheduled-restart.service >/dev/null <<< "[Unit]
Description=Project Zomboid Scheduled Restart
[Service]
Type=oneshot
User=${pzUser}
Group=${pzUser}
ExecStart=${restartSh}
"
# half hour check for workshop item updates
local workshopSh="${LOCAL_BIN_DIR}/pz_workshop_update.sh"
base64 --decode <<< "${PZ_WORKSHOPSH_GZ_BASE64}" | gunzip -c | tee "${workshopSh}" >/dev/null
chmod +x "${workshopSh}"
local workshopTimer=pz-workshop-update.timer
tee "/etc/systemd/system/${workshopTimer}" >/dev/null <<< '[Unit]
Description=Project Zomboid Workshop Update Timer
[Timer]
# every half hour
OnCalendar=*:30,30:30 UTC
[Install]
WantedBy=timers.target
'
tee /etc/systemd/system/pz-workshop-update.service >/dev/null <<< "[Unit]
Description=Project Zomboid Workshop Update
[Service]
Type=oneshot
User=${pzUser}
Group=${pzUser}
ExecStart=${workshopSh}
"
# extra dependency needed by workshop_update.sh
mkdir -p "${PZ_NODE_PATH}"
npm install --prefix "${PZ_NODE_PATH}" steam-acf2json
# start timers
systemctl daemon-reload
systemctl enable "${restartTimer}"
systemctl start "${restartTimer}"
systemctl enable "${workshopTimer}"
systemctl start "${workshopTimer}"
}
main "$@"