Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Function names to snake case #491

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
source "/home/steam/server/helper_functions.sh"

if [ "${RCON_ENABLED,,}" != true ]; then
LogWarn "Unable to reboot. RCON is required."
log_warn "Unable to reboot. RCON is required."
exit 1
fi

if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then
players_count=$(get_player_count)
if [ "$players_count" -gt 0 ]; then
LogWarn "There are ${players_count} players online. Skipping auto reboot."
log_warn "There are ${players_count} players online. Skipping auto reboot."
exit 0
fi
fi
Expand All @@ -22,11 +22,11 @@ case "${countdown_exit_code}" in
shutdown_server
;;
1 )
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty"
log_error "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}"
log_error "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
24 changes: 12 additions & 12 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

DiscordMessage "Backup" "${DISCORD_PRE_BACKUP_MESSAGE}" "in-progress" "${DISCORD_PRE_BACKUP_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_MESSAGE_URL}"
discord_message "Backup" "${DISCORD_PRE_BACKUP_MESSAGE}" "in-progress" "${DISCORD_PRE_BACKUP_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_MESSAGE_URL}"
if [ "${RCON_ENABLED,,}" = true ]; then
save_server
fi
Expand All @@ -11,33 +11,33 @@ DATE=$(date +"%Y-%m-%d_%H-%M-%S")
FILE_PATH="/palworld/backups/palworld-save-${DATE}.tar.gz"
cd /palworld/Pal/ || exit

LogAction "Creating backup"
log_action "Creating backup"
tar -zcf "$FILE_PATH" "Saved/"

if [ "$(id -u)" -eq 0 ]; then
chown steam:steam "$FILE_PATH"
fi
LogInfo "Backup created at ${FILE_PATH}"
DiscordMessage "Backup" "${DISCORD_POST_BACKUP_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_MESSAGE_URL}"
log_info "Backup created at ${FILE_PATH}"
discord_message "Backup" "${DISCORD_POST_BACKUP_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_MESSAGE_URL}"

if [ "${DELETE_OLD_BACKUPS,,}" != true ]; then
exit 0
fi

if [ -z "${OLD_BACKUP_DAYS}" ]; then
LogWarn "Unable to delete old backups, OLD_BACKUP_DAYS is empty."
DiscordMessage "Backup" "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn"
log_warn "Unable to delete old backups, OLD_BACKUP_DAYS is empty."
discord_message "Backup" "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn"
exit 0
fi

if [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then
LogAction "Removing Old Backups"
LogInfo "Removing backups older than ${OLD_BACKUP_DAYS} days"
DiscordMessage "Backup" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "in-progress" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_URL}"
log_action "Removing Old Backups"
log_info "Removing backups older than ${OLD_BACKUP_DAYS} days"
discord_message "Backup" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "in-progress" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_URL}"
find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete
DiscordMessage "Backup" "${DISCORD_POST_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_URL}"
discord_message "Backup" "${DISCORD_POST_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_URL}"
exit 0
fi

LogError "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}"
DiscordMessage "Backup" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE//\$\{OLD_BACKUP_DAYS\}/${OLD_BACKUP_DAYS}}}" "failure" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_URL}"
log_error "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}"
discord_message "Backup" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE//\$\{OLD_BACKUP_DAYS\}/${OLD_BACKUP_DAYS}}}" "failure" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_URL}"
12 changes: 6 additions & 6 deletions scripts/compile-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ engine_dir=$(dirname "$engine_file")
mkdir -p "$engine_dir" || exit
# If file exists then check if it is writable
if [ -f "$engine_file" ]; then
if ! isWritable "$engine_file"; then
LogError "Unable to create $engine_file"
if ! is_writable "$engine_file"; then
log_error "Unable to create $engine_file"
exit 1
fi
# If file does not exist then check if the directory is writable
elif ! isWritable "$engine_dir"; then
elif ! is_writable "$engine_dir"; then
# Exiting since the file does not exist and the directory is not writable.
LogError "Unable to create $engine_file"
log_error "Unable to create $engine_file"
exit 1
fi

