1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#!/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'
util/addons reinstall # reinstall all plugins
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));
App::$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,App::$plugins);
$x = check_plugin_versions($info);
if($enabled && ! $x) {
$enabled = false;
$idz = array_search($id, App::$plugins);
if ($idz !== false) {
unset(App::$plugins[$idz]);
uninstall_plugin($id);
set_config("system","addon", implode(", ",App::$plugins));
}
}
$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 == 2 && $argv[1] === 'reinstall') {
require_once("include/plugin.php");
if($plugins) {
foreach($plugins as $p) {
if($p[1]) {
echo "Reinstall: ". $p[0] . "\n";
uninstall_plugin($p[0]);
install_plugin($p[0]);
}
}
}
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 {
App::$plugins[] = $p[0];
install_plugin($p[0]);
set_config("system","addon", implode(", ",App::$plugins));
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 {
$idx = array_search($p[0], App::$plugins);
if ($idx !== false)
unset(App::$plugins[$idx]);
uninstall_plugin($p[0]);
set_config("system","addon", implode(", ",App::$plugins));
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";
}
killme();
}
|