From 84aafc1b7b8dc0c97fdca12c3977025bc4afdd56 Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Mon, 17 Sep 2018 15:57:41 +0200 Subject: [PATCH] Add a script for import account from csv --- scripts/csv2ldap_account.sh | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 scripts/csv2ldap_account.sh 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}" <