Show
Ignore:
Timestamp:
12/09/11 11:18:20 (1 year ago)
Author:
p_lindheimer
Message:

add some logging, add set-freepbx-settings option (experimental untested), make parser force booleans

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.10/install_amp

    r12996 r13054  
    8080  foreach ($file as $line) { 
    8181    if (preg_match("/^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/",$line,$matches)) {  
    82       $conf[ $matches[1] ] = $matches[2]; 
     82 
     83      // TODO: force booleans into 0/1 this should be ok given the limited number of configuration values 
     84      // 
     85      switch (trim(strtolower($matches[2]))) { 
     86      case 'false': 
     87      case 'no': 
     88      case 'off': 
     89      case '0': 
     90        $conf[$matches[1]] = '0'; 
     91      case 'true': 
     92      case 'yes': 
     93      case 'on': 
     94      case '1': 
     95        $conf[$matches[1]] = '1'; 
     96      default: 
     97        $conf[$matches[1]] = $matches[2]; 
     98      break; 
     99      } 
    83100    } 
    84101  } 
     
    95112  if ( !isset($conf["AMPENGINE"]) || ($conf["AMPENGINE"] == "")) { 
    96113    $conf["AMPENGINE"] = "asterisk"; 
     114  } 
     115  out("parsed amp_conf variables from $filename:"); 
     116  foreach ($conf as $keyword => $value) { 
     117    out("amp_conf [$keyword] => [$value]"); 
    97118  } 
    98119 
     
    577598// **** Parse out command-line options 
    578599$shortopts = "h?u:p:"; 
    579 $longopts = array("help","debug","dry-run","username=","password=","force-version=","dbhost=","no-files","force-overwrite","dbname=","my-svn-is-correct","engine=","webroot=","install-moh","install-fop=","make-links-devel","dev-links","skip-module-install","uid=","gid=","scripted","freepbxip=","asteriskip="); 
     600$longopts = array("help","debug","dry-run","username=","password=","force-version=","dbhost=","no-files","force-overwrite","dbname=","my-svn-is-correct","engine=","webroot=","install-moh","install-fop=","make-links-devel","dev-links","skip-module-install","uid=","gid=","scripted","freepbxip=","asteriskip=","set-freepbx-settings"); 
    580601 
    581602$args = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), $shortopts, $longopts); 
     
    595616$make_links = false; 
    596617$module_install = true; 
     618$set_freepbx_settings = false; 
    597619 
    598620//initialize variables to avoid php notices 
     
    660682    case "--install-moh": 
    661683      $install_moh = true; 
     684    break; 
     685    case "--set-freepbx-settings": 
     686      $set_freepbx_settings = true; 
    662687    break; 
    663688    case "--fopwebroot": 
     
    753778// **** Check for amportal.conf, create if necessary 
    754779 
     780// TODO: Check if freepbx_settings has been setup, if so then we don't even want to mess with ampportal.conf, that 
     781//       should only be first time install. 
     782// 
    755783outn("Checking for ".AMP_CONF.".."); 
    756784if (!file_exists(AMP_CONF)) { 
     
    10731101} 
    10741102 
    1075 // **** Apply amportal.conf configuration to files 
    1076 if (file_exists(dirname(__FILE__)."/apply_conf.sh")) {  
    1077   debug("Running ".dirname(__FILE__)."/apply_conf.sh"); 
    1078 } 
    10791103 
    10801104// Ensure executables are executable 
     
    11081132    outn("no freepbx_engine.."); 
    11091133  } 
     1134  // TODO: we just did this above 
    11101135  if (file_exists($amp_conf["AMPBIN"]."/freepbx_setting")) { 
    11111136    exec("chmod 755 ".$amp_conf["AMPBIN"]."/freepbx_setting"); 
     
    11341159  // reload manager in asterisk if it is running: 
    11351160  // 
    1136   outn("apply username/password changes to conf files.."); 
    11371161  if (file_exists(dirname(__FILE__)."/apply_conf.sh")) {  
     1162    out("apply username/password changes to conf files:"); 
     1163    debug("Running ".dirname(__FILE__)."/apply_conf.sh"); 
     1164    $apply_conf_out = array(); 
    11381165    if ($force_amportal_conf) { 
     1166      out("running apply_conf.sh from " . AMP_CONF); 
    11391167      putenv('FORCE_AMPORTAL_CONF=1'); 
    1140       exec(dirname(__FILE__)."/apply_conf.sh ".AMP_CONF); 
     1168      exec(dirname(__FILE__)."/apply_conf.sh ".AMP_CONF, $apply_conf_out); 
    11411169      putenv('FORCE_AMPORTAL_CONF='); 
    11421170    } else { 
    1143       exec(dirname(__FILE__)."/apply_conf.sh"); 
     1171      out("running apply_conf.sh from freepbx_settings"); 
     1172      exec(dirname(__FILE__)."/apply_conf.sh", $apply_conf_out); 
    11441173    } 
    1145   } 
    1146   out("done"); 
     1174    foreach ($apply_conf_out as $line) { 
     1175      out($line); 
     1176    } 
     1177    unset($apply_conf_out); 
     1178    out("done with apply_conf.sh"); 
     1179  } 
    11471180 
    11481181  /* As of Asterisk 1.4.16 or there about, a missing #include file will make the reload fail. So 
     
    12291262out("..OK"); 
    12301263 
     1264// TODO: if file is $force_amportal_conf let's go set any settings in freepbx_settings, 
     1265//       question is, should we do this further up??? 
     1266// 
     1267if ($set_freepbx_settings && $force_amportal_conf) { 
     1268  out("Setting freepbx settings form " . AMP_CONF); 
     1269  $freepbx_conf =& freepbx_conf::create(); 
     1270  foreach ($amp_conf as $keyword => $value) { 
     1271    if ($freepbx_conf->conf_setting_exists($keyword)) { 
     1272      $freepbx_conf->set_conf_values(array($keyword => $value),true,true); 
     1273      out("freepbx setting [$keyword] set to [$value]"); 
     1274    } else { 
     1275      out("freepbx setting [$keyword] DOES NOT EXIST, can't set to [$value]"); 
     1276    } 
     1277  } 
     1278} 
     1279 
    12311280// **** Generate AMP configs 
    12321281out("Generating AMP configs..");