Commit f8b551ed authored by Marius Burkard's avatar Marius Burkard

- added helper script for installing addons

parent 46f5b91a
<?php
/*
Copyright (c) 2007-2016, Till Brehm, projektfarm Gmbh
Copyright (c) 2018 Marius Burkard, ISPConfig UG
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
......@@ -38,35 +38,33 @@ ini_set('error_reporting', E_ALL & ~E_NOTICE);
// make sure server_id is always an int
$conf['server_id'] = intval($conf['server_id']);
// Load required base-classes
$app->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
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment