mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Shellcheck for Test for $? -eq 0
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
parent
a713cf7952
commit
a122fb2900
1 changed files with 60 additions and 84 deletions
|
@ -252,16 +252,13 @@ chooseInterface() {
|
||||||
# Find out how many interfaces are available to choose from
|
# Find out how many interfaces are available to choose from
|
||||||
interfaceCount=$(echo "${availableInterfaces}" | wc -l)
|
interfaceCount=$(echo "${availableInterfaces}" | wc -l)
|
||||||
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount})
|
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount})
|
||||||
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty)
|
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) || \
|
||||||
if [[ $? = 0 ]]; then
|
{ echo "::: Cancel selected. Exiting"; exit 1; }
|
||||||
for desiredInterface in ${chooseInterfaceOptions}; do
|
for desiredInterface in ${chooseInterfaceOptions}; do
|
||||||
PIHOLE_INTERFACE=${desiredInterface}
|
PIHOLE_INTERFACE=${desiredInterface}
|
||||||
echo "::: Using interface: $PIHOLE_INTERFACE"
|
echo "::: Using interface: $PIHOLE_INTERFACE"
|
||||||
done
|
done
|
||||||
else
|
|
||||||
echo "::: Cancel selected, exiting...."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useIPv6dialog() {
|
useIPv6dialog() {
|
||||||
|
@ -281,32 +278,27 @@ use4andor6() {
|
||||||
cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" ${r} ${c} 2)
|
cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" ${r} ${c} 2)
|
||||||
options=(IPv4 "Block ads over IPv4" on
|
options=(IPv4 "Block ads over IPv4" on
|
||||||
IPv6 "Block ads over IPv6" on)
|
IPv6 "Block ads over IPv6" on)
|
||||||
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) || { echo "::: Cancel selected. Exiting"; exit 1; }
|
||||||
if [[ $? = 0 ]];then
|
for choice in ${choices}
|
||||||
for choice in ${choices}
|
do
|
||||||
do
|
case ${choice} in
|
||||||
case ${choice} in
|
IPv4 ) useIPv4=true;;
|
||||||
IPv4 ) useIPv4=true;;
|
IPv6 ) useIPv6=true;;
|
||||||
IPv6 ) useIPv6=true;;
|
esac
|
||||||
esac
|
done
|
||||||
done
|
if [[ ${useIPv4} ]]; then
|
||||||
if [[ ${useIPv4} ]]; then
|
find_IPv4_information
|
||||||
find_IPv4_information
|
getStaticIPv4Settings
|
||||||
getStaticIPv4Settings
|
setStaticIPv4
|
||||||
setStaticIPv4
|
fi
|
||||||
fi
|
if [[ ${useIPv6} ]]; then
|
||||||
if [[ ${useIPv6} ]]; then
|
useIPv6dialog
|
||||||
useIPv6dialog
|
fi
|
||||||
fi
|
echo "::: IPv4 address: ${IPV4_ADDRESS}"
|
||||||
echo "::: IPv4 address: ${IPV4_ADDRESS}"
|
echo "::: IPv6 address: ${IPV6_ADDRESS}"
|
||||||
echo "::: IPv6 address: ${IPV6_ADDRESS}"
|
if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then
|
||||||
if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then
|
echo "::: Cannot continue, neither IPv4 or IPv6 selected"
|
||||||
echo "::: Cannot continue, neither IPv4 or IPv6 selected"
|
echo "::: Exiting"
|
||||||
echo "::: Exiting"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "::: Cancel selected. Exiting..."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -326,36 +318,29 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
|
||||||
# Start by getting the IPv4 address (pre-filling it with info gathered from DHCP)
|
# Start by getting the IPv4 address (pre-filling it with info gathered from DHCP)
|
||||||
# Start a loop to let the user enter their information with the chance to go back and edit it if necessary
|
# Start a loop to let the user enter their information with the chance to go back and edit it if necessary
|
||||||
until [[ ${ipSettingsCorrect} = True ]]; do
|
until [[ ${ipSettingsCorrect} = True ]]; do
|
||||||
|
|
||||||
# Ask for the IPv4 address
|
# Ask for the IPv4 address
|
||||||
IPV4_ADDRESS=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPV4_ADDRESS}" 3>&1 1>&2 2>&3)
|
IPV4_ADDRESS=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPV4_ADDRESS}" 3>&1 1>&2 2>&3) || \
|
||||||
if [[ $? = 0 ]]; then
|
|
||||||
echo "::: Your static IPv4 address: ${IPV4_ADDRESS}"
|
|
||||||
# Ask for the gateway
|
|
||||||
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3)
|
|
||||||
if [[ $? = 0 ]]; then
|
|
||||||
echo "::: Your static IPv4 gateway: ${IPv4gw}"
|
|
||||||
# Give the user a chance to review their settings before moving on
|
|
||||||
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
|
|
||||||
IP address: ${IPV4_ADDRESS}
|
|
||||||
Gateway: ${IPv4gw}" ${r} ${c}); then
|
|
||||||
# After that's done, the loop ends and we move on
|
|
||||||
ipSettingsCorrect=True
|
|
||||||
else
|
|
||||||
# If the settings are wrong, the loop continues
|
|
||||||
ipSettingsCorrect=False
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Cancelling gateway settings window
|
|
||||||
ipSettingsCorrect=False
|
|
||||||
echo "::: Cancel selected. Exiting..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Cancelling IPv4 settings window
|
# Cancelling IPv4 settings window
|
||||||
ipSettingsCorrect=False
|
{ ipSettingsCorrect=False; echo "::: Cancel selected. Exiting..."; exit 1; }
|
||||||
echo "::: Cancel selected. Exiting..."
|
echo "::: Your static IPv4 address: ${IPV4_ADDRESS}"
|
||||||
exit 1
|
|
||||||
fi
|
# Ask for the gateway
|
||||||
|
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) || \
|
||||||
|
# Cancelling gateway settings window
|
||||||
|
{ ipSettingsCorrect=False; echo "::: Cancel selected. Exiting..."; exit 1; }
|
||||||
|
echo "::: Your static IPv4 gateway: ${IPv4gw}"
|
||||||
|
|
||||||
|
# Give the user a chance to review their settings before moving on
|
||||||
|
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
|
||||||
|
IP address: ${IPV4_ADDRESS}
|
||||||
|
Gateway: ${IPv4gw}" ${r} ${c}); then
|
||||||
|
# After that's done, the loop ends and we move on
|
||||||
|
ipSettingsCorrect=True
|
||||||
|
else
|
||||||
|
# If the settings are wrong, the loop continues
|
||||||
|
ipSettingsCorrect=False
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
# End the if statement for DHCP vs. static
|
# End the if statement for DHCP vs. static
|
||||||
fi
|
fi
|
||||||
|
@ -446,8 +431,8 @@ setDNS() {
|
||||||
Norton "" off
|
Norton "" off
|
||||||
Comodo "" off
|
Comodo "" off
|
||||||
Custom "" off)
|
Custom "" off)
|
||||||
DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty)
|
DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) || \
|
||||||
if [[ $? = 0 ]];then
|
{ echo "::: Cancel selected. Exiting"; exit 1; }
|
||||||
case ${DNSchoices} in
|
case ${DNSchoices} in
|
||||||
Google)
|
Google)
|
||||||
echo "::: Using Google DNS servers."
|
echo "::: Using Google DNS servers."
|
||||||
|
@ -489,20 +474,15 @@ setDNS() {
|
||||||
prePopulate="${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}"
|
prePopulate="${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "${prePopulate}" 3>&1 1>&2 2>&3)
|
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "${prePopulate}" 3>&1 1>&2 2>&3) || \
|
||||||
|
{ echo "::: Cancel selected. Exiting"; exit 1; }
|
||||||
if [[ $? = 0 ]]; then
|
PIHOLE_DNS_1=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
||||||
PIHOLE_DNS_1=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
PIHOLE_DNS_2=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
||||||
PIHOLE_DNS_2=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
if ! valid_ip "${PIHOLE_DNS_1}" || [ ! "${PIHOLE_DNS_1}" ]; then
|
||||||
if ! valid_ip "${PIHOLE_DNS_1}" || [ ! "${PIHOLE_DNS_1}" ]; then
|
PIHOLE_DNS_1=${strInvalid}
|
||||||
PIHOLE_DNS_1=${strInvalid}
|
fi
|
||||||
fi
|
if ! valid_ip "${PIHOLE_DNS_2}" && [ "${PIHOLE_DNS_2}" ]; then
|
||||||
if ! valid_ip "${PIHOLE_DNS_2}" && [ "${PIHOLE_DNS_2}" ]; then
|
PIHOLE_DNS_2=${strInvalid}
|
||||||
PIHOLE_DNS_2=${strInvalid}
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "::: Cancel selected, exiting...."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
if [[ ${PIHOLE_DNS_1} == "${strInvalid}" ]] || [[ ${PIHOLE_DNS_2} == "${strInvalid}" ]]; then
|
if [[ ${PIHOLE_DNS_1} == "${strInvalid}" ]] || [[ ${PIHOLE_DNS_2} == "${strInvalid}" ]]; then
|
||||||
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $PIHOLE_DNS_1\n DNS Server 2: ${PIHOLE_DNS_2}" ${r} ${c}
|
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $PIHOLE_DNS_1\n DNS Server 2: ${PIHOLE_DNS_2}" ${r} ${c}
|
||||||
|
@ -524,10 +504,6 @@ setDNS() {
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
|
||||||
echo "::: Cancel selected. Exiting..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setLogging() {
|
setLogging() {
|
||||||
|
|
Loading…
Reference in a new issue