Migrate legacy zapret runtime paths

This commit is contained in:
ushan0v
2026-05-01 15:48:28 +03:00
parent 5f0415dc83
commit 2da71c3b86
2 changed files with 72 additions and 0 deletions
+52
View File
@@ -824,6 +824,56 @@ migrate_legacy_zapret_nfqws_default() {
legacy_migration_changed=1
}
migrate_legacy_runtime_path_option() {
local section="$1"
local option="$2"
local value next_value
config_get value "$section" "$option"
[ -n "$value" ] || return 0
next_value="$(rewrite_legacy_zapret_runtime_paths "$value")"
[ "$next_value" != "$value" ] || return 0
log "Migrating legacy Zapret runtime path in '$section.$option'"
uci set "$PODKOP_CONFIG_NAME.$section.$option=$next_value"
legacy_migration_changed=1
}
migrate_legacy_runtime_path_list() {
local section="$1"
local option="$2"
local value item next_value changed=0
config_get value "$section" "$option"
[ -n "$value" ] || return 0
for item in $value; do
next_value="$(rewrite_legacy_zapret_runtime_paths "$item")"
[ "$next_value" != "$item" ] && changed=1
done
[ "$changed" -eq 1 ] || return 0
log "Migrating legacy Zapret runtime paths in '$section.$option'"
uci -q delete "$PODKOP_CONFIG_NAME.$section.$option"
for item in $value; do
next_value="$(rewrite_legacy_zapret_runtime_paths "$item")"
uci add_list "$PODKOP_CONFIG_NAME.$section.$option=$next_value"
done
legacy_migration_changed=1
}
migrate_legacy_zapret_runtime_paths() {
local section="$1"
migrate_legacy_runtime_path_option "$section" "nfqws_opt"
migrate_legacy_runtime_path_list "$section" "local_domain_lists"
migrate_legacy_runtime_path_list "$section" "local_subnet_lists"
migrate_legacy_runtime_path_list "$section" "domain_ip_lists"
migrate_legacy_runtime_path_list "$section" "rule_set"
}
check_requirements() {
log "Check Requirements"
@@ -1240,6 +1290,8 @@ migration() {
config_foreach normalize_incomplete_rule_section "rule"
config_foreach migrate_builtin_rulesets_to_community_lists "rule"
config_foreach migrate_legacy_zapret_nfqws_default "rule"
config_foreach migrate_legacy_zapret_runtime_paths "rule"
cleanup_legacy_zapret_runtime
if [ "$legacy_migration_changed" -eq 1 ]; then
commit_podkop_config
+20
View File
@@ -647,6 +647,11 @@ zapret_package_installed() {
return 1
}
zapret_legacy_runtime_path_present() {
uci -q show "$PODKOP_CONFIG_NAME" 2>/dev/null | grep -Fq "$ZAPRET_LEGACY_RUNTIME_BASE_DIR" && return 0
[ -d "$ZAPRET_LEGACY_RUNTIME_BASE_DIR" ]
}
rewrite_legacy_zapret_runtime_paths() {
local provider_path legacy_path
@@ -865,6 +870,7 @@ build_generated_zapret_hostlist() {
}
check_zapret_requirements() {
cleanup_legacy_zapret_runtime
has_enabled_zapret_rules || return 0
if ! is_zapret_provider_available; then
@@ -1006,6 +1012,20 @@ ensure_zapret_standalone_conflict_resolved() {
return 0
}
stop_legacy_zapret_runtime_processes() {
local pid
ps w 2>/dev/null | grep -F "$ZAPRET_LEGACY_RUNTIME_BASE_DIR/nfq/nfqws" | grep -v grep | awk '{ print $1 }' | while read -r pid; do
[ -n "$pid" ] || continue
kill "$pid" 2>/dev/null || true
done
}
cleanup_legacy_zapret_runtime() {
stop_legacy_zapret_runtime_processes
rm -rf "$ZAPRET_LEGACY_RUNTIME_BASE_DIR"
}
get_zapret_nfqws_process_count() {
local count=0 pidfile pid