Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/Minecraft Java Server/description
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is a simple tool to create a Minecraft server: Vanilla, Fabric, Forge, Paper, and Purpur are supported
This is a simple tool to create a Minecraft server: Vanilla, Fabric, Forge, Paper, Folia, and Purpur are supported

You can play over your local network (or you can create a port forward on your internet router/modem at port 25565 to play over the internet)

Expand All @@ -7,10 +7,10 @@ Attach to a server in the background with: screen -r Minecraft_Server
Detach from a running server session with: CTRL+A then D
To start from a terminal: sudo systemctl start minecraft-server
To stop the server: sudo systemctl stop minecraft-server
To start on automatically on boot and stop on shutdown: sudo systemctl enable minecraft-server
To start now, start on boot, and stop on shutdown: sudo systemctl enable --now minecraft-server

Refer to the ~/Minecraft-Java-Server/start-server.sh file if you need to add custom JVM arguements
Refer to the start-server.sh file in your chosen directory if you need to add custom JVM arguements

Temurin (Adoptium) Java 8/17/21 apt repos are used in this installer for compatibility.
Temurin (Adoptium) Java 8/17/21/25 apt repos are used in this installer for compatibility.

If you uninstall or update this app for whatever reason, your world, mod, and versions folder will remain in ~/Minecraft-Java-Server so there is no data loss.
If you uninstall or update this app for whatever reason, your world, mod, and versions folder will remain in your chosen directory so there is no data loss.
99 changes: 68 additions & 31 deletions apps/Minecraft Java Server/install
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ fi
# add jq to use in script
install_packages jq || exit 1

mkdir -p "$HOME/Minecraft-Java-Server"
cd "$HOME/Minecraft-Java-Server" || error "Could not enter Minecraft-Java-Server folder."
# using the mcserdir.txt file or creating it
mkdir -p "$HOME/Documents"
cd "$HOME/Documents" || error "Could not enter Documents folder."
if [ -f "mcserdir.txt" ];then
# read mcserdir.txt
directory=$(cat "mcserdir.txt")
# make sure the user wants to install the server in the saved directory, as mcserdir.txt persists on uninstall
text="Using the $directory directory.\nIf you would like to use a different directory,\nexit the script and delete the $HOME/Documents/mcserdir.txt file."
userinput_func "$text" "Continue with the $directory directory"
else
# allow user to select directory
directory=$(yad --center --wrap --text "Choose directory:\nDefault is $directory.\nMake sure it ends with Minecraft-Java-Server if you don't want it to fail." --entry --entry-text="$directory" --button="Submit":0)
# store directory in $HOME/Documents so it can be used later
echo "$directory" > mcserdir.txt
fi
mkdir -p "$directory" || error "$directory is invalid or privileged."
Comment thread
theofficialgman marked this conversation as resolved.
Outdated
cd "$directory" || error "Could not enter $directory folder."

description="What type of Minecraft server\ndo you want to run?"
table=("Vanilla" "Fabric" "Forge" "Paper" "Purpur")
table=("Vanilla" "Fabric" "Forge" "Paper" "Folia" "Purpur")
userinput_func "$description" "${table[@]}"
server_category="$output"

