#!/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 in background)" (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!" trap "" INT 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 -rp "> " 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" (cd "${VRISING_COMPOSE_HOME}" && docker-compose logs -f) ;; 4) stdout "Use ctrl-c to detach from the logs at any time" (cd "${VRISING_COMPOSE_HOME}" && docker-compose restart && docker-compose logs -f) ;; 5) stdout "Use ctrl-c to detach from the logs at any time" (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