2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-07-19 20:01:19 +00:00
|
|
|
set -e
|
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
# shellcheck source=start-utils
|
|
|
|
. "${SCRIPTS:-/}start-utils"
|
2021-03-14 20:02:40 +00:00
|
|
|
|
|
|
|
loadForgeVars() {
|
|
|
|
cfgFile=${1?}
|
|
|
|
pat='^([^#;][^=]+)=[:space:]*([^;]*)'
|
|
|
|
while read -r line || [[ -n "$line" ]] ; do
|
|
|
|
if [[ $line =~ $pat ]]; then
|
|
|
|
#echo "MATCHED $line"
|
|
|
|
k=${BASH_REMATCH[1]}
|
|
|
|
v=${BASH_REMATCH[2]}
|
|
|
|
case $k in
|
|
|
|
FORGEURL)
|
|
|
|
forgeInstallerUrl="$v"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done < "$cfgFile"
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:44:11 +00:00
|
|
|
isDebugging && set -x
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
: "${FTB_BASE_DIR:=${CF_BASE_DIR:-/data/FeedTheBeast}}"
|
2020-12-31 19:11:26 +00:00
|
|
|
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
|
2021-04-26 13:19:50 +00:00
|
|
|
export TYPE=CURSEFORGE
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2019-01-22 03:07:38 +00:00
|
|
|
FTB_SERVER_MOD=${FTB_SERVER_MOD:-$CF_SERVER_MOD}
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Looking for Feed-The-Beast / CurseForge server modpack."
|
2020-07-19 20:01:19 +00:00
|
|
|
requireVar FTB_SERVER_MOD
|
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
if ! isTrue "${USE_MODPACK_START_SCRIPT:-true}"; then
|
2020-08-19 01:44:11 +00:00
|
|
|
if ! [ -f "${FTB_SERVER_MOD}" ]; then
|
2020-07-19 20:01:19 +00:00
|
|
|
log "ERROR unable to find requested modpack file ${FTB_SERVER_MOD}"
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 2
|
2020-07-19 20:01:19 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-19 23:10:16 +00:00
|
|
|
needsInstall=true
|
|
|
|
installMarker=/data/.curseforge-installed
|
|
|
|
if [ -f $installMarker ]; then
|
|
|
|
if [ "$(cat $installMarker)" != "${FTB_SERVER_MOD}" ]; then
|
|
|
|
log "Upgrading modpack"
|
|
|
|
|
2022-01-01 17:05:07 +00:00
|
|
|
serverJar=$(find "${FTB_BASE_DIR}" -type f \( -path "*/libraries/*" -o -path "*/mods/*" \) -prune -o -name "forge*.jar" -not -name "forge*installer.jar" -print)
|
2020-07-19 23:10:16 +00:00
|
|
|
if [[ "${serverJar}" ]]; then
|
2021-10-22 02:52:55 +00:00
|
|
|
rm -rf "$(dirname "${serverJar}")"/{mods,*.jar,libraries,resources,scripts,config}
|
2020-07-19 23:10:16 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
needsInstall=false
|
|
|
|
fi
|
2020-07-19 20:01:19 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-19 23:10:16 +00:00
|
|
|
if $needsInstall; then
|
|
|
|
log "Unpacking FTB server modpack ${FTB_SERVER_MOD} ..."
|
2021-10-22 02:52:55 +00:00
|
|
|
mkdir -p "${FTB_BASE_DIR}"
|
|
|
|
unzip -o "${FTB_SERVER_MOD}" -d "${FTB_BASE_DIR}" | awk '{printf "."} END {print ""}'
|
2020-08-19 01:44:11 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
serverJar=$(find "${FTB_BASE_DIR}" -type f \( -path "*/libraries/*" -o -path "*/mods/*" \) -prune -o -name "forge*.jar" -not -name "forge*installer.jar" -print)
|
2021-04-30 16:05:56 +00:00
|
|
|
if [[ -z "$serverJar" ]]; then
|
2021-03-14 20:02:40 +00:00
|
|
|
|
|
|
|
if [ -f "${FTB_BASE_DIR}/settings.cfg" ]; then
|
|
|
|
loadForgeVars "${FTB_BASE_DIR}/settings.cfg"
|
|
|
|
|
|
|
|
if [[ $forgeInstallerUrl ]]; then
|
|
|
|
forgeInstallerJar="${FTB_BASE_DIR}/forge-installer.jar"
|
|
|
|
if ! curl -fsSL -o "$forgeInstallerJar" "$forgeInstallerUrl" ; then
|
|
|
|
log "ERROR failed to download Forge installer from $forgeInstallerUrl"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
2021-03-19 00:56:40 +00:00
|
|
|
forgeInstallerJar=$(find "${FTB_BASE_DIR}" -name "forge*installer.jar")
|
2021-03-14 20:02:40 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ -z "${forgeInstallerJar}" ]]; then
|
2021-03-14 20:02:40 +00:00
|
|
|
log "ERROR Unable to find forge installer in modpack"
|
|
|
|
log " or download using modpack config."
|
2020-08-19 01:44:11 +00:00
|
|
|
log " Make sure you downloaded the server files."
|
|
|
|
exit 2
|
|
|
|
fi
|
2020-07-19 23:10:16 +00:00
|
|
|
|
2020-08-19 01:44:11 +00:00
|
|
|
log "Installing forge server"
|
2021-06-05 22:46:59 +00:00
|
|
|
dirOfInstaller=$(dirname "${forgeInstallerJar}")
|
2021-10-22 02:52:55 +00:00
|
|
|
(cd "${dirOfInstaller}"; java -jar "$(basename "${forgeInstallerJar}")" --installServer)
|
2020-07-19 23:10:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${FTB_SERVER_MOD}" > $installMarker
|
|
|
|
fi
|
2020-07-19 20:01:19 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
SERVER=$(find "${FTB_BASE_DIR}" -maxdepth 2 -type f \( -path "/libraries/*" -o -path "/mods/*" \) -prune -o -name "forge*.jar" -not -name "forge*installer.jar" -print)
|
2020-07-19 20:01:19 +00:00
|
|
|
if [[ -z "${SERVER}" || ! -f "${SERVER}" ]]; then
|
|
|
|
log "ERROR unable to locate installed forge server jar"
|
2021-10-22 02:52:55 +00:00
|
|
|
isDebugging && find "${FTB_BASE_DIR}" -name "forge*.jar"
|
2020-07-19 20:01:19 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2021-10-22 02:52:55 +00:00
|
|
|
export SERVER
|
2020-07-19 20:01:19 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
FTB_DIR=$(dirname "${SERVER}")
|
|
|
|
export FTB_DIR
|
2020-07-19 20:01:19 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
exec "${SCRIPTS:-/}start-setupWorld" "$@"
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
2020-05-23 14:55:38 +00:00
|
|
|
entryScriptExpr="
|
|
|
|
-name ServerStart.sh
|
2020-07-23 19:29:39 +00:00
|
|
|
-o -name serverstart.sh
|
2020-05-23 14:55:38 +00:00
|
|
|
-o -name ServerStartLinux.sh
|
|
|
|
-o -name LaunchServer.sh
|
|
|
|
-o -name server-start.sh
|
2021-05-14 22:17:07 +00:00
|
|
|
-o -name start-server.sh
|
2020-07-23 19:29:39 +00:00
|
|
|
-o -name startserver.sh
|
|
|
|
-o -name StartServer.sh
|
2020-05-23 14:55:38 +00:00
|
|
|
"
|
2019-01-22 03:07:38 +00:00
|
|
|
|
2018-08-12 22:25:16 +00:00
|
|
|
if [[ -d ${FTB_BASE_DIR} ]]; then
|
2021-10-22 02:52:55 +00:00
|
|
|
startScriptCount=$(find "${FTB_BASE_DIR}" $entryScriptExpr |wc -l)
|
|
|
|
if (( startScriptCount > 1 )); then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Conflicting FTB/CurseForge packages have been installed. Please cleanup ${FTB_BASE_DIR}"
|
2018-08-12 22:25:16 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
startScriptCount=0
|
|
|
|
fi
|
|
|
|
|
2018-05-15 01:52:49 +00:00
|
|
|
# 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
|
2018-08-12 22:25:16 +00:00
|
|
|
if [[ $startScriptCount = 0 ]]; then
|
2018-05-15 01:52:49 +00:00
|
|
|
srv_modpack=${FTB_SERVER_MOD}
|
2020-08-19 01:44:11 +00:00
|
|
|
if isURL "${srv_modpack}"; then
|
2021-10-22 02:52:55 +00:00
|
|
|
log "Downloading modpack from ${srv_modpack}..."
|
|
|
|
if ! srv_modpack=$(get -o /data --output-filename --skip-existing "${srv_modpack}"); then
|
|
|
|
log "ERROR: failed to download modpack"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-05-15 01:52:49 +00:00
|
|
|
fi
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ "${srv_modpack:0:5}" == "data/" ]]; then
|
2018-05-15 01:52:49 +00:00
|
|
|
# Prepend with "/"
|
2020-08-19 01:44:11 +00:00
|
|
|
srv_modpack="/${srv_modpack}"
|
2018-05-15 01:52:49 +00:00
|
|
|
fi
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ ! "${srv_modpack:0:1}" == "/" ]]; then
|
2018-05-15 01:52:49 +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-03-06 15:52:17 +00:00
|
|
|
log "FTB server modpack ${srv_modpack} not found."
|
2018-05-15 01:52:49 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2020-08-19 01:44:11 +00:00
|
|
|
if [[ ! "${srv_modpack: -4}" == ".zip" ]]; then
|
2020-03-06 15:52:17 +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."
|
2018-05-15 01:52:49 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Unpacking FTB server modpack ${srv_modpack} ..."
|
2021-10-22 02:52:55 +00:00
|
|
|
mkdir -p "${FTB_BASE_DIR}"
|
|
|
|
unzip -o "${srv_modpack}" -d "${FTB_BASE_DIR}" | awk '{printf "."} END {print ""}'
|
2021-04-11 15:36:17 +00:00
|
|
|
|
|
|
|
installScript=$(find "${FTB_BASE_DIR}" -maxdepth 2 -type f -name install.sh)
|
|
|
|
if [[ "$installScript" ]]; then
|
|
|
|
(
|
|
|
|
cd "$(dirname "${installScript}")"
|
|
|
|
chmod +x ./install.sh
|
|
|
|
log "Running included install.sh"
|
|
|
|
./install.sh
|
|
|
|
)
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
2018-05-15 01:52:49 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
if [[ $(find "${FTB_BASE_DIR}" $entryScriptExpr | wc -l) = 0 ]]; then
|
2019-03-11 02:50:42 +00:00
|
|
|
|
2020-04-10 15:59:07 +00:00
|
|
|
# Allow up to 2 levels since some modpacks have a top-level directory named
|
|
|
|
# for the modpack
|
2021-10-20 20:36:02 +00:00
|
|
|
forgeJar=$(find "${FTB_BASE_DIR}" -maxdepth 2 -type f \( -path "/libraries/*" -o -path "/mods/*" \) -prune -o -name "forge*.jar" -not -name "forge*installer.jar" -print)
|
2019-06-08 21:47:28 +00:00
|
|
|
if [[ "$forgeJar" ]]; then
|
2021-10-22 02:52:55 +00:00
|
|
|
FTB_BASE_DIR=$(dirname "${forgeJar}")
|
|
|
|
export FTB_BASE_DIR
|
2020-03-06 15:52:17 +00:00
|
|
|
log "No entry script found, so building one for ${forgeJar}"
|
2019-07-01 23:19:50 +00:00
|
|
|
cat > "${FTB_BASE_DIR}/ServerStart.sh" <<EOF
|
2019-03-11 02:50:42 +00:00
|
|
|
#!/bin/sh
|
|
|
|
. ./settings-local.sh
|
2019-07-01 23:19:50 +00:00
|
|
|
java \${JAVA_PARAMETERS} -Xmx\${MAX_RAM} -jar $(basename "${forgeJar}") nogui
|
2019-03-11 02:50:42 +00:00
|
|
|
EOF
|
2019-07-01 23:19:50 +00:00
|
|
|
chmod +x "${FTB_BASE_DIR}/ServerStart.sh"
|
2019-03-11 02:50:42 +00:00
|
|
|
else
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Please make sure you are using the server version of the FTB modpack!"
|
2019-03-11 02:50:42 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2018-08-14 15:45:51 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-01 23:19:50 +00:00
|
|
|
scriptCount=$(find "${FTB_BASE_DIR}" $entryScriptExpr | wc -l)
|
2019-06-08 21:47:28 +00:00
|
|
|
if [[ $scriptCount = 0 ]]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Please make sure you are using the server version of the FTB modpack!"
|
2018-09-30 19:39:37 +00:00
|
|
|
exit 2
|
2021-10-22 02:52:55 +00:00
|
|
|
elif (( scriptCount > 1 )); then
|
|
|
|
log "Ambiguous startup scripts in FTB modpack! Found:"
|
|
|
|
find "${FTB_BASE_DIR}" $entryScriptExpr
|
2019-06-08 21:47:28 +00:00
|
|
|
exit 2
|
2018-09-30 19:39:37 +00:00
|
|
|
fi
|
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
FTB_SERVER_START=$(find "${FTB_BASE_DIR}" $entryScriptExpr)
|
|
|
|
export FTB_SERVER_START
|
2019-06-08 21:47:28 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
FTB_DIR=$(dirname "${FTB_SERVER_START}")
|
|
|
|
export FTB_DIR
|
2019-06-08 21:47:28 +00:00
|
|
|
chmod a+x "${FTB_SERVER_START}"
|
2020-08-19 01:44:11 +00:00
|
|
|
grep fml.queryResult=confirm "${FTB_SERVER_START}" > /dev/null || \
|
2020-03-29 13:55:53 +00:00
|
|
|
sed -i 's/-jar/-Dfml.queryResult=confirm -jar/' "${FTB_SERVER_START}"
|
2019-06-08 21:47:28 +00:00
|
|
|
sed -i 's/.*read.*Restart now/#\0/' "${FTB_SERVER_START}"
|
|
|
|
legacyJavaFixerPath="${FTB_DIR}/mods/legacyjavafixer.jar"
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2021-10-22 02:52:55 +00:00
|
|
|
if isTrue "${FTB_LEGACYJAVAFIXER}" && [ ! -e "${legacyJavaFixerPath}" ]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Installing legacy java fixer to ${legacyJavaFixerPath}"
|
2021-10-22 02:52:55 +00:00
|
|
|
if ! get -o "${legacyJavaFixerPath}" ${legacyJavaFixerUrl}; then
|
|
|
|
log "ERROR failed to download legacy java fixer from ${legacyJavaFixerUrl}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-01-07 23:18:45 +00:00
|
|
|
fi
|
|
|
|
|
2019-06-08 21:47:28 +00:00
|
|
|
if [ -e "${FTB_DIR}/FTBInstall.sh" ]; then
|
|
|
|
pushd "${FTB_DIR}"
|
2018-09-18 23:27:34 +00:00
|
|
|
sh FTBInstall.sh
|
2018-07-14 03:33:55 +00:00
|
|
|
popd
|
2019-06-08 21:47:28 +00:00
|
|
|
elif [ -e "${FTB_DIR}/Install.sh" ]; then
|
|
|
|
pushd "${FTB_DIR}"
|
2018-09-18 23:27:34 +00:00
|
|
|
sh Install.sh
|
2018-07-14 03:33:55 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2021-12-11 02:50:40 +00:00
|
|
|
export FAMILY=FORGE
|
2021-10-22 02:52:55 +00:00
|
|
|
exec "${SCRIPTS:-/}start-setupWorld" "$@"
|