Expand Down Expand Up @@ -55,15 +70,26 @@ case "$server_category" in
wget -O "$server_jar" "https://maven.minecraftforge.net/net/minecraftforge/forge/$installer_version/forge-$installer_version-installer.jar" || exit 1
;;
"Paper")
available_versions=$(wget -O- https://api.papermc.io/v2/projects/paper/ | jq -r '.versions | .[]')
available_versions=$(wget -O- https://fill.papermc.io/v3/projects/paper/versions | jq -r '.versions.[].version.id')
description="What version of $server_category do you want to run?"
table=($available_versions)
userinput_func "$description" "${table[@]}"
server_version="$output"
status "Selected $server_category version $server_version"
version_info=$(wget -O- https://api.papermc.io/v2/projects/paper/versions/$server_version/builds | jq -r '.builds | [last]')
server_jar="$(echo "$version_info" | jq -r '.[].downloads.application.name')"
wget -O "$server_jar" "https://api.papermc.io/v2/projects/paper/versions/$server_version/builds/$(echo "$version_info" | jq -r '.[].build')/downloads/$server_jar" || exit 1
version_info=$(wget -O- https://fill.papermc.io/v3/projects/paper/versions/$server_version/builds/latest | jq -r '.downloads."server:default"')
server_jar="$(echo "$version_info" | jq -r '.name')"
wget -O "$server_jar" "$(echo "$version_info" | jq -r '.url')" || exit 1
;;
"Folia")
available_versions=$(wget -O- https://fill.papermc.io/v3/projects/folia/versions | jq -r '.versions.[].version.id')
description="What version of $server_category do you want to run?"
table=($available_versions)
userinput_func "$description" "${table[@]}"
server_version="$output"
status "Selected $server_category version $server_version"
version_info=$(wget -O- https://fill.papermc.io/v3/projects/folia/versions/$server_version/builds/latest | jq -r '.downloads."server:default"')
server_jar="$(echo "$version_info" | jq -r '.name')"
wget -O "$server_jar" "$(echo "$version_info" | jq -r '.url')" || exit 1
;;
"Purpur")
available_versions=$(wget -O- https://api.purpurmc.org/v2/purpur/ | jq -r '.versions | .[]')
Expand Down Expand Up @@ -94,7 +120,7 @@ esac

while [[ ! -a $(echo ${server_jar}) ]]; do
description="Please use the website which has opened to download your chosen version of the Minecraft Java Server.\
\nAdd your ${server_jar} file to the folder opened $HOME/Minecraft-Java-Server and press OK.\
\nAdd your ${server_jar} file to the folder opened $directory and press OK.\
\n\nYou have not added a ${server_jar}."
table=("OK")
userinput_func "$description" "${table[@]}"
Expand All @@ -104,26 +130,31 @@ done
server_jar=$(echo ${server_jar})

if [ -z "$server_version" ]; then
# tell user to choose java 8, 17, or 21
# tell user to choose java 8, 17, 21, or 25
description="In order to run Minecraft, the game requires a specific version of Java.\
\nPlease choose below which version of java the server of your choice should run with.\
\nJava versions can be 8, 17, or 21.\
\nJava versions can be 8, 17, 21, or 25.\
\n\nAll versions of Minecraft before and including Minecraft 1.16.5 should use Java 8.\
\nMinecraft 1.17-1.20 should use java 17.\
\nMinecraft 1.21+ should use java 21."
table=("Java 21" "Java 17" "Java 8")
\nMinecraft 1.21-1.21.11 should use java 21.\
\nMinecraft 26.1+ should use java 25."
table=("Java 25" "Java 21" "Java 17" "Java 8")
userinput_func "$description" "${table[@]}"
java_selection="$output"
else
# we know the version of minecraft in use
# choose the appropriate version of java based on that
# version <= 1.16.5 java 8
# 1.17 <= version < 1.21 java 17
# version >= 1.21 java 21
# 1.21 <= version < 26.1 java 21
# version >= 26.1 java 25
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }
if [ $(version $server_version) -le $(version "1.16.5") ]; then
echo "Using Java 8 by default"
java_selection="Java 8"
elif [ $(version $server_version) -ge $(version "26.1") ]; then
echo "Using Java 25 by default"
java_selection="Java 25"
elif [ $(version $server_version) -ge $(version "1.21") ]; then
echo "Using Java 21 by default"
java_selection="Java 21"
Expand All @@ -134,11 +165,12 @@ else
description="WARNING: We don't know how you got here... your version $server_version does not seem to be a normal minecraft format.\
\n\nIn order to run Minecraft, the game requires a specific version of Java.\
\nPlease choose below which version of java the server of your choice should run with.\
\nJava versions can be 8, 17, or 21.\
\nJava versions can be 8, 17, 21, or 25.\
\n\nAll version of Minecraft before and including Minecraft 1.16.5 should use Java 8.\
\nMinecraft 1.17-1.20 should use java 17.\
\nMinecraft 1.21+ should use java 21."
table=("Java 21" "Java 17" "Java 8")
\nMinecraft 1.21-1.21.11 should use java 21.\
\nMinecraft 26.1+ should use java 25."
table=("Java 25" "Java 21" "Java 17" "Java 8")
userinput_func "$description" "${table[@]}"
java_selection="$output"
fi
Expand All @@ -147,10 +179,10 @@ fi
install_packages lsb-release wget gpg screen || exit 1

case "$java_selection" in
"Java 21")
"Java 21"|"Java 25")
case "$arch" in
"32")
error "User error: Java 21 is not available for your platform from Adoptium. All 32-bit based architectures are being deprecated and removed by Java. Please use a 64-bit OS. Exiting the script."
error "User error: Java 21+ is not available for your platform from Adoptium. All 32-bit based architectures are being deprecated and removed by Java. Please use a 64-bit OS. Exiting the script."
;;
*)
adoptium_installer || exit 1
Expand Down Expand Up @@ -194,13 +226,21 @@ case "$java_selection" in
fi
java_location="/usr/lib/jvm/temurin-21-jre-$dpkg_arch/bin/java"
;;
"Java 25")
if package_available temurin-25-jre ;then
install_packages temurin-25-jre || exit 1
else
error "Java 25 is not available for your platform from Adoptium. Exiting the script."
fi
java_location="/usr/lib/jvm/temurin-25-jre-$dpkg_arch/bin/java"
;;
esac

