remove old script, moved to init

This commit is contained in:
Jeremy McClure 2025-03-30 00:46:21 -04:00
parent f325f54ee9
commit 8dafd475ba
Signed by: jeremy
GPG Key ID: CA27BD8443157067

View File

@ -1,160 +0,0 @@
#!/bin/env bash
MC_LOADER="${MC_LOADER:-"paper"}"
MC_VERSION=${MC_VERSION:-"1.21.4"}
JAVA_VERSION=${JAVA_VERSION:-"temurin@21"}
JAR=${JAR:-"server.jar"}
MEM=${MEMORY:-2G}
ADD_ARGS=${ADD_ARGS:-""}
RESTART=${RESTART:-"true"}
crash() {
sleep 5
exit 1
}
setEula() {
echo "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA)." >eula.txt
echo "eula=true" >>eula.txt
}
javaCheck() {
JAVA_HOME=/data/java/${JAVA_VERSION}
if [[ -f "$HOME/.jabba/jabba.sh" ]]; then
source $HOME/.jabba/jabba.sh
else
echo "Something went wrong with locating jabba(the java installer)"
exit 0
fi
if [[ ! -n "${JAVA_VERSION}" ]]; then
echo "NO JAVA_VERSION ENVIRONMENT VARIABLE SET SET IT"
crash
fi
if [[ ! -f "/data/java/${JAVA_VERSION}/bin/java" ]]; then
rm -rf /data/java/${JAVA_VERSION}
jabba install ${JAVA_VERSION} -o /data/java/${JAVA_VERSION}
fi
PATH=${JAVA_HOME}/bin:$PATH
JAVA="java"
}
getPaper() {
LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${MC_LOADER}/versions/${MC_VERSION}/builds |
jq -r '.builds | map(select(.channel == "default") | .build) | .[-1]')
if [ "$LATEST_BUILD" != "null" ]; then
JAR_NAME=${MC_LOADER}-${MC_VERSION}-${LATEST_BUILD}.jar
PAPERMC_URL="https://api.papermc.io/v2/projects/${MC_LOADER}/versions/${MC_VERSION}/builds/${LATEST_BUILD}/downloads/${JAR_NAME}"
# Download the latest Paper version
curl -o server.jar $PAPERMC_URL
echo "Download completed"
echo "Minecraft Version: ${MC_VERSION}"
echo "Paper Version: ${LATEST_BUILD}"
else
echo "No stable build for version $MC_VERSION found :("
fi
}
getFabric() {
LATEST_BUILD=$(curl -s https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION} | jq -s '.[] .[0] .loader .version' | tr -d '"')
LATEST_INSTALLER=$(curl -s https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml | xmllint --xpath "/metadata/versioning/latest/text()" -)
DL_URL=https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}/${LATEST_BUILD}/${LATEST_INSTALLER}/server/jar
if [ "$LATEST_BUILD" != "null" ]; then
echo "$DL_URL"
curl -o server.jar ${DL_URL}
else
echo "TODO ERROR TEXT"
fi
}
getForge() {
LATEST_BUILD=$(curl -s https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json | jq -r ".promos[\"${MC_VERSION}-latest\"]")
DL_BUILD=${MC_VERSION}-${LATEST_BUILD}
DL_URL=https://maven.minecraftforge.net/net/minecraftforge/forge/$DL_BUILD/forge-$DL_BUILD-installer.jar
if [ "$LATEST_BUILD" != "null" ]; then
echo "$DL_URL"
curl -o forge-install.jar ${DL_URL}
echo "$JAVA -jar forge-install.jar --installServer"
$JAVA -jar forge-install.jar --installServer
ln -s forge-${MC_VERSION}-${LATEST_BUILD}-shim.jar server.jar
touch server.properties
rm -f user_jvm_args.txt
rm -f forge-install.jar
rm -f forge-install.jar.log
rm -f README.txt
rm -f run.bat
rm -f run.sh
else
echo "TODO ERROR TEXT"
fi
}
serverSelect() {
mkdir -p /data/server
cd /data/server
if [[ ! -f server.jar ]]; then
case $MC_LOADER in
vanilla)
getVanilla
;;
paper)
getPaper
;;
fabric)
getFabric
;;
forge)
getForge
;;
*)
echo "Server of type ${MC_LOADER} is not recognized."
crash
;;
esac
fi
}
buildCommand() {
JAVA_ARGS="-Xms${MEM} -Xmx${MEM}"
if [[ -z ${ADD_ARGS+x} ]]; then
RUN_STRING="${ADD_ARGS} ${JAVA_ARGS} -jar ${JAR} nogui"
else
RUN_STRING="${JAVA_ARGS} -jar ${JAR} nogui"
fi
}
runServer() {
setEula
while true; do
if [[ -f $JAR ]]; then
buildCommand
echo "${JAVA} ${RUN_STRING}"
$JAVA ${RUN_STRING}
else
echo "${JAR} not found."
fi
if [[ "${RESTART}" != "true" ]]; then
echo "Exiting..."
exit 0
fi
echo -e "\n${RD}Automatically restarting server in 5 seconds. Press CTRL + C to abort and exit.${NC}"
sleep 5
done
}
# ------------------------------------------------------------------------------- #
javaCheck
serverSelect
setEula
#runServer