- service.sh: split service_remove into internal (no prompts) and interactive versions to prevent 'eternal wait' when installing new strategy. Install now calls service_remove_internal > /dev/null instead of service_remove. Also filter strategy list to general*.sh only to avoid clutter. Systemd ExecStart now points to run_strategy.sh <name> consistently. - run_strategy.sh: add SIGTERM/SIGINT trap cleanup_strategy() that kills nfqws and cleans up firewall. Prevents stale nfqws/firewall rules after autotest kill. Also handles nfqws exit gracefully with final cleanup. - autotest.sh: rewritten to test strategies by config name (not wrapper filename). Stop now sends SIGTERM to wrapper (which triggers trap cleanup) instead of bare kill. Added extra sleep after stop to let trap fire. Auto-install ExecStart fixed to run_strategy.sh <strategy>. - setup.sh: added libmnl-dev and zlib1g-dev to Ubuntu/Debian dependency install to prevent build failures (missing libmnl/libmnl.h and zlib.h). - general*.sh: removed UTF-8 BOM (0xEF 0xBB 0xBF) that caused 'exec format error' when running scripts on Linux. All 19 wrappers cleaned. - ensure_wrappers.sh: always rewrite wrappers to ensure no stale BOM or paths. Fixes: eternal wait on menu option 1, nfqws build failure, stale processes after test.
155 lines
4.6 KiB
Bash
Executable File
155 lines
4.6 KiB
Bash
Executable File
#!/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 ""
|