mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-26 03:28:04 +02:00
simple DNS test
This commit is contained in:
@@ -22,62 +22,57 @@ if [ "${DNSSERVER}" = "test" ]; then
|
|||||||
dnsworking=$(host w3c.org | grep -c "w3c.org has address")
|
dnsworking=$(host w3c.org | grep -c "w3c.org has address")
|
||||||
|
|
||||||
# when no dialog just return result of test and exit
|
# when no dialog just return result of test and exit
|
||||||
if [ "${NODIALOG}" = "nodialog" ]; then
|
if [ "${NODIALOG}" = "nodialog" ] || [ ${dnsworking} -eq 1 ]; then
|
||||||
echo "dnsworking=${dnsworking}"
|
echo "dnsworking=${dnsworking}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# when dns not working ask in dialog to set a preset DNS
|
# dns is not working --> ask in dialog to set a preset DNS
|
||||||
if [ ${dnsworking} -eq 0 ]; then
|
whiptail --title ' DNS Test Failed ' --yes-button='Set DNS 1.1.1.1' --no-button='Ignore' --yesno "It looks like your DNS within local network is not working.\n
|
||||||
whiptail --title ' DNS Test Failed ' --yes-button='Set DNS 1.1.1.1' --no-button='Ignore' --yesno "It looks like your DNS within local network is not working.\n
|
|
||||||
Do you want to set the fixed DNS 1.1.1.1 by cloudfare (they claim they provide privacy) for your RaspiBlitz and reboot?\n
|
Do you want to set the fixed DNS 1.1.1.1 by cloudfare (they claim they provide privacy) for your RaspiBlitz and reboot?\n
|
||||||
" 10 64
|
" 10 64
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "SETTING 1.1.1.1"
|
echo "# SETTING 1.1.1.1"
|
||||||
DNSSERVER="1.1.1.1"
|
DNSSERVER="1.1.1.1"
|
||||||
autoreboot=1
|
autoreboot=1
|
||||||
else
|
|
||||||
echo "Ignoring DNS-Test fail"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "DNS TEST --> OK"
|
echo "# Ignoring DNS-Test fail"
|
||||||
fi
|
fi
|
||||||
exit 1
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "The DNS server you want to set is: ${DNSSERVER}"
|
echo "The DNS server you want to set is: ${DNSSERVER}"
|
||||||
|
|
||||||
# checking parameter
|
# checking parameter
|
||||||
if [[ $DNSSERVER =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then
|
if [[ $DNSSERVER =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then
|
||||||
echo "OK IPv6"
|
echo "# OK IPv6"
|
||||||
elif [[ $DNSSERVER =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then
|
elif [[ $DNSSERVER =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then
|
||||||
echo "OK IPv4"
|
echo "# OK IPv4"
|
||||||
else
|
else
|
||||||
echo "FAIL - not an IPv4 or IPv6 address"
|
echo "error='not an IPv4 or IPv6 address'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# setting DNS address
|
# setting DNS address
|
||||||
echo "Setting DNS server in /etc/dhcpcd.conf ..."
|
echo "# Setting DNS server in /etc/dhcpcd.conf ..."
|
||||||
sudo sed -i "s/^static domain_name_servers=.*/static domain_name_servers=${DNSSERVER}/g" /etc/dhcpcd.conf
|
sudo sed -i "s/^static domain_name_servers=.*/static domain_name_servers=${DNSSERVER}/g" /etc/dhcpcd.conf
|
||||||
echo "OK"
|
echo "# OK"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# make sure entry in raspiblitz.conf exists
|
# make sure entry in raspiblitz.conf exists
|
||||||
source /mnt/hdd/raspiblitz.conf
|
source /mnt/hdd/raspiblitz.conf
|
||||||
if [ ${#dnsServer} -eq 0 ]; then
|
if [ ${#dnsServer} -eq 0 ]; then
|
||||||
echo "Adding value to /mnt/hdd/raspiblitz.conf"
|
echo "# Adding value to /mnt/hdd/raspiblitz.conf"
|
||||||
echo "dnsServer=${DNSSERVER}" >> /mnt/hdd/raspiblitz.conf
|
echo "dnsServer=${DNSSERVER}" >> /mnt/hdd/raspiblitz.conf
|
||||||
else
|
else
|
||||||
echo "Updating value in /mnt/hdd/raspiblitz.conf"
|
echo "# Updating value in /mnt/hdd/raspiblitz.conf"
|
||||||
sudo sed -i "s/^dnsServer=.*/dnsServer=${DNSSERVER}/g" /mnt/hdd/raspiblitz.conf
|
sudo sed -i "s/^dnsServer=.*/dnsServer=${DNSSERVER}/g" /mnt/hdd/raspiblitz.conf
|
||||||
fi
|
fi
|
||||||
echo "OK"
|
echo "# OK"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "DNS Server is set - reboot needed before active"
|
echo "# DNS Server is set - reboot needed before active"
|
||||||
if [ ${autoreboot} -eq 1 ]; then
|
if [ ${autoreboot} -eq 1 ]; then
|
||||||
sudo shutdown -r now
|
sudo shutdown -r now
|
||||||
fi
|
fi
|
Reference in New Issue
Block a user