This repository has been archived on 2024-12-14. You can view files and clone it, but cannot push or open issues or pull requests.
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-02 21:55:45 +00:00
|
|
|
# If running user is not root, pivot to custom user/group
|
2023-05-04 01:30:07 +00:00
|
|
|
if [ "$uid" != "0" ]; then
|
2023-05-03 20:22:51 +00:00
|
|
|
getent group "$gid" \
|
|
|
|
&& groupdel "$(awk -v i="$gid" -F: '$3 == i' /etc/group | cut -d: -f1)"
|
|
|
|
getent passwd "$uid" \
|
|
|
|
&& userdel "$(awk -v i="$uid" -F: '$3 == i' /etc/passwd | cut -d: -f1)"
|
2023-05-02 21:55:45 +00:00
|
|
|
groupadd -g "$gid" "${user}"
|
|
|
|
useradd \
|
|
|
|
-g "$gid" \
|
|
|
|
-G sudo \
|
|
|
|
-u "$uid" \
|
|
|
|
-d "/home/${user}" \
|
|
|
|
-s /bin/bash \
|
2023-05-02 21:58:10 +00:00
|
|
|
"${user}"
|
2023-05-02 21:55:45 +00:00
|
|
|
setpriv --reuid="$uid" --regid="$gid" --init-groups "$@"
|
2023-05-04 01:30:07 +00:00
|
|
|
else
|
|
|
|
exec "$@"
|
|
|
|
fi
|