#!/usr/bin/env php 1) { print 'FATAL: This utility is designed for the main Data Collector only' . PHP_EOL; exit(1); } // process calling arguments $parms = $_SERVER['argv']; array_shift($parms); $debug = false; $force = false; if (cacti_sizeof($parms)) { $shortopts = 'VvHh'; $longopts = [ // Options without a value 'debug', 'force', 'version', 'help', ]; $options = getopt($shortopts, $longopts); foreach ($options as $arg => $value) { switch($arg) { case 'debug': $debug = true; break; case 'force': $force = true; break; case 'version': case 'V': case 'v': display_version(); exit(0); case 'help': case 'H': case 'h': display_help(); exit(0); default: print "ERROR: Invalid Argument: ($arg)" . PHP_EOL . PHP_EOL; display_help(); exit(1); } } } $fstart = microtime(true); $php_binary = read_config_option('path_php_binary'); if (!$force) { if (!register_process_start('pfetch', 'master', 0, 900)) { print 'WARNING: Another plugin fetch process is running' . PHP_EOL; exit(0); } } else { debug('Fetch Process is being forced'); } debug('About to fetch Cacti Plugins from GitHub'); plugin_fetch_latest_plugins(); if (!$force) { unregister_process('pfetch', 'master', 0); } $fend = microtime(true); debug(sprintf('Fetch Process has Completed in %0.2f seconds', $fend - $fstart)); exit(0); function debug(string $message) : void { global $debug; if ($debug) { print('DEBUG: ' . trim($message) . PHP_EOL); } } /** * display_version - displays version information * * @return void */ function display_version() : void { $version = get_cacti_cli_version(); print "Cacti Fetch Latest Plugins Utility, Version $version, " . COPYRIGHT_YEARS . PHP_EOL; } /** * display_help - displays the usage of the function * * @return void */ function display_help() : void { display_version(); print PHP_EOL; print 'usage: fetch_plugins.php [ --debug ]' . PHP_EOL . PHP_EOL; print 'A utility gathers the latest official plugins from the Cacti Group GitHub' . PHP_EOL; print 'site and prepares them from loading and install' . PHP_EOL; }