From 142c15a438c04ce30ecb3a6ecc96698c543ecfcb Mon Sep 17 00:00:00 2001 From: TuRz4m Date: Fri, 8 Jul 2016 16:12:46 +0200 Subject: [PATCH] #11 : add UID & GID. --- Dockerfile | 11 +++++++++-- run.sh | 14 ++++++-------- user.sh | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 user.sh diff --git a/Dockerfile b/Dockerfile index 3a3724a..47b2b50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,10 @@ ENV STEAMPORT 7778 ENV BACKUPONSTOP 0 # If the server warn the players before stopping ENV WARNONSTOP 0 +# UID of the user steam +ENV UID 1000 +# GID of the user steam +ENV GID 1000 # Install dependencies RUN apt-get update &&\ @@ -48,10 +52,13 @@ RUN usermod -a -G sudo steam # Copy & rights to folders COPY run.sh /home/steam/run.sh +COPY user.sh /home/steam/user.sh COPY crontab /home/steam/crontab COPY arkmanager-user.cfg /home/steam/arkmanager.cfg +RUN touch /root/.bash_profile RUN chmod 777 /home/steam/run.sh +RUN chmod 777 /home/steam/user.sh RUN mkdir /ark @@ -75,7 +82,7 @@ COPY instance.cfg /etc/arkmanager/instances/main.cfg RUN chown steam -R /ark && chmod 755 -R /ark -USER steam +#USER steam # download steamcmd RUN mkdir /home/steam/steamcmd &&\ @@ -96,4 +103,4 @@ VOLUME /ark WORKDIR /ark # Update game launch the game. -ENTRYPOINT ["/home/steam/run.sh"] +ENTRYPOINT ["/home/steam/user.sh"] diff --git a/run.sh b/run.sh index f235743..a6721af 100644 --- a/run.sh +++ b/run.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash echo "###########################################################################" echo "# Ark Server - " `date` +echo "# UID $UID - GID $GID" echo "###########################################################################" [ -p /tmp/FIFO ] && rm /tmp/FIFO mkfifo /tmp/FIFO @@ -20,10 +21,7 @@ function stop { exit } -if [ ! -w /ark ]; then - echo "[Error] Can't access ark directory. Check permissions on your mapped directory with /ark" - exit 1 -fi + # Change working directory to /ark to allow relative path cd /ark @@ -38,14 +36,14 @@ cp /home/steam/crontab /ark/template/crontab [ ! -d /ark/log ] && mkdir /ark/log [ ! -d /ark/backup ] && mkdir /ark/backup [ ! -d /ark/staging ] && mkdir /ark/staging -[ ! -f /ark/Game.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/Game.ini Game.ini -[ ! -f /ark/GameUserSettings.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini GameUserSettings.ini +[ ! -L /ark/Game.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/Game.ini Game.ini +[ ! -L /ark/GameUserSettings.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini GameUserSettings.ini [ ! -f /ark/crontab ] && cp /ark/template/crontab /ark/crontab -if [ ! -d "/ark/server" ] || [ ! -f "/ark/server/arkversion" ];then - mkdir /ark/server +if [ ! -d /ark/server ] || [ ! -f /ark/server/arkversion ];then + echo "No game files found. Installing..." arkmanager install # Create mod dir mkdir /ark/server/ShooterGame/Content/Mods diff --git a/user.sh b/user.sh new file mode 100644 index 0000000..a49bdfc --- /dev/null +++ b/user.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Change the UID if needed +if [ ! "$(id -u steam)" -eq "$UID" ]; then + echo "Changing steam uid to $UID." + usermod -o -u "$UID" steam ; +fi +# Change gid if needed +if [ ! "$(id -g steam)" -eq "$GID" ]; then + echo "Changing steam gid to $GID." + groupmod -o -g "$GID" steam ; +fi + +# Put steam owner of directories (if the uid changed, then it's needed) +chown -R steam:steam /ark /home/steam + +# avoid error message when su -p (we need to read the /root/.bash_rc ) +chmod -R 777 /root/ + +# Launch run.sh with user steam (-p allow to keep env variables) +su -p - steam -c /home/steam/run.sh