Changed MODPACK and MODS to only resolve effective URL when needed

For #592
This commit is contained in:
Geoff Bourne
2020-08-02 19:57:12 -05:00
parent 49d9f4a89d
commit c359a0f2ac
+42 -24
View File
@@ -18,42 +18,60 @@ fi
# If supplied with a URL for a modpack (simple zip of jars), download it and unpack # If supplied with a URL for a modpack (simple zip of jars), download it and unpack
if [[ "$MODPACK" ]]; then if [[ "$MODPACK" ]]; then
EFFECTIVE_MODPACK_URL=$(curl -Ls -o /dev/null -w %{url_effective} $MODPACK) if isURL "${MODPACK}"; then
case "X$EFFECTIVE_MODPACK_URL" in if [[ "${MODPACK}" == *.zip ]]; then
X[Hh][Tt][Tt][Pp]*.zip) downloadUrl="${MODPACK}"
else
downloadUrl=$(curl -Ls -o /dev/null -w %{url_effective} $MODPACK)
if ! [[ $downloadUrl == *.zip ]]; then
log "ERROR Invalid URL given for MODPACK: $downloadUrl resolved from $MODPACK"
log " Must be HTTP or HTTPS and a ZIP file"
exit 1
fi
fi
log "Downloading mod/plugin pack via HTTP" log "Downloading mod/plugin pack via HTTP"
log " from $EFFECTIVE_MODPACK_URL ..." log " from $downloadUrl ..."
if ! curl -sSL -o /tmp/modpack.zip "$EFFECTIVE_MODPACK_URL"; then if ! curl -sSL -o /tmp/modpack.zip "$downloadUrl"; then
log "ERROR: failed to download from $EFFECTIVE_MODPACK_URL" log "ERROR: failed to download from $downloadUrl"
exit 2 exit 2
fi fi
if [ "$TYPE" = "SPIGOT" ]; then if [ "$TYPE" = "SPIGOT" ]; then
mkdir -p /data/plugins mkdir -p /data/plugins
if ! unzip -o -d /data/plugins /tmp/modpack.zip; then if ! unzip -o -d /data/plugins /tmp/modpack.zip; then
log "ERROR: failed to unzip the modpack from $EFFECTIVE_MODPACK_URL" log "ERROR: failed to unzip the modpack from $downloadUrl"
fi fi
else else
mkdir -p /data/mods mkdir -p /data/mods
if ! unzip -o -d /data/mods /tmp/modpack.zip; then if ! unzip -o -d /data/mods /tmp/modpack.zip; then
log "ERROR: failed to unzip the modpack from $EFFECTIVE_MODPACK_URL" log "ERROR: failed to unzip the modpack from $downloadUrl"
fi fi
fi fi
rm -f /tmp/modpack.zip rm -f /tmp/modpack.zip
;;
*) else
log "Invalid URL given for modpack: Must be HTTP or HTTPS and a ZIP file" log "ERROR Invalid URL given for MODPACK: $MODPACK"
;; exit 1
esac fi
fi fi
# If supplied with a URL for a plugin download it. # If supplied with a URL for a plugin download it.
if [[ "$MODS" ]]; then if [[ "$MODS" ]]; then
for i in ${MODS//,/ } for i in ${MODS//,/ }
do do
EFFECTIVE_MOD_URL=$(curl -Ls -o /dev/null -w %{url_effective} $i) if isURL $i; then
case "X$EFFECTIVE_MOD_URL" in if [[ $i == *.jar ]]; then
X[Hh][Tt][Tt][Pp]*.jar) EFFECTIVE_MOD_URL=$i
else
EFFECTIVE_MOD_URL=$(curl -Ls -o /dev/null -w %{url_effective} $i)
if ! [[ $EFFECTIVE_MOD_URL == *.jar ]]; then
log "ERROR Invalid URL given in MODS: $EFFECTIVE_MOD_URL resolved from $i"
log " Must be HTTP or HTTPS and a JAR file"
exit 1
fi
fi
log "Downloading mod/plugin via HTTP" log "Downloading mod/plugin via HTTP"
log " from $EFFECTIVE_MOD_URL ..." log " from $EFFECTIVE_MOD_URL ..."
if ! curl -sSL -o /tmp/${EFFECTIVE_MOD_URL##*/} $EFFECTIVE_MOD_URL; then if ! curl -sSL -o /tmp/${EFFECTIVE_MOD_URL##*/} $EFFECTIVE_MOD_URL; then
@@ -69,12 +87,12 @@ do
mv /tmp/${EFFECTIVE_MOD_URL##*/} /data/mods/${EFFECTIVE_MOD_URL##*/} mv /tmp/${EFFECTIVE_MOD_URL##*/} /data/mods/${EFFECTIVE_MOD_URL##*/}
fi fi
rm -f /tmp/${EFFECTIVE_MOD_URL##*/} rm -f /tmp/${EFFECTIVE_MOD_URL##*/}
;;
*) else
log "Invalid URL given for modpack: Must be HTTP or HTTPS and a JAR file" log "ERROR Invalid URL given in MODS: $i"
;; exit 1
esac fi
done done
fi fi
if [[ "$MANIFEST" ]]; then if [[ "$MANIFEST" ]]; then