handle host user being root or a default debian user/group

This commit is contained in:
Lance Vick 2023-05-01 15:53:32 -07:00
parent 4eff8b258b
commit 108089eac2
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
1 changed files with 18 additions and 10 deletions

View File

@ -6,7 +6,10 @@ gid=${GID?}
user=${USER:-"build"} user=${USER:-"build"}
export HOME="/home/${user}" export HOME="/home/${user}"
groupdel dialout # If running user is not root, make a custom user/group
[ "$uid" != "0" ] && {
getent group "$gid" && groupdel "$gid"
getent passwd "$uid" && userdel "$uid"
groupadd -g "$gid" "${user}" groupadd -g "$gid" "${user}"
useradd \ useradd \
-g "$gid" \ -g "$gid" \
@ -15,6 +18,11 @@ useradd \
-d "/home/${user}" \ -d "/home/${user}" \
-s /bin/bash \ -s /bin/bash \
"${user}" "${user}"
}
cd "$HOME" cd "$HOME"
# If running user is not root, pivot to running user
[ "$uid" != "0" ] && {
setpriv --reuid="$uid" --regid="$gid" --init-groups "$@" setpriv --reuid="$uid" --regid="$gid" --init-groups "$@"
}