Forbid required variables to be empty.
This commit is contained in:
parent
71a9a0d910
commit
ba13ab7f77
1 changed files with 13 additions and 20 deletions
|
@ -14,13 +14,6 @@ for executable in ldapsearch slappasswd ldapadd sed; do
|
|||
fi
|
||||
done
|
||||
|
||||
# Default user details to quiet shellcheck (FIXME?).
|
||||
uid=""
|
||||
mail=""
|
||||
given_name=""
|
||||
sn=""
|
||||
password=""
|
||||
|
||||
# Prompt for user details.
|
||||
for input in uid mail given_name sn password; do
|
||||
printf "Please enter %s for new user: " $input
|
||||
|
@ -38,24 +31,24 @@ last_uid_number=$(ldapsearch -x -H $LDAP_SERVER -b $LDAP_BASE_DN \
|
|||
next_uid_number=$(( "$last_uid_number" + 1))
|
||||
|
||||
# Compute CN and hash password.
|
||||
cn="$given_name $sn"
|
||||
hashed_password=$(slappasswd -s "$password")
|
||||
cn="${given_name:?} ${sn:?}"
|
||||
hashed_password=$(slappasswd -s "${password:?}")
|
||||
|
||||
# Generate new user, and ask for user-validation.
|
||||
ldif=$(cat << EOF
|
||||
dn: uid=$uid,ou=users,dc=recycled,dc=cloud
|
||||
dn: uid=${uid:?},ou=users,dc=recycled,dc=cloud
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: posixAccount
|
||||
cn: $cn
|
||||
displayName: $cn
|
||||
gidNumber: $DEFAULT_GROUP_UID_NUMBER
|
||||
givenName: $given_name
|
||||
homeDirectory: /home/$uid
|
||||
mail: $mail
|
||||
sn: $sn
|
||||
uid: $uid
|
||||
uidNumber: $next_uid_number
|
||||
userPassword: $hashed_password
|
||||
cn: ${cn:?}
|
||||
displayName: ${cn:?}
|
||||
gidNumber: ${DEFAULT_GROUP_UID_NUMBER:?}
|
||||
givenName: ${given_name:?}
|
||||
homeDirectory: /home/${uid:?}
|
||||
mail: ${mail:?}
|
||||
sn: ${sn:?}
|
||||
uid: ${uid:?}
|
||||
uidNumber: ${next_uid_number:?}
|
||||
userPassword: ${hashed_password:?}
|
||||
EOF
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue