Skip to content

Commit 5215ee4

Browse files
committed
fix: run as user when specify alternate home volume
1 parent 290efed commit 5215ee4

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

docker-wine

+18-13
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ print_help () {
77
echo "OPTIONS:"
88
echo " --local Use locally built docker-wine image instead of pulling"
99
echo " image from DockerHub"
10-
echo " --as-root Run as root"
11-
echo " --as-me Run using your current username, UID and GID (default"
12-
echo " when alternate --home value specified)"
10+
echo " --as-root Start the container as root"
11+
echo " --as-me Start the container using your current username, UID and"
12+
echo " GID (default when alternate --home value specified)"
1313
echo " --rdp Shortcut for --rdp=interactive"
1414
echo " --rdp=OPTION Runs docker-wine container with Remote Desktop Protocol"
1515
echo " server"
@@ -57,9 +57,16 @@ print_help () {
5757
}
5858

5959
add_run_arg () {
60-
local arg="$1"
60+
RUN_ARGS+=("$1")
61+
}
6162

62-
RUN_ARGS+=("${arg}")
63+
add_run_args_for_as_me () {
64+
USER_HOME="${HOME}"
65+
WORKDIR="${USER_HOME}"
66+
add_run_arg --env="USER_NAME=$(whoami)"
67+
add_run_arg --env="USER_UID=$(id -u)"
68+
add_run_arg --env="USER_GID=$(id -g)"
69+
add_run_arg --env="USER_HOME=${USER_HOME}"
6370
}
6471

6572

@@ -81,15 +88,10 @@ while [ $# -gt 0 ]; do
8188
;;
8289
--as-root)
8390
add_run_arg --env="RUN_AS_ROOT=yes"
84-
WORKDIR="/root"
91+
WORKDIR="/"
8592
;;
8693
--as-me)
87-
USER_HOME="${HOME}"
88-
WORKDIR="${USER_HOME}"
89-
add_run_arg --env="USER_NAME=$(whoami)"
90-
add_run_arg --env="USER_UID=$(id -u)"
91-
add_run_arg --env="USER_GID=$(id -g)"
92-
add_run_arg --env="USER_HOME=${USER_HOME}"
94+
add_run_args_for_as_me
9395
;;
9496
--rdp)
9597
USE_RDP_SERVER="interactive"
@@ -106,6 +108,9 @@ while [ $# -gt 0 ]; do
106108
;;
107109
--home-volume=*)
108110
USER_VOLUME="${1#*=}"
111+
112+
# Start container as self to prevent unintentionally changing ownership of a user's local filesystem by wineuser
113+
add_run_args_for_as_me
109114
;;
110115
--password=*)
111116
add_run_arg --env="USER_PASSWD=$(openssl passwd -1 "${1#*=}")"
@@ -244,7 +249,7 @@ else
244249
elif [ "$(uname)" == "Linux" ]; then
245250

246251
# Check for .Xauthority command -v is required for authenticating as the current user on the host's X11 server
247-
if [ -z "${XAUTHORITY}" ] && [ -s "${HOME}/.Xauthority" ]; then
252+
if [ -z "${XAUTHORITY}" -a -s "${HOME}/.Xauthority" ]; then
248253
echo "ERROR: No valid .Xauthority file found for X11"
249254
exit 1
250255
fi

0 commit comments

Comments
 (0)