#!/bin/bash # setup.sh - Initial setup for zapret-discord-youtube Linux set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/lib/functions.sh" if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then print_red "[!] This script must be run as root (or with sudo)" echo " sudo $0" exit 1 fi echo "==============================================" echo " Zapret for Linux - Setup" echo "==============================================" echo "" # Make all scripts executable echo "[*] Setting executable permissions..." chmod +x "$SCRIPT_DIR"/*.sh chmod +x "$SCRIPT_DIR"/lib/*.sh chmod +x "$SCRIPT_DIR"/utils/*.sh print_green "[OK] Permissions set." # Detect distro if [ -f /etc/os-release ]; then . /etc/os-release DISTRO="$ID" else DISTRO="unknown" fi echo "" echo "[*] Detected distro: $DISTRO" # Check dependencies echo "" echo "[*] Checking dependencies..." missing=() if ! command -v curl >/dev/null 2>&1; then missing+=("curl") fi if ! command -v git >/dev/null 2>&1; then missing+=("git") fi if ! command -v make >/dev/null 2>&1; then missing+=("make") fi if ! command -v gcc >/dev/null 2>&1; then missing+=("gcc") fi if [[ ${#missing[@]} -gt 0 ]]; then print_red "[!] Missing packages: ${missing[*]}" echo "[*] Attempting to install..." case "$DISTRO" in ubuntu|debian|linuxmint|pop) apt-get update apt-get install -y curl git make gcc build-essential libmnl-dev zlib1g-dev ;; arch|manjaro) pacman -Syu --noconfirm curl git make gcc ;; fedora) dnf install -y curl git make gcc ;; *) print_red "[!] Please install manually: ${missing[*]}" exit 1 ;; esac else print_green "[OK] All basic dependencies present." fi # Check nfnetlink_queue module echo "" echo "[*] Checking kernel module nfnetlink_queue..." if ! lsmod | grep -q "nfnetlink_queue"; then print_yellow "[!] nfnetlink_queue not loaded. Loading..." modprobe nfnetlink_queue 2>/dev/null || { print_red "[!] Failed to load nfnetlink_queue." echo " Install: linux-headers + libnetfilter_queue" } else print_green "[OK] nfnetlink_queue is loaded." fi # Build nfqws echo "" if [[ ! -x "$SCRIPT_DIR/bin/nfqws" ]]; then echo "[*] nfqws binary not found. Starting build..." bash "$SCRIPT_DIR/install_nfqws.sh" else echo "[*] nfqws already built." fi # Create user lists if missing echo "" echo "[*] Creating user lists..." mkdir -p "$SCRIPT_DIR/.service" [[ ! -f "$SCRIPT_DIR/lists/list-general-user.txt" ]] && echo "domain.example.abc" > "$SCRIPT_DIR/lists/list-general-user.txt" [[ ! -f "$SCRIPT_DIR/lists/list-exclude-user.txt" ]] && echo "domain.example.abc" > "$SCRIPT_DIR/lists/list-exclude-user.txt" [[ ! -f "$SCRIPT_DIR/lists/ipset-exclude-user.txt" ]] && echo "203.0.113.113/32" > "$SCRIPT_DIR/lists/ipset-exclude-user.txt" print_green "[OK] User lists ready." # Offer to install systemd service echo "" if command -v systemctl >/dev/null 2>&1; then read -rp "Install systemd service for auto-start? [y/N]: " ans if [[ "$ans" == [yY]* ]]; then bash "$SCRIPT_DIR/service.sh" && true || true fi else print_yellow "[!] systemctl not found. Skipping systemd setup." fi echo "" print_green "==============================================" print_green " Setup complete!" print_green "==============================================" echo "" echo "Quick start:" echo " 1. Test manually: sudo ./general.sh" echo " 2. Manage service: sudo ./service.sh" echo " 3. Auto-update: sudo ./update.sh" echo ""