-
Notifications
You must be signed in to change notification settings - Fork 0
/
DayZ_Mod_Launcher.sh
540 lines (474 loc) · 14 KB
/
DayZ_Mod_Launcher.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
#!/usr/bin/env bash
#####################################################################################################################################
### DAYZ MOD LAUNCHER ###
#####################################################################################################################################
startmenu() {
unset number
until [[ $number == +([1-2]) ]] ; do
read -s -n1 -p $'
\e[1;40m
\e[92m Select:\n
\e[92m 1) Normal Mod Setup\n
\e[92m 2) Fixed Mod Setup
\e[0m\n' number
done
case ${number} in
######################################################
#### Normal Mod Setup Start ##########################
######################################################
[1] )
echo ""
echo -e "\e[1;40m\n
\e[1;33m Server Info can be found at \e[1;36m https://www.battlemetrics.com/servers/dayz/
\e[0m"
sleep 0.5
echo ""
ppath=/home/$USER/
echo -e "\e[1;40m\n
\e[92m Enter IP-Address:Port
\e[0m"
sleep 0.5
read SSERVER
sleep 0.5
echo -e "\e[1;40m\n
\e[92m Enter Query Port Number
\e[0m"
sleep 0.5
read PPORT
sleep 0.5
echo -e "\e[1;40m\n
\e[92m Enter Username
\e[0m"
sleep 0.5
read NNAME
sleep 0.5;;
######################################################
#### Normal Mod Setup End ############################
######################################################
######################################################
#### Static Mod Setup Start ##########################
######################################################
[2] )
# Replace this server info with your server info..
echo ""
SSERVER=65.109.89.237:2502 # IP-Adress:Port
PPORT=27018 # Query Port
NNAME=ice # Username
ppath=/home/$USER/
#echo -e "\e[1;44m\n
#\e[30m IP-Address:Port: $SSERVER
#\e[30m Query Port: $PPORT
#\e[30m Username: $NNAME
#\e[0m";
sleep 0.1;;
esac
}
######################################################
#### Static Mod Setup End ############################
######################################################
set -eo pipefail
SELF=$(basename "$(readlink -f "${0}")")
DAYZ_ID=221100
DEFAULT_GAMEPORT=2302
DEFAULT_QUERYPORT=27016
API_URL="https://dayzsalauncher.com/api/v1/query/@ADDRESS@/@PPORT@"
API_PARAMS=(
-sSL
-m 10
-H "User-Agent: $USER"
)
WORKSHOP_URL="https://steamcommunity.com/sharedfiles/filedetails/SubscribeItem/?id=@ID@"
SSERVER=""
PPORT="${DEFAULT_QUERYPORT}"
DEBUG=0
LAUNCH=0
STEAM=""
SERVER=""
PORT="${DEFAULT_QUERYPORT}"
NAME=""
NNAME=""
INPUT=()
MODS=()
MODS2=()
PARAMS=()
IP=()
PORT=()
SDIR=/home/jones/.steam/debian-installation/steamapps/workshop/downloads/
declare -A DEPS=(
[gawk]="required for mod metadata. Try: sudo apt install gawk"
[curl]="required for the server API. Try: sudo apt install curl"
[jq]="required for the server API's JSON response. Try: sudo apt install jq"
)
while (( "$#" )); do
case "${1}" in
-h|--help)
print_help
exit
;;
-d|--debug)
DEBUG=1
;;
--steam)
STEAM="${2}"
shift
;;
-l|--launch)
LAUNCH=1
;;
-s|--server)
SERVER="${2}"
[[ "${SERVER}" = *:* ]] || SERVER="${SERVER}:${DEFAULT_GAMEPORT}"
shift
;;
-p|--port)
PORT="${2}"
shift
;;
-n|--name)
NAME="${2}"
shift
;;
--)
shift
PARAMS+=("${@}")
LAUNCH=1
break
;;
*)
INPUT+=("${1}")
;;
esac
shift
done
err() {
echo -e >&2 "[\e[1;31m${SELF}][error] ${@}"
exit 1
}
msg() {
echo "[${SELF}][info] ${@}"
}
debug() {
if [[ ${DEBUG} == 1 ]]; then
echo "[${SELF}][debug] ${@}"
fi
}
check_dir() {
debug "Checking directory: ${1}"
if [ ! -d "${1}" ] ; then
mkdir "/home/$USER/.steam/debian-installation/steamapps/workshop/content/221100"
fi
}
check_dep() {
command -v "${1}" >/dev/null 2>&1
}
check_deps() {
for dep in "${!DEPS[@]}"; do
check_dep "${dep}" || err "'${dep}' not installed (${DEPS["${dep}"]})"
done
}
dec2base64() {
echo "$1" \
| LC_ALL=C gawk '
{
do {
printf "%c", and($1, 255)
$1 = rshift($1, 8)
} while ($1 > 0)
}
' \
| base64 \
| sed 's|/|-|g; s|+|_|g; s|=||g'
}
resolve_steam() {
if [[ -n "${STEAM}" ]]; then
check_dep "${STEAM}" || err "Could not find the '${STEAM}' executable"
fi
if check_dep steam; then
STEAM=steam
fi
}
query_server_api() {
[[ -z "${SSERVER}" ]] && return
local query
local response
echo ""
echo -e "\e[1;40m\n
\e[32m Server IP : $SSERVER
\e[32m Query Port : $PPORT
\e[32m UserName : $NNAME
\e[0m"
query="$(sed -e "s/@ADDRESS@/${SSERVER%:*}/" -e "s/@PPORT@/${PPORT}/" <<< "${API_URL}")"
debug "Querying ${query}"
response="$(curl "${API_PARAMS[@]}" "${query}")"
debug "Parsing API response"
jq -e '.result.mods | select(type == "array")' >/dev/null 2>&1 <<< "${response}" || err "Missing data from API response. Try again in a few seconds"
jq -e '.result.mods[]' >/dev/null 2>&1 <<< "${response}" || { echo ""; echo ""; echo -e "\e[1;36m This is a Vanilla Server.\e[0m"; echo ""; echo ""; read -p $'\e[36m Press ENTER to launch Vanilla DayZ.' foo; echo ""; echo ""; echo "Starting DayZ.. Please Wait.."; echo ""; echo ""; steam -applaunch 221100 -connect=${SSERVER} --PPORT ${PPORT} -name=${NNAME} -nolauncher -world=empty; exit; }
INPUT+=( $(jq -r ".result.mods[] | .steamWorkshopId" <<< "${response}") )
}
mainmenu(){
sleep 0.25
if [ -f "/home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_221100.acf" ] ; then
rm /home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_221100.acf
fi
sleep 0.25
if [ -f "/home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_241100.acf" ] ; then
rm /home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_241100.acf
fi
sleep 0.25
missing=0
unset number
until [[ $number == +([1-4]) ]] ; do
read -s -n1 -p $'
\e[1;40m\n
\e[1;92m 1) Join Server\n
\e[1;92m 2) Mods Menu\n
\e[1;92m 3) Save Menu\n
\e[1;92m 4) Quit
\e[0m\n' number
done
case $number in
[1])
echo ""
echo -e "\e[1;40m\n
\e[1;48m Checking Server Mods ..
\e[0m"
sleep 0.25
rm -rf /home/$USER/.steam/debian-installation/steamapps/workshop/content/downloads/*
rm -r -f /home/$USER/.steam/debian-installation/steamapps/common/DayZ/@*
sleep 0.1;;
[2])
submenu1
;;
[3])
submenu2
;;
[4])
exit
;;
*)
echo "invalid answer, please try again"
;;
esac
}
submenu1(){
unset number
until [[ $number == +([1-4]) ]] ; do
read -s -n1 -p $'
\e[1;40m\n
\e[1;92m 1) Verify Mods\n
\e[1;92m 2) Remove Mods Used By This Server\n
\e[1;92m 3) Remove All Mods\n
\e[1;92m 4) Back
\e[0m\n' number
done
case $number in
"1") ######################################################################################
read -p $'\e[1;40m\n
\e[31m Press Enter to Verify Mods for this Server.
\e[0m\n' foo
sleep 0.25
for modid in "${INPUT[@]}"; do
rm -rf /home/$USER/.steam/debian-installation/steamapps/workshop/content/221100/${modid}
rm -r -f /home/$USER/.steam/debian-installation/steamapps/common/DayZ/@*
continue
done
sleep 0.1
rm -rf /home/$USER/.steam/debian-installation/steamapps/workshop/content/downloads/*
sleep 0.1
rm -r -f /home/$USER/.steam/debian-installation/steamapps/common/DayZ/@*
sleep 0.1
if [ -f "/home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_221100.acf" ] ; then
rm /home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_221100.acf
fi
sleep 0.1;;
"2") ######################################################################################
unset mods2
for modid in "${INPUT[@]}"; do
local modpath2="${dir_workshop}/${modid}"
local namelink="${modid}"
MODS2+=("${namelink}")
local mods2="$(IFS=";" echo "${MODS2[*]}")"
done
read -p $'\e[1;40m\n
\e[31m Press Enter to Delete Mods Used By This Server.
\e[0m\n' foo
echo -e "\e[1;40m\n
\e[31m Mods Deleted:\n ${mods2}\n From Workshop Directory: \n ${dir_workshop}
\e[0m"
sleep 0.1
for modid in "${INPUT[@]}"; do
rm -rf /home/$USER/.steam/debian-installation/steamapps/workshop/content/221100/${modid}
continue
done
rm -rf /home/$USER/.steam/debian-installation/steamapps/workshop/downloads/*
sleep 0.1
rm -r -f /home/$USER/.steam/debian-installation/steamapps/common/DayZ/@*
if [ -f "/home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_221100.acf" ] ; then
rm /home/$USER/.steam/debian-installation/steamapps/workshop/appworkshop_221100.acf
fi
mainmenu "${dir_dayz}" "${dir_workshop}" || exit 1;;
"3") ######################################################################################
read -p $'\e[1;40m\n
\e[31m Press Enter to Delete All DayZ Mods.
\e[0m' foo
echo ""
echo -e "\e[1;31m Deleted All Mods From Steam Workshop Directory:\n \e[1;33m${dir_workshop}"
echo ""
sleep 0.1
rm -rf /home/$USER/.steam/debian-installation/steamapps/workshop/content/221100/*
sleep 0.1
rm -rf /home/$USER/.steam/debian-installation/steamapps/workshop/downloads/*
sleep 0.1
rm -r -f /home/$USER/.steam/debian-installation/steamapps/common/DayZ/@*
mainmenu "${dir_dayz}" "${dir_workshop}" || exit 1;;
"4") ######################################################################################
mainmenu
;;
*)
echo "invalid answer, please try again"
;;
esac
}
submenu2(){
unset number
until [[ $number == +([1-3]) ]] ; do
read -s -n1 -p $'
\e[1;40;92m\n
1) Save Script\n
2) Save Alias\n
3) Back
\e[0m\n' number
done
case $number in
"1") ############################# Mods 1 ##########################################################
echo -e "\e[1;40m\n
\e[1;92m Choose a filename for the Server Launch Script:
\e[0m";
read fname;
echo ""
unset MODS
for modid in "${INPUT[@]}"; do
local modlink="@$(dec2base64 "${modid}")"
local modpath="${dir_workshop}/${modid}"
local modmeta="${modpath}/meta.cpp"
MODS+=("${modlink}")
local mods="$(IFS=";"; echo "${MODS[*]}")"
local modlink="@$(dec2base64 "${modid}")"
sleep 0.2
done
cat > $ppath$fname.sh << ENDMASTER
steam -applaunch 221100 "-mod=$mods" -connect=${SSERVER} --port ${PPORT} -name=${NNAME} -nolauncher -world=empty
ENDMASTER
echo -e "\e[1;40m\n
\e[1;92m Launch script created:\e[0m\e[1;40m\e\e[1;32m$ppath$fname.sh
\e[0m";
echo "";
mainmenu "${dir_dayz}" "${dir_workshop}" || exit 1;;
"2") ############################# Mods 2 ##########################################################
echo -e "\e[1;40m\n
\e[1;92m Choose alias for the Server Launch Script:
\e[0m"
echo ""
unset MODS
for modid in "${INPUT[@]}"; do
local modlink="@$(dec2base64 "${modid}")"
local modpath="${dir_workshop}/${modid}"
local modmeta="${modpath}/meta.cpp"
MODS+=("${modlink}")
local mods="$(IFS=";"; echo "${MODS[*]}")"
local modlink="@$(dec2base64 "${modid}")"
sleep 0.2
done
read fname
sed -i -e '1i'"alias $fname='steam -applaunch 221100 \"-mod=$mods\" -connect=${SSERVER} --port ${PPORT} -name=${NNAME} -nolauncher -world=empty'" /home/$USER/.bash_aliases;
source /home/$USER/.bash_aliases;
echo -e "\e[1;40m\n
\e[1;92m Alias created in '/home/$USER/.bash_aliases'
\e[0m";
echo ""
mainmenu "${dir_dayz}" "${dir_workshop}" || exit 1;;
"3") ######################################################################################
mainmenu;;
*) ######################################################################################
echo "invalid answer, please try again" ;;
esac
}
mods_setup() {
local dir_dayz="${1}"
local dir_workshop="${2}"
unset MODS
for modid in "${INPUT[@]}"; do
local modlink="@$(dec2base64 "${modid}")"
local modpath="${dir_workshop}/${modid}"
if ! [[ -d "${modpath}" ]]; then
missing=1
echo -e "\e[1;40m\n
\e[1;31m MOD MISSING: ${modid}:\e[1;35m $(sed -e"s/@ID@/${modid}/" <<< "${WORKSHOP_URL}")
\e[1;92m DOWNLOADING MOD: ${modid}...
\e[0m";
echo ""
steam steam+workshop_download_item 221100 ${modid} && wait
continue
fi
done
if (( missing == 1 )); then
echo -e "\e[1;44m\n
\e[1;30m Downloading Mods.. Please Wait..
\e[0m"
until [ "$(echo "$SDIR/"*)" = "$SDIR/*" ] && sleep 5 && [ "$(echo "$SDIR/"*)" = "$SDIR/*" ]
do
sleep 1
done
fi
echo ""
missing=0
unset MODS
for modid in "${INPUT[@]}"; do
local modlink="@$(dec2base64 "${modid}")"
local modpath="${dir_workshop}/${modid}"
local modmeta="${modpath}/meta.cpp"
ln -sr -f "${modpath}" "${dir_dayz}/${modlink}"
MODS+=("${modlink}")
local mods="$(IFS=";"; echo "${MODS[*]}")"
local modlink="@$(dec2base64 "${modid}")"
continue
done
echo -e "\e[1;42m\n
\e[1;30m Name: $NNAME
\e[1;30m Game IP:Port $SSERVER
\e[1;30m Query Port: $PPORT
\e[0m"
echo ""
echo -e "\e[1;40m\n
\e[1;40m\e[1;32m Launch command for this server:\n\n steam -applaunch 221100 \"-mod=$mods\" -connect=${SSERVER} --port ${PPORT} -name=${NNAME} -nolauncher -world=empty
\e[0m"
echo ""
read -p $'\e[1;40m\n
\e[1;92m Press " Enter " to Launch DayZ
\e[0m\n' foo
echo -e "\e[1;40m\n
\e[1;31m Starting DayZ.. Please Wait..
\e[0m\n";
steam -applaunch 221100 "-mod=$mods" -connect=${SSERVER} --port ${PPORT} -name=${NNAME} -nolauncher -world=empty
echo "";
exit;
}
main() {
check_deps
resolve_steam
if [[ -z "${STEAM_ROOT}" ]]; then
STEAM_ROOT="${XDG_DATA_HOME:-${HOME}/.steam}/steam"
fi
STEAM_ROOT="${STEAM_ROOT}/steamapps"
local dir_dayz="${STEAM_ROOT}/common/DayZ"
local dir_workshop="${STEAM_ROOT}/workshop/content/${DAYZ_ID}"
check_dir "${dir_dayz}"
check_dir "${dir_workshop}"
startmenu "${dir_dayz}" "${dir_workshop}" || exit 1
query_server_api
mainmenu "${dir_dayz}" "${dir_workshop}" || exit 1
mods_setup "${dir_dayz}" "${dir_workshop}" || exit 1
local mods="$(IFS=";"; echo "${MODS[*]}")"
local mods2="$(IFS=";"; echo "${MODS2[*]}")"
}
main