Mass provisioning script
Chloé Desoutter
chloe.desoutter at atasta.net
Thu Jul 4 14:51:13 CEST 2013
Le 04/07/2013 13:04, Torsten Grote a écrit :
> On Thursday 04 July 2013 12:08:54 Chloé Desoutter wrote:
>> Has anyone around here developed a mass provisioning script for Kolab
>> 3.x ?
>
> I think what is available is at
>
> https://git.kolab.org/kolab-scripts/tree/
>
> Does this help? If not, publishing your scripts under a Free Software license
> would be appreciated!
>
> Thanks,
> Torsten
Hi Torsten, hi guys,
We dit it the simple way (generating a LDIF). It's useful and we'll use
it in no time. I have tested it on a limited extent and I'm quite satisfied.
It has the advantage of cleaning up accents and white spaces in names,
which cause trouble with the recent Kolab (we French people have
compound names like "de La Roque de Villardieu" with whitespaces all the
way long, and Cyrus doesn't like mailboxen like this).
Joined is also a provisioning sample so you can test the script.
"The specs is the code".
Yours sincerely,
--
Chloé Desoutter
Directrice de production, ATASTA NET
-------------- next part --------------
#!/bin/bash
# kolab-provision-users
# mass-provision users from a CSV file.
# (c) 2013 Atasta SAS
# by Chloé Desoutter <chloe.desoutter at atasta.net>
# kolab-provision-users is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License
# kolab-provision-users is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2, for more details.
# You should have received a copy of the GNU General Public License
# along with kolab-provision-users. If not, see <http://www.gnu.org/licenses/>.
export domain="atasta.net"
export rootdn="dc=atasta,dc=net"
# variables we'll be using
declare givenname
declare surname
declare userpassword
declare telephonenumber
declare mobile
declare mailalternateaddress
# parses a CSV using semicolon separator.
# change the field numbers to fit your own CSV format
parseCSV() {
LINE=$1
f_fn=1
f_sn=2
f_pw=3
f_tn=4
f_mo=5
f_em=6
export givenname=$(echo $LINE | cut -d\; -f${f_fn})
export surname=$(echo $LINE | cut -d\; -f${f_sn})
export userpassword=$(echo $LINE | cut -d\; -f${f_pw})
export telephonenumber=$(echo $LINE | cut -d\; -f${f_tn})
export mobile=$(echo $LINE | cut -d\; -f${f_mo})
export mailalternateaddress=$(echo $LINE | cut -d\; -f${f_em} | sed "s/,/ /g")
}
while read csvline; do
if [ -z $csvline ]; then
continue;
fi
parseCSV "$csvline";
givenname_lower="$(echo ${givenname} | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g' | iconv -f utf8 -t ascii//TRANSLIT -)"
surname_lower="$(echo ${surname} | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g' | iconv -f utf8 -t ascii//TRANSLIT -)"
uid="$(echo ${givenname:0:1}${surname} | tr '[:upper:]' '[:lower:]' | sed 's/ /_/g')"
echo "dn: uid=$uid,ou=People,${rootdn}"
echo "uid: $uid"
echo "givenName: $givenname"
echo "objectclass: top"
echo "objectclass: person"
echo "objectclass: inetOrgPerson"
echo "objectclass: kolabinetorgperson"
echo "objectclass: organizationalperson"
echo "objectclass: mailrecipient"
echo "userpassword: ${userpassword}"
if [ ! -z "${telephonenumber}" ]; then
echo "telephonenumber: ${telephonenumber}"
fi
if [ ! -z "${mobile}" ]; then
echo "mobile: ${mobile}"
fi
if [ ! -z "${mailalternateaddress}" ]; then
for e in $(echo ${mailalternateaddress}); do
echo "mailalternateaddress: ${e}"
done
fi
echo "sn: $surname"
echo "cn: $givenname $surname"
echo "displayname: $surname, $givenname"
echo "mail: ${givenname_lower}.${surname_lower}@${domain}"
echo ""
done
#import it using ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: essai provisioning.csv
Type: application/vnd.ms-excel
Size: 298 bytes
Desc: not available
URL: <http://lists.kolab.org/pipermail/users/attachments/20130704/e1a94542/attachment.xlb>
More information about the users
mailing list