Compare commits

...

51 Commits
v1.0.1 ... main

Author SHA1 Message Date
9984440a38
fix(README): grammar 2023-09-08 15:08:50 +02:00
c585238c2d Fix: the selected version printed when migrating server versions 2023-04-10 20:57:54 +02:00
dd93be3a8e Fix: moving java 16 into ~/.adoptium_java 2023-04-10 20:53:29 +02:00
1997882671 Fix: download java 16 2023-04-10 20:49:54 +02:00
13aaecb315 fix(server_launch): set proper java arguments 2023-03-30 19:21:26 +02:00
78d6bcfd5a
Create FUNDING.yml 2023-03-04 06:40:04 +01:00
8fb2cf7488 Fix version and server type failsafe triggering on server install 2023-03-02 21:31:28 +01:00
e31a66529a Fix the server type failsafe 2023-03-02 20:48:50 +01:00
f446eadde4 Fix version number 2023-03-02 20:37:35 +01:00
353b49a76d Add a failsafe for server type change 2023-03-02 20:35:23 +01:00
3563330d6b Fix variable not assigning properly 2023-02-27 05:53:34 +01:00
64d2a60f8e Bugfix version bump 2023-02-27 05:50:46 +01:00
a16e68ca37 Fix a typo 2023-02-27 05:49:13 +01:00
2dd188a630 Add fabric suported servers in readme 2023-02-27 05:46:30 +01:00
cd9c5910b7
Merge pull request #2 from jiriks74/add_fabric_support
Add initial support for Fabric
2023-02-27 05:44:06 +01:00
7cb94c80a2
Remove complicated variable getting
It was there for no reason
2023-02-27 05:43:39 +01:00
0ea15a86f5
Remove useless echo 2023-02-27 05:42:14 +01:00
c84d8c7d44 Add initial support for Fabric 2023-02-27 05:39:44 +01:00
68ca598ba1 Update help message 2023-02-27 04:02:43 +01:00
ad53b9a6cf Fix duplicate helper scripts update 2023-02-27 03:54:19 +01:00
2731e6f2a3 Fix Makefile's version mismatch detection 2023-02-27 03:48:05 +01:00
b12f4589f5 Fix updating helper scripts after script update 2023-02-27 03:32:43 +01:00
5b637cf84d Fix system java detection 2023-02-27 03:22:55 +01:00
2845e4cd4f Fi typo in Makefile and .gitignore 2023-02-27 03:07:54 +01:00
d5928d5533 Update oneliner setup 2023-02-27 02:58:02 +01:00
2d6862a240 Fix bad download link in helper scripts update, remove --redownload 2023-02-27 02:55:31 +01:00
0f1e4b2562 Fix script downloading old helper scripts 2023-02-27 02:48:05 +01:00
58edc3ee22 Fix helper script download and script restarting for curl isntall 2023-02-27 02:39:07 +01:00
5ba70719a6 Bugfix version bump 2023-02-27 02:34:06 +01:00
7ef61167a4 Fix script restarting 2023-02-27 02:33:15 +01:00
5221d16f00 Add helper-script to gitignore, bugfix version bump 2023-02-27 02:29:42 +01:00
ff6b4a53ea Fix --redownload not restarting after successful download 2023-02-27 02:27:55 +01:00
cd7ec87178 Add check to Makefile for scripts version mismatch 2023-02-27 02:20:54 +01:00
a28a24c053 Fix script reload 2023-02-27 01:30:23 +01:00
3b81b39731 Bugfix version bump 2023-02-27 01:27:23 +01:00
cc2ec17b05 Fix relaunching the script after update 2023-02-27 01:23:54 +01:00
be70839f3b Fix --editor-config 2023-02-27 01:19:19 +01:00
6581e516e8 Swith to bash 2023-02-27 01:17:25 +01:00
2f2655b0db Fix --editor-config 2023-02-27 01:16:49 +01:00
4763f4038a Fix $EDITOR check 2023-02-27 01:15:02 +01:00
02b3d0fa54 Update Basic setup 2023-02-27 01:13:24 +01:00
066323ed77 Improve Makefile 2023-02-27 01:10:24 +01:00
7a2fbb29e8 Implement a simple makefile
to make creating a new release archive easier
2023-02-27 01:06:28 +01:00
0858631fee Remove accidentally added files 2023-02-27 01:05:14 +01:00
0b1b2d1626 Version bump 2023-02-27 01:04:32 +01:00
dc45b90d98 Implement --edit-config 2023-02-27 01:03:56 +01:00
b017c00a6c Reload the script after --redownload 2023-02-27 00:57:15 +01:00
9e2d15238b Fix --redownload
Was missing a call to get the latest version
2023-02-27 00:55:27 +01:00
f8dd301eeb Improve --redownload
Refactor junk code
2023-02-27 00:52:04 +01:00
11eeafa289 Fix --redownload 2023-02-27 00:48:56 +01:00
3fd64aacf0 Move launch.cfg to msman.cfg to fix it 2023-02-27 00:43:02 +01:00
16 changed files with 223 additions and 346 deletions

