toolchain/scripts/host-env

25 lines
511 B
Bash
Executable File

#!/bin/bash
set -e
uid=${UID?}
gid=${GID?}
user=${USER:-"build"}
export HOME="/home/${user}"
# If running user is not root, pivot to 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}"
setpriv --reuid="$uid" --regid="$gid" --init-groups "$@"
}
exec "$@"