#!/bin/bash # WireGuard Secure Installer # Copyright (c) 2025 Muhammad Fadhila Abiyyu Faris # GitHub: [github.com/fadhila36/wireguard-secure-installer](https://github.com/fadhila36/wireguard-secure-installer) check_os() { if [ -f /etc/os-release ]; then . /etc/os-release OS=$ID VERSION_ID=$VERSION_ID else fatal_error "Cannot detect OS. /etc/os-release not found." fi log_info "Detected OS: $OS $VERSION_ID" case "$OS" in ubuntu|debian) PKG_MANAGER="apt-get" UPDATE_CMD="apt-get update" INSTALL_CMD="apt-get install -y" ;; centos|rhel|rocky|almalinux) PKG_MANAGER="dnf" UPDATE_CMD="dnf check-update" # dnf update is slow, check-update is enough to refresh metadata INSTALL_CMD="dnf install -y" ;; *) fatal_error "Unsupported OS: $OS. Supported: Ubuntu, Debian, CentOS, Rocky, AlmaLinux." ;; esac } install_dependencies() { log_info "Installing dependencies..." $UPDATE_CMD >> "$LOG_FILE" 2>&1 case "$OS" in ubuntu|debian) $INSTALL_CMD wireguard qrencode curl iptables >> "$LOG_FILE" 2>&1 ;; centos|rhel|rocky|almalinux) $INSTALL_CMD epel-release >> "$LOG_FILE" 2>&1 $INSTALL_CMD wireguard-tools qrencode curl iptables-services >> "$LOG_FILE" 2>&1 ;; esac if ! command -v wg >/dev/null; then fatal_error "WireGuard installation failed." fi }