2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-09-29 16:45:21 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
. /start-utils
|
|
|
|
|
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
|
|
|
|
if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then
|
|
|
|
if [ "$TYPE" = "SPIGOT" ]; then
|
|
|
|
rm -rf /data/plugins/*
|
|
|
|
else
|
|
|
|
rm -rf /data/mods/*
|
|
|
|
fi
|
|
|
|
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
|
2019-07-07 20:16:48 +00:00
|
|
|
EFFECTIVE_MODPACK_URL=$(curl -Ls -o /dev/null -w %{url_effective} $MODPACK)
|
|
|
|
case "X$EFFECTIVE_MODPACK_URL" in
|
2017-11-01 05:42:44 +00:00
|
|
|
X[Hh][Tt][Tt][Pp]*.zip)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Downloading mod/plugin pack via HTTP"
|
|
|
|
log " from $EFFECTIVE_MODPACK_URL ..."
|
2019-07-07 20:16:48 +00:00
|
|
|
if ! curl -sSL -o /tmp/modpack.zip "$EFFECTIVE_MODPACK_URL"; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "ERROR: failed to download from $EFFECTIVE_MODPACK_URL"
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$TYPE" = "SPIGOT" ]; then
|
|
|
|
mkdir -p /data/plugins
|
|
|
|
if ! unzip -o -d /data/plugins /tmp/modpack.zip; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "ERROR: failed to unzip the modpack from $EFFECTIVE_MODPACK_URL"
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
mkdir -p /data/mods
|
|
|
|
if ! unzip -o -d /data/mods /tmp/modpack.zip; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "ERROR: failed to unzip the modpack from $EFFECTIVE_MODPACK_URL"
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
rm -f /tmp/modpack.zip
|
|
|
|
;;
|
|
|
|
*)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Invalid URL given for modpack: Must be HTTP or HTTPS and a ZIP file"
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2018-10-12 22:11:57 +00:00
|
|
|
# If supplied with a URL for a plugin download it.
|
|
|
|
if [[ "$MODS" ]]; then
|
|
|
|
for i in ${MODS//,/ }
|
|
|
|
do
|
2019-07-07 20:16:48 +00:00
|
|
|
EFFECTIVE_MOD_URL=$(curl -Ls -o /dev/null -w %{url_effective} $i)
|
|
|
|
case "X$EFFECTIVE_MOD_URL" in
|
2018-10-12 22:11:57 +00:00
|
|
|
X[Hh][Tt][Tt][Pp]*.jar)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Downloading mod/plugin via HTTP"
|
|
|
|
log " from $EFFECTIVE_MOD_URL ..."
|
2019-07-07 20:16:48 +00:00
|
|
|
if ! curl -sSL -o /tmp/${EFFECTIVE_MOD_URL##*/} $EFFECTIVE_MOD_URL; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "ERROR: failed to download from $EFFECTIVE_MOD_URL to /tmp/${EFFECTIVE_MOD_URL##*/}"
|
2018-10-12 22:11:57 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$TYPE" = "SPIGOT" ]; then
|
|
|
|
mkdir -p /data/plugins
|
2019-07-07 20:16:48 +00:00
|
|
|
mv /tmp/${EFFECTIVE_MOD_URL##*/} /data/plugins/${EFFECTIVE_MOD_URL##*/}
|
2018-10-12 22:11:57 +00:00
|
|
|
else
|
|
|
|
mkdir -p /data/mods
|
2019-07-07 20:16:48 +00:00
|
|
|
mv /tmp/${EFFECTIVE_MOD_URL##*/} /data/mods/${EFFECTIVE_MOD_URL##*/}
|
2018-10-12 22:11:57 +00:00
|
|
|
fi
|
2019-07-07 20:16:48 +00:00
|
|
|
rm -f /tmp/${EFFECTIVE_MOD_URL##*/}
|
2018-10-12 22:11:57 +00:00
|
|
|
;;
|
|
|
|
*)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Invalid URL given for modpack: Must be HTTP or HTTPS and a JAR file"
|
2018-10-12 22:11:57 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
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
|
|
|
|
EFFECTIVE_MANIFEST_URL=$(curl -Ls -o /dev/null -w %{url_effective} $MANIFEST)
|
|
|
|
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
|
2019-08-03 12:47:41 +00:00
|
|
|
redirect_url="$(curl -Ls -o /dev/null -w %{url_effective} ${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
|
|
|
|
generic_pack_url=${GENERIC_PACK}
|
|
|
|
GENERIC_PACK=/tmp/$(basename ${generic_pack_url})
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Downloading generic pack from ${generic_pack_url} ..."
|
2019-09-29 16:45:21 +00:00
|
|
|
curl -fsSL -o ${GENERIC_PACK} ${generic_pack_url}
|
|
|
|
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}
|
|
|
|
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}
|
|
|
|
sha256sum ${GENERIC_PACK} > ${sum_file}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
exec /start-finalSetup03Modconfig $@
|