Created
March 20, 2010 03:33
-
-
Save cogentParadigm/338462 to your computer and use it in GitHub Desktop.
Automated Wordpress Installer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$usage = "Automated Wordpress installer\nby Ali Gangji\nUsage: wordpress install_dir -u dbuser -p dbpass -d dbname\nOptions:\n"; | |
$usage .= " -u dbuser Database username\n"; | |
$usage .= " -p dbpass Database password\n"; | |
$usage .= " -d dbname Database name\n"; | |
$usage .= " -h dbhost Database host\n"; | |
$usage .= " --private Hide blog from search engines\n"; | |
$usage .= " --prefix prefix Database prefix\n"; | |
if ($argc < 2) { | |
echo $usage; | |
exit; | |
} | |
function curl_get_file_contents($URL) { | |
$c = curl_init(); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($c, CURLOPT_URL, $URL); | |
$contents = curl_exec($c); | |
curl_close($c); | |
if ($contents) return $contents; | |
else return false; | |
} | |
$dir = $argv[1]; | |
$ex_str = (file_exists($dir)) ? "" : "mkdir $dir; "; | |
exec($ex_str."curl -O http://www.wordpress.org/latest.tar.gz; tar -xzf latest.tar.gz; mv wordpress/* $dir/; rmdir wordpress; rm latest.tar.gz"); | |
$public = 1; | |
foreach($argv as $i => $v) { | |
if ($v == "-u") $user = $argv[$i+1]; | |
else if ($v == "-p") $pass = $argv[$i+1]; | |
else if ($v == "-d") $dbse = $argv[$i+1]; | |
else if ($v == "-h") $host = $argv[$i+1]; | |
else if ($v == "--private") $public = 0; | |
else if ($v == "--prefix") $prefix = $argv[$i+1]; | |
} | |
if (file_exists("$dir/wp-config-sample.php") && !file_exists("$dir/wp-config.php")) { | |
$wpconfig = file_get_contents("$dir/wp-config-sample.php"); | |
$keys = curl_get_file_contents("https://api.wordpress.org/secret-key/1.1/"); | |
$start = strpos($wpconfig, "define('AUTH_KEY'"); | |
$search = substr($wpconfig, $start, 221); | |
$wpconfig = str_replace($search, $keys, $wpconfig); | |
if (!empty($user)) $wpconfig = str_replace("define('DB_USER', 'usernamehere');", "define('DB_USER', '$user');", $wpconfig); | |
if (!empty($pass)) $wpconfig = str_replace("define('DB_PASSWORD', 'yourpasswordhere');", "define('DB_PASSWORD', '$pass');", $wpconfig); | |
if (!empty($dbse)) $wpconfig = str_replace("define('DB_NAME', 'putyourdbnamehere');", "define('DB_NAME', '$dbse');", $wpconfig); | |
if (!empty($host)) $wpconfig = str_replace("define('DB_HOST', 'localhost');", "define('DB_HOST', '$host');", $wpconfig); | |
if (!empty($prefix)) $wpconfig = str_replace("\$table_prefix = 'wp_';", "\$table_prefix = '$prefix';", $wpconfig); | |
$file = fopen("$dir/wp-config.php", "wb"); | |
fwrite($file, $wpconfig); | |
fclose($file); | |
} else fwrite(STDOUT, "wp-config.php already exists\nusing existing configuration\n"); | |
fwrite(STDOUT, "Visit wp-admin/install.php to complete the installation."); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment