11<?php
22
33/*
4- Copyright (c) 2007-2016, Till Brehm, projektfarm Gmbh
4+ Copyright (c) 2018 Marius Burkard, ISPConfig UG
55All rights reserved.
66
77Redistribution and use in source and binary forms, with or without modification,
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+ }
0 commit comments