mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-21 09:35:21 +00:00
129 lines
2.4 KiB
PHP
Executable file
129 lines
2.4 KiB
PHP
Executable file
#!/usr/bin/env php
|
|
<?php
|
|
|
|
// plugin management utility
|
|
use Code\Lib\Addon;
|
|
|
|
|
|
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'
|
|
|
|
EOT;
|
|
}
|
|
|
|
require_once('include/cli_startup.php');
|
|
|
|
cli_startup();
|
|
|
|
$installed = Addon::list_installed();
|
|
|
|
|
|
$plugins = [];
|
|
$files = glob('addon/*/');
|
|
if($files) {
|
|
foreach($files as $file) {
|
|
if(is_dir($file)){
|
|
list($tmp, $id) = array_map('trim', explode('/', $file));
|
|
$info = Addon::get_info($id);
|
|
$enabled = in_array($id,$installed);
|
|
$x = check_plugin_versions($info);
|
|
if($enabled && ! $x) {
|
|
$enabled = false;
|
|
Addon::uninstall($id);
|
|
$installed = Addon::list_installed();
|
|
}
|
|
|
|
$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";
|
|
}
|
|
}
|
|
}
|
|
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]);
|
|
echo $p[0] . ' installed.' . "\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
killme();
|
|
}
|
|
|
|
|
|
|
|
if($argc == 3 && $argv[1] === 'uninstall') {
|
|
|
|
$found = false;
|
|
|
|
if($plugins) {
|
|
foreach($plugins as $p) {
|
|
if($p[0] === $argv[2]) {
|
|
$found = true;
|
|
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]);
|
|
echo $p[0] . ' uninstalled.' . "\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// force uninstall of addon which no longer exists
|
|
|
|
if(! $found) {
|
|
Addon::uninstall($argv[2]);
|
|
echo $argv[2] . ' uninstalled.' . "\n";
|
|
}
|
|
|
|
killme();
|
|
}
|
|
|
|
|