2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-10-17 03:32:34 +00:00
|
|
|
: "${FORGEVERSION:=RECOMMENDED}"
|
|
|
|
|
|
|
|
# shellcheck source=start-utils
|
|
|
|
. "${SCRIPTS:-$(dirname "$0")}/start-utils"
|
2021-03-11 22:21:59 +00:00
|
|
|
isDebugging && set -x
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2021-10-03 00:20:08 +00:00
|
|
|
get_installer() {
|
|
|
|
if [[ -z $FORGE_INSTALLER_URL ]]; then
|
|
|
|
log "Downloading $normForgeVersion"
|
|
|
|
|
|
|
|
forgeFileNames="
|
|
|
|
$shortForgeVersion/forge-$shortForgeVersion-installer.jar
|
2021-11-21 20:58:55 +00:00
|
|
|
$normForgeVersion/forge-$normForgeVersion-installer.jar
|
2021-10-03 00:20:08 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
for fn in $forgeFileNames; do
|
|
|
|
downloadUrl=https://maven.minecraftforge.net/net/minecraftforge/forge/$fn
|
|
|
|
log "...trying $downloadUrl"
|
2021-10-17 03:32:34 +00:00
|
|
|
if get -o "$FORGE_INSTALLER" "$downloadUrl"; then
|
2021-10-03 00:20:08 +00:00
|
|
|
return
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
2021-10-03 00:20:08 +00:00
|
|
|
done
|
|
|
|
log "Unable to locate usable URL for $normForgeVersion"
|
|
|
|
exit 2
|
|
|
|
else
|
|
|
|
log "Downloading $FORGE_INSTALLER_URL ..."
|
2021-10-17 03:32:34 +00:00
|
|
|
if ! get -o "$FORGE_INSTALLER" "$FORGE_INSTALLER_URL"; then
|
2021-10-03 00:20:08 +00:00
|
|
|
log "Failed to download from given location $FORGE_INSTALLER_URL"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2021-10-03 00:20:08 +00:00
|
|
|
install() {
|
2021-10-17 03:32:34 +00:00
|
|
|
if [ ! -e "$FORGE_INSTALLER" ]; then
|
|
|
|
get_installer "$normForgeVersion" "$shortForgeVersion"
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
2022-04-15 03:03:34 +00:00
|
|
|
# reference issue #1459
|
|
|
|
rm -f run.sh
|
|
|
|
|
2022-01-29 20:53:34 +00:00
|
|
|
log "Installing Forge $shortForgeVersion. This might take a minute or two..."
|
2017-11-01 05:42:44 +00:00
|
|
|
mkdir -p mods
|
|
|
|
tries=3
|
2022-01-29 20:53:34 +00:00
|
|
|
while true; do
|
|
|
|
if ! java -jar "$FORGE_INSTALLER" --installServer &> forge-installer.log; then
|
|
|
|
if ((--tries <= 0)); then
|
|
|
|
cat forge-installer.log
|
|
|
|
log "
|
|
|
|
ERROR Forge failed to install after several tries.
|
|
|
|
"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
log "Install failed. Trying again..."
|
|
|
|
else
|
|
|
|
break # out of this loop
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
# 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..."
|
2018-04-26 01:48:42 +00:00
|
|
|
unset -v latest
|
2021-10-20 20:36:02 +00:00
|
|
|
# 1.17+ ?
|
|
|
|
if [ -f /data/run.sh ]; then
|
|
|
|
latest=/data/run.sh
|
|
|
|
# else pre 1.17
|
|
|
|
else
|
|
|
|
for file in *forge*.jar; do
|
|
|
|
if ! [[ $file =~ installer ]]; then
|
|
|
|
if [[ -z $latest ]] || [[ $file -nt $latest ]]; then
|
|
|
|
latest=$file
|
|
|
|
fi
|
2021-03-12 01:40:11 +00:00
|
|
|
fi
|
2021-10-20 20:36:02 +00:00
|
|
|
done
|
|
|
|
fi
|
2018-04-26 01:48:42 +00:00
|
|
|
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
|
|
|
|
|
2018-04-26 01:48:42 +00:00
|
|
|
export SERVER=$latest
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Using server $SERVER"
|
2021-10-20 20:36:02 +00:00
|
|
|
debug "Writing install marker at $installMarker"
|
2021-10-17 03:32:34 +00:00
|
|
|
echo "$SERVER" > "$installMarker"
|
2021-10-03 00:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resolve_versions() {
|
|
|
|
if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then
|
|
|
|
norm=$VANILLA_VERSION
|
|
|
|
|
|
|
|
case $VANILLA_VERSION in
|
|
|
|
*.*.*)
|
|
|
|
norm=$VANILLA_VERSION ;;
|
|
|
|
*.*)
|
|
|
|
norm=${VANILLA_VERSION}.0 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
#################################################################################
|
2021-10-17 03:32:34 +00:00
|
|
|
promosUrl=http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json
|
2021-10-03 00:20:08 +00:00
|
|
|
|
|
|
|
log "Checking Forge version information."
|
|
|
|
case $FORGEVERSION in
|
2021-10-17 03:32:34 +00:00
|
|
|
LATEST)
|
2022-02-27 03:28:30 +00:00
|
|
|
if ! FORGE_VERSION=$(get --json-path ".promos['$VANILLA_VERSION-latest']" --json-value-when-missing "" "$promosUrl"); then
|
2021-10-17 03:32:34 +00:00
|
|
|
log "ERROR: Version $VANILLA_VERSION is not supported by Forge"
|
|
|
|
log " Refer to http://files.minecraftforge.net/ for supported versions"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2021-10-03 00:20:08 +00:00
|
|
|
RECOMMENDED)
|
2022-02-27 03:28:30 +00:00
|
|
|
if ! FORGE_VERSION=$(get -s --json-path ".promos['$VANILLA_VERSION-recommended']" --json-value-when-missing "" "$promosUrl"); then
|
|
|
|
if ! FORGE_VERSION=$(get --json-path ".promos['$VANILLA_VERSION-latest']" --json-value-when-missing "" "$promosUrl"); then
|
2021-10-03 00:20:08 +00:00
|
|
|
log "ERROR: Version $VANILLA_VERSION is not supported by Forge"
|
|
|
|
log " Refer to http://files.minecraftforge.net/ for supported versions"
|
|
|
|
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
|
|
|
|
log "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER"
|
|
|
|
exit 2
|
|
|
|
else
|
|
|
|
shortForgeVersion=$VANILLA_VERSION-${FORGE_INSTALLER_CUSTOM_VERSION:-custom}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
### main
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2021-10-03 00:20:08 +00:00
|
|
|
resolve_versions
|
|
|
|
|
|
|
|
installMarker="/data/.forge-installed-$shortForgeVersion"
|
|
|
|
|
2021-10-23 14:33:12 +00:00
|
|
|
if [ ! -e "$installMarker" ] || isTrue "${FORCE_REINSTALL:-false}"; then
|
2021-10-03 00:20:08 +00:00
|
|
|
install
|
2017-11-01 05:42:44 +00:00
|
|
|
else
|
2021-10-17 03:32:34 +00:00
|
|
|
SERVER=$(cat "$installMarker")
|
|
|
|
export SERVER
|
2021-10-20 20:36:02 +00:00
|
|
|
if [ ! -e "$SERVER" ]; then
|
2021-10-03 00:20:08 +00:00
|
|
|
rm "$installMarker"
|
|
|
|
install
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
2021-12-11 02:50:40 +00:00
|
|
|
export FAMILY=FORGE
|
2022-01-29 20:53:34 +00:00
|
|
|
|
2021-10-20 20:36:02 +00:00
|
|
|
exec "${SCRIPTS:-/}start-setupWorld" "$@"
|