[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #! /bin/bash
   2  # postinst script for se3-dhcp
   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  #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  14  #          <failed-install-package> <version> `removing'
  15  #          <conflicting-package> <version>
  16  # for details, see http://www.debian.org/doc/debian-policy/ or
  17  # the debian-policy package
  18  #
  19  
  20  case "$1" in
  21      install|configure)
  22  
  23  IS_IP() # Return EMPTY or IP adress if correct
  24  {
  25  test=`echo "$1" | sed -n -e "s/^\(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)$/\1/p"`
  26  if [ "X$test" = "X" ] ; then
  27      echo ""
  28  else
  29      echo "$1"
  30  fi
  31  }
  32  
  33  
  34  
  35  
  36  
  37  ### on suppose que l'on est sous debian  ####
  38  WWWPATH="/var/www"
  39  ## recuperation des variables necessaires pour interoger mysql ###
  40  . /usr/share/se3/includes/config.inc.sh -s -o -v -m > /dev/null
  41  ## Take some variables for initializing dhcp parameter (gateway / dns / wins ...)
  42  
  43  device=`/sbin/ifconfig | grep Ethernet |cut -d" " -f 1 | head -n 1`
  44  dns_primary=`cat /etc/resolv.conf | grep nameserver | cut -d" "  -f 2 | head -n 1`
  45  dns_secondary=`cat /etc/resolv.conf | grep nameserver | cut -d" "  -f 2 | head -n 2 | tail -n 1`
  46  gateway=`cat /etc/network/interfaces | grep gateway | grep -v -e ^\# | sed -n -e "s/^.*gateway[[:space:]]*\(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*$/\1/p" `
  47  
  48  
  49  dns_primary=`IS_IP "$dns_primary"`
  50  dns_sec=`IS_IP "$dns_sec"`
  51  gateway=`IS_IP "$gateway"`
  52  
  53  domain_name=`echo "SELECT value FROM params WHERE name='domain' " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  54  
  55  
  56  echo "ALTER TABLE params CHANGE descr descr VARCHAR( 100 )" | mysql $dbname -u $dbuser -p$dbpass
  57  ##########################################################################################
  58  ## Put mysql conf data in se3db base######################################################
  59  ##### Activation du dhcp dans l'interface web 
  60  test_exist=`echo "SELECT id FROM params WHERE name='dhcp'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  61  if [ "X$test_exist" = "X" ]; then # if empty
  62      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp\",\"1\",\"\",\"Activation du dhcp  dans l'interface web\",6) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  63  fi
  64  #SETMYSQL "dhcp" 1 "Activation du dhcp  dans l'interface web" 6
  65  
  66  ##### Activate dhcp on boot ? non jusqu'a la conf du dhcp
  67  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_on_boot'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  68  if [ "X$test_exist" = "X" ]; then # if empty
  69      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_on_boot\",\"1\",\"\",\"Activation du dhcp au boot\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  70      ##### DHCP3-SERVER does not start oin boot after install ...
  71      /usr/sbin/update-rc.d -f dhcp3-server remove
  72  else
  73       echo "UPDATE params SET cat=7 WHERE name='dhcp_on_boot'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  74  
  75  fi
  76  
  77  ##### Interface who dhcp listen by default firs iface
  78  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_iface'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  79  if [ "X$test_exist" = "X" ]; then # if empty
  80      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_iface\",\"$device\",\"\",\"Interface d'écoute du dhcp \",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  81  else
  82       echo "UPDATE params SET cat=7 WHERE name='dhcp_iface'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  83  
  84  fi
  85  ##### begin range reservations
  86  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_ip_min'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  87  if [ "X$test_exist" = "X" ]; then # if empty
  88      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_ip_min\",\"\",\"\",\"Début de la plage de reservation (par defaut network + 51) \",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  89  else
  90       echo "UPDATE params SET cat=7,descr=\"Début de la plage de reservation (par defaut network + 51)\" WHERE name='dhcp_ip_min'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  91  fi
  92  
  93  ##### begin range dynamic
  94  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_begin_range'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  95  if [ "X$test_exist" = "X" ]; then # if empty
  96      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_begin_range\",\"\",\"\",\"Début de la plage dynamique\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  97  else
  98       echo "UPDATE params SET cat=7 WHERE name='dhcp_begin_range'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
  99  fi
 100  ##### end range dynamic
 101  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_end_range'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 102  if [ "X$test_exist" = "X" ]; then # if empty
 103      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_end_range\",\"\",\"\",\"Fin de la plage dynamique\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 104  else
 105       echo "UPDATE params SET cat=7 WHERE name='dhcp_end_range'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 106  
 107  fi
 108  ##### DNS PRIMARY
 109  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_dns_server_prim'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 110  if [ "X$test_exist" = "X" ]; then # if empty
 111      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_dns_server_prim\",\"$dns_primary\",\"\",\"Serveur DNS primaire\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 112  else
 113       echo "UPDATE params SET cat=7 WHERE name='dhcp_dns_server_prim'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 114  
 115  fi
 116  ##### DNS SECONDARY
 117  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_dns_server_sec'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 118  if [ "X$test_exist" = "X" ]; then # if empty
 119      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_dns_server_sec\",\"$dns_secondary\",\"\",\"Serveur DNS secondaire\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 120  else
 121       echo "UPDATE params SET cat=7 WHERE name='dhcp_dns_server_sec'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 122  
 123  fi
 124  ##### GATEWAY
 125  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_gateway'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 126  if [ "X$test_exist" = "X" ]; then # if empty
 127      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_gateway\",\"$gateway\",\"\",\"Passerelle\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 128  else
 129       echo "UPDATE params SET cat=7 WHERE name='dhcp_gateway'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 130  
 131  fi
 132  ##### WINS SERVER it's se3 ip by default
 133  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_wins'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 134  if [ "X$test_exist" = "X" ]; then # if empty
 135      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_wins\",\"$se3ip\",\"\",\"Serveur wins\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 136  else
 137       echo "UPDATE params SET cat=7 WHERE name='dhcp_wins'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 138  fi
 139  
 140  ##### NTP server
 141  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_ntp'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 142  if [ "X$test_exist" = "X" ]; then # if empty
 143      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_ntp\",\"\",\"\",\"Serveur de temps\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 144  else
 145       echo "UPDATE params SET cat=7 WHERE name='dhcp_ntp'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 146  fi
 147  
 148  ##### MAX lease
 149  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_max_lease'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 150  if [ "X$test_exist" = "X" ]; then # if empty
 151      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_max_lease\",\"72000\",\"\",\"Bail maximum\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 152  else
 153       echo "UPDATE params SET cat=7 WHERE name='dhcp_max_lease'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 154  
 155  fi
 156  
 157  ##### Default lease
 158  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_default_lease'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 159  if [ "X$test_exist" = "X" ]; then # if empty
 160      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_default_lease\",\"6000\",\"\",\"Bail par défaut\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 161  else
 162       echo "UPDATE params SET cat=7 WHERE name='dhcp_default_lease'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 163  fi
 164  
 165  ##### Domain name
 166  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_domain_name'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 167  if [ "X$test_exist" = "X" ]; then # if empty
 168      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_domain_name\",\"$domain_name\",\"\",\"Nom du domaine\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 169  else
 170       echo "UPDATE params SET cat=7 WHERE name='dhcp_domain_name'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 171  fi
 172  
 173  ##### serveur tftp
 174  ##### next-server IPTFTP;
 175  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_tftp_server'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 176  if [ "X$test_exist" = "X" ]; then # if empty
 177      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_tftp_server\",\"$se3ip\",\"\",\"Serveur TFTP\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 178  else
 179       echo "UPDATE params SET cat=7 WHERE name='dhcp_tftp_server'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 180  fi
 181  
 182  ##### UNATTENDED PARAMS*
 183  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_unatt_login'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 184  if [ "X$test_exist" = "X" ]; then # if empty
 185      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_unatt_login\",\"\",\"\",\"Nom d'utilisateur pour unattended\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 186  else
 187       echo "UPDATE params SET cat=7 WHERE name='dhcp_unatt_login'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 188  fi
 189  
 190  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_unatt_pass'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 191  if [ "X$test_exist" = "X" ]; then # if empty
 192      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_unatt_pass\",\"\",\"\",\"Mot de passe pour unattended\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 193  else
 194       echo "UPDATE params SET cat=7 WHERE name='dhcp_unatt_pass'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 195  fi
 196  
 197  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_unatt_filename'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 198  if [ "X$test_exist" = "X" ]; then # if empty
 199      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_unatt_filename\",\"pxelinux.0\",\"\",\"Fichier de boot PXE utilisé pour udpcast ou unattented\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 200  else
 201       echo "UPDATE params SET cat=7 WHERE name='dhcp_unatt_filename'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 202  fi
 203  # extra option
 204  test_exist=`echo "SELECT id FROM params WHERE name='dhcp_extra_option'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
 205  if [ "X$test_exist" = "X" ]; then # if empty
 206      echo "INSERT into params (name,value,srv_id,descr,cat) VALUES (\"dhcp_extra_option\",\"\",\"\",\"Fichier de conf a inclure (chemin absolu)\",7) " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 207  else
 208       echo "UPDATE params SET cat=7,descr=\"Fichier de conf a inclure (chemin absolu)\" WHERE name='dhcp_extra_option'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N
 209  fi
 210  
 211  
 212  ##### nom du fichier PXE
 213  #  filename "pxelinux.0";
 214  # parametres de cx samba
 215  ##### option option-233 "z_user=USERINSTALL z_pass=PASSINSTALL z_path=//IPUNATT/unattended";
 216  
 217  
 218  
 219  ##### sudo script for make dhcpd conf 
 220  chmod +x /usr/share/se3/scripts/makedhcpdconf
 221  
 222  ##### Now create table if not exist for recorded dhcp computers
 223  mysql -h $dbhost $dbname -u $dbuser -p$dbpass < /var/cache/se3_install/se3-dhcp/se3-dhcp.sql >/dev/null 2>&1
 224  
 225  
 226  
 227  ##### SVG dhcp.conf if exist
 228  if [ -f /etc/dhcp/dhcpd.conf ]; then
 229      mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.svg.SE3
 230      /usr/share/se3/scripts/makedhcpdconf
 231  fi
 232  
 233  # actualisation du cache des parametres : 
 234  
 235  /usr/share/se3/includes/config.inc.sh -clpbmsdf 
 236  
 237  
 238  ##### END POSTINST se3-dhcp installed
 239  
 240  
 241  
 242  ##### ADD good line in /etc/sudoers.conf if necessary and restart sudo
 243  # if [  ! "`cat /etc/sudoers | grep SE3DHCP`" ]; then
 244  # sed -i 's/^\(www-se3.*\)$/\1,NOPASSWD:SE3DHCP/'  /etc/sudoers
 245  # sed -i 's|^\(# Cmnd alias specification.*\)$|\1\nCmnd_Alias SE3DHCP=/usr/share/se3/scripts/makedhcpdconf,/usr/share/se3/scripts/move_dhcp_leases.sh|' /etc/sudoers
 246  # /etc/init.d/sudo restart
 247  # else
 248  #     # La ligne Cmnd_Alias SE3DHCP existe déjà (avec au moins une commande 
 249  #     if [ ! "$(grep "/usr/share/se3/scripts/move_dhcp_leases.sh" /etc/sudoers)" ]; then
 250  #         # On ajoute la commande au premier rang
 251  #         sed -i 's|Cmnd_Alias SE3DHCP=|Cmnd_Alias SE3DHCP=/usr/share/se3/scripts/move_dhcp_leases.sh,|' /etc/sudoers
 252  #         TEMOIN_CHGT_SUDO="y"
 253  #     fi
 254  # 
 255  # fi
 256  
 257      ;;
 258  
 259      abort-upgrade|abort-remove|abort-deconfigure)
 260  
 261      ;;
 262  
 263      *)
 264          echo "postinst called with unknown argument \`$1'" >&2
 265          exit 1
 266      ;;
 267  esac
 268  
 269  # dh_installdeb will replace this with shell code automatically
 270  # generated by other debhelper scripts.
 271  
 272  #DEBHELPER#
 273  
 274  exit 0
 275  
 276  


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