]> git.lizzy.rs Git - elidragon_v2.git/commitdiff
Complete scripts collection
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 12:50:20 +0000 (13:50 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 12:50:20 +0000 (13:50 +0100)
scripts/console.sh [new file with mode: 0755]
scripts/internal.sh [new file with mode: 0644]
scripts/restart.sh [new file with mode: 0755]
scripts/setup.sh [new file with mode: 0755]
scripts/start.sh [new file with mode: 0755]
scripts/stop.sh [new file with mode: 0755]
scripts/update.sh [new file with mode: 0755]
setup.sh [deleted file]
update.sh [deleted file]

diff --git a/scripts/console.sh b/scripts/console.sh
new file mode 100755 (executable)
index 0000000..6751c0c
--- /dev/null
@@ -0,0 +1,9 @@
+#! /bin/bash
+# Elidragon v2 console script
+# Attach to the console of a world
+# Arguments: <worldname>
+
+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 (file)
index 0000000..8bfd1fc
--- /dev/null
@@ -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 (executable)
index 0000000..a39e454
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/bash
+# Elidragon v2 restart script
+# Restart one or all worlds
+# Arguments: [<worldname>]
+
+source scripts/internal.sh
+
+run_one_or_all restart_world $1
diff --git a/scripts/setup.sh b/scripts/setup.sh
new file mode 100755 (executable)
index 0000000..33e7eb8
--- /dev/null
@@ -0,0 +1,16 @@
+#! /bin/bash
+# Elidragon v2 setup script
+# Install everything needed by the server
+
+# Initialize submodules
+git submodule update --recursive --remote
+
+# Add apt repo to always get the lastest MT release
+add-apt-repository ppa:minetestdevs/stable
+apt-get update -y
+
+# Install minetest and screen
+apt install minetest screen -y
+
+# Install multiserver
+go get github.com/HimbeerserverDE/multiserver
diff --git a/scripts/start.sh b/scripts/start.sh
new file mode 100755 (executable)
index 0000000..96cc2fe
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/bash
+# Elidragon v2 start script
+# Start one or all worlds
+# Arguments: [<worldname>]
+
+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 (executable)
index 0000000..7e95f2c
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/bash
+# Elidragon v2 stop script
+# Stop one or all worlds
+# Arguments: [<worldname>]
+
+source scripts/internal.sh
+
+run_one_or_all stop_world $1
diff --git a/scripts/update.sh b/scripts/update.sh
new file mode 100755 (executable)
index 0000000..78abf52
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/bash
+# Elidragon v2 update script
+# Update all software used by the server
+
+# Update this repo, also update submodules
+git pull --recurse-submodules
+
+# Update minetest and screen
+apt-get update -y
+apt-get upgrade minetest screen -y
+
+# Update multiserver
+go get -u github.com/HimbeerserverDE/multiserver
diff --git a/setup.sh b/setup.sh
deleted file mode 100644 (file)
index b385cfe..0000000
--- a/setup.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#! /bin/bash
-# Setup script for the Elidragon v2 server
-
-# Initialize submodules
-git submodule update --recursive --remote
-
-# Add apt repo to always get the lastest MT release
-add-apt-repository ppa:minetestdevs/stable
-apt-get update -y
-
-# Install minetest and screen
-apt install minetest screen -y
-
-# Install multiserver
-go get github.com/HimbeerserverDE/multiserver
diff --git a/update.sh b/update.sh
deleted file mode 100644 (file)
index 5f9cfe6..0000000
--- a/update.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#! /bin/bash
-# Update script for the Elidragon v2 server
-
-# Update this repo, also update submodules
-git pull --recurse-submodules
-
-# Update minetest and screen
-apt-get update -y
-apt-get upgrade minetest screen -y
-
-# Update multiserver
-go get -u github.com/HimbeerserverDE/multiserver