karnel-termux 4.17.38 → 4.17.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/karnel/RELEASE_COMMIT
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
9381d567e1350c2d361ee0259d3d915ba6859a71
|
|
@@ -25,6 +25,23 @@ plugin_main() {
|
|
|
25
25
|
update)
|
|
26
26
|
_plugin_update_main "$@"
|
|
27
27
|
;;
|
|
28
|
+
enable)
|
|
29
|
+
if [[ $# -ne 1 ]]; then
|
|
30
|
+
log_error "Usage: karnel plugin enable <name>"
|
|
31
|
+
return 1
|
|
32
|
+
fi
|
|
33
|
+
_plugin_enable "$1"
|
|
34
|
+
;;
|
|
35
|
+
disable)
|
|
36
|
+
if [[ $# -ne 1 ]]; then
|
|
37
|
+
log_error "Usage: karnel plugin disable <name>"
|
|
38
|
+
return 1
|
|
39
|
+
fi
|
|
40
|
+
_plugin_disable "$1"
|
|
41
|
+
;;
|
|
42
|
+
config)
|
|
43
|
+
_plugin_config_main "$@"
|
|
44
|
+
;;
|
|
28
45
|
list|ls)
|
|
29
46
|
if [[ $# -ne 0 ]]; then
|
|
30
47
|
log_error "Usage: karnel plugin list"
|
|
@@ -85,6 +102,114 @@ _plugin_install_main() {
|
|
|
85
102
|
install_plugin "$target" "$unsafe_flag"
|
|
86
103
|
}
|
|
87
104
|
|
|
105
|
+
_plugin_enable() {
|
|
106
|
+
local name="$1"
|
|
107
|
+
local plugin_dir plugin_root
|
|
108
|
+
|
|
109
|
+
_plugin_validate_name "$name" || return 1
|
|
110
|
+
_plugin_require_jq || return 1
|
|
111
|
+
_plugin_prepare_plugins_dir || return 1
|
|
112
|
+
plugin_dir="$PLUGINS_DIR/$name"
|
|
113
|
+
if [[ ! -d "$plugin_dir" ]]; then
|
|
114
|
+
log_error "Plugin '$name' is not installed."
|
|
115
|
+
return 1
|
|
116
|
+
fi
|
|
117
|
+
plugin_root="$(_plugin_validate_installed_plugin "$plugin_dir" "$name")" || return 1
|
|
118
|
+
if _plugin_is_enabled "$plugin_root"; then
|
|
119
|
+
log_info "Plugin '$name' is already enabled."
|
|
120
|
+
return 0
|
|
121
|
+
fi
|
|
122
|
+
_plugin_set_enabled "$plugin_root" "true" || return 1
|
|
123
|
+
log_success "Plugin '$name' enabled."
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_plugin_disable() {
|
|
127
|
+
local name="$1"
|
|
128
|
+
local plugin_dir plugin_root
|
|
129
|
+
|
|
130
|
+
_plugin_validate_name "$name" || return 1
|
|
131
|
+
_plugin_require_jq || return 1
|
|
132
|
+
_plugin_prepare_plugins_dir || return 1
|
|
133
|
+
plugin_dir="$PLUGINS_DIR/$name"
|
|
134
|
+
if [[ ! -d "$plugin_dir" ]]; then
|
|
135
|
+
log_error "Plugin '$name' is not installed."
|
|
136
|
+
return 1
|
|
137
|
+
fi
|
|
138
|
+
plugin_root="$(_plugin_validate_installed_plugin "$plugin_dir" "$name")" || return 1
|
|
139
|
+
if ! _plugin_is_enabled "$plugin_root"; then
|
|
140
|
+
log_info "Plugin '$name' is already disabled."
|
|
141
|
+
return 0
|
|
142
|
+
fi
|
|
143
|
+
_plugin_set_enabled "$plugin_root" "false" || return 1
|
|
144
|
+
log_success "Plugin '$name' disabled."
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_plugin_config_main() {
|
|
148
|
+
if [[ $# -eq 0 ]]; then
|
|
149
|
+
log_error "Usage: karnel plugin config <name> [key] [value]"
|
|
150
|
+
log_info " karnel plugin config <name> Show all config"
|
|
151
|
+
log_info " karnel plugin config <name> <key> Get a config value"
|
|
152
|
+
log_info " karnel plugin config <name> <key> <value> Set a config value"
|
|
153
|
+
log_info " karnel plugin config <name> --delete <key> Delete a config key"
|
|
154
|
+
return 1
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
local name="$1"
|
|
158
|
+
shift
|
|
159
|
+
local plugin_dir plugin_root
|
|
160
|
+
|
|
161
|
+
_plugin_validate_name "$name" || return 1
|
|
162
|
+
_plugin_require_jq || return 1
|
|
163
|
+
_plugin_prepare_plugins_dir || return 1
|
|
164
|
+
plugin_dir="$PLUGINS_DIR/$name"
|
|
165
|
+
if [[ ! -d "$plugin_dir" ]]; then
|
|
166
|
+
log_error "Plugin '$name' is not installed."
|
|
167
|
+
return 1
|
|
168
|
+
fi
|
|
169
|
+
plugin_root="$(_plugin_validate_installed_plugin "$plugin_dir" "$name")" || return 1
|
|
170
|
+
|
|
171
|
+
if [[ $# -eq 0 ]]; then
|
|
172
|
+
local config
|
|
173
|
+
config="$(_plugin_get_config "$plugin_root")"
|
|
174
|
+
if [[ "$config" == "{}" ]]; then
|
|
175
|
+
log_info "Plugin '$name' has no configuration."
|
|
176
|
+
else
|
|
177
|
+
echo "$config" | jq -r 'to_entries[] | " \(.key) = \(.value)"'
|
|
178
|
+
fi
|
|
179
|
+
return 0
|
|
180
|
+
fi
|
|
181
|
+
|
|
182
|
+
if [[ "$1" == "--delete" ]]; then
|
|
183
|
+
if [[ $# -ne 2 ]]; then
|
|
184
|
+
log_error "Usage: karnel plugin config <name> --delete <key>"
|
|
185
|
+
return 1
|
|
186
|
+
fi
|
|
187
|
+
_plugin_delete_config "$plugin_root" "$2" || return 1
|
|
188
|
+
log_success "Config '$2' deleted from plugin '$name'."
|
|
189
|
+
return 0
|
|
190
|
+
fi
|
|
191
|
+
|
|
192
|
+
if [[ $# -eq 1 ]]; then
|
|
193
|
+
local val
|
|
194
|
+
val="$(_plugin_get_config "$plugin_root" "$1")"
|
|
195
|
+
if [[ -z "$val" ]]; then
|
|
196
|
+
log_info "Config '$1' is not set for plugin '$name'."
|
|
197
|
+
else
|
|
198
|
+
echo "$val"
|
|
199
|
+
fi
|
|
200
|
+
return 0
|
|
201
|
+
fi
|
|
202
|
+
|
|
203
|
+
if [[ $# -eq 2 ]]; then
|
|
204
|
+
_plugin_set_config "$plugin_root" "$1" "$2" || return 1
|
|
205
|
+
log_success "Config '$1' set for plugin '$name'."
|
|
206
|
+
return 0
|
|
207
|
+
fi
|
|
208
|
+
|
|
209
|
+
log_error "Usage: karnel plugin config <name> [key] [value]"
|
|
210
|
+
return 1
|
|
211
|
+
}
|
|
212
|
+
|
|
88
213
|
_plugin_update_main() {
|
|
89
214
|
local name=""
|
|
90
215
|
local unsafe_flag=""
|
|
@@ -132,6 +257,9 @@ plugin_help() {
|
|
|
132
257
|
printf " ${D_CYAN}%-30s${NC} %s\n" "install <owner/repo> --unsafe" "Install an unreviewed plugin after confirmation"
|
|
133
258
|
printf " ${D_CYAN}%-30s${NC} %s\n" "remove <name>" "Remove a plugin safely"
|
|
134
259
|
printf " ${D_CYAN}%-30s${NC} %s\n" "update <name>" "Atomically update an approved plugin"
|
|
260
|
+
printf " ${D_CYAN}%-30s${NC} %s\n" "enable <name>" "Enable a disabled plugin"
|
|
261
|
+
printf " ${D_CYAN}%-30s${NC} %s\n" "disable <name>" "Disable a plugin without removing it"
|
|
262
|
+
printf " ${D_CYAN}%-30s${NC} %s\n" "config <name> [key] [value]" "View or set per-plugin configuration"
|
|
135
263
|
printf " ${D_CYAN}%-30s${NC} %s\n" "list" "List installed plugins and trust source"
|
|
136
264
|
printf " ${D_CYAN}%-30s${NC} %s\n" "search [query] [filters]" "Search the approved registry"
|
|
137
265
|
printf " ${D_CYAN}%-30s${NC} %s\n" "create <name>" "Create a validated local plugin"
|
|
@@ -151,6 +279,9 @@ plugin_help() {
|
|
|
151
279
|
echo " karnel plugin install karnel-hello"
|
|
152
280
|
echo " karnel plugin install username/repo --unsafe"
|
|
153
281
|
echo " karnel plugin update karnel-hello"
|
|
282
|
+
echo " karnel plugin enable karnel-hello"
|
|
283
|
+
echo " karnel plugin disable karnel-hello"
|
|
284
|
+
echo " karnel plugin config karnel-hello greeting 'Hello World'"
|
|
154
285
|
echo " karnel plugin remove karnel-hello"
|
|
155
286
|
}
|
|
156
287
|
|
|
@@ -582,7 +582,7 @@ _plugin_install_metadata_errors() {
|
|
|
582
582
|
else
|
|
583
583
|
. as $metadata |
|
|
584
584
|
[
|
|
585
|
-
if (($metadata | keys | sort) != ["checksum", "commit", "name", "ref", "registryName", "repo", "schemaVersion", "source", "version"]) then "metadata has unknown or missing fields" else empty end,
|
|
585
|
+
if (($metadata | keys | sort) != ["checksum", "commit", "config", "enabled", "name", "ref", "registryName", "repo", "schemaVersion", "source", "version"]) then "metadata has unknown or missing fields" else empty end,
|
|
586
586
|
if $metadata.schemaVersion != 1 then "metadata schemaVersion must be 1" else empty end,
|
|
587
587
|
if (["registry", "unsafe", "local"] | index($metadata.source)) == null then "metadata source is invalid" else empty end,
|
|
588
588
|
if ($metadata.name | safe_name | not) then "metadata name is invalid" else empty end,
|
|
@@ -933,7 +933,7 @@ _plugin_write_install_metadata() {
|
|
|
933
933
|
--argjson ref "$ref_json" \
|
|
934
934
|
--argjson commit "$commit_json" \
|
|
935
935
|
--argjson registry_name "$registry_json" \
|
|
936
|
-
'{schemaVersion: 1, source: $source, name: $name, repo: $repo, ref: $ref, commit: $commit, version: $version, checksum: (if $checksum == "" then null else $checksum end), registryName: $registry_name}' >"$metadata"; then
|
|
936
|
+
'{schemaVersion: 1, source: $source, name: $name, repo: $repo, ref: $ref, commit: $commit, version: $version, checksum: (if $checksum == "" then null else $checksum end), registryName: $registry_name, enabled: true, config: {}}' >"$metadata"; then
|
|
937
937
|
log_error "Failed to write installation metadata for '$name'."
|
|
938
938
|
return 1
|
|
939
939
|
fi
|
|
@@ -1327,6 +1327,72 @@ _plugin_read_metadata_field() {
|
|
|
1327
1327
|
jq -r ".$field // empty" "$plugin_root/.karnel-install.json"
|
|
1328
1328
|
}
|
|
1329
1329
|
|
|
1330
|
+
_plugin_is_enabled() {
|
|
1331
|
+
local plugin_root="$1"
|
|
1332
|
+
local enabled
|
|
1333
|
+
|
|
1334
|
+
enabled="$(_plugin_read_metadata_field "$plugin_root" enabled)"
|
|
1335
|
+
[[ "$enabled" != "false" ]]
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
_plugin_set_enabled() {
|
|
1339
|
+
local plugin_root="$1"
|
|
1340
|
+
local enabled="$2"
|
|
1341
|
+
local metadata="$plugin_root/.karnel-install.json"
|
|
1342
|
+
|
|
1343
|
+
if ! jq --arg val "$enabled" '.enabled = $val' "$metadata" >"$metadata.tmp"; then
|
|
1344
|
+
log_error "Failed to update enabled state."
|
|
1345
|
+
return 1
|
|
1346
|
+
fi
|
|
1347
|
+
if ! mv -- "$metadata.tmp" "$metadata"; then
|
|
1348
|
+
log_error "Failed to persist enabled state."
|
|
1349
|
+
return 1
|
|
1350
|
+
fi
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
_plugin_get_config() {
|
|
1354
|
+
local plugin_root="$1"
|
|
1355
|
+
local key="${2:-}"
|
|
1356
|
+
local metadata="$plugin_root/.karnel-install.json"
|
|
1357
|
+
|
|
1358
|
+
if [[ -z "$key" ]]; then
|
|
1359
|
+
jq -r '.config // {}' "$metadata"
|
|
1360
|
+
else
|
|
1361
|
+
jq -r --arg k "$key" '.config[$k] // empty' "$metadata"
|
|
1362
|
+
fi
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
_plugin_set_config() {
|
|
1366
|
+
local plugin_root="$1"
|
|
1367
|
+
local key="$2"
|
|
1368
|
+
local value="$3"
|
|
1369
|
+
local metadata="$plugin_root/.karnel-install.json"
|
|
1370
|
+
|
|
1371
|
+
if ! jq --arg k "$key" --arg v "$value" '.config[$k] = $v' "$metadata" >"$metadata.tmp"; then
|
|
1372
|
+
log_error "Failed to set config '$key'."
|
|
1373
|
+
return 1
|
|
1374
|
+
fi
|
|
1375
|
+
if ! mv -- "$metadata.tmp" "$metadata"; then
|
|
1376
|
+
log_error "Failed to persist config."
|
|
1377
|
+
return 1
|
|
1378
|
+
fi
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
_plugin_delete_config() {
|
|
1382
|
+
local plugin_root="$1"
|
|
1383
|
+
local key="$2"
|
|
1384
|
+
local metadata="$plugin_root/.karnel-install.json"
|
|
1385
|
+
|
|
1386
|
+
if ! jq --arg k "$key" 'del(.config[$k])' "$metadata" >"$metadata.tmp"; then
|
|
1387
|
+
log_error "Failed to delete config '$key'."
|
|
1388
|
+
return 1
|
|
1389
|
+
fi
|
|
1390
|
+
if ! mv -- "$metadata.tmp" "$metadata"; then
|
|
1391
|
+
log_error "Failed to persist config."
|
|
1392
|
+
return 1
|
|
1393
|
+
fi
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1330
1396
|
update_plugin() {
|
|
1331
1397
|
local name="$1"
|
|
1332
1398
|
local unsafe_flag="${2:-}"
|
|
@@ -1536,7 +1602,11 @@ _list_plugins() {
|
|
|
1536
1602
|
description="$(jq -r '.description' "$manifest")" || return 1
|
|
1537
1603
|
version="$(jq -r '.version' "$manifest")" || return 1
|
|
1538
1604
|
source="$(_plugin_read_metadata_field "$plugin_root" source)" || return 1
|
|
1539
|
-
|
|
1605
|
+
if _plugin_is_enabled "$plugin_root"; then
|
|
1606
|
+
printf " ${D_GREEN}%-20s${NC} v%-10s [%s] %s\n" "$name" "$version" "$source" "$description"
|
|
1607
|
+
else
|
|
1608
|
+
printf " ${D_YELLOW}%-20s${NC} v%-10s [%s] [disabled] %s\n" "$name" "$version" "$source" "$description"
|
|
1609
|
+
fi
|
|
1540
1610
|
found=1
|
|
1541
1611
|
done
|
|
1542
1612
|
|
|
@@ -1559,6 +1629,9 @@ _plugin_collect_commands() {
|
|
|
1559
1629
|
return 1
|
|
1560
1630
|
fi
|
|
1561
1631
|
plugin_root="$(_plugin_validate_installed_plugin "$plugin_dir" "$name")" || return 1
|
|
1632
|
+
if ! _plugin_is_enabled "$plugin_root"; then
|
|
1633
|
+
continue
|
|
1634
|
+
fi
|
|
1562
1635
|
while IFS= read -r command_name; do
|
|
1563
1636
|
printf '%s\t%s\t%s\n' "$name" "$plugin_root/commands/$command_name.sh" "$command_name"
|
|
1564
1637
|
done < <(jq -r '.commands[]' "$plugin_root/karnel-plugin.json")
|
package/package.json
CHANGED