-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
266 lines (199 loc) · 8.54 KB
/
deploy.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
#!/bin/bash
printf "Sven Co-op custom resource bouncer\n\n"
# Config
PLATFORM=""
case "$(uname -s)" in
Darwin)
PLATFORM=MacOS
;;
Linux)
PLATFORM=Linux
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
PLATFORM=Windows
;;
*)
printf "[Error] Platform \"$(uname -s)\" not supported.\n"
exit 1
;;
esac
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
GAME_DIR_PATHNAME=$(realpath "${DIR}/../..")
if [ -n "${1}" ] && [ ! -z "${1}" ]; then
if [ ! -d "${1}" ]; then
printf "[Error] Game directory specified not found.\n"
exit 1
fi
GAME_DIR_PATHNAME=$(realpath "${1}")
fi
GAME_BASE_DIR_PATHNAME=$(realpath "${GAME_DIR_PATHNAME}/svencoop")
GAME_BASE_DIR_NAME=$(basename "${GAME_BASE_DIR_PATHNAME}")
GAME_ADDON_DIR_PATHNAME=$(realpath "${GAME_BASE_DIR_PATHNAME}_addon")
GAME_ADDON_DIR_NAME=$(basename "${GAME_ADDON_DIR_PATHNAME}")
GAME_DOWNLOADS_DIR_PATHNAME=$(realpath "${GAME_BASE_DIR_PATHNAME}_downloads")
GAME_DOWNLOADS_DIR_NAME=$(basename "${GAME_DOWNLOADS_DIR_PATHNAME}")
REPLACEMENT_RESOURCES_DIR_PATHNAME=$(realpath "${DIR}/resources")
REPLACEMENT_PLAYER_MODEL_NAME="helmet"
REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME=$(realpath "${GAME_BASE_DIR_PATHNAME}/models/player/${REPLACEMENT_PLAYER_MODEL_NAME}")
FILTER_PLAYER_MODELS_FILE_PATHNAME=$(realpath "${DIR}/filter-player-models.txt")
FILTER_SOUNDS_FILE_PATHNAME=$(realpath "${DIR}/filter-sounds.txt")
# Information
printf "Platform: ${PLATFORM}\n"
printf "\n"
printf "Directory path names:\n"
printf -- "- Tool ${DIR}\n"
printf -- "- Game ${GAME_DIR_PATHNAME}\n"
printf -- "- Base content ${GAME_BASE_DIR_PATHNAME}\n"
printf -- "- Add-on content ${GAME_ADDON_DIR_PATHNAME}\n"
printf -- "- Downloaded content ${GAME_DOWNLOADS_DIR_PATHNAME}\n"
printf "\n"
printf "Player model sub: ${REPLACEMENT_PLAYER_MODEL_NAME}\n"
printf "Player model filter: ${FILTER_PLAYER_MODELS_FILE_PATHNAME}\n"
printf "Sounds filter: ${FILTER_SOUNDS_FILE_PATHNAME}\n"
printf "\n"
# Pre-flight checks
if [ ! -d "${GAME_DIR_PATHNAME}" ]; then
printf "[Error] Game directory not found.\n"
exit 1
fi
if [ ! -d "${GAME_BASE_DIR_PATHNAME}" ]; then
printf "[Error] Game base directory not found.\n"
exit 1
fi
if [ ! -f "${GAME_BASE_DIR_PATHNAME}/liblist.gam" ]; then
printf "[Error] Game base content directory invalid.\n"
exit 1
fi
if [ ! -f "${GAME_ADDON_DIR_PATHNAME}/../${GAME_BASE_DIR_NAME}/liblist.gam" ]; then
printf "[Error] Game add-on content directory invalid.\n"
exit 1
fi
if [ ! -d "${GAME_DOWNLOADS_DIR_PATHNAME}" ]; then
printf "[Info] Game downloaded content directory not found. It will be created.\n"
mkdir -p "${GAME_DOWNLOADS_DIR_PATHNAME}"
if [ ! -d "${GAME_DOWNLOADS_DIR_PATHNAME}" ]; then
printf "[Error] Game downloaded content directory could not be created.\n"
exit 1
fi
fi
if [ ! -f "${GAME_DOWNLOADS_DIR_PATHNAME}/../${GAME_BASE_DIR_NAME}/liblist.gam" ]; then
printf "[Error] Game downloaded content directory invalid.\n"
exit 1
fi
if [ ! -d "${REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME}" ]; then
printf "[Error] Replacement player model directory \"${REPLACEMENT_PLAYER_MODEL_NAME}\" not found.\n"
exit 1
fi
if [ ! -f "${REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME}/${REPLACEMENT_PLAYER_MODEL_NAME}.mdl" ]; then
printf "[Error] Replacement player model file \"${REPLACEMENT_PLAYER_MODEL_NAME}\" not found.\n"
exit 1
fi
if [ ! -f "${REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME}/${REPLACEMENT_PLAYER_MODEL_NAME}.bmp" ]; then
printf "[Warning] Replacement player model file \"${REPLACEMENT_PLAYER_MODEL_NAME}\" thumbnail not found.\n"
fi
# Prepare resource directories
printf "\nPreparing resource directories...\n\n"
if [ ! -d "${GAME_ADDON_DIR_PATHNAME}/models/player" ]; then
mkdir -p "${GAME_ADDON_DIR_PATHNAME}/models/player"
fi
if [ ! -d "${GAME_ADDON_DIR_PATHNAME}/sound" ]; then
mkdir -p "${GAME_ADDON_DIR_PATHNAME}/sound"
fi
if [ ! -d "${GAME_DOWNLOADS_DIR_PATHNAME}/models/player" ]; then
mkdir -p "${GAME_DOWNLOADS_DIR_PATHNAME}/models/player"
fi
if [ ! -d "${GAME_DOWNLOADS_DIR_PATHNAME}/sound" ]; then
mkdir -p "${GAME_DOWNLOADS_DIR_PATHNAME}/sound"
fi
# Filter player models
printf "\nFiltering player models...\n\n"
if [ -f "${FILTER_PLAYER_MODELS_FILE_PATHNAME}" ]; then
if [ -s "${FILTER_PLAYER_MODELS_FILE_PATHNAME}" ]; then
while read FILTER_PLAYER_MODEL_NAME; do
FILTER_PLAYER_MODEL_NAME=${FILTER_PLAYER_MODEL_NAME//[$'\t\r\n']}
if [ ! -n "${FILTER_PLAYER_MODEL_NAME}" ] || [ -z "${FILTER_PLAYER_MODEL_NAME}" ]; then
continue
fi
printf -- "${FILTER_PLAYER_MODEL_NAME}:\n"
FILTER_PLAYER_MODEL_ADDON_DIR_PATHNAME=$(realpath "${GAME_ADDON_DIR_PATHNAME}/models/player/${FILTER_PLAYER_MODEL_NAME}")
FILTER_PLAYER_MODEL_DOWNLOADS_DIR_PATHNAME=$(realpath "${GAME_DOWNLOADS_DIR_PATHNAME}/models/player/${FILTER_PLAYER_MODEL_NAME}")
if [ -d "${FILTER_PLAYER_MODEL_DOWNLOADS_DIR_PATHNAME}" ]; then
printf -- "- Deleting directory from downloads.\n"
rm -rf "${FILTER_PLAYER_MODEL_DOWNLOADS_DIR_PATHNAME}"
fi
if [ ! -d "${FILTER_PLAYER_MODEL_ADDON_DIR_PATHNAME}" ]; then
mkdir -p "${FILTER_PLAYER_MODEL_ADDON_DIR_PATHNAME}"
fi
if [ "${PLATFORM}" == "Windows" ]; then
cp "${REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME}/${REPLACEMENT_PLAYER_MODEL_NAME}.mdl" "${FILTER_PLAYER_MODEL_ADDON_DIR_PATHNAME}/${FILTER_PLAYER_MODEL_NAME}.mdl"
cp "${REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME}/${REPLACEMENT_PLAYER_MODEL_NAME}.bmp" "${FILTER_PLAYER_MODEL_ADDON_DIR_PATHNAME}/${FILTER_PLAYER_MODEL_NAME}.bmp"
else
ln -s "${REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME}/${REPLACEMENT_PLAYER_MODEL_NAME}.mdl" "${FILTER_PLAYER_MODEL_ADDON_DIR_PATHNAME}/${FILTER_PLAYER_MODEL_NAME}.mdl"
ln -s "${REPLACEMENT_PLAYER_MODEL_DIR_PATHNAME}/${REPLACEMENT_PLAYER_MODEL_NAME}.bmp" "${FILTER_PLAYER_MODEL_ADDON_DIR_PATHNAME}/${FILTER_PLAYER_MODEL_NAME}.bmp"
fi
printf -- "- Filter installed.\n"
done < "${FILTER_PLAYER_MODELS_FILE_PATHNAME}"
else
printf "[Warning] Player models filter file is empty.\n"
fi
else
printf "[Warning] Player models filter file not found.\n"
fi
# Filter sounds
printf "\nFiltering sounds...\n\n"
if [ -f "${FILTER_SOUNDS_FILE_PATHNAME}" ]; then
if [ -s "${FILTER_SOUNDS_FILE_PATHNAME}" ]; then
while read FILTER_SOUND_NAME; do
FILTER_SOUND_NAME=${FILTER_SOUND_NAME//[$'\t\r\n']}
if [ ! -n "${FILTER_SOUND_NAME}" ] || [ -z "${FILTER_SOUND_NAME}" ]; then
continue
fi
printf "${FILTER_SOUND_NAME}:\n"
FILTER_SOUND_DOWNLOADS_PATHNAME=$(realpath "${GAME_DOWNLOADS_DIR_PATHNAME}/sound/${FILTER_SOUND_NAME}")
declare -a FILTER_SOUND_REPLACEMENT_FILE_PATHNAMES
if [ -d "${FILTER_SOUND_DOWNLOADS_PATHNAME}" ]; then
while read FILTER_SOUND_DOWNLOADS_SUBITEM_PATHNAME; do
FILTER_SOUND_REPLACEMENT_FILE_PATHNAMES+=( "${FILTER_SOUND_DOWNLOADS_SUBITEM_PATHNAME}" )
#printf -- "- Detected file to filter: ${FILTER_SOUND_DOWNLOADS_SUBITEM_PATHNAME}\n"
done < <(find "${FILTER_SOUND_DOWNLOADS_PATHNAME}" -type f | sort)
elif [ -f "${FILTER_SOUND_DOWNLOADS_PATHNAME}" ]; then
FILTER_SOUND_REPLACEMENT_FILE_PATHNAMES+=( "${FILTER_SOUND_DOWNLOADS_PATHNAME}" )
#printf -- "- Detected file to filter: ${FILTER_SOUND_DOWNLOADS_PATHNAME}\n"
else
if [ "${FILTER_SOUND_NAME: -1}" != "/" ]; then
FILTER_SOUND_REPLACEMENT_FILE_PATHNAMES+=( "${FILTER_SOUND_DOWNLOADS_PATHNAME}" )
fi
#printf -- "- No downloaded directory or file detected to filter.\n"
fi
if [ "${FILTER_SOUND_NAME: -1}" == "/" ]; then
if [ ! -d "${FILTER_SOUND_DOWNLOADS_PATHNAME}" ]; then
mkdir -p "${FILTER_SOUND_DOWNLOADS_PATHNAME}"
fi
else
if [ ! -f "${FILTER_SOUND_DOWNLOADS_PATHNAME}" ]; then
mkdir -p $(dirname "${FILTER_SOUND_DOWNLOADS_PATHNAME}")
fi
fi
for FILTER_SOUND_REPLACEMENT_PATHNAME in "${FILTER_SOUND_REPLACEMENT_FILE_PATHNAMES[@]}"; do
if [ -f "${FILTER_SOUND_REPLACEMENT_PATHNAME}" ]; then
if [ -s "${FILTER_SOUND_REPLACEMENT_PATHNAME}" ]; then
rm -f "${FILTER_SOUND_REPLACEMENT_PATHNAME}"
touch "${FILTER_SOUND_REPLACEMENT_PATHNAME}"
printf -- "- Filter installed: ${FILTER_SOUND_REPLACEMENT_PATHNAME}\n"
else
printf -- "- Filter already installed: ${FILTER_SOUND_REPLACEMENT_PATHNAME}\n"
fi
else
touch "${FILTER_SOUND_REPLACEMENT_PATHNAME}"
printf -- "- Filter pre-emptively installed: ${FILTER_SOUND_REPLACEMENT_PATHNAME}\n"
fi
done
done < "${FILTER_SOUNDS_FILE_PATHNAME}"
else
printf "[Warning] Sounds filter file is empty.\n"
fi
else
printf "[Warning] Sounds filter file not found.\n"
fi
# Finished
exit 0