mirror of
https://github.com/silverstripe/silverstripe-installer
synced 2024-10-22 17:05:33 +02:00
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:
parent
1fe1614bce
commit
5ed785dc71
20
Makefile
Normal file
20
Makefile
Normal 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
|
83
install.php
83
install.php
@ -9,15 +9,25 @@ ini_set('max_execution_time', 300);
|
|||||||
|
|
||||||
session_start();
|
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
|
// Load database config
|
||||||
if(isset($_REQUEST['mysql'])) {
|
if(isset($_REQUEST['mysql'])) {
|
||||||
$databaseConfig = $_REQUEST['mysql'];
|
$databaseConfig = $_REQUEST['mysql'];
|
||||||
} else {
|
} else {
|
||||||
$databaseConfig = array(
|
$databaseConfig = array(
|
||||||
"server" => "localhost",
|
"type" => "MySQLDatabase",
|
||||||
"username" => "root",
|
"server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost",
|
||||||
"password" => "",
|
"username" => defined('SS_DATABASE_USERNAME') ? SS_DATABASE_USERNAME : "root",
|
||||||
"database" => "SS_mysite",
|
"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
|
// 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
|
// Confirm before reinstalling
|
||||||
if(!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) {
|
if(!isset($_REQUEST['force_reinstall']) && !$installFromCli && $alreadyInstalled) {
|
||||||
include('config-form.html');
|
include('config-form.html');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$inst = new Installer();
|
$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
|
// Show the config form
|
||||||
@ -129,8 +145,8 @@ class InstallRequirements {
|
|||||||
|
|
||||||
$this->requireTempFolder(array('File permissions', 'Is the temporary folder writeable?', null));
|
$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']));
|
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
|
||||||
if($webserver == '') {
|
if($webserver == '') {
|
||||||
$webserver = "I can't tell what webserver you are running";
|
$webserver = "I can't tell what webserver you are running";
|
||||||
@ -143,8 +159,8 @@ class InstallRequirements {
|
|||||||
$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->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."));
|
$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
|
// Check for GD support
|
||||||
if(!$this->requireFunction("imagecreatetruecolor", array("PHP Configuration", "GD2 support", "PHP must have GD version 2."))) {
|
if(!$this->requireFunction("imagecreatetruecolor", array("PHP Configuration", "GD2 support", "PHP must have GD version 2."))) {
|
||||||
@ -490,8 +506,12 @@ class InstallRequirements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected $baseDir;
|
||||||
function getBaseDir() {
|
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) {
|
function testing($testDetails) {
|
||||||
@ -533,6 +553,11 @@ class InstallRequirements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Installer extends InstallRequirements {
|
class Installer extends InstallRequirements {
|
||||||
|
function __construct() {
|
||||||
|
// Cache the baseDir value
|
||||||
|
$this->getBaseDir();
|
||||||
|
}
|
||||||
|
|
||||||
function install($config) {
|
function install($config) {
|
||||||
?>
|
?>
|
||||||
<h1>Installing SilverStripe...</h1>
|
<h1>Installing SilverStripe...</h1>
|
||||||
@ -582,7 +607,7 @@ class Installer extends InstallRequirements {
|
|||||||
$template = $_POST['template'] == 'tutorial' ? 'tutorial' : 'mysite';
|
$template = $_POST['template'] == 'tutorial' ? 'tutorial' : 'mysite';
|
||||||
|
|
||||||
$theme = '';
|
$theme = '';
|
||||||
if($_POST['template'] == 'default') {
|
if($_POST['template'] != 'tutorial') {
|
||||||
$theme = <<<PHP
|
$theme = <<<PHP
|
||||||
// This line set's the current theme. More themes can be
|
// This line set's the current theme. More themes can be
|
||||||
// downloaded from http://www.silverstripe.com/cms-themes-and-skin
|
// downloaded from http://www.silverstripe.com/cms-themes-and-skin
|
||||||
@ -631,7 +656,7 @@ PHP
|
|||||||
$this->createHtaccess();
|
$this->createHtaccess();
|
||||||
|
|
||||||
// Load the sapphire runtime
|
// 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');
|
chdir('sapphire');
|
||||||
|
|
||||||
require_once('core/Core.php');
|
require_once('core/Core.php');
|
||||||
@ -652,6 +677,7 @@ PHP
|
|||||||
$con = new Controller();
|
$con = new Controller();
|
||||||
$con->pushCurrent();
|
$con->pushCurrent();
|
||||||
ManifestBuilder::compileManifest();
|
ManifestBuilder::compileManifest();
|
||||||
|
require(MANIFEST_FILE);
|
||||||
$dbAdmin = new DatabaseAdmin();
|
$dbAdmin = new DatabaseAdmin();
|
||||||
$dbAdmin->init();
|
$dbAdmin->init();
|
||||||
|
|
||||||
@ -673,13 +699,9 @@ PHP
|
|||||||
$_SESSION['password'] = $_REQUEST['admin']['password'];
|
$_SESSION['password'] = $_REQUEST['admin']['password'];
|
||||||
|
|
||||||
if($this->checkModRewrite()) {
|
if($this->checkModRewrite()) {
|
||||||
|
|
||||||
|
|
||||||
if($this->errors) {
|
if($this->errors) {
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo "<p>Installed SilverStripe successfully. I will now try and direct you to
|
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>
|
<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>
|
<script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script>
|
||||||
@ -728,6 +750,7 @@ PHP
|
|||||||
|
|
||||||
function createFile($filename, $content) {
|
function createFile($filename, $content) {
|
||||||
$base = $this->getBaseDir();
|
$base = $this->getBaseDir();
|
||||||
|
echo "<li>Creating $base$filename\n";
|
||||||
|
|
||||||
if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
|
if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
|
||||||
return true;
|
return true;
|
||||||
@ -740,11 +763,12 @@ PHP
|
|||||||
$start = "### SILVERSTRIPE START ###\n";
|
$start = "### SILVERSTRIPE START ###\n";
|
||||||
$end = "\n### SILVERSTRIPE END ###";
|
$end = "\n### SILVERSTRIPE END ###";
|
||||||
$base = dirname($_SERVER['SCRIPT_NAME']);
|
$base = dirname($_SERVER['SCRIPT_NAME']);
|
||||||
|
if($base != '.') $baseClause = "RewriteBase $base\n";
|
||||||
|
else $baseClause = "";
|
||||||
|
|
||||||
$rewrite = <<<TEXT
|
$rewrite = <<<TEXT
|
||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
RewriteBase $base
|
$baseClause
|
||||||
|
|
||||||
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
|
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
|
||||||
|
|
||||||
RewriteCond %{REQUEST_URI} ^(.*)$
|
RewriteCond %{REQUEST_URI} ^(.*)$
|
||||||
@ -772,23 +796,22 @@ TEXT
|
|||||||
function createHtaccessAlternative() {
|
function createHtaccessAlternative() {
|
||||||
$start = "### SILVERSTRIPE START ###\n";
|
$start = "### SILVERSTRIPE START ###\n";
|
||||||
$end= "\n### SILVERSTRIPE END ###";
|
$end= "\n### SILVERSTRIPE END ###";
|
||||||
|
|
||||||
$base = dirname($_SERVER['SCRIPT_NAME']);
|
$base = dirname($_SERVER['SCRIPT_NAME']);
|
||||||
|
if($base != '.') $baseClause = "RewriteBase $base\n";
|
||||||
|
|
||||||
$rewrite = <<<TEXT
|
$rewrite = <<<TEXT
|
||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
RewriteBase $base
|
$baseClause
|
||||||
|
|
||||||
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
|
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
|
||||||
|
|
||||||
RewriteCond %{REQUEST_URI} ^(.*)$
|
RewriteCond %{REQUEST_URI} ^(.*)$
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
|
RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
|
||||||
TEXT
|
TEXT;
|
||||||
;
|
|
||||||
|
|
||||||
|
if(file_exists($this->getBaseDir() . '.htaccess')) {
|
||||||
if(file_exists('.htaccess')) {
|
$htaccess = file_get_contents($this->getBaseDir() . '.htaccess');
|
||||||
$htaccess = file_get_contents('.htaccess');
|
|
||||||
|
|
||||||
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
|
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
|
||||||
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
|
$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);
|
$this->createFile('.htaccess', $start . $rewrite . $end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,6 +869,11 @@ TEXT
|
|||||||
}
|
}
|
||||||
|
|
||||||
function performModRewriteTest() {
|
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']);
|
$baseURL = dirname($_SERVER['SCRIPT_NAME']);
|
||||||
if($baseURL == "/") {
|
if($baseURL == "/") {
|
||||||
$baseURL = "";
|
$baseURL = "";
|
||||||
@ -851,6 +881,7 @@ TEXT
|
|||||||
|
|
||||||
// Check if mod_rewrite works properly
|
// 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';
|
$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);
|
@$testrewriting = file_get_contents($location);
|
||||||
|
|
||||||
if($testrewriting == 'OK') {
|
if($testrewriting == 'OK') {
|
||||||
|
Loading…
Reference in New Issue
Block a user