From 196b0d1e89848789a993a625c87268dab0f0fb9d Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Thu, 2 Mar 2023 15:05:48 -0800 Subject: [PATCH] Move shared functions to importable file. Fix combination boolean logic. --- Dockerfile | 2 ++ run.sh | 12 ++++-------- shared.sh | 8 ++++++++ user-space.sh | 6 ++---- 4 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 shared.sh diff --git a/Dockerfile b/Dockerfile index 3cfe061..6f92f75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,6 +64,8 @@ RUN mkdir -p /ark \ COPY crontab /home/steam/crontab # Add run and user scripts +COPY shared.sh /shared.sh +RUN chmod +x /shared.sh COPY run.sh /run.sh RUN chmod +x /run.sh COPY user-space.sh /user-space.sh diff --git a/run.sh b/run.sh index e0b6140..6fc9f84 100644 --- a/run.sh +++ b/run.sh @@ -1,12 +1,6 @@ #!/usr/bin/env bash -function log { echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } -function warn { >&2 echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } - -function error { - log "!!! $1" - exit 1 -} +. /shared.sh function stop { if [ ${BACKUPONSTOP} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks)" ]; then @@ -98,7 +92,9 @@ verify_dir /etc/arkmanager verify_dir /home/steam # Create custom config if not set, use custom config -[ ! -f /ark/arkmanager.cfg ] && su steam -c "cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg" || warn "Could not save default config file." +if [ ! -f /ark/arkmanager.cfg ]; then + su steam -c "cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg" || warn "Could not save default config file." +fi su steam -c "cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg" || warn "Could not save main instance config file." ######################## diff --git a/shared.sh b/shared.sh new file mode 100644 index 0000000..33d6982 --- /dev/null +++ b/shared.sh @@ -0,0 +1,8 @@ + +function log { echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } +function warn { >&2 echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } + +function error { + log "!!! $1" + exit 1 +} diff --git a/user-space.sh b/user-space.sh index fba6072..137cc86 100644 --- a/user-space.sh +++ b/user-space.sh @@ -1,11 +1,9 @@ +#!/usr/bin/env bash -# Create custom config if not set, use custom config -[ ! -f /ark/arkmanager.cfg ] && cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg || warn "Could not save default config file." -cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg || warn "Could not save main instance config file." +. /shared.sh if [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ] || [ ! -f /ark/server/version.txt ]; then warn "No game files found. Installing..." - # touch /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer arkmanager install || error "Could not install game files." else if [ ${BACKUPONSTART} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks/)" ]; then