Forbid required variables to be empty.

This commit is contained in:
Joachim Desroches 2021-03-24 12:07:01 +01:00
parent 71a9a0d910
commit ba13ab7f77
No known key found for this signature in database
GPG key ID: 6778C9C29C02D691

View file

@ -14,13 +14,6 @@ for executable in ldapsearch slappasswd ldapadd sed; do
fi fi
done done
# Default user details to quiet shellcheck (FIXME?).
uid=""
mail=""
given_name=""
sn=""
password=""
# Prompt for user details. # Prompt for user details.
for input in uid mail given_name sn password; do for input in uid mail given_name sn password; do
printf "Please enter %s for new user: " $input 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)) next_uid_number=$(( "$last_uid_number" + 1))
# Compute CN and hash password. # Compute CN and hash password.
cn="$given_name $sn" cn="${given_name:?} ${sn:?}"
hashed_password=$(slappasswd -s "$password") hashed_password=$(slappasswd -s "${password:?}")
# Generate new user, and ask for user-validation. # Generate new user, and ask for user-validation.
ldif=$(cat << EOF ldif=$(cat << EOF
dn: uid=$uid,ou=users,dc=recycled,dc=cloud dn: uid=${uid:?},ou=users,dc=recycled,dc=cloud
objectClass: inetOrgPerson objectClass: inetOrgPerson
objectClass: posixAccount objectClass: posixAccount
cn: $cn cn: ${cn:?}
displayName: $cn displayName: ${cn:?}
gidNumber: $DEFAULT_GROUP_UID_NUMBER gidNumber: ${DEFAULT_GROUP_UID_NUMBER:?}
givenName: $given_name givenName: ${given_name:?}
homeDirectory: /home/$uid homeDirectory: /home/${uid:?}
mail: $mail mail: ${mail:?}
sn: $sn sn: ${sn:?}
uid: $uid uid: ${uid:?}
uidNumber: $next_uid_number uidNumber: ${next_uid_number:?}
userPassword: $hashed_password userPassword: ${hashed_password:?}
EOF EOF
) )