Skip to content

Commit a9fb986

Browse files
committed
[common-utils] fix bug when user home is custom by base docker
1 parent 3a22c41 commit a9fb986

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/common-utils/main.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,15 @@ fi
408408
if [ "${USERNAME}" = "root" ]; then
409409
user_home="/root"
410410
else
411-
user_home="/home/${USERNAME}"
412-
if [ ! -d "${user_home}" ]; then
413-
mkdir -p "${user_home}"
414-
chown ${USERNAME}:${group_name} "${user_home}"
411+
# Check if user already has a home directory other than /home/${USERNAME}
412+
if [ "/home/${USERNAME}" != $( getent passwd $USERNAME | cut -d: -f6 ) ]; then
413+
user_home=$( getent passwd $USERNAME | cut -d: -f6 )
414+
else
415+
user_home="/home/${USERNAME}"
416+
if [ ! -d "${user_home}" ]; then
417+
mkdir -p "${user_home}"
418+
chown ${USERNAME}:${group_name} "${user_home}"
419+
fi
415420
fi
416421
fi
417422

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "user is customUser" grep customUser <(whoami)
10+
check "home is /customHome" grep "/customHome" <(getent passwd customUser | cut -d: -f6)
11+
12+
# Report result
13+
reportResults
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM ubuntu:focal
2+
3+
RUN groupadd customUser -g 30000 && \
4+
useradd customUser -u 30000 -g 30000 --create-home --home-dir /customHome

test/common-utils/scenarios.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,14 @@
183183
"configureZshAsDefaultShell": true
184184
}
185185
}
186+
},
187+
"devcontainer-custom-home": {
188+
"build": {
189+
"dockerfile": "Dockerfile"
190+
},
191+
"remoteUser": "customUser",
192+
"features": {
193+
"common-utils": {}
194+
}
186195
}
187196
}

0 commit comments

Comments
 (0)