Skip to content

Commit

Permalink
#191 Fix newlines on colorful echo aliases by thejcpalma
Browse files Browse the repository at this point in the history
  • Loading branch information
jammsen committed Feb 10, 2024
1 parent c7fbcb5 commit bb8e0a1
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 73 deletions.
6 changes: 3 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ source /includes/colors.sh


if [[ "${PUID}" -eq 0 ]] || [[ "${PGID}" -eq 0 ]]; then
ew ">>> Running as root is not supported, please fix your PUID and PGID!\n"
ew ">>> Running as root is not supported, please fix your PUID and PGID!"
exit 1
elif [[ "$(id -u steam)" -ne "${PUID}" ]] || [[ "$(id -g steam)" -ne "${PGID}" ]]; then
ei "> Current steam user UID is '$(id -u steam)' and GID is '$(id -g steam)'\n"
ei "> Setting new steam user UID to '${PUID}' and GID to '${PGID}'\n"
ei "> Current steam user UID is '$(id -u steam)' and GID is '$(id -g steam)'"
ei "> Setting new steam user UID to '${PUID}' and GID to '${PGID}'"
groupmod -g "${PGID}" steam && usermod -u "${PUID}" -g "${PGID}" steam
fi

Expand Down
28 changes: 27 additions & 1 deletion includes/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,51 @@
# Ansi Default Color Codes https://hyperskill.org/learn/step/18193#terminal-support
# Use ANSI whenever possible. Makes logs compatible with almost all systems.

# Aliases for colorful echos
# Aliases for colorful echos with newlines
function e() {
colorful_echos --base "${@}"
echo ""
}

function ee() {
colorful_echos --error "${@}"
echo ""
}

function ei() {
colorful_echos --info "${@}"
echo ""
}

function es() {
colorful_echos --success "${@}"
echo ""
}

function ew() {
colorful_echos --warning "${@}"
echo ""
}

# Aliases for colorful echos without newlines
function e_nn() {
colorful_echos --base "${@}"
}

function ee_nn() {
colorful_echos --error "${@}"
}

function ei_nn() {
colorful_echos --info "${@}"
}

function es_nn() {
colorful_echos --success "${@}"
}

function ew_nn() {
colorful_echos --warning "${@}"
}

