summaryrefslogtreecommitdiffstats
path: root/net/adblock/files/95-adblock-housekeeping
blob: 4451d166944b2c9056880c28ebf96159a1bbcaea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
# Copyright (c) 2015-2026 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.

# (s)hellcheck exceptions
# shellcheck disable=all

export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"

config="adblock"
old_options="adb_sources adb_forcedns adb_fetchutil adb_hag_sources adb_hst_sources adb_stb_sources adb_utc_sources \
	adb_maxqueue adb_backup adb_dnsfilereset adb_tmpbase adb_mailcnt adb_safesearchmod adb_srcfile adb_srcarc adb_nice \
	adb_hag_feed adb_jaildir adb_dnsdenyip adb_dnsallowip adb_zonelist adb_portlist adb_dnsforce adb_replisten"

for option in ${old_options}; do
	inplace="0"
	if uci -q get ${config}.global.${option} >/dev/null 2>&1; then
		old_values="$(uci -q get ${config}.global.${option})"
		for value in ${old_values}; do
			case "${option}" in
				"adb_sources")
					if ! uci -q get ${config}.global.adb_feed | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_feed="${value}"
					fi
				;;
				"adb_hag_sources")
					if ! uci -q get ${config}.global.adb_hag_feed | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_hag_feed="${value}"
					fi
				;;
				"adb_hst_sources")
					if ! uci -q get ${config}.global.adb_hst_feed | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_hst_feed="${value}"
					fi
				;;
				"adb_stb_sources")
					if ! uci -q get ${config}.global.adb_stb_feed | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_stb_feed="${value}"
					fi
				;;
				"adb_utc_sources")
					if ! uci -q get ${config}.global.adb_utc_feed | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_utc_feed="${value}"
					fi
				;;
				"adb_fetchutil")
					uci -q set ${config}.global.adb_fetchcmd="${value}"
				;;
				"adb_tmpbase")
					uci -q set ${config}.global.adb_basedir="${value}"
				;;
				"adb_nice")
					uci -q set ${config}.global.adb_nicelimit="${value}"
				;;
				"adb_hag_feed")
					inplace="1"
					if ! printf "%s" "${value}" | grep -qE "^(wildcard/|domains/)"; then
						uci -q del_list ${config}.global.adb_hag_feed="${value}"
						uci -q add_list ${config}.global.adb_hag_feed="wildcard/${value}"
					fi
				;;
				"adb_forcedns" | "adb_dnsforce")
					uci -q set ${config}.global.adb_nftforce="${value}"
				;;
				"adb_zonelist")
					if ! uci -q get ${config}.global.adb_nftdevforce | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_nftdevforce="${value}"
					fi
				;;
				"adb_portlist")
					if ! uci -q get ${config}.global.adb_nftportforce | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_nftportforce="${value}"
					fi
				;;
				"adb_replisten")
					if ! uci -q get ${config}.global.adb_repport | grep -q "${value}"; then
						uci -q add_list ${config}.global.adb_repport="${value}"
					fi
				;;
			esac
		done
		[ "${inplace}" = "0" ] && uci -q delete ${config}.global.${option}
	fi
done
[ -n "$(uci -q changes ${config})" ] && uci -q commit ${config}

# remove former adblock-related firewall zones
#
fwcfg="$(uci -qNX show "firewall" | awk 'BEGIN{FS="[.=]"};/adblock_/{if(zone==$2){next}else{ORS=" ";zone=$2;print zone}}')"
for section in ${fwcfg}; do
	uci -q delete firewall."${section}"
done
if [ -n "$(uci -q changes firewall)" ]; then
	uci -q commit firewall
	/etc/init.d/firewall reload
fi
exit 0