[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #!/bin/bash
   2  # Auteur: Denis Bonnenfant
   3  #
   4  #
   5  ## $Id: update-csv.sh 6914 2012-02-20 01:56:34Z keyser $ ##
   6  #
   7  ##### script generant le fichier unattend.csv à partir du ldap #####
   8  
   9  TEMOIN=/tmp/csvtodo
  10  # On ne fait rien si pas de modif
  11  if [ ! -e $TEMOIN ]; then
  12    exit 0
  13  fi
  14  
  15  LOCKFILE=/tmp/csvgenerate
  16  if [ -e $LOCKFILE ];
  17  then
  18    echo "Script deja en cours d execution"
  19    exit 1
  20  fi
  21  
  22  rm -f $TEMOIN
  23  rm -f /tmp/emailunattended_generate
  24  
  25  # initialisation de la config
  26  # recup parametres ldap
  27  . /etc/se3/config_l.cache.sh
  28  . /etc/se3/config_m.cache.sh
  29  
  30  REPSITE=/home/netlogon/domscripts
  31  UNATTENDEDSITE=/var/se3/unattended/install/site
  32  UNATTENDCSV=$REPSITE/unattend.csv
  33  UNATTENDTXT=unattend.txt
  34  
  35  
  36  ##### variables a stocker dans mysql ########
  37  if [ -e /var/se3/unattended/install/os/xp.txt ] ; then
  38    PRODUCTKEY="`cat /var/se3/unattended/install/os/xp.txt | grep "^PRODUCTKEY=" | cut -d= -f2 | sed 's/\r//g' | sed 's/ //g' | sed 's/:/-/g'`"
  39    NOMOS="`cat /var/se3/unattended/install/os/xp.txt | grep "^OSNAME=" | cut -d= -f2 | sed 's/\r//g' `"
  40  else
  41    NOMOS="Windows XP Professionnel"
  42    PRODUCTKEY="*****-*****-*****-*****-*****"
  43  fi
  44  ##################### creation de unattend.csv #################################
  45  #echo "Creation de unattend.csv"
  46  echo "\"Lookup\",\"Property\",\"Value\"" > $UNATTENDCSV
  47  echo "\"Default\",\"OS_media\",\"xp\"" >> $UNATTENDCSV
  48  echo "\"Default\",\"OrgName\",\"$se3_domain\"" >> $UNATTENDCSV
  49  echo "\"Default\",\"UnattendedFile\",\"$UNATTENDTXT\"" >> $UNATTENDCSV
  50  echo "" >> $UNATTENDCSV
  51  echo "\"Default\",\"$NOMOS ProductID\",\"$PRODUCTKEY\"" >> $UNATTENDCSV
  52  echo "\"Default\",\"$NOMOS ProductKey\",\"$PRODUCTKEY\"" >> $UNATTENDCSV
  53  echo "\"Default\",\"ntp_servers\",\"ntp.ac-creteil.fr\"" >> $UNATTENDCSV
  54  echo "\"Default\",\"top_scripts\",\"basese3.bat\"" >> $UNATTENDCSV
  55  echo "\"Default\",\"AdminPassword\",\"wawa\"" >> $UNATTENDCSV
  56  echo "\"Default\",\"JoinWorkgroup\",\"workgroup\"" >> $UNATTENDCSV
  57  echo "\"Default\",\"FullName\",\"Unattended XP\"" >> $UNATTENDCSV
  58  echo "" >> $UNATTENDCSV
  59  
  60  export COMPUTER
  61  export LISTEMACADD
  62  
  63  ldapsearch -xLLL -b $computersRdn,$ldap_base_dn | grep -E "(dn: cn=|macAddress:)" | while read A
  64  do
  65    if [ "`echo "$A" | grep "^dn: cn="`" == "" ]; then
  66      # on vient de recuperer l adresse mac
  67      #MACADD="$(ldapsearch -xLLL -b cn=$POSTESPARC,$computersRdn,$ldap_base_dn | grep macAddress | cut -d" " -f2)"
  68          MACADD=$(echo "$A" | cut -d" " -f2 | sed "s/://g" | tr '[a-f]' '[A-F]')
  69          # echo "ADRESSEMAC:$MACADD PC:$COMPUTER"
  70          # teste si adresse mac en double
  71          if [ "`echo "$MACADD" | grep "^[0-9A-F]*$"`" != "" ]; then
  72                if [ "`echo "$LISTEMACADD" | grep "$MACADD"`" == "" ]; then
  73                    # pas de soucis d'adresse mac en double
  74                    LISTEMACADD="$LISTEMACADD $MACADD"
  75                    
  76                    # a patcher dans le futur pour creer des groupes de postes (meme config). Ex : $FullName=DELLOPTIPLEX740
  77                    # pour l'instant : FullName=ComputerName
  78                    if [ "$COMPUTER" != "clone" ]; then
  79                        echo "\"$MACADD\",\"ComputerName\",\"$COMPUTER\"" >> $UNATTENDCSV
  80                        echo "\"$COMPUTER\",\"FullName\",\"$COMPUTER\"" >> $UNATTENDCSV
  81                        [ -e $UNATTENDEDSITE/$COMPUTER.txt ] && echo "\"$MACADD\",\"UnattendedFile\",\"$COMPUTER.txt\"" >> $UNATTENDCSV
  82                    fi
  83                else
  84                    echo "L'adresse MAC : $MACADD correspond a deux ordinateurs de la branche Computers (il faut corriger en ne gardant qu'une des entrees suivantes)." >> /tmp/emailunattended_generate
  85                    echo "$COMPUTER"  >> /tmp/emailunattended_generate
  86                    cat "$UNATTENDCSV" | grep "$MACADD" | cut -d, -f3 | sed 's/"//g' >> /tmp/emailunattended_generate
  87                fi
  88          fi
  89    else
  90      COMPUTER=`echo $A | cut -d= -f2 | cut -d, -f1`
  91    fi
  92  done
  93  # Envoi de l'e-mail rapport
  94  if [ -e /tmp/emailunattended_generate ] ; then
  95    echo "Pour corriger : Sur l'interface web, Menu gestion des parcs, cliquer sur recherche puis supprimer les entrees obsoletes.
  96  
  97  Dans le cas ou vous ne corrigeriez pas, les reinstallations unattended risqueraient de se faire sous le mauvais nom." >> /tmp/emailunattended_generate
  98  #  cat  /tmp/emailunattended_generate
  99  fi
 100  if [ -e $UNATTENDCSV ]; then
 101      todos $UNATTENDCSV
 102      mkdir -p $UNATTENDEDSITE
 103      cp -f $UNATTENDCSV $UNATTENDEDSITE
 104  fi
 105  if [ -e $LOCKFILE ]; then
 106    rm $LOCKFILE
 107  fi
 108  exit 0
 109  
 110  


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