13
.github/FUNDING.yml vendored Normal file

@ -0,0 +1,13 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: jiriks74 # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

1
.gitignore vendored Normal file

@ -0,0 +1 @@
msman-helper.tar.gz

@ -1,192 +0,0 @@
#!/bin/bash
set -e
# Setup Java
function setup_java {
# Get the required Java version for the Minecraft version
get_required_java
# Check if java was downloaded by the script
check_script_java
# Check if java is installed
if [[ $java_version == false ]]; then
check_java_exec
if [[ $java_version != false ]]; then
echo "System Java $java_version will be used."
fi
fi
if [[ $java_version == false ]]; then
>&2 echo "Java $required_java is not installed."
>&2 echo "Java $required_java is required to run Minecraft $version."
# Ask the user if they want to download Adoptium JRE
ask_jre
fi
echo
echo
}
# Ask the user if they want to download Adoptium JRE
function ask_jre {
echo "This script can download the correct Adoptium JRE into '$(echo $HOME)/.adoptium_java' for you."
echo "You have 15 seconds to confirm or the script will exit."
read -t 12 -p "Do you want to download Adoptium JRE? (y/N)" download_java
if [[ $download_java == "y" ]] || [[ $download_java == "Y" ]]; then
get_os_arch
download_jre
check_script_java
if [[ $java_version == false ]]; then
>&2 echo "Java $required_java was not downloaded correctly."
>&2 echo "Please install Java $required_java manually."
exit 4
fi
else
>&2 echo "Please install Java $required_java and run this script again."
exit 12
fi
}
# Check if java was downloaded by the script
function check_script_java {
if [[ -d "$(echo $HOME)/.adoptium_java" ]]; then
if [[ $required_java == "8" ]]; then
if [[ -d "$(echo $HOME)/.adoptium_java/jre8" ]]; then
java_version=8
if [[ -f "$(echo $HOME).adoptium_java/jre8/bin/java" ]]; then
PATH="$(echo $HOME)/.adoptium_java/jre8/bin:$PATH"
fi
fi
elif [[ $required_java == "11" ]]; then
if [[ -d "$(echo $HOME)/.adoptium_java/jre11" ]]; then
java_version=11
PATH="$(echo $HOME)/.adoptium_java/jre11/bin:$PATH"
fi
elif [[ $required_java == "16" ]]; then
if [[ -d "$(echo $HOME)/.adoptium_java/jre16" ]]; then
java_version=16
PATH="$(echo $HOME)/.adoptium_java/jre16/bin:$PATH"
fi
elif [[ $required_java == "17" ]]; then
if [[ -d "$(echo $HOME)/.adoptium_java/jre17" ]]; then
java_version=17
PATH="$(echo $HOME)/.adoptium_java/jre17/bin:$PATH"
fi
fi
check_java_exec
if [[ $java_version == $required_java ]]; then
echo "Java $java_version detected in '$(echo $HOME)/.adoptium_java/jre$(echo $java_version)/bin/java.' will be used."
else
java_version=false
fi
else
java_version=false
fi
}
# Get the system Java version
function check_java_exec {
# Check if java is installed
if ! command -v java &> /dev/null
then
java_version=false
fi
# If java is installed, get the version (the java_version won't be 0)
if [[ $java_version != false ]]; then
# Get the current Java version and extract the build number
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F '.' '{print $1}')
fi
}
# Get the required Java version for the Minecraft version
# For version 1.8 to 1.11 use java 8
# For version 1.12 to 1.16.4 use java 11
# For version 1.16.5 use java 16
# For version 1.17.1 to 1.18.1+ use java 17
function get_required_java {
# Extract the middle number of the Minecraft version
minecraft_middle=$(echo "$version" | awk -F '.' '{print $2}')
# Get the java version for the defined server version
if (( 8 <= minecraft_middle && minecraft_middle <= 11 )); then
if ! [[ $java_version -eq 8 ]]; then
required_java=8
fi
elif (( 12 <= minecraft_middle && minecraft_middle <= 16 )); then
if ! [[ $java_version -eq 11 ]]; then
required_java=11
fi
elif (( minecraft_middle == 17 )); then
if ! [[ $java_version -eq 16 ]]; then
required_java=16
fi
elif (( 18 <= minecraft_middle )); then
if ! [[ $java_version -eq 17 ]]; then
required_java=17
fi
else
>&2 echo "Unsupported Minecraft version $select_version."
fi
}
# Check host architecture
function get_os_arch {
if [[ $(uname -m) == "x86_64" ]]; then
arch="x64"
elif [[ $(uname -m) == "aarch64" ]]; then
arch="aarch64"
else
>&2 echo "Unsupported architecture $(uname -m)."
>&2 echo "Please install Java $required_java manually."
exit 3
fi
}
# Download openjdk jre
function download_jre {
# Check if .java folder exists
if ! [[ -d "$(echo $HOME)/.adoptium_java" ]]; then
echo "Creating $(echo $HOME)/.adoptium_java folder"
mkdir "$(echo $HOME)/.adoptium_java"
fi
# Download the correct version of Java
if [[ $required_java == "8" ]]; then
echo "Downloading Adoptium JRE 8"
curl -L -o java.tar.gz "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u362-b09/OpenJDK8U-jre_$(echo $arch)_linux_hotspot_8u362b09.tar.gz"
echo "Extracting Java 8"
tar -xzf java.tar.gz
echo "Moving Java 8 to $(echo $HOME)/.adoptium_java/jre8"
mv jdk8u362-b09-jre "$(echo $HOME)/.adoptium_java/jre8"
echo "Removing temporary files"
rm java.tar.gz
elif [[ $required_java == "11" ]]; then
echo "Downloading Adoptium JRE 11"
curl -L -o java.tar.gz "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.18%2B10/OpenJDK11U-jre_$(echo $arch)_linux_hotspot_11.0.18_10.tar.gz"
echo "Extracting Java 11"
tar -xzf java.tar.gz
echo "Moving Java 11 to $(echo $HOME)/.adoptium_java/jre11"
mv jdk-11.0.18+10-jre "$(echo $HOME)/.adoptium_java/jre11"
echo "Removing temporary files"
rm java.tar.gz
elif [[ $required_java == "16" ]]; then
echo "Downloading Java 16"
curl -L -o java.tar.gz "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.18%2B10/OpenJDK11U-jre_$(echo $arch)_linux_hotspot_16.0.2_7.tar.gz"
echo "Extracting Java 16"
tar -xzf java.tar.gz
echo "Moving Java 16 to $(echo $HOME)/.adoptium_java/jre16"
mv jdk-16.0.2+7-jre "$(echo $HOME)/.adoptium_java/jre16"
echo "Removing temporary files"
rm java.tar.gz
elif [[ $required_java == "17" ]]; then
echo "Downloading Java 17"
curl -L -o java.tar.gz "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.6%2B10/OpenJDK17U-jre_$(echo $arch)_linux_hotspot_17.0.6_10.tar.gz"
echo "Extracting Java 17"
tar -xzf java.tar.gz
echo "Moving Java 17 to $(echo $HOME)/.adoptium_java/jre17"
mv jdk-17.0.6+10-jre "$(echo $HOME)/.adoptium_java/jre17"
echo "Removing temporary files"
rm java.tar.gz
fi
}

