From f8b551ed0aceb1c71dcdf4a5bef21a1691056af8 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Fri, 16 Nov 2018 15:53:55 +0100 Subject: [PATCH] - added helper script for installing addons --- server/addons.php | 56 +++++++++---------- .../ispconfig_addon_installer_base.inc.php | 27 +++++++++ 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/server/addons.php b/server/addons.php index 615a56d743..f914e496e6 100644 --- a/server/addons.php +++ b/server/addons.php @@ -1,7 +1,7 @@ uses('ini_parser,file,services,getconf,system,cron,functions'); -$app->load('libdatetime,cronjob'); - -// Path settings -$path = SCRIPT_PATH . '/lib/classes/cron.d'; - -//** Get commandline options -$cmd_opt = getopt('', array('cronjob::')); - -if(isset($cmd_opt['cronjob']) && is_file($path.'/'.$cmd_opt['cronjob'])) { - // Cronjob that shell be run - $cronjob_file = $cmd_opt['cronjob']; -} else { - die('Usage example: php cron_debug.php --cronjob=100-mailbox_stats.inc.php'); +if(!isset($_SERVER['argv'])) { + die('No package path given.'); } -// Load and run the cronjob -$name = substr($cronjob_file, 0, strpos($cronjob_file, '.')); -if(preg_match('/^\d+\-(.*)$/', $name, $match)) $name = $match[1]; // strip numerical prefix from file name -include $path . '/' . $cronjob_file; -$class_name = 'cronjob_' . $name; -$cronjob = new $class_name(); +$action = ''; +$package = ''; -$cronjob->onPrepare(); -$cronjob->onBeforeRun(); -$cronjob->onRunJob(); -$cronjob->onAfterRun(); - -die("finished.\n"); +$argv = $_SERVER['argv']; +for($a = 0; $a < count($argv); $a++) { + if($argv[$a] === '--install' || $argv[$a] === 'install' + || $argv[$a] === '--update' || $argv[$a] === 'update') { + $action = 'install'; + } elseif($argv[$a] === '--uninstall' || $argv[$a] === 'uninstall') { + $action = 'uninstall'; + } elseif(substr($argv[$a], -4) === '.pkg' && is_file($argv[$a])) { + $package = $argv[$a]; + } else { + die('Unknown argument ' . $argv[$a]); + } +} -?> +if($action == 'uninstall') { + die('Automatic uninstall not supported, yet.'); +} else { + try { + $app->addon_installer->installAddon($package); + } catch(Exception $e) { + die('Error: ' . $e->getMessage() . "\n"); + } +} \ No newline at end of file diff --git a/server/lib/classes/ispconfig_addon_installer_base.inc.php b/server/lib/classes/ispconfig_addon_installer_base.inc.php index e971321ce5..e02ac00360 100644 --- a/server/lib/classes/ispconfig_addon_installer_base.inc.php +++ b/server/lib/classes/ispconfig_addon_installer_base.inc.php @@ -72,6 +72,31 @@ class ispconfig_addon_installer_base { } } + protected function copyAddonFiles() { + global $app, $conf; + + $install_dir = realpath($conf['rootpath'] . '/..') . '/addons/' . $this->addon_ident; + if(!is_dir($install_dir)) { + if(!$app->system->mkdir($install_dir, false, 0750, true)) { + throw new AddonInstallerException('Could not create addons dir ' . $install_dir); + } + } + + if(is_dir($this->temp_dir . '/install')) { + $ret = null; + $retval = 0; + $command = 'cp -rf ' . escapeshellarg($this->temp_dir . '/addon.ini') . ' ' . escapeshellarg($this->temp_dir . '/' . $this->addon_ident . 'addon.php') . ' ' . escapeshellarg($this->temp_dir . '/install'). ' ' . escapeshellarg($install_dir . '/'); + exec($command, $ret, $retval); + if($retval != 0) { + throw new AddonInstallerException('Command ' . $command . ' failed with code ' . $retval); + } + + return true; + } else { + return false; + } + } + protected function executeSqlStatements() { global $app, $conf; @@ -128,6 +153,7 @@ class ispconfig_addon_installer_base { public function onBeforeInstall() { } public function onInstall() { + $this->copyAddonFiles(); $this->copyInterfaceFiles(); $this->copyServerFiles(); $this->executeSqlStatements(); @@ -138,6 +164,7 @@ class ispconfig_addon_installer_base { public function onBeforeUpdate() { } public function onUpdate() { + $this->copyAddonFiles(); $this->copyInterfaceFiles(); $this->copyServerFiles(); $this->executeSqlStatements(); -- GitLab