docker-minecraft-server/start-deployForge

122 lines
3.4 KiB
Text
Raw Normal View History

2017-11-01 05:42:44 +00:00
#!/bin/bash
. ${SCRIPTS:-/}start-utils
: ${FORGEVERSION:=RECOMMENDED}
isDebugging && set -x
2017-11-01 05:42:44 +00:00
if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then
norm=$VANILLA_VERSION
case $VANILLA_VERSION in
*.*.*)
norm=$VANILLA_VERSION ;;
*.*)
norm=${VANILLA_VERSION}.0 ;;
esac
#################################################################################
2020-03-06 15:52:17 +00:00
log "Checking Forge version information."
2017-11-01 05:42:44 +00:00
case $FORGEVERSION in
RECOMMENDED)
curl -fsSL -o /tmp/forge.json http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json
FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-recommended\"]")
if [ $FORGE_VERSION = null ]; then
FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-latest\"]")
if [ $FORGE_VERSION = null ]; then
2020-03-06 15:52:17 +00:00
log "ERROR: Version $VANILLA_VERSION is not supported by Forge"
log " Refer to http://files.minecraftforge.net/ for supported versions"
2017-11-01 05:42:44 +00:00
exit 2
fi
fi
;;
*)
FORGE_VERSION=$FORGEVERSION
;;
esac
normForgeVersion=$VANILLA_VERSION-$FORGE_VERSION-$norm
shortForgeVersion=$VANILLA_VERSION-$FORGE_VERSION
FORGE_INSTALLER="/tmp/forge-$shortForgeVersion-installer.jar"
elif [[ -z $FORGE_INSTALLER ]]; then
FORGE_INSTALLER="/tmp/forge-installer.jar"
elif [[ ! -e $FORGE_INSTALLER ]]; then
2020-03-06 15:52:17 +00:00
log "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER"
2017-11-01 05:42:44 +00:00
exit 2
else
shortForgeVersion=$VANILLA_VERSION-${FORGE_INSTALLER_CUSTOM_VERSION:-custom}
2017-11-01 05:42:44 +00:00
fi
installMarker="/data/.forge-installed-$shortForgeVersion"
2017-11-01 05:42:44 +00:00
if [ ! -e $installMarker ]; then
if [ ! -e $FORGE_INSTALLER ]; then
if [[ -z $FORGE_INSTALLER_URL ]]; then
2020-03-06 15:52:17 +00:00
log "Downloading $normForgeVersion"
2017-11-01 05:42:44 +00:00
forgeFileNames="
$normForgeVersion/forge-$normForgeVersion-installer.jar
$shortForgeVersion/forge-$shortForgeVersion-installer.jar
END
"
for fn in $forgeFileNames; do
if [ $fn == END ]; then
2020-03-06 15:52:17 +00:00
log "Unable to compute URL for $normForgeVersion"
2017-11-01 05:42:44 +00:00
exit 2
fi
2021-05-25 01:47:51 +00:00
downloadUrl=https://maven.minecraftforge.net/net/minecraftforge/forge/$fn
2020-03-06 15:52:17 +00:00
log "...trying $downloadUrl"
2017-11-01 05:42:44 +00:00
if curl -o $FORGE_INSTALLER -fsSL $downloadUrl; then
break
fi
done
else
2020-03-06 15:52:17 +00:00
log "Downloading $FORGE_INSTALLER_URL ..."
2017-11-01 05:42:44 +00:00
if ! curl -o $FORGE_INSTALLER -fsSL $FORGE_INSTALLER_URL; then
2020-03-06 15:52:17 +00:00
log "Failed to download from given location $FORGE_INSTALLER_URL"
2017-11-01 05:42:44 +00:00
exit 2
fi
fi
fi
2020-03-06 15:52:17 +00:00
log "Installing Forge $shortForgeVersion using $FORGE_INSTALLER"
2017-11-01 05:42:44 +00:00
mkdir -p mods
tries=3
while ((--tries >= 0)); do
java -jar $FORGE_INSTALLER --installServer
if [ $? == 0 ]; then
break
fi
done
if (($tries < 0)); then
2020-03-06 15:52:17 +00:00
log "Forge failed to install after several tries." >&2
2017-11-01 05:42:44 +00:00
exit 10
fi
# NOTE $shortForgeVersion will be empty if installer location was given to us
2020-03-06 15:52:17 +00:00
log "Finding installed server jar..."
unset -v latest
for file in *forge*.jar; do
if ! [[ $file =~ installer ]]; then
if [[ -z $latest ]] || [[ $file -nt $latest ]]; then
latest=$file
fi
fi
2017-11-01 05:42:44 +00:00
done
if [[ -z $latest ]]; then
2020-03-06 15:52:17 +00:00
log "Unable to derive server jar for Forge"
2017-11-01 05:42:44 +00:00
exit 2
fi
export SERVER=$latest
2020-03-06 15:52:17 +00:00
log "Using server $SERVER"
2017-11-01 05:42:44 +00:00
echo $SERVER > $installMarker
else
export SERVER=$(cat $installMarker)
fi
exec ${SCRIPTS:-/}start-setupWorld $@