#!/bin/bash # Install shared-bans client on a server. # Run as root on the target server. set -euo pipefail REPO_URL="${1:-}" if [ -z "$REPO_URL" ]; then echo "Usage: $0 " echo "Example: $0 'http://shared-bans-reader:TOKEN@100.81.59.99:3030/sami7777/shared-bans.git'" exit 1 fi # Install scripts install -m 0755 scripts/shared-bans-apply.sh /usr/local/bin/shared-bans-apply.sh install -m 0755 scripts/shared-bans-update-static.sh /usr/local/bin/shared-bans-update-static.sh install -m 0755 scripts/shared-bans-stage-ban.sh /usr/local/bin/shared-bans-stage-ban.sh install -m 0644 scripts/fail2ban-action-shared-bans.conf /etc/fail2ban/action.d/shared-bans.conf # Config cat > /etc/shared-bans.conf < /etc/systemd/system/shared-bans-apply.service <<'EOF' [Unit] Description=Apply shared IP ban list from git repo to local ipset [Service] Type=oneshot ExecStart=/usr/local/bin/shared-bans-apply.sh EOF cat > /etc/systemd/system/shared-bans-apply.timer <<'EOF' [Unit] Description=Apply shared IP ban list from git repo to local ipset [Timer] OnBootSec=2min OnUnitActiveSec=5min [Install] WantedBy=timers.target EOF cat > /etc/systemd/system/shared-bans-update-static.service <<'EOF' [Unit] Description=Update shared IP ban list static sources from URLs [Service] Type=oneshot ExecStart=/usr/local/bin/shared-bans-update-static.sh EOF cat > /etc/systemd/system/shared-bans-update-static.timer <<'EOF' [Unit] Description=Nightly update of shared IP ban list static sources [Timer] OnCalendar=*-*-* 03:30:00 Persistent=true [Install] WantedBy=timers.target EOF systemctl daemon-reload systemctl enable --now shared-bans-apply.timer shared-bans-update-static.timer # fail2ban jail update mkdir -p /var/lib/shared-bans-staging if command -v nft >/dev/null 2>&1 && systemctl is-active nftables >/dev/null 2>&1; then FW_ACTION='nftables-multiport[name=sshd, port="22", protocol=tcp]' else FW_ACTION='iptables-multiport[name=sshd, port="22", protocol=tcp]' fi cat > /etc/fail2ban/jail.local <