#!/bin/bash ############################################################ # Decription: manage user in directory # # Author: Gilles Mouchet (gilles.mouchet@gmail.com) # Creation Date: 27-Dec-2024 # Version: 1.0 # Install: # see README.md # Usage: ./manage_user.sh --help # Changelog: # V1.0 - 28-Dec-2024 - GMo # Added # - Creation of script from scratch # ############################################################ # debug #set -x #------------------------------------------------------------------------------ # printUsge function printUsage { /bin/cat << EOF Usage: $progName [options] Options: -a ,--add Add user in the directory IMPORTANT: The first and last name are separated by a space. Spaces in the first and last name must be replaced by hyphens. Examples: Von Doe becomes Van-Doe -d ,--del= Deleted user from directory -h,--help Show this help -v,--version Show version Examples: Add user $progName -a "Yvan Descloux" $progName --add="John Von-Doe" Delete user John Von-Doe $progName -d "John Von-Doe" Delete user Yvan Descloux $progName --del="Yvan Descloux" EOF } #------------------------------------------------------------------------------ # addUser function addUser { # check if the format is coorect if [ $(echo $user_to_add | grep -o " " | wc -l) != "1" ]; then echo "'$user_to_add' format is not correct" echo "The first name and last name must be separated by at least one space" exit 1 fi # parse cn first_name=$(echo $user_to_add | cut -d' ' -f1) last_name=$(echo $user_to_add | cut -d' ' -f2) # get next uidNumber getNextUidNumber # set password (lastname) user_pass=$(slappasswd -s $last_name) # set home dir home_dir=${first_name:0:3}${last_name} lhome_dir=$(echo "${home_dir,,}") #,, set lowercase # set mail address email="${first_name,,}"."${last_name,,}"@$LDAP_USER_MAIL_DOMAIN # add user in directory ldapadd -x -H $LDAP_SRV -D "$LDAP_MANAGER_USER" -w $LDAP_MANAGER_PASS <