From 80e0a44f6d37453b8c3310ad3748e393160994a8 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 3 Oct 2016 18:51:22 +0200 Subject: [PATCH] B #4792: CONTEXT/USERNAME does not create a user in linux --- .../one-context.d/20-set-username-password | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/base/etc/one-context.d/20-set-username-password b/base/etc/one-context.d/20-set-username-password index 037e5b9..89fbb27 100755 --- a/base/etc/one-context.d/20-set-username-password +++ b/base/etc/one-context.d/20-set-username-password @@ -16,23 +16,22 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -[ -n "${PASSWORD}${CRYPTED_PASSWORD}" ] || exit 0 - -if [ -z "${USERNAME}" ] -then +if [ -z "${USERNAME}" ]; then USERNAME=root fi -if ! getent passwd "${USERNAME}" > /dev/null 2>&1 -then - echo "User “${USERNAME}” does not exist" >&2 - exit 0 +if ! getent passwd "${USERNAME}" > /dev/null 2>&1; then + useradd -m "${USERNAME}" fi -if [ -n "${PASSWORD}" ] -then +if [ -n "${CRYPTED_PASSWORD_BASE64}" ]; then + CRYPTED_PASSWORD=$(echo $CRYPTED_PASSWORD_BASE64 | base64 -d) + usermod -p "${CRYPTED_PASSWORD}" "${USERNAME}" +elif [ -n "${PASSWORD_BASE64}" ]; then + PASSWORD=$(echo $PASSWORD_BASE64 | base64 -d) chpasswd <<< "${USERNAME}:${PASSWORD}" -elif [ -n "${CRYPTED_PASSWORD}" ] -then +elif [ -n "${CRYPTED_PASSWORD}" ]; then usermod -p "${CRYPTED_PASSWORD}" "${USERNAME}" +elif [ -n "${PASSWORD}" ]; then + chpasswd <<< "${USERNAME}:${PASSWORD}" fi