Refactor, add support for version changing
This commit is contained in:
parent
2efcddd508
commit
c7e6877fd1
Binary file not shown.
383
start.sh
383
start.sh
@ -18,7 +18,7 @@
|
|||||||
# I am not responsible for any loss of data #
|
# I am not responsible for any loss of data #
|
||||||
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
|
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
|
||||||
# If enough people request it (or someone creates a PR) I'll add the functionality to migrate versions
|
# If enough people request it (or someone creates a PR) I'll add the functionality to migrate versions
|
||||||
version="1.12.2"
|
select_version="1.19.3"
|
||||||
# Leave blank to use the latest build (auto updates on every run)
|
# Leave blank to use the latest build (auto updates on every run)
|
||||||
select_build=""
|
select_build=""
|
||||||
|
|
||||||
@ -32,55 +32,34 @@ select_build=""
|
|||||||
# lower than your available memory if you're running just the #
|
# lower than your available memory if you're running just the #
|
||||||
# minecraft server. #
|
# minecraft server. #
|
||||||
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
|
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
|
||||||
mem="2000M"
|
mem="6000M"
|
||||||
|
|
||||||
|
#############
|
||||||
|
# Overrides #
|
||||||
|
#############
|
||||||
|
|
||||||
|
# Shouldn't be needed, but if for whatever reason you want to override some things, use the below options
|
||||||
|
|
||||||
|
java_version_override=false
|
||||||
|
|
||||||
|
# Aikar's flags are used by defauls (https://docs.papermc.io/paper/aikars-flags)
|
||||||
|
# And are set by memory usage so if you allocated more than 12GB or RAM they are set automatically
|
||||||
|
override_java_flags=false
|
||||||
|
java_launchoptions=""
|
||||||
|
|
||||||
|
# Flags for the server itself
|
||||||
|
mc_launchoptions="-nogui"
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
# You shouldn't need to change anything below this
|
# You shouldn't need to change anything below this
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
|
|
||||||
# Options for the server
|
# API URL
|
||||||
mc_launchoptions="-nogui"
|
api_url="https://api.papermc.io/v2/projects/paper/versions/$select_version/builds"
|
||||||
|
|
||||||
if [[ "${mem%M}" -gt 12000 ]]; then
|
|
||||||
G1NewSize=40
|
|
||||||
G1MaxNewSize=50
|
|
||||||
G1HeapRegionSize=16M
|
|
||||||
G1Reserve=15
|
|
||||||
InitiatingHeapOccupancy=20
|
|
||||||
else
|
|
||||||
G1NewSize=30
|
|
||||||
G1MaxNewSize=40
|
|
||||||
G1HeapRegionSize=8M
|
|
||||||
G1Reserve=20
|
|
||||||
InitiatingHeapOccupancy=15
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Aikar's flags are used by default
|
|
||||||
# See https://docs.papermc.io/paper/aikars-flags
|
|
||||||
java_launchoptions="-Xms$mem -Xmx$mem -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=$G1NewSize -XX:G1MaxNewSizePercent=$G1MaxNewSize -XX:G1HeapRegionSize=$G1HeapRegionSize -XX:G1ReservePercent=$G1Reserve -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=$InitiatingHeapOccupancy -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true"
|
|
||||||
|
|
||||||
# Api url
|
|
||||||
url="https://api.papermc.io/v2/projects/paper/versions/$version/builds"
|
|
||||||
|
|
||||||
##########
|
|
||||||
# Checks #
|
|
||||||
##########
|
|
||||||
|
|
||||||
# Check if selected version exists
|
|
||||||
if curl -s "$url" | grep -q '{"error":"Version not found."}'; then
|
|
||||||
echo "Error: Invalid version selected: $version"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
# Check if selected build exists
|
|
||||||
if [ ! -z "$select_build" ]; then
|
|
||||||
if curl -Is "https://api.papermc.io/v2/projects/paper/versions/$version/builds/$select_build/downloads/paper-$version-$select_build.jar" | grep "HTTP/2 404" >/dev/null; then
|
|
||||||
echo "Error: Invalid build selected: $select_build"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Check for dependencies
|
||||||
|
function check_dependencies {
|
||||||
# Check if curl is installed
|
# Check if curl is installed
|
||||||
if ! command -v curl &> /dev/null
|
if ! command -v curl &> /dev/null
|
||||||
then
|
then
|
||||||
@ -101,27 +80,23 @@ then
|
|||||||
echo "Error: awk is not installed"
|
echo "Error: awk is not installed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Check if java is installed
|
# Check if the version and build are valid
|
||||||
if ! command -v java &> /dev/null
|
function check_version_valid {
|
||||||
then
|
if curl -s "$api_url" | grep -q '{"error":"Version not found."}'; then
|
||||||
echo "Error: Java is not installed"
|
echo "Error: Invalid version selected: $select_version"
|
||||||
java_version="0"
|
exit 2
|
||||||
|
else
|
||||||
|
# Check if selected build exists
|
||||||
|
if [ ! -z "$select_build" ]; then
|
||||||
|
if curl -Is "https://api.papermc.io/v2/projects/paper/versions/$select_version/builds/$select_build/downloads/paper-$select_version-$select_build.jar" | grep "HTTP/2 404" >/dev/null; then
|
||||||
|
echo "Error: Invalid build selected: $select_build"
|
||||||
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#####################################################
|
|
||||||
# Check if the correct version of Java is installed #
|
|
||||||
#####################################################
|
|
||||||
#
|
|
||||||
|
|
||||||
# Extract the middle number of the Minecraft version
|
|
||||||
minecraft_middle=$(echo "$version" | awk -F '.' '{print $2}')
|
|
||||||
|
|
||||||
# If java is installed, get the version (the java_version won't be 0)
|
|
||||||
if [[ $java_version != "0" ]]; 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
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Ask if the user wants to continue anyway
|
# Ask if the user wants to continue anyway
|
||||||
# If the user doesn't answer in 15 seconds, the script will exit
|
# If the user doesn't answer in 15 seconds, the script will exit
|
||||||
@ -130,153 +105,266 @@ function ask_continue {
|
|||||||
answer=""
|
answer=""
|
||||||
echo "You have 15 seconds to respond before the script exits."
|
echo "You have 15 seconds to respond before the script exits."
|
||||||
read -t 15 -p "Do you want to continue anyway? [y/N]: " answer
|
read -t 15 -p "Do you want to continue anyway? [y/N]: " answer
|
||||||
if [[ $answer != "y" ]] || [[ $answer != "Y" ]]; then
|
if [[ $answer != "y" ]] && [[ $answer != "Y" ]]; then
|
||||||
echo "Exiting..."
|
echo "Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the correct version of java is installed
|
# Check if the correct version of Java is installed
|
||||||
# For version 1.8 to 1.11 use java 8
|
# For version 1.8 to 1.11 use java 8
|
||||||
# For version 1.12 to 1.16.4 use java 11
|
# For version 1.12 to 1.16.4 use java 11
|
||||||
# For version 1.16.5 use java 16
|
# For version 1.16.5 use java 16
|
||||||
# For version 1.17.1 to 1.18.1+ use java 17
|
# For version 1.17.1 to 1.18.1+ use java 17
|
||||||
|
function check_java {
|
||||||
|
# Check if java is installed
|
||||||
|
if ! command -v java &> /dev/null
|
||||||
|
then
|
||||||
|
echo "Error: Java is not installed"
|
||||||
|
java_version="0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract the middle number of the Minecraft version
|
||||||
|
minecraft_middle=$(echo "$select_version" | awk -F '.' '{print $2}')
|
||||||
|
|
||||||
|
# If java is installed, get the version (the java_version won't be 0)
|
||||||
|
if [[ $java_version != "0" ]]; 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
|
||||||
|
|
||||||
|
# Check if the correct version of java is installed
|
||||||
if (( 8 <= minecraft_middle && minecraft_middle <= 11 )); then
|
if (( 8 <= minecraft_middle && minecraft_middle <= 11 )); then
|
||||||
if ! [[ $java_version -eq 8 ]]; then
|
if ! [[ $java_version -eq 8 ]]; then
|
||||||
echo "Java 8 is required for Minecraft version $version. Please install Java 8."
|
echo "Java 8 is required for Minecraft version $select_version. Please install Java 8."
|
||||||
if [[ $java_version == 0 ]]; then
|
if [[ $java_version == 0 ]]; then
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
ask_continue
|
ask_continue
|
||||||
fi
|
fi
|
||||||
elif (( 12 <= minecraft_middle && minecraft_middle <= 16 )); then
|
elif (( 12 <= minecraft_middle && minecraft_middle <= 16 )); then
|
||||||
if ! [[ $java_version -eq 11 ]]; then
|
if ! [[ $java_version -eq 11 ]]; then
|
||||||
if [[ $java_version == 0 ]]; then
|
if [[ $java_version == 0 ]]; then
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
echo "Java 11 is required for Minecraft version $version. Please install Java 11."
|
echo "Java 11 is required for Minecraft version $select_version. Please install Java 11."
|
||||||
ask_continue
|
ask_continue
|
||||||
fi
|
fi
|
||||||
elif (( minecraft_middle == 17 )); then
|
elif (( minecraft_middle == 17 )); then
|
||||||
if ! [[ $java_version -eq 16 ]]; then
|
if ! [[ $java_version -eq 16 ]]; then
|
||||||
echo "Java 16 is required for Minecraft version $version. Please install Java 16."
|
echo "Java 16 is required for Minecraft version $select_version. Please install Java 16."
|
||||||
if [[ $java_version == 0 ]]; then
|
if [[ $java_version == 0 ]]; then
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
ask_continue
|
ask_continue
|
||||||
fi
|
fi
|
||||||
elif (( 18 <= minecraft_middle )); then
|
elif (( 18 <= minecraft_middle )); then
|
||||||
if ! [[ $java_version -eq 17 ]]; then
|
if ! [[ $java_version -eq 17 ]]; then
|
||||||
echo "Java 17 is required for Minecraft version $version. Please install Java 17."
|
echo "Java 17 is required for Minecraft version $select_version. Please install Java 17."
|
||||||
if [[ $java_version == 0 ]]; then
|
if [[ $java_version == 0 ]]; then
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
ask_continue
|
ask_continue
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Unsupported Minecraft version $version."
|
echo "Unsupported Minecraft version $select_version."
|
||||||
if [[ $java_version == 0 ]]; then
|
if [[ $java_version == 0 ]]; then
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
ask_continue
|
ask_continue
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Check if some server already exists
|
# Get existing version and build
|
||||||
|
function get_existing_version {
|
||||||
if ls paper-*.jar 1> /dev/null 2>&1; then
|
if ls paper-*.jar 1> /dev/null 2>&1; then
|
||||||
# Get the current server file name
|
# Get the current server file name
|
||||||
server_file=$(basename ./paper-*.jar)
|
server_file=$(basename ./paper-*.jar)
|
||||||
|
|
||||||
# Extract the build number using cut command
|
# 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)
|
current_build=$(echo "$server_file" | cut -d'-' -f3)
|
||||||
|
current_version="${current_version%-*}"
|
||||||
current_build="${current_build%.jar}"
|
current_build="${current_build%.jar}"
|
||||||
|
echo "Current server file: $server_file"
|
||||||
|
echo " - Version $current_version"
|
||||||
|
echo " - Build $current_build"
|
||||||
|
else
|
||||||
|
echo "No old server file found."
|
||||||
|
server_file=false
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Check if select_build variable is set
|
# Download server set by $select_version and $download_build
|
||||||
if [ -z "$select_build" ]; then
|
function download_server {
|
||||||
echo "Checking for newer build..."
|
# Download the server
|
||||||
json_response=$(curl -s "$url") # Get all the versions from the paper api
|
echo "Downloading PaperMC server..."
|
||||||
|
echo " - Version $select_version"
|
||||||
|
echo " - Build $download_build"
|
||||||
|
curl -s "https://api.papermc.io/v2/projects/paper/versions/$select_version/builds/$download_build/downloads/paper-$select_version-$download_build.jar" -o "./paper-$select_version-$download_build.jar"
|
||||||
|
echo "Download complete."
|
||||||
|
}
|
||||||
|
|
||||||
# Get the latest build number
|
# Delete old server file with name $old_server_file
|
||||||
latest_build=$(curl -s $url | jq '.builds[-1].build')
|
function delete_old_server {
|
||||||
|
# Delete the old server file
|
||||||
|
echo "Deleting old server file $server_file..."
|
||||||
|
rm "$old_server_file"
|
||||||
|
echo "Old server file deleted."
|
||||||
|
}
|
||||||
|
|
||||||
# Check if the latest build is newer than the current build
|
# Set arguments for java
|
||||||
if [ "$latest_build" -gt "$current_build" ]; then
|
function set_java_args {
|
||||||
echo "Newer build available: $latest_build"
|
# Check if $override_flags is not true
|
||||||
|
if [[ $override_flags != true ]]; then
|
||||||
|
if [[ "${mem%M}" -gt 12000 ]]; then
|
||||||
|
G1NewSize=40
|
||||||
|
G1MaxNewSize=50
|
||||||
|
G1HeapRegionSize=16M
|
||||||
|
G1Reserve=15
|
||||||
|
InitiatingHeapOccupancy=20
|
||||||
|
else
|
||||||
|
G1NewSize=30
|
||||||
|
G1MaxNewSize=40
|
||||||
|
G1HeapRegionSize=8M
|
||||||
|
G1Reserve=20
|
||||||
|
InitiatingHeapOccupancy=15
|
||||||
|
fi
|
||||||
|
# Aikar's flags are used by default
|
||||||
|
# See https://docs.papermc.io/paper/aikars-flags
|
||||||
|
java_launchoptions="-Xms$mem -Xmx$mem -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=$G1NewSize -XX:G1MaxNewSizePercent=$G1MaxNewSize -XX:G1HeapRegionSize=$G1HeapRegionSize -XX:G1ReservePercent=$G1Reserve -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=$InitiatingHeapOccupancy -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Ask the user if they want to download and install the new build
|
# Ask if the new server version differs from the old one
|
||||||
|
function ask_version_differs {
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
echo "You have 15 seconds to answer, then the new build will be downloaded automatically"
|
echo "The server version differs from the one you selected."
|
||||||
read -t 15 -p "Do you want to download and install the new build? (Y/n) " answer
|
echo "The server version is $current_version and the selected version is $select_version."
|
||||||
# If the user doesn't answer set the answer to "y"
|
echo "Do you want to update the server version?"
|
||||||
if [ -z "$answer" ]; then
|
echo "This can cause many issues if you don't know what you are doing."
|
||||||
answer="y"
|
echo
|
||||||
|
echo "I am not responsible for any damage caused by updating the server version."
|
||||||
|
echo
|
||||||
|
echo "You have 15 seconds to respond, or the script will exit"
|
||||||
|
read -t 15 -p "Do you want to update the server version? [y/N] " version_differs
|
||||||
|
|
||||||
|
if [ "$version_differs" != "y" ] && [ "$version_differs" != "Y" ]; then
|
||||||
|
echo "Server version not updated."
|
||||||
|
echo "To start the server again with the current version, change the version in the config to $current_version."
|
||||||
|
exit 4
|
||||||
fi
|
fi
|
||||||
if [ "$answer" == "y" ]; then
|
|
||||||
# Download the new build
|
|
||||||
echo "Downloading the new build..."
|
|
||||||
curl -s "https://api.papermc.io/v2/projects/paper/versions/$version/builds/$latest_build/downloads/paper-$version-$latest_build.jar" -o "./paper-$version-$latest_build.jar"
|
|
||||||
echo "Download complete"
|
|
||||||
|
|
||||||
# Remove the old server file
|
if [ "$version_differs" == "y" ] || [ "$version_differs" == "Y" ]; then
|
||||||
echo "Removing the old server file..."
|
read -t 15 -p "Are you sure you want to update the server version? [y/N] " version_differs
|
||||||
rm "$server_file"
|
if [ "$version_differs" != "y" ] && [ "$version_differs" != "Y" ]; then
|
||||||
echo "Old server file removed"
|
echo "Server version not updated."
|
||||||
|
echo "To start the server again with the current version, change the version in the config to $current_version."
|
||||||
|
exit 4
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
server_file=$(basename ./paper-*.jar)
|
# Check if up to date
|
||||||
|
function check_up_to_date {
|
||||||
|
if [[ $server_file == false ]]; then
|
||||||
|
download_build=$latest_build
|
||||||
|
update_version=true
|
||||||
|
update_build=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if $select_build is empty
|
||||||
|
if [[ -z $select_build ]]; then
|
||||||
|
# Check if the current version is the same as the one selected
|
||||||
|
if [[ $current_version == $select_version ]]; then
|
||||||
|
# Check if the current build is the same as the one selected
|
||||||
|
if [[ $current_build == $latest_build ]]; then
|
||||||
|
echo "Server is up to date."
|
||||||
else
|
else
|
||||||
echo "Skipping download and installation"
|
echo "Server is not up to date."
|
||||||
|
download_build=$latest_build
|
||||||
|
update_build=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Server is up to date"
|
# 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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ "$current_build" -ne "$select_build" ]; then
|
# Check if the current version is the same as the one selected
|
||||||
echo "The current build is not the selected build"
|
if [[ $current_version == $select_version ]]; then
|
||||||
echo "Downloading the selected build..."
|
# Check if the current build is the same as the one selected
|
||||||
curl -s "https://api.papermc.io/v2/projects/paper/versions/$version/builds/$select_build/downloads/paper-$version-$select_build.jar" -o "./paper-$version-$select_build.jar"
|
if [[ $current_build == $select_build ]]; then
|
||||||
echo "Download complete"
|
echo "Server is up to date."
|
||||||
|
|
||||||
echo "Removing the old server file..."
|
|
||||||
rm "$server_file"
|
|
||||||
echo "Old server file removed"
|
|
||||||
server_file=$(basename ./paper-*.jar)
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If no server file exists
|
|
||||||
else
|
else
|
||||||
# Check if select_build variable is set
|
echo "Server is not up to date."
|
||||||
if [ -z "$select_build" ]; then
|
download_build=$select_build
|
||||||
echo "Downloading the latest build of version $version..."
|
update_build=true
|
||||||
json_response=$(curl -s "$url")
|
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=$select_build
|
||||||
|
update_version=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Get the latest build number
|
# Get the latest build number
|
||||||
latest_build=$(curl -s $url | jq '.builds[-1].build')
|
function get_latest_build {
|
||||||
|
# Get the latest build number
|
||||||
|
latest_build=$(curl -s $api_url | jq '.builds[-1].build')
|
||||||
|
}
|
||||||
|
|
||||||
curl -s "https://api.papermc.io/v2/projects/paper/versions/$version/builds/$latest_build/downloads/paper-$version-$latest_build.jar" -o "./paper-$version-$latest_build.jar"
|
# Check for updates
|
||||||
echo "Download complete"
|
function check_and_update {
|
||||||
|
# Get current version and build
|
||||||
|
get_existing_version
|
||||||
|
|
||||||
|
echo Checking for updates...
|
||||||
|
# Get the latest build number
|
||||||
|
get_latest_build
|
||||||
|
|
||||||
|
# Check if the current version is up to date
|
||||||
|
check_up_to_date
|
||||||
|
|
||||||
|
# Check if $build_update is true or $version_update is true
|
||||||
|
if [[ $update_build == true ]] || [[ $update_version == true ]]; then
|
||||||
|
if [[ $server_file != false ]]; then
|
||||||
|
old_server_file=$server_file
|
||||||
|
server_file="paper-$select_version-$download_build.jar"
|
||||||
|
download_server
|
||||||
|
# Delete the old server file
|
||||||
|
delete_old_server
|
||||||
else
|
else
|
||||||
echo "Downloading version $version build $select_build..."
|
server_file="paper-$select_version-$download_build.jar"
|
||||||
curl -s "https://api.papermc.io/v2/projects/paper/versions/$version/builds/$select_build/downloads/paper-$version-$select_build.jar" -o "./paper-$version-$select_build.jar"
|
download_server
|
||||||
echo "Download complete"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Accept EULA
|
||||||
|
function accept_eula {
|
||||||
if test "$(cat eula.txt 2>/dev/null)" != "eula=true"; then
|
if test "$(cat eula.txt 2>/dev/null)" != "eula=true"; then
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
echo "'eula.txt' does not exist or is not accepted"
|
echo "'eula.txt' does not exist or EULA is not accepted"
|
||||||
echo "Please agree to the Minecraft EULA by entering 'y'"
|
echo "You have to accept the Minecraft EULA to run the server"
|
||||||
echo "By entering 'y' you are indicating your agreement to Minecraft's EULA (https://aka.ms/MinecraftEULA)."
|
echo "By entering 'y' you are indicating your agreement to Minecraft's EULA (https://aka.ms/MinecraftEULA)."
|
||||||
echo "You have 15 seconds to respond, or the script will exit"
|
echo "You have 15 seconds to respond, or the script will exit"
|
||||||
read -t 15 -p "Do you agree to the Minecraft EULA? [y/N] " eula_agreed
|
read -t 15 -p "Do you agree to the Minecraft EULA? [y/N] " eula_agreed
|
||||||
|
|
||||||
if [ "$eula_agreed" == "y" ]; then
|
if [ "$eula_agreed" == "y" ] || [ "$eula_agreed" == "Y" ]; then
|
||||||
if [ ! -f eula.txt ]; then
|
if [ ! -f eula.txt ]; then
|
||||||
# Write eula_agreed to eula.txt
|
|
||||||
echo "eula=true" > eula.txt
|
echo "eula=true" > eula.txt
|
||||||
else
|
else
|
||||||
rm eula.txt
|
rm eula.txt
|
||||||
@ -293,9 +381,38 @@ if test "$(cat eula.txt 2>/dev/null)" != "eula=true"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Run the server
|
# Launch the server
|
||||||
|
function launch_server {
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
echo "Starting the server..."
|
echo "Starting the server..."
|
||||||
|
echo
|
||||||
|
echo
|
||||||
java $java_launchoptions -jar "$(basename ./paper-*.jar)" $mc_launchoptions
|
java $java_launchoptions -jar "$(basename ./paper-*.jar)" $mc_launchoptions
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
function main {
|
||||||
|
# Check dependencies
|
||||||
|
check_dependencies
|
||||||
|
|
||||||
|
# Check if the version and build are valid
|
||||||
|
check_version_valid
|
||||||
|
|
||||||
|
# Check if the correct java version is installed
|
||||||
|
check_java
|
||||||
|
|
||||||
|
# Check if the server is up to date and if not, update it
|
||||||
|
check_and_update
|
||||||
|
|
||||||
|
# Accept EULA
|
||||||
|
accept_eula
|
||||||
|
|
||||||
|
# Launch the server
|
||||||
|
launch_server
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the main function
|
||||||
|
main
|
||||||
|
Loading…
x
Reference in New Issue
Block a user