fc13a9ee87
- Legacy-Standalone-Daemon entfernt (__init__.py, adapter.py, _merge_config.py, uninstall.sh) - Plugin-Dateien in plugin/ strukturiert (von produktiver Susi-Instanz) - Neuer install.sh: --lang en/de, --help, --non-interactive, Bot Username Prompt, Re-Install-Erkennung - tools.py: Rocket.Chat REST-Tools fur Rooms, Users, DMs, Send - BasePlatformAdapter-Vererbung, DDP-added-Events, case-insensitive Filter
249 lines
11 KiB
Bash
Executable File
249 lines
11 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
#
|
||
# Hermes Rocket.Chat Plugin — Interactive Installer
|
||
# https://gitea.thomander.de/andreas/Hermes_rocket.chat_Plugin
|
||
#
|
||
set -euo pipefail
|
||
|
||
# ─── Defaults ──────────────────────────────────────────────
|
||
LANG="${LANG:-de_DE.UTF-8}"
|
||
ARG_LANG=""
|
||
NONINTERACTIVE=false
|
||
|
||
# ─── Language packs ─────────────────────────────────────────
|
||
declare -A T
|
||
msg() { local k="$1"; shift; printf "${T[$k]:-$k}\n" "$@"; }
|
||
|
||
load_lang() {
|
||
local lang="${1:-de}"
|
||
case "$lang" in
|
||
de|de_DE*|de_DE.UTF-8) lang=de ;;
|
||
en|en_*) lang=en ;;
|
||
*) lang=en ;;
|
||
esac
|
||
|
||
if [ "$lang" = "en" ]; then
|
||
T=(
|
||
[banner]="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n Hermes Rocket.Chat Plugin — Installer\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
[checking]="🔍 Checking prerequisites…"
|
||
[found_hermes]="✅ Hermes Agent found at: %s"
|
||
[no_hermes]="❌ Hermes Agent not found.\n Install it first: https://github.com/nousresearch/hermes-agent\n Expected under: ~/hermes-agent or ~/.hermes/hermes-agent"
|
||
[existing]="📋 Existing installation detected:"
|
||
[confirm_values]=" Press ENTER to keep a value, or type a new one."
|
||
[enter_url]="Rocket.Chat URL"
|
||
[enter_botuser]="Bot Username (the bot account on the Rocket.Chat server)"
|
||
[enter_botpass]="Bot Password"
|
||
[enter_channel]="Home Channel (name or room ID, e.g. #ki-assistent or 69f4e…)"
|
||
[current_val]=" Current: %s"
|
||
[new_val]=" → "
|
||
[summary]="📋 Configuration Summary:"
|
||
[copying]="📁 Copying plugin files…"
|
||
[env_written]="🔑 Credentials written to %s"
|
||
[config_updated]="⚙️ config.yaml updated"
|
||
[service_installed]="⚡ Gateway service installed"
|
||
[restarting]="🔄 Restarting gateway…"
|
||
[done]="✅ Rocket.Chat Plugin installed successfully!\n After the gateway restarts, check for a pairing code\n in the gateway logs and enter it in your home channel."
|
||
[dry_info]="ℹ️ Use --help for all options."
|
||
[help_text]="USAGE: ./install.sh [OPTIONS]\n\nOPTIONS:\n --help Show this help\n --lang en|de Language (default: auto-detect from \$LANG)\n --non-interactive Batch mode — reads from env vars:\n RC_URL, RC_BOT_USER, RC_BOT_PASS, RC_HOME_CHANNEL"
|
||
[env_required]="❌ --non-interactive requires RC_URL, RC_BOT_USER, RC_BOT_PASS, RC_HOME_CHANNEL"
|
||
[param_error]="❌ Unknown option: %s"
|
||
)
|
||
else
|
||
# German (default)
|
||
T=(
|
||
[banner]="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n Hermes Rocket.Chat Plugin — Installer\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
[checking]="🔍 Prüfe Voraussetzungen…"
|
||
[found_hermes]="✅ Hermes Agent gefunden unter: %s"
|
||
[no_hermes]="❌ Hermes Agent nicht gefunden.\n Bitte zuerst installieren: https://github.com/nousresearch/hermes-agent\n Erwartet unter: ~/hermes-agent oder ~/.hermes/hermes-agent"
|
||
[existing]="📋 Bestehende Installation erkannt:"
|
||
[confirm_values]=" ENTER = Wert behalten, oder neuen Wert eingeben."
|
||
[enter_url]="Rocket.Chat Server URL"
|
||
[enter_botuser]="Bot Username (der Bot-Account auf dem Rocket.Chat Server)"
|
||
[enter_botpass]="Bot Passwort"
|
||
[enter_channel]="Home Channel (Name oder Raum-ID, z.B. #ki-assistent oder 69f4e…)"
|
||
[current_val]=" Aktuell: %s"
|
||
[new_val]=" → "
|
||
[summary]="📋 Zusammenfassung der Konfiguration:"
|
||
[copying]="📁 Kopiere Plugin-Dateien…"
|
||
[env_written]="🔑 Zugangsdaten gespeichert in %s"
|
||
[config_updated]="⚙️ config.yaml aktualisiert"
|
||
[service_installed]="⚡ Gateway-Service installiert"
|
||
[restarting]="🔄 Starte Gateway neu…"
|
||
[done]="✅ Rocket.Chat Plugin erfolgreich installiert!\n Nach dem Gateway-Neustart bitte den Pairing-Code\n aus den Gateway-Logs im Home-Channel eingeben."
|
||
[dry_info]="ℹ️ Mit --help alle Optionen anzeigen."
|
||
[help_text]="AUFRUF: ./install.sh [OPTIONEN]\n\nOPTIONEN:\n --help Diese Hilfe anzeigen\n --lang en|de Sprache (Standard: auto-Erkennung über \$LANG)\n --non-interactive Stapelverarbeitung — liest aus Umgebungsvariablen:\n RC_URL, RC_BOT_USER, RC_BOT_PASS, RC_HOME_CHANNEL"
|
||
[env_required]="❌ --non-interactive benötigt RC_URL, RC_BOT_USER, RC_BOT_PASS, RC_HOME_CHANNEL"
|
||
[param_error]="❌ Unbekannte Option: %s"
|
||
)
|
||
fi
|
||
}
|
||
|
||
# ─── Helper ──────────────────────────────────────────────
|
||
confirm_or_edit() {
|
||
# $1 = env-var name (RC_URL, RC_BOT_USER, …)
|
||
# $2 = message key (enter_url, enter_botuser, …)
|
||
# $3 = current value (may be empty)
|
||
local varname="$1" msgkey="$2" current="$3" input
|
||
|
||
if [ -n "$current" ]; then
|
||
msg current_val "$current"
|
||
msg confirm_values
|
||
fi
|
||
|
||
printf "%s" "${T[$new_val]}"
|
||
read -r input
|
||
|
||
if [ -n "$input" ]; then
|
||
printf -v "$varname" '%s' "$input"
|
||
fi
|
||
}
|
||
|
||
# ─── Argument parsing ────────────────────────────────────
|
||
while [ $# -gt 0 ]; do
|
||
case "$1" in
|
||
--help|-h)
|
||
load_lang "${ARG_LANG:-${LANG##*.}}"
|
||
echo; echo -e "${T[help_text]}"; echo; exit 0 ;;
|
||
--lang)
|
||
ARG_LANG="$2"; shift 2 ;;
|
||
--lang=*)
|
||
ARG_LANG="${1#*=}"; shift ;;
|
||
--non-interactive)
|
||
NONINTERACTIVE=true; shift ;;
|
||
*)
|
||
load_lang "${ARG_LANG:-${LANG##*.}}"
|
||
msg param_error "$1"; echo; exit 1 ;;
|
||
esac
|
||
done
|
||
|
||
# ─── Load language ────────────────────────────────────────
|
||
load_lang "${ARG_LANG:-${LANG##*.}}"
|
||
|
||
echo -e "\n${T[banner]}\n"
|
||
|
||
# ─── Find Hermes Agent ────────────────────────────────────
|
||
msg checking
|
||
HERMES_DIR=""
|
||
for d in "$HOME/hermes-agent" "$HOME/.hermes/hermes-agent"; do
|
||
if [ -d "$d" ]; then HERMES_DIR="$d"; break; fi
|
||
done
|
||
|
||
if [ -z "$HERMES_DIR" ]; then
|
||
msg no_hermes; exit 1
|
||
fi
|
||
msg found_hermes "$HERMES_DIR"
|
||
|
||
# ─── Detect existing installation ─────────────────────────
|
||
ENV_FILE="$HOME/.config/hermes/rocketchat.env"
|
||
HAVE_EXISTING=false
|
||
RC_URL="" RC_BOT_USER="" RC_BOT_PASS="" RC_HOME_CHANNEL=""
|
||
|
||
if [ -f "$ENV_FILE" ]; then
|
||
HAVE_EXISTING=true
|
||
# shellcheck disable=SC1090
|
||
source "$ENV_FILE" 2>/dev/null || true
|
||
RC_URL="${ROCKETCHAT_BASE_URL:-${RC_URL:-}}"
|
||
RC_BOT_USER="${ROCKETCHAT_USER:-${RC_BOT_USER:-}}"
|
||
RC_HOME_CHANNEL="${ROCKETCHAT_ROOM_NAME:-${RC_HOME_CHANNEL:-}}"
|
||
fi
|
||
|
||
# ─── Non-interactive mode ─────────────────────────────────
|
||
if $NONINTERACTIVE; then
|
||
RC_URL="${RC_URL:-}" RC_BOT_USER="${RC_BOT_USER:-}"
|
||
RC_BOT_PASS="${RC_BOT_PASS:-}" RC_HOME_CHANNEL="${RC_HOME_CHANNEL:-}"
|
||
if [ -z "$RC_URL" ] || [ -z "$RC_BOT_USER" ] || [ -z "$RC_BOT_PASS" ] || [ -z "$RC_HOME_CHANNEL" ]; then
|
||
msg env_required; exit 1
|
||
fi
|
||
else
|
||
# ─── Interactive mode ──────────────────────────────────
|
||
if $HAVE_EXISTING; then
|
||
msg existing
|
||
echo
|
||
fi
|
||
|
||
confirm_or_edit RC_URL enter_url "$RC_URL"
|
||
confirm_or_edit RC_BOT_USER enter_botuser "$RC_BOT_USER"
|
||
confirm_or_edit RC_BOT_PASS enter_botpass ""
|
||
confirm_or_edit RC_HOME_CHANNEL enter_channel "$RC_HOME_CHANNEL"
|
||
|
||
echo
|
||
msg summary
|
||
echo " URL: $RC_URL"
|
||
echo " Bot User: $RC_BOT_USER"
|
||
echo " Home Channel: $RC_HOME_CHANNEL"
|
||
echo
|
||
fi
|
||
|
||
# ─── Write credentials ────────────────────────────────────
|
||
msg copying
|
||
mkdir -p "$(dirname "$ENV_FILE")"
|
||
|
||
cat > "$ENV_FILE" <<EOF
|
||
# Hermes Rocket.Chat Plugin — credentials (generated by install.sh)
|
||
export ROCKETCHAT_BASE_URL="${RC_URL}"
|
||
export ROCKETCHAT_USER="${RC_BOT_USER}"
|
||
export ROCKETCHAT_PASSWORD='${RC_BOT_PASS}'
|
||
export ROCKETCHAT_ROOM_NAME="${RC_HOME_CHANNEL}"
|
||
export ROCKETCHAT_ALLOW_ALL_USERS=true
|
||
export GATEWAY_ALLOW_ALL_USERS=true
|
||
export ROCKETCHAT_PING_SEC=8
|
||
export ROCKETCHAT_IDLE_SEC=900
|
||
EOF
|
||
chmod 600 "$ENV_FILE"
|
||
msg env_written "$ENV_FILE"
|
||
|
||
# ─── Copy plugin files ────────────────────────────────────
|
||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||
PLUGIN_DST="$HERMES_DIR/plugins/platforms/rocketchat"
|
||
mkdir -p "$PLUGIN_DST"
|
||
|
||
for f in plugin.yaml __init__.py adapter.py tools.py; do
|
||
if [ -f "$SCRIPT_DIR/plugin/$f" ]; then
|
||
cp "$SCRIPT_DIR/plugin/$f" "$PLUGIN_DST/$f"
|
||
fi
|
||
done
|
||
|
||
# ─── Patch config.yaml ────────────────────────────────────
|
||
CONFIG="$HOME/.hermes/config.yaml"
|
||
if [ -f "$CONFIG" ]; then
|
||
# Ensure rocketchat-platform is in plugins.enabled
|
||
if ! grep -q 'rocketchat-platform' "$CONFIG" 2>/dev/null; then
|
||
# Simple append — user can refine later
|
||
cat >> "$CONFIG" <<'YAML'
|
||
|
||
# Added by Rocket.Chat Plugin installer
|
||
plugins:
|
||
enabled:
|
||
- rocketchat-platform
|
||
YAML
|
||
fi
|
||
msg config_updated
|
||
fi
|
||
|
||
# ─── Gateway service ──────────────────────────────────────
|
||
cd "$HERMES_DIR"
|
||
|
||
if [ -f "venv/bin/python" ]; then
|
||
PYTHON="venv/bin/python"
|
||
elif [ -f ".venv/bin/python" ]; then
|
||
PYTHON=".venv/bin/python"
|
||
else
|
||
PYTHON="python3"
|
||
fi
|
||
|
||
# Install / refresh systemd user service
|
||
$PYTHON -m hermes_cli.main gateway install 2>/dev/null || true
|
||
|
||
# Ensure lingering is enabled (may need sudo — best-effort)
|
||
loginctl enable-linger 2>/dev/null || true
|
||
|
||
msg service_installed
|
||
|
||
# ─── Restart gateway ──────────────────────────────────────
|
||
msg restarting
|
||
systemctl --user daemon-reload 2>/dev/null || true
|
||
systemctl --user restart hermes-gateway 2>/dev/null || true
|
||
|
||
msg done
|
||
echo
|