* Print newline on error message
* Output last three lines of error if update fails
* Consistent error messages & housekeeping
* Add shellcheck directive to ignore COL_TABLE
* Quoted and braced variables for codebase consistency
* Escaped newlines correctly
* Made error messages consistent (indenting and wording)
* Removed consecutive echos
* Conditional formatting consistency
* Braced, quoted and used [[ on conditionals
* Fix specific ShellCheck issues
* Fixed issues that could be safely changed without extensive testing
* Update SELinux whiptail behaviour & more
* Colourised some strings
* Fixed multiple line string indenting
* Made output consistent with existing codebase
* Removed sequential echos
* Make SELinux whiptail use "--defaultno", and change text wording
* Add help text for hostrecord, and colourise output
* this should fix the tests...
Signed-off-by: Adam Warner <adamw@rner.email>
* revert changes to `update_package_cache()` to prove tests
Signed-off-by: Adam Warner <adamw@rner.email>
# This is an important file as it contains information specific to the machine it's being installed on
setupVars=/etc/pihole/setupVars.conf
# Pi-hole uses lighttpd as a Web server, and this is the config file for it
# shellcheck disable=SC2034
lighttpdConfig=/etc/lighttpd/lighttpd.conf
# This is a file used for the colorized output
coltable=/opt/pihole/COL_TABLE
@ -79,7 +79,7 @@ reconfigure=false
runUnattended=false
# If the color table file exists,
if[[ -f ${coltable}]];then
if[[ -f "${coltable}"]];then
# source it
source${coltable}
# Othwerise,
@ -91,8 +91,9 @@ else
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]"
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]"
INFO="[i]"
# shellcheck disable=SC2034
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
OVER="\r\033[K"
OVER="\\r\\033[K"
fi
# A simple function that just echoes out our logo in ASCII format
@ -122,7 +123,6 @@ show_ascii_berry() {
"
}
# Compatibility
distro_check(){
# If apt-get is installed, then we know it's part of the Debian family
@ -321,13 +321,13 @@ getGitFiles() {
# Show that we're checking it
echo -e "${OVER}${TICK}${str}"
# Update the repo, returning an error message on failure
update_repo "${directory}"||{echo -e "\n ${COL_LIGHT_RED}Error: Could not update local repository. Contact support.${COL_NC}";exit 1;}
update_repo "${directory}"||{echo -e "\\n ${COL_LIGHT_RED}Error: Could not update local repository. Contact support.${COL_NC}";exit 1;}
# If it's not a .git repo,
else
# Show an error
echo -e "${OVER}${CROSS}${str}"
# Attempt to make the repository, showing an error on falure
make_repo "${directory}""${remoteRepo}"||{echo -e "\n ${COL_LIGHT_RED}Error: Could not update local repository. Contact support.${COL_NC}";exit 1;}
make_repo "${directory}""${remoteRepo}"||{echo -e "\\n ${COL_LIGHT_RED}Error: Could not update local repository. Contact support.${COL_NC}";exit 1;}
fi
# echo a blank line
echo""
@ -380,13 +380,13 @@ get_available_interfaces() {
# A function for displaying the dialogs the user sees when first running the installer
welcomeDialogs(){
# Display the welcome dialog using an approriately sized window via the calculation conducted earlier in the script
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer""\n\nThis installer will transform your device into a network-wide ad blocker!" ${r}${c}
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer""\\n\\nThis installer will transform your device into a network-wide ad blocker!" ${r}${c}
# Request that users donate if they enjoy the software since we all work on it in our free time
whiptail --msgbox --backtitle "Plea" --title "Free and open source""\n\nThe Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" ${r}${c}
whiptail --msgbox --backtitle "Plea" --title "Free and open source""\\n\\nThe Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" ${r}${c}
# Explain the need for a static address
whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed""\n\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed""\\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them."${r}${c}
# Dialog for the user to enter custom upstream servers
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 -e "${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}";exit 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}')
# If the IP is valid,
if ! valid_ip "${PIHOLE_DNS_1}"||[ ! "${PIHOLE_DNS_1}"];then
if ! valid_ip "${PIHOLE_DNS_1}"||[[ ! "${PIHOLE_DNS_1}"]];then
# store it in the variable so we can use it
PIHOLE_DNS_1=${strInvalid}
fi
# Do the same for the secondary server
if ! valid_ip "${PIHOLE_DNS_2}"&&["${PIHOLE_DNS_2}"];then
if ! valid_ip "${PIHOLE_DNS_2}"&&[["${PIHOLE_DNS_2}"]];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}
# and set the variables back to nothing
if[[${PIHOLE_DNS_1}=="${strInvalid}"]];then
if[["${PIHOLE_DNS_1}"=="${strInvalid}"]];then
PIHOLE_DNS_1=""
fi
if[[${PIHOLE_DNS_2}=="${strInvalid}"]];then
if[["${PIHOLE_DNS_2}"=="${strInvalid}"]];then
PIHOLE_DNS_2=""
fi
# Since the settings will not work, stay in the loop
@ -856,7 +857,7 @@ setDNS() {
# Othwerise,
else
# Show the settings
if(whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $PIHOLE_DNS_1\n DNS Server 2: ${PIHOLE_DNS_2}"${r}${c});then
if(whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\\n DNS Server 1: $PIHOLE_DNS_1\\n DNS Server 2: ${PIHOLE_DNS_2}"${r}${c});then
# and break from the loop since the servers are vaid
DNSSettingsCorrect=True
# Otherwise,
@ -878,7 +879,7 @@ setLogging() {
local LogChoices
# Ask if the user wants to log queries
LogToggleCommand=(whiptail --separate-output --radiolist "Do you want to log queries?\n (Disabling will render graphs on the Admin page useless):" ${r}${c} 6)
LogToggleCommand=(whiptail --separate-output --radiolist "Do you want to log queries?\\n (Disabling will render graphs on the Admin page useless):" ${r}${c} 6)
echo -e " No default index.lighttpd.html file found... not backing up"
echo -e "${OVER}${CROSS}${str}
No default index.lighttpd.html file found... not backing up"
fi
fi
@ -1435,9 +1431,9 @@ configureFirewall() {
# If a firewall is running,
if firewall-cmd --state &> /dev/null;then
# ask if the user wants to install Pi-hole's default firwall rules
whiptail --title "Firewall in use" --yesno "We have detected a running firewall\n\nPi-hole currently requires HTTP and DNS port access.\n\n\n\nInstall Pi-hole default firewall rules?" ${r}${c}||\
whiptail --title "Firewall in use" --yesno "We have detected a running firewall\\n\\nPi-hole currently requires HTTP and DNS port access.\\n\\n\\n\\nInstall Pi-hole default firewall rules?" ${r}${c}||\
{echo -e "${INFO} Not installing firewall rulesets.";return 0;}
echo -e "${TICK} Configuring FirewallD for httpd and dnsmasq."
echo -e "${TICK} Configuring FirewallD for httpd and dnsmasq"
whiptail --title "Firewall in use" --yesno "We have detected a running firewall\n\nPi-hole currently requires HTTP and DNS port access.\n\n\n\nInstall Pi-hole default firewall rules?" ${r}${c}||\
whiptail --title "Firewall in use" --yesno "We have detected a running firewall\\n\\nPi-hole currently requires HTTP and DNS port access.\\n\\n\\n\\nInstall Pi-hole default firewall rules?" ${r}${c}||\
{echo -e "${INFO} Not installing firewall rulesets.";return 0;}
echo -e "${TICK} Installing new IPTables firewall rulesets."
echo -e "${TICK} Installing new IPTables firewall rulesets"
# Check chain first, otherwise a new rule will duplicate old ones
# If the Web interface is not set to be installed,
if[[${INSTALL_WEB}==false]];then
if[["${INSTALL_WEB}"==false]];then
# and if there is not an IPv4 address,
if[${IPV4_ADDRESS}];then
if[["${IPV4_ADDRESS}"]];then
# there is no block page, so set IPv4 to 0.0.0.0 (all IP addresses)
IPV4_ADDRESS="0.0.0.0"
fi
if[${IPV6_ADDRESS}];then
if[["${IPV6_ADDRESS}"]];then
# and IPv6 to ::/0
IPV6_ADDRESS="::/0"
fi
fi
# If the setup variable file exists,
if[ -e "${setupVars}"];then
sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/QUERY_LOGGING/d;/INSTALL_WEB/d;/LIGHTTPD_ENABLED/d;'"${setupVars}"
if[[ -e "${setupVars}"]];then
# update the variables in the file
sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/QUERY_LOGGING/d;/INSTALL_WEB/d;'"${setupVars}"
fi
# echo the information to the user
{
@ -1526,7 +1523,7 @@ installLogrotate() {
# the local properties of the /var/log directory
logusergroup="$(stat -c '%U %G' /var/log)"
# If the variable has a value,
if[[ ! -z $logusergroup]];then
if[[ ! -z "${logusergroup}"]];then
#
sed -i "s/# su #/su ${logusergroup}/g;" /etc/pihole/logrotate
whiptail --title "SELinux Enforcing Detected" --yesno "SELinux is being Enforced on your system!\n\nPi-hole currently does not support SELinux, but you may still continue with the installation.\n\nNote: Admin UI Will not function fully without setting your policies correctly\n\nContinue installing Pi-hole?"${r}${c}||\
echo -e "${INFO} Continuing installation with SELinux Enforcing"
echo -e "${INFO} Please refer to official SELinux documentation to create a custom policy"
whiptail --defaultno --title "SELinux Enforcing Detected" --yesno "SELinux is being ENFORCED on your system! \\n\\nPi-hole currently does not support SELinux, but you may still continue with the installation.\\n\\nNote: Web Admin will not be fully functional unless you set your policies correctly\\n\\nContinue installing Pi-hole?"${r}${c}||\
additional="View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin
@ -1678,7 +1673,7 @@ ${additional}" ${r} ${c}
update_dialogs(){
# If pihole -r "reconfigure" option was selected,
if["${reconfigure}"=true];then
if[["${reconfigure}"=true]];then
# set some variables that will be used
opt1a="Repair"
opt1b="This will retain existing settings"
@ -1694,7 +1689,7 @@ update_dialogs() {
opt2b="This will allow you to enter new settings"
# Display the information to the user
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)"${r}${c}2\
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\\n\\nWe have detected an existing install.\\n\\nPlease choose from the following options: \\n($strAdd)"${r}${c}2\
"${opt1a}""${opt1b}"\
"${opt2a}""${opt2b}" 3>&2 2>&1 1>&3)||\
{echo -e "${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}";exit 1;}
@ -1703,7 +1698,7 @@ update_dialogs() {
case${UpdateCmd} in
# repair, or
${opt1a})
echo -e "${INFO}${opt1a} option selected."
echo -e "${INFO}${opt1a} option selected"
useUpdateVars=true
;;
# recongigure,
@ -1714,7 +1709,6 @@ update_dialogs() {
esac
}
clone_or_update_repos(){
# If the user wants to reconfigure,
if[["${reconfigure}"==true]];then
@ -1725,7 +1719,7 @@ clone_or_update_repos() {
exit 1;\
}
# If the Web interface was installed,
if[[${INSTALL_WEB}==true]];then
if[["${INSTALL_WEB}"==true]];then
# reset it's repo
resetRepo ${webInterfaceDir}||\
{echo -e "${COL_LIGHT_RED}Unable to reset ${webInterfaceDir}, exiting installer${COL_NC}";\