jvm_test="1"
jvm_args=""
while [[ $jvm_test != 0 ]]; do
# userinput jvm_args
jvm_args=$(yad --center --wrap --text "Would you like to input any JVM Arguments?\nA defaut list is prepopulated in the text box below.\n\nThe most inportant arguments -XmxXXXXM -XmsXXXXM are at the beginning and define how much ram for your server to use.\nHint, use your keyboard Home key to see the start of this list" --entry --entry-text="-Xmx1200M -Xms1200M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1" --button="Validate JVM Arguments":0)
jvm_args=$(yad --center --wrap --text "Would you like to input any JVM Arguments?\nA default list is prepopulated in the text box below.\n\nThe most important arguments, -Xmx and -Xms, are at the beginning and define the max RAM and initial RAM, respectively.\nYou should specify a value slightly less than your total RAM in bytes, kilobytes(k), megabytes(m), or gigabytes(g).\nHint, use your keyboard Home key to see the start of this list." --entry --entry-text="-Xmx1200m -Xms1200m -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1" --button="Validate JVM Arguments":0)
Comment thread
theofficialgman marked this conversation as resolved.
Outdated
$java_location $jvm_args -version
jvm_test="$?"
if [[ $jvm_test != 0 ]]; then
Expand All @@ -212,7 +252,7 @@ done
if [[ "$server_category" == "Forge" ]]; then
# run the server installer
rm -f start-server.sh
$java_location -jar $HOME/Minecraft-Java-Server/${server_jar} --installServer || error "Failed to install forge server"
$java_location -jar $directory/${server_jar} --installServer || error "Failed to install forge server"
rm -f ${server_jar}

# forge has MANY ways to launch depending on the version
Expand Down Expand Up @@ -242,10 +282,10 @@ if [[ "$server_category" == "Forge" ]]; then
fi

