2025-09-18 16:15:35 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2025-12-24 18:56:39 +01:00
|
|
|
# THe name of the screen in which the proxy server will run
|
2025-09-18 16:15:35 +02:00
|
|
|
PROXY_SCREEN="proxy"
|
2025-12-25 20:08:14 +01:00
|
|
|
# The relative path of the velocity proxy server
|
|
|
|
|
VELOCITY_DIR="proxy"
|
|
|
|
|
# The relative path of the bungeecord proxy server
|
|
|
|
|
BUNGEE_DIR="bungee"
|
2025-12-24 18:56:39 +01:00
|
|
|
# How many seconds to sleep before starting the server again, unless it is explicitly specified
|
|
|
|
|
DEFAULT_SLEEP_SECONDS=3
|
|
|
|
|
|
2025-12-25 22:47:19 +01:00
|
|
|
|
|
|
|
|
function show_help {
|
|
|
|
|
local cmd=$0
|
|
|
|
|
|
|
|
|
|
echo "Create a start loop for the minecraft server, additionally behind a velocity proxy or bungeecord proxy"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Usage $cmd [OPTIONS]"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "OPTIONS:"
|
|
|
|
|
echo " -c --config <mode> How to configure the server (see ./configure.sh --help). 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"
|
|
|
|
|
echo " --bungee Start the server behind a bungeecord proxy"
|
|
|
|
|
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 18:56:39 +01:00
|
|
|
function main {
|
|
|
|
|
local proxy=false
|
|
|
|
|
local bungee=false
|
|
|
|
|
local help=false
|
|
|
|
|
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
|
2025-12-24 23:24:44 +01:00
|
|
|
local config=""
|
2025-12-25 19:22:14 +01:00
|
|
|
local start_proxy=false
|
2025-12-25 20:08:14 +01:00
|
|
|
local tmp=false
|
2025-12-24 18:56:39 +01:00
|
|
|
|
|
|
|
|
local cmd=$0
|
|
|
|
|
|
2025-12-25 20:08:14 +01:00
|
|
|
# Parse arguments
|
2025-12-24 18:56:39 +01:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
local arg=$1
|
|
|
|
|
case "$arg" in
|
2025-12-24 23:24:44 +01:00
|
|
|
"--config" | "-c")
|
2025-12-25 19:22:14 +01:00
|
|
|
local mode=$2
|
|
|
|
|
case "$mode" in
|
2025-12-25 20:08:14 +01:00
|
|
|
"proxy")
|
|
|
|
|
config="velocity"
|
2025-12-25 19:22:14 +01:00
|
|
|
;;
|
2025-12-25 20:08:14 +01:00
|
|
|
"bungee")
|
|
|
|
|
config="bungeecord"
|
|
|
|
|
;;
|
|
|
|
|
"standalone")
|
|
|
|
|
config="standalone"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2025-12-25 19:22:14 +01:00
|
|
|
err "Invalid mode for --config: $mode"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2025-12-25 20:08:14 +01:00
|
|
|
|
2025-12-25 19:22:14 +01:00
|
|
|
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
|
2025-12-24 23:24:44 +01:00
|
|
|
shift 2
|
|
|
|
|
;;
|
2025-12-25 20:08:14 +01:00
|
|
|
"--temp" | "--tmp" | "-t")
|
|
|
|
|
tmp=true
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2025-12-24 18:56:39 +01:00
|
|
|
"--sleep" | "-s")
|
|
|
|
|
sleep_seconds=$2
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
"--proxy")
|
|
|
|
|
proxy=true
|
|
|
|
|
if $bungee; then
|
|
|
|
|
err "--proxy can't be used together with --bungee"
|
2025-12-25 19:22:14 +01:00
|
|
|
elif [[ -n $config ]]; then
|
|
|
|
|
err "--proxy can't be used together with --config"
|
2025-12-24 18:56:39 +01:00
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
"--bungee")
|
|
|
|
|
bungee=true
|
|
|
|
|
if $proxy; then
|
|
|
|
|
err "--bungee can't be used together with --proxy"
|
2025-12-25 19:22:14 +01:00
|
|
|
elif [[ -n $config ]]; then
|
|
|
|
|
err "--bungee can't be used together with --config"
|
2025-12-24 18:56:39 +01:00
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
"--help" | "-h")
|
|
|
|
|
help=true
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
err "Unknown argument: $arg"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2025-12-25 20:08:14 +01:00
|
|
|
# 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
|
|
|
|
|
|
2025-12-24 18:56:39 +01:00
|
|
|
if $help; then
|
2025-12-25 22:47:19 +01:00
|
|
|
show_help $cmd
|
2025-12-24 18:56:39 +01:00
|
|
|
fi
|
|
|
|
|
|
2025-12-25 20:08:14 +01:00
|
|
|
# Apply configuration
|
2025-12-25 20:18:27 +01:00
|
|
|
local previous_config=$(./configure.sh --fetch)
|
|
|
|
|
echo "Current configuration is $previous_config"
|
2025-12-25 20:08:14 +01:00
|
|
|
if [[ -n $config ]]; then
|
2025-12-25 20:18:27 +01:00
|
|
|
./configure.sh "$config"
|
2025-12-25 20:08:14 +01:00
|
|
|
fi
|
2025-09-18 16:15:35 +02:00
|
|
|
|
2025-12-25 20:08:14 +01:00
|
|
|
# Start proxy
|
|
|
|
|
if $start_proxy; then
|
2025-12-24 18:56:39 +01:00
|
|
|
# create proxy screen if it doesn't exist yet
|
|
|
|
|
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
|
|
|
|
|
# start the proxy
|
2025-12-25 20:08:14 +01:00
|
|
|
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"
|
2025-09-18 16:15:35 +02:00
|
|
|
fi
|
|
|
|
|
|
2025-12-25 20:08:14 +01:00
|
|
|
function cleanup {
|
|
|
|
|
if $start_proxy; then
|
2025-12-24 18:56:39 +01:00
|
|
|
# stop the proxy
|
|
|
|
|
screen -S "$PROXY_SCREEN" -X stuff "end\n"
|
|
|
|
|
echo "The proxy has been stopped"
|
|
|
|
|
fi
|
2025-12-25 20:08:14 +01:00
|
|
|
if $tmp; then
|
|
|
|
|
./configure.sh "$previous_config"
|
|
|
|
|
fi
|
2025-12-24 18:56:39 +01:00
|
|
|
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 20:08:14 +01:00
|
|
|
trap cleanup SIGINT
|
|
|
|
|
|
2025-12-24 18:56:39 +01:00
|
|
|
while true
|
|
|
|
|
do
|
|
|
|
|
echo starting server...
|
|
|
|
|
./launch.sh
|
|
|
|
|
echo sleeping...
|
|
|
|
|
sleep "$sleep_seconds"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 20:08:14 +01:00
|
|
|
# Shows an error message and exits the program with code 1
|
2025-12-24 18:56:39 +01:00
|
|
|
#
|
|
|
|
|
# Usage: err <msg>
|
|
|
|
|
function err {
|
|
|
|
|
echo "$1"
|
|
|
|
|
exit 1
|
2025-09-18 16:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-24 18:56:39 +01:00
|
|
|
main "$@"
|
2025-09-18 16:15:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|