Created
January 14, 2011 13:28
-
-
Save birkir/779602 to your computer and use it in GitHub Desktop.
execute: "php kohana.php"
This file contains 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
<?php | |
function input() | |
{ | |
$handle = fopen("php://stdin", "r"); | |
return fgets($handle); | |
} | |
function fetch($url = NULL) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
try { | |
$out = curl_exec($ch); | |
curl_close($ch); | |
} | |
catch(Exception $e) | |
{ | |
$out = FALSE; | |
} | |
return $out; | |
} | |
function save($path = NULL, $contents = NULL) | |
{ | |
try { | |
$fp = fopen($path, "w"); | |
fwrite($fp, $contents); | |
fclose($fp); | |
return TRUE; | |
} | |
catch(Exception $e) | |
{ | |
return FALSE; | |
} | |
} | |
print("This script will install the current development version of Kohana from GitHub. To use the latest stable release, run \"git submodule foreach 'git checkout master'\" after installation.\n"); | |
print("\n"); | |
print(" > Continue installation? (Y/n): "); | |
$input = input(); | |
if (strtolower($input) == 'n' OR strtolower($input) == 'no') | |
{ | |
exit; | |
} | |
print(" > Install to? (Directory name): "); | |
$input = trim(input()); | |
if ( ! is_dir($input)) | |
{ | |
print(" ~ Creating directory ... "); | |
if ( ! mkdir($input, 0777, TRUE)) | |
{ | |
print(" ! Could not create requested directory.\n"); | |
exit; | |
} | |
print("done\n"); | |
} | |
chdir($input); | |
$root = getcwd(); | |
if ( ! is_dir($root."/.git")) | |
{ | |
print(" ~ Creating git repository ... "); | |
shell_exec("cd $root && git init"); | |
print("done\n"); | |
} | |
else | |
{ | |
print(" ! Could not create git repository.\n"); | |
exit; | |
} | |
if ( ! is_dir($root."/system")) | |
{ | |
print(" ~ Installing core system ... "); | |
shell_exec("cd $root && git submodule add git://github.com/kohana/core.git system > /dev/null 2>&1"); | |
print("done\n"); | |
} | |
print(" > Do you want to install any kohana modules? (Y/n): "); | |
$input = input(); | |
if (strtolower(trim($input)) == 'y' OR strtolower(trim($input)) == 'yes') | |
{ | |
print(" ~ Loading available modules ... "); | |
$m = array(); | |
$modules = fetch('https://github.com/kolanos/kohana-universe/raw/master/.gitmodules'); | |
$modules = explode('.git', $modules); | |
foreach ($modules as $module) | |
{ | |
if (preg_match('#path = (.*?)\n#s', $module, $modulename)) | |
{ | |
$name = str_replace('modules/', NULL, $modulename[1]); | |
if (preg_match('#url = (.*?);#s', $module.';', $moduleurl)) | |
{ | |
$m[$name] = $moduleurl[1].'.git'; | |
} | |
} | |
} | |
print("done\n\n"); | |
print(" Name Description | |
--------------------------------------------------------------------------- | |
auth Authentication module | |
cache Cache library with drivers | |
codebench Benchmarking module | |
database Database interactions, query builder and prepared statements | |
image Image manipulating module | |
oauth OAuth implementation module | |
orm Object Relational Mapping module (requires database) | |
pagination Pagination module | |
unittest PHPUnit intergration module | |
userguide Userguide and live API documentation | |
Unofficial Modules | |
--------------------------------------------------------------------------- | |
"); | |
$length = 0; | |
foreach ($m as $k => $v) | |
{ | |
if ( ! strpos('github.com/kohana/', $v)) | |
{ | |
$length += (strlen($k)+1); | |
echo " $k"; | |
if ($length >= 68) | |
{ | |
echo "\n"; | |
$length = 0; | |
} | |
} | |
} | |
print("\n"); | |
while(TRUE) | |
{ | |
print(" > Module names? (Blank stop): "); | |
$input = trim(input()); | |
if (empty($input)) | |
break; | |
$modules = explode(' ', $input); | |
foreach($modules as $module) | |
{ | |
print(" ~ Installing $module ... "); | |
shell_exec("cd $root && git submodule add {$m[$module]} ".$root."/modules/".$module." > /dev/null 2>&1"); | |
print("done\n"); | |
} | |
} | |
print(" ~ Commiting submodules ... "); | |
shell_exec("cd $root && git submodule init > /dev/null 2>&1"); | |
shell_exec("cd $root && git submodule update > /dev/null 2>&1"); | |
shell_exec("cd $root && git add . > /dev/null 2>&1"); | |
shell_exec("cd $root && git commit -m 'Added submodules to repository' > /dev/null 2>&1"); | |
print("done\n"); | |
} | |
print(" > Create application structure? [Y/n] "); | |
$input = input(); | |
if (strtolower(trim($input)) == 'y' OR strtolower(trim($input)) == 'yes') | |
{ | |
print(" ~ Creating structure ... "); | |
mkdir($root."/application/classes/controller", 0777, TRUE); | |
mkdir($root."/application/classes/model", 0777, TRUE); | |
mkdir($root."/application/cache", 0777, TRUE); | |
mkdir($root."/application/logs", 0777, TRUE); | |
if ( ! save($root."/application/logs/.gitignore", "[^.]*")){ | |
print(" ! Could not write to APPPATH/logs/.gitignore"); | |
} | |
if ( ! save($root."/application/cache/.gitignore", "[^.]*")){ | |
print(" ! Could not write to APPPATH/cache/.gitignore"); | |
} | |
print("done\n"); | |
print(" ~ Downloading index.php ... "); | |
$file = fetch('https://github.com/kohana/kohana/raw/3.0/master/index.php'); | |
if ( $file AND ! save($root."/index.php", $file)){ | |
print("\n ! Could not write to $root/index.php"); | |
}else | |
print("done\n"); | |
print(" ~ Downloading bootstrap.php ... "); | |
$file = fetch('https://github.com/kohana/kohana/raw/3.0/master/application/bootstrap.php'); | |
if ( $file AND ! save($root."/application/bootstrap.php", $file)){ | |
print("\n ! Could not write to $root/application/index.php"); | |
}else | |
print("done\n"); | |
print(" ~ Downloading example.htaccess ... "); | |
$file = fetch('https://github.com/kohana/kohana/raw/3.0/master/example.htaccess'); | |
if ( $file AND ! save($root."/.htaccess", $file)){ | |
print("\n ! Could not write to $root/.htaccess"); | |
}else | |
print("done\n"); | |
print(" ~ Committing application structure ... "); | |
shell_exec("cd $root && git add .htaccess index.php application > /dev/null 2>&1"); | |
shell_exec("cd $root && git commit -m 'Basic application structure created' > /dev/null 2>&1"); | |
print("done\n"); | |
} | |
print(" ! Kohana has been installed. Enjoy!\n"); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment