Skip to content

Commit

Permalink
Allow running satisfactory as rootless user (#222)
Browse files Browse the repository at this point in the history
* feat: add option to run container rootless
  • Loading branch information
98jan authored Dec 13, 2023
1 parent 0369925 commit b21d607
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v2

- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
Expand Down Expand Up @@ -39,4 +39,4 @@ jobs:
push: true
tags: |
ghcr.io/${{ github.repository }}/${{ github.event.repository.name }}:dev
${{ steps.meta.outputs.tags }}
${{ steps.meta.outputs.tags }}
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ ENV AUTOPAUSE="true" \
SKIPUPDATE="false" \
STEAMAPPID="1690800" \
STEAMBETA="false" \
TIMEOUT="30"
TIMEOUT="30"\
ROOTLESS="false"

EXPOSE 7777/udp 15000/udp 15777/udp

Expand Down
37 changes: 22 additions & 15 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ if [[ $(lscpu | grep 'Model name:' | sed 's/Model name:[[:space:]]*//g') = "Comm
exit 1
fi

if [[ "$CURRENTUID" -ne "0" ]]; then
printf "${MSGERROR} Current user is not root (%s)\\nPass your user and group to the container using the PGID and PUID environment variables\\nDo not use the --user flag (or user: field in Docker Compose)\\n" "$CURRENTUID"
exit 1
if [[ "$ROOTLESS" = false ]]; then
if [[ "$CURRENTUID" -ne "0" ]]; then
printf "${MSGERROR} Current user is not root (%s)\\nPass your user and group to the container using the PGID and PUID environment variables\\nDo not use the --user flag (or user: field in Docker Compose)\\n" "$CURRENTUID"
exit 1
fi
fi

printf "Checking available memory...%sGB detected\\n" "$RAMAVAILABLE"
Expand All @@ -58,16 +60,18 @@ elif [[ "$PUID" -eq 0 ]]; then
exit 1
fi

if [[ $(getent group $PGID | cut -d: -f1) ]]; then
usermod -a -G "$PGID" steam
else
groupmod -g "$PGID" steam
fi
if [[ "$ROOTLESS" = false ]]; then
if [[ $(getent group $PGID | cut -d: -f1) ]]; then
usermod -a -G "$PGID" steam
else
groupmod -g "$PGID" steam
fi

if [[ $(getent passwd ${PUID} | cut -d: -f1) ]]; then
USER=$(getent passwd $PUID | cut -d: -f1)
else
usermod -u "$PUID" steam
if [[ $(getent passwd ${PUID} | cut -d: -f1) ]]; then
USER=$(getent passwd $PUID | cut -d: -f1)
else
usermod -u "$PUID" steam
fi
fi

mkdir -p \
Expand All @@ -80,6 +84,9 @@ mkdir -p \
"${GAMECONFIGDIR}/Logs" \
"${GAMESAVESDIR}/server" \
|| exit 1

chown -R "$PUID":"$PGID" /config /home/steam /tmp/dumps
exec gosu "$USER" "/home/steam/run.sh" "$@"
if [[ "$ROOTLESS" = false ]]; then
chown -R "$PUID":"$PGID" /config /home/steam /tmp/dumps
exec gosu "$USER" "/home/steam/run.sh" "$@"
else
exec "/home/steam/run.sh" "$@"
fi
8 changes: 6 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ if [ -n "$SERVERIP" ]; then
SERVERIP="-multihome=\"$SERVERIP\""
fi

# should we add an check, that if it is first installation to download the files?
if ! [[ "${SKIPUPDATE,,}" == "true" ]]; then
if [[ "${STEAMBETA,,}" == "true" ]]; then
printf "Experimental flag is set. Experimental will be downloaded instead of Early Access.\\n"
STEAMBETAFLAG="experimental"
else
STEAMBETAFLAG="public"
fi

# returns for Kubernetes 0 but works, probably for wrong folder the check is done?
STORAGEAVAILABLE=$(stat -f -c "%a*%S" .)
STORAGEAVAILABLE=$((STORAGEAVAILABLE/1024/1024/1024))
printf "Checking available storage...%sGB detected\\n" "$STORAGEAVAILABLE"
Expand All @@ -138,7 +139,10 @@ if ! [[ "${SKIPUPDATE,,}" == "true" ]]; then
fi

printf "Downloading the latest version of the game...\\n"

if [[ "$ROOTLESS" = true ]]; then
export USER=steam
export HOME=/home/steam
fi
steamcmd +force_install_dir /config/gamefiles +login anonymous +app_update "$STEAMAPPID" -beta "$STEAMBETAFLAG" validate +quit
else
printf "Skipping update as flag is set\\n"
Expand Down

0 comments on commit b21d607

Please sign in to comment.