Fix install.sh: Replace with corrected version that resolves update check issues

This commit is contained in:
Hermes Agent
2026-06-01 08:15:46 +02:00
parent a614071ac4
commit b3927e7ada
Executable → Regular
+168 -3
View File
@@ -9,6 +9,8 @@ set -euo pipefail
LANG="${LANG:-de_DE.UTF-8}" LANG="${LANG:-de_DE.UTF-8}"
ARG_LANG="" ARG_LANG=""
NONINTERACTIVE=false NONINTERACTIVE=false
CHECK_ONLY=false
UPDATE_MODE=false
# ─── Language packs ───────────────────────────────────────── # ─── Language packs ─────────────────────────────────────────
declare -A T declare -A T
@@ -44,9 +46,18 @@ load_lang() {
[restarting]="🔄 Restarting gateway…" [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." [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." [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" [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\n --check Check for updates only\n --update Check for updates and install if available"
[env_required]="❌ --non-interactive requires 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" [param_error]="❌ Unknown option: %s"
[check_update]="🔍 Checking for updates…"
[update_available]="📦 New version available: %s (current: %s)"
[no_update]="✅ Plugin is up to date (%s)"
[perform_update]="🔄 Updating plugin to version %s…"
[backup_created]="💾 Backup created: %s"
[update_success]="✅ Plugin successfully updated to version %s"
[rollback]="⏪ Restoring backup: %s"
[rollback_success]="✅ Backup successfully restored"
[update_failed]="❌ Update failed. Error: %s"
) )
else else
# German (default) # German (default)
@@ -71,9 +82,18 @@ load_lang() {
[restarting]="🔄 Starte Gateway neu…" [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." [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." [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" [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\n --check Nur auf Updates prüfen\n --update Auf Updates prüfen und bei Bedarf installieren"
[env_required]="❌ --non-interactive benötigt 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" [param_error]="❌ Unbekannte Option: %s"
[check_update]="🔍 Prüfe auf Updates…"
[update_available]="📦 Neue Version verfügbar: %s (aktuell: %s)"
[no_update]="✅ Plugin ist auf dem neuesten Stand (%s)"
[perform_update]="🔄 Aktualisiere Plugin auf Version %s…"
[backup_created]="💾 Backup erstellt: %s"
[update_success]="✅ Plugin erfolgreich aktualisiert auf Version %s"
[rollback]="⏪ Stelle Backup wieder her: %s"
[rollback_success]="✅ Backup erfolgreich wiederhergestellt"
[update_failed]="❌ Update fehlgeschlagen. Fehler: %s"
) )
fi fi
} }
@@ -98,6 +118,133 @@ confirm_or_edit() {
fi fi
} }
# ─── Update Functions ──────────────────────────────────────
check_for_updates() {
msg check_update
# Get the script directory (repo root)
local script_dir
script_dir="$(cd "$(dirname "$0")" && pwd)"
# Change to repo directory
cd "$script_dir"
# Get local version (latest tag)
local local_version
local_version=$(git describe --tags 2>/dev/null || echo "unknown")
# Get remote version (latest tag on origin)
local remote_version
remote_version=$(git ls-remote --tags origin | grep -E 'refs/tags/v[0-9]+(\.[0-9]+)*$' | sed 's|.*refs/tags/||' | sort -V | tail -n1 || echo "unknown")
# If we can't determine versions, exit with error
if [ "$local_version" = "unknown" ] || [ "$remote_version" = "unknown" ]; then
echo "Could not determine version information"
return 1
fi
# Compare versions
if [ "$local_version" != "$remote_version" ]; then
msg update_available "$remote_version" "$local_version"
return 1 # Update available
else
msg no_update "$local_version"
return 0 # No update needed
fi
}
create_backup() {
local backup_file="$1"
local plugin_dir="$2"
local config_file="$3"
local env_file="$4"
# Create backup of current installation
tar -czf "$backup_file" -C "$(dirname "$plugin_dir")" "$(basename "$plugin_dir")" \
--exclude="*.pyc" --exclude="__pycache__" \
"$config_file" "$env_file" 2>/dev/null || true
msg backup_created "$backup_file"
}
perform_update() {
# Get the script directory (repo root)
local script_dir
script_dir="$(cd "$(dirname "$0")" && pwd)"
# Change to repo directory
cd "$script_dir"
# Get remote version
local remote_version
remote_version=$(git ls-remote --tags origin | grep -E 'refs/tags/v[0-9]+(\.[0-9]+)*$' | sed 's|.*refs/tags/||' | sort -V | tail -n1 || echo "unknown")
if [ "$remote_version" = "unknown" ]; then
msg update_failed "Could not determine remote version"
return 1
fi
msg perform_update "$remote_version"
# Create backup before updating
local backup_file="/tmp/hermes-rocketchat-backup-$(date +%s).tar.gz"
local hermes_dir
hermes_dir=""
for d in "$HOME/hermes-agent" "$HOME/.hermes/hermes-agent"; do
if [ -d "$d" ]; then hermes_dir="$d"; break; fi
done
if [ -n "$hermes_dir" ]; then
local plugin_dir="$hermes_dir/plugins/platforms/rocketchat"
local config_file="$HOME/.hermes/config.yaml"
local env_file="$HOME/.config/hermes/rocketchat.env"
create_backup "$backup_file" "$plugin_dir" "$config_file" "$env_file"
fi
# Perform the update
local update_error=""
{
# Pull latest changes
git fetch --tags origin 2>&1 || { update_error="Failed to fetch from remote"; return 1; }
git checkout "$remote_version" 2>&1 || { update_error="Failed to checkout version $remote_version"; return 1; }
# Run the installer to update files
HERMES_DIR="$hermes_dir" UPDATE_MODE=true ./install.sh --non-interactive 2>&1
} || {
# Update failed, rollback
if [ -n "$update_error" ]; then
msg update_failed "$update_error"
else
msg update_failed "Installation failed"
fi
if [ -f "$backup_file" ]; then
msg rollback "$backup_file"
# Extract backup
tar -xzf "$backup_file" -C "$HOME" 2>/dev/null || true
msg rollback_success
# Clean up backup file
rm -f "$backup_file"
fi
return 1
}
# Clean up backup file on success
rm -f "$backup_file"
msg update_success "$remote_version"
# Restart gateway
if [ -n "$hermes_dir" ]; then
cd "$hermes_dir"
systemctl --user daemon-reload 2>/dev/null || true
systemctl --user restart hermes-gateway 2>/dev/null || true
fi
return 0
}
# ─── Argument parsing ──────────────────────────────────── # ─── Argument parsing ────────────────────────────────────
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
@@ -110,6 +257,10 @@ while [ $# -gt 0 ]; do
ARG_LANG="${1#*=}"; shift ;; ARG_LANG="${1#*=}"; shift ;;
--non-interactive) --non-interactive)
NONINTERACTIVE=true; shift ;; NONINTERACTIVE=true; shift ;;
--check)
CHECK_ONLY=true; shift ;;
--update)
UPDATE_MODE=true; shift ;;
*) *)
load_lang "${ARG_LANG:-${LANG##*.}}" load_lang "${ARG_LANG:-${LANG##*.}}"
msg param_error "$1"; echo; exit 1 ;; msg param_error "$1"; echo; exit 1 ;;
@@ -121,6 +272,20 @@ load_lang "${ARG_LANG:-${LANG##*.}}"
echo -e "\n${T[banner]}\n" echo -e "\n${T[banner]}\n"
# ─── Update Check/Perform ──────────────────────────────────────
if $CHECK_ONLY; then
check_for_updates
exit $?
elif $UPDATE_MODE; then
check_for_updates
if [ $? -eq 1 ]; then
perform_update
exit $?
else
exit 0
fi
fi
# ─── Find Hermes Agent ──────────────────────────────────── # ─── Find Hermes Agent ────────────────────────────────────
msg checking msg checking
HERMES_DIR="" HERMES_DIR=""
@@ -245,4 +410,4 @@ systemctl --user daemon-reload 2>/dev/null || true
systemctl --user restart hermes-gateway 2>/dev/null || true systemctl --user restart hermes-gateway 2>/dev/null || true
msg done msg done
echo echo