[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/includes/ -> config.inc.sh (source)

   1  #!/bin/bash
   2  
   3  ## $Id: config.inc.sh 7309 2012-06-28 17:02:32Z dbo $ ##
   4  #
   5  ##### script permettant la lecture des infos dans la table params de mysql #####
   6  #
   7  
   8  
   9  # unset CONFIG LDAP PATHSE3 BACKUP SYSTEM HIDE VERSBOSE
  10  function usage {
  11      echo "script permettant la lecture des infos dans la table params de mysql" 
  12      echo "usage: $0 -c -l -p -b -h -s -m -d -o -f"
  13      echo "       -c :  parametres de configuration generale, ex urlse3"
  14      echo "       -l :  parametres ldap, ex ldap_base_dn"
  15      echo "       -p :  chemins, ex path_to_wwwse3"
  16      echo "       -b :  parametres sauvegarde, ex bck_user"
  17      echo "       -m :  parametres masques, ex xppass"
  18      echo "       -s :  parametres systemes, ex quota_warn_home "
  19      echo "       -d :  parametres dhcp, ex dhcp_iface"
  20      echo "       -o :  only : uniquement les variables pour interroger mysql"
  21      echo "       -h :  show this help"
  22      echo "       -v :  mode verbeux : liste les variables initialisees"
  23      echo "       -f :  ecrit les parametres selectionnes dans les ficihers cache /etc/se3/config_*.cache.sh "
  24      exit $1
  25  }
  26  
  27  
  28  function getmypasswd {
  29  
  30  WWWPATH="/var/www"
  31  if [ -e $WWWPATH/se3/includes/config.inc.php ]; then
  32  dbhost=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbhost=" | cut -d = -f 2 |cut -d \" -f 2`
  33  dbname=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbname=" | cut -d = -f 2 |cut -d \" -f 2`
  34  dbuser=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbuser=" | cut -d = -f 2 |cut -d \" -f 2`
  35  dbpass=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbpass=" | cut -d = -f 2 |cut -d \" -f 2`
  36  else
  37      echo "Fichier de conf inaccessible."
  38      exit 1
  39  fi
  40  }
  41  
  42  function getmysql {
  43  getmypasswd
  44  if [ "$2" == "2" ]; then
  45      echo "# parametres se3, ne pas modifier" > $3
  46  fi
  47  
  48  for i in $(echo "SELECT name FROM params WHERE cat='$1'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass | grep -v "^name$")
  49  do
  50      eval $i="$(echo "SELECT value FROM params WHERE name='$i' " | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N | sed -e "s/[()]//g"|sed -e "s/ /_/g")"
  51      if [ "$2" == "1" ]; then
  52          echo "$i-->${!i}"
  53      elif [ "$2" == "2" ]; then
  54          echo "$i=\"${!i}\"" >> $3
  55      fi
  56  done
  57  if [ "$2" == "2" ]; then
  58      chmod 700 $3
  59  fi
  60  
  61  }
  62  
  63  
  64  if [ $# -eq "0" ]  # Script appele sans argument?
  65  then
  66    echo "option incorrecte"
  67    usage 1 
  68  fi
  69  
  70  VERSBOSE=0
  71  while getopts ":clpbmsdvhof" cmd
  72  do
  73      case $cmd in    
  74      c) CONFIG=1 ;;
  75      l) LDAP=1 ;;
  76      p) PATHSE3=1 ;;
  77      b) BACKUP=1 ;;
  78      m) HIDE=1 ;;
  79      s) SYSTEM=1 ;;
  80      d) DHCP=1 ;;
  81      o|v) VERSBOSE=1 ;;
  82      f) VERSBOSE=2 ;;
  83      h) usage 0 ;;
  84      \?) echo "bad option!"
  85      usage 1 ;;
  86      *) echo "bad option!"
  87      usage 1 ;;
  88      esac
  89      fichier=/etc/se3/config_$cmd.cache.sh
  90  done
  91  
  92  if [ "$VERSBOSE" == "1" ]; then
  93      getmypasswd
  94      echo "dbhost-->$dbhost}"
  95      echo "dbname-->$dbname}"
  96      echo "dbuser-->$dbuser}"
  97      echo "dbpass-->$dbpass}"
  98  elif [ "$VERSBOSE" == "2" ]; then
  99      getmypasswd
 100      fichier=/etc/se3/config_o.cache.sh
 101      echo "dbhost=\"$dbhost}\"" > $fichier
 102      echo "dbname=\"$dbname}\"" >> $fichier
 103      echo "dbuser=\"$dbuser}\"" >> $fichier
 104      echo "dbpass=\"$dbpass}\"" >> $fichier
 105      chmod 700 $fichier
 106      chown -R www-se3 /etc/se3
 107  fi
 108  
 109  
 110  proxy=$(grep "http_proxy=" /etc/profile | head -n 1 | sed -e "s#.*//##;s/\"//")
 111  
 112  if [ ! -z "$proxy" ]; then
 113  export http_proxy="http://$proxy"
 114  export https_proxy="http://$proxy"
 115  export ftp_proxy="http://$proxy"
 116  fi
 117  
 118  
 119  if [ "$CONFIG" == "1" ]; then
 120      getmysql "1" $VERSBOSE /etc/se3/config_c.cache.sh
 121      
 122  fi
 123  
 124  if  [ "$LDAP" == "1" ]; then
 125  getmysql "2" $VERSBOSE /etc/se3/config_l.cache.sh
 126  fi
 127  
 128  if [ "$PATHSE3" == "1" ]; then 
 129  getmysql "3" $VERSBOSE /etc/se3/config_p.cache.sh
 130  fi
 131  
 132  if [ "$BACKUP" == "1" ]; then 
 133  getmysql "5" $VERSBOSE /etc/se3/config_b.cache.sh
 134  fi
 135  
 136  if [ "$HIDE" == "1" ]; then
 137  getmysql "4" $VERSBOSE /etc/se3/config_m.cache.sh
 138  fi
 139  
 140  if [ "$SYSTEM" == "1" ]; then
 141  getmysql "6" $VERSBOSE /etc/se3/config_s.cache.sh
 142  fi
 143  
 144  if [ "$DHCP" == "1" ]; then
 145  getmysql "7" $VERSBOSE /etc/se3/config_d.cache.sh
 146  fi
 147  


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