2020-05-31 23:18:54 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-07-26 13:35:13 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
. ${SCRIPTS:-/}start-utils
|
2020-08-19 01:44:11 +00:00
|
|
|
isDebugging && set -x
|
2020-05-31 23:18:54 +00:00
|
|
|
|
2020-12-31 19:11:26 +00:00
|
|
|
: ${FTB_BASE_DIR:=${CF_BASE_DIR:-/data/FeedTheBeast}}
|
|
|
|
export FTB_BASE_DIR
|
|
|
|
|
2020-10-15 02:21:40 +00:00
|
|
|
legacyJavaFixerUrl=https://ftb.forgecdn.net/FTB2/maven/net/minecraftforge/lex/legacyjavafixer/1.0/legacyjavafixer-1.0.jar
|
2020-05-31 23:18:54 +00:00
|
|
|
export TYPE=CURSEFORGE
|
|
|
|
|
|
|
|
FTB_SERVER_MOD=${FTB_SERVER_MOD:-$CF_SERVER_MOD}
|
|
|
|
|
2020-07-26 13:35:13 +00:00
|
|
|
log "Looking for Feed-The-Beast / CurseForge server modpack."
|
|
|
|
requireVar FTB_SERVER_MOD
|
|
|
|
|
|
|
|
if ! isTrue ${USE_MODPACK_START_SCRIPT:-true}; then
|
2020-08-19 01:44:11 +00:00
|
|
|
if ! [ -f "${FTB_SERVER_MOD}" ]; then
|
2020-07-26 13:35:13 +00:00
|
|
|
log "ERROR unable to find requested modpack file ${FTB_SERVER_MOD}"
|
2020-05-31 23:18:54 +00:00
|
|
|
exit 2
|
2020-07-26 13:35:13 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
needsInstall=true
|
|
|
|
installMarker=/data/.curseforge-installed
|
|
|
|
if [ -f $installMarker ]; then
|
|
|
|
if [ "$(cat $installMarker)" != "${FTB_SERVER_MOD}" ]; then
|
|
|
|
log "Upgrading modpack"
|
|
|
|
|
|
|
|
serverJar=$(find ${FTB_BASE_DIR} -not -name "forge*installer.jar" -name "forge*.jar")
|
|
|
|
if [[ "${serverJar}" ]]; then
|
2020-09-27 15:27:46 +00:00
|
|
|
rm -rf $(dirname "${serverJar}")/{mods,*.jar,libraries,resources,scripts,config}
|
2020-07-26 13:35:13 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
needsInstall=false
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $needsInstall; then
|
|
|
|
log "Unpacking FTB server modpack ${FTB_SERVER_MOD} ..."
|
|
|
|
mkdir -p ${FTB_BASE_DIR}
|
2020-08-19 01:44:11 +00:00
|
|
|
unzip -o "${FTB_SERVER_MOD}" -d ${FTB_BASE_DIR} | awk '{printf "."} END {print ""}'
|
|
|
|
|
|
|
|
serverJar=$(find ${FTB_BASE_DIR} -path "*/libraries/*" -prune -type f -o -not -name "forge*installer.jar" -name "forge*.jar")
|
|
|
|
if [[ -z "$serverJar" ]]; then
|
|
|
|
forgeInstallerJar=$(find ${FTB_BASE_DIR} -name "forge*installer.jar")
|
|
|
|
if [[ -z "${forgeInstallerJar}" ]]; then
|
|
|
|
log "ERROR Unable to find forge installer in modpack."
|
|
|
|
log " Make sure you downloaded the server files."
|
|
|
|
exit 2
|
|
|
|
fi
|
2020-07-26 13:35:13 +00:00
|
|
|
|
2020-08-19 01:44:11 +00:00
|
|
|
log "Installing forge server"
|
|
|
|
(cd $(dirname "${forgeInstallerJar}"); java -jar $(basename "${forgeInstallerJar}") --installServer) | awk '{printf "."} END {print ""}'
|
2020-07-26 13:35:13 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${FTB_SERVER_MOD}" > $installMarker
|
|
|
|
fi
|
|
|
|
|
2020-08-19 01:44:11 +00:00
|
|
|
export SERVER=$(find ${FTB_BASE_DIR} -path "*/libraries/*" -prune -type f -o -not -name "forge*installer.jar" -name "forge*.jar")
|
2020-07-26 13:35:13 +00:00
|
|
|
if [[ -z "${SERVER}" || ! -f "${SERVER}" ]]; then
|
|
|
|
log "ERROR unable to locate installed forge server jar"
|
|
|
|
isDebugging && find ${FTB_BASE_DIR} -name "forge*.jar"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
export FTB_DIR=$(dirname "${SERVER}")
|
|
|
|
|
|
|
|
exec ${SCRIPTS:-/}start-finalSetupWorld $@
|
2020-05-31 23:18:54 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-26 13:35:13 +00:00
|
|
|
entryScriptExpr="
|
|
|
|
-name ServerStart.sh
|
|
|
|
-o -name serverstart.sh
|
|
|
|
-o -name ServerStartLinux.sh
|
|
|
|
-o -name LaunchServer.sh
|
|
|
|
-o -name server-start.sh
|
|
|
|
-o -name startserver.sh
|
|
|
|
-o -name StartServer.sh
|
|
|
|
"
|
2020-05-31 23:18:54 +00:00
|
|
|
|
|
|
|
if [[ -d ${FTB_BASE_DIR} ]]; then
|
|
|
|
startScriptCount=$(find ${FTB_BASE_DIR} $entryScriptExpr |wc -l)
|
|
|
|
if [[ $startScriptCount > 1 ]]; then
|
|
|
|
log "Conflicting FTB/CurseForge packages have been installed. Please cleanup ${FTB_BASE_DIR}"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
startScriptCount=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# only download and install if a mod pack isn't already installed
|
|
|
|
# also check for the start script rather than just the folder
|
|
|
|
# this allows saving just the world separate from the rest of the data directory
|
|
|
|
if [[ $startScriptCount = 0 ]]; then
|
|
|
|
srv_modpack=${FTB_SERVER_MOD}
|
2020-08-19 01:44:11 +00:00
|
|
|
if isURL "${srv_modpack}"; then
|
2020-05-31 23:18:54 +00:00
|
|
|
case $srv_modpack in
|
|
|
|
https://www.feed-the-beast.com/*/download|https://www.curseforge.com/minecraft/modpacks/*/download/*/file)
|
|
|
|
;;
|
|
|
|
https://www.curseforge.com/minecraft/modpacks/*/download/*)
|
|
|
|
srv_modpack=${srv_modpack}/file;;
|
|
|
|
https://www.feed-the-beast.com/*)
|
|
|
|
srv_modpack=${srv_modpack}/download;;
|
|
|
|
esac
|
|
|
|
file=$(basename $(dirname $srv_modpack))
|
|
|
|
downloaded=/data/${file}.zip
|
|
|
|
if [ ! -e $downloaded ]; then
|
|
|
|
log "Downloading FTB modpack...
|
|
|
|
$srv_modpack -> $downloaded"
|
|
|
|
curl -sSL -o $downloaded $srv_modpack
|
|
|
|
fi
|
|
|
|
srv_modpack=$downloaded
|
|
|
|
fi
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ "${srv_modpack:0:5}" == "data/" ]]; then
|
2020-05-31 23:18:54 +00:00
|
|
|
# Prepend with "/"
|
2020-08-19 01:44:11 +00:00
|
|
|
srv_modpack="/${srv_modpack}"
|
2020-05-31 23:18:54 +00:00
|
|
|
fi
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ ! "${srv_modpack:0:1}" == "/" ]]; then
|
2020-05-31 23:18:54 +00:00
|
|
|
# If not an absolute path, assume file is in "/data"
|
|
|
|
srv_modpack=/data/${srv_modpack}
|
|
|
|
fi
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ ! -f "${srv_modpack}" ]]; then
|
2020-05-31 23:18:54 +00:00
|
|
|
log "FTB server modpack ${srv_modpack} not found."
|
|
|
|
exit 2
|
|
|
|
fi
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ ! "${srv_modpack: -4}" == ".zip" ]]; then
|
2020-05-31 23:18:54 +00:00
|
|
|
log "FTB server modpack ${srv_modpack} is not a zip archive."
|
|
|
|
log "Please set FTB_SERVER_MOD to a file with a .zip extension."
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
log "Unpacking FTB server modpack ${srv_modpack} ..."
|
|
|
|
mkdir -p ${FTB_BASE_DIR}
|
2020-08-19 01:44:11 +00:00
|
|
|
unzip -o "${srv_modpack}" -d ${FTB_BASE_DIR} | awk '{printf "."} END {print ""}'
|
2020-05-31 23:18:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $(find ${FTB_BASE_DIR} $entryScriptExpr | wc -l) = 0 ]]; then
|
|
|
|
|
|
|
|
# Allow up to 2 levels since some modpacks have a top-level directory named
|
|
|
|
# for the modpack
|
|
|
|
forgeJar=$(find ${FTB_BASE_DIR} -maxdepth 2 -name 'forge*.jar' -a -not -name 'forge*installer')
|
|
|
|
if [[ "$forgeJar" ]]; then
|
|
|
|
export FTB_BASE_DIR=$(dirname "${forgeJar}")
|
|
|
|
log "No entry script found, so building one for ${forgeJar}"
|
|
|
|
cat > "${FTB_BASE_DIR}/ServerStart.sh" <<EOF
|
|
|
|
#!/bin/sh
|
|
|
|
. ./settings-local.sh
|
|
|
|
java \${JAVA_PARAMETERS} -Xmx\${MAX_RAM} -jar $(basename "${forgeJar}") nogui
|
|
|
|
EOF
|
|
|
|
chmod +x "${FTB_BASE_DIR}/ServerStart.sh"
|
|
|
|
else
|
|
|
|
log "Please make sure you are using the server version of the FTB modpack!"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
scriptCount=$(find "${FTB_BASE_DIR}" $entryScriptExpr | wc -l)
|
|
|
|
if [[ $scriptCount = 0 ]]; then
|
|
|
|
log "Please make sure you are using the server version of the FTB modpack!"
|
|
|
|
exit 2
|
|
|
|
elif [[ $scriptCount > 1 ]]; then
|
|
|
|
log "Ambigous startup scripts in FTB modpack!"
|
|
|
|
log "found:"
|
|
|
|
find ${FTB_BASE_DIR} $entryScriptExpr
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
export FTB_SERVER_START=$(find "${FTB_BASE_DIR}" $entryScriptExpr)
|
|
|
|
|
|
|
|
export FTB_DIR=$(dirname "${FTB_SERVER_START}")
|
|
|
|
chmod a+x "${FTB_SERVER_START}"
|
2020-08-19 01:44:11 +00:00
|
|
|
grep fml.queryResult=confirm "${FTB_SERVER_START}" > /dev/null || \
|
2020-05-31 23:18:54 +00:00
|
|
|
sed -i 's/-jar/-Dfml.queryResult=confirm -jar/' "${FTB_SERVER_START}"
|
|
|
|
sed -i 's/.*read.*Restart now/#\0/' "${FTB_SERVER_START}"
|
|
|
|
legacyJavaFixerPath="${FTB_DIR}/mods/legacyjavafixer.jar"
|
|
|
|
|
|
|
|
if isTrue ${FTB_LEGACYJAVAFIXER} && [ ! -e "${legacyJavaFixerPath}" ]; then
|
|
|
|
log "Installing legacy java fixer to ${legacyJavaFixerPath}"
|
|
|
|
curl -sSL -o "${legacyJavaFixerPath}" ${legacyJavaFixerUrl}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "${FTB_DIR}/FTBInstall.sh" ]; then
|
|
|
|
pushd "${FTB_DIR}"
|
|
|
|
sh FTBInstall.sh
|
|
|
|
popd
|
|
|
|
elif [ -e "${FTB_DIR}/Install.sh" ]; then
|
|
|
|
pushd "${FTB_DIR}"
|
|
|
|
sh Install.sh
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Continue to Final Setup
|
2020-07-26 13:35:13 +00:00
|
|
|
exec ${SCRIPTS:-/}start-finalSetupWorld $@
|