#!/bin/bash # install.sh - One-shot installer: setup + build + autotest + systemd install # Works in Russia (GitHub blocked): supports HTTPS_PROXY, offline bundle, mirrors # Usage: # sudo ./install.sh # normal (with proxy/VPN) # sudo ./install.sh --offline # use pre-downloaded bundle # HTTPS_PROXY=socks5://127.0.0.1:1080 sudo ./install.sh set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/lib/functions.sh" source "$SCRIPT_DIR/lib/download_helper.sh" if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then print_red "[!] Run as root (or sudo)" echo " sudo ./install.sh" exit 1 fi # Check for offline flag OFFLINE_MODE=0 if [[ "${1:-}" == "--offline" ]]; then OFFLINE_MODE=1 echo "" echo "[*] OFFLINE MODE: skipping network, using local bundle only" sleep 1 fi # Load proxy load_proxy # Check if proxy is set if [[ -n "${HTTPS_PROXY:-}" ]]; then echo "[OK] Proxy detected: $HTTPS_PROXY" fi echo "" echo "==============================================" echo " Zapret for Linux - Full Installer" echo "==============================================" echo "" echo " This will:" echo " 1. Sync upstream lists & strategies" echo " 2. Install dependencies" echo " 3. Build nfqws from source" echo " 4. Auto-test strategies" echo " 5. Install systemd service" echo "" if [[ "$OFFLINE_MODE" -eq 1 ]]; then echo " Mode: OFFLINE (no internet required)" else echo " Mode: ONLINE (needs internet or proxy/VPN)" if ! curl -sfL --max-time 5 "https://github.com" >/dev/null 2>&1; then print_yellow "[!] GitHub NOT reachable." echo " Options:" echo " a) Set proxy: HTTPS_PROXY=socks5://127.0.0.1:1080 sudo ./install.sh" echo " b) Use VPN and re-run" echo " c) Run offline: sudo ./install.sh --offline" echo " d) Or prepare offline bundle first: proxychains ./prepare_offline_bundle.sh" echo "" read -rp "Continue anyway? [y/N]: " ans [[ "$ans" == [yY]* ]] || exit 1 fi fi read -rp "Continue? [Y/n]: " ans [[ "${ans:-Y}" == [yY]* ]] || { echo "Aborted."; exit 0; } # Step 0: Sync upstream (lists, hosts, new .bat strategies) if [[ "$OFFLINE_MODE" -eq 0 ]]; then echo "" echo "[*] Step 0: Syncing upstream lists/strategies..." set +e bash "$SCRIPT_DIR/sync_from_upstream.sh" 2>&1 SYNC_EXIT=$? set -e if [[ "$SYNC_EXIT" -eq 2 ]]; then print_yellow "[!] Sync flagged: rebuild needed (exit 2). Continuing..." elif [[ "$SYNC_EXIT" -ne 0 ]]; then print_yellow "[!] Sync failed (exit $SYNC_EXIT). Continuing with local files..." fi else echo "" echo "[*] Step 0: OFFLINE — skipping upstream sync" fi # Step 1: Setup echo "" echo "[*] Step 1/4: Installing dependencies..." bash "$SCRIPT_DIR/setup.sh" || { print_red "[!] Setup failed. Check dependencies." exit 1 } # Step 2: Build nfqws echo "" echo "[*] Step 2/4: Building nfqws..." check_nfqws || { bash "$SCRIPT_DIR/install_nfqws.sh" || { print_red "[!] Build failed." echo "" echo "Common causes:" echo " - GitHub blocked (set HTTPS_PROXY or use --offline)" echo " - Missing build tools (gcc, make)" echo " - libnetfilter_queue not installed" echo "" echo "Try:" echo " HTTPS_PROXY=socks5://127.0.0.1:1080 sudo ./install.sh" echo " OR" echo " sudo ./install.sh --offline" exit 1 } } # Step 3: Auto-test echo "" echo "[*] Step 3/4: Auto-testing strategies..." bash "$SCRIPT_DIR/autotest.sh" --auto || { print_yellow "[!] Auto-test: no strategy worked automatically." echo " Try manually: sudo ./general.sh, sudo ./general_ALT.sh, ..." } # Step 4: Done echo "" print_green "==============================================" print_green " Installation Complete!" print_green "==============================================" echo "" if command -v systemctl >/dev/null 2>&1; then systemctl status zapret --no-pager 2>/dev/null || true echo "" echo "Commands:" echo " sudo systemctl status zapret" echo " sudo systemctl stop zapret" echo " sudo systemctl start zapret" echo " sudo systemctl restart zapret" echo " sudo journalctl -u zapret -f" else echo "[*] systemd not found. To start manually:" echo " sudo ./general.sh" fi echo "" echo "[*] To update in future:" if [[ "$OFFLINE_MODE" -eq 1 ]]; then echo " Re-run with VPN/proxy: sudo ./install.sh" else echo " sudo ./update.sh # auto sync + rebuild" echo " sudo ./update.sh --full-auto # force rebuild" fi echo ""