#!/bin/bash # # _nnnn_ # dGGGGMMb # @p~qp~~qMb # M|@||@) M| # @,----.JM| # JS^\__/ qKL # dZP qKRb # dZP qKKb # fZP SMMb # HZM MMMM # FqM MMMM # __| ". |\dS"qML # | `. | `' \Zq # _) \.___.,| .' # \____ )MMMMMP| .' # `-' `--' # # Debian 12 Fail2Ban Clean Install # By: 16BitMiker (v2024-10-27) # # ~~~~~~~~~~~~~~~~ BEGIN # Enable debugging output set -x # Don't exit on error, but log it set +e log_error() { echo "ERROR: $1" >&2 } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ REMOVAL echo "Checking if Fail2Ban is installed..." if dpkg -s fail2ban &> /dev/null; then echo "Fail2Ban is installed. Proceeding with removal..." echo "Stopping and disabling Fail2Ban..." sudo systemctl stop fail2ban || log_error "Failed to stop Fail2Ban" sudo systemctl disable fail2ban || log_error "Failed to disable Fail2Ban" echo "Removing Fail2Ban..." sudo DEBIAN_FRONTEND=noninteractive apt-get purge --auto-remove fail2ban -y || log_error "Failed to purge Fail2Ban" else echo "Fail2Ban is not installed. Skipping removal steps." fi echo "Removing any remaining Fail2Ban files..." sudo rm -rf /etc/fail2ban 2>/dev/null || log_error "Failed to remove /etc/fail2ban" sudo rm -f /var/lib/fail2ban/fail2ban.sqlite3 2>/dev/null || log_error "Failed to remove fail2ban.sqlite3" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INSTALL echo "Updating package lists..." sudo DEBIAN_FRONTEND=noninteractive apt-get update -y || log_error "Failed to update package lists" echo "Installing Fail2Ban and rsyslog..." sudo DEBIAN_FRONTEND=noninteractive apt-get install fail2ban rsyslog -y || log_error "Failed to install Fail2Ban and rsyslog" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURATION echo "Configuring Fail2Ban..." sudo mkdir -p /etc/fail2ban || log_error "Failed to create /etc/fail2ban directory" sudo tee /etc/fail2ban/jail.local <