summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Burton <phil@pgburton.com>2017-08-22 10:10:29 +0100
committerPhil Burton <phil@pgburton.com>2017-08-22 10:10:29 +0100
commit7b1e62d0cbc3519c469b2afd4da712125707de66 (patch)
tree06ee38c18849f9b0c85c2eb82bded824e2ff34e6
parenta4170353515c254ab7404117e7d9b3f15887214a (diff)
parent47b154758e789e75ec597d88540cdb7f4e352225 (diff)
Merge branch 'master' of www.blatech.co.uk:FBeans/dipper
-rw-r--r--nginx/stub.php (renamed from nginx.php)0
-rw-r--r--scripts/run.php89
-rw-r--r--scripts/test.php15
-rw-r--r--src/Filesystem/CreateFile.php13
-rw-r--r--src/Nginx/Restart.php21
-rw-r--r--src/Script/Command/Site/Create.php5
6 files changed, 41 insertions, 102 deletions
diff --git a/nginx.php b/nginx/stub.php
index e362fb3..e362fb3 100644
--- a/nginx.php
+++ b/nginx/stub.php
diff --git a/scripts/run.php b/scripts/run.php
index 3b4de6e..0ba999a 100644
--- a/scripts/run.php
+++ b/scripts/run.php
@@ -8,88 +8,9 @@ error_reporting(E_ALL);
require(realpath(dirname(__FILE__) . "/../bootstrap.php"));
// Set up siteroot
-define('DIPPER_ROOT', realpath(dirname(__FILE__) . "/../"));
+// TODO Don't rely on trailing slashes here
+define('DIPPER_ROOT', realpath(dirname(__FILE__) . "/../") . '/');
+define('SITES_ROOT', '/home/phil/sites/');
+define('CONFIG_ROOT', '/home/phil/sites/');
-// Handle options
-$options = getopt('d:n:');
-
-if (!array_key_exists('d', $options)) {
- finish("please provide a domain (-d)");
-}
-
-if (!array_key_exists('n', $options)) {
- finish("please provide a name (-n)");
-}
-
-/**
- * Exit application with optional mesage
- *
- * @author Phil Burton <phil@pgburton.com>
- * @param string $message [description]
- */
-function finish($message)
-{
- if ($message) {
- message($message);
- exit();
- }
-}
-
-/**
- * Echo a message
- *
- * @author Phil Burton <phil@pgburton.com>
- * @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");
+new App\Script\Console;
diff --git a/scripts/test.php b/scripts/test.php
deleted file mode 100644
index f1203ce..0000000
--- a/scripts/test.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-ini_set("display_errors", 1);
-ini_set("display_startup_errors", 1);
-error_reporting(E_ALL);
-
-// Pull in bootstrap
-require(realpath(dirname(__FILE__) . "/../bootstrap.php"));
-
-// Set up siteroot
-define('DIPPER_ROOT', realpath(dirname(__FILE__) . "/../"));
-define('SITES_ROOT', '/home/phil/sites/');
-define('CONFIG_ROOT', '/home/phil/sites/');
-
-new App\Script\Console;
diff --git a/src/Filesystem/CreateFile.php b/src/Filesystem/CreateFile.php
index 08ba0db..93c66a6 100644
--- a/src/Filesystem/CreateFile.php
+++ b/src/Filesystem/CreateFile.php
@@ -18,16 +18,22 @@ class CreateFile
protected $filename;
+ protected $contents;
+
/**
* Check if the file already exists
*
* @param string $filename
* @author Phil Burton <phil@d3r.com>
*/
- public function __construct(string $filename)
+ public function __construct(string $filename, $contents = false)
{
$this->filename = $filename;
+ if ($contents) {
+ $this->contents = $contents;
+ }
+
if (!is_writable(dirname($filename))) {
throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename);
}
@@ -45,5 +51,10 @@ class CreateFile
public function execute()
{
touch($this->filename);
+
+ $contents = $this->contents;
+ if ($contents) {
+ file_put_contents($this->filename, $contents);
+ }
}
}
diff --git a/src/Nginx/Restart.php b/src/Nginx/Restart.php
new file mode 100644
index 0000000..cd150be
--- /dev/null
+++ b/src/Nginx/Restart.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Nginx;
+
+/**
+ * Restarts nginx
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
+class Restart
+{
+ /**
+ * Create the new file
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
+ public function restart()
+ {
+
+ }
+}
diff --git a/src/Script/Command/Site/Create.php b/src/Script/Command/Site/Create.php
index c7936fd..81df87e 100644
--- a/src/Script/Command/Site/Create.php
+++ b/src/Script/Command/Site/Create.php
@@ -52,7 +52,7 @@ class Create extends SyCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $taskCount = 6;
+ $taskCount = 9;
$name = $input->getArgument('name');
$domain = $input->getArgument('domain');
@@ -83,7 +83,8 @@ class Create extends SyCommand
);
$tasks['Creating nginx config file'] = new \App\Filesystem\CreateFile(
- CONFIG_ROOT . $name . '.conf'
+ CONFIG_ROOT . $name . '.conf',
+ include_once(DIPPER_ROOT . 'nginx/stub.php')
);
} catch (\Exception $e) {
$output->writeln('');