From 492fddef88d2b8acdb64c5d812965108d55dda2d Mon Sep 17 00:00:00 2001 From: TheiLLeniumStudios <104288623+TheiLLeniumStudios@users.noreply.github.com> Date: Mon, 6 Feb 2023 11:53:49 +0000 Subject: [PATCH] Update --- entrypoint.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4724656..0215f38 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,7 @@ beginswith() { case $2 in "$1"*) true;; *) false;; esac; } -resource_exists() { +exists_in_array() { local element="$1" local array_str="$2" for i in $array_str; do @@ -13,13 +13,12 @@ resource_exists() { return 1 } -RESTART_INDIVIDUAL_RESOURCES=$1 +is_array_empty() { + local array_str="$1" + [ -z "$array_str" ] +} -if [ "$RESTART_INDIVIDUAL_RESOURCES" = true ] ; then - echo "Will restart individual resources" -else - echo "Will restart the whole server" -fi +RESTART_INDIVIDUAL_RESOURCES=$1 SERVER_IP=$2 SERVER_PORT=$3 @@ -54,11 +53,22 @@ echo "${DIFF}" | while read -r changed; do if beginswith ${RESOURCES_FOLDER} "${changed}"; then filtered=${changed##*]/} # Remove subfolders filtered=${filtered%%/*} # Remove filename and get the folder which corresponds to the resource name - if ! resource_exists "$filtered" "$resources_to_restart"; then + if ! exists_in_array "$filtered" "$resources_to_restart"; then echo "Adding $filtered to resources that need to restart" resources_to_restart="$resources_to_restart $filtered" fi - else - echo "No in resources" fi done + +if ! is_array_empty "$resources_to_restart"; then + if [ "$RESTART_INDIVIDUAL_RESOURCES" = true ] ; then + echo "Will restart individual resources" + for resource in $resources_to_restart; do + echo "Restarting ${resource}" + #rcon -a ${SERVER_IP}:${SERVER_PORT} -p ${RCON_PASSWORD} command "ensure ${resource}" + done + else + echo "Will restart the whole server" + #rcon -a ${SERVER_IP}:${SERVER_PORT} -p ${RCON_PASSWORD} command 'quit "Restarting server"' + fi +fi