diff --git a/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.ps1 b/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.ps1 index 2a051e8f4..2636e5263 100644 --- a/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.ps1 +++ b/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.ps1 @@ -8,6 +8,9 @@ if ( (New-Object Security.Principal.WindowsPrincipal([Security.Principal.Windows Write-Host "Warning! Running with administrator-privileges is not recommended." } +Write-Host "Start script generated by ServerPackCreator SPC_SERVERPACKCREATOR_VERSION_SPC." +Write-Host "To change the launch settings of this server, such as JVM args / flags, Minecraft version, modloader version etc., edit the variables.txt-file." + # Acquire variable hashtable from variables.txt $ExternalVariablesFile = Split-Path $script:MyInvocation.MyCommand.Path $ExternalVariablesFile += "\variables.txt" @@ -149,22 +152,21 @@ Function global:SetupForge $script:MinecraftServerJarLocation = "libraries/net/minecraft/server/${MinecraftVersion}/server-${MinecraftVersion}.jar" $script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true @user_jvm_args.txt @libraries/net/minecraftforge/forge/${MinecraftVersion}-${ModLoaderVersion}/win_args.txt nogui" - if (!(Test-Path -Path 'user_jvm_args.txt' -PathType Leaf)) - { - "# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" + - "# They can take any number, followed by an M or a G.`n" + - "# M means Megabyte, G means Gigabyte.`n" + - "# For example, to set the maximum to 3GB: -Xmx3G`n" + - "# To set the minimum to 2.5GB: -Xms2500M`n" + - "# A good default for a modded server is 4GB.`n" + - "# Uncomment the next line to set it.`n" + - "# -Xmx4G`n" + - "${script:JavaArgs}" | Out-File user_jvm_args.txt -encoding utf8 - } - else - { - "user_jvm_args.txt present..." - } + Write-Host "Generating user_jvm_args.txt from variables..." + Write-Host "Edit JAVA_ARGS in your variables.txt. Do not edit user_jvm_args.txt directly!" + Write-Host "Manually made changes to user_jvm_args.txt will be lost in the nether!" + + DeleteFileSilently 'user_jvm_args.txt' + + "# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" + + "# They can take any number, followed by an M or a G.`n" + + "# M means Megabyte, G means Gigabyte.`n" + + "# For example, to set the maximum to 3GB: -Xmx3G`n" + + "# To set the minimum to 2.5GB: -Xms2500M`n" + + "# A good default for a modded server is 4GB.`n" + + "# Uncomment the next line to set it.`n" + + "# -Xmx4G`n" + + "${script:JavaArgs}" | Out-File user_jvm_args.txt -encoding utf8 } if ((DownloadIfNotExists "${ForgeJarLocation}" "forge-installer.jar" "${ForgeInstallerUrl}")) @@ -196,7 +198,6 @@ Function global:SetupForge Crash } } - "" } # If modloader = Fabric, run Fabric-specific checks @@ -259,13 +260,11 @@ Function global:SetupFabric } else { - "fabric-server-launch.jar present. Moving on..." $script:LauncherJarLocation = "fabric-server-launcher.jar" $script:MinecraftServerJarLocation = "server.jar" } } $script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true ${script:JavaArgs} -jar ${script:LauncherJarLocation} nogui" - "" } # If modloader = Quilt, run Quilt-specific checks @@ -300,14 +299,10 @@ Function global:SetupQuilt } } - else - { - "quilt-server-launch.jar present. Moving on..." - } + $script:LauncherJarLocation = "quilt-server-launch.jar" $script:MinecraftServerJarLocation = "server.jar" $script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true ${JavaArgs} -jar ${LauncherJarLocation} nogui" - "" } # If modloader = LegacyFabric, run LegacyFabric-specific checks @@ -342,20 +337,15 @@ Function global:SetupLegacyFabric } } - else - { - "fabric-server-launch.jar present. Moving on..." - } + $script:LauncherJarLocation = "fabric-server-launch.jar" $script:MinecraftServerJarLocation = "server.jar" $script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true ${JavaArgs} -jar ${LauncherJarLocation} nogui" - "" } # Check for a minecraft server and download it if necessary Function global:Minecraft { - "" if (($ModLoader -eq "Fabric") -and (${ImprovedFabricLauncherAvailable} -eq "200")) { "Skipping Minecraft Server JAR checks because we are using the improved Fabric Server Launcher." @@ -364,13 +354,11 @@ Function global:Minecraft { (DownloadIfNotExists "${MinecraftServerJarLocation}" "${MinecraftServerJarLocation}" "${MinecraftServerUrl}") > $null } - "" } # Check for eula.txt and generate if necessary Function Eula { - "" if (!(Test-Path -Path 'eula.txt' -PathType Leaf)) { "Mojang's EULA has not yet been accepted. In order to run a Minecraft server, you must accept Mojang's EULA." @@ -381,7 +369,6 @@ Function Eula if (${Answer} -eq "I agree") { "User agreed to Mojang's EULA." - "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).`n" + "eula=true" | Out-File eula.txt -encoding utf8 } @@ -393,21 +380,14 @@ Function Eula Crash } } - else - { - "eula.txt present. Moving on..." - } - "" } if ( ${PSScriptRoot}.Contains(" ")) { "WARNING! The current location of this script contains spaces. This may cause this server to crash!" "It is strongly recommended to move this server pack to a location whose path does NOT contain SPACES!" - "" "Current path:" "${PSScriptRoot}" - "" $WhyMustPowerShellBeThisWayLikeSeriouslyWhatTheFrag = Read-Host -Prompt 'Are you sure you want to continue? (Yes/No): ' @@ -453,7 +433,6 @@ Eula "" "Starting server..." -"" "Minecraft version: ${MinecraftVersion}" "Modloader: ${ModLoader}" "Modloader version: ${ModLoaderVersion}" diff --git a/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.sh b/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.sh index 922ec6d9e..f4166ef88 100644 --- a/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.sh +++ b/serverpackcreator-api/src/jvmMain/resources/de/griefed/resources/server_files/default_template.sh @@ -9,6 +9,9 @@ if [[ "$(id -u)" == "0" ]]; then echo "Warning! Running with administrator-privileges is not recommended." fi +echo "Start script generated by ServerPackCreator SPC_SERVERPACKCREATOR_VERSION_SPC." +echo "To change the launch settings of this server, such as JVM args / flags, Minecraft version, modloader version etc., edit the variables.txt-file." + # Acquire variables from variables.txt source "variables.txt" @@ -30,14 +33,17 @@ crash() { # true if the file was successfully downloaded, false if it already exists downloadIfNotExist() { if [[ ! -s "${1}" ]]; then + echo "${1} could not be found." >&2 echo "Downloading ${2}" >&2 echo "from ${3}" >&2 curl -# -L -o "./${2}" "${3}" + if [[ -s "${2}" ]]; then echo "Download complete." >&2 echo "true" fi + else echo "${1} present." >&2 echo "false" @@ -63,36 +69,30 @@ setup_forge() { IFS="." read -ra MINOR <<<"${MINECRAFT_VERSION}" if [[ ${MINOR[1]} -le 16 ]]; then - FORGE_JAR_LOCATION="forge.jar" LAUNCHER_JAR_LOCATION="forge.jar" MINECRAFT_SERVER_JAR_LOCATION="minecraft_server.${MINECRAFT_VERSION}.jar" SERVER_RUN_COMMAND="-Dlog4j2.formatMsgNoLookups=true ${JAVA_ARGS} -jar ${LAUNCHER_JAR_LOCATION} nogui" - else - FORGE_JAR_LOCATION="libraries/net/minecraftforge/forge/${MINECRAFT_VERSION}-${MODLOADER_VERSION}/forge-${MINECRAFT_VERSION}-${MODLOADER_VERSION}-server.jar" MINECRAFT_SERVER_JAR_LOCATION="libraries/net/minecraft/server/${MINECRAFT_VERSION}/server-${MINECRAFT_VERSION}.jar" SERVER_RUN_COMMAND="-Dlog4j2.formatMsgNoLookups=true @user_jvm_args.txt @libraries/net/minecraftforge/forge/${MINECRAFT_VERSION}-${MODLOADER_VERSION}/unix_args.txt nogui" - if [[ ! -s "user_jvm_args.txt" ]]; then - - { - echo "# Xmx and Xms set the maximum and minimum RAM usage, respectively." - echo "# They can take any number, followed by an M or a G." - echo "# M means Megabyte, G means Gigabyte." - echo "# For example, to set the maximum to 3GB: -Xmx3G" - echo "# To set the minimum to 2.5GB: -Xms2500M" - echo "# A good default for a modded server is 4GB." - echo "# Uncomment the next line to set it." - echo "# -Xmx4G" - echo "${JAVA_ARGS}" - } >>user_jvm_args.txt - - else - echo "user_jvm_args.txt present..." - fi - + echo "Generating user_jvm_args.txt from variables..." + echo "Edit JAVA_ARGS in your variables.txt. Do not edit user_jvm_args.txt directly!" + echo "Manually made changes to user_jvm_args.txt will be lost in the nether!" + rm -f user_jvm_args.txt + { + echo "# Xmx and Xms set the maximum and minimum RAM usage, respectively." + echo "# They can take any number, followed by an M or a G." + echo "# M means Megabyte, G means Gigabyte." + echo "# For example, to set the maximum to 3GB: -Xmx3G" + echo "# To set the minimum to 2.5GB: -Xms2500M" + echo "# A good default for a modded server is 4GB." + echo "# Uncomment the next line to set it." + echo "# -Xmx4G" + echo "${JAVA_ARGS}" + } >>user_jvm_args.txt fi if [[ $(downloadIfNotExist "${FORGE_JAR_LOCATION}" "forge-installer.jar" "${FORGE_INSTALLER_URL}") == "true" ]]; then @@ -101,33 +101,24 @@ setup_forge() { runJavaCommand "-jar forge-installer.jar --installServer" if [[ ${MINOR[1]} -gt 16 ]]; then - rm -f run.bat rm -f run.sh - else - echo "Renaming forge-${MINECRAFT_VERSION}-${MODLOADER_VERSION}.jar to forge.jar" mv forge-"${MINECRAFT_VERSION}"-"${MODLOADER_VERSION}".jar forge.jar - fi if [[ -s "${FORGE_JAR_LOCATION}" ]]; then - rm -f forge-installer.jar rm -f forge-installer.jar.log echo "Installation complete. forge-installer.jar deleted." - else - rm -f forge-installer.jar echo "Something went wrong during the server installation. Please try again in a couple of minutes and check your internet connection." crash - fi fi - echo "" } # If modloader = Fabric, run Fabric-specific checks @@ -142,17 +133,13 @@ setup_fabric() { IMPROVED_FABRIC_LAUNCHER_AVAILABLE="$(curl -LI ${IMPROVED_FABRIC_LAUNCHER_URL} -o /dev/null -w '%{http_code}\n' -s)" if [[ "$IMPROVED_FABRIC_LAUNCHER_AVAILABLE" == "200" ]]; then - echo "Improved Fabric Server Launcher available..." echo "The improved launcher will be used to run this Fabric server." LAUNCHER_JAR_LOCATION="fabric-server-launcher.jar" downloadIfNotExist "fabric-server-launcher.jar" "fabric-server-launcher.jar" "${IMPROVED_FABRIC_LAUNCHER_URL}" >/dev/null - elif [[ "${FABRIC_AVAILABLE}" != "200" ]]; then - echo "Fabric is not available for Minecraft ${MINECRAFT_VERSION}, Fabric ${MODLOADER_VERSION}." crash - elif [[ $(downloadIfNotExist "fabric-server-launch.jar" "fabric-installer.jar" "${FABRIC_INSTALLER_URL}") == "true" ]]; then echo "Installer downloaded..." @@ -161,30 +148,23 @@ setup_fabric() { runJavaCommand "-jar fabric-installer.jar server -mcversion ${MINECRAFT_VERSION} -loader ${MODLOADER_VERSION} -downloadMinecraft" if [[ -s "fabric-server-launch.jar" ]]; then - rm -rf .fabric-installer rm -f fabric-installer.jar echo "Installation complete. fabric-installer.jar deleted." - else - rm -f fabric-installer.jar echo "fabric-server-launch.jar not found. Maybe the Fabric servers are having trouble." echo "Please try again in a couple of minutes and check your internet connection." crash - fi else - echo "fabric-server-launch.jar present. Moving on..." LAUNCHER_JAR_LOCATION="fabric-server-launcher.jar" MINECRAFT_SERVER_JAR_LOCATION="server.jar" - fi SERVER_RUN_COMMAND="-Dlog4j2.formatMsgNoLookups=true ${JAVA_ARGS} -jar ${LAUNCHER_JAR_LOCATION} nogui" - echo "" } # If modloader = Quilt, run Quilt-specific checks @@ -197,37 +177,27 @@ setup_quilt() { QUILT_AVAILABLE="$(curl -LI ${QUILT_CHECK_URL} -o /dev/null -w '%{http_code}\n' -s)" if [[ "${#QUILT_AVAILABLE}" -eq "2" ]]; then - echo "Quilt is not available for Minecraft ${MINECRAFT_VERSION}, Quilt ${MODLOADER_VERSION}." crash - elif [[ $(downloadIfNotExist "quilt-server-launch.jar" "quilt-installer.jar" "${QUILT_INSTALLER_URL}") == "true" ]]; then - echo "Installer downloaded. Installing..." runJavaCommand "-jar quilt-installer.jar install server ${MINECRAFT_VERSION} --download-server --install-dir=." if [[ -s "quilt-server-launch.jar" ]]; then - rm quilt-installer.jar echo "Installation complete. quilt-installer.jar deleted." - else - rm -f quilt-installer.jar echo "quilt-server-launch.jar not found. Maybe the Quilt servers are having trouble." echo "Please try again in a couple of minutes and check your internet connection." crash - fi - else - echo "quilt-server-launch.jar present. Moving on..." fi LAUNCHER_JAR_LOCATION="quilt-server-launch.jar" MINECRAFT_SERVER_JAR_LOCATION="server.jar" SERVER_RUN_COMMAND="-Dlog4j2.formatMsgNoLookups=true ${JAVA_ARGS} -jar ${LAUNCHER_JAR_LOCATION} nogui" - echo "" } # If modloader = LegacyFabric, run LegacyFabric-specific checks @@ -240,52 +210,37 @@ setup_legacyfabric() { LEGACYFABRIC_AVAILABLE="$(curl -LI ${LEGACYFABRIC_CHECK_URL} -o /dev/null -w '%{http_code}\n' -s)" if [[ "${#LEGACYFABRIC_AVAILABLE}" -eq "2" ]]; then - echo "LegacyFabric is not available for Minecraft ${MINECRAFT_VERSION}, LegacyFabric ${MODLOADER_VERSION}." crash - elif [[ $(downloadIfNotExist "fabric-server-launch.jar" "legacyfabric-installer.jar" "${LEGACYFABRIC_INSTALLER_URL}") == "true" ]]; then - echo "Installer downloaded. Installing..." runJavaCommand "-jar legacyfabric-installer.jar server -mcversion ${MINECRAFT_VERSION} -loader ${MODLOADER_VERSION} -downloadMinecraft" if [[ -s "fabric-server-launch.jar" ]]; then - rm legacyfabric-installer.jar echo "Installation complete. legacyfabric-installer.jar deleted." - else - rm -f legacyfabric-installer.jar echo "fabric-server-launch.jar not found. Maybe the LegacyFabric servers are having trouble." echo "Please try again in a couple of minutes and check your internet connection." crash - fi - else - echo "fabric-server-launch.jar present. Moving on..." fi LAUNCHER_JAR_LOCATION="fabric-server-launch.jar" MINECRAFT_SERVER_JAR_LOCATION="server.jar" SERVER_RUN_COMMAND="-Dlog4j2.formatMsgNoLookups=true ${JAVA_ARGS} -jar ${LAUNCHER_JAR_LOCATION} nogui" - echo "" } # Check for a minecraft server and download it if necessary minecraft() { echo "" if [[ "${MODLOADER}" == "Fabric" && "$IMPROVED_FABRIC_LAUNCHER_AVAILABLE" == "200" ]]; then - echo "Skipping Minecraft Server JAR checks because we are using the improved Fabric Server Launcher." - else - downloadIfNotExist "${MINECRAFT_SERVER_JAR_LOCATION}" "${MINECRAFT_SERVER_JAR_LOCATION}" "${MINECRAFT_SERVER_URL}" >/dev/null - fi - echo "" } # Check for eula.txt and generate if necessary @@ -300,23 +255,16 @@ eula() { read -r ANSWER if [[ "${ANSWER}" == "I agree" ]]; then - echo "User agreed to Mojang's EULA." 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 - else - echo "User did not agree to Mojang's EULA." echo "Entered: ${ANSWER}" crash - fi - else - echo "eula.txt present. Moving on..." fi - echo "" } # Main @@ -351,14 +299,11 @@ if [[ "${PWD}" == *" "* ]]; then echo "Current path:" echo "${PWD}" echo "" - echo -n "Are you sure you want to continue? (Yes/No): " read -r WHY if [[ "${WHY}" == "Yes" ]]; then - echo "Alrighty. Prepare for unforseen consequences, Mr. Freeman..." - else crash fi @@ -370,7 +315,6 @@ eula echo "" echo "Starting server..." -echo "" echo "Minecraft version: ${MINECRAFT_VERSION}" echo "Modloader: ${MODLOADER}" echo "Modloader version: ${MODLOADER_VERSION}"