[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #!/bin/bash
   2  
   3  #
   4  ## $Id: se3_modif_gidNumber.sh 7745 2013-03-31 23:53:39Z keyser $ ##
   5  #
   6  ##### Script de correction pour les doublons de gidnumbers - stéphane Boireau #####
   7  
   8  if [ "$1" = "--help" -o "$1" = "-h" ]
   9  then
  10      echo "Corrige le doublon de gidNumber"
  11      echo "Usage : aucune option"
  12      exit
  13  fi
  14  
  15  
  16  # Pour régler la collision clamav/lcs-users
  17  # Après traitement, on doit avoir:
  18  #    clamav:    108
  19  #    lcs-users: 1000
  20  # Seul le gidNumber du groupe lcs-users et des comptes utilisateurs dont le gidNumber était 108 doiven être modifiés pour passer à 1000
  21  gid1=108
  22  gid2=1000
  23  
  24  # Pour régler la collision lcs-users/machines
  25  # Après traitement, on doit avoir:
  26  #    lcs-users: 1000
  27  #    machines:  999
  28  # Seul le gidNumber du groupe machines et des comptes machines doit être modifié dans la deuxième étape
  29  gid3=1000
  30  gid4=999
  31  
  32  
  33  #BASE=$(grep "^BASE" /etc/ldap/ldap.conf | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | cut -d" " -f2)
  34  #ROOTDN=$(grep "^rootdn" /etc/ldap/slapd.conf | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | sed -e 's/"//g' | cut -d" " -f2)
  35  #ROOTPW=$(cat /etc/ldap.secret)
  36  BASEDN=$(cat /etc/ldap/ldap.conf | grep "^BASE" | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | cut -d" " -f2)
  37  ROOTDN=$(cat /etc/ldap/slapd.conf | grep "^rootdn" | tr "\t" " " | cut -d'"' -f2)
  38  PASSDN=$(cat /etc/ldap.secret)
  39  
  40  ladate=$(date +"%Y.%m.%d-%H.%M.%S");
  41  
  42  #tmp=/root/tmp/tmp.$ladate
  43  tmp=/home/_root_tmp.$ladate
  44  mkdir -p $tmp
  45  chmod 700 $tmp
  46  
  47  #Couleurs
  48  COLTITRE="\033[1;35m"   # Rose
  49  COLPARTIE="\033[1;34m"  # Bleu
  50  
  51  COLTXT="\033[0;37m"     # Gris
  52  COLCHOIX="\033[1;33m"   # Jaune
  53  COLDEFAUT="\033[0;33m"  # Brun-jaune
  54  COLSAISIE="\033[1;32m"  # Vert
  55  
  56  COLCMD="\033[1;37m"     # Blanc
  57  
  58  COLERREUR="\033[1;31m"  # Rouge
  59  COLINFO="\033[0;36m"    # Cyan
  60  
  61  echo -e "$COLTITRE"
  62  echo "*****************************"
  63  echo "* Modification de gidNumber *"
  64  echo "*****************************"
  65  
  66  echo -e "$COLINFO"
  67  echo "Traitement de clamav/lcs-users"
  68  
  69  echo -e "$COLTXT"
  70  echo "Sauvegarde des ACL de /var/se3"
  71  echo -e "$COLCMD\c"
  72  cd /var/se3
  73  getfacl -R . > $tmp/varse3.acl
  74  
  75  echo -e "$COLTXT"
  76  echo "Sauvegarde des ACL de /home"
  77  echo -e "$COLCMD\c"
  78  cd /home
  79  getfacl -R . > $tmp/home.acl
  80  
  81  echo -e "$COLTXT"
  82  echo "Sauvegarde de l'annuaire..."
  83  echo -e "$COLCMD\c"
  84  ldapsearch -xLLL -D $ROOTDN -w $PASSDN > $tmp/svg_ldap_$ladate}.ldif
  85  
  86  echo -e "$COLTXT"
  87  echo "Modification des groupes propriétaires de $gid1 à $gid2 sur /var/se3" | tee -a $tmp/chg_proprio_var_se3.txt
  88  echo -e "$COLCMD\c"
  89  find /var/se3/ -gid $gid1 | while read A
  90  do
  91      echo "Traitement de: $A" >> $tmp/chg_proprio_var_se3.txt
  92      chown :$gid2 "$A" | tee -a $tmp/chg_proprio_var_se3.txt
  93      #chown -v :$gid2 "$A" | tee -a $tmp/chg_proprio_var_se3.txt
  94  done
  95  
  96  echo -e "$COLTXT"
  97  echo "Modification des groupes propriétaires de $gid1 à $gid2 sur /home" | tee -a $tmp/chg_proprio_home.txt
  98  echo -e "$COLCMD\c"
  99  find /home/ -gid $gid1 | while read A
 100  do
 101      echo "Traitement de: $A" >> $tmp/chg_proprio_home.txt
 102      chown :$gid2 "$A" | tee -a $tmp/chg_proprio_home.txt
 103      #chown -v :$gid2 "$A" | tee -a $tmp/chg_proprio_home.txt
 104  done
 105  
 106  echo -e "$COLTXT"
 107  echo "Modif du gidNumber pour cn=lcs-users" | tee -a $tmp/chg_gidNumber_lcs-users.txt
 108  echo -e "$COLCMD\c"
 109  echo "dn: cn=lcs-users,ou=Groups,$BASEDN
 110  changetype: modify
 111  replace: gidNumber
 112  gidNumber: $gid2
 113  " > $tmp/lcsusers_modif.ldif
 114  ldapmodify -x -D $ROOTDN -w $PASSDN -f $tmp/lcsusers_modif.ldif | tee -a $tmp/chg_gidNumber_lcs-users.txt
 115  
 116  echo -e "$COLTXT"
 117  echo "Recherche des comptes à modifier..." | tee -a $tmp/chg_gidNumber_comptes.txt
 118  echo -e "$COLCMD\c"
 119  ldapsearch -xLLL -b ou=People,$BASEDN gidNumber=$gid1 uid | grep "^uid: " | sed -e "s/^uid: //" | while read uid
 120  do
 121          echo -e "$COLTXT\c"
 122          echo "Modification de $uid" | tee -a $tmp/chg_gidNumber_comptes.txt
 123          echo -e "$COLCMD\c"
 124          echo "dn: uid=$uid,ou=People,$BASEDN
 125  changetype: modify
 126  replace: gidNumber
 127  gidNumber: $gid2
 128  " > $tmp/$uid}_modif.ldif
 129          ldapmodify -x -D $ROOTDN -w $PASSDN -f $tmp/$uid}_modif.ldif | tee -a $tmp/chg_gidNumber_comptes.txt
 130  done
 131  
 132  
 133  tst=$(ldapsearch -xLLL -b ou=Groups,$BASEDN cn=machines gidNumber | grep "^gidNumber: " | sed -e "s/^gidNumber: //")
 134  if [ "$tst" = "1000" ]; then
 135  
 136      echo -e "$COLINFO"
 137      echo "Traitement de lcs-users/machines"
 138  
 139      echo -e "$COLTXT"
 140      echo "Modif du gidNumber pour cn=machines" | tee -a $tmp/chg_gidNumber_machines.txt
 141      echo -e "$COLCMD\c"
 142      echo "dn: cn=machines,ou=Groups,$BASEDN
 143  changetype: modify
 144  replace: gidNumber
 145  gidNumber: $gid4
 146  " > $tmp/machines_modif.ldif
 147      ldapmodify -x -D $ROOTDN -w $PASSDN -f $tmp/machines_modif.ldif | tee -a $tmp/chg_gidNumber_machines.txt
 148  
 149      echo -e "$COLTXT"
 150      echo "Recherche des comptes à modifier..." | tee -a $tmp/chg_gidNumber_comptes.txt
 151      echo -e "$COLCMD\c"
 152      ldapsearch -xLLL -b ou=Computers,$BASEDN gidNumber=$gid3 uid | grep "^uid: " | sed -e "s/^uid: //" | while read uid
 153      do
 154              n_uid=$(echo "$uid" | tr "$" "_")
 155              echo -e "$COLTXT\c"
 156              echo "Modification de $uid" | tee -a $tmp/chg_gidNumber_comptes_machines.txt
 157              echo -e "$COLCMD\c"
 158              echo "dn: uid=$uid,ou=Computers,$BASEDN
 159  changetype: modify
 160  replace: gidNumber
 161  gidNumber: $gid4
 162  " > $tmp/$n_uid}_modif.ldif
 163              ldapmodify -x -D $ROOTDN -w $PASSDN -f $tmp/$n_uid}_modif.ldif | tee -a $tmp/chg_gidNumber_comptes_machines.txt
 164  #" > $tmp/${uid}_modif.ldif
 165              #ldapmodify -x -D $ROOTDN -w $PASSDN -f $tmp/${uid}_modif.ldif | tee -a $tmp/chg_gidNumber_comptes_machines.txt
 166      done
 167  fi
 168  
 169  
 170  echo -e "$COLTXT"
 171  echo "Les sauvegardes et les fichiers temporaires sont accessibles dans:"
 172  echo -e "   $COLINFO}$tmp}"
 173  
 174  echo -e "$COLTITRE"
 175  echo "***********"
 176  echo "* Terminé *"
 177  echo "***********"
 178  echo -e "$COLTXT"


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