[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-clonage/sources/debian/ -> postinst (source)

   1  #!/bin/bash
   2  # postinst script for se3-clonage
   3  #
   4  # see: dh_installdeb(1)
   5  
   6  set -e
   7  
   8  # summary of how this script can be called:
   9  #        * <postinst> `configure' <most-recently-configured-version>
  10  #        * <old-postinst> `abort-upgrade' <new version>
  11  #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  12  #          <new-version>
  13  #        * <postinst> `abort-remove'
  14  #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  15  #          <failed-install-package> <version> `removing'
  16  #          <conflicting-package> <version>
  17  # for details, see http://www.debian.org/doc/debian-policy/ or
  18  # the debian-policy package
  19  
  20  
  21  case "$1" in
  22      install|configure)
  23  
  24  . /usr/share/se3/includes/config.inc.sh -lmd
  25  
  26  mysqlrequest="mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N"
  27  
  28  test_exist=`echo "SELECT value FROM params WHERE name='clonage'" | $mysqlrequest`
  29  if [ "X$test_exist" = "X" ]; then # if empty
  30      echo "INSERT INTO params VALUES ('', 'clonage', '0', 0, 'Activation du serveur de boot pxe - udpcast / unattented', 6)" |$mysqlrequest
  31  fi
  32  
  33  echo "CREATE TABLE IF NOT EXISTS se3_tftp_action (
  34  id INT(11),
  35  mac VARCHAR(255),
  36  name VARCHAR(255),
  37  date INT(11),
  38  type VARCHAR(255),
  39  num_op INT(11),
  40  infos VARCHAR(255)
  41  );" |$mysqlrequest
  42  
  43  echo "CREATE TABLE IF NOT EXISTS se3_tftp_sauvegardes (
  44  id INT( 11 ) NOT NULL ,
  45  name VARCHAR( 255 ) NOT NULL ,
  46  mac VARCHAR( 255 ) NOT NULL ,
  47  partition VARCHAR( 255 ) NOT NULL ,
  48  image VARCHAR( 255 ) NOT NULL ,
  49  date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  50  descriptif TEXT NOT NULL,
  51  df TEXT NOT NULL,
  52  partitionnement TEXT NOT NULL,
  53  identifiant int(11) NOT NULL auto_increment,
  54  PRIMARY KEY  (identifiant)
  55  );" |$mysqlrequest
  56  
  57  
  58      echo "CREATE TABLE IF NOT EXISTS se3_tftp_rapports (
  59  id INT( 11 ) NOT NULL ,
  60  name VARCHAR( 255 ) NOT NULL ,
  61  mac VARCHAR( 255 ) NOT NULL ,
  62  date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  63  tache VARCHAR( 255 ) NOT NULL ,
  64  statut VARCHAR( 255 ) NOT NULL ,
  65  descriptif TEXT NOT NULL,
  66  identifiant int(11) NOT NULL auto_increment,
  67  PRIMARY KEY  (identifiant)
  68  );" |$mysqlrequest
  69  
  70  
  71      echo "CREATE TABLE IF NOT EXISTS se3_tftp_infos (
  72  id INT( 11 ) NOT NULL ,
  73  name VARCHAR( 255 ) NOT NULL ,
  74  mac VARCHAR( 255 ) NOT NULL ,
  75  nom VARCHAR( 255 ) NOT NULL ,
  76  valeur VARCHAR( 255 ) NOT NULL ,
  77  identifiant int(11) NOT NULL auto_increment,
  78  PRIMARY KEY  (identifiant)
  79  );" |$mysqlrequest
  80  
  81  
  82  # Test du nombre de caracteres du champ name de se3db.params
  83  # debut_nom_champ="a$(date +%Y%m%d%H%M%S)"
  84  # nom_champ_tmp="${debut_nom_champ}0123456789012345"
  85  # 
  86  # # Enregistrement d'une valeur temporaire
  87  # echo "INSERT INTO params SET name='$nom_champ_tmp';" | $mysqlrequest
  88  # 
  89  # test_champ=`echo "SELECT 1=1 FROM params WHERE name='$nom_champ_tmp';" | $mysqlrequest`
  90  # if [ -z "$test_champ" ]; then
  91  #     echo "ALTER TABLE params CHANGE name name VARCHAR( 30 );" | $mysqlrequest
  92  # fi
  93  # 
  94  # # Menage:
  95  # echo "DELETE FROM params WHERE name LIKE '$debut_nom_champ%';"| $mysqlrequest
  96  
  97  #==============================================================================
  98  
  99  # on rend executable les script sudo et sbin
 100  for i in se3_tftp_boot_pxe.sh pxe_gen_cfg.sh recup_rapport.php se3_tftp_menage_atq.sh se3_pxe_menu_ou_pas.sh set_password_menu_tftp.sh se3_pxe_slitaz_cmdline.sh se3_get_sysresccd.sh se3_get_slitaz.sh se3_get_udpcast.sh
 101  do
 102      if [ -e /usr/share/se3/scripts/$i ]; then
 103          chmod +x /usr/share/se3/scripts/$i
 104          chown www-se3 /usr/share/se3/scripts/$i
 105      fi
 106  done
 107  
 108  if [ -e /usr/share/se3/sbin/controle_actions_tftp.sh ]; then
 109      chmod +x /usr/share/se3/sbin/controle_actions_tftp.sh
 110  fi
 111  #==============================================================================
 112  
 113  
 114  # Ajout d'un droit pour que des personnes auxquelles un parc est delegue 'manage' puissent sauvegarder, restaurer, cloner,... sur ce parc
 115  t=$(ldapsearch -xLLL -b $rightsRdn},$ldap_base_dn} cn=parc_can_clone)
 116  if [ -z "$t" ]; then
 117      echo "dn: cn=parc_can_clone,$rightsRdn},$ldap_base_dn}
 118  objectClass: groupOfNames
 119  cn: parc_can_clone
 120  member: uid=admin,$peopleRdn},$ldap_base_dn}
 121  " | ldapadd -x -D $adminRdn},$ldap_base_dn} -w $adminPw}
 122  fi
 123  
 124  #==============================================================================
 125  
 126  ##### ADD good line in /etc/sudoers.conf if necessary and restart sudo
 127  TEMOIN_CHGT_SUDO="n"
 128  # TEST=$(grep "NOPASSWD:SE3CLONAGE" /etc/sudoers)
 129  # if [ ! "$(grep "NOPASSWD:SE3CLONAGE" /etc/sudoers)" ]; then
 130  #     # Insertion de l'autorisation de lancement par www-se3
 131  #     sed -i 's/^\(www-se3.*\)$/\1,NOPASSWD:SE3CLONAGE/' /etc/sudoers
 132  #     TEMOIN_CHGT_SUDO="y"
 133  # fi
 134  
 135  TEST=$(cat /etc/sudoers | grep "Cmnd_Alias SE3CLONAGE")
 136  
 137  if [ ! "$(grep "Cmnd_Alias SE3CLONAGE" /etc/sudoers)" ]; then
 138      # On insere toute la ligne des commandes
 139      sed -i 's|^\(# Cmnd alias specification.*\)$|\1\nCmnd_Alias SE3CLONAGE=/usr/share/se3/scripts/se3_tftp_boot_pxe.sh,/usr/share/se3/scripts/pxe_gen_cfg.sh,/usr/share/se3/scripts/recup_rapport.php,/usr/share/se3/scripts/se3_tftp_menage_atq.sh,/usr/share/se3/scripts/se3_pxe_menu_ou_pas.sh,/usr/share/se3/scripts/set_password_menu_tftp.sh,/usr/share/se3/scripts/se3_pxe_slitaz_cmdline.sh,/usr/share/se3/scripts/se3_get_sysresccd.sh,/usr/share/se3/scripts/se3_get_slitaz.sh,/usr/share/se3/scripts/se3_get_udpcast.sh|' /etc/sudoers
 140      TEMOIN_CHGT_SUDO="y"
 141  else
 142      # La ligne Cmnd_Alias SE3CLONAGE existe deja (avec au moins une commande donc)
 143  
 144      for i in se3_tftp_boot_pxe.sh pxe_gen_cfg.sh recup_rapport.php se3_tftp_menage_atq.sh se3_pxe_menu_ou_pas.sh set_password_menu_tftp.sh se3_pxe_slitaz_cmdline.sh se3_get_sysresccd.sh se3_get_slitaz.sh se3_get_udpcast.sh se3_get_install_client_linux.sh
 145      do
 146          if [ ! "$(grep "/usr/share/se3/scripts/$i" /etc/sudoers)" ]; then
 147              # On ajoute la commande au premier rang
 148              sed -i "s|Cmnd_Alias SE3CLONAGE=|Cmnd_Alias SE3CLONAGE=/usr/share/se3/scripts/$i,|" /etc/sudoers
 149              TEMOIN_CHGT_SUDO="y"
 150          fi
 151      done
 152  fi
 153  
 154  if [ "$TEMOIN_CHGT_SUDO" = "y" ]; then
 155      /etc/init.d/sudo restart
 156  fi
 157  
 158  #==============================================================================
 159  
 160  # Pour toujours utiliser la derniere version des outils pxelinux
 161  if [ -e /tftpboot/pxelinux.0 ]; then
 162      rm -f /tftpboot/pxelinux.0
 163  fi
 164  
 165  #for A in chain.c32 cpuidtest.c32 dmitest.c32 ethersel.c32 mboot.c32 menu.c32 pcitest.c32 vesamenu.c32 pxelinux.0
 166  #do
 167  #    if [ ! -e "/tftpboot/$A" ]; then
 168  #        ln -s /usr/lib/syslinux/$A /tftpboot
 169  #    fi
 170  #done
 171  
 172  ls /usr/lib/syslinux/ | egrep -v "(\.com$|\.exe$|\.gz$)" | while read A
 173  do 
 174      if [ ! -e /tftpboot/$A ]; then
 175      ln -s /usr/lib/syslinux/$A /tftpboot/$A 
 176      fi
 177      
 178  done
 179  
 180  #==============================================================================
 181  # Configuration des scripts dans /tftpboot d'apres les enregistrements en cours
 182  # tftp_aff_menu_pxe=$(echo "SELECT value FROM params WHERE name='tftp_aff_menu_pxe';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 183  # tftp_pass_menu_pxe=$(echo "SELECT value FROM params WHERE name='tftp_pass_menu_pxe';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 184  # tftp_slitaz_cmdline=$(echo "SELECT value FROM params WHERE name='tftp_slitaz_cmdline';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 185  
 186  
 187  if [ "$tftp_aff_menu_pxe}" != "y" ]; then
 188      /usr/share/se3/scripts/se3_pxe_menu_ou_pas.sh 'standard'
 189  else
 190      /usr/share/se3/scripts/se3_pxe_menu_ou_pas.sh 'menu'
 191  fi
 192  
 193  if [ "$tftp_pass_menu_pxe}" != "" ]; then
 194      /usr/share/se3/scripts/set_password_menu_tftp.sh "$tftp_pass_menu_pxe}"
 195  fi
 196  
 197  if [ "$tftp_slitaz_cmdline}" != "" ]; then
 198      /usr/share/se3/scripts/se3_pxe_slitaz_cmdline.sh "$tftp_slitaz_cmdline}"
 199  fi
 200  #==============================================================================
 201  
 202  mkdir -p /etc/se3/www-tools/tftp
 203  chmod 770 /etc/se3/www-tools/tftp
 204  chown www-se3:root /etc/se3/www-tools/tftp
 205  if [ -e "/tftpboot/pxelinux.cfg" ]; then
 206    chown www-se3:root /tftpboot/pxelinux.cfg
 207  fi
 208  
 209  /usr/sbin/update-rc.d -f atftpd remove
 210  mkdir -p /srv
 211  if [ ! -h /srv/tftp ]; then
 212      rm -rf /srv/tftp 
 213      ln -s /tftpboot /srv/tftp 
 214  fi
 215  
 216  # Activation par inetd.conf
 217  [ "$test_exist" != "0" ] && /usr/share/se3/scripts/se3_tftp_boot_pxe.sh start
 218  
 219  # Pour renseigner le fichier param.ini du paquet post-clonage
 220  if [ -e /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini -a -z "$(grep 'Ne pas modifier' /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini)" ]; then
 221  #     dhcp_iface=$(echo "SELECT value FROM params WHERE name='dhcp_iface';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 222  #     netmask=$(/sbin/ifconfig $dhcp_iface |/bin/grep 'inet ' |/usr/bin/cut -d":" -f4 |/usr/bin/cut -d' '  -f1)
 223  #     dhcp_gateway=$(echo "SELECT value FROM params WHERE name='dhcp_gateway';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 224  #     dhcp_dns_server_prim=$(echo "SELECT value FROM params WHERE name='dhcp_dns_server_prim';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 225  #     dhcp_wins=$(echo "SELECT value FROM params WHERE name='dhcp_wins';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 226  #     se3_domain=$(echo "SELECT value FROM params WHERE name='se3_domain';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 227  #     se3ip=$(echo "SELECT value FROM params WHERE name='se3ip';" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N)
 228  #     
 229  
 230      if [ -n "$dhcp_iface" -a -n "$se3mask" -a -n "$dhcp_gateway" -a -n "$dhcp_dns_server_prim" -a -n "$dhcp_wins" -a -n "$se3_domain" -a -n "$se3ip" ]; then
 231          cp /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini.$(date +%Y%m%d%%H%M%S)
 232  
 233          prefip=$(echo "$se3ip" | cut -d'.' -f1)
 234  
 235          octet=$(echo "$se3mask" | cut -d'.' -f2)
 236          if [ "$octet" = "255" ]; then
 237              prefip="$prefip."$(echo "$se3ip" | cut -d'.' -f2)
 238  
 239              octet=$(echo "$se3mask" | cut -d'.' -f3)
 240              if [ "$octet" = "255" ]; then
 241                  prefip="$prefip."$(echo "$se3ip" | cut -d'.' -f3)    
 242              fi
 243          fi
 244          prefip="$prefip."
 245  
 246          echo "GW=$dhcp_gateway
 247  MASK=$se3mask
 248  DNS=$dhcp_dns_server_prim
 249  WINS=$dhcp_wins
 250  PREFIP=$prefip
 251  SMB_DOMAIN=$se3_domain
 252  " > /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini.tmp
 253          cat /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini.tmp | perl -pe 's/\n/\r\n/' > /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini
 254          rm -f /var/se3/Progs/install/paquet_post-clonage/temp/clone/param.ini.tmp
 255      fi
 256  fi
 257  
 258  # Pour tenir compte des prochaines versions SysRescCD:
 259  if [ ! -e /tftpboot/rescue32 -a -e /tftpboot/rescuecd ]; then
 260      cd /tftpboot && mv rescuecd rescue32 && ln -s rescue32 rescuecd
 261      # On pourrait plutot forcer un telechargement de la nouvelle version SysRescCD:
 262      # L'absence de rescuecd et rescue32 inviterait au telechargement.
 263      #cd /tftpboot && rm rescuecd
 264  fi
 265      ;;
 266  
 267      abort-upgrade|abort-remove|abort-deconfigure)
 268      ;;
 269  
 270      *)
 271          echo "postinst called with unknown argument \`$1'" >&2
 272          exit 1
 273      ;;
 274  esac
 275  
 276  # dh_installdeb will replace this with shell code automatically
 277  # generated by other debhelper scripts.
 278  
 279  
 280  
 281  exit 0
 282  
 283  


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