-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Real first commit with proposer ignored vendor
- Loading branch information
Showing
5 changed files
with
414 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "thomas/make-webapp", | ||
"description": "Auto configuration of webserver for new web app", | ||
// "repositories":[ | ||
// { | ||
// "type":"vcs", | ||
// "url":"[email protected]:tech/infra/deployment-script.git" | ||
// } | ||
// ], | ||
"require": { | ||
"league/climate": "^3.4" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Thomas Chartron", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Helpers\\": "src/Helpers/" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
require_once('../vendor/autoload.php'); | ||
|
||
use League\CLImate\CLImate; | ||
use Helpers\CLImateHelper; | ||
$climate = new CLImate; | ||
$helper = new CLImateHelper; | ||
|
||
$climate->arguments->add([ | ||
'web-server' => [ | ||
'prefix' => 'ws', | ||
'longPrefix' => 'web-server', | ||
'description' => 'Webserver name (apache2 nginx)', | ||
// 'required' => true | ||
], | ||
'name' => [ | ||
'prefix' => 'n', | ||
'longPrefix' => 'name', | ||
'description' => 'Website name', | ||
// 'required' => true | ||
], | ||
'vhost' => [ | ||
'prefix' => 'h', | ||
'longPrefix' => 'vhost', | ||
'description' => 'Vhost name', | ||
// 'required' => true | ||
], | ||
'local-address' => [ | ||
'prefix' => 'a', | ||
'longPrefix' => 'address', | ||
'description' => 'Local address to create (eg site-name.work)', | ||
// 'required' => true | ||
], | ||
'interactive' => [ | ||
'prefix' => 'i', | ||
'longPrefix' => 'interactive', | ||
'description' => 'Interactive creation', | ||
// 'required' => true | ||
], | ||
'verbose' => [ | ||
'prefix' => 'v', | ||
'longPrefix' => 'verbose', | ||
'description' => 'Verbose output', | ||
'noValue' => true, | ||
], | ||
'help' => [ | ||
'longPrefix' => 'help', | ||
'description' => 'Prints a usage statement', | ||
'noValue' => true, | ||
], | ||
'other' => [ | ||
'description' => 'The other args passed', | ||
], | ||
]); | ||
$climate->arguments->parse(); | ||
|
||
if($climate->arguments->defined('help')) { | ||
$climate->usage(); | ||
} | ||
|
||
$climate->backgroundLightGreen()->bold()->black()->out('Welcome to web app configuration'); | ||
|
||
//Here we should be able to choose if apache2 or nginx is used | ||
|
||
//////////////// | ||
//CORE SCRIPT // | ||
//////////////// | ||
|
||
$shellCurrentUser = execOrFail("whoami"); | ||
$shellCurrentUser = $shellCurrentUser[0]; //dirty change | ||
// die($shellCurrentUser[0]); | ||
//Interactive mode | ||
if($climate->arguments->defined('interactive')) { | ||
$args = interactive(); | ||
$climate->backgroundLightGreen()->black()->out('WebApp configuration :'); | ||
$climate->backgroundLightGreen()->black()->br()->out('Web server : '.$args['web-server']); | ||
$climate->backgroundLightGreen()->black()->br()->out('Site Folder : /home/'.$shellCurrentUser.'/www/'.$args['site-name']); | ||
$climate->backgroundLightGreen()->black()->br()->out('Vhost file name : '.$args['vhost-name']); | ||
$climate->backgroundLightGreen()->black()->br()->out('Local address : '.$args['local-address']); | ||
$climate->backgroundLightGreen()->black()->br()->out('DocumentRoot : '.$args['document-root']); | ||
$input = $climate->input('Should we create this ? [Y/n]'); | ||
$input->defaultTo('Y'); | ||
$input->accept(['Y', 'n']); | ||
$response = $input->prompt(); | ||
|
||
if($response === "Y") { | ||
makeApp($args); | ||
|
||
} | ||
|
||
// die(var_dump($args)); | ||
} | ||
|
||
|
||
// $args = $climate->arguments->get('other'); | ||
// die(var_dump($args)); | ||
|
||
|
||
|
||
$climate->backgroundLightGreen()->bold()->black()->out('Congratz !'); | ||
|
||
/** | ||
* Allow for interactive needed argument filling | ||
* @return [type] [description] | ||
*/ | ||
function interactive() : array | ||
{ | ||
global $climate; | ||
$args = []; | ||
//Site folder | ||
$input = $climate->input('Web server ? default : apache2'); | ||
$input->defaultTo('apache2'); | ||
$args['web-server'] = $input->prompt(); | ||
|
||
$input = $climate->input('Site name folder ? ex : site-name'); | ||
$input->accept(function($response) { | ||
return ($response !== ''); | ||
}); | ||
$args['site-name'] = $input->prompt(); | ||
|
||
$input = $climate->input('Vhost file name ? ex : 001-site-name.conf'); | ||
$input->accept(function($response) { | ||
return ($response !== ''); | ||
}); | ||
$args['vhost-name'] = $input->prompt(); | ||
|
||
$input = $climate->input('Local address ? default : site-name.work'); | ||
$input->defaultTo($args['site-name'].".work"); | ||
$args['local-address'] = $input->prompt(); | ||
|
||
$input = $climate->input('Document Root ? default : /var/www/site-name/public'); | ||
$input->defaultTo("/var/www/".$args['site-name']."/public"); | ||
$args['document-root'] = $input->prompt(); | ||
|
||
return $args; | ||
} | ||
|
||
function makeApp($args) : bool | ||
{ | ||
global $shellCurrentUser, $climate; | ||
foreach ($args as $key => $value) { | ||
switch($key) { | ||
// case 'web-server': | ||
|
||
// break; | ||
case 'site-name': | ||
if($args['web-server'] === "apache2") { | ||
execOrFail('mkdir -p /home/'.$shellCurrentUser.'/www/'.$args['site-name']); | ||
if($climate->arguments->defined('verbose')) { | ||
$climate->backgroundLightBlue()->black()->br()->out('Creating /home/'.$shellCurrentUser.'/www/'.$args['site-name'].' folder'); | ||
} | ||
} | ||
break; | ||
case 'vhost-name': | ||
if($args['web-server'] === "apache2") { | ||
execOrFail('mkdir -p /home/'.$shellCurrentUser.'/www/'.$args['site-name']); | ||
if($climate->arguments->defined('verbose')) { | ||
$climate->backgroundLightBlue()->black()->br()->out('Creating /home/'.$shellCurrentUser.'/www/'.$args['site-name'].' folder'); | ||
} | ||
} | ||
break; | ||
case 'local-address': | ||
if($args['web-server'] === "apache2") { | ||
|
||
} | ||
break; | ||
|
||
} | ||
} | ||
return false; | ||
} | ||
|
||
function execOrFail($command) { | ||
try { | ||
exec($command, $output); | ||
} catch (Exception $e) { | ||
return $e->getMessage(); | ||
} | ||
// return (!empty($output)) ? $output : true; | ||
return $output; | ||
} |
Oops, something went wrong.