Skip to content

Commit

Permalink
chown step regarding ZWIFT_UID and ZWIFT_GID is run regardless of equ…
Browse files Browse the repository at this point in the history
…ality within container in docker. (#117)

* chown step regarding ZWIFT_UID and ZWIFT_GID is run regardless  of equality within container in docker.
Fixes #116

* Slight Readme Update

* chown step regarding ZWIFT_UID and ZWIFT_GID is run regardless  of equality within container in docker.
Fixes #116
  • Loading branch information
sHedC authored May 14, 2024
1 parent 7fe43b6 commit 6094b9d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Examples:

`NETWORKING=host zwift` will use host networking which may be needed to have Zwift talk to WiFi enabled trainers.

`ZWIFT_UID=123 ZWIFT_GID=123 zwift` will run Zwift as the given uid and gid. By default Zwift runs with the uid and gid of the user that started the container. You should not need to change this except in rare cases.
`ZWIFT_UID=123 ZWIFT_GID=123 zwift` will run Zwift as the given uid and gid. By default Zwift runs with the uid and gid of the user that started the container. You should not need to change this except in rare cases. NOTE: This does not work in wayland only X11.

You can also set these in `~/.config/zwift/config` to be sourced by the zwift.sh script on execution.

Expand All @@ -81,6 +81,27 @@ The credentials will be used to authenticate before launching the Zwift app, and

Note: This will be loaded by zwift.sh in cleartext as environment variables into the container.

## Where are the saves and why do I get a popup can't write to Document Folder?

This is a hang up from previous versions, mainly with podman. delete the volumes and after re-creation it should work fine.
```
podman volume rm zwift-xxxxx
or
docker volume rm zwift-xxxxx
```

NOTE: if you see a weird volume e.g. zwift-naeva it is a hang up from the past, delete it.

## I sometimes get a popup Not responding why?

For Gnome it is just timing out before zwift responds, just extend the timeout.

```
gsettings set org.gnome.mutter check-alive-timeout 60000
```

## How do I connect my trainer, heart rate monitor, etc?

You can [use your phone as a bridge](https://support.zwift.com/using-the-zwift-companion-app-Hybn8qzPr).
Expand Down
37 changes: 20 additions & 17 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,50 @@ if [[ "$CONTAINER" == "docker" ]]; then
# home directory of the "user" user.
ZWIFT_USER_HOME=$( getent passwd "user" | cut -d: -f6 )
ZWIFT_HOME="$ZWIFT_USER_HOME/.wine/drive_c/Program Files (x86)/Zwift"

mkdir -p "$ZWIFT_HOME"
cd "$ZWIFT_HOME"

USER_UID=`id -u user`
USER_GID=`id -g user`

# Test that it exists and is a number
if [ -n "$ZWIFT_UID" ] && [ "$ZWIFT_UID" -eq "$ZWIFT_UID" ]; then
# Test that it exists and is a number, and only if different to existing.
if [ "$ZWIFT_UID" -eq "$ZWIFT_UID" ] && [ "$USER_UID" -ne "$ZWIFT_UID" ]; then
USER_UID=$ZWIFT_UID
SWITCH_IDS=1
else
echo "ZWIFT_UID is not set or not a number: '$ZWIFT_UID'"
fi
if [ -n "$ZWIFT_GID" ] && [ "$ZWIFT_GID" -eq "$ZWIFT_GID" ]; then
if [ "$ZWIFT_GID" -eq "$ZWIFT_GID" ] && [ "$USER_GID" -ne "$ZWIFT_GID" ]; then
USER_GID=$ZWIFT_GID
SWITCH_IDS=1
else
echo "ZWIFT_GID is not set or not a number: ''$ZWIFT_GID'"
fi

# The next two should be no-ops if ZWIFT_UID/GID are not set but no harm
# running them anyway.
usermod -o -u ${USER_UID} user
groupmod -o -g ${USER_GID} user
chown -R ${USER_UID}:${USER_GID} /home/user
# This section is only run if we are switching either UID or GID.
if [ ! -z $SWITCH_IDS ]; then
usermod -o -u ${USER_UID} user
groupmod -o -g ${USER_GID} user
chown -R ${USER_UID}:${USER_GID} /home/user

# Only make the directory if not there.
if [ ! -d "/run/user/${USER_ID}" ]; then
mkdir -p /run/user/${USER_UID}
fi
# Only make the directory if not there.
if [ ! -d "/run/user/${USER_ID}" ]; then
mkdir -p /run/user/${USER_UID}
fi

# Only alter pulse if the user id changes.
if [ $ZWIFT_UID -ne 1000 ]; then
chown -R user:user /run/user/${USER_UID}
sed -i "s/1000/${USER_UID}/g" /etc/pulse/client.conf
fi

# Run update if that's the first argument or if zwift directory is empty
if [ "$1" = "update" ] || [ ! "$(ls -A .)" ] ; then
gosu user:user /bin/update_zwift.sh "$@"
# Have to change owner for build as everything is root.
chown -R user:user /home/user
gosu user:user /bin/update_zwift.sh "$@"
else
gosu user:user /bin/run_zwift.sh "$@"
# Volume is mounted as root so always re-own.
chown -R ${USER_UID}:${USER_GID} /home/user/.wine/drive_c/users/user/Documents/Zwift
gosu user:user /bin/run_zwift.sh "$@"
fi
else
# We are running in podman.
Expand Down
25 changes: 19 additions & 6 deletions zwift.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env bash
set -x

### FORMATTING ###
RED='\033[0;31m'
NC='\033[0m'
BOLD='\033[1m'
UNDERLINE='\033[4m'

### DEFAULT CONFIGURATION ###

# Set the container image to use
Expand All @@ -22,6 +28,14 @@ fi

NETWORKING=${NETWORKING:-bridge}

# If we are running wayland and ZWIFT_UID provided exit
if [ ! -z $ZWIFT_UID ] || [ ! -z $ZWIFT_GID ]; then
if [ ! -z $WAYLAND_DISPLAY ]; then
echo "Wayland not supported with ZWIFT_UID/ ZWIFT_GID"
exit 0
fi
fi

ZWIFT_UID=${ZWIFT_UID:-$(id -u)}
ZWIFT_GID=${ZWIFT_GID:-$(id -g)}

Expand Down Expand Up @@ -70,10 +84,6 @@ then
if [ "$REMOTE_SUM" = "$THIS_SUM" ]; then
echo "You are running latest zwift.sh 👏"
else
RED='\033[0;31m'
NC='\033[0m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
echo -e "${RED}${BOLD}${UNDERLINE}You are not running the latest zwift.sh 😭, please update!${NC}"
sleep 5
fi
Expand Down Expand Up @@ -160,9 +170,12 @@ CONTAINER=$($CONTAINER_TOOL run ${GENERAL_FLAGS[@]} \
${PODMAN_FLAGS[@]} \
$IMAGE:$VERSION $@
)
if [ $? -ne 0 ]; then
echo -e "${RED}${BOLD}${UNDERLINE}Error can't run zwift, check variables!${NC}"
exit 0
fi

# Allow container to connect to X, has to be set for different UID
if [[ -z $WAYLAND_DISPLAY ]]
then
if [[ -z $WINE_EXPERIMENTAL_WAYLAND ]]; then
xhost +local:$($CONTAINER_TOOL inspect --format='{{ .Config.Hostname }}' $CONTAINER)
fi

0 comments on commit 6094b9d

Please sign in to comment.