diskimage-builder/elements/devuser/install.d/50-devuser
Gregory Haynes 031a7b03be Add generic devuser element
The devuser element is useful for configuring a generic utility user for
the built images.

Change-Id: Ifd9dcf3ba88d7abc98b1e44a93f6d9a6b4e764dd
2015-04-08 07:01:24 +00:00

34 lines
998 B
Bash
Executable file

#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
user_shell_args=
if [ -n "${DIB_DEV_USER_SHELL}" ]; then
user_shell_args="-s ${DIB_DEV_USER_SHELL}"
fi
useradd -m ${DIB_DEV_USER_USERNAME} $user_shell_args
set +x
if [ -n "${DIB_DEV_USER_PASSWORD}" ]; then
echo "Setting password."
echo "${DIB_DEV_USER_USERNAME}:${DIB_DEV_USER_PASSWORD}" | chpasswd
fi
set -x
if [ -n "${DIB_DEV_USER_PWDLESS_SUDO}" ]; then
cat > /etc/sudoers.d/${DIB_DEV_USER_USERNAME} << EOF
${DIB_DEV_USER_USERNAME} ALL=(ALL) NOPASSWD:ALL
EOF
chmod 0440 /etc/sudoers.d/${DIB_DEV_USER_USERNAME}
visudo -c || rm /etc/sudoers.d/${DIB_DEV_USER_USERNAME}
fi
if [ -f /tmp/in_target.d/devuser-ssh-authorized-keys ]; then
mkdir -p /home/${DIB_DEV_USER_USERNAME}/.ssh
cp /tmp/in_target.d/devuser-ssh-authorized-keys /home/${DIB_DEV_USER_USERNAME}/.ssh/authorized_keys
fi
chown -R ${DIB_DEV_USER_USERNAME}:${DIB_DEV_USER_USERNAME} /home/${DIB_DEV_USER_USERNAME}