#!/usr/bin/env bash # Zapret automatic installation script (Arch fixed) set -e BLOCKED_DOMAIN="${1:-discord.com}" ZAPRET_VERSION="72.9" ZAPRET_URL="https://github.com/bol-van/zapret/releases/download/v${ZAPRET_VERSION}/zapret-v${ZAPRET_VERSION}.zip" INSTALL_DIR="/tmp/zapret" OPT_DIR="/opt/zapret" # Root check if [[ $EUID -ne 0 ]]; then echo "Run as root: sudo $0 $BLOCKED_DOMAIN" exit 1 fi echo "==========================================" echo " Zapret Installer (Arch fixed)" echo " Target: $BLOCKED_DOMAIN" echo "==========================================" install_deps() { echo "[1/7] Installing dependencies..." . /etc/os-release case "$ID" in arch|manjaro|endeavouros|cachyos|artix) pacman -Sy --noconfirm --needed \ bind curl dnscrypt-proxy nftables unzip wget ;; *) echo "This script is optimized for Arch-based systems." echo "Install manually if needed." ;; esac } setup_dns() { echo "[2/7] Setting up systemd-resolved..." systemctl enable systemd-resolved 2>/dev/null || true systemctl start systemd-resolved 2>/dev/null || true mkdir -p /etc/systemd/resolved.conf.d cat > /etc/systemd/resolved.conf.d/zapret-dns.conf << 'EOF' [Resolve] DNS=1.1.1.1 1.0.0.1 DNSOverTLS=yes EOF ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf systemctl restart systemd-resolved } download_zapret() { echo "[3/7] Downloading Zapret..." rm -rf "$INSTALL_DIR" /tmp/zapret.zip wget -q -O /tmp/zapret.zip "$ZAPRET_URL" || { echo "Download failed!" exit 1 } unzip -q -d /tmp /tmp/zapret.zip mv "/tmp/zapret-v${ZAPRET_VERSION}" "$INSTALL_DIR" rm -f /tmp/zapret.zip } prepare_install() { echo "[4/7] Preparing..." [[ -x "$OPT_DIR/uninstall_easy.sh" ]] && "$OPT_DIR/uninstall_easy.sh" || true rm -rf "$OPT_DIR" echo -e "\n" | "$INSTALL_DIR/install_prereq.sh" || true echo -e "\n" | "$INSTALL_DIR/install_bin.sh" || true } run_blockcheck() { echo "[5/7] Running DPI detection..." LOG="/tmp/zapret_blockcheck.log" ( echo "$BLOCKED_DOMAIN" echo "46" echo "Y" echo "Y" echo "N" echo "1" echo "1" ) | "$INSTALL_DIR/blockcheck.sh" 2>&1 | tee "$LOG" || true NFQWS=$(grep "nfqws --dpi-desync=" "$LOG" \ | sed -n 's/.*nfqws \(--dpi-desync=.*\)/\1/p' \ | head -1) if [[ -z "$NFQWS" ]]; then NFQWS="--dpi-desync=fakeddisorder --dpi-desync-ttl=1 --dpi-desync-autottl=-5 --dpi-desync-split-pos=1" fi echo "$NFQWS" > /tmp/zapret_nfqws_opt.txt echo "Using NFQWS: $NFQWS" } create_editor_wrapper() { cat > /tmp/zapret_editor.sh << 'EOF' #!/bin/bash OPT=$(cat /tmp/zapret_nfqws_opt.txt 2>/dev/null) FILE="$1" if [[ -n "$OPT" && -f "$FILE" ]]; then if grep -q '^NFQWS_OPT=' "$FILE"; then sed -i "s|^NFQWS_OPT=.*|NFQWS_OPT=\"$OPT\"|" "$FILE" else echo "NFQWS_OPT=\"$OPT\"" >> "$FILE" fi fi EOF chmod +x /tmp/zapret_editor.sh export EDITOR="/tmp/zapret_editor.sh" } run_install_easy() { echo "[6/7] Installing..." create_editor_wrapper ( echo "Y" echo "" echo "" echo "" echo "" echo "" echo "" echo "Y" echo "Y" echo "" echo "" echo "" ) | EDITOR="/tmp/zapret_editor.sh" "$INSTALL_DIR/install_easy.sh" || true } finish() { echo "[7/7] Finalizing..." systemctl enable nfqws 2>/dev/null || true systemctl start nfqws 2>/dev/null || true rm -rf "$INSTALL_DIR" \ /tmp/zapret_nfqws_opt.txt \ /tmp/zapret_editor.sh \ /tmp/zapret_blockcheck.log echo "" echo "==========================================" echo " Done! Open: $BLOCKED_DOMAIN" echo " Uninstall: sudo $OPT_DIR/uninstall_easy.sh" echo "==========================================" } install_deps setup_dns download_zapret prepare_install run_blockcheck run_install_easy finish