mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
convert-dns-settings: Import all possible PPP dialin profiles.
* Avoid from adding the same imported DNS server multiple times. Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org> Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
This commit is contained in:
committed by
Arne Fitzenreiter
parent
dc08d74d95
commit
dcc655efb8
@@ -22,25 +22,49 @@
|
||||
main() {
|
||||
# Do not convert anything if we already have some servers set
|
||||
if [ ! -s "/var/ipfire/dns/servers" ]; then
|
||||
local DNS0 DNS1 DNS2
|
||||
# Array to store all found DNS servers.
|
||||
SERVERS=()
|
||||
|
||||
# Try to get the DNS servers from ethernet settings file.
|
||||
local DNS1 DNS2
|
||||
eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
|
||||
|
||||
if [ -s "/var/ipfire/ppp/settings" ]; then
|
||||
eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
|
||||
# Add the grabbed DNS servers to the servers array.
|
||||
SERVERS+=($DNS1 $DNS2)
|
||||
|
||||
# Check if the ppp settings file is not empty.
|
||||
if [ -s "/var/ipfire/ppp/settings" ]; then
|
||||
# Loop though all profile files.
|
||||
for file in /var/ipfire/ppp/settings*; do
|
||||
local DNS1 DNS2
|
||||
eval $(/usr/local/bin/readhash $file)
|
||||
|
||||
# Add the DNS servers to the array of SERVERS.
|
||||
for var in DNS1 DNS2; do
|
||||
local server="${!var}"
|
||||
|
||||
# Check if the current server is allready part
|
||||
# of the array.
|
||||
for element in "${SERVERS[@]}"; do
|
||||
[[ $element == $server ]] && continue
|
||||
done
|
||||
|
||||
SERVERS+=($server)
|
||||
done
|
||||
|
||||
# Remove DNS1 and DNS2 settings from profile file.
|
||||
sed -i "/^DNS[12]?=/d" $file
|
||||
done
|
||||
|
||||
# Remove DNS, DNS1 and DNS2
|
||||
sed -i "/^DNS[12]?=/d" /var/ipfire/ppp/settings
|
||||
elif [ -s "/var/ipfire/dns/settings" ]; then
|
||||
eval $(/usr/local/bin/readhash /var/ipfire/dns/settings)
|
||||
fi
|
||||
|
||||
local var
|
||||
local server
|
||||
local i=3
|
||||
for var in DNS0 DNS1 DNS2; do
|
||||
if [ -n "${!var}" ]; then
|
||||
echo "${i},${!var},,enabled,"
|
||||
(( i++ ))
|
||||
fi
|
||||
for server in "${SERVERS[@]}"; do
|
||||
echo "${i},${server},,enabled,"
|
||||
(( i++ ))
|
||||
done > /var/ipfire/dns/servers
|
||||
|
||||
# Empty the old settings file
|
||||
|
||||
Reference in New Issue
Block a user