From 401212cadedd49705ad58c4c850e0ba6391c1ed7 Mon Sep 17 00:00:00 2001 From: Leonard Steppy Date: Mon, 22 Dec 2025 17:18:32 +0100 Subject: [PATCH] Add fetch and help options to configure.sh --- configure.sh | 131 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 100 insertions(+), 31 deletions(-) diff --git a/configure.sh b/configure.sh index 1ce6711..962264c 100755 --- a/configure.sh +++ b/configure.sh @@ -1,33 +1,102 @@ #!/usr/bin/env bash -if [ "$1" == "velocity" ]; then - #disable online-mode - sed -ie "/online-mode/c\online-mode=false" server.properties - #change port to 25566 - sed -ie "/server-port/c\server-port=25566" server.properties - #enable velocity - yq -iy ".proxies.velocity.enabled = true" config/paper-global.yml - #disable bungeecord - yq -iy ".settings.bungeecord = false" spigot.yml -elif [ "$1" == "bungeecord" ]; then - #disable online-mode - sed -ie "/online-mode/c\online-mode=false" server.properties - #change port to 25566 - sed -ie "/server-port/c\server-port=25566" server.properties - #disable velocity - yq -iy ".proxies.velocity.enabled = false" config/paper-global.yml - #enable bungeecord - yq -iy ".settings.bungeecord = true" spigot.yml -elif [ "$1" == "standalone" ]; then - #enable online-mode - sed -ie "/online-mode/c\online-mode=true" server.properties - #change port to 25565 - sed -ie "/server-port/c\server-port=25565" server.properties - #disable velocity - yq -iy ".proxies.velocity.enabled = false" config/paper-global.yml - #disable bungeecord - yq -iy ".settings.bungeecord = false" spigot.yml -else - echo "Invalid argument, possible values are: [velocity, standalone, bungeecord]" - exit 1 -fi +function main { + + # parse arguments + velocity=false + bungeecord=false + standalone=false + fetch=false + help=false + + for arg in "@$"; do + case "$arg" in + "velocity") + velocity=true + if $bungeecord || $standalone; then + echo "argument velocity can't be used together with bungeecord or standalone" + exit 1 + fi + ;; + "benugeecord") + bungeecord=true + if $velocity || $standalone; then + echo "argument bungeecord can't be used together with velocity or standalone" + exit 1 + fi + ;; + "standalone") + standalone=true + if $bungeecord || $velocity; then + echo "argument standalone can't be used together with bungeecord or velocity" + exit 1 + fi + ;; + "--fetch") + fetch=true + ;; + "--help") + help=true + ;; + esac + done + + if $help; then + echo "Configure the server to be used with BungeeCord, Velcity or in standalone mode." + echo "" + echo "Usage $0 [OPTIONS] " + echo "" + echo "mode:" + echo " velocity" + echo " bungeecord" + echo " standalone" + echo "" + echo "OPTIONS:" + echo " --fetch - print the current mode before reconfiguring the server. Nothing else will be printed." + echo " --help - show this message" + exit 0 + fi + + # fetch current configuration + if $fetch; then + if [ "$(yq '.proxies.velocity.enabled // false' config/paper-global.yml)" = "true" ]; then + echo "velocity" + elif [ "$(yq '.settings.bungeecord // false' spigot.yml)" = "true" ]; then + echo "bungeecord" + else + echo "standalone" + fi + fi + + # TODO clean this part up a bit + if $velocity; then + #disable online-mode + sed -ie "/online-mode/c\online-mode=false" server.properties + #change port to 25566 + sed -ie "/server-port/c\server-port=25566" server.properties + #enable velocity + yq -iy ".proxies.velocity.enabled = true" config/paper-global.yml + #disable bungeecord + yq -iy ".settings.bungeecord = false" spigot.yml + elif $bungeecord; then + #disable online-mode + sed -ie "/online-mode/c\online-mode=false" server.properties + #change port to 25566 + sed -ie "/server-port/c\server-port=25566" server.properties + #disable velocity + yq -iy ".proxies.velocity.enabled = false" config/paper-global.yml + #enable bungeecord + yq -iy ".settings.bungeecord = true" spigot.yml + elif $standalone; then + #enable online-mode + sed -ie "/online-mode/c\online-mode=true" server.properties + #change port to 25565 + sed -ie "/server-port/c\server-port=25565" server.properties + #disable velocity + yq -iy ".proxies.velocity.enabled = false" config/paper-global.yml + #disable bungeecord + yq -iy ".settings.bungeecord = false" spigot.yml + fi +} + +main