Newer
Older
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
#!/bin/sh
. /lib/functions.sh
bbfdm_sysctl_conf="/etc/bbfdm/sysctl.conf"
update_device_section() {
local section="${1}"
local dev_name="${2}"
local ipv6="${3}"
local name
# Get name value
config_get name "${section}" name
# Retrun if the name value is different to the dev_name value
[ "${name}" != "${dev_name}" ] && return
if [ "${ipv6}" = "0" ]; then
ipv6="1"
else
ipv6="0"
fi
# Add ipv6 option
uci -q set network.${section}.ipv6="${ipv6}"
}
parse_bbfdm_sysctl_conf_file() {
# Check if the file exists
[ -f "${bbfdm_sysctl_conf}" ] || return
# Create a temporary file
tmpfile=$(mktemp)
# Load network config
config_load network
# Read each line of the file
while read -r line; do
if echo "$line" | grep -Eq '^net\.ipv6\.conf\.(.+)\.disable_ipv6=([0-1])$'; then
name=$(echo "$line" | sed -n 's/^net\.ipv6\.conf\.\(.*\)\.disable_ipv6=[0-1]$/\1/p')
value=$(echo "$line" | sed -n 's/^net\.ipv6\.conf\.\(.*\)\.disable_ipv6=\([0-1]\)$/\2/p')
config_foreach update_device_section device "${name}" "${value}"
else
# If the line doesn't match, preserve it in the temporary file
echo "$line" >> "$tmpfile"
fi
done < "${bbfdm_sysctl_conf}"
# Replace the original file with the modified content
mv "$tmpfile" "${bbfdm_sysctl_conf}"
}
parse_bbfdm_sysctl_conf_file
exit 0