Compare commits

...

2 Commits

Author SHA1 Message Date
Leonard Steppy
c870aae9da Implement functionality of config parameter 2025-12-25 20:08:14 +01:00
Leonard Steppy
95f5d293bf Ensure mode is valid and config parameter is incompatible with proxy and bungee parameters 2025-12-25 19:22:14 +01:00

108
start.sh
View File

@ -2,6 +2,10 @@
# THe name of the screen in which the proxy server will run
PROXY_SCREEN="proxy"
# The relative path of the velocity proxy server
VELOCITY_DIR="proxy"
# The relative path of the bungeecord proxy server
BUNGEE_DIR="bungee"
# How many seconds to sleep before starting the server again, unless it is explicitly specified
DEFAULT_SLEEP_SECONDS=3
@ -11,17 +15,43 @@ function main {
local help=false
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
local config=""
local start_proxy=false
local tmp=false
local cmd=$0
# TODO --config is incompatible with --proxy, --bungee and standalone
# Parse arguments
while [ $# -gt 0 ]; do
local arg=$1
case "$arg" in
"--config" | "-c")
config=$2 #TODO ensure mode is valid
local mode=$2
case "$mode" in
"proxy")
config="velocity"
;;
"bungee")
config="bungeecord"
;;
"standalone")
config="standalone"
;;
*)
err "Invalid mode for --config: $mode"
;;
esac
if $proxy; then
err "--config can't be used together with --proxy"
elif $bungee; then
err "--config can't be used together with --bungee"
fi
shift 2
;;
"--temp" | "--tmp" | "-t")
tmp=true
shift
;;
"--sleep" | "-s")
sleep_seconds=$2
shift 2
@ -30,6 +60,8 @@ function main {
proxy=true
if $bungee; then
err "--proxy can't be used together with --bungee"
elif [[ -n $config ]]; then
err "--proxy can't be used together with --config"
fi
shift
;;
@ -37,6 +69,8 @@ function main {
bungee=true
if $proxy; then
err "--bungee can't be used together with --proxy"
elif [[ -n $config ]]; then
err "--bungee can't be used together with --config"
fi
shift
;;
@ -50,6 +84,20 @@ function main {
esac
done
# Late parsing:
if $tmp && [[ -z $config ]]; then
err "--temp requires --config parameter"
fi
if $proxy; then
start_proxy=true
config="velocity"
tmp=true
elif $bungee; then
start_proxy=true
config="bungeecord"
tmp=true
fi
if $help; then
echo "Create a start loop for the minecraft server, additionally behind a velocity proxy or bungeecord proxy"
echo ""
@ -57,6 +105,7 @@ function main {
echo ""
echo "OPTIONS:"
echo " -c --config <mode> How to configure the server. Possible values for mode are: proxy, bungee, standalone"
echo " -t --temp --tmp Apply the configuration only temporary, while the server is running. Requires --config."
echo " -s --sleep <secs> How many seconds to sleep after the server has stopped before starting it again"
echo " -h --help Show help"
echo " --proxy Start the server behind a velocity proxy"
@ -64,42 +113,45 @@ function main {
exit
fi
# TODO perform configuration according to config parameter
if $proxy; then
./configure.sh velocity
# create proxy screen if it doesn't exist yet
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
# start the proxy
screen -S "$PROXY_SCREEN" -X stuff "cd $(pwd)/proxy; ./launch.sh\n"
echo "The velocity proxy has been started in the screen '$PROXY_SCREEN'"
elif $bungee; then
./configure.sh bungeecord
# create proxy screen if it doesn't exist yet
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
# start the proxy
screen -S "$PROXY_SCREEN" -X stuff "cd $(pwd)/bungee; ./launch.sh\n"
echo "The bungeecord proxy has been started in the screen '$PROXY_SCREEN'"
else
./configure.sh standalone
# Apply configuration
local previous_config=""
if [[ -n $config ]]; then
previous_config=$(./configure.sh "$config" --fetch)
fi
trap cleanup SIGINT
# Start proxy
if $start_proxy; then
# create proxy screen if it doesn't exist yet
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
# start the proxy
local proxy_dir="$(pwd)/proxy"
case "$config" in
"velocity")
proxy_dir=$VELOCITY_DIR
;;
"bungeecord")
proxy_dir=$BUNGEE_DIR
;;
esac
screen -S "$PROXY_SCREEN" -X stuff "cd $proxy_dir; ./launch.sh\n"
echo "The proxy has been started in screen $PROXY_SCREEN"
fi
cleanup() {
if $proxy || $bungee; then
function cleanup {
if $start_proxy; then
# stop the proxy
screen -S "$PROXY_SCREEN" -X stuff "end\n"
echo "The proxy has been stopped"
fi
if $tmp; then
./configure.sh "$previous_config"
fi
exit
}
trap cleanup SIGINT
while true
do
echo starting server...
@ -109,7 +161,7 @@ function main {
done
}
# Shows ans error message and exits the program with code 1
# Shows an error message and exits the program with code 1
#
# Usage: err <msg>
function err {