From c0c6ac506033cb7000df8f1cb290633bd1f1f251 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 10 Jun 2013 14:04:31 -0400
Subject: [PATCH] Add deploy cli script

This will allow folks following the git development model to checkout the
sourcecode to one folder, follow an upstream git brach, and deploy the
osticket installation from a current branch to a location somewhere.

The deploy process differs from the unpack process in that it does not
assume to be inside an 'upload/' folder from the install zipball, and it
does not deploy the 'setup/' folder.

The include folder is still supported to be installed elsewhere.
---
 setup/cli/modules/deploy.php | 57 ++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 setup/cli/modules/deploy.php

diff --git a/setup/cli/modules/deploy.php b/setup/cli/modules/deploy.php
new file mode 100644
index 000000000..9e9285479
--- /dev/null
+++ b/setup/cli/modules/deploy.php
@@ -0,0 +1,57 @@
+<?php
+require_once dirname(__file__) . "/class.module.php";
+require_once dirname(__file__) . "/unpack.php";
+
+class Deployment extends Unpacker {
+    var $prologue = "Deploys osTicket into target install path";
+
+    var $epilog =
+        "Deployment is used from the continuous development model. If you
+        are following the upstream git repo, then you can use the deploy
+        script to deploy changes made by you or upstream development to your
+        installation target";
+
+    function find_root_folder() {
+        # Hop up to the root folder of this repo
+        $start = dirname(__file__);
+        for (;;) {
+            if (is_file($start . '/main.inc.php')) break;
+            $start .= '/..';
+        }
+        return realpath($start);
+    }
+
+    function run($args, $options) {
+        $this->destination = $args['install-path'];
+        if (!is_dir($this->destination))
+            if (!@mkdir($this->destination, 0751, true))
+                die("Destination path does not exist and cannot be created");
+        $this->destination = realpath($this->destination).'/';
+
+        # Determine if this is an upgrade, and if so, where the include/
+        # folder is currently located
+        $upgrade = file_exists("{$this->destination}/main.inc.php");
+
+        # Get the current value of the INCLUDE_DIR before overwriting
+        # main.inc.php
+        $include = ($upgrade) ? $this->get_include_dir()
+            : ($options['include'] ? $options['include']
+                : "{$this->destination}/include");
+        if (substr($include, -1) !== '/')
+            $include .= '/';
+
+        # Locate the upload folder
+        $root = $this->find_root_folder();
+
+        # Unpack everything but the include/ folder
+        $this->unpackage("$root/*", $this->destination, -1,
+            array("$root/setup", "$root/include", "*.md", "*.txt"));
+        # Unpack the include folder
+        $this->unpackage("$root/include/*", $include, -1);
+        if (!$upgrade && $include != "{$this->destination}/include")
+            $this->change_include_dir($include);
+    }
+}
+
+Module::register('deploy', 'Deployment');
+?>
-- 
GitLab