Fix logic in versionCheckDNSmasq, as dnsmasq.conf was being overwritten every time install was run. Fixes @kmr2319 's concern in #98

This commit is contained in:
Promofaux 2016-02-01 22:19:17 +00:00
parent 70e4104c17
commit aa1d3a4c2e

View file

@ -308,30 +308,34 @@ versionCheckDNSmasq(){
dnsFile2="/etc/dnsmasq.conf.orig" dnsFile2="/etc/dnsmasq.conf.orig"
dnsSearch="addn-hosts=/etc/pihole/gravity.list" dnsSearch="addn-hosts=/etc/pihole/gravity.list"
# Check if /etc/dnsmasq.conf exists defaultFile="/etc/.pihole/advanced/dnsmasq.conf.original"
if [ -d "/etc/dnsmasq.conf" ]; then newFileToInstall="/etc/.pihole/advanced/01-pihole.conf"
# If true, Check dnsmasq.conf for pihole magic newFileFinalLocation="/etc/dnsmasq.d/01-pihole.conf"
if [ -f $dnsFile1 ]; then
echo -n "::: Existing dnsmasq.conf found..."
if grep -q $dnsSearch $dnsFile1; then if grep -q $dnsSearch $dnsFile1; then
# If true, Check dnsmasq.conf.orig for pihole magic echo " it is from a previous pi-hole install."
if grep -q $dnsSearch $dnsFile2; then echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..."
# If true, use advanced/dnsmasq.conf.original $SUDO mv -f $dnsFile1 $dnsFile2
$SUDO mv -f /etc/dnsmasq.conf /etc/dnsmasq.conf.orig echo " done."
$SUDO cp /etc/.pihole/advanced/dnsmasq.conf.original /etc/dnsmasq.conf echo -n "::: Restoring default dnsmasq.conf..."
$SUDO cp $defaultFile $dnsFile1
echo " done."
else else
# If false, mv original file back echo " it is not a pi-hole file, leaving alone!"
$SUDO mv -f /etc/dnsmasq.conf.orig /etc/dnsmasq.conf
fi
# If false, This is a fresh install
fi fi
else else
# If false, use advanced/dnsmasq.conf.original echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..."
$SUDO cp /etc/.pihole/advanced/dnsmasq.conf.original /etc/dnsmasq.conf $SUDO cp $defaultFile $dnsFile1
echo " done."
fi fi
$SUDO cp /etc/.pihole/advanced/01-pihole.conf /etc/dnsmasq.d/01-pihole.conf echo "::: copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf"
$SUDO sed -i "s/@INT@/$piholeInterface/" /etc/dnsmasq.d/01-pihole.conf $SUDO cp $newFileToInstall $newFileFinalLocation
$SUDO sed -i "s/@DNS1@/$piholeDNS1/" /etc/dnsmasq.d/01-pihole.conf $SUDO sed -i "s/@INT@/$piholeInterface/" $newFileFinalLocation
$SUDO sed -i "s/@DNS2@/$piholeDNS2/" /etc/dnsmasq.d/01-pihole.conf $SUDO sed -i "s/@DNS1@/$piholeDNS1/" $newFileFinalLocation
$SUDO sed -i "s/@DNS2@/$piholeDNS2/" $newFileFinalLocation
} }
installScripts() { installScripts() {