From f757285ea8f0a7f82f84c00061ff1ab6c69a9aa0 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 12 Jan 2016 18:00:20 -0800 Subject: cli utility for managing addons --- util/addons | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100755 util/addons (limited to 'util/addons') diff --git a/util/addons b/util/addons new file mode 100755 index 000000000..602cc228e --- /dev/null +++ b/util/addons @@ -0,0 +1,130 @@ +#!/usr/bin/env php +plugins = $plugins_arr; + + $plugins = array(); + $files = glob('addon/*/'); + if($files) { + foreach($files as $file) { + if(is_dir($file)){ + list($tmp, $id) = array_map('trim', explode('/', $file)); + $info = get_plugin_info($id); + $enabled = in_array($id,$a->plugins); + $x = check_plugin_versions($info); + if($enabled && ! $x) { + $enabled = false; + $idz = array_search($id, $a->plugins); + if ($idz !== false) { + unset($a->plugins[$idz]); + uninstall_plugin($id); + set_config("system","addon", implode(", ",$a->plugins)); + } + } + $info['disabled'] = 1-intval($x); + + $plugins[] = array( $id, (($enabled)? '*' : '') , $info); + } + } + } + +if($argc == 1) { + usage(); + killme(); +} + + +if($argc == 2 && $argv[1] === 'list') { + $r = q("select * from addon where installed = 1"); + if($r) { + foreach($r as $rr) { + echo $rr['name'] . "\n"; + } + } + 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 { + $a->plugins[] = $p[0]; + install_plugin($p[0]); + set_config("system","addon", implode(", ",$a->plugins)); + echo $p[0] . ' installed.' . "\n"; + } + } + } + } + + killme(); +} + + + +if($argc == 3 && $argv[1] === 'uninstall') { + + if($plugins) { + foreach($plugins as $p) { + if($p[0] === $argv[2]) { + if(! $p[1]) + echo $p[0] . ' not installed.' . "\n"; + elseif($p[2]['disabled']) + echo $p[0] . ' disabled (version compatibility).' . "\n"; + else { + $idx = array_search($p[0], $a->plugins); + if ($idx !== false) + unset($a->plugins[$idx]); + uninstall_plugin($p[0]); + set_config("system","addon", implode(", ",$a->plugins)); + echo $p[0] . ' uninstalled.' . "\n"; + } + } + } + } + + killme(); +} + + -- cgit v1.2.3 From 58efd7553c9ec872a64d430efd90ff62c6b4e3e5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 13 Jan 2016 00:08:07 -0800 Subject: very small tweaks to CLI plugin manager utility --- util/addons | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'util/addons') diff --git a/util/addons b/util/addons index 602cc228e..2c128c50e 100755 --- a/util/addons +++ b/util/addons @@ -10,6 +10,7 @@ echo <<< EOT 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' + EOT; } @@ -58,12 +59,13 @@ if($argc == 1) { if($argc == 2 && $argv[1] === 'list') { - $r = q("select * from addon where installed = 1"); - if($r) { - foreach($r as $rr) { - echo $rr['name'] . "\n"; + if($plugins) { + foreach($plugins as $p) { + if($p[1]) { + echo $p[0] . "\n"; + } } - } + } killme(); } -- cgit v1.2.3 From 9abd95fad3784a10fc48bc40f9b8a75d7d74edda Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 31 Mar 2016 16:06:03 -0700 Subject: static App --- util/addons | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'util/addons') diff --git a/util/addons b/util/addons index 2c128c50e..8fcd40cbc 100755 --- a/util/addons +++ b/util/addons @@ -25,7 +25,7 @@ $a = get_app(); if($plugs) $plugins_arr = explode(',', str_replace(' ', '', $plugs)); - $a->plugins = $plugins_arr; + App::$plugins = $plugins_arr; $plugins = array(); $files = glob('addon/*/'); @@ -34,15 +34,15 @@ $a = get_app(); if(is_dir($file)){ list($tmp, $id) = array_map('trim', explode('/', $file)); $info = get_plugin_info($id); - $enabled = in_array($id,$a->plugins); + $enabled = in_array($id,App::$plugins); $x = check_plugin_versions($info); if($enabled && ! $x) { $enabled = false; - $idz = array_search($id, $a->plugins); + $idz = array_search($id, App::$plugins); if ($idz !== false) { - unset($a->plugins[$idz]); + unset(App::$plugins[$idz]); uninstall_plugin($id); - set_config("system","addon", implode(", ",$a->plugins)); + set_config("system","addon", implode(", ",App::$plugins)); } } $info['disabled'] = 1-intval($x); @@ -91,9 +91,9 @@ if($argc == 3 && $argv[1] === 'install') { elseif($p[2]['disabled']) echo $p[0] . ' disabled (version compatibility).' . "\n"; else { - $a->plugins[] = $p[0]; + App::$plugins[] = $p[0]; install_plugin($p[0]); - set_config("system","addon", implode(", ",$a->plugins)); + set_config("system","addon", implode(", ",App::$plugins)); echo $p[0] . ' installed.' . "\n"; } } @@ -115,11 +115,11 @@ if($argc == 3 && $argv[1] === 'uninstall') { elseif($p[2]['disabled']) echo $p[0] . ' disabled (version compatibility).' . "\n"; else { - $idx = array_search($p[0], $a->plugins); + $idx = array_search($p[0], App::$plugins); if ($idx !== false) - unset($a->plugins[$idx]); + unset(App::$plugins[$idx]); uninstall_plugin($p[0]); - set_config("system","addon", implode(", ",$a->plugins)); + set_config("system","addon", implode(", ",App::$plugins)); echo $p[0] . ' uninstalled.' . "\n"; } } -- cgit v1.2.3