From 8dbf27e20441f141abd0cdb8fa52ef244f07dc1c Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Thu, 1 Feb 2018 18:14:36 +0100 Subject: [PATCH] WIP : files for mass import --- create_mass_primtux_users.sh | 31 +++++++++++++++++++++++++++ create_primtux_user.sh | 19 +++++++++-------- generate_users.sh | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 9 deletions(-) create mode 100755 create_mass_primtux_users.sh create mode 100755 generate_users.sh diff --git a/create_mass_primtux_users.sh b/create_mass_primtux_users.sh new file mode 100755 index 00000000..b7bee71b --- /dev/null +++ b/create_mass_primtux_users.sh @@ -0,0 +1,31 @@ +#!/bin/bash +DIR=`dirname $0` + +usage(){ + echo "Usage $0 names.txt" + echo "Reads a list of name corresponding to some ldap users" + echo "and run $DIR/create_primtux_user.sh on each of them" +} + +if [ -z "$1" ] +then + usage + exit 1 +fi + +if [ ! -f "$1" ] +then + echo "$1 is not a file" + usage + exit 1 +fi + +while read first last level +do + echo $first + echo $last + echo $level + uid=`ldapsearch -x cn="$first $last" | grep "^uid:" | cut -f ' ' -d 2` + echo $uid + echo $DIR/create_primtux_user.sh $uid $level +done < $1 diff --git a/create_primtux_user.sh b/create_primtux_user.sh index dba9c912..bafbbeb3 100755 --- a/create_primtux_user.sh +++ b/create_primtux_user.sh @@ -1,17 +1,17 @@ #!/bin/bash -LEVELS="cycle_1 cycle_2 cycle_3 professeur direction" +LEVELS="cycle1 cycle2 cycle3 prof direction" declare -A SKELS -SKELS[cycle_1]="01-mini" -SKELS[cycle_2]="02-super" -SKELS[cycle_3]="03-maxi" -SKELS[professeur]="prof" +SKELS[cycle1]="01-mini" +SKELS[cycle2]="02-super" +SKELS[cycle3]="03-maxi" +SKELS[prof]="prof" SKELS[direction]="direction" declare -A GRPS -GRPS[cycle_1]="Cycle1" -GRPS[cycle_2]="Cycle2" -GRPS[cycle_3]="Cycle3" -GRPS[professeur]="Profs" +GRPS[cycle1]="Cycle1" +GRPS[cycle2]="Cycle2" +GRPS[cycle3]="Cycle3" +GRPS[prof]="Profs" GRPS[direction]="Administratifs" user="$1" @@ -86,6 +86,7 @@ do ln -sf "$home/`basename \"$f\" | sed 's/.* \(.*\)/\u\1/'`" "$f" done sed -i s@${SKELS[$level]}@$user@g $home/.config/xfce4/panel/launcher-4/14504679941.desktop +sed -i s@/home/${SKELS[$level]}/Documents@/home/$user/Documents @g $home/.handymenu.conf sed -i s@${SKELS[$level]}@$user@g $home/.handymenu.conf # fix samba passwd # echo "You will be prompted twice for samba password, please enter the same as for LDAP" diff --git a/generate_users.sh b/generate_users.sh new file mode 100755 index 00000000..a5bacfd6 --- /dev/null +++ b/generate_users.sh @@ -0,0 +1,41 @@ +#!/bin/bash +usage(){ + echo "Usage $0 numberOfEntriesPerLevel" + echo "Create two txt files for importing users to the SLIS" +} +if [ -z "$1" ] +then + usage + exit 1 +fi +save_uid (){ + echo $2 $1 $3 >> names.txt +} +STUDENT_LEVELS="cycle1 cycle2 cycle3" +TEACH_LEVELS="prof" +rm classes.txt eleves.txt profs.txt names.txt +for i in `seq 1 $1` +do + for l in $STUDENT_LEVELS + do + gender=`[ $(( $RANDOM % 2 )) == 1 ] && echo "M" || echo "F"` + echo "|$l|-$i|19700101|$gender|Primtux" >> eleves.txt + save_uid $l -$i $l + done + for l in $TEACH_LEVELS + do + gender=$(( 1 + $RANDOM % 2 )) + echo "|$l|$i|19700101|$gender" >> profs.txt + save_uid $l $i $l + done +done +echo "|direction|1|19700101|$gender" >> profs.txt +save_uid direction 1 direction +echo "|administratif|1|19700101|$gender" >> profs.txt +save_uid administratif 1 direction +for level in $STUDENT_LEVELS $TEACH_LEVELS direction +do + echo "$level|classe des $level|" >> classes.txt +done +echo "All done, please import eleves.txt, profs.txt and classes.txt" +echo "Then run `dirname $0`/create_mass_primtux_users.sh names.txt" -- GitLab