Files
gniza4linux/scripts/uninstall.sh
shuki cf00ecdd4b Add web dashboard with systemd service support
- Flask web dashboard with dark theme matching TUI
- Login with API key authentication
- Dashboard shows targets, remotes, schedules, last backup status
- Trigger backups from web UI per target
- View logs via /api/logs endpoint
- systemd service: gniza web install-service / remove-service / status
- CLI: gniza web start [--port=PORT] [--host=HOST]
- TUI settings: web enabled, port, host, API key fields
- Install script: optional web dashboard setup with auto-generated API key
- Uninstall script: removes systemd service

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 05:34:02 +02:00

109 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
# Colors
if [[ -t 1 ]]; then
C_GREEN=$'\033[0;32m'
C_RED=$'\033[0;31m'
C_YELLOW=$'\033[0;33m'
C_BOLD=$'\033[1m'
C_RESET=$'\033[0m'
else
C_GREEN="" C_RED="" C_YELLOW="" C_BOLD="" C_RESET=""
fi
info() { echo "${C_GREEN}[INFO]${C_RESET} $*"; }
warn() { echo "${C_YELLOW}[WARN]${C_RESET} $*" >&2; }
error() { echo "${C_RED}[ERROR]${C_RESET} $*" >&2; }
# ── Determine uninstall mode ────────────────────────────────
if [[ $EUID -eq 0 ]]; then
MODE="root"
INSTALL_DIR="/usr/local/gniza"
BIN_LINK="/usr/local/bin/gniza"
CONFIG_DIR="/etc/gniza"
LOG_DIR="/var/log/gniza"
else
MODE="user"
INSTALL_DIR="$HOME/.local/share/gniza"
BIN_LINK="$HOME/.local/bin/gniza"
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/gniza"
LOG_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/gniza/log"
fi
info "Uninstall mode: ${C_BOLD}${MODE}${C_RESET}"
echo ""
# ── Remove cron entries ──────────────────────────────────────
info "Removing gniza cron entries..."
CRON_TAG="# gniza4linux:"
current_crontab=$(crontab -l 2>/dev/null) || current_crontab=""
if [[ -n "$current_crontab" ]]; then
filtered=""
skip_next=false
removed=0
while IFS= read -r line; do
if [[ "$line" == "${CRON_TAG}"* ]]; then
skip_next=true
((removed++)) || true
continue
fi
if [[ "$skip_next" == "true" ]]; then
skip_next=false
continue
fi
filtered+="$line"$'\n'
done <<< "$current_crontab"
if (( removed > 0 )); then
echo "$filtered" | crontab - 2>/dev/null || warn "Failed to update crontab"
info "Removed $removed cron entry/entries"
else
info "No gniza cron entries found"
fi
else
info "No crontab entries to check"
fi
# ── Remove web service ───────────────────────────────────────
if systemctl is-active gniza-web &>/dev/null || [[ -f /etc/systemd/system/gniza-web.service ]]; then
echo "Removing GNIZA web service..."
systemctl stop gniza-web 2>/dev/null || true
systemctl disable gniza-web 2>/dev/null || true
rm -f /etc/systemd/system/gniza-web.service
systemctl daemon-reload
fi
# ── Remove symlink ───────────────────────────────────────────
if [[ -L "$BIN_LINK" ]]; then
rm -f "$BIN_LINK"
info "Removed symlink: $BIN_LINK"
elif [[ -f "$BIN_LINK" ]]; then
warn "Expected symlink but found regular file: $BIN_LINK (not removing)"
fi
# ── Remove install directory ─────────────────────────────────
if [[ -d "$INSTALL_DIR" ]]; then
rm -rf "$INSTALL_DIR"
info "Removed install directory: $INSTALL_DIR"
else
info "Install directory not found: $INSTALL_DIR"
fi
# ── Notify about config and logs ─────────────────────────────
echo ""
echo "${C_GREEN}${C_BOLD}Uninstall complete!${C_RESET}"
echo ""
echo "The following directories were ${C_YELLOW}NOT${C_RESET} removed (may contain your data):"
echo ""
if [[ -d "$CONFIG_DIR" ]]; then
echo " Config: $CONFIG_DIR"
echo " To remove: rm -rf $CONFIG_DIR"
fi
if [[ -d "$LOG_DIR" ]]; then
echo " Logs: $LOG_DIR"
echo " To remove: rm -rf $LOG_DIR"
fi
echo ""