-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdayzserver.sh
596 lines (526 loc) · 20.9 KB
/
dayzserver.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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#!/bin/bash
#############################################
### DayZ Standalone Linux Server script
### Original script by thelastnoc
### Modified by haywardgg
#############################################
### NO NEED TO EDIT ANYTHING IN THIS FILE ###
### Changes should be made in config.ini ###
if [ "${ansi}" != "off" ]; then
# echo colors
default="\e[0m"
red="\e[31m"
green="\e[32m"
yellow="\e[33m"
lightyellow="\e[93m"
blue="\e[34m"
lightblue="\e[94m"
magenta="\e[35m"
cyan="\e[36m"
# carriage return & erase to end of line
creeol="\r\033[K"
fi
# Define the config file path
CONFIG_FILE="config.ini"
# Default content of the config.ini file
DEFAULT_CONFIG="
# DayZ SteamID
appid=223350
dayz_id=221100
#stable=223350
#exp_branch=1042420
# Game Port (Not Steam QueryPort. Add/Change that in your serverDZ.cfg file)
port=2301
# IMPORTANT PARAMETERS
steamlogin=CHANGEME
config=serverDZ.cfg
BEpath=\"-BEpath=\${HOME}/serverfiles/battleye/\"
profiles=\"-profiles=\${HOME}/serverprofile/\"
# optional - just remove the # to enable
#logs=\"-dologs -adminlog -netlog\"
# Discord Notifications.
discord_webhook_url=\"\"
# DayZ Mods from Steam Workshop
# Edit the workshop.cfg and add one Mod Number per line.
# To enable mods, remove the # below and list the Mods like this: \"@mod1;@mod2;@spaces work\". Lowercase only.
#workshop=\"\"
# To enable serverside mods, remove the # below and list the Mods like this: \"@servermod1;@server mod2\". Lowercase only.
#servermods=\"\"
# modify carefully! server won't start if syntax is corrupt!
dayzparameter=\" -config=\${config} -port=\${port} -freezecheck \${BEpath} \${profiles} \${logs}\""
# Check if the config.ini file exists
if [ ! -f "$CONFIG_FILE" ]; then
printf "[ ${yellow}Warning${default} ] ${CONFIG_FILE} file not found.\n"
echo -e "$DEFAULT_CONFIG" > "$CONFIG_FILE"
printf "[ ${green}Fixed${default} ] Default ${lightyellow}${CONFIG_FILE}${default} created.\n"
printf "[ ${red}Important${default} ] Please edit the ${CONFIG_FILE} file before running this script again.\n"
chmod 600 "$CONFIG_FILE"
exit 1
else
printf "[ ${green}Success${default} ] Config file found. Reading values...\n"
# Source the config file to load its variables
source "$CONFIG_FILE"
printf "[ ${green}Finished${default} ] Configuration file loaded.\n"
chmod 600 "$CONFIG_FILE"
fi
# Check if steamlogin is set to CHANGEME
if [ "$steamlogin" = "CHANGEME" ]; then
printf "[ ${red}Error${default} ] Please update ${CONFIG_FILE} before running this script again.\n"
exit 1
fi
fn_checkroot_dayz(){
if [ "$(whoami)" == "root" ]; then
printf "[ ${red}FAIL${default} ] ${yellow}Do NOT run this script as root!\n"
printf "\tSwitch to the dayz user!${default}\n"
exit 1
fi
}
check_dependencies(){
missing_tools=()
tools=("tmux" "curl" "jq" "wget")
libraries=("lib32gcc-s1")
# Check executables
for tool in "${tools[@]}"; do
if ! command -v "$tool" &>/dev/null; then
missing_tools+=("$tool")
fi
done
# Check libraries
for lib in "${libraries[@]}"; do
if ! dpkg -l | grep -q "$lib"; then
missing_tools+=("$lib")
fi
done
if [ "${#missing_tools[@]}" -ne 0 ]; then
echo -e "[ ${red}ERROR${default} ] The following dependencie(s) are missing and must be installed:"
for tool in "${missing_tools[@]}"; do
echo " - $tool"
done
echo -e "[ ${yellow}INFO${default} ] Install these dependencie(s) using your package manager. For example:"
echo " sudo apt install ${missing_tools[*]} # For Debian/Ubuntu"
echo " sudo yum install ${missing_tools[*]} # For CentOS/RHEL"
echo " sudo dnf install ${missing_tools[*]} # For Fedora"
echo " sudo pacman -S ${missing_tools[*]} # For Arch"
exit 1
else
echo -e "[ ${green}OK${default} ] All required tools are installed."
fi
}
fn_checkscreen(){
if [ -n "${STY}" ]; then
printf "[ ${red}FAIL${default} ] The Script creates a tmux session when starting the server.\n"
printf "\tIt is not possible to run a tmux session inside screen session\n"
exit 1
fi
}
fn_status_dayz(){
dayzstatus=$(tmux list-sessions -F $(whoami)-tmux 2> /dev/null | grep -Ecx $(whoami)-tmux)
}
fn_clear_logs(){
# Delete *.RPT, *.log, and *.mdmp files from the profiles directory
profiles_dir="${HOME}/serverprofile" # Update this path if necessary
if [ -d "${profiles_dir}" ]; then
find "${profiles_dir}" -type f \( -name "*.RPT" -o -name "*.log" -o -name "*.mdmp" \) -delete
printf "[ ${green}DayZ${default} ] Cleared old .RPT, .log, and .mdmp files from profiles directory.\n"
fi
}
fn_start_dayz(){
fn_status_dayz
if [ "${dayzstatus}" == "1" ]; then
printf "[ ${yellow}DayZ${default} ] Server already running.\n"
exit 1
else
fn_backup_dayz
fn_update_dayz
fn_workshop_mods
fn_clear_logs
printf "[ ${green}DayZ${default} ] Starting server...\n"
sleep 0.5
sleep 0.5
cd ${HOME}/serverfiles
tmux new-session -d -x 23 -y 80 -s $(whoami)-tmux ./DayZServer $dayzparameter -mod="$workshop" -servermod="$servermods"
sleep 1
cd ${HOME}
date > ${HOME}/.dayzlockfile
fi
}
fn_stop_dayz(){
fn_status_dayz
if [ "${dayzstatus}" == "1" ]; then
printf "[ ${magenta}...${default} ] Stopping Server graceful."
# waits up to 90 seconds giving the server time to shutdown gracefuly
for seconds in {1..90}; do
fn_status_dayz
if [ "${dayzstatus}" == "0" ]; then
printf "\r[ ${green}OK${default} ] Stopping Server graceful.\n"
rm -f ${HOME}/.dayzlockfile
break
fi
printf "\r[ ${magenta}...${default} ] Stopping Server graceful: ${seconds} seconds"
tmux send-keys C-c -t $(whoami)-tmux > /dev/null 2>&1
sleep 1
done
fn_status_dayz
if [ "${dayzstatus}" != "0" ]; then
printf "\n[ ${red}FAIL${default} ] Stopping Server graceful failed. Stop Signal.\n"
sleep 2
rm -f ${HOME}/.dayzlockfile
tmux kill-session -t $(whoami)-tmux
#killall -u $(whoami)
fi
else
printf "[ ${yellow}DayZ${default} ] Server not running.\n"
fi
}
fn_restart_dayz(){
fn_stop_dayz
sleep 1
fn_start_dayz
}
fn_monitor_dayz(){
if [ ! -f ".dayzlockupdate" ]; then
fn_status_dayz
if [ "${dayzstatus}" == "0" ] && [ -f "${HOME}/.dayzlockfile" ]; then
fn_restart_dayz
elif [ "${dayzstatus}" != "0" ] && [ -f "${HOME}/.dayzlockfile" ]; then
printf "[ ${lightblue}INFO${default} ] Server should be online!\n"
else
printf "[ ${yellow}INFO${default} ] Don't use monitor to start the server. Use the start command.\n"
fi
else
printf "[ ${yellow}INFO${default} ] Serverfiles being updated\n."
fi
}
fn_console_dayz(){
printf "[${yellow} Warning ${default}] Press \"CTRL+b\" then \"d\" to exit console.\n Do NOT press CTRL+c to exit.\n\n"
sleep 0.1
while true; do
read -e -i "Y" -p "Continue? [Y/n] " -r answer
case "${answer}" in
[Yy]|[Yy][Ee][Ss]) tmux a -t $(whoami)-tmux
return 0;;
[Nn]|[Nn][Oo]) return 1 ;;
*) echo "Please answer yes or no." ;;
esac
done
}
fn_install_dayz(){
if [ ! -f "${HOME}/steamcmd/steamcmd.sh" ]; then
mkdir ${HOME}/steamcmd &> /dev/null
curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxf - -C steamcmd
printf "[ ${yellow}STEAM${default} ] Steamcmd installed\n"
else
printf "[ ${lightblue}STEAM${default} ] Steamcmd already installed\n"
fi
if [ ! -f "${HOME}/serverfiles/DayZServer" ]; then
mkdir ${HOME}/serverfiles &> /dev/null
mkdir ${HOME}/serverprofile &> /dev/null
printf "[ ${yellow}DayZ${default} ] Downloading DayZ Server-Files!\n"
fn_runvalidate_dayz
else
printf "[ ${lightblue}DayZ${default} ] The Server is already installed.\n"
fn_opt_usage
fi
}
fn_runupdate_dayz(){
${HOME}/steamcmd/steamcmd.sh +force_install_dir ${HOME}/serverfiles +login "${steamlogin}" +app_update "${appid}" +quit
}
fn_update_dayz(){
appmanifestfile=${HOME}/serverfiles/steamapps/appmanifest_"${appid}".acf
printf "[ ... ] Checking for update: SteamCMD"
# gets currentbuild
currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d \ -f3)
# Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
rm -f "${HOME}/Steam/appcache/appinfo.vdf"
sleep 1
fi
# check for new build
availablebuild=$(${HOME}/steamcmd/steamcmd.sh +login "${steamlogin}" +app_info_update 1 +app_info_print "${appid}" +app_info_print "${appid}" +quit | sed -n '/branch/,$p' | grep -m 1 buildid | tr -cd '[:digit:]')
if [ -z "${availablebuild}" ]; then
printf "\r[ ${red}FAIL${default} ] Checking for update: SteamCMD\n"
sleep 0.5
printf "\r[ ${red}FAIL${default} ] Checking for update: SteamCMD: Not returning version info\n"
exit
else
printf "\r[ ${green}OK${default} ] Checking for update: SteamCMD"
sleep 0.5
fi
# compare builds
if [ "${currentbuild}" != "${availablebuild}" ]; then
printf "\r[ ${green}OK${default} ] Checking for update: SteamCMD: Update available\n"
printf "Update available:\n"
sleep 0.5
printf "\tCurrent build: ${red}${currentbuild}${default}\n"
printf "\tAvailable build: ${green}${availablebuild}${default}\n"
printf "\thttps://steamdb.info/app/${appid}/\n"
sleep 0.5
date > ${HOME}/.dayzlockupdate
printf "\nApplying update"
for seconds in {1..3}; do
printf "."
sleep 1
done
printf "\n"
# run update
fn_status_dayz
if [ "${dayzstatus}" == "0" ]; then
fn_runupdate_dayz
fn_workshop_mods
rm -f ${HOME}/.dayzlockupdate
else
fn_stop_dayz
fn_runupdate_dayz
fn_workshop_mods
fn_start_dayz
rm -f ${HOME}/.dayzlockupdate
fi
else
printf "\r[ ${green}OK${default} ] Checking for update: SteamCMD: No update available\n"
printf "\nNo update available:\n"
printf "\tCurrent version: ${green}${currentbuild}${default}\n"
printf "\tAvailable version: ${green}${availablebuild}${default}\n"
printf "\thttps://steamdb.info/app/${appid}/\n\n"
fi
}
fn_runvalidate_dayz(){
${HOME}/steamcmd/steamcmd.sh +force_install_dir ${HOME}/serverfiles +login "${steamlogin}" +app_update "${appid}" validate +quit
}
fn_validate_dayz(){
if [ "${dayzstatus}" == "0" ]; then
fn_runvalidate_dayz
else
date > ${HOME}/.dayzlockupdate
fn_stop_dayz
fn_runvalidate_dayz
fn_workshop_mods
rm -f ${HOME}/.dayzlockupdate
fn_start_dayz
fi
}
fn_workshop_mods(){
declare -a workshopID
workshopfolder="${HOME}/serverfiles/steamapps/workshop/content/221100"
workshoplist=""
timestamp_file="${HOME}/mod_timestamps.json"
workshop_cfg="${HOME}/workshop.cfg"
# If .workshop.cfg doesn't exist, create it.
if [ ! -f "$workshop_cfg" ]; then
touch $workshop_cfg
chmod 600 ${HOME}/workshop.cfg
fi
# Read the updated workshop.cfg into workshopID array
mapfile -t workshopID < "$workshop_cfg"
# Initialize timestamp file if it doesn't exist
if [ ! -f "$timestamp_file" ]; then
echo "{}" > "$timestamp_file"
echo "Timestamp file '$timestamp_file' created."
fi
# Gather mods for download
for i in "${workshopID[@]}"; do
mod_id=$(echo "$i" | awk '{print $1}')
if [[ "$mod_id" =~ ^[0-9]+$ ]]; then
workshoplist+=" +workshop_download_item "${dayz_id}" "$mod_id""
fi
done
# Download mods
${HOME}/steamcmd/steamcmd.sh +force_install_dir ${HOME}/serverfiles +login "${steamlogin}" ${workshoplist} +quit
# Link mods and check for updates
for i in "${workshopID[@]}"; do
mod_id=$(echo "$i" | awk '{print $1}')
mod_name=$(echo "$i" | cut -d' ' -f2-)
if [[ "$mod_id" =~ ^[0-9]+$ ]] && [ -d "${workshopfolder}/$mod_id" ]; then
mod_meta_file="${workshopfolder}/$mod_id/meta.cpp"
# Ensure mod_name is accurate
if [ -f "$mod_meta_file" ]; then
actual_mod_name=$(cut -d '"' -f 2 <<< $(grep name "$mod_meta_file"))
mod_name=${actual_mod_name:-$mod_name}
fi
# Convert modname to lowercase
mod_name=$(echo "${mod_name}" | tr '[:upper:]' '[:lower:]')
# Rename main mod folder to lowercase if necessary
if [ ! -d "${HOME}/serverfiles/@${mod_name}" ]; then
mv "${HOME}/serverfiles/@$(basename "${workshopfolder}/$mod_id")" "${HOME}/serverfiles/@${mod_name}" 2>/dev/null
fi
# Create a symlink if it doesn't already exist
if [ ! -d "${HOME}/serverfiles/@${mod_name}" ]; then
ln -s ${workshopfolder}/$mod_id "${HOME}/serverfiles/@${mod_name}" &> /dev/null
fi
# Check if mod has been updated
mod_last_modified=$(date -r "$mod_meta_file" +%s 2>/dev/null || echo 0)
prev_timestamp=$(jq -r --arg mod "$mod_id" '.[$mod] // 0' "$timestamp_file")
if [ "$mod_last_modified" -gt "$prev_timestamp" ]; then
# Send Discord notification if URL is set
if [ -n "$discord_webhook_url" ]; then
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"The mod '$mod_name' (ID: $mod_id) has been updated.\"}" "$discord_webhook_url"
else
echo "Discord webhook URL is not set. Skipping notification for mod '$mod_name'."
fi
# Update timestamp file
jq --arg mod "$mod_id" --argjson time "$mod_last_modified" '.[$mod] = $time' "$timestamp_file" > "${timestamp_file}.tmp" && mv "${timestamp_file}.tmp" "$timestamp_file"
fi
fi
done
# Parse and update workshop.cfg with mod names
while IFS= read -r line; do
# Extract mod ID and name (if present)
mod_id=$(echo "$line" | awk '{print $1}')
mod_name=$(echo "$line" | cut -d' ' -f2-)
# Skip invalid lines
if [[ ! "$mod_id" =~ ^[0-9]+$ ]]; then
continue
fi
# Get mod name from meta.cpp if not present
if [[ -z "$mod_name" || "$mod_name" == "$mod_id" ]]; then
mod_meta_file="${workshopfolder}/$mod_id/meta.cpp"
if [ -f "$mod_meta_file" ]; then
mod_name=$(cut -d '"' -f 2 <<< $(grep name "$mod_meta_file"))
else
mod_name="Unknown"
fi
fi
# Save the updated line
updated_workshop_cfg+="${mod_id} ${mod_name}"$'\n'
done < "$workshop_cfg"
# Rewrite workshop.cfg if necessary
if [ -n "$updated_workshop_cfg" ]; then
echo "$updated_workshop_cfg" > "$workshop_cfg"
echo "Updated workshop.cfg with mod names."
fi
# Copy key files
if ls ${HOME}/serverfiles/@* 1> /dev/null 2>&1; then
printf "\n[ ${green}DayZ${default} ] Copying Mod Keys to Server Keys folder...\n"
for keydir in ${HOME}/serverfiles/@*/[Kk]eys/ ${HOME}/serverfiles/@*/[Kk]ey/; do
if [ -d "$keydir" ]; then
cp -vu "$keydir"* "${HOME}/serverfiles/keys/" > /dev/null 2>&1
fi
done
fi
}
fn_backup_dayz(){
fn_status_dayz
# Ensure backup directory exists
if [ ! -d "${HOME}/backup" ]; then
mkdir -p ${HOME}/backup &> /dev/null
fi
# Get the mission folder name
missionfolder=$(grep template ${HOME}/serverfiles/serverDZ.cfg | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d \ -f3)
# Format for backup files: missionfolder-Month-Day-Hour-Minute.tar
backup_file="${HOME}/backup/${missionfolder}-$(date +%m-%d-%H-%M).tar"
profile_backup_file="${HOME}/backup/serverprofile-$(date +%m-%d-%H-%M).tar"
# Create the backup of the mission folder
if [ "${dayzstatus}" == "0" ]; then
printf "[ ${green}DayZ${default} ] Creating backup of Missionfolder: ${cyan}${missionfolder}${default}\n"
tar -cf "$backup_file" -C "${HOME}/serverfiles/mpmissions" "${missionfolder}"
# Backup the serverprofile directory while excluding .log and .RPT files
printf "[ ${green}DayZ${default} ] Creating backup of Serverprofile directory: ${cyan}${HOME}/serverprofile${default}\n"
tar --exclude='*.log' --exclude='*.RPT' -cf "$profile_backup_file" -C "${HOME}" "serverprofile"
else
fn_stop_dayz
fn_start_dayz
fi
# Delete backups older than 2 days
printf "[ ${green}DayZ${default} ] Cleaning up backups older than 2 days...\n"
find "${HOME}/backup" -type f -name "${missionfolder}-*.tar" -mtime +2 -exec rm -f {} \;
find "${HOME}/backup" -type f -name "serverprofile-*.tar" -mtime +2 -exec rm -f {} \;
}
fn_wipe_dayz(){
missionfolder=$(grep template ${HOME}/serverfiles/serverDZ.cfg | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d \ -f3)
printf "[ ${red}WARNING${default} ] Wiping Players and reset Central Economy state from...\n"
for seconds in {9..0}; do
printf "\r\t Selected Mission: ${cyan}${missionfolder}${default} in ${red}"${seconds}"${default} seconds."
sleep 1
done
printf "\n"
if [ "${dayzstatus}" == "0" ]; then
rm -f ${HOME}/serverfiles/mpmissions/${missionfolder}/storage_1/players.db
rm -f ${HOME}/serverfiles/mpmissions/${missionfolder}/storage_1/data/*
printf "[ ${yellow}DayZ${default} ] Player.db and Storage-data wiped!\n"
else
fn_stop_dayz
rm -f ${HOME}/serverfiles/mpmissions/${missionfolder}/storage_1/players.db
rm -f ${HOME}/serverfiles/mpmissions/${missionfolder}/storage_1/data/*
printf "[ ${yellow}DayZ${default} ] Player.db and Storage-data wiped!\n"
sleep 0.5
fn_start_dayz
fi
}
cmd_start=( "st;start" "fn_start_dayz" "Start the server." )
cmd_stop=( "sp;stop" "fn_stop_dayz" "Stop the server." )
cmd_restart=( "r;restart" "fn_restart_dayz" "Restart the server.")
cmd_monitor=( "m;monitor" "fn_monitor_dayz" "Check server status and restart if crashed." )
cmd_console=( "c;console" "fn_console_dayz" "Access server console." )
cmd_install=( "i;install" "fn_install_dayz" "Install steamcmd and DayZ Server-Files." )
cmd_update=( "u;update" "fn_update_dayz" "Check and apply any server updates." )
cmd_validate=( "v;validate" "fn_validate_dayz" "Validate server files with SteamCMD." )
cmd_workshop=( "ws;workshop" "fn_workshop_mods" "Download Mods from Steam Workshop." )
cmd_backup=( "b;backup" "fn_backup_dayz" "Create backup archives of the server (mpmission)." )
cmd_wipe=( "wi;wipe" "fn_wipe_dayz" "Wipe your server data (Player and Storage)." )
### Set specific opt here ###
currentopt=( "${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_console[@]}" "${cmd_install[@]}" "${cmd_update[@]}" "${cmd_validate[@]}" "${cmd_workshop[@]}" "${cmd_backup[@]}" "${cmd_wipe[@]}" )
### Build list of available commands
optcommands=()
index="0"
for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
cmdamount="$(echo "${currentopt[index]}" | awk -F ';' '{ print NF }')"
for ((cmdindex=1; cmdindex <= ${cmdamount}; cmdindex++)); do
optcommands+=( "$(echo "${currentopt[index]}" | awk -F ';' -v x=${cmdindex} '{ print $x }')" )
done
done
# Shows LinuxGSM usage
fn_opt_usage(){
printf "\nDayZ - Linux Game Server"
printf "\nUsage:${lightblue} $0 [command]${default}\n\n"
printf "${lightyellow}Commands${default}\n"
# Display available commands
index="0"
{
for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
# Hide developer commands
if [ "${currentopt[index+2]}" != "DEVCOMMAND" ]; then
echo -e "${cyan}$(echo "${currentopt[index]}" | awk -F ';' '{ print $2 }')\t${default}$(echo "${currentopt[index]}" | awk -F ';' '{ print $1 }')\t|${currentopt[index+2]}"
fi
done
} | column -s $'\t' -t
exit 1
}
# start functions
fn_checkroot_dayz
check_dependencies
fn_checkscreen
getopt=$1
if [ ! -f "${HOME}/steamcmd/steamcmd.sh" ] || [ ! -f "${HOME}/serverfiles/DayZServer" ] && [ "${getopt}" != "cfg" ]; then
printf "[ ${yellow}INFO${default} ] No installed steamcmd and/or serverfiles found!\n"
chmod u+x ${HOME}/dayzserver
fn_install_dayz
if [ -f "${HOME}/steamcmd/steamcmd.sh" ] && [ -f "${HOME}/serverfiles/DayZServer" ]; then
fn_opt_usage
fi
exit
else
### Check if user commands exist and run corresponding scripts, or display script usage
if [ -z "${getopt}" ]; then
fn_opt_usage
fi
fi
# Command exists
for i in "${optcommands[@]}"; do
if [ "${i}" == "${getopt}" ] ; then
# Seek and run command
index="0"
for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
currcmdamount="$(echo "${currentopt[index]}" | awk -F ';' '{ print NF }')"
for ((currcmdindex=1; currcmdindex <= ${currcmdamount}; currcmdindex++)); do
if [ "$(echo "${currentopt[index]}" | awk -F ';' -v x=${currcmdindex} '{ print $x }')" == "${getopt}" ]; then
# Run command
eval "${currentopt[index+1]}"
exit 1
break
fi
done
done
fi
done
# If we're executing this, it means command was not found
echo -e "${red}Unknown command${default}: $0 ${getopt}"
fn_opt_usage