29 lines
717 B
Bash
Executable File
29 lines
717 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
uid=${UID?}
|
|
gid=${GID?}
|
|
user=${USER:-"build"}
|
|
export HOME="/home/${user}"
|
|
[ ! -z "$PATH_PREFIX" ] && \
|
|
export PATH="${PATH_PREFIX}:${PATH}"
|
|
|
|
# If running user is not root, pivot to custom user/group
|
|
if [ "$uid" != "0" ]; then
|
|
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)"
|
|
groupadd -g "$gid" "${user}"
|
|
useradd \
|
|
-g "$gid" \
|
|
-G sudo \
|
|
-u "$uid" \
|
|
-d "/home/${user}" \
|
|
-s /bin/bash \
|
|
"${user}"
|
|
setpriv --reuid="$uid" --regid="$gid" --init-groups "$@"
|
|
else
|
|
exec "$@"
|
|
fi
|