aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSamruddhi Khandale <skhandale@microsoft.com>2022-05-31 19:21:29 +0300
committerGitHub <noreply@github.com>2022-05-31 19:21:29 +0300
commit0431ec33f17ff2d62c0771d152ef1727070fea36 (patch)
treec0c2729b382aed6c03a5b4a71d301c6bc8e1f503 /src
parent0956fb3e749f3d9c582d8e2aa324845d84fc100e (diff)
Diffstat (limited to 'src')
-rw-r--r--src/anaconda/install.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/anaconda/install.sh b/src/anaconda/install.sh
index 8a23bc4..bdcdf4a 100644
--- a/src/anaconda/install.sh
+++ b/src/anaconda/install.sh
@@ -47,6 +47,38 @@ elif [ "${USERNAME}" = "none" ]; then
USER_GID=0
fi
+# Create or update a non-root user to match UID/GID.
+group_name="${USERNAME}"
+if id -u ${USERNAME} > /dev/null 2>&1; then
+ # User exists, update if needed
+ if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -g $USERNAME)" ]; then
+ group_name="$(id -gn $USERNAME)"
+ groupmod --gid $USER_GID ${group_name}
+ usermod --gid $USER_GID $USERNAME
+ fi
+ if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
+ usermod --uid $USER_UID $USERNAME
+ fi
+else
+ # Create user
+ if [ "${USER_GID}" = "automatic" ]; then
+ groupadd $USERNAME
+ else
+ groupadd --gid $USER_GID $USERNAME
+ fi
+ if [ "${USER_UID}" = "automatic" ]; then
+ useradd -s /bin/bash --gid $USERNAME -m $USERNAME
+ else
+ useradd -s /bin/bash --uid $USER_UID --gid $USERNAME -m $USERNAME
+ fi
+fi
+
+# Add add sudo support for non-root user
+if [ "${USERNAME}" != "root" ]; then
+ echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
+ chmod 0440 /etc/sudoers.d/$USERNAME
+fi
+
architecture="$(uname -m)"
if [ "${architecture}" != "x86_64" ]; then
echo "(!) Architecture $architecture unsupported"