[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/sbin/ -> se3_corrige_gidNumber.sh (source)

   1  #!/bin/bash
   2  
   3  #
   4  ## $Id: se3_corrige_gidNumber.sh 7744 2013-03-31 23:47:51Z keyser $ ##
   5  #
   6  ##### Script de correction pour de gidnumbers en passant de Slis a LCS - stéphane Boireau #####
   7  
   8  # gidNumber du groupe slis
   9  # gid1=600
  10  gid1=$(ldapsearch -xLLL uid=admin gidNumber | grep gidNumber | cut -d" " -f2)
  11  
  12  # gidNumber du groupe lcs-users
  13  gid2=5005
  14  # gid2=$(ldapsearch -xLLL cn=lcs-users gidNumber | grep "^gidNumber: " | sed -e "s/^gidNumber: //")
  15  
  16  if [ "$1" = "--help" -o "$1" = "-h" ]
  17  then
  18      echo "Correction des gidNumber de $gid1 a $gid2 sur le SE3."
  19      echo "Le script suppose que l'annuaire utilise est local."
  20      echo "Usage : aucune option"
  21      exit
  22  fi
  23  
  24  #BASE=$(grep "^BASE" /etc/ldap/ldap.conf | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | cut -d" " -f2)
  25  #ROOTDN=$(grep "^rootdn" /etc/ldap/slapd.conf | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | sed -e 's/"//g' | cut -d" " -f2)
  26  #ROOTPW=$(cat /etc/ldap.secret)
  27  BASEDN=$(cat /etc/ldap/ldap.conf | grep "^BASE" | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | cut -d" " -f2)
  28  ROOTDN=$(cat /etc/ldap/slapd.conf | grep "^rootdn" | tr "\t" " " | cut -d'"' -f2)
  29  PASSDN=$(cat /etc/ldap.secret)
  30  
  31  ladate=$(date +"%Y.%m.%d-%H.%M.%S");
  32  
  33  #tmp=/root/tmp/tmp.$ladate
  34  tmp=/home/_root_tmp.$ladate
  35  mkdir -p $tmp
  36  chmod 700 $tmp
  37  
  38  #Couleurs
  39  COLTITRE="\033[1;35m"   # Rose
  40  COLPARTIE="\033[1;34m"  # Bleu
  41  
  42  COLTXT="\033[0;37m"     # Gris
  43  COLCHOIX="\033[1;33m"   # Jaune
  44  COLDEFAUT="\033[0;33m"  # Brun-jaune
  45  COLSAISIE="\033[1;32m"  # Vert
  46  
  47  COLCMD="\033[1;37m"     # Blanc
  48  
  49  COLERREUR="\033[1;31m"  # Rouge
  50  COLINFO="\033[0;36m"    # Cyan
  51  
  52  echo -e "$COLTITRE"
  53  echo "*****************************"
  54  echo "* Modification de gidNumber *"
  55  echo "*****************************"
  56  
  57  echo -e "$COLINFO"
  58  echo "Traitement de slis/lcs-users"
  59  
  60  #echo -e "$COLTXT"
  61  #echo "Sauvegarde des ACL de /var/se3"
  62  #echo -e "$COLCMD\c"
  63  #cd /var/se3
  64  #getfacl -R . > $tmp/varse3.acl
  65  
  66  #echo -e "$COLTXT"
  67  #echo "Sauvegarde des ACL de /home"
  68  #echo -e "$COLCMD\c"
  69  #cd /home
  70  #getfacl -R . > $tmp/home.acl
  71  
  72  echo -e "$COLTXT"
  73  echo "Sauvegarde de l'annuaire..."
  74  echo -e "$COLCMD\c"
  75  ldapsearch -xLLL -D $ROOTDN -w $PASSDN > $tmp/svg_ldap_$ladate}.ldif
  76  if [ "$?" != "0" ]; then
  77      echo -e "$COLERREUR"
  78      echo "Il s'est produit une erreur lors de la sauvegarde."
  79      echo "Abandon."
  80      echo -e "$COLTXT"
  81      exit
  82  fi
  83  
  84  echo -e "$COLTXT"
  85  echo "Modification des groupes propriétaires de $gid1 à $gid2 sur /var/se3" | tee -a $tmp/chg_proprio_var_se3.txt
  86  echo -e "$COLCMD\c"
  87  find /var/se3/ -gid $gid1 | while read A
  88  do
  89      echo "Traitement de: $A" >> $tmp/chg_proprio_var_se3.txt
  90      chown :$gid2 "$A" | tee -a $tmp/chg_proprio_var_se3.txt
  91      #chown -v :$gid2 "$A" | tee -a $tmp/chg_proprio_var_se3.txt
  92  done
  93  
  94  echo -e "$COLTXT"
  95  echo "Modification des groupes propriétaires de $gid1 à $gid2 sur /home" | tee -a $tmp/chg_proprio_home.txt
  96  echo -e "$COLCMD\c"
  97  find /home/ -gid $gid1 | while read A
  98  do
  99      echo "Traitement de: $A" >> $tmp/chg_proprio_home.txt
 100      chown :$gid2 "$A" | tee -a $tmp/chg_proprio_home.txt
 101      #chown -v :$gid2 "$A" | tee -a $tmp/chg_proprio_home.txt
 102  done
 103  
 104  echo -e "$COLTXT"
 105  echo "Mofification du gidnumber de lcs-users pour passage à 5005..." | tee -a $tmp/chg_gidNumber_comptes.txt
 106  echo -e "$COLCMD\c"
 107  echo "dn: cn=lcs-users,ou=Groups,$BASEDN
 108  changetype: modify
 109  replace: gidNumber
 110  gidNumber: $gid2
 111  " > $tmp/lcs-users_modif.ldif
 112  ldapmodify -x -D $ROOTDN -w $PASSDN -f $tmp/lcs-users_modif.ldif | tee -a $tmp/lcs-users_modif.txt
 113  
 114  echo -e "$COLTXT"
 115  echo "Recherche des comptes à modifier..." | tee -a $tmp/chg_gidNumber_comptes.txt
 116  echo -e "$COLCMD\c"
 117  ldapsearch -xLLL -b ou=People,$BASEDN gidNumber=$gid1 uid | grep "^uid: " | sed -e "s/^uid: //" | while read uid
 118  do
 119          echo -e "$COLTXT\c"
 120          echo "Modification de $uid" | tee -a $tmp/chg_gidNumber_comptes.txt
 121          echo -e "$COLCMD\c"
 122          echo "dn: uid=$uid,ou=People,$BASEDN
 123  changetype: modify
 124  replace: gidNumber
 125  gidNumber: $gid2
 126  " >> $tmp/$uid}_modif.ldif
 127          ldapmodify -x -D $ROOTDN -w $PASSDN -f $tmp/$uid}_modif.ldif | tee -a $tmp/chg_gidNumber_comptes.txt
 128  done
 129  
 130  
 131  echo -e "$COLTXT"
 132  echo "Les sauvegardes et les fichiers temporaires sont accessibles dans:"
 133  echo -e "   $COLINFO}$tmp}"
 134  
 135  echo -e "$COLTITRE"
 136  echo "***********"
 137  echo "* Terminé *"
 138  echo "***********"
 139  echo -e "$COLTXT"


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1