From deb429f6557443e3cd3e8cf7cefcd15ae92df635 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Feb 2021 13:50:20 +0100 Subject: [PATCH] Complete scripts collection --- scripts/console.sh | 9 ++++ scripts/internal.sh | 78 ++++++++++++++++++++++++++++++++++ scripts/restart.sh | 8 ++++ setup.sh => scripts/setup.sh | 3 +- scripts/start.sh | 8 ++++ scripts/stop.sh | 8 ++++ update.sh => scripts/update.sh | 3 +- 7 files changed, 115 insertions(+), 2 deletions(-) create mode 100755 scripts/console.sh create mode 100644 scripts/internal.sh create mode 100755 scripts/restart.sh rename setup.sh => scripts/setup.sh (82%) mode change 100644 => 100755 create mode 100755 scripts/start.sh create mode 100755 scripts/stop.sh rename update.sh => scripts/update.sh (77%) mode change 100644 => 100755 diff --git a/scripts/console.sh b/scripts/console.sh new file mode 100755 index 0000000..6751c0c --- /dev/null +++ b/scripts/console.sh @@ -0,0 +1,9 @@ +#! /bin/bash +# Elidragon v2 console script +# Attach to the console of a world +# Arguments: + +source scripts/internal.sh + +assert_running $1 +screen -r `world_screenname $1` diff --git a/scripts/internal.sh b/scripts/internal.sh new file mode 100644 index 0000000..8bfd1fc --- /dev/null +++ b/scripts/internal.sh @@ -0,0 +1,78 @@ +# internal functions used by Elidragon v2 scripts + +function world_lock { + echo "/tmp/ElidragonV2_$1_lock" +} + +function world_screenname { + echo "Elidragon v2 - $1" +} + +function kill_world { + kill `cat \`world_lock $1\`` +} + +function is_running { + return $(test -f `world_lock $1`) +} + +function loop_worlds { + WORLDS=`ls worlds` + for WORLD in $WORLDS; do + $1 $WORLD + done +} + +function assert_running { + if ! is_running $1; then + echo "Error: World $1 is not running" + exit 1 + fi +} + +function assert_not_running { + if is_running $1; then + echo "Error: World $1 is already running" + exit 1 + fi +} + +function start_world { + echo "Starting $1..." + assert_not_running $1 + + LOCK=`world_lock $1` + + screen -dmS `world_screenname $1` bash -c " + while is_running $1; do + bash -c \" + echo \\$\\$ > $LOCK + exec minetest --server --terminal --world worlds/$1 --config worlds/$1/minetest.conf --logfile worlds/$1/debug.txt + \" + done + rm $LOCK + " +} + +function stop_world { + echo "Stopping $1..." + assert_running $1 + + kill_world $1 + rm `world_lock $1` +} + +function restart_world { + echo "Restarting $1..." + assert_running $1 + + kill_world $1 +} + +function run_one_or_all { + if [ -z "$2" ]; then + loop_worlds $1 + else + $1 $2 + fi +} diff --git a/scripts/restart.sh b/scripts/restart.sh new file mode 100755 index 0000000..a39e454 --- /dev/null +++ b/scripts/restart.sh @@ -0,0 +1,8 @@ +#! /bin/bash +# Elidragon v2 restart script +# Restart one or all worlds +# Arguments: [] + +source scripts/internal.sh + +run_one_or_all restart_world $1 diff --git a/setup.sh b/scripts/setup.sh old mode 100644 new mode 100755 similarity index 82% rename from setup.sh rename to scripts/setup.sh index b385cfe..33e7eb8 --- a/setup.sh +++ b/scripts/setup.sh @@ -1,5 +1,6 @@ #! /bin/bash -# Setup script for the Elidragon v2 server +# Elidragon v2 setup script +# Install everything needed by the server # Initialize submodules git submodule update --recursive --remote diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100755 index 0000000..96cc2fe --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,8 @@ +#! /bin/bash +# Elidragon v2 start script +# Start one or all worlds +# Arguments: [] + +source scripts/internal.sh + +run_one_or_all start_world $1 diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100755 index 0000000..7e95f2c --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,8 @@ +#! /bin/bash +# Elidragon v2 stop script +# Stop one or all worlds +# Arguments: [] + +source scripts/internal.sh + +run_one_or_all stop_world $1 diff --git a/update.sh b/scripts/update.sh old mode 100644 new mode 100755 similarity index 77% rename from update.sh rename to scripts/update.sh index 5f9cfe6..78abf52 --- a/update.sh +++ b/scripts/update.sh @@ -1,5 +1,6 @@ #! /bin/bash -# Update script for the Elidragon v2 server +# Elidragon v2 update script +# Update all software used by the server # Update this repo, also update submodules git pull --recurse-submodules -- 2.44.0