#!/bin/bash

# PURPOSE: Add the guest image user that will own the trove agent source if the
# user does not already exist

if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
    set -x
fi
set -e
set -o pipefail

GUEST_USERNAME=${GUEST_USERNAME:-"ubuntu"}

if ! id -u ${GUEST_USERNAME} >/dev/null 2>&1; then
    echo "Adding ${GUEST_USERNAME} user"
    useradd -G sudo -m ${GUEST_USERNAME} -s /bin/bash
    chown ${GUEST_USERNAME}:${GUEST_USERNAME} /home/${GUEST_USERNAME}
    passwd ${GUEST_USERNAME} <<_EOF_
${GUEST_USERNAME}
${GUEST_USERNAME}
_EOF_
fi
