-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteamcmd_helper
executable file
·153 lines (130 loc) · 6.01 KB
/
steamcmd_helper
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
#!/bin/sh
#display help when we have wrong number of arguments
#or we type "--help"
if [ "$#" -lt 2 ] || [ "$1" = "--help" ]; then
echo "usage: $0 <steamapps> <steam_app_ids>"
echo "will download game with <app_id> to <steamapps>/common/<game name>"
echo "<steamapps> must be a valid steamapps folder"
echo "the file steamcmd_settings.txt will automatically be passed to steamcmd as a script file."
echo "Do your account etc. setup in that file."
echo "If it doesn't exist, there will NOT be an opportunity to login to steam as part of this script, meaning most likely it will not work at all"
echo ""
echo "See here for more details:"
echo "https://developer.valvesoftware.com/wiki/SteamCMD#Automating_SteamCMD"
echo ""
echo "appids should be space separated"
echo "appids can be found at https://steamdb.info/"
exit 1
fi
#PROCESS FIRST ARGUMENT
if ! [ -d "$1" ] || ! [ -d "$1/common" ]; then
echo "$1 is not an existing steamapps directory. Creating a new directory at $1"
fi
#generate our command line string
command="steamcmd"
options_path=$(realpath ./steamcmd_settings.txt)
#add our options file if it exists
if [ -f "$options_path" ]; then
script=' +runscript "'${options_path}'"'
else
echo "$options_path not found. SteamCMD will be unable to login. Exiting..."
exit 1
fi
#process each argument
count=0
processed=0
for arg in "$@"
do
#skip the first argument - it's the path, we just want
#the delimited list of values
if [ $count -gt 0 ]; then
#check that our argument is numeric
case $arg in
''|*[!0-9]*) echo "($arg)" contains non-numeric characters. Skipping && continue ;;
*) ;;
esac
appid_file="./.appid.steamcmd"
#so, we have validated our appid. Now we need to get it's folder information
eval "$command$script +app_info_print "${arg}" +quit | tee $appid_file"
#now that we have the app info in a file, we can grep it for the install directory
#I better explain this monstrosity because it's awful.
#so first we grep our temp file for the "installdir" line, which tells steam the name of the folder
#that the game is supposed to be installed into (we can't change this).
#then we use cut to find the fourth "section" (based on whitespace) that is broken up by quotes
#so if our line was
# "installdir" "cool game"
#1 2 3 4 5
#section 4 starts just after the quote mark and goes until the 5th quote mark
#the monstrous bundle of quotes you see below is because we need to tell cut what our delimiter is
#(it's a ") which means we have to put it in single quotes like: cut -d '"' -f4
#but since we are already using quotes for our eval, we have to use strings of different type
#it would look much better spaced out, but cut complains if we do that
#this should make more sense: cut -d' "'" <-left '"' <-delim "'" <-right ' -f4'
installdir=$(eval 'grep -m 1 -w -e "installdir" $appid_file | cut -d '"'"'"'"'"' -f4')
appname=$(eval 'grep -m 1 -w -e "name" $appid_file | cut -d '"'"'"'"'"' -f4')
echo "==========================================="
echo "App Name: "$appname
echo "==========================================="
#remove the temp file we created
rm -f "$appid_file"
if [ "$installdir" = "" ]; then
echo "an error occurred retrieving the app information for appid ${arg}"
continue
fi
#we want to download <appid> to <$installdir>
#since the argument was in the form of
#so our fullpath is <steamapps>($1)/common/$installdir
#if we had a leading trail in our path,
#it will be $1/common//$installdir, but don't worry
#bash handles that for us
dir=$1/common/$installdir
#make a directory for our game
mkdir -p "$dir"
#we need to make a symlink to our steamapps dir
#inside the folder for the game we are downloading
#because of a quirk with the way that SteamCMD works
if ! [ -L "$dir/steamapps" ]; then
ln -s "$1" "$dir/steamapps"
fi
#we need to tell the tool where to install our games, which we can do by
#writing 'force_install_dir' into a temporary run script
dir_string='force_install_dir "'$dir'"'
script_file="./.force_install_dir.steamcmd"
echo "$dir_string" > "$script_file"
echo "@ShutdownOnFailedCommand 1" >> "$script_file" #not sure if this is required
script_file_path=$(realpath "${script_file}")
script2=$script' +runscript "'${script_file_path}'"'
#update and validate our apps
#validation is technically options, but recommended
app_string=" +app_update $arg validate"
#and now we are ready to go
#echo "$command$script$app_string +quit"
eval "$command$script$script2$app_string +quit"
#remove the temp file we created
rm -f "$script_file"
#keep track of how many downloads we processed
processed=$((processed + 1))
#remove unneeded steamapps link left over
#because of the lack of -r, it should theoretically be impossible
#for this to wipe out the real steamapps dir, in case anything really, really bad happens
rm -f "$dir/steamapps"
#remove random EmptySteamDepot folder (likely a bug in SteamCMD)
if [ -d "$dir/EmptySteamDepot" ]; then
rm -rf "$dir/EmptySteamDepot"
fi
#add appname to our list of processed apps
if [ $processed -gt 1 ]; then
processed_list=$processed_list", "$appname
else
processed_list=$appname
fi
#display finished message
echo "finished processing $appname"
fi
count=$((count + 1))
done
if [ $processed -gt 0 ]; then
echo "finished. Processed $processed downloads: $processed_list"
else
echo "finished. No downloads."
fi