streams/util/addons

146 lines
3 KiB
Text
Raw Normal View History

2016-01-13 02:00:20 +00:00
#!/usr/bin/env php
<?php
// Hubzilla plugin management utility
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();
$plugs = get_config('system', 'addon');
$plugins_arr = array();
if($plugs)
$plugins_arr = explode(',', str_replace(' ', '', $plugs));
2016-03-31 23:06:03 +00:00
App::$plugins = $plugins_arr;
2016-01-13 02:00:20 +00:00
$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);
2016-03-31 23:06:03 +00:00
$enabled = in_array($id,App::$plugins);
2016-01-13 02:00:20 +00:00
$x = check_plugin_versions($info);
if($enabled && ! $x) {
$enabled = false;
2016-03-31 23:06:03 +00:00
$idz = array_search($id, App::$plugins);
2016-01-13 02:00:20 +00:00
if ($idz !== false) {
2016-03-31 23:06:03 +00:00
unset(App::$plugins[$idz]);
2016-01-13 02:00:20 +00:00
uninstall_plugin($id);
2016-03-31 23:06:03 +00:00
set_config("system","addon", implode(", ",App::$plugins));
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 {
2016-03-31 23:06:03 +00:00
App::$plugins[] = $p[0];
2016-01-13 02:00:20 +00:00
install_plugin($p[0]);
2016-03-31 23:06:03 +00:00
set_config("system","addon", implode(", ",App::$plugins));
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 {
2016-03-31 23:06:03 +00:00
$idx = array_search($p[0], App::$plugins);
2016-01-13 02:00:20 +00:00
if ($idx !== false)
2016-03-31 23:06:03 +00:00
unset(App::$plugins[$idx]);
2016-01-13 02:00:20 +00:00
uninstall_plugin($p[0]);
2016-03-31 23:06:03 +00:00
set_config("system","addon", implode(", ",App::$plugins));
2016-01-13 02:00:20 +00:00
echo $p[0] . ' uninstalled.' . "\n";
}
}
}
}
// force uninstall of addon which no longer exists
if(! $found) {
$idx = array_search($argv[2], App::$plugins);
if ($idx !== false)
unset(App::$plugins[$idx]);
uninstall_plugin($argv[2]);
set_config("system","addon", implode(", ",App::$plugins));
echo $argv[2] . ' uninstalled.' . "\n";
}
2016-01-13 02:00:20 +00:00
killme();
}