2025-09-18 16:15:35 +02:00
|
|
|
#!/usr/bin/env bash
|
2025-12-25 23:09:37 +01:00
|
|
|
|
|
|
|
|
# How many seconds to sleep before starting the server again, unless it is explicitly specified
|
|
|
|
|
DEFAULT_SLEEP_SECONDS=3
|
|
|
|
|
|
2025-12-26 08:31:59 +01:00
|
|
|
declare -A DEV
|
|
|
|
|
DEV[option]="dev"
|
|
|
|
|
DEV[screen]="steptech"
|
|
|
|
|
DEV[dir]=".."
|
|
|
|
|
|
|
|
|
|
# Which paper servers can be started with this script
|
|
|
|
|
SERVERS=( DEV )
|
|
|
|
|
|
|
|
|
|
# Which configuration to apply to the paper servers
|
|
|
|
|
CONFIG="proxy" # Velocity
|
|
|
|
|
|
2025-12-25 23:09:37 +01:00
|
|
|
function show_help {
|
|
|
|
|
local cmd=$0
|
|
|
|
|
|
|
|
|
|
echo "Create a start loop for the proxy server and optionally start a number of paper servers with it"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Usage: $cmd [OPTIONS]"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "OPTIONS:"
|
2025-12-26 08:31:59 +01:00
|
|
|
{
|
|
|
|
|
local fmt=" %s\t%s\t%s\n"
|
|
|
|
|
|
|
|
|
|
printf "$fmt" "-s" "--sleep" "How many seconds to sleep after stopping the server"
|
|
|
|
|
printf "$fmt" "-n" "--no-loop" "Don't restart the proxy server once it stopped"
|
|
|
|
|
|
|
|
|
|
for server_name in "${SERVERS[@]}"; do
|
|
|
|
|
declare -n server="$server_name"
|
|
|
|
|
printf "$fmt" "" "--${server[option]}" "Start the ${server[screen]} server (${server[dir]})"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
printf "$fmt" "-h" "--help" "Show this message"
|
|
|
|
|
} | column -t -s $'\t'
|
2025-12-25 23:09:37 +01:00
|
|
|
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function main {
|
|
|
|
|
|
|
|
|
|
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
|
|
|
|
|
local help=false
|
2025-12-26 08:31:59 +01:00
|
|
|
local loop=true
|
|
|
|
|
local servers=()
|
2025-12-25 23:09:37 +01:00
|
|
|
|
|
|
|
|
# Parse arguments
|
|
|
|
|
local cmd=$0
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
|
local arg=$1
|
|
|
|
|
case "$arg" in
|
|
|
|
|
"--sleep" | "-s")
|
|
|
|
|
sleep_seconds=$2
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
2025-12-26 08:31:59 +01:00
|
|
|
"--no-loop" | "-n")
|
|
|
|
|
loop=false
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2025-12-25 23:09:37 +01:00
|
|
|
"--help" | "-h")
|
|
|
|
|
help=true
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2025-12-26 08:31:59 +01:00
|
|
|
local option_found=false
|
|
|
|
|
for server_name in "${SERVERS[@]}"; do
|
|
|
|
|
declare -n server="$server_name"
|
|
|
|
|
if [ "$arg" = "--${server[option]}" ]; then
|
|
|
|
|
servers+=("$server_name")
|
|
|
|
|
option_found=true
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if ! $option_found; then
|
|
|
|
|
err "Unknown argument: $arg"
|
|
|
|
|
fi
|
|
|
|
|
shift
|
2025-12-25 23:09:37 +01:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if $help; then
|
|
|
|
|
show_help "$cmd"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-12-26 08:31:59 +01:00
|
|
|
# Start servers
|
|
|
|
|
for server_name in "${servers[@]}"; do
|
|
|
|
|
declare -n server="$server_name"
|
|
|
|
|
# Create server screen if it doesn't exist yet
|
|
|
|
|
local screen="${server[screen]}"
|
|
|
|
|
screen -ls | grep -q "$screen" || screen -dmS "$screen"
|
|
|
|
|
# Start the server
|
|
|
|
|
screen -S "$screen" -X stuff "cd $(pwd)/${server[dir]}; ./start.sh --no-loop --config \"$CONFIG\" --tmp\n"
|
|
|
|
|
echo "Started paper server in screen $screen"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
function cleanup {
|
|
|
|
|
for server_name in "${servers[@]}"; do
|
|
|
|
|
declare -n server="$server_name"
|
|
|
|
|
local screen="${server[screen]}"
|
|
|
|
|
screen -S "$screen" -X stuff "stop\n"
|
|
|
|
|
echo "Stopped paper server in screen $screen"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap cleanup SIGINT
|
|
|
|
|
|
|
|
|
|
while :; do
|
2025-12-25 23:09:37 +01:00
|
|
|
echo "Starting proxy..."
|
|
|
|
|
./launch.sh
|
2025-12-26 08:31:59 +01:00
|
|
|
|
|
|
|
|
$loop || break
|
|
|
|
|
|
2025-12-25 23:09:37 +01:00
|
|
|
echo "Sleeping for $sleep_seconds seconds..."
|
|
|
|
|
sleep "$sleep_seconds"
|
|
|
|
|
done
|
2025-12-26 08:31:59 +01:00
|
|
|
|
|
|
|
|
cleanup
|
2025-12-25 23:09:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Shows an error message and exits the program with code 1
|
|
|
|
|
#
|
|
|
|
|
# Usage: err <msg>
|
|
|
|
|
function err {
|
|
|
|
|
echo "$1"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main "$@"
|
|
|
|
|
|