# This creates a wrapper for echo to add colors
Expand Down
44 changes: 22 additions & 22 deletions includes/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ source /includes/colors.sh
function setup_engine_ini() {
pattern1="OnlineSubsystemUtils.IpNetDriver"
pattern2="^NetServerMaxTickRate=[0-9]*"
ei ">>> Setting up Engine.ini ...\n"
ei "> Checking if config already exists...\n"
ei ">>> Setting up Engine.ini ..."
ei "> Checking if config already exists..."
if [ ! -f "${GAME_ENGINE_FILE}" ]; then
ew "> No config found, generating one!"
if [ ! -d "${GAME_CONFIG_PATH}" ]; then
Expand All @@ -15,36 +15,36 @@ function setup_engine_ini() {
# Create empty Engine.ini file
echo "" > "${GAME_ENGINE_FILE}"
else
ei "> Found existing config!\n"
ei "> Found existing config!"
fi
if grep -qE "${pattern1}" "${GAME_ENGINE_FILE}" 2>/dev/null; then
ei "> Found [/Script/OnlineSubsystemUtils.IpNetDriver] section.\n"
ei "> Found [/Script/OnlineSubsystemUtils.IpNetDriver] section"
else
ew "> Found no [/Script/OnlineSubsystemUtils.IpNetDriver], adding it.\n"
echo -e "\n[/Script/OnlineSubsystemUtils.IpNetDriver]" >> "${GAME_ENGINE_FILE}"
ew "> Found no [/Script/OnlineSubsystemUtils.IpNetDriver], adding it"
echo -e "[/Script/OnlineSubsystemUtils.IpNetDriver]" >> "${GAME_ENGINE_FILE}"
fi
if grep -qE "${pattern2}" "${GAME_ENGINE_FILE}" 2>/dev/null; then
ei "> Found NetServerMaxTickRate parameter, changing it to '${NETSERVERMAXTICKRATE}'\n"
ei "> Found NetServerMaxTickRate parameter, changing it to '${NETSERVERMAXTICKRATE}'"
sed -E -i "s/${pattern2}/NetServerMaxTickRate=${NETSERVERMAXTICKRATE}/" "${GAME_ENGINE_FILE}"
else
ew "> Found no NetServerMaxTickRate parameter, adding it with value '${NETSERVERMAXTICKRATE}'\n"
ew "> Found no NetServerMaxTickRate parameter, adding it with value '${NETSERVERMAXTICKRATE}'"
echo "NetServerMaxTickRate=${NETSERVERMAXTICKRATE}" >> "${GAME_ENGINE_FILE}"
fi
es ">>> Finished setting up Engine.ini!\n"
es ">>> Finished setting up Engine.ini!"
}

function setup_palworld_settings_ini() {
ei ">>> Setting up PalWorldSettings.ini ...\n"
ei "> Checking if config already exists...\n"
ei ">>> Setting up PalWorldSettings.ini ..."
ei "> Checking if config already exists..."
if [ ! -f "${GAME_SETTINGS_FILE}" ]; then
ew "> No config found, generating one.\n"
ew "> No config found, generating one"
if [ ! -d "${GAME_CONFIG_PATH}" ]; then
mkdir -p "${GAME_CONFIG_PATH}/"
fi
# Copy default-config, which comes with SteamCMD to gameserver save location
cp "${GAME_ROOT}/DefaultPalWorldSettings.ini" "${GAME_SETTINGS_FILE}"
else
ei "> Found existing config!\n"
ei "> Found existing config!"
fi

if [[ -n ${DIFFICULTY+x} ]]; then
Expand Down Expand Up @@ -301,36 +301,36 @@ function setup_palworld_settings_ini() {
echo "> Setting BanListURL to '$BAN_LIST_URL'"
sed -E -i "s~BanListURL=\"[^\"]*\"~BanListURL=\"$BAN_LIST_URL\"~" "$GAME_SETTINGS_FILE"
fi
es ">>> Finished setting up PalWorldSettings.ini\n"
es ">>> Finished setting up PalWorldSettings.ini"
}

function setup_rcon_yaml () {
if [[ -n ${RCON_ENABLED+x} ]] && [ "$RCON_ENABLED" == "true" ] ; then
ei ">>> RCON is enabled - Setting up rcon.yaml ...\n"
ei ">>> RCON is enabled - Setting up rcon.yaml ..."
if [[ -n ${RCON_PORT+x} ]]; then
sed -i "s/###RCON_PORT###/$RCON_PORT/" "$RCON_CONFIG_FILE"
else
ee "> RCON_PORT is not set, please set it for RCON functionality to work!\n"
ee "> RCON_PORT is not set, please set it for RCON functionality to work!"
fi
if [[ -n ${ADMIN_PASSWORD+x} ]]; then
sed -i "s/###ADMIN_PASSWORD###/$ADMIN_PASSWORD/" "$RCON_CONFIG_FILE"
else
ee "> RCON_PORT is not set, please set it for RCON functionality to work!\n"
ee "> RCON_PORT is not set, please set it for RCON functionality to work!"
fi
es ">>> Finished setting up 'rcon.yaml' config file.\n"
es ">>> Finished setting up 'rcon.yaml' config file"
else
ei ">>> RCON is disabled, skipping 'rcon.yaml' config file!\n"
ei ">>> RCON is disabled, skipping 'rcon.yaml' config file!"
fi
}

function setup_configs() {
if [[ -n ${SERVER_SETTINGS_MODE} ]] && [[ ${SERVER_SETTINGS_MODE} == "auto" ]]; then
ei ">>> SERVER_SETTINGS_MODE is set to '${SERVER_SETTINGS_MODE}', using environment variables to configure the server!\n"
ei ">>> SERVER_SETTINGS_MODE is set to '${SERVER_SETTINGS_MODE}', using environment variables to configure the server!"
setup_engine_ini
setup_palworld_settings_ini
setup_rcon_yaml
else
ew ">>> SERVER_SETTINGS_MODE is set to '${SERVER_SETTINGS_MODE}', NOT using environment variables to configure the server!\n"
ew ">>> ALL SETTINGS including setup of rcon.yaml has to be done manually by the user!\n"
ew ">>> SERVER_SETTINGS_MODE is set to '${SERVER_SETTINGS_MODE}', NOT using environment variables to configure the server!"
ew ">>> ALL SETTINGS including setup of rcon.yaml has to be done manually by the user!"
fi
}
2 changes: 1 addition & 1 deletion includes/cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ function setup_crons() {
echo "${BACKUP_CRON_EXPRESSION} backupmanager --create" >> cronlist
fi
/usr/local/bin/supercronic -passthrough-logs cronlist &
ei ">>> Supercronic started\n"
ei ">>> Supercronic started"
}
12 changes: 6 additions & 6 deletions includes/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
source /includes/colors.sh

function fresh_install_server() {
ei ">>> Doing a fresh install of the gameserver...\n"
ei ">>> Doing a fresh install of the gameserver..."
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_install_notification
fi
"${STEAMCMD_PATH}"/steamcmd.sh +force_install_dir "$GAME_ROOT" +login anonymous +app_update 2394010 validate +quit
es "> Done installing the gameserver\n"
es "> Done installing the gameserver"
}

function update_server() {
if [[ -n $STEAMCMD_VALIDATE_FILES ]] && [[ $STEAMCMD_VALIDATE_FILES == "true" ]]; then
ei ">>> Doing an update and validate of the gameserver files...\n"
ei ">>> Doing an update and validate of the gameserver files..."
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_update_and_validate_notification
fi
"${STEAMCMD_PATH}"/steamcmd.sh +force_install_dir "$GAME_ROOT" +login anonymous +app_update 2394010 validate +quit
es ">>> Done updating and validating the gameserver files\n"
es ">>> Done updating and validating the gameserver files"
else
ei ">>> Doing an update of the gameserver files...\n"
ei ">>> Doing an update of the gameserver files..."
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_update_notification
fi
"${STEAMCMD_PATH}"/steamcmd.sh +force_install_dir "$GAME_ROOT" +login anonymous +app_update 2394010 +quit
es ">>> Done updating the gameserver files\n"
es ">>> Done updating the gameserver files"
fi
}
25 changes: 22 additions & 3 deletions includes/rcon.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
# shellcheck disable=SC2148

function save_and_shutdown_server() {
rcon 'broadcast Server-shutdown-was-requested-init-saving'
rcon 'save'
rcon 'broadcast Done-saving-server-shuts-down-now'
rconcli 'broadcast Server-shutdown-was-requested-init-saving'
rconcli 'save'
rconcli 'broadcast Done-saving-server-shuts-down-now'
}

function broadcast_backup_start() {
time=$(date '+%H:%M:%S')

rconcli "broadcast ${time}-Saving-in-5-seconds"
sleep 5
rconcli 'broadcast Saving-world...'
rconcli 'save'
rconcli 'broadcast Saving-done'
rconcli 'broadcast Creating-backup'
}

function broadcast_backup_success() {
rconcli 'broadcast Backup-done'
}

function broadcast_backup_failed() {
rconcli 'broadcast Backup-failed'
}
6 changes: 3 additions & 3 deletions includes/security.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
source /includes/colors.sh

function check_for_default_credentials() {
ei "> Checking for existence of default credentials\n"
ei "> Checking for existence of default credentials"
if [[ -n $ADMIN_PASSWORD ]] && [[ $ADMIN_PASSWORD == "adminPasswordHere" ]]; then
ee ">>> Security thread detected: Please change the default admin password. Aborting server start ...\n"
ee ">>> Security thread detected: Please change the default admin password. Aborting server start ..."
exit 1
fi
if [[ -n $SERVER_PASSWORD ]] && [[ $SERVER_PASSWORD == "serverPasswordHere" ]]; then
ee ">>> Security thread detected: Please change the default server password. Aborting server start ...\n"
ee ">>> Security thread detected: Please change the default server password. Aborting server start ..."
exit 1
fi
}
Loading

0 comments on commit bb8e0a1

Please sign in to comment.