2023-01-28 00:05:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
uid=${UID?}
|
|
|
|
gid=${GID?}
|
|
|
|
user=${USER:-"build"}
|
|
|
|
export HOME="/home/${user}"
|
|
|
|
|
2023-05-01 22:53:32 +00:00
|
|
|
# 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}"
|
|
|
|
useradd \
|
|
|
|
-g "$gid" \
|
|
|
|
-G sudo \
|
|
|
|
-u "$uid" \
|
|
|
|
-d "/home/${user}" \
|
|
|
|
-s /bin/bash \
|
|
|
|
"${user}"
|
|
|
|
}
|
2023-01-28 00:05:03 +00:00
|
|
|
|
|
|
|
cd "$HOME"
|
2023-05-01 22:53:32 +00:00
|
|
|
|
|
|
|
# If running user is not root, pivot to running user
|
|
|
|
[ "$uid" != "0" ] && {
|
|
|
|
setpriv --reuid="$uid" --regid="$gid" --init-groups "$@"
|
|
|
|
}
|