Skip to content

Commit

Permalink
added detection for linux and mac OS
Browse files Browse the repository at this point in the history
  • Loading branch information
pgodel committed Dec 17, 2009
1 parent 78983c4 commit 2dcddb0
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions SymWebDevInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
$defaultHostname = $projectName.'.local';

$isWindows = false;
$isLinux = false;


if ( isset( $_SERVER['SystemRoot'] ) )
{
Expand All @@ -43,20 +45,25 @@

$this->logBlock("Windows OS detected at $winDir", 'INFO');
}
else
{
$linux = exec( 'uname', $output );
$isLinux = strpos( $output[0], 'Linux' ) !== false;
}

$ipAddress = $this->askAndValidate('What is the IP address for your web project (default: '.$defaultIp.')?'
, new sfValidatorString( array( 'empty_value' => $defaultIp, 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
, new sfValidatorString( array( 'empty_value' => $defaultIp, 'required' => false ) ), array('style' => 'QUESTION_LARGE'));

$this->logBlock("IP address set to $ipAddress", 'INFO');


$hostname = $this->askAndValidate('What is the hostname for your web project (default: '.$defaultHostname.')?'
, new sfValidatorString( array( 'empty_value' => $defaultHostname, 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
, new sfValidatorString( array( 'empty_value' => $defaultHostname, 'required' => false ) ), array('style' => 'QUESTION_LARGE'));

$this->logBlock("Hostname set to $hostname", 'INFO');

$apacheConfFile = $this->askAndValidate('Enter the full file name of Apache Web Server configuration file (default: auto-search)?'
, new sfValidatorString( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
, new sfValidatorString( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));

$this->logBlock( empty( $apacheConfFile ) ? "Will search for Apache configuration" : "Apache configuration set to $apacheConfFile", 'INFO');

Expand All @@ -74,29 +81,29 @@
if ( ! file_exists( $hostsFile ) )
{
$hostsFile = $this->askAndValidate('Could not find hosts file. Please provide the full path name of the hosts file (press enter to skip this step)'
, new sfValidatorFile( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
, new sfValidatorFile( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
}
else
{
$this->logBlock("hosts file set to $hostsFile", 'INFO');
$this->logBlock("hosts file set to $hostsFile", 'INFO');
}

$content = "
# Added by Symfony Web Developent Environment installer
$ipAddress $hostname
";
$ipAddress $hostname
";

if ( !empty( $hostsFile )
&& file_exists( $hostsFile )
&& $this->askConfirmation("Add '$ipAddress $hostname' to hosts file located at $hostsFile? (y/n)", 'QUESTION_LARGE'))
&& file_exists( $hostsFile )
&& $this->askConfirmation("Add '$ipAddress $hostname' to hosts file located at $hostsFile? (y/n)", 'QUESTION_LARGE'))
{
if ( ! file_put_contents ( $hostsFile, $content, FILE_APPEND ) )
{
$this->logBlock("Failed to add $content to hosts file at $hostsFile. Please check that you have permissions to update this file.", 'ERROR_LARGE');
}
else
{
$this->logBlock("hosts file modified successfully.", 'INFO');
$this->logBlock("hosts file modified successfully.", 'INFO');
}
}
else
Expand All @@ -112,17 +119,17 @@
{

$possibleLocations = array(
'C:\Program Files\Zend\Apache2\conf\httpd.conf',
'C:\Program Files\Zend\Apache2\conf\httpd.conf',
);
}
else
{
$possibleLocations = array(
'/etc/httpd/conf/httpd.conf',
'/etc/apache2/conf/apache.conf',
'/usr/local/apache2/conf/httpd.conf',
'/usr/local/apache/conf/httpd.conf',
'/usr/local/Zend/Apache2/conf/httpd.conf',
'/etc/httpd/conf/httpd.conf',
'/etc/apache2/conf/apache.conf',
'/usr/local/apache2/conf/httpd.conf',
'/usr/local/apache/conf/httpd.conf',
'/usr/local/zend/apache2/conf/httpd.conf',
);
}

Expand All @@ -143,7 +150,7 @@
if ( ! file_exists( $apacheConfFile ) )
{
$hostsFile = $this->askAndValidate('Could not find hosts file. Please provide the full path name of the hosts file'
, new sfValidatorFile( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
, new sfValidatorFile( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
}

$content = '
Expand All @@ -161,27 +168,24 @@
';

if ( !empty( $apacheConfFile )
&& file_exists( $apacheConfFile )
&& $this->askConfirmation("Add Virtual Host section to $apacheConfFile? (y/n)", 'QUESTION_LARGE'))
&& file_exists( $apacheConfFile )
&& $this->askConfirmation("Add Virtual Host section to $apacheConfFile? (y/n)", 'QUESTION_LARGE'))
{
if ( ! file_put_contents ( $apacheConfFile, $content, FILE_APPEND ) )
{
$this->logBlock("Failed to add configuration to $apacheConfFile. Please check that you have permissions to update this file.", 'ERROR_LARGE');
}
else
{
$this->logBlock("Apache configured successfully.", 'INFO');
$this->logBlock("Apache configured successfully.", 'INFO');
}

}

if ($this->askConfirmation("Do you want to restart Apache to load the new configuration? (y/n)", 'QUESTION_LARGE'))
{
if ( $isWindows )
{
$cmd = "";
}
else
$cmd = '';
if ( $isLinux )
{
$cmd = "service httpd restart";
}
Expand Down

0 comments on commit 2dcddb0

Please sign in to comment.