Skip to content

Commit 1c7ba4e

Browse files
committed
Add option to add base user for Ubuntu distro
1 parent 57c46b8 commit 1c7ba4e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/modules/base/config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ if [ "${BASE_DISTRO}" == "ubuntu" ]; then
2020
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=`ls -t $BASE_IMAGE_PATH/ubuntu-*.xz | head -n 1`
2121
# Default user ubuntu
2222
[ -n "$BASE_USER" ] || BASE_USER=ubuntu
23+
24+
# Add base user if does not exist
25+
[ -n "$BASE_ADD_USER" ] || BASE_ADD_USER=yes
26+
# When adding a base user which password to use
27+
[ -n "$BASE_USER_PASSWORD" ] || BASE_USER_PASSWORD=ubuntu
2328
elif [ "${BASE_DISTRO}" == "raspios64" ]; then
2429
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=`ls -t $BASE_IMAGE_PATH/*-{raspbian,raspios}-*-arm64-*.zip | head -n 1`
30+
[ -n "$BASE_ADD_USER" ] || BASE_ADD_USER=no
2531
else
2632
# Default image raspbian
2733
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=`ls -t $BASE_IMAGE_PATH/*-{raspbian,raspios}*.zip | head -n 1`
2834
# Default user raspbian
2935
[ -n "$BASE_USER" ] || BASE_USER=pi
36+
[ -n "$BASE_ADD_USER" ] || BASE_ADD_USER=no
3037
fi
3138

3239
# Release compression

src/modules/base/start_chroot_script

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ if [ "${BASE_DISTRO}" == "ubuntu" ]; then
3333

3434
#Undo prevent any installed services from automatically starting
3535
rm -r /usr/sbin/policy-rc.d || true
36+
37+
fi
38+
39+
if [ "${BASE_ADD_USER}" == "yes" ]; then
40+
if id -u "${BASE_USER}" >/dev/null 2>&1; then
41+
echo "Base user exists, not adding"
42+
else
43+
echo "Adding base user ${BASE_USER}"
44+
password=$(perl -e 'printf("%s\n", crypt($ARGV[0], "password"))' "${BASE_USER_PASSWORD}")
45+
useradd -m -p "${password}" -s /bin/bash "${BASE_USER}"
46+
fi
3647
fi
3748

3849
if [ -n "$BASE_APT_PROXY" ]

0 commit comments

Comments
 (0)