From 0ed82a2c6ffd8e981d9dd388306379941ecb5720 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 20 Aug 2017 04:18:13 +0100 Subject: WIP rejigging stuff --- bootstrap.php | 3 + composer.json | 13 ++ composer.lock | 332 +++++++++++++++++++++++++++++++++++++ new-site.php | 23 ++- scripts/run.php | 95 +++++++++++ scripts/test.php | 13 ++ src/Filesystem/Create.php | 20 +++ src/Filesystem/CreateDirectory.php | 25 +++ src/Filesystem/CreateFile.php | 25 +++ src/Script/Command/Site.php | 80 +++++++++ src/Script/Console.php | 16 ++ 11 files changed, 633 insertions(+), 12 deletions(-) create mode 100644 bootstrap.php create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 scripts/run.php create mode 100644 scripts/test.php create mode 100644 src/Filesystem/Create.php create mode 100644 src/Filesystem/CreateDirectory.php create mode 100644 src/Filesystem/CreateFile.php create mode 100644 src/Script/Command/Site.php create mode 100644 src/Script/Console.php diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000..b696801 --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,3 @@ +=5.5.9" + }, + "conflict": { + "league/flysystem-sftp": "<1.0.6" + }, + "require-dev": { + "ext-fileinfo": "*", + "mockery/mockery": "~0.9", + "phpspec/phpspec": "^2.2", + "phpunit/phpunit": "~4.8" + }, + "suggest": { + "ext-fileinfo": "Required for MimeType", + "league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2", + "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", + "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", + "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", + "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", + "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", + "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", + "league/flysystem-webdav": "Allows you to use WebDAV storage", + "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter", + "spatie/flysystem-dropbox": "Allows you to use Dropbox storage", + "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Flysystem\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frenky.net" + } + ], + "description": "Filesystem abstraction: Many filesystems, one API.", + "keywords": [ + "Cloud Files", + "WebDAV", + "abstraction", + "aws", + "cloud", + "copy.com", + "dropbox", + "file systems", + "files", + "filesystem", + "filesystems", + "ftp", + "rackspace", + "remote", + "s3", + "sftp", + "storage" + ], + "time": "2017-08-06T17:41:04+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "symfony/console", + "version": "v3.3.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "b0878233cb5c4391347e5495089c7af11b8e6201" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/b0878233cb5c4391347e5495089c7af11b8e6201", + "reference": "b0878233cb5c4391347e5495089c7af11b8e6201", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3", + "symfony/dependency-injection": "~3.3", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/filesystem": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/filesystem": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2017-07-29T21:27:59+00:00" + }, + { + "name": "symfony/debug", + "version": "v3.3.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/7c13ae8ce1e2adbbd574fc39de7be498e1284e13", + "reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/http-kernel": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2017-07-28T15:27:31+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2017-06-14T15:44:48+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/new-site.php b/new-site.php index 0568f8a..53e593d 100644 --- a/new-site.php +++ b/new-site.php @@ -5,18 +5,17 @@ // Nginx conf // Git repo // Directory structure - // Handle options $options = getopt('d:n:'); if (!array_key_exists('d', $options)) { - echo "please provide a domain (-d)\n"; - exit(1); + echo "please provide a domain (-d)\n"; + exit(1); } if (!array_key_exists('n', $options)) { - echo "please provide a name (-n)\n"; - exit(1); + echo "please provide a name (-n)\n"; + exit(1); } $domain = $options['d']; @@ -29,23 +28,23 @@ $conf = sprintf($conf[0], $domain, $name, $name, $name, $name, $name); echo "Making directory structure\n"; if (!mkdir('/web/sites/' . $name)) { - echo "Failed to create '/web/sites/'" . $name . "\n"; - exit(1); + echo "Failed to create '/web/sites/'" . $name . "\n"; + exit(1); } chown('/web/sites/' . $name, "nginx"); if (!mkdir('/web/sites/' . $name . '/logs')) { - echo "Failed to create '/web/sites/'" . $name . "/logs\n"; - exit(1); + echo "Failed to create '/web/sites/'" . $name . "/logs\n"; + exit(1); } chown('/web/sites/' . $name . '/logs', "nginx"); if (!mkdir('/web/sites/' . $name . '/web')) { - echo "Failed to create '/web/sites/'" . $name . "/web\n"; - exit(1); + echo "Failed to create '/web/sites/'" . $name . "/web\n"; + exit(1); } chown('/web/sites/' . $name . '/logs', "nginx"); @@ -53,7 +52,7 @@ chown('/web/sites/' . $name . '/logs', "nginx"); echo "Complete\n"; if (!file_put_contents("/web/etc/nginx/" . $name . ".conf", $conf)) { - echo "Failed to write nginx conf\n"; + echo "Failed to write nginx conf\n"; } chown('/web/etc/nginx/' . $name . ".conf", "nginx"); diff --git a/scripts/run.php b/scripts/run.php new file mode 100644 index 0000000..3b4de6e --- /dev/null +++ b/scripts/run.php @@ -0,0 +1,95 @@ + + * @param string $message [description] + */ +function finish($message) +{ + if ($message) { + message($message); + exit(); + } +} + +/** + * Echo a message + * + * @author Phil Burton + * @param string $message [description] + */ +function message($message) +{ + echo $message . PHP_EOL; +} +// +// $domain = $options['d']; +// $name = $options['n']; +// +// $conf = include_once('nginx.php'); +// +// $conf = sprintf($conf[0], $domain, $name, $name, $name, $name, $name); +// +// echo "Making directory structure\n"; +// +// if (!mkdir('/web/sites/' . $name)) { +// echo "Failed to create '/web/sites/'" . $name . "\n"; +// exit(1); +// } +// +// chown('/web/sites/' . $name, "nginx"); +// +// if (!mkdir('/web/sites/' . $name . '/logs')) { +// echo "Failed to create '/web/sites/'" . $name . "/logs\n"; +// exit(1); +// } +// +// chown('/web/sites/' . $name . '/logs', "nginx"); +// +// +// if (!mkdir('/web/sites/' . $name . '/web')) { +// echo "Failed to create '/web/sites/'" . $name . "/web\n"; +// exit(1); +// } +// +// chown('/web/sites/' . $name . '/logs', "nginx"); +// +// echo "Complete\n"; +// +// if (!file_put_contents("/web/etc/nginx/" . $name . ".conf", $conf)) { +// echo "Failed to write nginx conf\n"; +// } +// +// chown('/web/etc/nginx/' . $name . ".conf", "nginx"); +// +// touch('/web/sites/' . $name . '/logs/' . $name . '.access_log'); +// chown('/web/sites/' . $name . '/logs/' . $name . '.access_log', "nginx"); +// +// touch('/web/sites/' . $name . '/logs/' . $name . '.error_log'); +// chown('/web/sites/' . $name . '/logs/' . $name . '.error_log', "nginx"); +// +// touch('/web/sites/' . $name . '/web/index.php'); +// chown('/web/sites/' . $name . '/web/index.php', "nginx"); diff --git a/scripts/test.php b/scripts/test.php new file mode 100644 index 0000000..83d8c5a --- /dev/null +++ b/scripts/test.php @@ -0,0 +1,13 @@ +filename = $filename; + + if (!is_writable(dirname($filename))) { + throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename); + } + } + + abstract public function excecute(); +} diff --git a/src/Filesystem/CreateDirectory.php b/src/Filesystem/CreateDirectory.php new file mode 100644 index 0000000..0c45c6c --- /dev/null +++ b/src/Filesystem/CreateDirectory.php @@ -0,0 +1,25 @@ +addArgument('name', InputArgument::REQUIRED, 'The name of the new site.'); + + $this + ->addArgument('domain', InputArgument::REQUIRED, 'The domain name of the new site.'); + + $this + ->setName('site:create') + ->setDescription('Create a new site.') + ->setHelp('This command allows you to create a new site.') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $taskCount = 6; + $output->writeln( + 'Creating new site with domain: ' + . $input->getArgument('domain') + . ' and name: ' + . $input->getArgument('name') + ); + + $progressBar = new ProgressBar($output, $taskCount); + $progressBar->setFormatDefinition('custom', ' %current%/%max% -- %message%'); + $progressBar->setFormat('custom'); + $progressBar->setMessage('Starting...'); + $progressBar->start(); + $progressBar->setMessage('Running pre-flight checks'); + + $progressBar->advance(); + try { + $create = new \App\Filesystem\CreateFile(DIPPER_ROOT . '/foo.test'); + $create = new \App\Filesystem\CreateDirectory(DIPPER_ROOT); + sleep(1); + } catch (\Exception $e) { + $output->writeln('Error with pre-flight checks'); + $output->writeln($e->getMessage()); + exit; + } + + $progressBar->advance(); + $progressBar->setMessage('Creating directory structure'); + sleep(1); + + $progressBar->advance(); + $progressBar->setMessage('Creating nginx config'); + sleep(1); + + $progressBar->advance(); + $progressBar->setMessage('Creating default index.php'); + sleep(1); + + $progressBar->advance(); + $progressBar->setMessage('Creating nginx config'); + sleep(1); + + $progressBar->advance(); + $progressBar->finish(); + + $output->writeln(''); + $output->writeln('Complete'); + } +} diff --git a/src/Script/Console.php b/src/Script/Console.php new file mode 100644 index 0000000..926f41f --- /dev/null +++ b/src/Script/Console.php @@ -0,0 +1,16 @@ +add(new Site()); + $application->run(); + } +} -- cgit v1.2.3