-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-setupModpack
executable file
·321 lines (281 loc) · 9.06 KB
/
start-setupModpack
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
#!/bin/bash
set -e -o pipefail
: "${REMOVE_OLD_MODS:=false}"
: "${MODS_FILE:=}"
: "${REMOVE_OLD_MODS_DEPTH:=1} "
: "${REMOVE_OLD_MODS_INCLUDE:=*.jar,*-version.json}"
sum_file=/data/.generic_pack.sum
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
isDebugging && set -x
# CURSE_URL_BASE used in manifest downloads below
CURSE_URL_BASE=${CURSE_URL_BASE:-https://minecraft.curseforge.com/projects}
# Remove old mods/plugins
if isTrue "${REMOVE_OLD_MODS}" && [ -z "${MODS_FILE}" ]; then
removeOldMods /data/mods
removeOldMods /data/plugins
rm -f "$sum_file"
fi
function handlePackwiz() {
# If packwiz url passed, bootstrap packwiz and update mods before other modpack processing
if [[ "${PACKWIZ_URL:-}" ]]; then
if ! packwizInstaller=$(mc-image-helper maven-download \
--maven-repo=https://maven.packwiz.infra.link/repository/release/ \
--group=link.infra.packwiz --artifact=packwiz-installer --classifier=dist \
--skip-existing); then
log "ERROR: failed to get packwiz installer"
exit 1
fi
log "Running packwiz installer against URL: ${PACKWIZ_URL}"
if ! java -cp "${packwizInstaller}" link.infra.packwiz.installer.Main -s server "${PACKWIZ_URL}"; then
log "ERROR failed to run packwiz installer"
exit 1
fi
fi
}
function handleModsFile() {
mod=${1?}
if isURL "$mod"; then
log "Downloading mod/plugin $mod ..."
cd "${out_dir}"
if ! curl --connect-timeout 5 --retry 5 --retry-delay 0 -sSOJL "$mod"; then
log "ERROR: failed to download from $mod into $out_dir"
exit 2
fi
elif [[ -f "$mod" && "$mod" =~ .*\.jar ]]; then
log "Copying plugin located at $mod ..."
out_file=$(basename "$mod")
if ! cp "$mod" "${out_dir}/$out_file"; then
log "ERROR: failed to copy from $mod into $out_dir"
exit 2
fi
elif [[ -d "$mod" ]]; then
log "Copying plugin jars from $mod ..."
cp "$mod"/*.jar "${out_dir}"
else
log "ERROR Invalid URL or path given in MODS: $mod"
exit 2
fi
}
function handleModpackListOrFile() {
# If supplied with a URL for a modpack (simple zip of jars), download it and unpack
if [[ "$MODPACK" ]]; then
if isURL "${MODPACK}"; then
log "Downloading mod/plugin pack"
if ! get -o /tmp/modpack.zip "${MODPACK}"; then
log "ERROR: failed to download from ${MODPACK}"
exit 2
fi
elif [[ "$MODPACK" =~ .*\.zip ]]; then
if ! cp "$MODPACK" /tmp/modpack.zip; then
log "ERROR: failed to copy from $MODPACK"
exit 2
fi
else
log "ERROR Invalid URL or Path given for MODPACK: $MODPACK"
exit 1
fi
if [ "$FAMILY" = "SPIGOT" ]; then
mkdir -p /data/plugins
if ! unzip -o -d /data/plugins /tmp/modpack.zip; then
log "ERROR: failed to unzip the modpack from ${MODPACK}"
fi
else
mkdir -p /data/mods
if ! unzip -o -d /data/mods /tmp/modpack.zip; then
log "ERROR: failed to unzip the modpack from ${MODPACK}"
fi
fi
rm -f /tmp/modpack.zip
elif [[ "$MODS" ]]; then
if [ "$FAMILY" = "SPIGOT" ]; then
out_dir=/data/plugins
else
out_dir=/data/mods
fi
mkdir -p "$out_dir"
for i in ${MODS//,/ }
do
handleModsFile $i &
done
FAIL=0
for job in `jobs -p`
do
wait $job || let "FAIL+=1"
done
if [ "$FAIL" == "0" ];
then
echo "Successfully downloaded all mods!"
else
echo "Mod download failed!"
exit 1
fi
elif [[ "$MODS_FILE" ]]; then
if [ ! -f "$MODS_FILE" ]; then
log "ERROR: given MODS_FILE file does not exist"
exit 2
fi
if [ "$FAMILY" = "SPIGOT" ]; then
out_dir=/data/plugins
else
out_dir=/data/mods
fi
mkdir -p "$out_dir"
args=(
-o "${out_dir}"
--log-progress-each
--skip-up-to-date
--uris-file "${MODS_FILE}"
)
if isTrue "${REMOVE_OLD_MODS}"; then
args+=(
--prune-others "${REMOVE_OLD_MODS_INCLUDE}"
--prune-depth "${REMOVE_OLD_MODS_DEPTH}"
)
fi
if ! get "${args[@]}" ; then
log "ERROR: failed to retrieve one or more mods"
exit 1
fi
fi
}
function handleCurseForgeManifest() {
if [[ "$MANIFEST" ]]; then
if [[ -e "$MANIFEST" ]]; then
EFFECTIVE_MANIFEST_FILE=$MANIFEST
elif isURL "$MANIFEST"; then
EFFECTIVE_MANIFEST_FILE=/tmp/manifest.json
EFFECTIVE_MANIFEST_URL=$(curl -Ls -o /dev/null -w "%{effective_url}" "$MANIFEST")
curl -Ls -o $EFFECTIVE_MANIFEST_FILE "$EFFECTIVE_MANIFEST_URL"
else
log "MANIFEST='$MANIFEST' is not a valid manifest url or location"
exit 2
fi
case "X$EFFECTIVE_MANIFEST_FILE" in
X*.json)
if [ -f "${EFFECTIVE_MANIFEST_FILE}" ]; then
MOD_DIR=${FTB_BASE_DIR:-/data}/mods
if [ ! -d "$MOD_DIR" ]
then
log "Creating mods dir $MOD_DIR"
mkdir -p "$MOD_DIR"
fi
log "Starting manifest download..."
jq -r '.files[] | (.projectID|tostring) + " " + (.fileID|tostring)' "${EFFECTIVE_MANIFEST_FILE}" | while read -r p f
do
if [ ! -f $MOD_DIR/${p}_${f}.jar ]
then
redirect_url="$(curl -Ls -o /dev/null -w "%{effective_url}" "${CURSE_URL_BASE}/${p}")"
url="$redirect_url/download/${f}/file"
log Downloading curseforge mod $url
# Manifest usually doesn't have mod names. Using id should be fine, tho
curl -sSL "${url}" -o $MOD_DIR/${p}_${f}.jar
fi
done
else
log "Could not find manifest file, insufficient privileges, or malformed path."
fi
;;
*)
log "Invalid manifest file for modpack. Please make sure it is a .json file."
;;
esac
fi
}
function genericPacks() {
: "${GENERIC_PACKS:=${GENERIC_PACK}}"
: "${GENERIC_PACKS_PREFIX:=}"
: "${GENERIC_PACKS_SUFFIX:=}"
if [[ "${GENERIC_PACKS}" ]]; then
IFS=',' read -ra packs <<< "${GENERIC_PACKS}"
packFiles=()
for packEntry in "${packs[@]}"; do
pack="${GENERIC_PACKS_PREFIX}${packEntry}${GENERIC_PACKS_SUFFIX}"
if isURL "${pack}"; then
mkdir -p /data/packs
log "Downloading generic pack from $pack"
if ! outfile=$(get -o /data/packs --output-filename --skip-up-to-date "$pack"); then
log "ERROR: failed to download $pack"
exit 2
fi
packFiles+=("$outfile")
else
packFiles+=("$pack")
fi
done
isDebugging && [ -f "$sum_file}" ] && cat "$sum_file"
log "Checking if generic packs are up to date"
if isTrue "${SKIP_GENERIC_PACK_UPDATE_CHECK:-false}" && [ -f "$sum_file" ]; then
log "Skipping generic pack update check"
elif isTrue "${FORCE_GENERIC_PACK_UPDATE}" || ! checkSum "${sum_file}"; then
log "Generic pack(s) are out of date. Re-applying..."
original_base_dir=/data/.tmp/generic_pack_base
base_dir=$original_base_dir
rm -rf "${base_dir}"
mkdir -p "${base_dir}"
for pack in "${packFiles[@]}"; do
isDebugging && ls -l "${pack}"
extract "${pack}" "${base_dir}"
done
# Remove any eula file since container manages it
rm -f "${base_dir}/eula.txt"
# recalculate the actual base directory of content
if ! base_dir=$(mc-image-helper find \
--max-depth=3 --type=directory --name=mods,plugins,config \
--only-shallowest --fail-no-matches --format '%h' \
"$base_dir"); then
log "ERROR: Unable to find content base of generic packs ${GENERIC_PACKS}. Directories:"
mc-image-helper find --name=* --max-depth=3 --type=directory --format '- %P' "$original_base_dir"
exit 1
fi
if [ -f /data/manifest.txt ]; then
log "Manifest exists from older generic pack, cleaning up ..."
while read -r f; do
rm -rf "/data/${f}"
done < /data/manifest.txt
# prune empty dirs
find /data -mindepth 1 -depth -type d -empty -delete
rm -f /data/manifest.txt
fi
log "Writing generic pack manifest ... "
find "${base_dir}" -type f -printf "%P\n" > /data/manifest.txt
log "Applying generic pack ..."
cp -R -f "${base_dir}"/* /data
rm -rf $original_base_dir
if isTrue "${SKIP_GENERIC_PACK_CHECKSUM:-false}"; then
log "Skipping generic pack(s) checksum"
else
log "Saving generic pack(s) checksum"
sha1sum "${packFiles[@]}" > "${sum_file}"
if isDebugging; then
cat "$sum_file"
fi
fi
fi
fi
}
function modrinthProjects() {
: "${MODRINTH_PROJECTS:=}"
: "${MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES:=true}"
: "${MODRINTH_ALLOWED_VERSION_TYPE:=release}"
if [[ $MODRINTH_PROJECTS ]] && isFamily HYBRID FORGE FABRIC; then
if isFamily HYBRID FORGE; then
loader=forge
else
loader="${FAMILY,,}"
fi
mc-image-helper modrinth \
--output-directory=/data \
--projects="${MODRINTH_PROJECTS}" \
--game-version="${VANILLA_VERSION}" \
--loader="$loader" \
--download-optional-dependencies="$MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES" \
--allowed-version-type="$MODRINTH_ALLOWED_VERSION_TYPE"
fi
}
handlePackwiz
handleModpackListOrFile
handleCurseForgeManifest
genericPacks
modrinthProjects
exec "${SCRIPTS:-/}start-setupModconfig" "$@"