Skip to content

Commit f8b551e

Browse files
author
Marius Burkard
committed
- added helper script for installing addons
1 parent 46f5b91 commit f8b551e

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

server/addons.php

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
Copyright (c) 2007-2016, Till Brehm, projektfarm Gmbh
4+
Copyright (c) 2018 Marius Burkard, ISPConfig UG
55
All rights reserved.
66
77
Redistribution and use in source and binary forms, with or without modification,
@@ -38,35 +38,33 @@
3838
// make sure server_id is always an int
3939
$conf['server_id'] = intval($conf['server_id']);
4040

41-
// Load required base-classes
42-
$app->uses('ini_parser,file,services,getconf,system,cron,functions');
43-
$app->load('libdatetime,cronjob');
44-
45-
// Path settings
46-
$path = SCRIPT_PATH . '/lib/classes/cron.d';
47-
48-
//** Get commandline options
49-
$cmd_opt = getopt('', array('cronjob::'));
50-
51-
if(isset($cmd_opt['cronjob']) && is_file($path.'/'.$cmd_opt['cronjob'])) {
52-
// Cronjob that shell be run
53-
$cronjob_file = $cmd_opt['cronjob'];
54-
} else {
55-
die('Usage example: php cron_debug.php --cronjob=100-mailbox_stats.inc.php');
41+
if(!isset($_SERVER['argv'])) {
42+
die('No package path given.');
5643
}
5744

58-
// Load and run the cronjob
59-
$name = substr($cronjob_file, 0, strpos($cronjob_file, '.'));
60-
if(preg_match('/^\d+\-(.*)$/', $name, $match)) $name = $match[1]; // strip numerical prefix from file name
61-
include $path . '/' . $cronjob_file;
62-
$class_name = 'cronjob_' . $name;
63-
$cronjob = new $class_name();
45+
$action = '';
46+
$package = '';
6447

65-
$cronjob->onPrepare();
66-
$cronjob->onBeforeRun();
67-
$cronjob->onRunJob();
68-
$cronjob->onAfterRun();
69-
70-
die("finished.\n");
48+
$argv = $_SERVER['argv'];
49+
for($a = 0; $a < count($argv); $a++) {
50+
if($argv[$a] === '--install' || $argv[$a] === 'install'
51+
|| $argv[$a] === '--update' || $argv[$a] === 'update') {
52+
$action = 'install';
53+
} elseif($argv[$a] === '--uninstall' || $argv[$a] === 'uninstall') {
54+
$action = 'uninstall';
55+
} elseif(substr($argv[$a], -4) === '.pkg' && is_file($argv[$a])) {
56+
$package = $argv[$a];
57+
} else {
58+
die('Unknown argument ' . $argv[$a]);
59+
}
60+
}
7161

72-
?>
62+
if($action == 'uninstall') {
63+
die('Automatic uninstall not supported, yet.');
64+
} else {
65+
try {
66+
$app->addon_installer->installAddon($package);
67+
} catch(Exception $e) {
68+
die('Error: ' . $e->getMessage() . "\n");
69+
}
70+
}

server/lib/classes/ispconfig_addon_installer_base.inc.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ protected function copyServerFiles() {
7272
}
7373
}
7474

75+
protected function copyAddonFiles() {
76+
global $app, $conf;
77+
78+
$install_dir = realpath($conf['rootpath'] . '/..') . '/addons/' . $this->addon_ident;
79+
if(!is_dir($install_dir)) {
80+
if(!$app->system->mkdir($install_dir, false, 0750, true)) {
81+
throw new AddonInstallerException('Could not create addons dir ' . $install_dir);
82+
}
83+
}
84+
85+
if(is_dir($this->temp_dir . '/install')) {
86+
$ret = null;
87+
$retval = 0;
88+
$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 . '/');
89+
exec($command, $ret, $retval);
90+
if($retval != 0) {
91+
throw new AddonInstallerException('Command ' . $command . ' failed with code ' . $retval);
92+
}
93+
94+
return true;
95+
} else {
96+
return false;
97+
}
98+
}
99+
75100
protected function executeSqlStatements() {
76101
global $app, $conf;
77102

@@ -128,6 +153,7 @@ protected function executeSqlStatements() {
128153
public function onBeforeInstall() { }
129154

130155
public function onInstall() {
156+
$this->copyAddonFiles();
131157
$this->copyInterfaceFiles();
132158
$this->copyServerFiles();
133159
$this->executeSqlStatements();
@@ -138,6 +164,7 @@ public function onAfterInstall() { }
138164
public function onBeforeUpdate() { }
139165

140166
public function onUpdate() {
167+
$this->copyAddonFiles();
141168
$this->copyInterfaceFiles();
142169
$this->copyServerFiles();
143170
$this->executeSqlStatements();

0 commit comments

Comments
 (0)