aboutsummaryrefslogtreecommitdiff
path: root/install/cli/sample_installer.php
blob: 0bae0cd23f1b5a2b9587ac2ee43441ca29baa268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
 * Sample cli installer script
 */

$enabled = false;

// Do not edit below this line. //////////////////////////////


if (!$enabled) {
	echo "To enable this script, change \$enabled to true.\n";
	echo "You *must* disable this script after a successful installation.\n";
	exit;
}

if (PHP_SAPI !== 'cli') {
	echo "You must use the command line to run this script.";
	exit;
}

require_once(dirname(dirname(__FILE__)) . "/ElggInstaller.php");

$installer = new ElggInstaller();

// none of the following may be empty
$params = array(
	// database parameters
	'dbuser' => '',
	'dbpassword' => '',
	'dbname' => '',

	// site settings
	'sitename' => '',
	'siteemail' => '',
	'wwwroot' => '',
	'dataroot' => '',

	// admin account
	'displayname' => '',
	'email' => '',
	'username' => '',
	'password' => '',
);

// install and create the .htaccess file
$installer->batchInstall($params, TRUE);

// at this point installation has completed (otherwise an exception halted execution).

// try to rewrite the script to disable it.
if (is_writable(__FILE__)) {
	$code = file_get_contents(__FILE__);
	if (preg_match('~\\$enabled\\s*=\\s*(true|1)\\s*;~i', $code)) {
		// looks safe to rewrite
		$code = preg_replace('~\\$enabled\\s*=\\s*(true|1)\\s*;~i', '$enabled = false;', $code);
		file_put_contents(__FILE__, $code);

		echo "\nNote: This script has been disabled for your safety.\n";
		exit;
	}
}

echo "\nWarning: You *must* disable this script by setting \$enabled = false;.\n";
echo "Leaving this script enabled could endanger your installation.\n";