LogAction "Compiling Engine.ini"
log_action "Compiling Engine.ini"

export LAN_SERVER_MAX_TICK_RATE=${LAN_SERVER_MAX_TICK_RATE:-120}
export NET_SERVER_MAX_TICK_RATE=${NET_SERVER_MAX_TICK_RATE:-120}
Expand Down Expand Up @@ -57,4 +57,4 @@ cat > "$engine_file" <<EOF
$(envsubst < /home/steam/server/files/Engine.ini.template)
EOF

LogSuccess "Compiling Engine.ini done!"
log_success "Compiling Engine.ini done!"
12 changes: 6 additions & 6 deletions scripts/compile-settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ config_dir=$(dirname "$config_file")
mkdir -p "$config_dir" || exit
# If file exists then check if it is writable
if [ -f "$config_file" ]; then
if ! isWritable "$config_file"; then
LogError "Unable to create $config_file"
if ! is_writable "$config_file"; then
log_error "Unable to create $config_file"
exit 1
fi
# If file does not exist then check if the directory is writable
elif ! isWritable "$config_dir"; then
elif ! is_writable "$config_dir"; then
# Exiting since the file does not exist and the directory is not writable.
LogError "Unable to create $config_file"
log_error "Unable to create $config_file"
exit 1
fi

LogAction "Compiling PalWorldSettings.ini"
log_action "Compiling PalWorldSettings.ini"

export DIFFICULTY=${DIFFICULTY:-None}
export DAYTIME_SPEEDRATE=${DAYTIME_SPEEDRATE:-1.000000}
Expand Down Expand Up @@ -160,4 +160,4 @@ cat > "$config_file" <<EOF
$(envsubst < /home/steam/server/files/PalWorldSettings.ini.template | tr -d "\n\r")
EOF

