Skip to content

Commit

Permalink
Changed exit codes for countdown_message
Browse files Browse the repository at this point in the history
  • Loading branch information
Dashboy1998 committed Feb 18, 2024
1 parent 82536b4 commit 131638d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 54 deletions.
21 changes: 13 additions & 8 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ if [ "${RCON_ENABLED,,}" = true ]; then
fi
fi

if countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; then
shutdown_server
elif [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty"
exit 1
else
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}"
fi
case "$(countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; echo $?)" in
0 )
shutdown_server
;;
1 )
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty"
exit 1
;;
2 )
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}"
exit 1
;;
esac
else
LogWarn "Unable to reboot. RCON is required."
exit 1
Expand Down
78 changes: 42 additions & 36 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -238,49 +238,55 @@ broadcast_command() {
}

# Given an amount of time in minutes and a message prefix
# Will skip countdown if no players are in the server, Will only check the mtime if there are players in the server
# Returns 0 on success
# If mtime is not an integer and there are players in game then return 1
# Returns 1 if mtime is empty
# Returns 2 if mtime is not an integer
countdown_message() {
local mtime="$1"
local message_prefix="$2"
local return_val=0

if [[ "${mtime}" =~ ^[0-9]+$ ]]; then
for ((i = "${mtime}" ; i > 0 ; i--)); do
if [ "$(get_player_count)" -eq 0 ]; then
break
fi
if [ "$i" -eq 1 ]; then
broadcast_command "${message_prefix}_in_${i}_minute"
sleep 30s
broadcast_command "${message_prefix}_in_30_seconds"
sleep 20s
broadcast_command "${message_prefix}_in_10_seconds"
sleep 10s
else
case "$i" in
"$mtime" )
;&
15 )
;&
10 )
;&
5 )
;&
2 )
broadcast_command "${message_prefix}_in_${i}_minutes"
;&
* )
sleep 1m
;;
esac
fi
done
return 0
else
# mtime is not an integer so check if there are no players
if [ "$(get_player_count)" -gt 0 ]; then
# Only do countdown if there are players
if [ "$(get_player_count)" -gt 0 ]; then
if [[ "${mtime}" =~ ^[0-9]+$ ]]; then
for ((i = "${mtime}" ; i > 0 ; i--)); do
if [ "$i" -eq 1 ]; then
broadcast_command "${message_prefix}_in_${i}_minute"
sleep 30s
broadcast_command "${message_prefix}_in_30_seconds"
sleep 20s
broadcast_command "${message_prefix}_in_10_seconds"
sleep 10s
else
case "$i" in
"$mtime" )
;&
15 )
;&
10 )
;&
5 )
;&
2 )
broadcast_command "${message_prefix}_in_${i}_minutes"
;&
* )
sleep 1m
;;
esac
fi
# Checking for players every minute
if [ "$(get_player_count)" -eq 0 ]; then
break
fi
done
# If there are players but mtime is empty
elif [ -z "${mtime}" ]; then
return_val=1
# If there are players but mtime is not an integer
else
return_val=2
fi
fi
return "$return_val"
Expand Down
26 changes: 16 additions & 10 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ if UpdateRequired; then
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
fi

if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then
LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST."
rm /palworld/steamapps/appmanifest_2394010.acf
case "$(countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; echo $?)" in
0 )
LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST."
rm /palworld/steamapps/appmanifest_2394010.acf

backup
shutdown_server
elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then
LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty."
else
LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}"
fi
backup
shutdown_server
;;
1 )
LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty."
exit 1
;;
2 )
LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}"
exit 1
;;
esac
fi

0 comments on commit 131638d

Please sign in to comment.