Skip to content

Commit

Permalink
🎉 Real first commit with proposer ignored vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
tchartron committed Jan 26, 2019
1 parent 800138f commit a323bb7
Show file tree
Hide file tree
Showing 5 changed files with 414 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
25 changes: 25 additions & 0 deletions composer.json
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/"
}
}
}
174 changes: 174 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

182 changes: 182 additions & 0 deletions scripts/make-webapp
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;
}
Loading

0 comments on commit a323bb7

Please sign in to comment.