Files
html/top-ia/plugin_store.sh
2026-04-16 23:42:50 +02:00

43 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Usage: plugin_store.sh <action:list|info|install> [name]
ACTION="${1:-list}"
NAME="${2:-}"
STORE=/opt/weval-plugins
sudo mkdir -p $STORE 2>/dev/null
case "$ACTION" in
list)
python3 <<PY
import os, json
store="$STORE"
plugins=[]
if os.path.isdir(store):
for d in sorted(os.listdir(store)):
p=os.path.join(store,d)
if os.path.isdir(p):
meta=os.path.join(p,"plugin.json")
info={"name":d,"path":p}
if os.path.exists(meta):
try: info.update(json.load(open(meta)))
except: pass
plugins.append(info)
print(json.dumps({"store":store,"count":len(plugins),"plugins":plugins},ensure_ascii=False))
PY
;;
info)
[ -z "$NAME" ] && { echo '{"error":"need name"}'; exit 1; }
META=$STORE/$NAME/plugin.json
[ -f "$META" ] && cat "$META" || echo "{\"error\":\"plugin $NAME not found\"}"
;;
install)
[ -z "$NAME" ] && { echo '{"error":"need name"}'; exit 1; }
# Create skeleton for manual add
PDIR=$STORE/$NAME
sudo mkdir -p $PDIR 2>/dev/null
sudo tee $PDIR/plugin.json >/dev/null <<EOF2
{"name":"$NAME","version":"0.1.0","description":"TODO","intents":[],"scripts":[],"author":"wevia","created":"$(date -Iseconds)"}
EOF2
echo "{\"installed\":\"$NAME\",\"path\":\"$PDIR\",\"note\":\"edit plugin.json to declare intents\"}"
;;
*) echo '{"error":"action must be list|info|install"}' ;;
esac