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
|
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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue