streams/util/addons

130 lines
2.4 KiB
Text
Raw Permalink Normal View History

2016-01-13 02:00:20 +00:00
#!/usr/bin/env php
<?php
// plugin management utility
2022-02-16 04:08:28 +00:00
use Code\Lib\Addon;
2016-01-13 02:00:20 +00:00
2016-01-13 02:00:20 +00:00
function usage() {
echo <<< EOT
Usage:
util/addons list # list installed addons
util/addons list all # list all addons (*)= installed, (!)= disabled due to version compatibility
util/addons install foo # install addon named 'foo'
util/addons uninstall foo # uninstall addon named 'foo'
2016-01-13 02:00:20 +00:00
EOT;
}
require_once('include/cli_startup.php');
cli_startup();
$installed = Addon::list_installed();
$plugins = [];
2016-01-13 02:00:20 +00:00
$files = glob('addon/*/');
if($files) {
foreach($files as $file) {
if(is_dir($file)){
list($tmp, $id) = array_map('trim', explode('/', $file));
2022-02-12 19:22:42 +00:00
$info = Addon::get_info($id);
$enabled = in_array($id,$installed);
2022-03-13 01:50:30 +00:00
$x = Addon::check_versions($info);
2016-01-13 02:00:20 +00:00
if($enabled && ! $x) {
$enabled = false;
Addon::uninstall($id);
$installed = Addon::list_installed();
}
2016-01-13 02:00:20 +00:00
$info['disabled'] = 1-intval($x);
$plugins[] = array( $id, (($enabled)? '*' : '') , $info);
}
}
}
if($argc == 1) {
usage();
killme();
}
if($argc == 2 && $argv[1] === 'list') {
if($plugins) {
foreach($plugins as $p) {
if($p[1]) {
echo $p[0] . "\n";
}
2016-01-13 02:00:20 +00:00
}
}
2016-01-13 02:00:20 +00:00
killme();
}
if($argc == 3 && $argv[1] === 'list' && $argv[2] === 'all') {
if($plugins) {
foreach($plugins as $p) {
echo $p[0] . (($p[1]) ? $p[1] : (($p[2]['disabled']) ? '!' : '')) . "\n";
}
}
killme();
}
if($argc == 3 && $argv[1] === 'install') {
if($plugins) {
foreach($plugins as $p) {
if($p[0] === $argv[2]) {
if($p[1])
echo $p[0] . ' already installed.' . "\n";
elseif($p[2]['disabled'])
echo $p[0] . ' disabled (version compatibility).' . "\n";
else {
Addon::install($p[0]);
2016-01-13 02:00:20 +00:00
echo $p[0] . ' installed.' . "\n";
}
}
}
}
killme();
}
if($argc == 3 && $argv[1] === 'uninstall') {
$found = false;
2016-01-13 02:00:20 +00:00
if($plugins) {
foreach($plugins as $p) {
if($p[0] === $argv[2]) {
$found = true;
2016-01-13 02:00:20 +00:00
if(! $p[1])
echo $p[0] . ' not installed.' . "\n";
elseif($p[2]['disabled'])
echo $p[0] . ' disabled (version compatibility).' . "\n";
else {
Addon::uninstall($p[0]);
2016-01-13 02:00:20 +00:00
echo $p[0] . ' uninstalled.' . "\n";
}
}
}
}
// force uninstall of addon which no longer exists
if(! $found) {
Addon::uninstall($argv[2]);
echo $argv[2] . ' uninstalled.' . "\n";
}
2016-01-13 02:00:20 +00:00
killme();
}