@ -1,3 +0,0 @@
#!/bin/bash
EXTRA_SCRIPTS_VERSION="v1.0.0"

@ -5,9 +5,10 @@ function get_existing_server {
if ls paper-*.jar 1> /dev/null 2>&1; then
existing_server_type="paper"
get_existing_paper
elif ls fabric-server-mc.*.jar 1> /dev/null 2>&1; then
existing_server_type="fabric"
get_existing_fabric
# TODO: Add support for other server types
# elif ls fabric-*.jar 1> /dev/null 2>&1; then
# existing_server_type="fabric"
# elif ls spigot-*.jar 1> /dev/null 2>&1; then
# existing_server_type="spigot"
# elif ls craftbukkit-*.jar 1> /dev/null 2>&1; then
@ -30,6 +31,30 @@ function get_existing_server {
fi
}
# Get existing version and build of fabric
function get_existing_fabric {
# Get the current server file name
server_file=$(basename ./fabric-server-mc.*.jar)
# Assign the file name to a variable
FILE=$server_file
# Remove the .jar extension
FILE=${FILE%.jar}
# Split by - and get the third field (mc.x.x.x)
current_version=$(echo $FILE | cut -d. -f2,3,4 | cut -d- -f1)
# Split by - and get the fourth field (launcher.x.x.x)
current_build=$(echo $FILE | cut -d- -f4 | cut -d. -f2,3,4)
echo "Current server file: $server_file"
echo " - Version $current_version"
echo " - Build $current_build"
echo
echo
}
# Get existing version and build of paper
function get_existing_paper {
# Get the current server file name

@ -1,19 +1,19 @@
#!/bin/bash
set -e
# API URL
api_url="https://api.papermc.io/v2/projects/paper/versions/$version/builds"
api_url="https://meta.fabricmc.net/v2/versions/"
# Example server's jar file name:
# fabric-server-mc.1.19.3-loader.0.14.14-launcher.0.11.1.jar
# Check if the version and build are valid
function check_version_valid {
if curl -s "$api_url" | grep -q '{"error":"Version not found."}'; then
if [[ $(curl -s "$(echo $api_url)/loader/$(echo $version)") == "[]" ]]; then
>&2 echo "Error: Invalid version selected: $version"
exit 2
else
# Check if selected build exists
if [ ! -z "$build" ]; then
# WARNING: Check if the shortened versin works
# if curl -Is "https://api.papermc.io/v2/projects/paper/versions/$version/builds/$build/downloads/paper-$version-$build.jar" | grep "HTTP/2 404" >/dev/null; then
if curl -Is "$api_url/$build/downloads/paper-$version-$build.jar" | grep "HTTP/2 404" >/dev/null; then
if [[ $(curl -s "$(echo $api_url)/loader/$(echo $version)/$(echo $build)") == "\"no loader version found for $(echo $version)\"" ]]; then
>&2 echo "Error: Invalid build selected: $build"
exit 2
fi
@ -21,22 +21,24 @@ function check_version_valid {
fi
}
# Download server set by $version and $download_build
function download_server {
# Download the server
echo "Downloading PaperMC server..."
echo "Downloading Fabric server..."
echo " - Version $version"
echo " - Build $download_build"
curl "https://api.papermc.io/v2/projects/paper/versions/$version/builds/$download_build/downloads/paper-$version-$download_build.jar" -o "./paper-$version-$download_build.jar"
echo " - Installer $latest_installer"
curl "$(echo $api_url)/loader/$(echo $version)/$(echo $download_build)/$(echo $latest_installer)/server/jar" -o "./fabric-server-mc.$(echo $version)-loader.$(echo $download_build)-launcher.$(echo $latest_installer).jar"
echo "Download complete."
}
# Check if up to date
function check_updates {
if [[ $server_file == false ]]; then
download_build=$latest_build
update_version=true
update_build=true
return
else
echo Checking for updates...
fi
# Check if $build is empty
@ -53,12 +55,10 @@ function check_updates {
fi
else
# Check if $server_file is false
if [[ $server_file != false ]]; then
ask_version_differs
echo "Server is not up to date."
download_build=$latest_build
update_version=true
fi
ask_version_differs
echo "Server is not up to date."
download_build=$latest_build
update_version=true
fi
else
# Check if the current version is the same as the one selected
@ -73,29 +73,24 @@ function check_updates {
fi
else
# Check if $server_file is false
if [[ $server_file != false ]]; then
ask_version_differs
echo "Server is not up to date."
download_build=$build
update_version=true
fi
ask_version_differs
echo "Server is not up to date."
download_build=$build
update_version=true
fi
fi
}
# Get the latest build number
# Get the latest build number and installer version
function get_latest_build {
# Get the latest build number
latest_build=$(curl -s $api_url | jq '.builds[-1].build')
latest_build=$(curl -s "$(echo $api_url)/loader/$version" | jq -r '.[0].loader.version')
latest_installer=$(curl -s "$(echo $api_url)/installer/" | jq -r '.[0].version')
}
# Check for updates
# Check if the server is up to date and update if it isn't
function check_and_update {
if [[ $server_file == false ]]; then
download_build=$latest_build
update_version=true
update_build=true
else
if ! [[ $server_file == false ]]; then
echo Checking for updates...
fi
@ -109,16 +104,15 @@ function check_and_update {
if [[ $update_build == true ]] || [[ $update_version == true ]]; then
if [[ $server_file != false ]]; then
old_server_file=$server_file
server_file="paper-$version-$download_build.jar"
server_file="fabric-server-mc.$version-loader.$download_build-launcher.$latest_installer.jar"
download_server
# Delete the old server file
delete_old_server
else
server_file="paper-$version-$download_build.jar"
server_file="fabric-server-mc.$version-loader.$download_build-launcher.$latest_installer.jar"
download_server
fi
fi
echo
echo
}

@ -86,17 +86,17 @@ function check_script_java {
# Get the system Java version
function check_java_exec {
# Check if java is installed
if ! command -v java &> /dev/null
then
java_version=false
fi
# If java is installed, get the version (the java_version won't be 0)
if [[ $java_version != false ]]; then
# Check if java is installed
if ! command -v java &> /dev/null; then
java_version=false
else
# Get the current Java version and extract the build number
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F '.' '{print $1}')
fi
if [[ $java_version != $required_java ]]; then
java_version=false
fi
}
# Get the required Java version for the Minecraft version
@ -172,11 +172,11 @@ function download_jre {
rm java.tar.gz
elif [[ $required_java == "16" ]]; then
echo "Downloading Java 16"
curl -L -o java.tar.gz "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.18%2B10/OpenJDK11U-jre_$(echo $arch)_linux_hotspot_16.0.2_7.tar.gz"
curl -L -o java.tar.gz "https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_$(echo $arch)_linux_hotspot_16.0.2_7.tar.gz"
echo "Extracting Java 16"
tar -xzf java.tar.gz
echo "Moving Java 16 to $(echo $HOME)/.adoptium_java/jre16"
mv jdk-16.0.2+7-jre "$(echo $HOME)/.adoptium_java/jre16"
mv jdk-16.0.2+7 "$(echo $HOME)/.adoptium_java/jre16"
echo "Removing temporary files"
rm java.tar.gz
elif [[ $required_java == "17" ]]; then

@ -37,6 +37,9 @@ function check_updates {
download_build=$latest_build
update_version=true
update_build=true
return
else
echo Checking for updates...
fi
# Check if $build is empty

3
.msman/version.sh Normal file

@ -0,0 +1,3 @@
#!/bin/bash
EXTRA_SCRIPTS_VERSION="v2.1.6"

21
Makefile Normal file

@ -0,0 +1,21 @@
# Simple makefile to create a tarball of the msman helper scripts
# Turn off verbose mode
MAKEFLAGS += -s
all:
CURRENT_SCRIPT_VERSION=`grep "CURRENT_SCRIPT_VERSION=" msman.sh | sed -e "s/CURRENT_SCRIPT_VERSION=//g" | head -n -1`; \
EXTRA_VERSION=`grep "EXTRA_SCRIPTS_VERSION=" .msman/version.sh | sed -e "s/EXTRA_SCRIPTS_VERSION=//g"`; \
if [ "$$CURRENT_SCRIPT_VERSION" != "$$EXTRA_VERSION" ]; then \
echo "ERROR: The version in msman.sh and .msman/version.sh are not the same!"; \
echo "ERROR: Please make sure they are the same."; \
exit 1; \
fi
rm -rf msman
mkdir msman
cp -r .msman msman
tar -czf msman-helper.tar.gz msman
rm -rf msman
clean:
rm -rf msman
rm -f msman-hepler.tar.gz

@ -8,7 +8,7 @@ branch.
The project grew out of the scope I envisioned at first, surprisingly quickly LOL,
so I moved all my development here.
This project aims to support more minecraft servers rather than just paper.
This project aims to support more Minecraft servers than just paper.
## Features
@ -16,7 +16,7 @@ This project aims to support more minecraft servers rather than just paper.
- Checks for the correct Java version installed
- Enables you to download a download a portable Java version from [Adoptium](https://adoptium.net/)
- The script download's it to `~/.adoptium_java` allowing you to use one
- The script downloads it to `~/.adoptium_java` allowing you to use one
Java downlaod across multiple server instances
- It also allows you to use multiple Java versions allowing you to run
multiple Minecraft servers requiring different Java versions
@ -39,11 +39,12 @@ This project aims to support more minecraft servers rather than just paper.
#### Self-update
- This script can self-update itself without the need for user doing it manually
- This script can self-update itself without the need for user intervention
## Currently supported servers
- [Paper](https://papermc.io/)
- [Fabric](https://fabricmc.net/use/server/)
## Dependencies
@ -65,11 +66,32 @@ you're running something like Ubuntu.*
> undefined behavior and may cause the script to crash or perform unexpected actions.
>
> I strongly advise against making any modifications to the server's `.jar` file
> manually, as it may interfere with the proper functioning of this script.
> manually, as it may interfere with the functionality of this script.
## Basic setup
- [ ] ***TBD***
- Option 1: Oneliner
```bash
curl -sSL "https://raw.githubusercontent.com/jiriks74/msman.sh/main/msman.sh" -o msman.sh && chmod +x msman.sh && ./msman.sh
```
- Option 2: Download `msman.sh` from release to where you want your minecraft
server and start it with
```bash
chmod +x msman.sh
./msman.sh
```
- Option 2: Clone the repository
```bash
git clone https://github.com/jiriks74/msman.sh minecraft_server
cd minecraft_server
chmod +x msman.sh
./msman.sh
```
## Updating the server

Binary file not shown.

@ -1,51 +0,0 @@
#!/bin/bash
set -e
# Detect the server type
function get_existing_server {
if ls paper-*.jar 1> /dev/null 2>&1; then
existing_server_type="paper"
get_existing_paper
# TODO: Add support for other server types
# elif ls fabric-*.jar 1> /dev/null 2>&1; then
# existing_server_type="fabric"
# elif ls spigot-*.jar 1> /dev/null 2>&1; then
# existing_server_type="spigot"
# elif ls craftbukkit-*.jar 1> /dev/null 2>&1; then
# existing_server_type="craftbukkit"
# elif ls vanilla-*.jar 1> /dev/null 2>&1; then
# existing_server_type="vanilla"
else
if ! ls *.jar 1> /dev/null 2>&1; then
echo "No server file found."
echo
echo
existing_server_type=false
server_file=false
else
>&2 echo "$(ls *.jar) file was found."
>&2 echo "Unknown server type."
exit 10
# TODO: Ask the user if they want to continue
fi
fi
}
# Get existing version and build of paper
function get_existing_paper {
# Get the current server file name
server_file=$(basename ./paper-*.jar)
# Extract the version and build number using cut command
current_version=$(echo "$server_file" | cut -d'-' -f2)
current_build=$(echo "$server_file" | cut -d'-' -f3)
# Remove the rest of the file names
current_version="${current_version%-*}"
current_build="${current_build%.jar}"
echo "Current server file: $server_file"
echo " - Version $current_version"
echo " - Build $current_build"
echo
echo
}

@ -1,3 +0,0 @@
#!/bin/bash
EXTRA_SCRIPTS_VERSION="v1.0.1"

@ -1,7 +1,7 @@
#############################################################
# Settings for start_papermc.sh script #
# Available at https://github.com/jiriks74/start_papermc.sh #
#############################################################
#####################################################
# Settings for start_papermc.sh script #
# Available at https://github.com/jiriks74/msman.sh #
#####################################################
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# This script is not made for migrating versions. #
@ -14,7 +14,9 @@
# I am not responsible for any loss of data #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# Only paper is currently supported
# Supported server types:
# - paper
# - fabric
server_type="paper"
version="1.19.3"
# Leave blank to use the latest build (auto updates on every run)
@ -38,7 +40,7 @@ mem="6000M"
# Flags for the server itself
# Usefull fot setting rcon password, server port, etc.
mc_launchoptions="-nogui"
mc_launchoptions="nogui"
# If you want to get rid of script updates notifications, set the below to false
check_for_script_updates=true

124
msman.sh

@ -3,12 +3,12 @@ set -e
#############################################################################################################
# MinecraftServerMANager #
# by jiriks74 #
# https://github.com/jiriks74/start_papermc.sh #
# https://github.com/jiriks74/msman.sh #
# This script is under GPLv3, if you want to distribute changes you have to do so under the same license #
# and acknowledge the original script and author. #
#############################################################################################################
CURRENT_SCRIPT_VERSION="v1.0.1"
CURRENT_SCRIPT_VERSION="v2.1.6"
# --------------------------------------------------
# You shouldn't need to change anything in this file
@ -107,7 +107,7 @@ function ask_version_differs {
echo
echo
echo "The current server version differs from the one you selected."
echo "The server version is $current_version and the selected version is $select_version."
echo "The server version is $current_version and the selected version is $version."
echo "Do you want to update the server version?"
echo "This can cause many issues if you don't know what you are doing."
echo
@ -132,6 +132,36 @@ function ask_version_differs {
fi
}
# Ask if the new server version differs from the old one
function ask_server_type_differs {
echo
echo
echo "The current server type differs from the one you selected."
echo "The server version is $existing_server_type and the selected type is $server_type."
echo "Do you want to change the server type?"
echo "This can cause many issues if you don't know what you are doing."
echo
echo "I am not responsible for any data loss caused by changing the server type."
echo
echo "You have 15 seconds to respond, or the script will exit"
read -t 15 -p "Do you want to change the server type? [y/N] " type_differs
if [ "$type_differs" != "y" ] && [ "$type_differs" != "Y" ]; then
echo "Server type not changed."
echo "To start the server again with the server type, change the server type in the config to $existing_server_type."
exit 4
fi
if [ "$type_differs" == "y" ] || [ "$type_differs" == "Y" ]; then
read -t 15 -p "Are you sure you want to change the server type? [y/N] " type_differs
if [ "$type_differs" != "y" ] && [ "$type_differs" != "Y" ]; then
echo "Server type not changed."
echo "To start the server again with the server type, change the server type in the config to $existing_server_type."
exit 4
fi
fi
}
# Ask if the new server version differs from the old one
function ask_server_differs {
echo
@ -199,7 +229,7 @@ function launch_server {
echo "Starting the server..."
echo
echo
java $java_launchoptions -jar "$(basename ./paper-*.jar)" $mc_launchoptions
java $java_launchoptions -jar $server_file $mc_launchoptions
}
# Helper scripts update
@ -207,20 +237,22 @@ function helper_scripts_update {
# Download matching version of helper scripts
echo "Updating helper scripts..."
# Download the file into ms-man-helper.tar.gz
if [[ $(curl -sLJ -w '%{http_code}\n' "https://github.com/jiriks74/msman.sh/releases/download/v1.0.0/ms-man-helper.tar.gz" -o msman-helper.tar.gz) == 200 ]]; then
# Remove the last line of the file
# sed -i '$d' ms-man-helper.tar.gz
if [[ $(curl -sLJ -w '%{http_code}\n' "https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/$CURRENT_SCRIPT_VERSION/msman-helper.tar.gz" -o msman-helper.tar.gz) == 200 ]]; then
# Extract the files from ms-man-helper.tar.gz
tar -xzf msman-helper.tar.gz
# Remove the old script
echo "Removing old helper scripts..."
rm -rf .msman
echo "Removed old script"
if [ -d .msman ]; then
# Remove the old scripts
echo "Removing old helper scripts..."
rm -rf .msman
echo "Removed old script"
fi
echo "Moving new helper scripts into place..."
mv msman .msman
mv msman/.msman .msman
echo "Removing temporary files..."
rm msman-helper.tar.gz
rm -rf msman
echo "Helper scripts updated successfully."
EXTRA_SCRIPTS_VERSION=$(echo $CURRENT_SCRIPT_VERSION)
echo
echo
else
@ -235,20 +267,20 @@ function helper_scripts_update {
function self_update {
# Download the latest version of the script
echo "Updating script..."
# Download the file into start_new.sh
curl -sLJ -w '%{http_code}\n' "https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/$LATEST_SCRIPT_VERSION/start.sh" > msman_new.sh
# Check if the download was successful by checking the last line of the file for 200
if [[ $(cat start_new.sh | tail -n 1) == 200 ]]; then
# Remove the last line of the file
sed -i '$d' msman_new.sh
# Download the file into msman_new.sh
if [[ $(curl -sLJ -w '%{http_code}\n' "https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/$LATEST_SCRIPT_VERSION/msman.sh" -o msman_new.sh) == 200 ]]; then
# Make the file executable
chmod +x msman_new.sh
# Remove the old script
rm msman.sh
echo "Removed old script"
if [[ -f msman.sh ]]; then
echo "Removing old script..."
rm msman.sh
echo "Removed old script"
fi
echo "Moving new script into place..."
# Rename the new script
mv msman_new.sh msman.sh
echo "Renamed new script"
echo "Moved new script into place"
echo "Script updated successfully."
echo
else
@ -318,8 +350,9 @@ function check_self_update {
read -t 15 -p "Do you want to update? [y/N] " update
if [ "$update" == "y" ] || [ "$update" == "Y" ]; then
self_update
CURRENT_VERSION=$LATEST_SCRIPT_VERSION
CURRENT_SCRIPT_VERSION=$LATEST_SCRIPT_VERSION
check_helper_scripts
bash -c "$(pwd)/msman.sh"
else
echo "Skipping update."
return
@ -337,12 +370,7 @@ function load_config {
echo "Config file does not exist."
echo "Downloading the default config file..."
# Download the default config file for the current version
curl -sLJ -w '%{http_code}' "https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/$CURRENT_SCRIPT_VERSION/msman.cfg" > msman.cfg
# Check if the download was successful by checking the last line of the file for 200
if [[ $(cat msman.cfg | tail -n 1) == 200 ]]; then
# Remove the last line of the file
sed -i '$d' msman.cfg
if [[ $(curl -sLJ -w '%{http_code}\n' "https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/$CURRENT_SCRIPT_VERSION/msman.cfg" -o msman.cfg) == 200 ]]; then
echo
read -p "Do you want to edit the config file? [y/N] " edit_config
if [ "$edit_config" == "y" ] || [ "$edit_config" == "Y" ]; then
@ -380,7 +408,7 @@ function load_config {
# Delete old server file with name $old_server_file
function delete_old_server {
# Delete the old server file
echo "Deleting old server file $server_file..."
echo "Deleting old server file '$server_file...'"
rm "$old_server_file"
echo "Old server file deleted."
}
@ -395,12 +423,12 @@ function load_script {
# Load the correct script
if [[ $server_type == "paper" ]]; then
source "./.msman/paper.sh"
elif [[ $server_type == "fabric" ]]; then
source "./.msman/fabric.sh"
# elif [[ $server_type == "vanilla" ]]; then
# source "$cwd/msman/vanilla.sh"
# elif [[ $server_type == "forge" ]]; then
# source "$cwd/msman/forge.sh"
# elif [[ $server_type == "fabric" ]]; then
# source "$cwd/msman/fabric.sh"
else
>&2 echo "Unknown server type."
echo "Exiting..."
@ -412,9 +440,9 @@ function load_script {
first_run() {
if [[ $first_run == true ]]; then
answer=""
echo "Since eula wasn't accepted, this is probably the first run of the server"
echo "Since eula wasn't accepted, this is probably the first run of the server."
echo "If you want to install plugins (or mods), answer 'n' and you can do so."
echo "If you don't answer, the server will start in 15 secondd."
echo "If you don't answer, the server will start in 15 seconds."
read -t 15 -p "Do you want to start the server now? [Y/n] " answer
if [ "$answer" == "n" ] || [ "$answer" == "N" ]; then
echo "Exiting..."
@ -448,6 +476,13 @@ function main {
# Gets the installed server info
get_existing_server
# Check if the server type differs from the one in the config
if [[ $server_file != false ]]; then
if [[ $existing_server_type != $server_type ]]; then
ask_server_differs
fi
fi
# Check if the version and build are valid
check_version_valid
@ -463,21 +498,28 @@ function main {
# Check if this is the first run
first_run
# Set the java arguments
set_java_args
# Launch the server
launch_server
}
# Check for updates on GitHub
if [[ "$1" == "--redownload" ]] || [[ "$1" == "-r" ]]; then
self_update
# TODO: Add `--edit-config` option
if [[ "$1" == "--edit-config" ]] || [[ "$1" == "-e" ]]; then
if ! command -v $EDITOR &> /dev/null; then
echo "EDITOR is not set."
echo "Open 'msman.cfg' manually."
exit 1
else
$EDITOR msman.cfg
exit 0
fi
elif [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
echo "Usage: ./script.sh [OPTION]"
echo "Usage: ./msman.sh [OPTION]"
echo "Starts the Minecraft server."
echo
echo
echo "Options:"
echo " -r, --redownload Redownloads the script from GitHub."
echo " -h, --help Show this help message."
echo " -e, --edit-config Edit the config file."
echo " -h, --help Show this help message."
echo
echo "To change the settings of the script, edit the 'msman.cfg' file."
echo "If the file does not exist, it will be downloaded automatically when the script is run and you will be asked if you want to edit it."