diff --git a/scripts/csv2ldap_account.sh b/scripts/csv2ldap_account.sh new file mode 100755 index 0000000..a361455 --- /dev/null +++ b/scripts/csv2ldap_account.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# +# Script for import evoadmin account from stdin csv file +# +# CSV format must be : mail_address;password +# + +set -eu + +tmp_file=$(mktemp --suffix=.ldif) +gid_file=$(mktemp) + +trap "rm ${tmp_file} ${gid_file}" 0 + +ldapvi --ldapsearch|grep -E "^gidNumber:"|awk '{ print $2 }'|sort -n|tail -n1 > "${gid_file}" + +dc=$(grep "^base:" /root/.ldapvirc|awk '{ print $2 }') + +get_gid() { + domain=${1:-} + gid=$(ldapvi --ldapsearch --read "cn=${domain},${dc}" 2>/dev/null|grep -E "^gidNumber:"|awk '{ print $2 }') + if [ -z "${gid}" ]; then + lastgid=$(cat "${gid_file}") + gid=$((lastgid + 1)) + echo "${gid}" > "${gid_file}" + cat >> "${tmp_file}" <> "${tmp_file}" <