LogSuccess "Compiling PalWorldSettings.ini done!"
log_success "Compiling PalWorldSettings.ini done!"
8 changes: 4 additions & 4 deletions scripts/discord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ URL=$5
if [ -n "${DISCORD_CONNECT_TIMEOUT}" ] && [[ "${DISCORD_CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then
CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT
else
LogWarn "CONNECT_TIMEOUT is not an integer, using default ${DEFAULT_CONNECT_TIMEOUT} seconds."
log_warn "CONNECT_TIMEOUT is not an integer, using default ${DEFAULT_CONNECT_TIMEOUT} seconds."
CONNECT_TIMEOUT=$DEFAULT_CONNECT_TIMEOUT
fi

if [ -n "${DISCORD_MAX_TIMEOUT}" ] && [[ "${DISCORD_MAX_TIMEOUT}" =~ ^[0-9]+$ ]]; then
MAX_TIMEOUT=$DISCORD_MAX_TIMEOUT
else
LogWarn "MAX_TIMEOUT is not an integer, using default ${DEFAULT_MAX_TIMEOUT} seconds."
log_warn "MAX_TIMEOUT is not an integer, using default ${DEFAULT_MAX_TIMEOUT} seconds."
MAX_TIMEOUT=$DEFAULT_MAX_TIMEOUT
fi

Expand All @@ -51,7 +51,7 @@ if [ -n "${LEVEL}" ]; then
COLOR=$DISCORD_GREEN
;;
* )
LogWarn "Could not find \"${LEVEL}\", using \"${DEFAULT_LEVEL}\""
log_warn "Could not find \"${LEVEL}\", using \"${DEFAULT_LEVEL}\""
COLOR=$DISCORD_BLUE
;;
esac
Expand All @@ -67,6 +67,6 @@ if [ "$ENABLED" = true ]; then
else
DISCORD_URL="$URL"
fi
LogInfo "Sending Discord json: ${JSON}"
log_info "Sending Discord json: ${JSON}"
curl -sfSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$MAX_TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_URL"
fi
46 changes: 23 additions & 23 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Checks if a given path is a directory
# Returns 0 if the path is a directory
# Returns 1 if the path is not a directory or does not exists and produces an output message
dirExists() {
dir_exists() {
local path="$1"
local return_val=0
if ! [ -d "${path}" ]; then
Expand All @@ -17,7 +17,7 @@ dirExists() {
# Checks if a given path is a regular file
# Returns 0 if the path is a regular file
# Returns 1 if the path is not a regular file or does not exists and produces an output message
fileExists() {
file_exists() {
local path="$1"
local return_val=0
if ! [ -f "${path}" ]; then
Expand All @@ -30,7 +30,7 @@ fileExists() {
# Checks if a given path exists and is readable
# Returns 0 if the path exists and is readable
# Returns 1 if the path is not readable or does not exists and produces an output message
isReadable() {
is_readable() {
local path="$1"
local return_val=0
if ! [ -e "${path}" ]; then
Expand All @@ -43,7 +43,7 @@ isReadable() {
# Checks if a given path is writable
# Returns 0 if the path is writable
# Returns 1 if the path is not writable or does not exists and produces an output message
isWritable() {
is_writable() {
local path="$1"
local return_val=0
# Directories may be writable but not deletable causing -w to return false
Expand All @@ -66,7 +66,7 @@ isWritable() {
# Checks if a given path is executable
# Returns 0 if the path is executable
# Returns 1 if the path is not executable or does not exists and produces an output message
isExecutable() {
is_executable() {
local path="$1"
local return_val=0
if ! [ -x "${path}" ]; then
Expand All @@ -85,7 +85,7 @@ get_players_list() {
return_val=1
fi

RCON "ShowPlayers"
rcon "ShowPlayers"
return "$return_val"
}

Expand Down Expand Up @@ -116,22 +116,22 @@ export GreenBoldText='\033[1;32m' # Green
export YellowBoldText='\033[1;33m' # Yellow
export CyanBoldText='\033[1;36m' # Cyan

LogInfo() {
Log "$1" "$WhiteText"
log_info() {
log "$1" "$WhiteText"
}
LogWarn() {
Log "$1" "$YellowBoldText"
log_warn() {
log "$1" "$YellowBoldText"
}
LogError() {
Log "$1" "$RedBoldText"
log_error() {
log "$1" "$RedBoldText"
}
LogSuccess() {
Log "$1" "$GreenBoldText"
log_success() {
log "$1" "$GreenBoldText"
}
LogAction() {
Log "$1" "$CyanBoldText" "****" "****"
log_action() {
log "$1" "$CyanBoldText" "****" "****"
}
Log() {
log() {
local message="$1"
local color="$2"
local prefix="$3"
Expand All @@ -141,7 +141,7 @@ Log() {

# Send Discord Message
# Level is optional variable defaulting to info
DiscordMessage() {
discord_message() {
local title="$1"
local message="$2"
local level="$3"
Expand All @@ -156,7 +156,7 @@ DiscordMessage() {
}

# RCON Call
RCON() {
rcon() {
local args="$1"
rcon-cli -c /home/steam/server/rcon.yaml "$args"
}
Expand All @@ -170,9 +170,9 @@ broadcast_command() {
# Replaces spaces with underscore
local message="${1// /_}"
if [[ $TEXT = *[![:ascii:]]* ]]; then
LogWarn "Unable to broadcast since the message contains non-ascii characters: \"${message}\""
log_warn "Unable to broadcast since the message contains non-ascii characters: \"${message}\""
return_val=1
elif ! RCON "broadcast ${message}" > /dev/null; then
elif ! rcon "broadcast ${message}" > /dev/null; then
return_val=1
fi
return "$return_val"
Expand All @@ -183,7 +183,7 @@ broadcast_command() {
# Returns 1 if it is not able to save
save_server() {
local return_val=0
if ! RCON save; then
if ! rcon save; then
return_val=1
fi
return "$return_val"
Expand All @@ -196,7 +196,7 @@ shutdown_server() {
local return_val=0
# Do not shutdown if not able to save
if save_server; then
if ! RCON "DoExit"; then
if ! "DoExit"; then
return_val=1
fi
else
Expand Down
Loading