forked from curseforge-docker/modpack-servers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.sh
executable file
·54 lines (41 loc) · 1.44 KB
/
prepare.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
#!/bin/bash
## Check if manifest.json exists, exit if it does not exist
if [ ! -f "manifest.json" ]; then
echo "## No manifest.json found, probably no files to download.."
exit 0
fi
OVERRIDES_DIR=$(cat manifest.json | jq -r .overrides)
if [ ! -z "${OVERRIDES_DIR}" ] && [ "${OVERRIDES_DIR}" != "null" ] && [ -d "./${OVERRIDES_DIR}" ]; then
mv "./${OVERRIDES_DIR}/"* ./
rm -r "./${OVERRIDES_DIR}"
fi
if [ ! -z "${PROJECTID_IGNORE}" ]; then
echo "${PROJECTID_IGNORE}" > projectid.ignore
fi
## Function to download mod files from manifest.json
function downloadFile {
if [[ $# != 2 ]]; then
echo "Not enough arguments to download file"
return
fi
ADDONID=${1}
FILEID=${2}
if [ -f ./projectid.ignore ] && grep -q "${ADDONID}" ./projectid.ignore; then
echo "Ignoring addon with id ${ADDONID}"
return
fi
## Change to mods directory
cd mods
## Get download url for mod file
MOD_FILE_URL=$(curl -sL "https://addons-ecs.forgesvc.net/api/v2/addon/${ADDONID}/file/${FILEID}/download-url")
echo "# Downloading mods/$(basename "$MOD_FILE_URL")"
curl -sSLOJ "$MOD_FILE_URL"
}
## Make downloadFile function accessible for xargs call
export -f downloadFile
# Create mods directory if it does not exist
[ ! -d "mods" ] && mkdir "mods"
# Download all mod files to mods directory
cat manifest.json | \
jq -r '.files[] | (.projectID|tostring) + " " + (.fileID|tostring)' | \
xargs -n 1 -P 10 -I {} bash -c 'downloadFile $@' _ {}