-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathentrypoint.sh
executable file
·84 lines (74 loc) · 2.79 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
set -e
set -x
# Check whetehr we are running in Docker/ Podman
# Docker has the file /.dockerenv
# Podman exposes itself in /run/.containerenv
if [[ -f "/.dockerenv" ]]; then
CONTAINER="docker"
elif [[ ! -z $(cat /run/.containerenv | grep "podman") ]]; then
CONTAINER="podman"
else
echo "Unknown Container."
exit 1
fi
# If Wayland Experimental need to blank DISPLAY here to enable Wayland.
# NOTE: DISPLAY must be unset here before run_swift to work
# Registry entrys are set in the container install or won't work.
if [ ! -z $WINE_EXPERIMENTAL_WAYLAND ]; then unset DISPLAY; fi
# Check what container we are in:
if [[ "$CONTAINER" == "docker" ]]; then
# This script runs as the root user in Docker so need to do this to find the
# 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, 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 [ "$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
# 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
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
# Have to change owner for build as everything is root.
chown -R user:user /home/user
gosu user:user /bin/update_zwift.sh "$@"
else
# 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.
ZWIFT_HOME="/home/user/.wine/drive_c/Program Files (x86)/Zwift"
mkdir -p "$ZWIFT_HOME"
cd "$ZWIFT_HOME"
if [ "$1" = "update" ] || [ ! "$(ls -A .)" ] ; then
/bin/update_zwift.sh "$@"
else
/bin/run_zwift.sh "$@"
fi
fi