From 4a2506154d3a3eceb0c6316234b1b840273b8bed Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 28 Jan 2024 01:36:21 -0500 Subject: [PATCH 01/29] add hooks --- README.md | 82 ++++++++++++++++++++++++++++++++++++---------- docker-compose.yml | 46 +++++++++++++------------- scripts/backup.sh | 10 ++++++ scripts/init.sh | 20 +++++++++++ 4 files changed, 117 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 983e33db8..d86fc743b 100644 --- a/README.md +++ b/README.md @@ -115,24 +115,30 @@ It is highly recommended you set the following environment values before startin * PUID * PGID -| Variable | Info | Default Values | Allowed Values | -|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|------------------------------------------------------------------------------------------------------------| -| TZ | Timezone used for time stamping backup server | UTC | See [TZ Identifiers](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#Time_Zone_abbreviations) | -| PLAYERS* | Max amount of players that are able to join the server | 16 | 1-32 | -| PORT* | UDP port that the server will expose | 8211 | 1024-65535 | -| PUID* | The uid of the user the server should run as | 1000 | !0 | -| PGID* | The gid of the group the server should run as | 1000 | !0 | -| MULTITHREADING** | Improves performance in multi-threaded CPU environments. It is effective up to a maximum of about 4 threads, and allocating more than this number of threads does not make much sense. | false | true/false | -| COMMUNITY | Whether or not the server shows up in the community server browser (USE WITH SERVER_PASSWORD) | false | true/false | -| PUBLIC_IP | You can manually specify the global IP address of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | x.x.x.x | -| PUBLIC_PORT | You can manually specify the port number of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | 1024-65535 | -| SERVER_NAME | A name for your server | | "string" | -| SERVER_PASSWORD | Secure your community server with a password | | "string" | -| ADMIN_PASSWORD | Secure administration access in the server with a password | | "string" | -| UPDATE_ON_BOOT** | Update/Install the server when the docker container starts (THIS HAS TO BE ENABLED THE FIRST TIME YOU RUN THE CONTAINER) | true | true/false | -| RCON_ENABLED*** | Enable RCON for the Palworld server | true | true/false | -| RCON_PORT | RCON port to connect to | 25575 | 1024-65535 | -| QUERY_PORT | Query port used to communicate with Steam servers | 27015 | 1024-65535 | +| Variable | Info | Default Values | Allowed Values | +|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|---------------------------------------------------------------------------------------| +| TZ | Timezone used for time stamping backup server | UTC | See [TZ Identifiers](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#Time_Zone_abbreviations) | +| PLAYERS* | Max amount of players that are able to join the server | 16 | 1-32 | +| PORT* | UDP port that the server will expose | 8211 | 1024-65535 | +| PUID* | The uid of the user the server should run as | 1000 | !0 | +| PGID* | The gid of the group the server should run as | 1000 | !0 | +| MULTITHREADING** | Improves performance in multi-threaded CPU environments. It is effective up to a maximum of about 4 threads, and allocating more than this number of threads does not make much sense. | false | true/false | +| COMMUNITY | Whether or not the server shows up in the community server browser (USE WITH SERVER_PASSWORD) | false | true/false | +| PUBLIC_IP | You can manually specify the global IP address of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | x.x.x.x | +| PUBLIC_PORT | You can manually specify the port number of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | 1024-65535 | +| SERVER_NAME | A name for your server | | "string" | +| SERVER_PASSWORD | Secure your community server with a password | | "string" | +| ADMIN_PASSWORD | Secure administration access in the server with a password | | "string" | +| UPDATE_ON_BOOT** | Update/Install the server when the docker container starts (THIS HAS TO BE ENABLED THE FIRST TIME YOU RUN THE CONTAINER) | true | true/false | +| RCON_ENABLED*** | Enable RCON for the Palworld server | true | true/false | +| RCON_PORT | RCON port to connect to | 25575 | 1024-65535 | +| QUERY_PORT | Query port used to communicate with Steam servers | 27015 | 1024-65535 | +| PRE_INIT_HOOK | You can add a custom sh commands before initializing | | sh command | +| POST_INIT_HOOK | You can add a custom sh commands after initializing | | sh command | +| PRE_BACKUP_HOOK | You can add a custom sh commands before a backup is created | | sh command | +| POST_BACKUP_HOOK | You can add a custom sh commands after a backup is created | | sh command | +| PRE_SHUTDOWN_HOOK | You can add a custom sh commands before pid is killed | | sh command | +| POST_SHUTDOWN_HOOK | You can add a custom sh commands after pid is killed | | sh command | *highly recommended to set @@ -203,6 +209,46 @@ Please keep in mind that the ENV variables will always overwrite the changes mad For a more detailed list of explanations of server settings go to: [shockbyte](https://shockbyte.com/billing/knowledgebase/1189/How-to-Configure-your-Palworld-server.html) +## Using sh hooks + +### Create a backup + +Backup the server whenever it is gracefully shut down. + +docker run: + +```sh +-e POST_SHUTDOWN_HOOK=backup +``` + +docker compose: + +```yaml +- POST_SHUTDOWN_HOOK=backup +``` + +### Send discord webhooks + +1. Generate a webhook url for your discord server in your discord's server settings. + +2. You can use the discord webhook in the pre init hook like so: + +send discord message with docker run: + +```sh +-e DISCORD_WEBHOOK="https://discord.com/api/webhooks/xxxx/xxxxx" \ +-e DISCORD_PRE_INIT_MESSAGE="Server initializing" \ +-e PRE_INIT_HOOK='curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$DISCORD_PRE_INIT_MESSAGE\"}" "$DISCORD_WEBHOOK"' +``` + +send discord message with docker compose: + +```yaml +- DISCORD_WEBHOOK=https://discord.com/api/webhooks/xxxx/xxxxx +- DISCORD_PRE_INIT_MESSAGE="Server initializing..." +- 'PRE_INIT_HOOK=curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$$(eval echo $$DISCORD_PRE_INIT_MESSAGE)\"}" $$DISCORD_WEBHOOK' +``` + ## Reporting Issues/Feature Requests Issues/Feature requests can be submitted by using [this link](https://github.com/thijsvanloef/palworld-server-docker/issues/new/choose). diff --git a/docker-compose.yml b/docker-compose.yml index 592f520ea..3cd213397 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,24 @@ services: - palworld: - image: thijsvanloef/palworld-server-docker:latest - restart: unless-stopped - container_name: palworld-server - ports: - - 8211:8211/udp - - 27015:27015/udp # Required if you want your server to show up in the community servers tab - environment: - - PUID=1000 - - PGID=1000 - - PORT=8211 # Optional but recommended - - PLAYERS=16 # Optional but recommended - - SERVER_PASSWORD="worldofpals" # Optional but recommended - - MULTITHREADING=true - - RCON_ENABLED=true - - RCON_PORT=25575 - - TZ=UTC - - ADMIN_PASSWORD="adminPasswordHere" - - COMMUNITY=false # Enable this if you want your server to show up in the community servers tab, USE WITH SERVER_PASSWORD! - - SERVER_NAME="World of Pals" - - SERVER_DESCRIPTION="" - volumes: - - ./palworld:/palworld/ + palworld: + image: thijsvanloef/palworld-server-docker:latest + restart: unless-stopped + container_name: palworld-server + ports: + - 8211:8211/udp + - 27015:27015/udp # Required if you want your server to show up in the community servers tab + environment: + - PUID=1000 + - PGID=1000 + - PORT=8211 # Optional but recommended + - PLAYERS=16 # Optional but recommended + - SERVER_PASSWORD="worldofpals" # Optional but recommended + - MULTITHREADING=true + - RCON_ENABLED=true + - RCON_PORT=25575 + - TZ=UTC + - ADMIN_PASSWORD="adminPasswordHere" + - COMMUNITY=false # Enable this if you want your server to show up in the community servers tab, USE WITH SERVER_PASSWORD! + - SERVER_NAME="World of Pals" + - SERVER_DESCRIPTION="" + volumes: + - ./palworld:/palworld/ \ No newline at end of file diff --git a/scripts/backup.sh b/scripts/backup.sh index 82e75eb19..a3e7e75a2 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [ -n "$PRE_BACKUP_HOOK" ]; then + echo "PRE_BACKUP_HOOK: $PRE_BACKUP_HOOK" + eval "$PRE_BACKUP_HOOK" +fi + if [ "${RCON_ENABLED}" = true ]; then rcon-cli save fi @@ -10,3 +15,8 @@ cd /palworld/Pal/ || exit tar -zcf "$FILE_PATH" "Saved/" echo "backup created at $FILE_PATH" + +if [ -n "$POST_BACKUP_HOOK" ]; then + echo "POST_BACKUP_HOOK: $POST_BACKUP_HOOK" + eval "$POST_BACKUP_HOOK" +fi \ No newline at end of file diff --git a/scripts/init.sh b/scripts/init.sh index bbf91a455..3be10264e 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [ -n "$PRE_INIT_HOOK" ]; then + echo "PRE_INIT_HOOK: $PRE_INIT_HOOK" + eval "$PRE_INIT_HOOK" +fi + if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n" usermod -o -u "${PUID}" steam @@ -18,6 +23,11 @@ if [ "${UPDATE_ON_BOOT}" = true ]; then fi term_handler() { + if [ -n "$PRE_SHUTDOWN_HOOK" ]; then + echo "PRE_SHUTDOWN_HOOK: $PRE_SHUTDOWN_HOOK" + eval "$PRE_SHUTDOWN_HOOK" + fi + if [ "${RCON_ENABLED}" = true ]; then rcon-cli save rcon-cli "shutdown 1" @@ -25,10 +35,20 @@ term_handler() { kill -SIGTERM "$(pidof PalServer-Linux-Test)" fi tail --pid=$killpid -f 2>/dev/null + + if [ -n "$POST_SHUTDOWN_HOOK" ]; then + echo "POST_SHUTDOWN_HOOK: $POST_SHUTDOWN_HOOK" + eval "$POST_SHUTDOWN_HOOK" + fi } trap 'term_handler' SIGTERM +if [ -n "$POST_INIT_HOOK" ]; then + echo "POST_INIT_HOOK: $POST_INIT_HOOK" + eval "$POST_INIT_HOOK" +fi + ./start.sh & killpid="$!" wait $killpid From 401057928d2bd2ecfef6c0cce872ba1a1c98ddf9 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 28 Jan 2024 02:17:42 -0500 Subject: [PATCH 02/29] -X is assumed when using -d arg for curl --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d86fc743b..9dadefa25 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ send discord message with docker run: ```sh -e DISCORD_WEBHOOK="https://discord.com/api/webhooks/xxxx/xxxxx" \ -e DISCORD_PRE_INIT_MESSAGE="Server initializing" \ --e PRE_INIT_HOOK='curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$DISCORD_PRE_INIT_MESSAGE\"}" "$DISCORD_WEBHOOK"' +-e PRE_INIT_HOOK='curl -sfSL -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$DISCORD_PRE_INIT_MESSAGE\"}" "$DISCORD_WEBHOOK"' ``` send discord message with docker compose: @@ -246,7 +246,7 @@ send discord message with docker compose: ```yaml - DISCORD_WEBHOOK=https://discord.com/api/webhooks/xxxx/xxxxx - DISCORD_PRE_INIT_MESSAGE="Server initializing..." -- 'PRE_INIT_HOOK=curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$$(eval echo $$DISCORD_PRE_INIT_MESSAGE)\"}" $$DISCORD_WEBHOOK' +- 'PRE_INIT_HOOK=curl -sfSL -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$$(eval echo $$DISCORD_PRE_INIT_MESSAGE)\"}" $$DISCORD_WEBHOOK' ``` ## Reporting Issues/Feature Requests From 65aae408e12f9b9a7a182c7653b2b91490a0ed2f Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Thu, 1 Feb 2024 03:35:44 -0500 Subject: [PATCH 03/29] testing new discord vars --- Dockerfile | 11 +++-- scripts/backup.sh | 26 +++++----- scripts/discord.sh | 115 +++++++++++++++++++++++++++++++++++++++++++++ scripts/init.sh | 20 ++------ scripts/start.sh | 21 +++++++-- scripts/update.sh | 3 ++ 6 files changed, 161 insertions(+), 35 deletions(-) create mode 100644 scripts/discord.sh diff --git a/Dockerfile b/Dockerfile index acaf6c779..92fe16349 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,10 +19,10 @@ ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0. SUPERCRONIC_SHA1SUM=cd48d45c4b10f3f0bfdd3a57d054cd05ac96812b RUN wget -q "$SUPERCRONIC_URL" \ - && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \ - && chmod +x "$SUPERCRONIC" \ - && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \ - && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic + && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \ + && chmod +x "$SUPERCRONIC" \ + && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \ + && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic ENV PORT= \ PUID=1000 \ @@ -50,7 +50,8 @@ ENV PORT= \ COPY ./scripts/* /home/steam/server/ RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh /home/steam/server/update.sh && \ mv /home/steam/server/backup.sh /usr/local/bin/backup && \ - mv /home/steam/server/update.sh /usr/local/bin/update + mv /home/steam/server/update.sh /usr/local/bin/update && \ + mv /home/steam/server/discord.sh /usr/local/bin/discord WORKDIR /home/steam/server diff --git a/scripts/backup.sh b/scripts/backup.sh index 55ab95fe4..98c429b60 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,12 +1,11 @@ #!/bin/bash -if [ -n "$PRE_BACKUP_HOOK" ]; then - echo "PRE_BACKUP_HOOK: $PRE_BACKUP_HOOK" - eval "$PRE_BACKUP_HOOK" +if [ -n "$DISCORD_PRE_BACKUP_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_BACKUP_JSON & fi if [ "${RCON_ENABLED}" = true ]; then - rcon-cli -c /home/steam/server/rcon.yaml save + rcon-cli -c /home/steam/server/rcon.yaml save fi DATE=$(date +"%Y-%m-%d_%H-%M-%S") @@ -16,17 +15,22 @@ cd /palworld/Pal/ || exit tar -zcf "$FILE_PATH" "Saved/" if [ "$(id -u)" -eq 0 ]; then - chown steam:steam "$FILE_PATH" + chown steam:steam "$FILE_PATH" fi -echo "backup created at $FILE_PATH" +echo "backup created at ${FILE_PATH}" -if [ -n "$POST_BACKUP_HOOK" ]; then - echo "POST_BACKUP_HOOK: $POST_BACKUP_HOOK" - eval "$POST_BACKUP_HOOK" +if [ -n "$DISCORD_POST_BACKUP_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_BACKUP_JSON & fi if [ "${DELETE_OLD_BACKUPS}" = true ]; then - echo "removing backups older than ${OLD_BACKUP_DAYS:=30} days" - find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -print -delete + echo "removing backups older than ${OLD_BACKUP_DAYS:=30} days" + if [ -n "$DISCORD_PRE_BACKUP_DELETE_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_BACKUP_DELETE_JSON & + fi + find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -print -delete + if [ -n "$DISCORD_POST_BACKUP_DELETE_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_BACKUP_DELETE_JSON & + fi fi diff --git a/scripts/discord.sh b/scripts/discord.sh new file mode 100644 index 000000000..cc058a353 --- /dev/null +++ b/scripts/discord.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +# Command usage +usage() { +cat << EOH +Usage: $0 [OPTION]... -d WEBHOOK_ID -t TIMEOUT -j JSON +Post a discord message via a discord webhook. By default uses a 30s connect-timeout. Webhook id an json are required. A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html +Package requirement: curl + +Examples: + $0 -i 01234/56789 -t 30 -l info -j {"username":"Palworld","content":"Server starting..."} + $0 --webhook-id 01234/56789 --timeout 30 --level info --json {"username":"Palworld","content":"Server starting..."} + +Options: + -i, --webhook-id The unique id that is used by discord to determine what server/channel/thread to post. ex: https://discord.com/api/webhooks/ + -t, --timeout The timeout for connecting to the discord webhook (Default: 30) + -j, --json The json message body sent to the discord webhook + -h, --help Display help text and exit +EOH +} + +# DISCORD_WEBHOOK +# DISCORD_USER +# DISCORD_TIMEOUT +# NICE_SHUTDOWN_TIME + +# Defaults +RED='\033[0;31m' +NC='\033[0m' +REQ=2 +REQ_FLAG=0 +TIMEOUT=30 + +# # Decimal Colors +# INFO=1127128 # blue +# IN_PROGRESS=15258703 # yellow +# WARN=14177041 # orange +# FAILURE=14614528 # red +# SUCCESS=52224 # green + +# Show usage if no arguments specified +if [[ $# -eq 0 ]]; then + usage + exit 0 +fi + +# Parse arguments +POSITIONAL=() +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -i|--webhook-id ) + WEBHOOK_ID="$2" + ((REQ_FLAG++)) + shift + shift + ;; + -t|--timeout ) + TIMEOUT="$2" + shift + shift + ;; + -j|--json ) + JSON="$2" + ((REQ_FLAG++)) + shift + shift + ;; + -h|--help ) + usage + exit 0 + ;; + * ) + POSITIONAL+=("$1") + shift + ;; + esac +done +set -- "${POSITIONAL[@]}" + +# Check required options +if [ $REQ_FLAG -lt $REQ ]; then + printf "${RED}webhook-id and json are required${NC}\n" + usage + exit 1 +fi + +# Set discord webhook +DISCORD_WEBHOOK = "https://discord.com/api/webhooks/$WEBHOOK_ID" +echo "Sending Discord json: ${JSON}" +curl -sfSL --connect-timeout "$TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" + +# # Log into AWS CLI if not already logged in +# check-aws-login + +# # Set AWS Profile for following aws commands +# export AWS_PROFILE=$PROFILE + +# if [ -n "$SERVICE_NAME" ]; then +# # Get arn of service +# SERVICE_LIST=$(aws ecs describe-services --cluster $CLUSTER --services $SERVICE_NAME | jq --raw-output '.services[].serviceArn') +# else +# # Get list of ECS service on cluster +# SERVICE_LIST=$(aws ecs list-services --cluster $CLUSTER | jq --raw-output '.serviceArns[]') +# fi + +# for SERVICE in $SERVICE_LIST; do +# SERVICE_NAME=$(cut -d/ -f2 <<< $SERVICE) +# TASK_DEF=$(aws ecs describe-services --cluster $CLUSTER --services $SERVICE_NAME | jq --raw-output '.services[].taskDefinition') + +# # Outputs the list of endpoints slightly formatted +# echo "Service $SERVICE_NAME:" +# aws ecs describe-task-definition --task-definition $TASK_DEF | jq -c '.taskDefinition.containerDefinitions[].environment[] | select(.value | contains("'$ELB_PREFIX'"))' | sed 's/{\"name\":\"/\t/; s/\",\"value\":\"/ = /; s/\"}//' +# done diff --git a/scripts/init.sh b/scripts/init.sh index 51b998b00..907e6c5d8 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,10 +1,5 @@ #!/bin/bash -if [ -n "$PRE_INIT_HOOK" ]; then - echo "PRE_INIT_HOOK: $PRE_INIT_HOOK" - eval "$PRE_INIT_HOOK" -fi - if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n" usermod -o -u "${PUID}" steam @@ -18,9 +13,8 @@ mkdir -p /palworld/backups chown -R steam:steam /palworld /home/steam/ term_handler() { - if [ -n "$PRE_SHUTDOWN_HOOK" ]; then - echo "PRE_SHUTDOWN_HOOK: $PRE_SHUTDOWN_HOOK" - eval "$PRE_SHUTDOWN_HOOK" + if [ -n "$DISCORD_WEBHOOK_ID" ]; then + su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_JSON" & fi if [ "${RCON_ENABLED}" = true ]; then @@ -31,19 +25,13 @@ term_handler() { fi tail --pid=$killpid -f 2>/dev/null - if [ -n "$POST_SHUTDOWN_HOOK" ]; then - echo "POST_SHUTDOWN_HOOK: $POST_SHUTDOWN_HOOK" - eval "$POST_SHUTDOWN_HOOK" + if [ -n "$DISCORD_WEBHOOK_ID" ]; then + su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_JSON" & fi } trap 'term_handler' SIGTERM -if [ -n "$POST_INIT_HOOK" ]; then - echo "POST_INIT_HOOK: $POST_INIT_HOOK" - eval "$POST_INIT_HOOK" -fi - su steam -c ./start.sh & # Process ID of su killpid="$!" diff --git a/scripts/start.sh b/scripts/start.sh index ab86d3b5f..1654e107d 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,8 +1,19 @@ #!/bin/bash + + if [ "${UPDATE_ON_BOOT}" = true ]; then printf "\e[0;32m*****STARTING INSTALL/UPDATE*****\e[0m\n" + + if [ -n "$DISCORD_PRE_UPDATE_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_UPDATE_JSON & + fi + /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit + + if [ -n "$DISCORD_POST_UPDATE_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_UPDATE_JSON & + fi fi STARTCOMMAND=("./PalServer.sh") @@ -61,7 +72,7 @@ if [ -n "${SERVER_PASSWORD}" ]; then fi if [ -n "${ADMIN_PASSWORD}" ]; then ADMIN_PASSWORD=$(sed -e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'$/\1/" <<< "$ADMIN_PASSWORD") - echo "ADMIN_PASSWORD=${ADMIN_PASSWORD}" + echo "ADMIN_PASSWORD=${ADMIN_PASSWORD}" sed -E -i "s/AdminPassword=\"[^\"]*\"/AdminPassword=\"$ADMIN_PASSWORD\"/" /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini fi if [ -n "${PLAYERS}" ]; then @@ -303,7 +314,6 @@ fi rm -f "/home/steam/server/crontab" if [ "${BACKUP_ENABLED}" = true ]; then echo "BACKUP_ENABLED=${BACKUP_ENABLED}" - echo "$BACKUP_CRON_EXPRESSION bash /usr/local/bin/backup" >> "/home/steam/server/crontab" fi @@ -324,6 +334,11 @@ default: EOL printf "\e[0;32m*****STARTING SERVER*****\e[0m\n" +if [ -n "$DISCORD_PRE_START_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_START_JSON & +fi echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" - +if [ -n "$DISCORD_POST_START_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_START_JSON & +fi \ No newline at end of file diff --git a/scripts/update.sh b/scripts/update.sh index c523c4c71..fa1ac23fe 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -25,6 +25,9 @@ fi if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD." if [ "${RCON_ENABLED}" = true ]; then + if [ -n "$DISCORD_PRE_UPDATE_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_UPDATE_JSON & + fi rm /palworld/steamapps/appmanifest_2394010.acf rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" From 5ed5522bdc4976139d313869aa9f8163c9922fc0 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 13:30:18 -0500 Subject: [PATCH 04/29] solve linting errors --- scripts/discord.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index cc058a353..6984584df 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -81,13 +81,13 @@ set -- "${POSITIONAL[@]}" # Check required options if [ $REQ_FLAG -lt $REQ ]; then - printf "${RED}webhook-id and json are required${NC}\n" + printf "%s\n" "${RED}webhook-id and json are required${NC}" usage exit 1 fi # Set discord webhook -DISCORD_WEBHOOK = "https://discord.com/api/webhooks/$WEBHOOK_ID" +DISCORD_WEBHOOK="https://discord.com/api/webhooks/$WEBHOOK_ID" echo "Sending Discord json: ${JSON}" curl -sfSL --connect-timeout "$TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" From 96e73b9dcedd645a3fe61a770a12a06f9dd8a29e Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 13:38:22 -0500 Subject: [PATCH 05/29] dockerfile linting --- Dockerfile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 69c57998e..9f64f3138 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ FROM cm2network/steamcmd:root LABEL maintainer="thijs@loef.dev" \ - name="thijsvanloef/palworld-server-docker" \ - github="https://github.com/thijsvanloef/palworld-server-docker" \ - dockerhub="https://hub.docker.com/r/thijsvanloef/palworld-server-docker" \ - org.opencontainers.image.authors="Thijs van Loef" \ - org.opencontainers.image.source="https://github.com/thijsvanloef/palworld-server-docker" + name="thijsvanloef/palworld-server-docker" \ + github="https://github.com/thijsvanloef/palworld-server-docker" \ + dockerhub="https://hub.docker.com/r/thijsvanloef/palworld-server-docker" \ + org.opencontainers.image.authors="Thijs van Loef" \ + org.opencontainers.image.source="https://github.com/thijsvanloef/palworld-server-docker" # update and install dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -27,16 +27,16 @@ ENV RCON_MD5SUM="8601c70dcab2f90cd842c127f700e398" \ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN wget --progress=dot:giga https://github.com/gorcon/rcon-cli/releases/download/v${RCON_VERSION}/rcon-${RCON_VERSION}-amd64_linux.tar.gz -O rcon.tar.gz \ - && echo "${RCON_MD5SUM}" rcon.tar.gz | md5sum -c - \ - && tar -xzvf rcon.tar.gz \ - && rm rcon.tar.gz \ - && mv rcon-${RCON_VERSION}-amd64_linux/rcon /usr/bin/rcon-cli \ - && rmdir /tmp/dumps + && echo "${RCON_MD5SUM}" rcon.tar.gz | md5sum -c - \ + && tar -xzvf rcon.tar.gz \ + && rm rcon.tar.gz \ + && mv rcon-${RCON_VERSION}-amd64_linux/rcon /usr/bin/rcon-cli \ + && rmdir /tmp/dumps RUN wget --progress=dot:giga https://github.com/aptible/supercronic/releases/download/v${SUPERCRONIC_VERSION}/supercronic-linux-amd64 -O supercronic \ - && echo "${SUPERCRONIC_SHA1SUM}" supercronic | sha1sum -c - \ - && chmod +x supercronic \ - && mv supercronic /usr/local/bin/supercronic + && echo "${SUPERCRONIC_SHA1SUM}" supercronic | sha1sum -c - \ + && chmod +x supercronic \ + && mv supercronic /usr/local/bin/supercronic ENV PORT= \ PUID=1000 \ From cd04e85e2949037879d82fcbf8b4ba707a70e7ca Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 13:40:02 -0500 Subject: [PATCH 06/29] remove comments --- scripts/discord.sh | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index 6984584df..85b212a4b 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -90,26 +90,3 @@ fi DISCORD_WEBHOOK="https://discord.com/api/webhooks/$WEBHOOK_ID" echo "Sending Discord json: ${JSON}" curl -sfSL --connect-timeout "$TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" - -# # Log into AWS CLI if not already logged in -# check-aws-login - -# # Set AWS Profile for following aws commands -# export AWS_PROFILE=$PROFILE - -# if [ -n "$SERVICE_NAME" ]; then -# # Get arn of service -# SERVICE_LIST=$(aws ecs describe-services --cluster $CLUSTER --services $SERVICE_NAME | jq --raw-output '.services[].serviceArn') -# else -# # Get list of ECS service on cluster -# SERVICE_LIST=$(aws ecs list-services --cluster $CLUSTER | jq --raw-output '.serviceArns[]') -# fi - -# for SERVICE in $SERVICE_LIST; do -# SERVICE_NAME=$(cut -d/ -f2 <<< $SERVICE) -# TASK_DEF=$(aws ecs describe-services --cluster $CLUSTER --services $SERVICE_NAME | jq --raw-output '.services[].taskDefinition') - -# # Outputs the list of endpoints slightly formatted -# echo "Service $SERVICE_NAME:" -# aws ecs describe-task-definition --task-definition $TASK_DEF | jq -c '.taskDefinition.containerDefinitions[].environment[] | select(.value | contains("'$ELB_PREFIX'"))' | sed 's/{\"name\":\"/\t/; s/\",\"value\":\"/ = /; s/\"}//' -# done From 97bd8409c2785a5c1cbc7770b708931de74704ef Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 13:50:02 -0500 Subject: [PATCH 07/29] define max_timeout --- scripts/discord.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index 85b212a4b..3fde5ea4b 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -3,7 +3,7 @@ # Command usage usage() { cat << EOH -Usage: $0 [OPTION]... -d WEBHOOK_ID -t TIMEOUT -j JSON +Usage: $0 [OPTION]... -d WEBHOOK_ID -t CONNECT_TIMEOUT -m MAX_TIMEOUT -j JSON Post a discord message via a discord webhook. By default uses a 30s connect-timeout. Webhook id an json are required. A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html Package requirement: curl @@ -12,10 +12,11 @@ Examples: $0 --webhook-id 01234/56789 --timeout 30 --level info --json {"username":"Palworld","content":"Server starting..."} Options: - -i, --webhook-id The unique id that is used by discord to determine what server/channel/thread to post. ex: https://discord.com/api/webhooks/ - -t, --timeout The timeout for connecting to the discord webhook (Default: 30) - -j, --json The json message body sent to the discord webhook - -h, --help Display help text and exit + -i, --webhook-id The unique id that is used by discord to determine what server/channel/thread to post. ex: https://discord.com/api/webhooks/ + -t, --connect-timeout The timeout for connecting to the discord webhook (Default: 30) + -m, --max-timeout The maximum time curl will wait for a response (Default: 30) + -j, --json The json message body sent to the discord webhook + -h, --help Display help text and exit EOH } @@ -30,6 +31,7 @@ NC='\033[0m' REQ=2 REQ_FLAG=0 TIMEOUT=30 +MAX_TIMEOUT=30 # # Decimal Colors # INFO=1127128 # blue @@ -56,8 +58,13 @@ while [[ $# -gt 0 ]]; do shift shift ;; - -t|--timeout ) - TIMEOUT="$2" + -t|--connect-timeout ) + CONNECT_TIMEOUT="$2" + shift + shift + ;; + -m|--max-timeout ) + MAX_TIMEOUT="$2" shift shift ;; @@ -89,4 +96,4 @@ fi # Set discord webhook DISCORD_WEBHOOK="https://discord.com/api/webhooks/$WEBHOOK_ID" echo "Sending Discord json: ${JSON}" -curl -sfSL --connect-timeout "$TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" +curl -sfSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$MAX_TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" From a39eca72fa8bb53e8ea6d79679c67699d4520260 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 13:59:32 -0500 Subject: [PATCH 08/29] testing new discord msgs --- scripts/init.sh | 4 ++-- scripts/start.sh | 8 ++++---- scripts/update.sh | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index ced6646a6..a4d01e5ff 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -15,7 +15,7 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { if [ -n "$DISCORD_WEBHOOK_ID" ]; then - su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_JSON" & + su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_SHUTDOWN_JSON" & fi if [ "${RCON_ENABLED,,}" = true ]; then rcon-cli save @@ -25,7 +25,7 @@ term_handler() { fi tail --pid="$killpid" -f 2>/dev/null if [ -n "$DISCORD_WEBHOOK_ID" ]; then - su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_JSON" & + su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_SHUTDOWN_JSON" & fi } diff --git a/scripts/start.sh b/scripts/start.sh index 55d365fdf..344459715 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -59,14 +59,14 @@ cd /palworld || exit if [ "${UPDATE_ON_BOOT,,}" = true ]; then printf "\e[0;32m*****STARTING INSTALL/UPDATE*****\e[0m\n" - if [ -n "$DISCORD_PRE_UPDATE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_UPDATE_JSON & + if [ -n "$DISCORD_PRE_UPDATE_BOOT_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_UPDATE_BOOT_JSON & fi /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit - if [ -n "$DISCORD_POST_UPDATE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_UPDATE_JSON & + if [ -n "$DISCORD_POST_UPDATE_BOOT_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_UPDATE_BOOT_JSON & fi fi diff --git a/scripts/update.sh b/scripts/update.sh index dd6cb817a..a2558ade6 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -33,6 +33,9 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then sleep "${AUTO_UPDATE_WARN_MINUTES}m" backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + if [ -n "$DISCORD_POST_UPDATE_JSON" ]; then + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_UPDATE_JSON & + fi else echo "An update is available however auto updating without rcon is not supported" fi From be93af234e1c2ed0b8c95f04e239aff0c30500f0 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 14:23:25 -0500 Subject: [PATCH 09/29] update printf formatting to interpret escapes --- scripts/discord.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index 3fde5ea4b..3416a8f78 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -88,7 +88,7 @@ set -- "${POSITIONAL[@]}" # Check required options if [ $REQ_FLAG -lt $REQ ]; then - printf "%s\n" "${RED}webhook-id and json are required${NC}" + printf "%b\n" "${RED}webhook-id and json are required${NC}" usage exit 1 fi From c1bcdc951e2c842c6d015a9954ede75f6c1d7829 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 14:35:15 -0500 Subject: [PATCH 10/29] update help msg --- scripts/discord.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index 3416a8f78..f64336c7d 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -4,7 +4,7 @@ usage() { cat << EOH Usage: $0 [OPTION]... -d WEBHOOK_ID -t CONNECT_TIMEOUT -m MAX_TIMEOUT -j JSON -Post a discord message via a discord webhook. By default uses a 30s connect-timeout. Webhook id an json are required. A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html +Post a discord message via a discord webhook. By default uses a 30s connect-timeout and 30s max-timeout. Webhook id an json are required to send a discord webhook. A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html Package requirement: curl Examples: From b932e6d00bf10bfd375c7a3cf516b00153c9daa4 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 14:38:24 -0500 Subject: [PATCH 11/29] update help params --- scripts/discord.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index f64336c7d..b85b78a3b 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -3,13 +3,13 @@ # Command usage usage() { cat << EOH -Usage: $0 [OPTION]... -d WEBHOOK_ID -t CONNECT_TIMEOUT -m MAX_TIMEOUT -j JSON +Usage: $0 [OPTION]... -i WEBHOOK_ID -t CONNECT_TIMEOUT -m MAX_TIMEOUT -j JSON Post a discord message via a discord webhook. By default uses a 30s connect-timeout and 30s max-timeout. Webhook id an json are required to send a discord webhook. A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html Package requirement: curl Examples: - $0 -i 01234/56789 -t 30 -l info -j {"username":"Palworld","content":"Server starting..."} - $0 --webhook-id 01234/56789 --timeout 30 --level info --json {"username":"Palworld","content":"Server starting..."} + $0 -i 01234/56789 -t 30 -m 30 -j {"username":"Palworld","content":"Server starting..."} + $0 --webhook-id 01234/56789 --connect-timeout 30 --max-timeout 30 --json {"username":"Palworld","content":"Server starting..."} Options: -i, --webhook-id The unique id that is used by discord to determine what server/channel/thread to post. ex: https://discord.com/api/webhooks/ From 54be46fc41eee1c9b2c67f299712338eb2b99c4a Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Sun, 4 Feb 2024 16:47:23 -0500 Subject: [PATCH 12/29] validate timeout integer and update discord cmd --- Dockerfile | 4 +++- scripts/backup.sh | 8 ++++---- scripts/discord.sh | 18 ++++++++++++++++-- scripts/start.sh | 4 ++-- scripts/update.sh | 4 ++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f64f3138..5751355cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,7 +64,9 @@ ENV PORT= \ AUTO_UPDATE_WARN_MINUTES=30 \ AUTO_REBOOT_ENABLED=false \ AUTO_REBOOT_WARN_MINUTES=5 \ - AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" + AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" \ + DISCORD_CONNECT_TIMEOUT=30 \ + DISCORD_MAX_TIMEOUT=30 COPY ./scripts/* /home/steam/server/ diff --git a/scripts/backup.sh b/scripts/backup.sh index 0500f9c3a..3d96f6c30 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "$DISCORD_PRE_BACKUP_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_BACKUP_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_BACKUP_JSON & fi if [ "${RCON_ENABLED,,}" = true ]; then @@ -22,12 +22,12 @@ fi echo "backup created at ${FILE_PATH}" if [ -n "$DISCORD_POST_BACKUP_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_BACKUP_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_BACKUP_JSON & fi if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then if [ -n "$DISCORD_PRE_BACKUP_DELETE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_BACKUP_DELETE_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_BACKUP_DELETE_JSON & fi if [ -z "${OLD_BACKUP_DAYS}" ]; then echo "Unable to deleted old backups, OLD_BACKUP_DAYS is empty." @@ -38,6 +38,6 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then echo "Unable to deleted old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" fi if [ -n "$DISCORD_POST_BACKUP_DELETE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_BACKUP_DELETE_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_BACKUP_DELETE_JSON & fi fi \ No newline at end of file diff --git a/scripts/discord.sh b/scripts/discord.sh index b85b78a3b..28b7447de 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -30,8 +30,8 @@ RED='\033[0;31m' NC='\033[0m' REQ=2 REQ_FLAG=0 -TIMEOUT=30 -MAX_TIMEOUT=30 +DEFAULT_CONNECT_TIMEOUT=30 +DEFAULT_MAX_TIMEOUT=30 # # Decimal Colors # INFO=1127128 # blue @@ -93,6 +93,20 @@ if [ $REQ_FLAG -lt $REQ ]; then exit 1 fi +if [ -n "${$CONNECT_TIMEOUT}" ] && [[ "${CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then + CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT +else + echo "CONNECT_TIMEOUT is not an integer, using default ${$DEFAULT_CONNECT_TIMEOUT} seconds." + CONNECT_TIMEOUT=$DEFAULT_CONNECT_TIMEOUT +fi + +if [ -n "${MAX_TIMEOUT}" ] && [[ "${MAX_TIMEOUT}" =~ ^[0-9]+$ ]]; then + MAX_TIMEOUT=$DISCORD_MAX_TIMEOUT +else + echo "MAX_TIMEOUT is not an integer, using default ${DEFAULT_MAX_TIMEOUT} seconds." + MAX_TIMEOUT=$DEFAULT_MAX_TIMEOUT +fi + # Set discord webhook DISCORD_WEBHOOK="https://discord.com/api/webhooks/$WEBHOOK_ID" echo "Sending Discord json: ${JSON}" diff --git a/scripts/start.sh b/scripts/start.sh index 344459715..130024a6e 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -404,11 +404,11 @@ EOL printf "\e[0;32m*****STARTING SERVER*****\e[0m\n" if [ -n "$DISCORD_PRE_START_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_START_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_START_JSON & fi echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" if [ -n "$DISCORD_POST_START_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_START_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_START_JSON & fi exit 0 diff --git a/scripts/update.sh b/scripts/update.sh index a2558ade6..8519e0a5f 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -26,7 +26,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD." if [ "${RCON_ENABLED,,}" = true ]; then if [ -n "$DISCORD_PRE_UPDATE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_PRE_UPDATE_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_UPDATE_JSON & fi rm /palworld/steamapps/appmanifest_2394010.acf rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" @@ -34,7 +34,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" if [ -n "$DISCORD_POST_UPDATE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_TIMEOUT -j $DISCORD_POST_UPDATE_JSON & + discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_UPDATE_JSON & fi else echo "An update is available however auto updating without rcon is not supported" From 1a8ae987b57e376045f426fd04fe7c4ef0359acb Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 04:08:36 -0500 Subject: [PATCH 13/29] tested basic discord functionality --- Dockerfile | 8 ++++- scripts/backup.sh | 36 ++++++++++++--------- scripts/discord.sh | 80 +++++++++++++++++++++++++++++++--------------- scripts/init.sh | 13 ++++---- scripts/start.sh | 28 ++++++++-------- scripts/update.sh | 21 ++++++++---- 6 files changed, 119 insertions(+), 67 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5751355cb..eddbe4622 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ procps=2:3.3.17-5 \ wget=1.21-1+deb11u1 \ xdg-user-dirs=0.17-2 \ + jo=1.3-2 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -66,7 +67,12 @@ ENV PORT= \ AUTO_REBOOT_WARN_MINUTES=5 \ AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" \ DISCORD_CONNECT_TIMEOUT=30 \ - DISCORD_MAX_TIMEOUT=30 + DISCORD_MAX_TIMEOUT=30 \ + DISCORD_PRE_UPDATE_BOOT_MESSAGE="Server is updating..." \ + DISCORD_POST_UPDATE_BOOT_MESSAGE="Server update complete!" \ + DISCORD_PRE_START_MESSAGE="Server is started!" \ + DISCORD_PRE_SHUTDOWN_MESSAGE="Server is shutting down..." \ + DISCORD_POST_SHUTDOWN_MESSAGE="Server is stopped!" COPY ./scripts/* /home/steam/server/ diff --git a/scripts/backup.sh b/scripts/backup.sh index 3d96f6c30..6ed249e8f 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash -if [ -n "$DISCORD_PRE_BACKUP_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_BACKUP_JSON & +if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Creating backup..." -l "in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then @@ -19,25 +19,31 @@ if [ "$(id -u)" -eq 0 ]; then chown steam:steam "$FILE_PATH" fi -echo "backup created at ${FILE_PATH}" - -if [ -n "$DISCORD_POST_BACKUP_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_BACKUP_JSON & +echo "Backup created at ${FILE_PATH}" +if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Backup created at ${FILE_PATH}" -l "success" fi if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then - if [ -n "$DISCORD_PRE_BACKUP_DELETE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_BACKUP_DELETE_JSON & - fi + if [ -z "${OLD_BACKUP_DAYS}" ]; then - echo "Unable to deleted old backups, OLD_BACKUP_DAYS is empty." + echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to deleted old backups, OLD_BACKUP_DAYS is empty." -l "warn" + fi elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then - echo "removing backups older than ${OLD_BACKUP_DAYS} days" + echo "Removing backups older than ${OLD_BACKUP_DAYS} days" + if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & + fi find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" + fi else - echo "Unable to deleted old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" - fi - if [ -n "$DISCORD_POST_BACKUP_DELETE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_BACKUP_DELETE_JSON & + echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to deleted old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" + fi fi fi \ No newline at end of file diff --git a/scripts/discord.sh b/scripts/discord.sh index 28b7447de..089b09989 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -3,28 +3,25 @@ # Command usage usage() { cat << EOH -Usage: $0 [OPTION]... -i WEBHOOK_ID -t CONNECT_TIMEOUT -m MAX_TIMEOUT -j JSON -Post a discord message via a discord webhook. By default uses a 30s connect-timeout and 30s max-timeout. Webhook id an json are required to send a discord webhook. A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html +Usage: $0 [OPTION]... -i WEBHOOK_ID -c CONNECT_TIMEOUT -M MAX_TIMEOUT -m MESSAGE -l level +Post a discord message via a discord webhook. Webhook id and message are required to send a discord webhook. By default uses a 30s connect-timeout and 30s max-timeout and level is info. +A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html Package requirement: curl Examples: - $0 -i 01234/56789 -t 30 -m 30 -j {"username":"Palworld","content":"Server starting..."} - $0 --webhook-id 01234/56789 --connect-timeout 30 --max-timeout 30 --json {"username":"Palworld","content":"Server starting..."} + $0 -i 01234/56789 -c 30 -M 30 -m "Server is started!" -l success + $0 --webhook-id 01234/56789 --connect-timeout 30 --max-timeout 30 --message "Server is started!" --level success Options: -i, --webhook-id The unique id that is used by discord to determine what server/channel/thread to post. ex: https://discord.com/api/webhooks/ - -t, --connect-timeout The timeout for connecting to the discord webhook (Default: 30) - -m, --max-timeout The maximum time curl will wait for a response (Default: 30) - -j, --json The json message body sent to the discord webhook + -c, --connect-timeout The timeout for connecting to the discord webhook (Default: 30) + -M, --max-timeout The maximum time curl will wait for a response (Default: 30) + -m, --message The json message body sent to the discord webhook + -l, --level The level affects the color of the embeds sidebar, available choices are: info, in-progress, warn, failure, success (Default: info) -h, --help Display help text and exit EOH } -# DISCORD_WEBHOOK -# DISCORD_USER -# DISCORD_TIMEOUT -# NICE_SHUTDOWN_TIME - # Defaults RED='\033[0;31m' NC='\033[0m' @@ -32,13 +29,12 @@ REQ=2 REQ_FLAG=0 DEFAULT_CONNECT_TIMEOUT=30 DEFAULT_MAX_TIMEOUT=30 - -# # Decimal Colors -# INFO=1127128 # blue -# IN_PROGRESS=15258703 # yellow -# WARN=14177041 # orange -# FAILURE=14614528 # red -# SUCCESS=52224 # green +DEFAULT_LEVEL="info" +DISCORD_BLUE=1127128 +DISCORD_YELLOW=15258703 +DISCORD_ORANGE=14177041 +DISCORD_RED=14614528 +DISCORD_GREEN=52224 # Show usage if no arguments specified if [[ $# -eq 0 ]]; then @@ -58,22 +54,27 @@ while [[ $# -gt 0 ]]; do shift shift ;; - -t|--connect-timeout ) + -c|--connect-timeout ) CONNECT_TIMEOUT="$2" shift shift ;; - -m|--max-timeout ) + -M|--max-timeout ) MAX_TIMEOUT="$2" shift shift ;; - -j|--json ) - JSON="$2" + -m|--message ) + MESSAGE="$2" ((REQ_FLAG++)) shift shift ;; + -l|--level ) + LEVEL="$2" + shift + shift + ;; -h|--help ) usage exit 0 @@ -88,12 +89,12 @@ set -- "${POSITIONAL[@]}" # Check required options if [ $REQ_FLAG -lt $REQ ]; then - printf "%b\n" "${RED}webhook-id and json are required${NC}" + printf "%b\n" "${RED}webhook-id and message are required${NC}" usage exit 1 fi -if [ -n "${$CONNECT_TIMEOUT}" ] && [[ "${CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then +if [ -n "${CONNECT_TIMEOUT}" ] && [[ "${CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT else echo "CONNECT_TIMEOUT is not an integer, using default ${$DEFAULT_CONNECT_TIMEOUT} seconds." @@ -107,7 +108,36 @@ else MAX_TIMEOUT=$DEFAULT_MAX_TIMEOUT fi + +if [ -n "${LEVEL}" ]; then + case $LEVEL in + info ) + COLOR=$DISCORD_BLUE + ;; + in-progress ) + COLOR=$DISCORD_YELLOW + ;; + warn ) + COLOR=$DISCORD_ORANGE + ;; + failure ) + COLOR=$DISCORD_RED + ;; + success ) + COLOR=$DISCORD_GREEN + ;; + * ) + echo "Could not find \"${LEVEL}\", using \"${DEFAULT_LEVEL}\"" + COLOR=$DISCORD_BLUE + ;; + esac +else + COLOR=$DISCORD_BLUE +fi + # Set discord webhook DISCORD_WEBHOOK="https://discord.com/api/webhooks/$WEBHOOK_ID" + +JSON=$(jo embeds[]="$(jo title="$MESSAGE" color=$COLOR)") echo "Sending Discord json: ${JSON}" curl -sfSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$MAX_TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" diff --git a/scripts/init.sh b/scripts/init.sh index a4d01e5ff..b4f6ca101 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,11 +1,11 @@ #!/bin/bash if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then - printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n" + printf "\e[0;32m%s\e[0m\n" "*****EXECUTING USERMOD*****" usermod -o -u "${PUID}" steam groupmod -o -g "${PGID}" steam else - printf "\033[31mRunning as root is not supported, please fix your PUID and PGID!\n" + printf "\033[31m%s\n" "Running as root is not supported, please fix your PUID and PGID!" exit 1 fi @@ -14,19 +14,18 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { - if [ -n "$DISCORD_WEBHOOK_ID" ]; then - su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_SHUTDOWN_JSON" & + if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_SHUTDOWN_MESSAGE}" ]; then + su steam -c "discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m '$DISCORD_PRE_SHUTDOWN_MESSAGE' -l in-progress" & fi + if [ "${RCON_ENABLED,,}" = true ]; then rcon-cli save rcon-cli "shutdown 1" else # Does not save kill -SIGTERM "$(pidof PalServer-Linux-Test)" fi + tail --pid="$killpid" -f 2>/dev/null - if [ -n "$DISCORD_WEBHOOK_ID" ]; then - su steam -c "discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_SHUTDOWN_JSON" & - fi } trap 'term_handler' SIGTERM diff --git a/scripts/start.sh b/scripts/start.sh index 130024a6e..ce145c599 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -57,16 +57,16 @@ isExecutable "/palworld" || exit cd /palworld || exit if [ "${UPDATE_ON_BOOT,,}" = true ]; then - printf "\e[0;32m*****STARTING INSTALL/UPDATE*****\e[0m\n" + printf "\e[0;32m%s\e[0m\n" "*****STARTING INSTALL/UPDATE*****" - if [ -n "$DISCORD_PRE_UPDATE_BOOT_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_UPDATE_BOOT_JSON & + if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_UPDATE_BOOT_MESSAGE" -l "in-progress" & fi /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit - if [ -n "$DISCORD_POST_UPDATE_BOOT_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_UPDATE_BOOT_JSON & + if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_UPDATE_BOOT_MESSAGE" -l "success" & fi fi @@ -95,12 +95,12 @@ if [ "${MULTITHREADING,,}" = true ]; then STARTCOMMAND+=("-useperfthreads" "-NoAsyncLoadingThread" "-UseMultithreadForDS") fi -printf "\e[0;32m*****CHECKING FOR EXISTING CONFIG*****\e[0m\n" +printf "\e[0;32m%s\e[0m\n" "*****CHECKING FOR EXISTING CONFIG*****" # shellcheck disable=SC2143 if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then - printf "\e[0;32m*****GENERATING CONFIG*****\e[0m\n" + printf "\e[0;32m%s\e[0m\n" "*****GENERATING CONFIG*****" # Server will generate all ini files after first run. timeout --preserve-status 15s ./PalServer.sh 1> /dev/null @@ -376,7 +376,6 @@ fi rm -f "/home/steam/server/crontab" if [ "${BACKUP_ENABLED,,}" = true ]; then echo "BACKUP_ENABLED=${BACKUP_ENABLED,,}" - echo "$BACKUP_CRON_EXPRESSION bash /usr/local/bin/backup" >> "/home/steam/server/crontab" fi @@ -402,13 +401,16 @@ default: password: "${ADMIN_PASSWORD}" EOL -printf "\e[0;32m*****STARTING SERVER*****\e[0m\n" -if [ -n "$DISCORD_PRE_START_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_START_JSON & +printf "\e[0;32m%s\e[0m\n" "*****STARTING SERVER*****" +if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_START_MESSAGE}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_START_MESSAGE" -l "success" & fi + echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" -if [ -n "$DISCORD_POST_START_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_START_JSON & + +if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_SHUTDOWN_MESSAGE}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_SHUTDOWN_MESSAGE" -l "failure" fi + exit 0 diff --git a/scripts/update.sh b/scripts/update.sh index 8519e0a5f..449b64032 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,6 +2,9 @@ if [ "${UPDATE_ON_BOOT}" = false ]; then echo "Update on Boot needs to be enabled for auto updating" + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Update on Boot needs to be enabled for auto updating" -l "warn" + fi exit 0 fi @@ -14,30 +17,36 @@ rm "$temp_file" if [ "$http_code" -ne 200 ]; then echo "There was a problem reaching the Steam api. Unable to check for updates!" + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "There was a problem reaching the Steam api. Unable to check for updates!" -l "failure" & + fi exit 1 fi if [ -z "$TARGETBUILD" ]; then echo "The server response does not contain the expected BuildID. Unable to check for updates!" + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The server response does not contain the expected BuildID. Unable to check for updates!" -l "failure" & + fi exit 1 fi if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD." if [ "${RCON_ENABLED,,}" = true ]; then - if [ -n "$DISCORD_PRE_UPDATE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_PRE_UPDATE_JSON & - fi rm /palworld/steamapps/appmanifest_2394010.acf + if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_UPDATE_MESSAGE}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" -l "info" & + fi rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" - if [ -n "$DISCORD_POST_UPDATE_JSON" ]; then - discord -i $DISCORD_WEBHOOK_ID -t $DISCORD_CONNECT_TIMEOUT -m $DISCORD_MAX_TIMEOUT -j $DISCORD_POST_UPDATE_JSON & - fi else echo "An update is available however auto updating without rcon is not supported" + if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_MESSAGE}" ]; then + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "An update is available however auto updating without rcon is not supported" -l "warn" + fi fi else echo "The Server is up to date!" From 896c04103340848c528c9733b879f01dcb5b3ebc Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 04:15:19 -0500 Subject: [PATCH 14/29] updated docs --- README.md | 50 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index ebf5efbb6..9799830ed 100644 --- a/README.md +++ b/README.md @@ -184,12 +184,14 @@ It is highly recommended you set the following environment values before startin | AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-reboots-with-cron) | | AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false | | AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | !0 | -| PRE_INIT_HOOK | You can add a custom sh commands before initializing | | sh command | -| POST_INIT_HOOK | You can add a custom sh commands after initializing | | sh command | -| PRE_BACKUP_HOOK | You can add a custom sh commands before a backup is created | | sh command | -| POST_BACKUP_HOOK | You can add a custom sh commands after a backup is created | | sh command | -| PRE_SHUTDOWN_HOOK | You can add a custom sh commands before pid is killed | | sh command | -| POST_SHUTDOWN_HOOK | You can add a custom sh commands after pid is killed | | sh command | +| DISCORD_WEBHOOK_ID | Discord webhook id found after creating a webhook on a discord server ex: discord.com/api/webhooks/ | 0123456789012345678/xxxxxxxxxxxxxxxxxxxxxx | | +| DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 | +| DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 | +| DISCORD_PRE_UPDATE_BOOT_MESSAGE | Discord message sent when server begins updating | Server is updating... | | +| DISCORD_POST_UPDATE_BOOT_MESSAGE | Discord message sent when server completes updating | Server update complete! | | +| DISCORD_PRE_START_MESSAGE | Discord message sent when server begins to start | Server is started! | | +| DISCORD_PRE_SHUTDOWN_MESSAGE | Discord message sent when server begins to shutdown | Server is shutting down... | | +| DISCORD_POST_SHUTDOWN_MESSAGE | Discord message sent when server has stopped | Server is stopped! | | *highly recommended to set @@ -431,44 +433,24 @@ Please keep in mind that the ENV variables will always overwrite the changes mad For a more detailed list of explanations of server settings go to: [shockbyte](https://shockbyte.com/billing/knowledgebase/1189/How-to-Configure-your-Palworld-server.html) -## Using sh hooks - -### Create a backup - -Backup the server whenever it is gracefully shut down. - -docker run: - -```sh --e POST_SHUTDOWN_HOOK=backup -``` - -docker compose: - -```yaml -- POST_SHUTDOWN_HOOK=backup -``` - -### Send discord webhooks +## Using discord webhooks 1. Generate a webhook url for your discord server in your discord's server settings. -2. You can use the discord webhook in the pre init hook like so: +2. Set the environment variable with the unique token at the end of the discord webhook url example: discord.com/api/webhooks/ -send discord message with docker run: +send discord messages with docker run: ```sh --e DISCORD_WEBHOOK="https://discord.com/api/webhooks/xxxx/xxxxx" \ --e DISCORD_PRE_INIT_MESSAGE="Server initializing" \ --e PRE_INIT_HOOK='curl -sfSL -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$DISCORD_PRE_INIT_MESSAGE\"}" "$DISCORD_WEBHOOK"' +-e DISCORD_WEBHOOK="xxxx/xxxxx" \ +-e DISCORD_PRE_UPDATE_BOOT_MESSAGE="Server is updating..." \ ``` -send discord message with docker compose: +send discord messages with docker compose: ```yaml -- DISCORD_WEBHOOK=https://discord.com/api/webhooks/xxxx/xxxxx -- DISCORD_PRE_INIT_MESSAGE="Server initializing..." -- 'PRE_INIT_HOOK=curl -sfSL -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$$(eval echo $$DISCORD_PRE_INIT_MESSAGE)\"}" $$DISCORD_WEBHOOK' +- DISCORD_WEBHOOK=xxxx/xxxxx +- DISCORD_PRE_UPDATE_BOOT_MESSAGE=Server is updating... ``` ## Reporting Issues/Feature Requests From 0a2ec77caabb67f0c0a66ca09a69bef07f36e021 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 04:20:01 -0500 Subject: [PATCH 15/29] gramma error in backup webhooks --- scripts/backup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 6ed249e8f..6334f3db9 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -29,7 +29,7 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then if [ -z "${OLD_BACKUP_DAYS}" ]; then echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to deleted old backups, OLD_BACKUP_DAYS is empty." -l "warn" + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" fi elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then echo "Removing backups older than ${OLD_BACKUP_DAYS} days" @@ -43,7 +43,7 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then else echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to deleted old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" + discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" fi fi fi \ No newline at end of file From 1ca842d6b77d8e73e53be2b274a83a773e903573 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 04:24:04 -0500 Subject: [PATCH 16/29] fix unintentional indirect expansion syntax --- scripts/discord.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index 089b09989..cea67deef 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -97,7 +97,7 @@ fi if [ -n "${CONNECT_TIMEOUT}" ] && [[ "${CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT else - echo "CONNECT_TIMEOUT is not an integer, using default ${$DEFAULT_CONNECT_TIMEOUT} seconds." + echo "CONNECT_TIMEOUT is not an integer, using default ${DEFAULT_CONNECT_TIMEOUT} seconds." CONNECT_TIMEOUT=$DEFAULT_CONNECT_TIMEOUT fi From 619a1436107317917eb6ca616c44657f66cf49e1 Mon Sep 17 00:00:00 2001 From: Thijs van Loef Date: Mon, 5 Feb 2024 18:50:20 +0100 Subject: [PATCH 17/29] fix linting error --- scripts/backup.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 6334f3db9..fc9b65b28 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Creating backup..." -l "in-progress" & + discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Creating backup..." -l "in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then @@ -21,7 +21,7 @@ fi echo "Backup created at ${FILE_PATH}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Backup created at ${FILE_PATH}" -l "success" + discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Backup created at ${FILE_PATH}" -l "success" fi if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then @@ -29,21 +29,21 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then if [ -z "${OLD_BACKUP_DAYS}" ]; then echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" + discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" fi elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then echo "Removing backups older than ${OLD_BACKUP_DAYS} days" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & + discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & fi find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" + discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" fi else echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" + discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" fi fi fi \ No newline at end of file From 72c61faabc8258870124fe87a4c5dd1f651159a0 Mon Sep 17 00:00:00 2001 From: Thijs van Loef Date: Mon, 5 Feb 2024 18:54:47 +0100 Subject: [PATCH 18/29] move discord from usr/local/bin --- Dockerfile | 13 ++++++------- scripts/backup.sh | 12 ++++++------ scripts/init.sh | 2 +- scripts/start.sh | 8 ++++---- scripts/update.sh | 10 +++++----- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index eddbe4622..97bd59b6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ FROM cm2network/steamcmd:root LABEL maintainer="thijs@loef.dev" \ - name="thijsvanloef/palworld-server-docker" \ - github="https://github.com/thijsvanloef/palworld-server-docker" \ - dockerhub="https://hub.docker.com/r/thijsvanloef/palworld-server-docker" \ - org.opencontainers.image.authors="Thijs van Loef" \ - org.opencontainers.image.source="https://github.com/thijsvanloef/palworld-server-docker" + name="thijsvanloef/palworld-server-docker" \ + github="https://github.com/thijsvanloef/palworld-server-docker" \ + dockerhub="https://hub.docker.com/r/thijsvanloef/palworld-server-docker" \ + org.opencontainers.image.authors="Thijs van Loef" \ + org.opencontainers.image.source="https://github.com/thijsvanloef/palworld-server-docker" # update and install dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -79,8 +79,7 @@ COPY ./scripts/* /home/steam/server/ RUN chmod +x /home/steam/server/*.sh && \ mv /home/steam/server/backup.sh /usr/local/bin/backup && \ mv /home/steam/server/update.sh /usr/local/bin/update && \ - mv /home/steam/server/restore.sh /usr/local/bin/restore && \ - mv /home/steam/server/discord.sh /usr/local/bin/discord + mv /home/steam/server/restore.sh /usr/local/bin/restore WORKDIR /home/steam/server diff --git a/scripts/backup.sh b/scripts/backup.sh index fc9b65b28..04b4bed73 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Creating backup..." -l "in-progress" & + /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Creating backup..." -l "in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then @@ -21,7 +21,7 @@ fi echo "Backup created at ${FILE_PATH}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Backup created at ${FILE_PATH}" -l "success" + /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Backup created at ${FILE_PATH}" -l "success" fi if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then @@ -29,21 +29,21 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then if [ -z "${OLD_BACKUP_DAYS}" ]; then echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" + /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" fi elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then echo "Removing backups older than ${OLD_BACKUP_DAYS} days" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then - discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & + /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & fi find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" + /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" fi else echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" + /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" fi fi fi \ No newline at end of file diff --git a/scripts/init.sh b/scripts/init.sh index b4f6ca101..5d827d196 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -15,7 +15,7 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_SHUTDOWN_MESSAGE}" ]; then - su steam -c "discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m '$DISCORD_PRE_SHUTDOWN_MESSAGE' -l in-progress" & + su steam -c "/home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m '$DISCORD_PRE_SHUTDOWN_MESSAGE' -l in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then diff --git a/scripts/start.sh b/scripts/start.sh index ce145c599..6fac4883a 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -60,13 +60,13 @@ if [ "${UPDATE_ON_BOOT,,}" = true ]; then printf "\e[0;32m%s\e[0m\n" "*****STARTING INSTALL/UPDATE*****" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_UPDATE_BOOT_MESSAGE" -l "in-progress" & + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_UPDATE_BOOT_MESSAGE" -l "in-progress" & fi /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_UPDATE_BOOT_MESSAGE" -l "success" & + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_UPDATE_BOOT_MESSAGE" -l "success" & fi fi @@ -403,14 +403,14 @@ EOL printf "\e[0;32m%s\e[0m\n" "*****STARTING SERVER*****" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_START_MESSAGE}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_START_MESSAGE" -l "success" & + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_START_MESSAGE" -l "success" & fi echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_SHUTDOWN_MESSAGE}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_SHUTDOWN_MESSAGE" -l "failure" + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_SHUTDOWN_MESSAGE" -l "failure" fi exit 0 diff --git a/scripts/update.sh b/scripts/update.sh index 449b64032..12d0741de 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -3,7 +3,7 @@ if [ "${UPDATE_ON_BOOT}" = false ]; then echo "Update on Boot needs to be enabled for auto updating" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Update on Boot needs to be enabled for auto updating" -l "warn" + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Update on Boot needs to be enabled for auto updating" -l "warn" fi exit 0 fi @@ -18,7 +18,7 @@ rm "$temp_file" if [ "$http_code" -ne 200 ]; then echo "There was a problem reaching the Steam api. Unable to check for updates!" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "There was a problem reaching the Steam api. Unable to check for updates!" -l "failure" & + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "There was a problem reaching the Steam api. Unable to check for updates!" -l "failure" & fi exit 1 fi @@ -26,7 +26,7 @@ fi if [ -z "$TARGETBUILD" ]; then echo "The server response does not contain the expected BuildID. Unable to check for updates!" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The server response does not contain the expected BuildID. Unable to check for updates!" -l "failure" & + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The server response does not contain the expected BuildID. Unable to check for updates!" -l "failure" & fi exit 1 fi @@ -36,7 +36,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then if [ "${RCON_ENABLED,,}" = true ]; then rm /palworld/steamapps/appmanifest_2394010.acf if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_UPDATE_MESSAGE}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" -l "info" & + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" -l "info" & fi rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" @@ -45,7 +45,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then else echo "An update is available however auto updating without rcon is not supported" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_MESSAGE}" ]; then - discord -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "An update is available however auto updating without rcon is not supported" -l "warn" + /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "An update is available however auto updating without rcon is not supported" -l "warn" fi fi else From 4464ba08d979db2f062c652ea4c08d9980cc99af Mon Sep 17 00:00:00 2001 From: Thijs van Loef Date: Mon, 5 Feb 2024 18:59:14 +0100 Subject: [PATCH 19/29] fix some more linting --- scripts/backup.sh | 12 ++++++------ scripts/init.sh | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 04b4bed73..30eaed7c7 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Creating backup..." -l "in-progress" & + /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Creating backup..." -l "in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then @@ -21,7 +21,7 @@ fi echo "Backup created at ${FILE_PATH}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Backup created at ${FILE_PATH}" -l "success" + /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Backup created at ${FILE_PATH}" -l "success" fi if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then @@ -29,21 +29,21 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then if [ -z "${OLD_BACKUP_DAYS}" ]; then echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" + /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" fi elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then echo "Removing backups older than ${OLD_BACKUP_DAYS} days" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then - /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & + /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & fi find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" + /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" fi else echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "$DISCORD_WEBHOOK_ID" -c "$DISCORD_CONNECT_TIMEOUT" -M "$DISCORD_MAX_TIMEOUT" -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" + /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" fi fi fi \ No newline at end of file diff --git a/scripts/init.sh b/scripts/init.sh index 5d827d196..6642063ec 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -15,7 +15,7 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_SHUTDOWN_MESSAGE}" ]; then - su steam -c "/home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m '$DISCORD_PRE_SHUTDOWN_MESSAGE' -l in-progress" & + su steam -c "/home/steam/server/discord.sh -i ${DISCORD_WEBHOOK_ID} -c ${DISCORD_CONNECT_TIMEOUT} -M ${DISCORD_MAX_TIMEOUT} -m '${DISCORD_PRE_SHUTDOWN_MESSAGE}' -l in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then From 34470e650b0ddeb96523644700ab76fe124f874c Mon Sep 17 00:00:00 2001 From: Thijs van Loef Date: Mon, 5 Feb 2024 19:00:18 +0100 Subject: [PATCH 20/29] revert printf --- scripts/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/init.sh b/scripts/init.sh index 6642063ec..0f7a7b671 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,7 +1,7 @@ #!/bin/bash if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then - printf "\e[0;32m%s\e[0m\n" "*****EXECUTING USERMOD*****" + printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n" usermod -o -u "${PUID}" steam groupmod -o -g "${PGID}" steam else From 21d7fec00f97a2a40c4e8e4bca74b9a98a5d5ebf Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 15:07:51 -0500 Subject: [PATCH 21/29] updated hooks to use less args, use webhook url var, default webhook url empty. --- Dockerfile | 1 + README.md | 2 +- scripts/backup.sh | 12 +++---- scripts/discord.sh | 90 ++-------------------------------------------- scripts/init.sh | 2 +- scripts/start.sh | 8 ++--- scripts/update.sh | 14 ++++---- 7 files changed, 23 insertions(+), 106 deletions(-) diff --git a/Dockerfile b/Dockerfile index 97bd59b6c..17a9f3296 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,6 +66,7 @@ ENV PORT= \ AUTO_REBOOT_ENABLED=false \ AUTO_REBOOT_WARN_MINUTES=5 \ AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" \ + DISCORD_WEBHOOK_URL= \ DISCORD_CONNECT_TIMEOUT=30 \ DISCORD_MAX_TIMEOUT=30 \ DISCORD_PRE_UPDATE_BOOT_MESSAGE="Server is updating..." \ diff --git a/README.md b/README.md index 9799830ed..bbaecb2f1 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ It is highly recommended you set the following environment values before startin | AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-reboots-with-cron) | | AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false | | AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | !0 | -| DISCORD_WEBHOOK_ID | Discord webhook id found after creating a webhook on a discord server ex: discord.com/api/webhooks/ | 0123456789012345678/xxxxxxxxxxxxxxxxxxxxxx | | +| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | https://discord.com/api/webhooks/ | | | DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 | | DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 | | DISCORD_PRE_UPDATE_BOOT_MESSAGE | Discord message sent when server begins updating | Server is updating... | | diff --git a/scripts/backup.sh b/scripts/backup.sh index 30eaed7c7..ef63b92ee 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Creating backup..." -l "in-progress" & + /home/steam/server/discord.sh "Creating backup..." "in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then @@ -21,7 +21,7 @@ fi echo "Backup created at ${FILE_PATH}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Backup created at ${FILE_PATH}" -l "success" + /home/steam/server/discord.sh "Backup created at ${FILE_PATH}" "success" fi if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then @@ -29,21 +29,21 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then if [ -z "${OLD_BACKUP_DAYS}" ]; then echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Unable to delete old backups, OLD_BACKUP_DAYS is empty." -l "warn" + /home/steam/server/discord.sh "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn" fi elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then echo "Removing backups older than ${OLD_BACKUP_DAYS} days" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then - /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Removing backups older than ${OLD_BACKUP_DAYS} days..." -l "in-progress" & + /home/steam/server/discord.sh "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress" & fi find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Removed backups older than ${OLD_BACKUP_DAYS} days" -l "success" + /home/steam/server/discord.sh "Removed backups older than ${OLD_BACKUP_DAYS} days" "success" fi else echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i "{$DISCORD_WEBHOOK_ID}" -c "{$DISCORD_CONNECT_TIMEOUT}" -M "{$DISCORD_MAX_TIMEOUT}" -m "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -l "failure" + /home/steam/server/discord.sh "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure" fi fi fi \ No newline at end of file diff --git a/scripts/discord.sh b/scripts/discord.sh index cea67deef..859d6614c 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -1,32 +1,6 @@ #!/bin/bash -# Command usage -usage() { -cat << EOH -Usage: $0 [OPTION]... -i WEBHOOK_ID -c CONNECT_TIMEOUT -M MAX_TIMEOUT -m MESSAGE -l level -Post a discord message via a discord webhook. Webhook id and message are required to send a discord webhook. By default uses a 30s connect-timeout and 30s max-timeout and level is info. -A good example for discord json formatting is located here: https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html -Package requirement: curl - -Examples: - $0 -i 01234/56789 -c 30 -M 30 -m "Server is started!" -l success - $0 --webhook-id 01234/56789 --connect-timeout 30 --max-timeout 30 --message "Server is started!" --level success - -Options: - -i, --webhook-id The unique id that is used by discord to determine what server/channel/thread to post. ex: https://discord.com/api/webhooks/ - -c, --connect-timeout The timeout for connecting to the discord webhook (Default: 30) - -M, --max-timeout The maximum time curl will wait for a response (Default: 30) - -m, --message The json message body sent to the discord webhook - -l, --level The level affects the color of the embeds sidebar, available choices are: info, in-progress, warn, failure, success (Default: info) - -h, --help Display help text and exit -EOH -} - # Defaults -RED='\033[0;31m' -NC='\033[0m' -REQ=2 -REQ_FLAG=0 DEFAULT_CONNECT_TIMEOUT=30 DEFAULT_MAX_TIMEOUT=30 DEFAULT_LEVEL="info" @@ -36,63 +10,9 @@ DISCORD_ORANGE=14177041 DISCORD_RED=14614528 DISCORD_GREEN=52224 -# Show usage if no arguments specified -if [[ $# -eq 0 ]]; then - usage - exit 0 -fi - # Parse arguments -POSITIONAL=() -while [[ $# -gt 0 ]]; do - key="$1" - - case $key in - -i|--webhook-id ) - WEBHOOK_ID="$2" - ((REQ_FLAG++)) - shift - shift - ;; - -c|--connect-timeout ) - CONNECT_TIMEOUT="$2" - shift - shift - ;; - -M|--max-timeout ) - MAX_TIMEOUT="$2" - shift - shift - ;; - -m|--message ) - MESSAGE="$2" - ((REQ_FLAG++)) - shift - shift - ;; - -l|--level ) - LEVEL="$2" - shift - shift - ;; - -h|--help ) - usage - exit 0 - ;; - * ) - POSITIONAL+=("$1") - shift - ;; - esac -done -set -- "${POSITIONAL[@]}" - -# Check required options -if [ $REQ_FLAG -lt $REQ ]; then - printf "%b\n" "${RED}webhook-id and message are required${NC}" - usage - exit 1 -fi +MESSAGE=$1 +LEVEL=$2 if [ -n "${CONNECT_TIMEOUT}" ] && [[ "${CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT @@ -108,7 +28,6 @@ else MAX_TIMEOUT=$DEFAULT_MAX_TIMEOUT fi - if [ -n "${LEVEL}" ]; then case $LEVEL in info ) @@ -135,9 +54,6 @@ else COLOR=$DISCORD_BLUE fi -# Set discord webhook -DISCORD_WEBHOOK="https://discord.com/api/webhooks/$WEBHOOK_ID" - JSON=$(jo embeds[]="$(jo title="$MESSAGE" color=$COLOR)") echo "Sending Discord json: ${JSON}" -curl -sfSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$MAX_TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" +curl -sfSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$MAX_TIMEOUT" -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK_URL" diff --git a/scripts/init.sh b/scripts/init.sh index 0f7a7b671..7c6b1712f 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -15,7 +15,7 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_SHUTDOWN_MESSAGE}" ]; then - su steam -c "/home/steam/server/discord.sh -i ${DISCORD_WEBHOOK_ID} -c ${DISCORD_CONNECT_TIMEOUT} -M ${DISCORD_MAX_TIMEOUT} -m '${DISCORD_PRE_SHUTDOWN_MESSAGE}' -l in-progress" & + su steam -c "/home/steam/server/discord.sh '${DISCORD_PRE_SHUTDOWN_MESSAGE}' in-progress" & fi if [ "${RCON_ENABLED,,}" = true ]; then diff --git a/scripts/start.sh b/scripts/start.sh index 6fac4883a..99c409e52 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -60,13 +60,13 @@ if [ "${UPDATE_ON_BOOT,,}" = true ]; then printf "\e[0;32m%s\e[0m\n" "*****STARTING INSTALL/UPDATE*****" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_UPDATE_BOOT_MESSAGE" -l "in-progress" & + /home/steam/server/discord.sh "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" & fi /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_UPDATE_BOOT_MESSAGE" -l "success" & + /home/steam/server/discord.sh "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" & fi fi @@ -403,14 +403,14 @@ EOL printf "\e[0;32m%s\e[0m\n" "*****STARTING SERVER*****" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_START_MESSAGE}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_PRE_START_MESSAGE" -l "success" & + /home/steam/server/discord.sh "${DISCORD_PRE_START_MESSAGE}" "success" & fi echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_SHUTDOWN_MESSAGE}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "$DISCORD_POST_SHUTDOWN_MESSAGE" -l "failure" + /home/steam/server/discord.sh "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure" fi exit 0 diff --git a/scripts/update.sh b/scripts/update.sh index 12d0741de..3395af850 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -3,7 +3,7 @@ if [ "${UPDATE_ON_BOOT}" = false ]; then echo "Update on Boot needs to be enabled for auto updating" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "Update on Boot needs to be enabled for auto updating" -l "warn" + /home/steam/server/discord.sh "Update on Boot needs to be enabled for auto updating" "warn" fi exit 0 fi @@ -18,7 +18,7 @@ rm "$temp_file" if [ "$http_code" -ne 200 ]; then echo "There was a problem reaching the Steam api. Unable to check for updates!" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "There was a problem reaching the Steam api. Unable to check for updates!" -l "failure" & + /home/steam/server/discord.sh "There was a problem reaching the Steam api. Unable to check for updates!" "failure" & fi exit 1 fi @@ -26,7 +26,7 @@ fi if [ -z "$TARGETBUILD" ]; then echo "The server response does not contain the expected BuildID. Unable to check for updates!" if [ -n "${DISCORD_WEBHOOK_ID}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The server response does not contain the expected BuildID. Unable to check for updates!" -l "failure" & + /home/steam/server/discord.sh "The server response does not contain the expected BuildID. Unable to check for updates!" "failure" & fi exit 1 fi @@ -35,8 +35,8 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD." if [ "${RCON_ENABLED,,}" = true ]; then rm /palworld/steamapps/appmanifest_2394010.acf - if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_UPDATE_MESSAGE}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "The Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" -l "info" & + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + /home/steam/server/discord.sh "The Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" @@ -44,8 +44,8 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else echo "An update is available however auto updating without rcon is not supported" - if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_MESSAGE}" ]; then - /home/steam/server/discord.sh -i $DISCORD_WEBHOOK_ID -c $DISCORD_CONNECT_TIMEOUT -M $DISCORD_MAX_TIMEOUT -m "An update is available however auto updating without rcon is not supported" -l "warn" + if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + /home/steam/server/discord.sh "An update is available however auto updating without rcon is not supported" "warn" fi fi else From 14e25710da58c9f1c1d69c577a66fdd7f0c0cbc3 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 15:39:30 -0500 Subject: [PATCH 22/29] dont set discord update status to run in background --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index 99c409e52..0149bdd07 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -66,7 +66,7 @@ if [ "${UPDATE_ON_BOOT,,}" = true ]; then /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" ]; then - /home/steam/server/discord.sh "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" & + /home/steam/server/discord.sh "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" fi fi From 5dc02348bc8c0391dab7ecd19cf2b16c8765b54e Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 15:57:46 -0500 Subject: [PATCH 23/29] no bare url in md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bbaecb2f1..fed5e2dae 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ It is highly recommended you set the following environment values before startin | AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-reboots-with-cron) | | AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false | | AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | !0 | -| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | https://discord.com/api/webhooks/ | | +| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | `https://discord.com/api/webhooks/` | | | DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 | | DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 | | DISCORD_PRE_UPDATE_BOOT_MESSAGE | Discord message sent when server begins updating | Server is updating... | | From 2b647ce270d55d76c24c85dda835252e49218c81 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 15:59:18 -0500 Subject: [PATCH 24/29] url is in wrong position in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fed5e2dae..d93e59eed 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ It is highly recommended you set the following environment values before startin | AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-reboots-with-cron) | | AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false | | AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | !0 | -| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | `https://discord.com/api/webhooks/` | | +| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | | `https://discord.com/api/webhooks/` | | DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 | | DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 | | DISCORD_PRE_UPDATE_BOOT_MESSAGE | Discord message sent when server begins updating | Server is updating... | | From 4126e261521f379c16471ffa32a08e1fa06797ab Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 16:00:26 -0500 Subject: [PATCH 25/29] added allowed vals for discord msgs --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d93e59eed..afd66514a 100644 --- a/README.md +++ b/README.md @@ -187,11 +187,11 @@ It is highly recommended you set the following environment values before startin | DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | | `https://discord.com/api/webhooks/` | | DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 | | DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 | -| DISCORD_PRE_UPDATE_BOOT_MESSAGE | Discord message sent when server begins updating | Server is updating... | | -| DISCORD_POST_UPDATE_BOOT_MESSAGE | Discord message sent when server completes updating | Server update complete! | | -| DISCORD_PRE_START_MESSAGE | Discord message sent when server begins to start | Server is started! | | -| DISCORD_PRE_SHUTDOWN_MESSAGE | Discord message sent when server begins to shutdown | Server is shutting down... | | -| DISCORD_POST_SHUTDOWN_MESSAGE | Discord message sent when server has stopped | Server is stopped! | | +| DISCORD_PRE_UPDATE_BOOT_MESSAGE | Discord message sent when server begins updating | Server is updating... | "string" | +| DISCORD_POST_UPDATE_BOOT_MESSAGE | Discord message sent when server completes updating | Server update complete! | "string" | +| DISCORD_PRE_START_MESSAGE | Discord message sent when server begins to start | Server is started! | "string" | +| DISCORD_PRE_SHUTDOWN_MESSAGE | Discord message sent when server begins to shutdown | Server is shutting down... | "string" | +| DISCORD_POST_SHUTDOWN_MESSAGE | Discord message sent when server has stopped | Server is stopped! | "string" | *highly recommended to set From 5d2d591fb0db884fdb01a9b3c848d3a16b3c1b4c Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 16:07:52 -0500 Subject: [PATCH 26/29] check for new URL var instead of ID --- scripts/backup.sh | 12 ++++++------ scripts/init.sh | 2 +- scripts/start.sh | 8 ++++---- scripts/update.sh | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index ef63b92ee..c82909e5a 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ -n "${DISCORD_WEBHOOK_ID}" ]; then +if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Creating backup..." "in-progress" & fi @@ -20,7 +20,7 @@ if [ "$(id -u)" -eq 0 ]; then fi echo "Backup created at ${FILE_PATH}" -if [ -n "${DISCORD_WEBHOOK_ID}" ]; then +if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Backup created at ${FILE_PATH}" "success" fi @@ -28,21 +28,21 @@ if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then if [ -z "${OLD_BACKUP_DAYS}" ]; then echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn" fi elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then echo "Removing backups older than ${OLD_BACKUP_DAYS} days" - if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then /home/steam/server/discord.sh "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress" & fi find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Removed backups older than ${OLD_BACKUP_DAYS} days" "success" fi else echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure" fi fi diff --git a/scripts/init.sh b/scripts/init.sh index 7c6b1712f..35ee2253a 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -14,7 +14,7 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { - if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_SHUTDOWN_MESSAGE}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_SHUTDOWN_MESSAGE}" ]; then su steam -c "/home/steam/server/discord.sh '${DISCORD_PRE_SHUTDOWN_MESSAGE}' in-progress" & fi diff --git a/scripts/start.sh b/scripts/start.sh index 0149bdd07..ad7ab56c2 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -59,13 +59,13 @@ cd /palworld || exit if [ "${UPDATE_ON_BOOT,,}" = true ]; then printf "\e[0;32m%s\e[0m\n" "*****STARTING INSTALL/UPDATE*****" - if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" ]; then /home/steam/server/discord.sh "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" & fi /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit - if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" ]; then /home/steam/server/discord.sh "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" fi fi @@ -402,14 +402,14 @@ default: EOL printf "\e[0;32m%s\e[0m\n" "*****STARTING SERVER*****" -if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_PRE_START_MESSAGE}" ]; then +if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_START_MESSAGE}" ]; then /home/steam/server/discord.sh "${DISCORD_PRE_START_MESSAGE}" "success" & fi echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" -if [ -n "${DISCORD_WEBHOOK_ID}" ] && [ -n "${DISCORD_POST_SHUTDOWN_MESSAGE}" ]; then +if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_POST_SHUTDOWN_MESSAGE}" ]; then /home/steam/server/discord.sh "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure" fi diff --git a/scripts/update.sh b/scripts/update.sh index 3395af850..25adec174 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,7 +2,7 @@ if [ "${UPDATE_ON_BOOT}" = false ]; then echo "Update on Boot needs to be enabled for auto updating" - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Update on Boot needs to be enabled for auto updating" "warn" fi exit 0 @@ -17,7 +17,7 @@ rm "$temp_file" if [ "$http_code" -ne 200 ]; then echo "There was a problem reaching the Steam api. Unable to check for updates!" - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "There was a problem reaching the Steam api. Unable to check for updates!" "failure" & fi exit 1 @@ -25,7 +25,7 @@ fi if [ -z "$TARGETBUILD" ]; then echo "The server response does not contain the expected BuildID. Unable to check for updates!" - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "The server response does not contain the expected BuildID. Unable to check for updates!" "failure" & fi exit 1 @@ -35,7 +35,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD." if [ "${RCON_ENABLED,,}" = true ]; then rm /palworld/steamapps/appmanifest_2394010.acf - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "The Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" @@ -44,7 +44,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else echo "An update is available however auto updating without rcon is not supported" - if [ -n "${DISCORD_WEBHOOK_ID}" ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "An update is available however auto updating without rcon is not supported" "warn" fi fi From 956f4add9ca5ffb565e5ab34ae10c245bbc12a85 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 16:28:31 -0500 Subject: [PATCH 27/29] resolve connect-timeout and max-timeout not an integer logs --- scripts/discord.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/discord.sh b/scripts/discord.sh index 859d6614c..6cae70147 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -14,14 +14,14 @@ DISCORD_GREEN=52224 MESSAGE=$1 LEVEL=$2 -if [ -n "${CONNECT_TIMEOUT}" ] && [[ "${CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then +if [ -n "${DISCORD_CONNECT_TIMEOUT}" ] && [[ "${DISCORD_CONNECT_TIMEOUT}" =~ ^[0-9]+$ ]]; then CONNECT_TIMEOUT=$DISCORD_CONNECT_TIMEOUT else echo "CONNECT_TIMEOUT is not an integer, using default ${DEFAULT_CONNECT_TIMEOUT} seconds." CONNECT_TIMEOUT=$DEFAULT_CONNECT_TIMEOUT fi -if [ -n "${MAX_TIMEOUT}" ] && [[ "${MAX_TIMEOUT}" =~ ^[0-9]+$ ]]; then +if [ -n "${DISCORD_MAX_TIMEOUT}" ] && [[ "${DISCORD_MAX_TIMEOUT}" =~ ^[0-9]+$ ]]; then MAX_TIMEOUT=$DISCORD_MAX_TIMEOUT else echo "MAX_TIMEOUT is not an integer, using default ${DEFAULT_MAX_TIMEOUT} seconds." From 56f20b7712287ad9751f62011582cfc44640dd45 Mon Sep 17 00:00:00 2001 From: Bryan Zick Date: Mon, 5 Feb 2024 20:07:34 -0500 Subject: [PATCH 28/29] remove "The" as other messages do not include it. --- scripts/update.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 25adec174..614597a74 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -26,7 +26,7 @@ fi if [ -z "$TARGETBUILD" ]; then echo "The server response does not contain the expected BuildID. Unable to check for updates!" if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "The server response does not contain the expected BuildID. Unable to check for updates!" "failure" & + /home/steam/server/discord.sh "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure" & fi exit 1 fi @@ -36,7 +36,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then if [ "${RCON_ENABLED,,}" = true ]; then rm /palworld/steamapps/appmanifest_2394010.acf if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "The Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & + /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" From 587b346190d80421cbd101916193aba705573449 Mon Sep 17 00:00:00 2001 From: Thijs van Loef Date: Tue, 6 Feb 2024 12:12:48 +0100 Subject: [PATCH 29/29] change text --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 17a9f3296..6a6885829 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,9 +71,9 @@ ENV PORT= \ DISCORD_MAX_TIMEOUT=30 \ DISCORD_PRE_UPDATE_BOOT_MESSAGE="Server is updating..." \ DISCORD_POST_UPDATE_BOOT_MESSAGE="Server update complete!" \ - DISCORD_PRE_START_MESSAGE="Server is started!" \ + DISCORD_PRE_START_MESSAGE="Server has been started!" \ DISCORD_PRE_SHUTDOWN_MESSAGE="Server is shutting down..." \ - DISCORD_POST_SHUTDOWN_MESSAGE="Server is stopped!" + DISCORD_POST_SHUTDOWN_MESSAGE="Server has been stopped!" COPY ./scripts/* /home/steam/server/