add auto update for vanilla
minecraft-build-testing / Docker prune (vm-docker-build2) (push) Successful in 5s
minecraft-build-testing / Build and Push testing (push) Successful in 43s
minecraft-build-testing / generate-changelogs (push) Successful in 8s
minecraft-build-testing / generate-build-info (push) Successful in 21s
minecraft-build-testing / Docker prune (vm-docker-build2) (push) Successful in 5s
minecraft-build-testing / Build and Push testing (push) Successful in 43s
minecraft-build-testing / generate-changelogs (push) Successful in 8s
minecraft-build-testing / generate-build-info (push) Successful in 21s
This commit is contained in:
+74
-55
@@ -4,26 +4,20 @@
|
||||
|
||||
DEBIAN_VERSION=13
|
||||
|
||||
MC_DIR_OLD=/mc_server
|
||||
MC_DIR=/mcserver
|
||||
|
||||
if [ -d "$MC_DIR_OLD" ]; then
|
||||
mkdir -p "$MC_DIR"
|
||||
mv $MC_DIR_OLD/* "$MC_DIR/" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
EULA_FILE=$MC_DIR/eula.txt
|
||||
EULA_MARKER=$MC_DIR/.eula_accepted
|
||||
INSTALLED_VERSION=$MC_DIR/installed-$TARGET_VERSION
|
||||
|
||||
SERVER_PROPERTIES=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/server.properties
|
||||
START_FILE=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/start.sh
|
||||
|
||||
RUN_VANILLA=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/run-vanilla.sh
|
||||
RUN_BUKKIT=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/run-bukkit.sh
|
||||
RUN_FABRIC=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/run-fabric.sh
|
||||
RUN_QUILT=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/run-quilt.sh
|
||||
|
||||
VERSION_CHECK=$(curl -s "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" | grep -Pom 1 '"url": "\K[^"]*'$MC_VERSION'.json')
|
||||
MC_SERVER_FILE=$(curl -s $VERSION_CHECK | jq --raw-output '.downloads.server.url')
|
||||
BUKKIT_INSTALLER_FILE=https://cdn.getbukkit.org/craftbukkit/craftbukkit-$MC_VERSION.jar
|
||||
FABRIC_SERVER_FILE=https://meta.fabricmc.net/v2/versions/loader/$MC_VERSION/$FABRIC_VERSION/$FABRIC_INSTALLER_VERSION/server/jar
|
||||
QUILT_INSTALLER_FILE=https://quiltmc.org/api/v1/download-latest-installer/java-universal
|
||||
@@ -53,32 +47,6 @@ elif [ $JAVA_VERSION = "openjdk-25-jre" ]; then
|
||||
apt-get update
|
||||
apt-get --no-install-recommends -y install openjdk-25-jre-headless
|
||||
fi
|
||||
# elif [ $JAVA_VERSION = "msopenjdk-21" ]; then
|
||||
# echo "INFO ! $JAVA_VERSION Selected"
|
||||
# if [ dpkg -s msopenjdk-21 &> /dev/null ]
|
||||
# then
|
||||
# echo "INFO ! $JAVA_VERSION installed ... moving on."
|
||||
# else
|
||||
# echo " "
|
||||
# echo "WARNING ! $JAVA_VERSION not installed ... will install now."
|
||||
# wget https://packages.microsoft.com/config/debian/$DEBIAN_VERSION/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
|
||||
# dpkg -i packages-microsoft-prod.deb
|
||||
# apt-get update && apt-get install -y msopenjdk-21
|
||||
# apt-get -y update && apt-get -y --fix-broken install
|
||||
# fi
|
||||
# elif [ $JAVA_VERSION = "msopenjdk-25" ]; then
|
||||
# echo "INFO ! $JAVA_VERSION Selected"
|
||||
# if [ dpkg -s msopenjdk-25 &> /dev/null ]
|
||||
# then
|
||||
# echo "INFO ! $JAVA_VERSION installed ... moving on."
|
||||
# else
|
||||
# echo " "
|
||||
# echo "WARNING ! $JAVA_VERSION not installed ... will install now."
|
||||
# wget https://packages.microsoft.com/config/debian/$DEBIAN_VERSION/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
|
||||
# dpkg -i packages-microsoft-prod.deb
|
||||
# apt-get update && apt-get install -y msopenjdk-25
|
||||
# apt-get -y update && apt-get -y --fix-broken install
|
||||
# fi
|
||||
else
|
||||
echo "ERROR ! Java version must be set first run"
|
||||
sleep infinity
|
||||
@@ -88,27 +56,78 @@ fi
|
||||
# Check for server files and download if needed.
|
||||
if [ $MC_TYPE = "vanilla" ]; then
|
||||
echo "INFO ! Vanilla Selected"
|
||||
if [ -e $MC_DIR/mcserver-$MC_VERSION.jar ]
|
||||
then
|
||||
echo " "
|
||||
echo "INFO ! mcserver-$MC_VERSION.jar found starting now."
|
||||
else
|
||||
echo " "
|
||||
echo "WARNING ! mcserver-$MC_VERSION.jar is out of date/missing ... will download now."
|
||||
echo " "
|
||||
echo "INFO ! Cleaning old files."
|
||||
cd $MC_DIR
|
||||
mkdir -pv old-server-versions/
|
||||
rm -fr *.jar libraries defaultconfigs config mods user_jvm_args.txt run.bat
|
||||
mv -v *.log old-server-versions/
|
||||
wget --no-cache --show-progress --progress=bar:force:noscroll $MC_SERVER_FILE -O mcserver-$MC_VERSION.jar
|
||||
chmod +x mcserver-$MC_VERSION.jar
|
||||
echo " "
|
||||
echo "WARNING ! run-$MC_TYPE-$MC_VERSION.sh is out of date/missing ... will generate now."
|
||||
mv -v run-*.sh old-server-versions/
|
||||
wget --no-cache --show-progress --progress=bar:force:noscroll $RUN_VANILLA -O run-$MC_TYPE-$MC_VERSION.sh
|
||||
chmod +x run-$MC_TYPE-$MC_VERSION.sh
|
||||
cd ..
|
||||
# Fallback to default channel type if MC_TYPE or MC_VERSION is empty
|
||||
: "${MC_VERSION:=latest}"
|
||||
echo "Using server type: $MC_TYPE"
|
||||
|
||||
# Get the currently installed Minecraft version from the filesystem
|
||||
CUR_VERSION=$(find "$MC_DIR" -name "installed-*" | cut -d - -f2-)
|
||||
echo "Current local version: '${CUR_VERSION:-None}'"
|
||||
|
||||
# Fetch the global Minecraft version manifest cleanly
|
||||
JSON=$(curl -s "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json")
|
||||
# Validate that we actually received valid JSON
|
||||
if [ -z "$JSON" ] || ! echo "$JSON" | jq . >/dev/null 2>&1; then
|
||||
echo "Error: Failed to fetch valid JSON from Mojang API"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Resolve the target version dynamically
|
||||
if [ ! -z "$MC_VERSION" ] && [ "$MC_VERSION" != "latest" ]; then
|
||||
# User specified an exact version string (e.g., 1.20.1)
|
||||
TARGET_VERSION=$(echo "$JSON" | jq -r --arg version "$MC_VERSION" '.versions[] | select(.id == $version) | .id')
|
||||
if [ -z "$TARGET_VERSION" ]; then
|
||||
echo "Error: Specified version '$MC_VERSION' not found in Mojang API."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# No version specified or "latest" chosen. Pull from the latest release
|
||||
TARGET_VERSION=$(echo "$JSON" | jq -r '.latest.release')
|
||||
fi
|
||||
echo "Target version determined: '$TARGET_VERSION'"
|
||||
# Update variable to match resolved target
|
||||
MC_VERSION=$TARGET_VERSION
|
||||
|
||||
# Compare versions and only update if they do NOT match
|
||||
if [ "$CUR_VERSION" != "$TARGET_VERSION" ]; then
|
||||
echo "Versions differ ($CUR_VERSION vs $TARGET_VERSION). Fetching Minecraft server download URL..."
|
||||
# Extract the target sub-manifest URL for this specific Minecraft version
|
||||
VERSION_CHECK=$(echo "$JSON" | jq -r --arg version "$TARGET_VERSION" '.versions[] | select(.id == $version) | .url')
|
||||
if [ "$VERSION_CHECK" == "null" ] || [ -z "$VERSION_CHECK" ]; then
|
||||
echo "Error: Metadata URL link not found for version $TARGET_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
# Fetch the specific version's metadata JSON and extract the server jar link
|
||||
MC_SERVER_FILE=$(curl -s "$VERSION_CHECK" | jq -r '.downloads.server.url')
|
||||
if [ "$MC_SERVER_FILE" == "null" ] || [ -z "$MC_SERVER_FILE" ]; then
|
||||
echo "Error: Server jar download URL not found for version $TARGET_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
echo "Ready to download: $MC_SERVER_FILE"
|
||||
# Process Vanilla Minecraft downloads
|
||||
echo " "
|
||||
echo "WARNING ! Minecraft server is out of date/missing ... will download now."
|
||||
echo "INFO ! Cleaning old files."
|
||||
cd "$MC_DIR" || exit 1
|
||||
mkdir -pv old-server-versions/
|
||||
# Wipe old dependencies cleanly
|
||||
rm -fr *.jar libraries defaultconfigs user_jvm_args.txt run.bat
|
||||
# Safely preserve old logs
|
||||
[ -f *.log ] && mv *.log old-server-versions/
|
||||
# Download and fix execution modes
|
||||
wget --no-cache --show-progress --progress=bar:force:noscroll "$MC_SERVER_FILE" -O "mcserver-$MC_VERSION.jar"
|
||||
chmod +x "mcserver-$MC_VERSION.jar"
|
||||
echo " "
|
||||
echo "WARNING ! run-$MC_TYPE-$MC_VERSION.sh is out of date/missing ... will download now."
|
||||
[ -f run-*.sh ] && mv -v run-*.sh old-server-versions/
|
||||
wget --no-cache --show-progress --progress=bar:force:noscroll "$RUN_VANILLA" -O "run-$MC_TYPE-$MC_VERSION.sh"
|
||||
chmod +x "run-$MC_TYPE-$MC_VERSION.sh"
|
||||
# Drop updated marker file
|
||||
rm -f installed-*
|
||||
touch installed-$MC_VERSION
|
||||
cd ..
|
||||
else
|
||||
echo "No update required. Local version matches target version."
|
||||
fi
|
||||
elif [ $MC_TYPE = "bukkit" ]; then
|
||||
echo "INFO ! Bukkit Selected"
|
||||
|
||||
Reference in New Issue
Block a user