]> git.ipfire.org Git - ipfire-2.x.git/blame - src/scripts/convert-dns-settings
Merge remote-tracking branch 'ms/next-dns-ng' into next
[ipfire-2.x.git] / src / scripts / convert-dns-settings
CommitLineData
ecbf6676
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A Linux-based firewall #
5# Copyright (C) 2020 IPFire Team <info@ipfire.org> #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22main() {
23 # Do not convert anything if we already have some servers set
24 if [ ! -s "/var/ipfire/dns/servers" ]; then
25 local DNS0 DNS1 DNS2
26 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
27
28 if [ -s "/var/ipfire/ppp/settings" ]; then
29 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
1434fa0d
MT
30
31 # Remove DNS, DNS1 and DNS2
32 sed -i "/^DNS[12]?=/d" /var/ipfire/ppp/settings
ecbf6676
MT
33 elif [ -s "/var/ipfire/dns/settings" ]; then
34 eval $(/usr/local/bin/readhash /var/ipfire/dns/settings)
35 fi
36
37 local var
38 local i=3
39 for var in DNS0 DNS1 DNS2; do
40 if [ -n "${!var}" ]; then
41 echo "${i},${!var},,enabled,"
42 (( i++ ))
43 fi
44 done > /var/ipfire/dns/servers
45
46 # Empty the old settings file
47 : > /var/ipfire/dns/settings
48
49 # Disable using ISP name servers when we already have some configured
50 if [ ${i} -gt 3 ]; then
51 echo "USE_ISP_NAMESERVERS=off" \
52 >> /var/ipfire/dns/settings
53 fi
54 fi
55
c73baee1
SS
56 # Set correct ownership.
57 chown nobody:nobody /var/ipfire/dns/settings
58
ecbf6676
MT
59 # Convert old unbound settings file
60 if [ -e "/etc/sysconfig/unbound" ]; then
61 local USE_FORWARDERS
62 local ENABLE_SAFE_SEARCH
63 local FORCE_TCP
64
65 # Read settings
66 eval $(/usr/local/bin/readhash /etc/sysconfig/unbound)
67
68 # Safe Search
69 if [ "${ENABLE_SAFE_SEARCH}" = "on" ]; then
70 echo "ENABLE_SAFE_SEARCH=${ENABLE_SAFE_SEARCH}" \
71 >> /var/ipfire/dns/settings
72 fi
73
74 # Force TCP
75 if [ "${FORCE_TCP}" = "on" ]; then
76 echo "PROTO=TCP" >> /var/ipfire/dns/settings
77 fi
78
79 # Run in recursor mode
80 if [ "${USE_FORWARDERS}" = "0" ]; then
81 # Remove all servers
82 : > /var/ipfire/dns/servers
83 fi
84
85 rm -f "/etc/sysconfig/unbound"
86 fi
c73baee1
SS
87
88 # Set correct ownership.
89 chown nobody:nobody /var/ipfire/dns/servers
7be4822f
MT
90
91 # Make DHCP leases readable for nobody
92 chown 644 /etc/unbound/dhcp-leases.conf
ecbf6676
MT
93}
94
95main "$@" || exit $?