Allow calling of installer by running 'make install' from an environment with an _ss_environment.php file. This is important for continuous integration.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/phpinstaller/trunk@48125 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
sminnee 2008-01-16 23:47:23 +00:00
parent 1fe1614bce
commit 5ed785dc71
2 changed files with 236 additions and 185 deletions

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# This makefile is a secondary way of installing SilverStripe.
# It is used for things like continuous integration
#
# Most users should simply visit the site root in your web browser.
#
install: mysite/_config.php
mysite/_config.php:
php install.php install SS_testdatabase
test: clean install
$(MAKE) -C sapphire test
clean:
if [ -f .htaccess ]; then rm .htaccess; fi
touch .htaccess
if [ -f mysite/_config.php ]; then rm mysite/_config.php; fi

View File

@ -9,15 +9,25 @@ ini_set('max_execution_time', 300);
session_start();
// Include environment files
$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php');
foreach($envFiles as $envFile) {
if(@file_exists($envFile)) {
include($envFile);
break;
}
}
// Load database config
if(isset($_REQUEST['mysql'])) {
$databaseConfig = $_REQUEST['mysql'];
} else {
$databaseConfig = array(
"server" => "localhost",
"username" => "root",
"password" => "",
"database" => "SS_mysite",
"type" => "MySQLDatabase",
"server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost",
"username" => defined('SS_DATABASE_USERNAME') ? SS_DATABASE_USERNAME : "root",
"password" => defined('SS_DATABASE_PASSWORD') ? SS_DATABASE_PASSWORD : "",
"database" => isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : "SS_mysite",
);
}
@ -60,14 +70,20 @@ if($databaseConfig) {
}
// Actual processor
if(isset($_REQUEST['go']) && !$req->hasErrors() && !$dbReq->hasErrors()) {
$installFromCli = (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'install');
if(isset($_REQUEST['go']) || $installFromCli && !$req->hasErrors() && !$dbReq->hasErrors()) {
// Confirm before reinstalling
if(!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) {
if(!isset($_REQUEST['force_reinstall']) && !$installFromCli && $alreadyInstalled) {
include('config-form.html');
} else {
$inst = new Installer();
$inst->install($_REQUEST);
if($_REQUEST) $inst->install($_REQUEST);
else $inst->install(array(
'database' => $databaseConfig['type'],
'mysql' => $databaseConfig,
'admin' => $adminConfig,
));
}
// Show the config form
@ -129,23 +145,23 @@ class InstallRequirements {
$this->requireTempFolder(array('File permissions', 'Is the temporary folder writeable?', null));
// Check for rewriting
// Check for web server, unless we're calling the installer from the command-line
if(!$_SERVER['argv']) {
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
if($webserver == '') {
$webserver = "I can't tell what webserver you are running";
}
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
if($webserver == '') {
$webserver = "I can't tell what webserver you are running";
$this->isRunningApache(array("Webserver Configuration", "Server software", "$webserver. Without Apache I can't tell if mod_rewrite is enabled.", $webserver));
if(function_exists('apache_get_modules')) {
$this->requireApacheModule('mod_rewrite', array("Webserver Configuration", "mod_rewrite enabled", "You need mod_rewrite to run SilverStripe CMS, but it is not enabled."));
} else {
$this->warning(array("Webserver Configuration", "mod_rewrite enabled", "I can't tell whether mod_rewrite is running. You may need to configure a rewriting rule yourself."));
}
$this->requireServerVariables(array('SCRIPT_NAME','HTTP_HOST','SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
}
$this->isRunningApache(array("Webserver Configuration", "Server software", "$webserver. Without Apache I can't tell if mod_rewrite is enabled.", $webserver));
if(function_exists('apache_get_modules')) {
$this->requireApacheModule('mod_rewrite', array("Webserver Configuration", "mod_rewrite enabled", "You need mod_rewrite to run SilverStripe CMS, but it is not enabled."));
} else {
$this->warning(array("Webserver Configuration", "mod_rewrite enabled", "I can't tell whether mod_rewrite is running. You may need to configure a rewriting rule yourself."));
}
// Check for $_SERVER configuration
$this->requireServerVariables(array('SCRIPT_NAME','HTTP_HOST','SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
// Check for GD support
if(!$this->requireFunction("imagecreatetruecolor", array("PHP Configuration", "GD2 support", "PHP must have GD version 2."))) {
$this->requireFunction("imagecreate", array("PHP Configuration", "GD2 support", "GD2 support", "GD support for PHP not included."));
@ -490,8 +506,12 @@ class InstallRequirements {
}
protected $baseDir;
function getBaseDir() {
return dirname($_SERVER['SCRIPT_FILENAME']) . '/';
// Cache the value so that when the installer mucks with SCRIPT_FILENAME half way through, this method
// still returns the correct value.
if(!$this->baseDir) $this->baseDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . '/';
return $this->baseDir;
}
function testing($testDetails) {
@ -533,6 +553,11 @@ class InstallRequirements {
}
class Installer extends InstallRequirements {
function __construct() {
// Cache the baseDir value
$this->getBaseDir();
}
function install($config) {
?>
<h1>Installing SilverStripe...</h1>
@ -582,7 +607,7 @@ class Installer extends InstallRequirements {
$template = $_POST['template'] == 'tutorial' ? 'tutorial' : 'mysite';
$theme = '';
if($_POST['template'] == 'default') {
if($_POST['template'] != 'tutorial') {
$theme = <<<PHP
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.com/cms-themes-and-skin
@ -631,7 +656,7 @@ PHP
$this->createHtaccess();
// Load the sapphire runtime
$_SERVER['SCRIPT_FILENAME'] = dirname($_SERVER['SCRIPT_FILENAME']) . '/sapphire/main.php';
$_SERVER['SCRIPT_FILENAME'] = dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/sapphire/main.php';
chdir('sapphire');
require_once('core/Core.php');
@ -652,6 +677,7 @@ PHP
$con = new Controller();
$con->pushCurrent();
ManifestBuilder::compileManifest();
require(MANIFEST_FILE);
$dbAdmin = new DatabaseAdmin();
$dbAdmin->init();
@ -673,13 +699,9 @@ PHP
$_SESSION['password'] = $_REQUEST['admin']['password'];
if($this->checkModRewrite()) {
if($this->errors) {
} else {
echo "<p>Installed SilverStripe successfully. I will now try and direct you to
<a href=\"home/successfullyinstalled?flush=1\">home/successfullyinstalled</a> to confirm that the installation was successful.</p>
<script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script>
@ -728,6 +750,7 @@ PHP
function createFile($filename, $content) {
$base = $this->getBaseDir();
echo "<li>Creating $base$filename\n";
if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
return true;
@ -740,11 +763,12 @@ PHP
$start = "### SILVERSTRIPE START ###\n";
$end = "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
if($base != '.') $baseClause = "RewriteBase $base\n";
else $baseClause = "";
$rewrite = <<<TEXT
RewriteEngine On
RewriteBase $base
$baseClause
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$
@ -772,23 +796,22 @@ TEXT
function createHtaccessAlternative() {
$start = "### SILVERSTRIPE START ###\n";
$end= "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
if($base != '.') $baseClause = "RewriteBase $base\n";
$rewrite = <<<TEXT
RewriteEngine On
RewriteBase $base
$baseClause
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
TEXT
;
TEXT;
if(file_exists('.htaccess')) {
$htaccess = file_get_contents('.htaccess');
if(file_exists($this->getBaseDir() . '.htaccess')) {
$htaccess = file_get_contents($this->getBaseDir() . '.htaccess');
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
@ -800,6 +823,8 @@ TEXT
}
}
echo "\n\nRewrite is $rewrite\n";
$this->createFile('.htaccess', $start . $rewrite . $end);
}
@ -844,6 +869,11 @@ TEXT
}
function performModRewriteTest() {
if(!$_SERVER['HTTP_HOST']) {
echo "<li>Installer seems to be called from command-line, we're going to assume that rewriting is working.\n";
return true;
}
$baseURL = dirname($_SERVER['SCRIPT_NAME']);
if($baseURL == "/") {
$baseURL = "";
@ -851,6 +881,7 @@ TEXT
// Check if mod_rewrite works properly
$location = 'http://' . (isset($_SERVER['PHP_AUTH_USER']) ? "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@" : '') . $_SERVER['HTTP_HOST'] . $baseURL . '/InstallerTest/testRewrite';
echo $location;
@$testrewriting = file_get_contents($location);
if($testrewriting == 'OK') {