-
Notifications
You must be signed in to change notification settings - Fork 2
/
steamcmd-wrapper.sh
executable file
·625 lines (492 loc) · 15.7 KB
/
steamcmd-wrapper.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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
#!/bin/bash
#-------------------------------------------------------------------------------
# Author: Michael DeGuzis
# Git: https://github.com/ProfessorKaos64/steamcmd-wrapper
# Scipt name: steamcmd-wrapper.sh
# Script Ver: 0.3.9
# Description: Wrapper around steamcmd for common functions
# Ex. Downloads a game from Steam, based on it's AppID, useful for
# for on-the-go situations, or free-to-play when you can't
# load the client.
#
# Usage: ./steamcmd-wrapper.sh [options]
# ./steamcmd-wrapper.sh [-h|--help]
set -e
# Set initial vars
STEAMCMD_ROOT="/opt/steamcmd"
TEMP_DIRECTORY="${STEAMCMD_ROOT}/steamcmd_tmp"
SERVER_ROOT="${STEAMCMD_ROOT}/servers"
DOWNLOAD_FILES="false"
STEAMCMD_CMD_UPDATE_LIST="false"
GAME_SERVER="false"
DATE_LONG=$(date +"%a, %d %b %Y %H:%M:%S %z")
DATE_SHORT=$(date +%Y%m%d)
OS=$(cat /etc/os-release | awk -F'=' '/^ID=/ {print $2}')
detect_steamcmd()
{
# A stub for now
if [[ ! -f "${STEAMCMD_ROOT}/steamcmd.sh" ]]; then
install_steamcmd
fi
}
get_appid_info()
{
# TODO - parse JSON
${STEAMCMD_ROOT}/steamcmd.sh +app_info_print ${GAME_APP_ID} +quit | less
}
install_steamcmd()
{
# Check Distro
# Use lsb_release and /etc/*-release as a backup
DISTRO_CHECK=$(lsb_release -si)
ID_LIKE=$(cat /etc/*-release | awk -F"=" '/ID_LIKE/{print $2}' | sed 's/"//'g)
if [[ "${DISTRO_CHECK}" == "" ]]; then
# try /etc/*-release
DISTRO_CHECK=$(cat /etc/*-release | awk -F"=" '/DISTRIB_ID/{print $2}')
fi
# Check for multilib
if [[ "${DISTRO_CHECK}" == "Debian" || "${DISTRO_CHECK}" == "SteamOS" || "${ID_LIKE}" =~ "debian" ]]; then
MULTIARCH=$(dpkg --print-foreign-architectures | grep i386)
if [[ "${MULTIARCH}" == "" ]]; then
echo -e "\nMultiarch not found!\n"
sudo dpkg --add-architecture i386
echo -e "Updating for multiarch\n"
sleep 2s
sudo apt-get update
fi
elif [[ "${DISTRO_CHECK}" == "Arch" || "${DISTRO_CHECK}" == "chimeraos" ]]; then
MULTIARCH=$(grep '\[multilib\]' /etc/pacman.conf)
if [[ "${MULTIARCH}" == "" ]]; then
echo -e "\nMultiarch not found!\n"
echo "[INFO] [multilib]" | sudo tee -a "/etc/pacman.conf"
echo "[INFO] Include = /etc/pacman.d/mirrorlist" | "sudo tee -a /etc/pacman.conf"
echo -e "Updating for multiarch\n"
sleep 2s
sudo pacman -Syy
fi
else
# Catch non supported distros
echo "[INFO] Distribution not currently supported!"
echo "[INFO] Distro: ${DISTRO_CHECK}"
echo "[INFO] ID like: ${ID_LIKE}"
exit 1
fi
# Install needed packages
if [[ "${DISTRO_CHECK}" == "Debian" || "${DISTRO_CHECK}" == "SteamOS" ]]; then
sudo apt-get install -y --force-yes lib32gcc1 libc6-i386 wget tar
elif [[ "${DISTRO_CHECK}" == "Arch" || "${DISTRO_CHECK}" == "chimeraos" ]]; then
if [[ "${DISTRO_CHECK}" == "chimeraos" ]]; then
echo "[INFO] Need to unlock system files for ChimeraOS first with frzr-unlock..."
sudo frzr-unlock
fi
sudo pacman -S wget tar grep lib32-gcc-libs
elif [[ "${DISTRO_CHECK}" == "Fedora" ]]; then
sudo yum install wget tar glibc.i686 libstdc++.i686
fi
# install steamcmd
echo -e "\n==> Installing/Updating steamcmd\n"
sudo mkdir -p "${STEAMCMD_ROOT}"
# Update perms on folder to user
sudo chown ${USER}:${USER} "${STEAMCMD_ROOT}"
wget "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" -q -nc --show-progress
tar -xf "steamcmd_linux.tar.gz" -C "${STEAMCMD_ROOT}"
rm -f "steamcmd_linux.tar.gz"
# Add steam to group for SteamOS (runs as steam)
if [[ "${OS}" == "steamos" ]]; then
echo "[INFO] Updating group owner to steam (SteamOS)"
sudo chgrp -R steam "${STEAMCMD_ROOT}"
sudo chmod -R g+rwx "${STEAMCMD_ROOT}"
fi
}
reset_steamcmd()
{
# Cleans out metadata cruft
echo -e "\n==> Reinstalling steamcmd\n" && sleep 2s
# Backup (suppress output if it doesn't exist)
cp -r "${HOME}/.steam" "${HOME}/.steam.bak" &> /dev/null
# Remove
rm -rf "${STEAMCMD_ROOT}/Steam/" "$HOME/.steam" "${STEAMCMD_ROOT}/steamcmd_tmp"
# Reinstall
install_steamcmd
}
show_steamcmd_commands()
{
# Show existing list if already generated
if [[ -f "${STEAMCMD_ROOT}/steamcmdcommands.txt" ]]; then
echo "[INFO] Existing list found at ${STEAMCMD_ROOT}/steamcmdcommands.txt"
else
echo -e "\nERROR: SteamCMD command list file not found. Generating...\n"
sleep 2s
generate_steamcmd_cmd_list
echo "[INFO] List generated to: ${STEAMCMD_ROOT}/steamcmdcommands.txt"
fi
# Update root listing if requested
if [[ "${STEAMCMD_UPDATE_CMD_LIST}" == "true" ]]; then
generate_steamcmd_cmd_list
echo "[INFO] List generated to: ${STEAMCMD_ROOT}/steamcmdcommands.txt"
if [[ "${GIT_PUSH}" == "true" ]]; then
cp "${STEAMCMD_ROOT}/steamcmdcommands.txt" "${PWD}"
echo -e "\n==>Updating GitHub command listing\n"
git add steamcmdcommands.txt
git commit -m "Update steamcmd command list"
git push origin master
fi
fi
}
generate_steamcmd_cmd_list()
{
# Imported code from https://github.com/dgibbs64/SteamCMD-Commands-List
# Credit:github.com/dgibbs64/
# Updated: 20160830
# Detect steacmd (required)
detect_steamcmd
cat<<-EOF
====================================
Getting SteamCMD Commands/Convars
====================================
EOF
mkdir -p "${STEAMCMD_ROOT}/tmp"
cd "${STEAMCMD_ROOT}"
for LETTER in {a..z}
do
echo "[INFO] ./steamcmd.sh +login anonymous +find ${LETTER} +quit"
./steamcmd.sh +login anonymous +find ${LETTER} +quit > "${STEAMCMD_ROOT}/tmp/${LETTER}"
echo "[INFO] Creating list for LETTER ${LETTER}."
sleep 0.5
echo "[INFO] "
# Commands List
cat "${STEAMCMD_ROOT}/tmp/${LETTER}" > "${STEAMCMD_ROOT}/tmp/${LETTER}commands"
sed -i '1,/Commands:/d' "${STEAMCMD_ROOT}/tmp/${LETTER}commands"
cat "${STEAMCMD_ROOT}/tmp/${LETTER}commands" >> "${STEAMCMD_ROOT}/tmp/commandslistraw"
#Convars List
cat "${STEAMCMD_ROOT}/tmp/${LETTER}" > "${STEAMCMD_ROOT}/tmp/${LETTER}convars"
sed -i '1,/ConVars:/d' "${STEAMCMD_ROOT}/tmp/${LETTER}convars"
#cat "${STEAMCMD_ROOT}/tmp/${LETTER}convars > "${STEAMCMD_ROOT}/tmp/${LETTER}convarscommands
sed -i '/Commands:/Q' "${STEAMCMD_ROOT}/tmp/${LETTER}convars"
cat "${STEAMCMD_ROOT}/tmp/${LETTER}convars" >> "${STEAMCMD_ROOT}/tmp/convarslistraw"
done
echo "[INFO] Sorting lists."
cd "${STEAMCMD_ROOT}/tmp"
sort -n commandslistraw > commandslistsort
uniq commandslistsort > commandslisttidy
cat commandslisttidy|tr -d '\000-\011\013\014\016-\037'| sed 's/\[0m//g'|sed 's/\[1m//g'> commandslist
sort -n convarslistraw > convarslistsort
uniq convarslistsort > convarslisttidy
cat convarslisttidy|tr -d '\000-\011\013\014\016-\037'| sed 's/\[0m//g'|sed 's/\[1m//g'> convarslist
echo "[INFO] Generating output."
# Time stamp list
echo "[INFO] List generated on:" > "${STEAMCMD_ROOT}/steamcmdcommands.txt"
echo "[INFO] ${DATE_LONG}" >> "${STEAMCMD_ROOT}/steamcmdcommands.txt"
echo "[INFO] ConVars:" >> "${STEAMCMD_ROOT}/steamcmdcommands.txt"
cat "convarslist" >> "${STEAMCMD_ROOT}/steamcmdcommands.txt"
echo "[INFO] Commands:" >> "${STEAMCMD_ROOT}/steamcmdcommands.txt"
cat "commandslist" >> "${STEAMCMD_ROOT}/steamcmdcommands.txt"
echo "[INFO] ConVars:"
cat "convarslist"
echo "[INFO] Commands:"
cat "commandslist"
echo "[INFO] Tidy up."
rm -rf "${STEAMCMD_ROOT}/tmp"
rm -rf "${STEAMCMD_ROOT}/steamcmd"
}
update_game_files()
{
read -erp " Steam username: " STEAM_LOGIN_NAME
${STEAMCMD_ROOT}/steamcmd.sh +@sSteamCmdForcePlatformType \
${PLATFORM} +login ${STEAM_LOGIN_NAME} +app_license_request \
${GAME_APP_ID} +app_update ${GAME_APP_ID} validate +quit
}
download_game_files()
{
# get game files via steam (you must own the game!)
echo -e "\n==> Acquiring files via Steam. You must own the game!"
read -erp " Steam username: " STEAM_LOGIN_NAME
# get proper install dir
INSTALL_DIR=$(${STEAMCMD_ROOT}/steamcmd.sh +app_info_print ${GAME_APP_ID} +quit | awk -F'"' '/installdir/ {print $4}')
if [[ -z ${INSTALL_DIR} ]]; then
echo "[INFO] Could not detect game installation directory!"
exit 1
fi
# Download
# steam cmd likes to put the files in the same directory as the script
# Set default based on SteamOS or standard-Linux
if [[ "${CUSTOM_DATA_PATH}" != "true" ]]; then
STEAM_ROOT="${HOME}"
MANIFEST_DIRECTORY="${STEAM_ROOT}/.local/share/Steam/steamapps"
FINAL_DIRECTORY="${STEAM_ROOT}/.local/share/Steam/steamapps/common/${INSTALL_DIR}"
mkdir -p "${FINAL_DIRECTORY}"
fi
rm -rf "${TEMP_DIRECTORY}"
mkdir -p "${TEMP_DIRECTORY}"
# run steamcmd
# +app_license_request works around downloading free to play games
cat <<- _EOF_
Steam login: ${STEAM_LOGIN_NAME}
TEMP_DIRECTORY: ${TEMP_DIRECTORY}
FINAL_DIRECTORY: ${FINAL_DIRECTORY}
MANIFEST_DIRECTORY: ${MANIFEST_DIRECTORY}
_EOF_
read -erp "Press ENTER to continue..."
echo -e "\n==> Downloading game files to: ${TEMP_DIRECTORY}\n"
if ${STEAMCMD_ROOT}/steamcmd.sh +@sSteamCmdForcePlatformType +force_install_dir \
${TEMP_DIRECTORY} ${PLATFORM} +login ${STEAM_LOGIN_NAME} +app_license_request \
${GAME_APP_ID} +app_update ${GAME_APP_ID} validate +quit; then
echo "[INFO] Temp directory contents:"
ls -la "${TEMP_DIRECTORY}"
# Move files to actual directory
echo "[INFO] Moving finished files..."
if [[ "${OS}" == "steamos" ]]; then
sudo rsync -ra --remove-source-files ${TEMP_DIRECTORY}/* "${FINAL_DIRECTORY}" --exclude "steamapps"
echo "[INFO] Copying over app manifest..."
sudo find "${TEMP_DIRECTORY}/steamapps" -name "*.acf" -exec cp -v {} ${MANIFEST_DIRECTORY} \;
else
rsync -ra --remove-source-files ${TEMP_DIRECTORY}/* "${FINAL_DIRECTORY}" --exclude "steamapps"
echo "[INFO] Copying over app manifest..."
find "${TEMP_DIRECTORY}/steamapps" -name "*.acf" -exec cp -v {} ${MANIFEST_DIRECTORY} \;
fi
echo -e "\nGame successfully downloaded to ${FINAL_DIRECTORY}"
echo "[INFO] If your game did not appear, check you are in online mode and/or restart Steam"
rm -rf ${TEMP_DIRECTORY}/*
else
echo "[INFO] Game download failed! Trying resetting steamcmd"
exit 1
fi
# chown files
if [[ "${OS}" == "steamos" ]]; then
echo "[INFO] Correcting permissions for SteamOS"
sudo chown -R steam:steam "${FINAL_DIRECTORY}"
fi
# Validate game files to slap Steam out of a daze and realize it has a new game
# The app manifest should be enough, but the idea here is to avoid having to
# click install or restart steam
echo "[INFO] Validating game files"
if ${STEAMCMD_ROOT}/steamcmd.sh +@sSteamCmdForcePlatformType \
${PLATFORM} +login ${STEAM_LOGIN_NAME} +app_update ${GAME_APP_ID} \
-validate +quit; then
echo "[INFO] Game validated"
else
echo "[INFO] Game cold not be validated!"
exit 1
fi
}
install_game_server()
{
# Main input prompt
cat<<-EOF
Please enter the game that you want to make the server of.
WARNING. you might have to install #7 multiple times to get the server to work
1) Team Fortress 2"
2) Counter-Strike: Source"
3) CS:GO"
4) Garry's Mod"
5) Left 4 Dead 2"
6) DOD:S"
7) Half-Life (also cs 1.6, dod, etc...)"
8) Other server (need steam id)"
EOF
# Simple loop to get input (if they enter it incorrectly)
while true
do
read erp "Choice: " GAME_SERVER
# Case statement to check the input var
case ${GAME_SERVER} in
1) echo "[INFO] Now installing Team Fortress 2 server."
SERVER_GAME="Team Fortress 2"
SERVER_ID=232250
break
;;
2) echo "[INFO] Now installing Counter Strike Source server."
SERVER_GAME="Counter-Strike Source"
SERVER_ID=232330
break
;;
3) echo "[INFO] Now installing CS:GO server."
SERVER_GAME="CS:GO"
SERVER_ID=740
break
;;
4) echo "[INFO] Now installing Garry's Mod server."
SERVER_GAME="Garry's Mod"
SERVER_ID=4020
break
;;
5) echo "[INFO] Now installing Left 4 Dead 2 server."
SERVER_GAME="Left 4 Dead 2"
SERVER_ID=222860
break
;;
6) echo "[INFO] Now installing DOD:S server."
SERVER_GAME="DOD:S"
SERVER_ID=232290
break
;;
7) echo "[INFO] Now installing Half-Life server."
SERVER_GAME="Half-Life"
SERVER_ID=90
break
;;
8) echo "[INFO] Now installing other server."
read -erp "Please enter a server ID: " SERVER_ID
break
;;
*) echo "[INFO] Please enter a valid option."
continue
;;
esac
done
if ${STEAMCMD_ROOT}/steamcmd.sh +login anonymous +force_install_dir ${SERVER_ROOT} \
+app_update ${SERVER_ID} validate +quit; then
echo -e "\nRequested server has been installed to ${SERVER_ROOT}\n"
else
echo -e "\nServer installation failed!"
fi
}
########################################
# source options
########################################
while :; do
case $1 in
--directory|-d) # Takes an option argument, ensuring it has been specified.
if [[ -n "$2" ]]; then
CUSTOM_DATA_PATH="true"
FINAL_DIRECTORY=$2
# echo "[INFO] INSTALL PATH: $FINAL_DIRECTORY"
shift
else
echo -e "ERROR: --directory|-d requires an argument.\n" >&2
exit 1
fi
;;
--get|-g)
if [[ -n "$2" ]]; then
GAME_APP_ID=$2
# echo "[INFO] INSTALL PATH: $FINAL_DIRECTORY"
shift
else
echo -e "ERROR: --get|-g requires the AppID an argument.\n" >&2
exit 1
fi
TYPE="download"
ACTION="download-files"
;;
--game-server|-s)
TYPE="game-server"
ACTION="setup"
;;
--info|-i)
if [[ -n "$2" ]]; then
GAME_APP_ID=$2
# echo "[INFO] INSTALL PATH: $FINAL_DIRECTORY"
shift
else
echo -e "ERROR: --info|-i requires the AppID an argument.\n" >&2
exit 1
fi
TYPE="info"
ACTION="fetch"
;;
--platform|-p)
# Takes an option argument, ensuring it has been specified.
if [[ -n "$2" ]]; then
PLATFORM=$2
# echo "[INFO] PLATFORM: $PLATFORM"
shift
else
echo -e "ERROR: --platform|-p requires an argument.\n" >&2
exit 1
fi
;;
--reset-steamcmd|-r)
# Very useful if you restore SteamoS.
reset_steamcmd
;;
--update|-u)
if [[ -n "$2" ]]; then
GAME_APP_ID=$2
# echo "[INFO] INSTALL PATH: $FINAL_DIRECTORY"
shift
else
echo -e "ERROR: --update|-u requires the AppID an argument.\n" >&2
exit 1
fi
TYPE="update"
ACTION="update-files"
;;
--steamcmd-cmds)
# Internal use only
if [[ "$2" == "--update-list" ]]; then
STEAMCMD_UPDATE_CMD_LIST="true"
fi
if [[ "$2" == "--git-push" || "$3" == "--git-push" ]]; then
GIT_PUSH="true"
fi
show_steamcmd_commands
break
;;
--help|-h)
cat<<-EOF
Usage: ./steamcmd-wrapper.sh [options]
Options:
-h|--help This help text
--info|-i Fetch appid info
--status|-s Fetch appid status info
--get|-g downloads a game
--game-server|s Installs a game server
--platform|-p [Platform]
--directory|-d [TARGET_DIR]
--steamcmd-cmds steamcmd command list
--reset-steamcmd|-r Resinstall SteamCMD
--update|-u Update a game
EOF
break
;;
--)
# End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*)
# Default case: If no more options then break out of the loop.
break
esac
# shift args
shift
done
main()
{
if [[ "${STEAMCMD_ROOT}/steam.sh" ]]; then
INSTALLED="yes"
else
INSTALLED="no"
fi
cat<<- _EOF_
#################################################
# steamcmd-wrapper
# Running on: ${OS}
# Installed?: ${INSTALLED}
#################################################
_EOF_
# Execute steamcmd for outlined functions
if [[ ${TYPE} == "download" && ${ACTION} == "download-files" ]]; then
detect_steamcmd
download_game_files
elif [[ ${TYPE} == "update" && ${ACTION} == "update-files" ]]; then
detect_steamcmd
update_game_files
elif [[ ${TYPE} == "info" && ${ACTION} == "fetch" ]]; then
detect_steamcmd
get_appid_info
elif [[ ${TYPE} == "status" && ${ACTION} == "fetch" ]]; then
read -erp " Steam username: " STEAM_LOGIN_NAME
detect_steamcmd
get_appid_status
elif [[ ${TYPE} == "game-server" && ${ACTION} == "setup" ]]; then
detect_steamcmd
install_game_server
fi
}
# start main
main