function run($args, $options) { if ($options['dns']) return $this->print_dns(); // Set some forced args and options $temp = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $stage_path = $temp . 'osticket' . substr(md5('osticket-stage'.getmypid().getcwd()), -8); $args['install-path'] = $stage_path . '/upload'; // Deployment will auto-create the staging area // Ensure that the staging path is cleaned up on exit register_shutdown_function(function() use ($stage_path) { $delTree = function($dir) use (&$delTree) { $files = array_diff(scandir($dir), array('.','..')); foreach ($files as $file) { (is_dir("$dir/$file")) ? $delTree("$dir/$file") : unlink("$dir/$file"); } return rmdir($dir); }; return $delTree($stage_path); }); $options['setup'] = true; $options['git'] = true; $options['verbose'] = true; $options['clean'] = false; $options['dry-run'] = false; $options['include'] = false; $this->_args = $args; $this->_options = $options; // TODO: Run the testing applet first $root = $this->find_root_folder(); if (!$this->getOption('skip-test') && $this->run_tests($root) > 0) $this->fail("Regression tests failed. Cowardly refusing to package"); // Run the deployment // NOTE: The deployment will change the working directory parent::run($args, $options); // Deploy the `setup/scripts` folder to `/scripts` $root = $this->source; Unpacker::unpackage("$root/setup/scripts/{,.}*", "$stage_path/scripts", -1); // Package up the staging area $version = exec('git describe'); switch (strtolower($this->getOption('format'))) { case 'zip': default: $this->packageZip("$root/osTicket-$version.zip", $stage_path); } }
function unpackage($folder, $destination, $recurse=0, $exclude=false) { $use_git = $this->getOption('git', false); if (!$use_git) return parent::unpackage($folder, $destination, $recurse, $exclude); // Attempt to read from git using `git ls-files` for deployment if (substr($destination, -1) !== '/') $destination .= '/'; $source = $this->source; if (substr($source, -1) != '/') $source .= '/'; $local = str_replace(array($source, '{,.}*'), array('',''), $folder); $pipes = array(); $patterns = array(); foreach ((array) $exclude as $x) { $patterns[] = str_replace($source, '', $x); } $X = implode(' --exclude-per-directory=', $patterns); chdir($source.$local); if (!($files = proc_open( "git ls-files -zs --exclude-standard --exclude-per-directory=$X -- .", array(1 => array('pipe', 'w')), $pipes ))) { return parent::unpackage($folder, $destination, $recurse, $exclude); } $dryrun = $this->getOption('dry-run', false); $verbose = $this->getOption('verbose') || $dryrun; while ($line = stream_get_line($pipes[1], 255, "\x00")) { list($mode, $hash, , $path) = preg_split('/\s+/', $line); $src = $source.$local.$path; if ($this->exclude($exclude, $src)) continue; if (!$this->isChanged($src, $hash)) continue; $dst = $destination.$path; if ($verbose) $this->stdout->write($dst."\n"); if ($dryrun) continue; if (!is_dir(dirname($dst))) mkdir(dirname($dst), 0755, true); $this->copyFile($src, $dst, $hash, octdec($mode)); } }