From fdfffc47d8aac67864ead6c2a89ef5967ab86e31 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 19:49:43 -0500 Subject: [PATCH 1/9] Minimized processes running as root. --- Dockerfile | 7 ++++--- scripts/backup.sh | 4 ++++ scripts/init.sh | 10 +++------- scripts/start.sh | 7 ++++++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 137cf38b2..363306a55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN wget -q https://github.com/gorcon/rcon-cli/releases/download/v0.10.3/rcon-0.10.3-amd64_linux.tar.gz -O - | tar -xz && \ - mv rcon-0.10.3-amd64_linux/rcon /usr/bin/rcon-cli + mv rcon-0.10.3-amd64_linux/rcon /usr/bin/rcon-cli && \ + ln -s /home/steam/server/rcon.yaml /root/rcon.yaml ENV PORT= \ PUID=1000 \ @@ -31,8 +32,8 @@ ENV PORT= \ SERVER_DESCRIPTION= COPY ./scripts/* /home/steam/server/ -RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh && \ - mv /home/steam/server/backup.sh /usr/local/bin/backup +RUN chmod u+x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh && \ + ln -s /home/steam/server/backup.sh /usr/local/bin/backup WORKDIR /home/steam/server diff --git a/scripts/backup.sh b/scripts/backup.sh index 82e75eb19..61911be2a 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -9,4 +9,8 @@ FILE_PATH="/palworld/backups/palworld-save-${DATE}.tar.gz" cd /palworld/Pal/ || exit tar -zcf "$FILE_PATH" "Saved/" + +if [ $(id -u) -eq 0 ]; then + chown steam:steam "$FILE_PATH" +fi echo "backup created at $FILE_PATH" diff --git a/scripts/init.sh b/scripts/init.sh index bbf91a455..24c3fac10 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -10,12 +10,7 @@ else fi mkdir -p /palworld/backups -chown -R steam:steam /palworld - -if [ "${UPDATE_ON_BOOT}" = true ]; then - printf "\e[0;32m*****STARTING INSTALL/UPDATE*****\e[0m\n" - su steam -c '/home/steam/steamcmd/steamcmd.sh +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit' -fi +chown -R steam:steam /palworld /home/steam/ term_handler() { if [ "${RCON_ENABLED}" = true ]; then @@ -29,6 +24,7 @@ term_handler() { trap 'term_handler' SIGTERM -./start.sh & +su steam -c ./start.sh & +# Process ID of su killpid="$!" wait $killpid diff --git a/scripts/start.sh b/scripts/start.sh index 2d83c36f4..bef212fe1 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [ "${UPDATE_ON_BOOT}" = true ]; then + printf "\e[0;32m*****STARTING INSTALL/UPDATE*****\e[0m\n" + /home/steam/steamcmd/steamcmd.sh +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit +fi + STARTCOMMAND=("./PalServer.sh") if [ -n "${PORT}" ]; then @@ -81,5 +86,5 @@ EOL printf "\e[0;32m*****STARTING SERVER*****\e[0m\n" echo "bash -c '${STARTCOMMAND[*]}'" -su steam -c "bash -c '${STARTCOMMAND[*]}'" +"${STARTCOMMAND[@]}" From 763c06774a3c700131a028d725535caf13aad6af Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 23:01:33 -0500 Subject: [PATCH 2/9] Removed su in start.sh --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index bef212fe1..6ee233a29 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -61,7 +61,7 @@ if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorld printf "\e[0;32m*****GENERATING CONFIG*****\e[0m\n" # Server will generate all ini files after first run. - su steam -c "timeout --preserve-status 15s ./PalServer.sh 1> /dev/null " + timeout --preserve-status 15s ./PalServer.sh 1> /dev/null # Wait for shutdown sleep 5 From e8089b8f3cfa958c2cea8a2f06c51f974cb20b3f Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 21:34:20 -0500 Subject: [PATCH 3/9] Removed directory to remove error. --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 363306a55..e9a853ac3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN wget -q https://github.com/gorcon/rcon-cli/releases/download/v0.10.3/rcon-0.10.3-amd64_linux.tar.gz -O - | tar -xz && \ mv rcon-0.10.3-amd64_linux/rcon /usr/bin/rcon-cli && \ - ln -s /home/steam/server/rcon.yaml /root/rcon.yaml + ln -s /home/steam/server/rcon.yaml /root/rcon.yaml && \ + rmdir /tmp/dumps ENV PORT= \ PUID=1000 \ From ac382af05703636e0c3caf8eb57f6889830a7d16 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 21:40:08 -0500 Subject: [PATCH 4/9] Added quotes --- scripts/backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 61911be2a..bf797b7ec 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -10,7 +10,7 @@ cd /palworld/Pal/ || exit tar -zcf "$FILE_PATH" "Saved/" -if [ $(id -u) -eq 0 ]; then +if [ "$(id -u)" -eq 0 ]; then chown steam:steam "$FILE_PATH" fi echo "backup created at $FILE_PATH" From d93330e1d710f7656938b436e4cecb1041dec609 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 21:47:25 -0500 Subject: [PATCH 5/9] Removed symbolic links --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e9a853ac3..5fd8106f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN wget -q https://github.com/gorcon/rcon-cli/releases/download/v0.10.3/rcon-0.10.3-amd64_linux.tar.gz -O - | tar -xz && \ mv rcon-0.10.3-amd64_linux/rcon /usr/bin/rcon-cli && \ - ln -s /home/steam/server/rcon.yaml /root/rcon.yaml && \ rmdir /tmp/dumps ENV PORT= \ @@ -33,8 +32,8 @@ ENV PORT= \ SERVER_DESCRIPTION= COPY ./scripts/* /home/steam/server/ -RUN chmod u+x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh && \ - ln -s /home/steam/server/backup.sh /usr/local/bin/backup +RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh && \ + mv /home/steam/server/backup.sh /usr/local/bin/backup WORKDIR /home/steam/server From f1d1ade290ba9e4788ab175fae6eba8a9edc128b Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 21:48:13 -0500 Subject: [PATCH 6/9] Added spacing --- scripts/backup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/backup.sh b/scripts/backup.sh index bf797b7ec..43eecb460 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -13,4 +13,5 @@ tar -zcf "$FILE_PATH" "Saved/" if [ "$(id -u)" -eq 0 ]; then chown steam:steam "$FILE_PATH" fi + echo "backup created at $FILE_PATH" From 6330c86fe9aba07e1eef83796528333ae1a209d0 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 22:08:54 -0500 Subject: [PATCH 7/9] Replaced * with @ to match --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index 6ee233a29..5bc03915d 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -85,6 +85,6 @@ default: EOL printf "\e[0;32m*****STARTING SERVER*****\e[0m\n" -echo "bash -c '${STARTCOMMAND[*]}'" +echo "bash -c '${STARTCOMMAND[@]}'" "${STARTCOMMAND[@]}" From e0d4e6c48f17a603ce4b2b39f0c8e8a2acefc48f Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 22:17:48 -0500 Subject: [PATCH 8/9] Changed back to [*] --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index 5bc03915d..6ee233a29 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -85,6 +85,6 @@ default: EOL printf "\e[0;32m*****STARTING SERVER*****\e[0m\n" -echo "bash -c '${STARTCOMMAND[@]}'" +echo "bash -c '${STARTCOMMAND[*]}'" "${STARTCOMMAND[@]}" From 9de1b91cc7e2b5db97df3412adc1cc007699df3e Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 27 Jan 2024 23:52:10 -0500 Subject: [PATCH 9/9] Updated echo for start command to reflect what is being executed. --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index 6ee233a29..c60c58b4f 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -85,6 +85,6 @@ default: EOL printf "\e[0;32m*****STARTING SERVER*****\e[0m\n" -echo "bash -c '${STARTCOMMAND[*]}'" +echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}"