From b466024001b151b30d73c95c5d1e95acab387f82 Mon Sep 17 00:00:00 2001 From: Davide Polonio Date: Thu, 25 May 2023 10:19:39 +0200 Subject: [PATCH] feat: add shell for vrising server editing --- vrising/src/vrising.sh | 89 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 vrising/src/vrising.sh diff --git a/vrising/src/vrising.sh b/vrising/src/vrising.sh new file mode 100755 index 0000000..390316c --- /dev/null +++ b/vrising/src/vrising.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +set -e + +### ### +# # +# V Rising on-the-fly shell # +# v0.1 # +### ### + +stdout() { + echo "${1}" +} + +stderr() { + >&2 echo "${1}" +} + +editWithRestart() { + local full_path_file_to_edit="${1}" + nano "${full_path_file_to_edit}" + stdout "The server will now be restarted and you will be attached to the logs." + stdout "Use ctrl-c to detach from the logs (the service will continue to run)" + sleep 2 + (cd "${VRISING_COMPOSE_HOME}" && docker-compose restart && docker-compose logs -f) +} + +USERNAME="${1}" + +shift + +BASE_VRISING_FOLDER="/srv/docker/vrising/saves/Settings/" +GAME_SETTINGS="ServerGameSettings.json" +HOST_SETTINGS="ServerHostSettings.json" +VRISING_COMPOSE_HOME="/home/davide/services/vrising/" +LOGS_FOLDER="${HOME}/logs" + +mkdir -p "${LOGS_FOLDER}" || (stderr "Unable to create logs folder, exiting" && exit 1) + +stdout "Welcome ${USERNAME}, please remember that your current activity in the server is logged!" +stdout "Exit and logout at any moment by pressing ctrl-c" + +while true +do + stdout """ +Select one of the following actions: +0 - exit +1 - edit ${GAME_SETTINGS} +2 - edit ${HOST_SETTINGS} +3 - inspect server logs +4 - restart server +5 - recreate server (destroy and recreate container) +""" + + ACTION="-1" + read -r ACTION + + case "${ACTION}" in + 0) + exit 0 + ;; + 1) + editWithRestart "${BASE_VRISING_FOLDER}${GAME_SETTINGS}" + ;; + 2) + editWithRestart "${BASE_VRISING_FOLDER}${HOST_SETTINGS}" + ;; + 3) + stdout "Use ctrl-c to detach from the logs at any time" + sleep 2 + (cd "${VRISING_COMPOSE_HOME}" && docker-compose logs -f) + ;; + 4) + stdout "Use ctrl-c to detach from the logs at any time" + sleep 2 + (cd "${VRISING_COMPOSE_HOME}" && docker-compose restart && docker-compose logs -f) + ;; + 5) + stdout "Use ctrl-c to detach from the logs at any time" + sleep 2 + (cd "${VRISING_COMPOSE_HOME}" && docker-compose down -v && sleep 1 && docker-compose up -d && docker-compose logs -f) + ;; + *) + stderr "The provided input is not valid. Please chose from the listed actions" + ;; + esac +done + +exit 0