Changeset 1021

Show
Ignore:
Timestamp:
05/22/05 21:55:04 (3 years ago)
Author:
torben
Message:

Added support for writing the detected configuration to a file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/support/autoconf.php

    r1015 r1021  
    99 * be found. 
    1010 *  
     11 * If no argument is present, the detmined configuration is only written to stdout after the 
     12 * debugging messages. Otherwise, the filename specified on the command line will be replaced 
     13 * with the autodetected configuration.  
     14 *  
    1115 * @package midcom 
    1216 * @author The Midgard Project, http://www.midgard-project.org  
     
    1721 
    1822$GLOBALS['configfile'] = ''; 
     23 
     24if ($argc == 1) 
     25{ 
     26    $GLOBALS['outfile'] = null; 
     27} 
     28else if ($argc == 2) 
     29{ 
     30    $GLOBALS['outfile'] = $argv[1]; 
     31} 
     32else 
     33{ 
     34?> 
     35Usage: php autoconf.php [ output_filename ] 
     36<?php 
     37exit(); 
     38} 
    1939 
    2040function add_option_to_configfile($option, $value) 
     
    5979    die("The 'which' utility cannot be found. It is required for auto-configuration. Aborting."); 
    6080} 
    61  
    62 // Todo: 
    63 // - Detect external utilities 
    64 // - Verify all required external utilities 
    65 // - Check PHP / PEAR dependencies 
    66 // - Collect midcom.conf lines. 
    6781 
    6882echo "Detecting Cache Handlers... "; 
     
    145159 
    146160 
     161// Check Memory Limit 
     162echo "Checking Memory Limit... "; 
     163$cur_limit = ini_get('memory_limit'); 
     164$last_char = substr($cur_limit, -1); 
     165if ($last_char == 'M') 
     166{ 
     167    $cur_limit = substr($cur_limit, 0, -1) * 1024 * 1024; 
     168} 
     169else if ($last_char == 'K') 
     170{ 
     171    $cur_limit = substr($cur_limit, 0, -1) * 1024; 
     172} 
     173else if ($last_char == 'G') 
     174{ 
     175    $cur_limit = substr($cur_limit, 0, -1) * 1024 * 1024 * 1024; 
     176} 
     177if ($cur_limit >= (20 * 1024 * 1024)) 
     178{ 
     179    echo "{$cur_limit} Bytes... OK\n"; 
     180} 
     181else 
     182{ 
     183    echo "{$cur_limit} Bytes... Memory Limit is below 20 MB, it is recommeded to set this in the php.ini file."; 
     184    $GLOBALS['configfile'] .= "ini_set('memory_limit', '20M');\n"; 
     185} 
     186 
     187// - Check PHP / PEAR dependencies 
     188 
    147189?> 
    148190 
     
    157199?> 
    158200---------------------------------------------------------------------------- 
     201<?php 
     202 
     203if (! is_null($GLOBALS['outfile'])) 
     204{ 
     205    $handle = fopen($GLOBALS['outfile'], 'w'); 
     206    if ($handle === false) 
     207    { 
     208        die ("Could not open output file {$GLOBALS['outfile']} for writing.\n"); 
     209    } 
     210    fwrite ($handle, "<?php\n"); 
     211    fwrite ($handle, $GLOBALS['configfile']); 
     212    fwrite ($handle, "?>\n"); 
     213    fclose($handle); 
     214     
     215    echo("\nConfiguration written to {$GLOBALS['outfile']}\n"); 
     216} 
     217 
     218?>