2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-12-12 03:12:44 +00:00
|
|
|
set -e -o pipefail
|
2019-09-29 16:45:21 +00:00
|
|
|
|
2020-06-19 16:05:32 +00:00
|
|
|
. ${SCRIPTS:-/}start-utils
|
2020-12-12 03:12:44 +00:00
|
|
|
if isDebugging; then
|
|
|
|
set -x
|
|
|
|
fi
|
2019-09-29 16:45:21 +00:00
|
|
|
|
2019-02-08 13:11:01 +00:00
|
|
|
# CURSE_URL_BASE used in manifest downloads below
|
|
|
|
CURSE_URL_BASE=${CURSE_URL_BASE:-https://minecraft.curseforge.com/projects}
|
|
|
|
|
2018-10-12 22:11:57 +00:00
|
|
|
# Remove old mods/plugins
|
2021-04-24 19:06:31 +00:00
|
|
|
if isTrue ${REMOVE_OLD_MODS:-false}; then
|
2021-04-28 21:29:47 +00:00
|
|
|
removeOldMods /data/mods
|
|
|
|
removeOldMods /data/plugins
|
2018-10-12 22:11:57 +00:00
|
|
|
fi
|
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
# If supplied with a URL for a modpack (simple zip of jars), download it and unpack
|
|
|
|
if [[ "$MODPACK" ]]; then
|
2020-08-03 00:57:12 +00:00
|
|
|
if isURL "${MODPACK}"; then
|
|
|
|
if [[ "${MODPACK}" == *.zip ]]; then
|
|
|
|
downloadUrl="${MODPACK}"
|
|
|
|
else
|
2020-12-12 21:22:07 +00:00
|
|
|
downloadUrl=$(curl -Ls -o /dev/null -w %{effective_url} $MODPACK)
|
2020-08-03 00:57:12 +00:00
|
|
|
if ! [[ $downloadUrl == *.zip ]]; then
|
|
|
|
log "ERROR Invalid URL given for MODPACK: $downloadUrl resolved from $MODPACK"
|
2021-04-28 21:44:39 +00:00
|
|
|
log " Must be HTTP, HTTPS or FTP and a ZIP file"
|
2020-08-03 00:57:12 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-04-28 21:44:39 +00:00
|
|
|
log "Downloading mod/plugin pack"
|
2020-08-03 00:57:12 +00:00
|
|
|
log " from $downloadUrl ..."
|
|
|
|
if ! curl -sSL -o /tmp/modpack.zip "$downloadUrl"; then
|
|
|
|
log "ERROR: failed to download from $downloadUrl"
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2021-05-06 21:27:30 +00:00
|
|
|
elif [[ "$MODPACK" =~ .*\.zip ]]; then
|
|
|
|
if ! cp $MODPACK /tmp/modpack.zip; then
|
|
|
|
log "ERROR: failed to copy from $MODPACK"
|
|
|
|
exit 2
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
2020-08-03 00:57:12 +00:00
|
|
|
else
|
2021-05-06 21:27:30 +00:00
|
|
|
log "ERROR Invalid URL or Path given for MODPACK: $MODPACK"
|
2020-08-03 00:57:12 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-06 21:27:30 +00:00
|
|
|
|
|
|
|
if [ "$TYPE" = "SPIGOT" ]; then
|
|
|
|
mkdir -p /data/plugins
|
|
|
|
if ! unzip -o -d /data/plugins /tmp/modpack.zip; then
|
|
|
|
log "ERROR: failed to unzip the modpack from $downloadUrl"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
mkdir -p /data/mods
|
|
|
|
if ! unzip -o -d /data/mods /tmp/modpack.zip; then
|
|
|
|
log "ERROR: failed to unzip the modpack from $downloadUrl"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
rm -f /tmp/modpack.zip
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
2018-10-12 22:11:57 +00:00
|
|
|
# If supplied with a URL for a plugin download it.
|
|
|
|
if [[ "$MODS" ]]; then
|
2020-12-12 21:22:07 +00:00
|
|
|
if [ "$TYPE" = "SPIGOT" ]; then
|
|
|
|
out_dir=/data/plugins
|
|
|
|
else
|
|
|
|
out_dir=/data/mods
|
|
|
|
fi
|
|
|
|
mkdir -p "$out_dir"
|
|
|
|
|
2020-08-03 00:57:12 +00:00
|
|
|
for i in ${MODS//,/ }
|
|
|
|
do
|
|
|
|
if isURL $i; then
|
2020-12-12 21:22:07 +00:00
|
|
|
log "Downloading mod/plugin $i ..."
|
2021-01-29 02:55:08 +00:00
|
|
|
if isValidFileURL jar "$i"; then
|
|
|
|
if ! curl -fsSL -o "${out_dir}/$(getFilenameFromUrl "${i}")" "${i}"; then
|
2020-12-12 21:22:07 +00:00
|
|
|
log "ERROR: failed to download from $i into $out_dir"
|
|
|
|
exit 2
|
2020-08-03 00:57:12 +00:00
|
|
|
fi
|
2018-10-12 22:11:57 +00:00
|
|
|
else
|
2021-01-29 02:55:08 +00:00
|
|
|
effective_url=$(resolveEffectiveUrl "$i")
|
|
|
|
if isValidFileURL jar "${effective_url}"; then
|
|
|
|
out_file=$(getFilenameFromUrl "${effective_url}")
|
|
|
|
if ! curl -fsSL -o "${out_dir}/$out_file" "${effective_url}"; then
|
|
|
|
log "ERROR: failed to download from $i into $out_dir"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
log "ERROR: $effective_url resolved from $i is not a valid jar URL"
|
|
|
|
exit 2
|
|
|
|
fi
|
2018-10-12 22:11:57 +00:00
|
|
|
fi
|
2021-05-13 01:41:28 +00:00
|
|
|
elif [[ -f "$i" && "$i" =~ .*\.jar ]]; then
|
2021-05-06 21:27:30 +00:00
|
|
|
log "Copying plugin located at $i ..."
|
|
|
|
out_file=$(basename "$i")
|
|
|
|
if ! cp "$i" "${out_dir}/$out_file"; then
|
|
|
|
log "ERROR: failed to copy from $i into $out_dir"
|
|
|
|
exit 2
|
|
|
|
fi
|
2021-05-13 01:41:28 +00:00
|
|
|
elif [[ -d "$i" ]]; then
|
|
|
|
log "Copying plugin jars from $i ..."
|
|
|
|
cp "$i"/*.jar "${out_dir}"
|
2020-08-03 00:57:12 +00:00
|
|
|
else
|
2021-05-13 01:41:28 +00:00
|
|
|
log "ERROR Invalid URL or path given in MODS: $i"
|
2020-12-12 21:22:07 +00:00
|
|
|
exit 2
|
2020-08-03 00:57:12 +00:00
|
|
|
fi
|
|
|
|
done
|
2018-10-12 22:11:57 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-08 13:11:01 +00:00
|
|
|
if [[ "$MANIFEST" ]]; then
|
2019-11-21 19:50:06 +00:00
|
|
|
if [[ -e "$MANIFEST" ]]; then
|
|
|
|
EFFECTIVE_MANIFEST_FILE=$MANIFEST
|
|
|
|
elif isURL "$MANIFEST"; then
|
|
|
|
EFFECTIVE_MANIFEST_FILE=/tmp/manifest.json
|
2020-12-12 21:22:07 +00:00
|
|
|
EFFECTIVE_MANIFEST_URL=$(curl -Ls -o /dev/null -w %{effective_url} $MANIFEST)
|
2019-11-21 19:50:06 +00:00
|
|
|
curl -Ls -o $EFFECTIVE_MANIFEST_FILE "$EFFECTIVE_MANIFEST_URL"
|
|
|
|
else
|
2020-03-06 15:52:17 +00:00
|
|
|
log "MANIFEST='$MANIFEST' is not a valid manifest url or location"
|
2019-11-21 19:50:06 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "X$EFFECTIVE_MANIFEST_FILE" in
|
2019-02-08 13:11:01 +00:00
|
|
|
X*.json)
|
2019-11-21 19:50:06 +00:00
|
|
|
if [ -f "${EFFECTIVE_MANIFEST_FILE}" ]; then
|
2019-02-15 03:04:09 +00:00
|
|
|
MOD_DIR=${FTB_BASE_DIR:-/data}/mods
|
2019-02-15 03:18:16 +00:00
|
|
|
if [ ! -d "$MOD_DIR" ]
|
|
|
|
then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Creating mods dir $MOD_DIR"
|
2019-02-15 03:18:16 +00:00
|
|
|
mkdir -p "$MOD_DIR"
|
|
|
|
fi
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Starting manifest download..."
|
2019-11-21 19:50:06 +00:00
|
|
|
cat "${EFFECTIVE_MANIFEST_FILE}" | jq -r '.files[] | (.projectID|tostring) + " " + (.fileID|tostring)'| while read -r p f
|
2019-02-08 13:11:01 +00:00
|
|
|
do
|
2019-02-08 16:31:40 +00:00
|
|
|
if [ ! -f $MOD_DIR/${p}_${f}.jar ]
|
|
|
|
then
|
2020-12-12 21:22:07 +00:00
|
|
|
redirect_url="$(curl -Ls -o /dev/null -w %{effective_url} ${CURSE_URL_BASE}/${p})"
|
2019-08-02 16:28:35 +00:00
|
|
|
url="$redirect_url/download/${f}/file"
|
2020-03-06 15:52:17 +00:00
|
|
|
log Downloading curseforge mod $url
|
2019-02-08 16:31:40 +00:00
|
|
|
# Manifest usually doesn't have mod names. Using id should be fine, tho
|
|
|
|
curl -sSL "${url}" -o $MOD_DIR/${p}_${f}.jar
|
|
|
|
fi
|
2019-02-08 13:11:01 +00:00
|
|
|
done
|
|
|
|
else
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Could not find manifest file, unsufficient privs, or malformed path."
|
2019-02-08 13:11:01 +00:00
|
|
|
fi
|
2019-02-08 13:18:18 +00:00
|
|
|
;;
|
2019-02-08 13:11:01 +00:00
|
|
|
*)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Invalid manifest file for modpack. Please make sure it is a .json file."
|
2019-02-08 13:11:01 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2019-09-29 16:45:21 +00:00
|
|
|
if [[ "${GENERIC_PACK}" ]]; then
|
|
|
|
if isURL "${GENERIC_PACK}"; then
|
2020-12-12 03:12:44 +00:00
|
|
|
log "Downloading generic pack ..."
|
|
|
|
curl -fsSL -o /tmp/generic_pack.zip "${GENERIC_PACK}"
|
|
|
|
GENERIC_PACK=/tmp/generic_pack.zip
|
2019-09-29 16:45:21 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
sum_file=/data/.generic_pack.sum
|
|
|
|
if ! sha256sum -c ${sum_file} -s 2> /dev/null; then
|
|
|
|
base_dir=/tmp/generic_pack_base
|
|
|
|
mkdir -p ${base_dir}
|
2020-12-29 16:56:05 +00:00
|
|
|
isDebugging && ls -l "${GENERIC_PACK}"
|
|
|
|
unzip -q -d ${base_dir} "${GENERIC_PACK}"
|
2020-04-12 14:39:28 +00:00
|
|
|
if [ -f /data/manifest.txt ]; then
|
|
|
|
log "Manifest exists from older generic pack, cleaning up ..."
|
|
|
|
while read f; do
|
|
|
|
rm -rf "/data/${f}"
|
|
|
|
done < /data/manifest.txt
|
|
|
|
find /data/* -type d -exec rmdir --ignore-fail-on-non-empty {} +
|
|
|
|
rm -f /data/manifest.txt
|
|
|
|
fi
|
|
|
|
log "Writing generic pack manifest ... "
|
|
|
|
find ${base_dir} -type f -print0 | xargs -0 -I {} echo "{}" | sed "s#${base_dir}/##" > /data/manifest.txt
|
|
|
|
log "Applying generic pack ..."
|
|
|
|
IFS='
|
|
|
|
'
|
|
|
|
set -f
|
|
|
|
for d in $(find ${base_dir} -type d); do mkdir -p "$(sed "s#${base_dir}#/data#" <<< $d)"; done
|
|
|
|
for f in $(find ${base_dir} -type f); do cp -f "$f" "$(sed "s#${base_dir}#/data#" <<< $f)"; done
|
2019-09-29 16:45:21 +00:00
|
|
|
rm -rf ${base_dir}
|
2020-12-29 16:56:05 +00:00
|
|
|
sha256sum "${GENERIC_PACK}" > ${sum_file}
|
2019-09-29 16:45:21 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-07-06 22:16:51 +00:00
|
|
|
exec ${SCRIPTS:-/}start-finalSetupModconfig $@
|