if [ -n "$server_jar" ]; then
sh -c "cat > $HOME/Minecraft-Java-Server/start-server.sh << _EOF_
sh -c "cat > $directory/start-server.sh << _EOF_
#!/bin/bash
echo 'Minecraft Server starting'
$java_location $jvm_args -jar $HOME/Minecraft-Java-Server/${server_jar} nogui || (echo -e '\e[91mMinecraft Server has crashed or could not start\e[0m'; sleep 10)
$java_location $jvm_args -jar $directory/${server_jar} nogui || (echo -e '\e[91mMinecraft Server has crashed or could not start\e[0m'; sleep 10)
echo 'Minecraft Server has stopped'
sleep 3
_EOF_"
Expand All @@ -263,7 +303,7 @@ tee "$HOME/.local/share/applications/Minecraft-Java-Server.desktop" <<EOF
[Desktop Entry]
Name=Minecraft Java Server
Exec=bash -c "sudo systemctl start minecraft-server; sleep 3; screen -r Minecraft_Server; if [ \$? == 1 ]; then echo 'The minecraft server has exited without the service stopping, restarting the service for you'; sudo systemctl restart minecraft-server; sleep 5; screen -r Minecraft_Server; fi"
Path=$HOME/Minecraft-Java-Server
Path=$directory
Icon=${DIRECTORY}/apps/Minecraft Java Server/icon-64.png
Type=Application
Categories=Game
Expand All @@ -273,13 +313,14 @@ EOF
screen_location=$(which screen)
sleep_location=$(which sleep)

sudo tee "/etc/systemd/system/minecraft-server.service" <<EOF
# this is equivalent to using tee "/etc/systemd/system/minecraft-server.service" and then systemctl daemon-reload
sudo systemctl edit --stdin --full --force minecraft-server <<EOF

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either a new/old feature of systemd or AI hallucination.

systemctl: unrecognized option '--stdin'

Please revert back to what this was before. No issue with it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I guess it's sorta new

[Service]
RemainAfterExit=yes
WorkingDirectory=$HOME/Minecraft-Java-Server
WorkingDirectory=$directory
User=$USER
# Start Screen, Java, and Minecraft
ExecStart=$screen_location -S Minecraft_Server -U -d -m $HOME/Minecraft-Java-Server/start-server.sh
ExecStart=$screen_location -S Minecraft_Server -U -d -m $directory/start-server.sh
# Tell Minecraft to gracefully stop.
# Ending Minecraft will terminate Java
# systemd will kill Screen after the 10-second delay. No explicit kill for Screen needed
Expand All @@ -292,10 +333,6 @@ WantedBy=multi-user.target
EOF
echo

# update services
sudo systemctl daemon-reload
sudo systemctl disable minecraft-server

Comment on lines -295 to -298

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be re-added. see above

status "Your IP address is one of the following:
$(hostname -I | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
status "The IP address is used to play on your local network
Expand All @@ -307,5 +344,5 @@ Attach to a server in the background with: screen -r Minecraft_Server
Detach from a running server session with: CTRL+A then D
To start from a terminal: sudo systemctl start minecraft-server
To stop the server: sudo systemctl stop minecraft-server
To start on automatically on boot and stop on shutdown: sudo systemctl enable minecraft-server
To start now, start on boot, and stop on shutdown: sudo systemctl enable --now minecraft-server
"
12 changes: 10 additions & 2 deletions apps/Minecraft Java Server/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ shopt -s extglob

#skip uninstallation if executed from an update
if [[ "$1" != "update" ]];then
text="You chose to uninstall the Minecraft Java Server script.\nAll files within your $HOME/Minecraft-Java-Server folder will be deleted except the worlds, mods, and versions subfolders.\nIf you would like to backup any other files/folders do that NOW before clicking the prompt."
# If there's no mcserdir.txt file (old install or otherwise), use the default directory
directory=$HOME/Minecraft-Java-Server
mkdir -p "$HOME/Documents"
cd "$HOME/Documents" || error "Could not enter Documents folder."
if [ -f "mcserdir.txt" ];then
# read mcserdir.txt
directory=$(cat "mcserdir.txt")
fi
text="You chose to uninstall the Minecraft Java Server script.\nAll files within your $directory folder will be deleted except the worlds, mods, and versions subfolders.\nIf you would like to backup any other files/folders do that NOW before clicking the prompt."
userinput_func "$text" "Ok, I have made any backups I wish, continue"
cd $HOME/Minecraft-Java-Server && rm -rf !(world|mods|versions)
cd $directory && rm -rf !(world|mods|versions)
rm -rf $HOME/.local/share/applications/Minecraft-Java-Server.desktop || error "Failed to remove the desktop file"
# stop the server
sudo systemctl stop minecraft-server
Expand Down
Loading