[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-wpkg/sources/scripts/ -> update_hosts_profiles_xml.sh (source)

   1  #!/bin/bash
   2  
   3  #########################################################################
   4  #   /usr/share/se3/scripts/update_hosts_profiles_xml.sh                 #
   5  #                                                                       #
   6  #########################################################################
   7  #
   8  #
   9  #   Met à jour hosts.xml et profiles.xml dans /var/se3/unattended/install/wpkg
  10  #   à partir des données de l'annuaire
  11  #
  12  #   A executer chaque fois que les parcs sont modifiés
  13  #   Syntaxe :  update_hosts_profiles_xml.sh ComputersRDN ParcsRDN BaseDN
  14  
  15  ## $Id: update_hosts_profiles_xml.sh 3592 2009-03-10 18:24:15Z jlebail $ ##
  16  #
  17  
  18  
  19  ComputersRDN="$1"
  20  ParcsRDN="$2"
  21  BaseDN="$3"
  22  
  23  wpkgroot="/var/se3/unattended/install/wpkg"
  24  wpkgwebdir="/var/www/se3/wpkg"
  25  
  26  HOSTS_XML="$wpkgroot/hosts.xml";
  27  PROFILES_XMLTMP="$wpkgroot/profiles.xml.tmp";
  28  PROFILES_XML="$wpkgroot/profiles.xml";
  29  
  30  if [ "$2" == "" ]; then
  31      echo "hosts.xml et profiles.xml dans /var/se3/unattended/install/wpkg/"
  32      echo "  Syntaxe :  update_hosts_profiles_xml.sh ComputersRDN ParcsRDN BaseDN"
  33      exit 1
  34  fi
  35  
  36  # Nom du profile TousLesPostes
  37  TousLesPostes="_TousLesPostes"
  38  
  39  #BaseDN=`echo "SELECT value FROM params WHERE name='ldap_base_dn'" | mysql -h localhost se3db -N`
  40  #ParcsRDN=`echo "SELECT value FROM params WHERE name='parcsRdn'" | mysql -h localhost se3db -N`
  41  #ComputersRDN=`echo "SELECT value FROM params WHERE name='computersRdn'" | mysql -h localhost se3db -N`
  42  
  43  # echo "ParcsRDN=$ParcsRDN; BaseDN=$BaseDN"
  44  
  45  # Création de $PROFILES_XMLTMP et $HOSTS_XML
  46  
  47  
  48  echo '<?xml version="1.0" encoding="iso-8859-1"?>' > $PROFILES_XMLTMP
  49  echo '<!-- Généré par SambaEdu. Ne pas modifier -->' >> $PROFILES_XMLTMP
  50  echo '<profiles>' >> $PROFILES_XMLTMP
  51  echo '<?xml version="1.0" encoding="iso-8859-1"?>' > $HOSTS_XML
  52  echo '<!-- Généré par SambaEdu. Ne pas modifier -->' >> $HOSTS_XML
  53  echo '<wpkg>' >> $HOSTS_XML
  54  # Ajout d'un profile pour chaque parc et pour chaque machine
  55  # Chaque profile poste depend du profile des parcs auxquels il appartient ainsi que du profile $TousLesPostes
  56  # Seuls les postes ayant un compte (WinXP et2K) sont répertoriés.
  57  
  58  # echo "ldapsearch -x -LLL -S 'cn' -b \"$ParcsRDN,$BaseDN\" '(cn=*)' cn member"
  59  ldapsearch -x -LLL -S 'cn' -b "$ParcsRDN,$BaseDN" '(cn=*)' cn member | 
  60      gawk '  BEGIN {
  61                  print "<profile id=\"'$TousLesPostes'\" />";
  62              }
  63              /^cn: /{
  64                  parc=$2;
  65                  print "<profile id=\"" parc "\" />";
  66              }
  67              /^member: /{
  68                  if ( split($2,a,"[=,]") > 2 ) {
  69                      HOST=tolower(a[2]);
  70                      tempParc[ HOST ] = HOST;
  71                  }
  72              }
  73              /^$/ {
  74                  for ( HOST in tempParc ) {
  75                      parcs[HOST] = parcs[HOST] ";" parc ;
  76                  }
  77                  delete tempParc;
  78                  parcsConnus[parc] = 1;
  79                  parc = "";
  80              }
  81              END {
  82                  for ( HOST in parcs ) {
  83                      if ( not (HOST in parcsConnus) ) {
  84                          parcs[HOST] = "'$TousLesPostes'" parcs[HOST] ;
  85                          hosts[HOST] = HOST;
  86                          ListHosts = ListHosts "(uid=" HOST "$)"
  87                      }
  88                  }
  89                  ListHosts = "ldapsearch -x -LLL -S \"uid\" -b \"'$ComputersRDN','$BaseDN'\" \"(|" ListHosts ")\" uid";
  90                  while ( ListHosts | getline ) {
  91                      if ( $1 == "uid:" ) {
  92                          sub("\\$", "", $2);
  93                          HOST = tolower($2);
  94                          print "<profile id=\""HOST"\" >";
  95                          split(parcs[HOST], a, ";");
  96                          for (iparc in a) {
  97                              if ( a[iparc] != "" ) {
  98                                  print "<depends profile-id=\"" a[iparc] "\" />";
  99                              }
 100                          }
 101                          print "</profile>";
 102                          print "<host name=\""HOST"\" profile-id=\""HOST"\" />" >> "'$HOSTS_XML'";
 103                      }
 104                  }
 105              }' >> $PROFILES_XMLTMP
 106  # Fermeture du noeud profiles de $PROFILES_XMLTMP et wpkg de $HOSTS_XML
 107  echo '</profiles>' >> $PROFILES_XMLTMP
 108  echo '</wpkg>' >> $HOSTS_XML
 109  
 110  # Profile profiles.xml
 111  if [ ! -e $PROFILES_XML ]; then
 112  cat - > $PROFILES_XML <<ProfilesXML
 113  <?xml version="1.0" encoding="iso-8859-1"?>
 114  <profiles>
 115    <profile id="_TousLesPostes">
 116      <package package-id="time" />
 117    </profile>
 118  </profiles>
 119  ProfilesXML
 120  fi
 121  
 122  # Réassocie les packages des profiles qui existaient dans profiles.xml
 123  gawk '{printf("%s",$0)}' $PROFILES_XMLTMP | xsltproc --output $PROFILES_XML $wpkgwebdir/bin/addPackages.xsl -
 124  #[ -e $PROFILES_XMLTMP ] && rm $PROFILES_XMLTMP


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