Initial commit: zapret-discord-youtube-linux v1.9.8c-linux
This commit is contained in:
@@ -0,0 +1,302 @@
|
||||
#!/bin/bash
|
||||
# update.sh - Auto-update, auto-build, auto-test, auto-install pipeline
|
||||
# Full automation: download updates → rebuild nfqws → test strategies → install working one
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/lib/functions.sh"
|
||||
|
||||
GITHUB_REPO="Flowseal/zapret-discord-youtube"
|
||||
GITHUB_RAW="https://raw.githubusercontent.com/$GITHUB_REPO/main"
|
||||
GITHUB_RELEASES="https://github.com/$GITHUB_REPO/releases"
|
||||
LOCAL_VERSION_FILE="$SCRIPT_DIR/.service/version.txt"
|
||||
UPDATE_LOG="$SCRIPT_DIR/.service/update.log"
|
||||
|
||||
mkdir -p "$SCRIPT_DIR/.service"
|
||||
|
||||
log_msg() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$UPDATE_LOG"
|
||||
}
|
||||
|
||||
# Check remote version
|
||||
check_remote_version() {
|
||||
local remote_ver
|
||||
remote_ver=$(curl -sfL "$GITHUB_RAW/.service/version.txt" 2>/dev/null | head -n1 | tr -d '[:space:]')
|
||||
if [[ -z "$remote_ver" ]]; then
|
||||
log_msg "ERROR: Failed to fetch remote version"
|
||||
return 1
|
||||
fi
|
||||
echo "$remote_ver"
|
||||
}
|
||||
|
||||
# Update lists and scripts (non-destructive)
|
||||
update_files() {
|
||||
log_msg "[*] Updating lists and scripts from GitHub..."
|
||||
|
||||
for file in list-general.txt list-google.txt list-exclude.txt ipset-exclude.txt; do
|
||||
local url="$GITHUB_RAW/lists/$file"
|
||||
local dest="$SCRIPT_DIR/lists/$file"
|
||||
if curl -sfL "$url" -o "$dest.tmp" 2>/dev/null; then
|
||||
mv "$dest.tmp" "$dest"
|
||||
log_msg " [OK] Updated lists/$file"
|
||||
else
|
||||
log_msg " [SKIP] lists/$file (unavailable)"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -f "$SCRIPT_DIR/.service/ipset_filter_loaded" ]] || [[ -f "$SCRIPT_DIR/.service/ipset_filter_any" ]]; then
|
||||
local url="$GITHUB_RAW/.service/ipset-all.txt"
|
||||
local dest="$SCRIPT_DIR/lists/ipset-all.txt"
|
||||
if curl -sfL "$url" -o "$dest.tmp" 2>/dev/null; then
|
||||
mv "$dest.tmp" "$dest"
|
||||
log_msg " [OK] Updated lists/ipset-all.txt"
|
||||
fi
|
||||
fi
|
||||
|
||||
for file in lib/functions.sh utils/test_zapret.sh utils/targets.txt; do
|
||||
local url="$GITHUB_RAW/$file"
|
||||
local dest="$SCRIPT_DIR/$file"
|
||||
if curl -sfL "$url" -o "$dest.tmp" 2>/dev/null; then
|
||||
mv "$dest.tmp" "$dest"
|
||||
log_msg " [OK] Updated $file"
|
||||
fi
|
||||
done
|
||||
|
||||
log_msg "[*] File update complete."
|
||||
}
|
||||
|
||||
# Rebuild nfqws with verification
|
||||
rebuild_nfqws() {
|
||||
log_msg "[*] Rebuilding nfqws..."
|
||||
|
||||
if ! bash "$SCRIPT_DIR/install_nfqws.sh"; then
|
||||
log_msg "[FAIL] nfqws build script failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Verify binary exists
|
||||
if [[ ! -x "$BIN_DIR/nfqws" ]]; then
|
||||
log_msg "[FAIL] nfqws binary not found after build."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Verify binary can start (quick help check)
|
||||
if ! "$BIN_DIR/nfqws" --help >/dev/null 2>&1; then
|
||||
log_msg "[FAIL] nfqws binary built but does not execute."
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_msg "[OK] nfqws rebuilt and verified."
|
||||
return 0
|
||||
}
|
||||
|
||||
# Run autotest to find working strategy and install it
|
||||
run_autotest_pipeline() {
|
||||
log_msg "[*] Running auto-test pipeline to find working strategy..."
|
||||
|
||||
# Stop any existing service first
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
systemctl stop zapret.service 2>/dev/null || true
|
||||
fi
|
||||
cleanup_firewall >/dev/null 2>&1 || true
|
||||
sleep 2
|
||||
|
||||
# Run autotest in auto mode
|
||||
if bash "$SCRIPT_DIR/autotest.sh" --auto; then
|
||||
log_msg "[OK] Auto-test found working strategy and installed it."
|
||||
return 0
|
||||
else
|
||||
log_msg "[FAIL] Auto-test did not find any working strategy."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Restart service if installed
|
||||
restart_service() {
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
if systemctl is-enabled zapret.service >/dev/null 2>&1; then
|
||||
log_msg "[*] Restarting zapret.service..."
|
||||
systemctl restart zapret.service
|
||||
log_msg "[OK] Service restarted."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Full pipeline: update → build → test → install
|
||||
full_pipeline() {
|
||||
local mode="${1:-interactive}"
|
||||
local force="${2:-no}"
|
||||
|
||||
if [[ "$mode" == "interactive" ]]; then
|
||||
echo ""
|
||||
echo "=============================================="
|
||||
echo " Zapret Full Auto Pipeline"
|
||||
echo " Current: $LOCAL_VERSION"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Step 1: Check remote version
|
||||
log_msg "[*] Step 1/4: Checking for updates..."
|
||||
local remote_version
|
||||
remote_version=$(check_remote_version) || {
|
||||
log_msg "Could not check remote version."
|
||||
if [[ "$mode" == "interactive" ]]; then
|
||||
read -rp "Continue with local rebuild anyway? [y/N]: " ans
|
||||
[[ "$ans" == [yY]* ]] || exit 1
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
remote_version="$LOCAL_VERSION"
|
||||
}
|
||||
|
||||
if [[ "$mode" == "interactive" ]]; then
|
||||
echo "Remote version: $remote_version"
|
||||
echo "Local version: $LOCAL_VERSION"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Decide whether to update
|
||||
local do_update=0
|
||||
if [[ "$remote_version" != "$LOCAL_VERSION" ]]; then
|
||||
do_update=1
|
||||
log_msg "New version available: $remote_version"
|
||||
elif [[ "$force" == "yes" ]]; then
|
||||
log_msg "Force rebuild requested."
|
||||
do_update=1
|
||||
fi
|
||||
|
||||
if [[ "$do_update" -eq 0 ]]; then
|
||||
log_msg "No update needed."
|
||||
if [[ "$mode" == "interactive" ]]; then
|
||||
read -rp "Rebuild nfqws and re-test anyway? [y/N]: " ans
|
||||
[[ "$ans" == [yY]* ]] || {
|
||||
echo "[*] Nothing to do. Exiting."
|
||||
exit 0
|
||||
}
|
||||
else
|
||||
log_msg "Exiting (no update, no force)."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 2: Update files
|
||||
if [[ "$remote_version" != "$LOCAL_VERSION" ]]; then
|
||||
log_msg "[*] Step 2/4: Updating files from GitHub..."
|
||||
update_files
|
||||
echo "LOCAL_VERSION=\"$remote_version-linux\"" > "$LOCAL_VERSION_FILE"
|
||||
else
|
||||
log_msg "[*] Step 2/4: Skipping file update (same version, force mode)."
|
||||
fi
|
||||
|
||||
# Step 3: Rebuild nfqws with verification
|
||||
log_msg "[*] Step 3/4: Rebuilding nfqws..."
|
||||
if ! rebuild_nfqws; then
|
||||
log_msg "[CRITICAL] Build failed. Aborting."
|
||||
if [[ "$mode" == "interactive" ]]; then
|
||||
read -rp "Press Enter to exit..."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 4: Auto-test and install
|
||||
log_msg "[*] Step 4/4: Auto-testing strategies..."
|
||||
if run_autotest_pipeline; then
|
||||
log_msg "[SUCCESS] Pipeline complete: updated, built, tested, installed."
|
||||
else
|
||||
log_msg "[WARNING] Build OK, but no working strategy found."
|
||||
log_msg " You may need to adjust parameters manually."
|
||||
fi
|
||||
|
||||
if [[ "$mode" == "interactive" ]]; then
|
||||
echo ""
|
||||
print_green "=============================================="
|
||||
print_green " Full Pipeline Complete!"
|
||||
print_green " Version: $(cat "$LOCAL_VERSION_FILE" 2>/dev/null || echo $LOCAL_VERSION)"
|
||||
print_green "=============================================="
|
||||
echo ""
|
||||
systemctl status zapret --no-pager 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
# Auto mode (for cron/systemd timers)
|
||||
auto_mode() {
|
||||
log_msg "Auto-update started..."
|
||||
|
||||
local remote_version
|
||||
remote_version=$(check_remote_version) || {
|
||||
log_msg "Update check failed. Exiting."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ "$remote_version" == "$LOCAL_VERSION" ]]; then
|
||||
log_msg "No update needed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log_msg "New version found: $remote_version"
|
||||
full_pipeline auto no
|
||||
log_msg "Auto-update finished."
|
||||
}
|
||||
|
||||
# CLI
|
||||
MODE="interactive"
|
||||
FORCE="no"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--auto|-a)
|
||||
MODE="auto"
|
||||
shift
|
||||
;;
|
||||
--force|-f)
|
||||
FORCE="yes"
|
||||
shift
|
||||
;;
|
||||
--full-auto)
|
||||
# Fully non-interactive: even if same version, rebuild and re-test
|
||||
MODE="auto"
|
||||
FORCE="yes"
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTIONS]
|
||||
|
||||
Zapret Update Pipeline: checks version → updates files → rebuilds nfqws → auto-tests → installs.
|
||||
|
||||
Options:
|
||||
--auto, -a Non-interactive mode (for cron/systemd timers)
|
||||
--force, -f Force rebuild even if versions match
|
||||
--full-auto Same as --auto --force (rebuild + re-test always)
|
||||
--help, -h Show this help
|
||||
|
||||
Interactive mode (default):
|
||||
sudo ./update.sh
|
||||
|
||||
Full automation (no questions, always rebuilds and re-tests):
|
||||
sudo ./update.sh --full-auto
|
||||
|
||||
For systemd timer (daily auto-update):
|
||||
sudo ./update.sh --auto
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$MODE" == "auto" ]]; then
|
||||
if [[ "$FORCE" == "yes" ]]; then
|
||||
full_pipeline auto yes
|
||||
else
|
||||
auto_mode
|
||||
fi
|
||||
else
|
||||
full_pipeline interactive "$FORCE"
|
||||
fi
|
||||
Reference in New Issue
Block a user