- 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.
132 lines
3.6 KiB
Bash
Executable File
132 lines
3.6 KiB
Bash
Executable File
#!/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 ""
|