Files
ssh-login-notifier/uninstall.sh
Patrick Asmus 6c2a6dc12b Initial Commit
2026-04-26 21:05:42 +02:00

79 lines
1.9 KiB
Bash

#!/bin/bash
# SSH Login Notifier - Deinstallationsscript
# https://git.techniverse.net/scriptos/ssh-login-notifier
set -e
INSTALL_DIR="/opt/ssh-login-notifier"
PROFILE_HOOK="/etc/profile.d/ssh-login-notify.sh"
ZSH_HOOK_MARKER="# SSH Login Notifier"
# --- Hilfsfunktionen ---
info() { echo -e "\e[32m[INFO]\e[0m $1"; }
warn() { echo -e "\e[33m[WARN]\e[0m $1"; }
error() { echo -e "\e[31m[ERROR]\e[0m $1"; exit 1; }
check_root() {
if [[ $EUID -ne 0 ]]; then
error "Dieses Script muss als root ausgefuehrt werden (sudo)."
fi
}
# --- Deinstallation ---
remove_profile_hook() {
if [[ -f "$PROFILE_HOOK" ]]; then
info "Entferne Profile-Hook: ${PROFILE_HOOK}"
rm -f "$PROFILE_HOOK"
info "Profile-Hook entfernt."
else
info "Kein Profile-Hook gefunden - nichts zu entfernen."
fi
}
remove_zsh_hook() {
local zshrc="/etc/zsh/zshrc"
if [[ -f "$zshrc" ]] && grep -qF "$ZSH_HOOK_MARKER" "$zshrc" 2>/dev/null; then
info "Entferne Zsh-Hook aus ${zshrc}"
sed -i "/^${ZSH_HOOK_MARKER}/,+2d" "$zshrc"
sed -i '/^$/N;/^\n$/d' "$zshrc"
info "Zsh-Hook entfernt."
else
info "Kein Zsh-Hook gefunden - nichts zu entfernen."
fi
}
remove_files() {
if [[ -d "$INSTALL_DIR" ]]; then
info "Entferne Installationsverzeichnis: ${INSTALL_DIR}"
rm -rf "$INSTALL_DIR"
info "Dateien entfernt."
else
info "Installationsverzeichnis nicht gefunden - nichts zu entfernen."
fi
}
# --- Hauptprogramm ---
echo ""
echo "SSH Login Notifier - Deinstallation"
echo "===================================="
echo ""
check_root
read -p "SSH Login Notifier wirklich deinstallieren? (j/N) " confirm
if [[ "$confirm" != "j" && "$confirm" != "J" ]]; then
info "Abgebrochen."
exit 0
fi
remove_profile_hook
remove_zsh_hook
remove_files
echo ""
info "SSH Login Notifier wurde vollstaendig deinstalliert."
echo ""