Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'automated install/basic-install.sh')
-rwxr-xr-xautomated install/basic-install.sh1534
1 files changed, 1074 insertions, 460 deletions
diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh
index 2cf2c61d..79754872 100755
--- a/automated install/basic-install.sh
+++ b/automated install/basic-install.sh
@@ -1,43 +1,65 @@
#!/usr/bin/env bash
+# shellcheck disable=SC1090
+
# Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
-# Installs Pi-hole
+# Installs and Updates Pi-hole
#
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
-
-
# pi-hole.net/donate
#
-# Install with this command (from your Pi):
+# Install with this command (from your Linux machine):
#
# curl -L install.pi-hole.net | bash
+# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
+# We do not want users to end up with a partially working install, so we exit the script
+# instead of continuing the installation with something broken
set -e
+
######## VARIABLES #########
+# For better maintainability, we store as much information that can change in variables
+# This allows us to make a change in one place that can propogate to all instances of the variable
+# These variables should all be GLOBAL variables, written in CAPS
+# Local variables will be in lowercase and will exist only within functions
+# It's still a work in progress, so you may see some variance in this guideline until it is complete
+
+# We write to a temporary file before moving the log to the pihole folder
tmpLog=/tmp/pihole-install.log
instalLogLoc=/etc/pihole/install.log
+# 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
+# We store several other folders and
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"
webInterfaceDir="/var/www/html/admin"
piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
PI_HOLE_LOCAL_REPO="/etc/.pihole"
+# These are the names of piholes files, stored in an array
PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update version gravity uninstall webpage)
+# This folder is where the Pi-hole scripts will be installed
PI_HOLE_INSTALL_DIR="/opt/pihole"
useUpdateVars=false
+# Pi-hole needs an IP address; to begin, these variables are empty since we don't know what the IP is until
+# this script can run
IPV4_ADDRESS=""
IPV6_ADDRESS=""
+# By default, query logging is enabled and the dashboard is set to be installed
QUERY_LOGGING=true
INSTALL_WEB=true
-# Find the rows and columns will default to 80x24 is it can not be detected
+# Find the rows and columns will default to 80x24 if it can not be detected
screen_size=$(stty size 2>/dev/null || echo 24 80)
rows=$(echo "${screen_size}" | awk '{print $1}')
columns=$(echo "${screen_size}" | awk '{print $2}')
@@ -50,19 +72,41 @@ r=$(( r < 20 ? 20 : r ))
c=$(( c < 70 ? 70 : c ))
######## Undocumented Flags. Shhh ########
+# These are undocumented flags; some of which we can use when repairing an installation
+# The runUnattended flag is one example of this
skipSpaceCheck=false
reconfigure=false
runUnattended=false
+# If the color table file exists,
+if [[ -f "${coltable}" ]]; then
+ # source it
+ source ${coltable}
+# Othwerise,
+else
+ # Set these values so the installer can still run in color
+ COL_NC='\e[0m' # No Color
+ COL_LIGHT_GREEN='\e[1;32m'
+ COL_LIGHT_RED='\e[1;31m'
+ 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"
+fi
+
+# A simple function that just echoes out our logo in ASCII format
+# This lets users know that it is a Pi-hole, LLC product
show_ascii_berry() {
- echo "
- .;;,.
+ echo -e "
+ ${COL_LIGHT_GREEN}.;;,.
.ccccc:,.
:cccclll:. ..,,
:ccccclll. ;ooodc
'ccll:;ll .oooodc
.;cll.;;looo:.
- .. ','.
+ ${COL_LIGHT_RED}.. ','.
.',,,,,,'.
.',,,,,,,,,,.
.',,,,,,,,,,,,....
@@ -75,70 +119,97 @@ show_ascii_berry() {
....',,,,,,,,,,,,.
.',,,,,,,,,'.
.',,,,,,'.
- ..'''.
+ ..'''.${COL_NC}
"
}
-
# Compatibility
distro_check() {
+# If apt-get is installed, then we know it's part of the Debian family
if command -v apt-get &> /dev/null; then
- #Debian Family
- #############################################
+ # Set some global variables here
+ # We don't set them earlier since the family might be Red Hat, so these values would be different
PKG_MANAGER="apt-get"
+ # A variable to store the command used to update the package cache
UPDATE_PKG_CACHE="${PKG_MANAGER} update"
+ # An array for something...
PKG_INSTALL=(${PKG_MANAGER} --yes --no-install-recommends install)
# grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE
PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"
- # #########################################
- # fixes for dependency differences
- # Debian 7 doesn't have iproute2 use iproute
+ # Some distros vary slightly so these fixes for dependencies may apply
+ # Debian 7 doesn't have iproute2 so if the dry run install is successful,
if ${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1; then
+ # we can install it
iproute_pkg="iproute2"
+ # Otherwise,
else
+ # use iproute
iproute_pkg="iproute"
fi
- # Prefer the php metapackage if it's there, fall back on the php5 packages
+ # We prefer the php metapackage if it's there
if ${PKG_MANAGER} install --dry-run php > /dev/null 2>&1; then
phpVer="php"
+ # If not,
else
+ # fall back on the php5 packages
phpVer="php5"
fi
- # #########################################
+ # We also need the correct version for `php-sqlite` (which differs across distros)
+ if ${PKG_MANAGER} install --dry-run ${phpVer}-sqlite3 > /dev/null 2>&1; then
+ phpSqlite="sqlite3"
+ else
+ phpSqlite="sqlite"
+ fi
+ # Since our install script is so large, we need several other programs to successfuly get a machine provisioned
+ # These programs are stored in an array so they can be looped through later
INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail)
- PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget)
- PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi)
+ # Pi-hole itself has several dependencies that also need to be installed
+ PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget idn2)
+ # The Web dashboard has some that also need to be installed
+ # It's useful to separate the two since our repos are also setup as "Core" code and "Web" code
+ PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer}-${phpSqlite})
+ # The Web server user,
LIGHTTPD_USER="www-data"
+ # group,
LIGHTTPD_GROUP="www-data"
+ # and config file
LIGHTTPD_CFG="lighttpd.conf.debian"
+ # The DNS server user
DNSMASQ_USER="dnsmasq"
+ # A function to check...
test_dpkg_lock() {
- i=0
- while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
- sleep 0.5
- ((i=i+1))
- done
- # Always return success, since we only return if there is no
- # lock (anymore)
- return 0
- }
+ # An iterator used for counting loop iterations
+ i=0
+ # fuser is a program to show which processes use the named files, sockets, or filesystems
+ # So while the command is true
+ while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
+ # Wait half a second
+ sleep 0.5
+ # and increase the iterator
+ ((i=i+1))
+ done
+ # Always return success, since we only return if there is no
+ # lock (anymore)
+ return 0
+ }
+# If apt-get is not found, check for rpm to see if it's a Red Hat family OS
elif command -v rpm &> /dev/null; then
- # Fedora Family
+ # Then check if dnf or yum is the package manager
if command -v dnf &> /dev/null; then
PKG_MANAGER="dnf"
else
PKG_MANAGER="yum"
fi
-# Fedora and family update cache on every PKG_INSTALL call, no need for a separate update.
+ # Fedora and family update cache on every PKG_INSTALL call, no need for a separate update.
UPDATE_PKG_CACHE=":"
PKG_INSTALL=(${PKG_MANAGER} install -y)
PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l"
INSTALLER_DEPS=(dialog git iproute net-tools newt procps-ng)
- PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils nmap-ncat sudo unzip wget)
- PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli)
+ PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils nmap-ncat sudo unzip wget libidn2 psmisc)
+ PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli php-pdo)
if ! grep -q 'Fedora' /etc/redhat-release; then
INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release");
fi
@@ -147,149 +218,233 @@ elif command -v rpm &> /dev/null; then
LIGHTTPD_CFG="lighttpd.conf.fedora"
DNSMASQ_USER="nobody"
+# If neither apt-get or rmp/dnf are found
else
- echo "OS distribution not supported"
+ # it's not an OS we can support,
+ echo -e " ${CROSS} OS distribution not supported"
+ # so exit the installer
exit
fi
}
+# A function for checking if a folder is a git repository
is_repo() {
- # Use git to check if directory is currently under VCS, return the value 128
- # if directory is not a repo. Return 1 if directory does not exist.
+ # Use a named, local variable instead of the vague $1, which is the first arguement passed to this function
+ # These local variables should always be lowercase
local directory="${1}"
+ # A local variable for the current directory
local curdir
+ # A variable to store the return code
local rc
-
+ # Assign the current directory variable by using pwd
curdir="${PWD}"
+ # If the first argument passed to this function is a directory,
if [[ -d "${directory}" ]]; then
- # git -C is not used here to support git versions older than 1.8.4
+ # move into the directory
cd "${directory}"
+ # Use git to check if the folder is a repo
+ # git -C is not used here to support git versions older than 1.8.4
git status --short &> /dev/null || rc=$?
+ # If the command was not successful,
else
- # non-zero return code if directory does not exist
+ # Set a non-zero return code if directory does not exist
rc=1
fi
+ # Move back into the directory the user started in
cd "${curdir}"
+ # Return the code; if one is not set, return 0
return "${rc:-0}"
}
+# A function to clone a repo
make_repo() {
+ # Set named variables for better readability
local directory="${1}"
local remoteRepo="${2}"
-
- echo -n "::: Cloning ${remoteRepo} into ${directory}..."
- # Clean out the directory if it exists for git to clone into
+ # The message to display when this function is running
+ str="Clone ${remoteRepo} into ${directory}"
+ # Display the message and use the color table to preface the message with an "info" indicator
+ echo -ne " ${INFO} ${str}..."
+ # If the directory exists,
if [[ -d "${directory}" ]]; then
+ # delete everything in it so git can clone into it
rm -rf "${directory}"
fi
+ # Clone the repo and return the return code from this command
git clone -q --depth 1 "${remoteRepo}" "${directory}" &> /dev/null || return $?
- echo " done!"
+ # Show a colored message showing it's status
+ echo -e "${OVER} ${TICK} ${str}"
+ # Always return 0? Not sure this is correct
return 0
}
+# We need to make sure the repos are up-to-date so we can effectively install Clean out the directory if it exists for git to clone into
update_repo() {
+ # Use named, local variables
+ # As you can see, these are the same variable names used in the last function,
+ # but since they are local, their scope does not go beyond this function
+ # This helps prevent the wrong value from being assigned if you were to set the variable as a GLOBAL one
local directory="${1}"
local curdir
+ # A variable to store the message we want to display;
+ # Again, it's useful to store these in variables in case we need to reuse or change the message;
+ # we only need to make one change here
+ local str="Update repo in ${1}"
+
+ # Make sure we know what directory we are in so we can move back into it
curdir="${PWD}"
+ # Move into the directory that was passed as an argument
cd "${directory}" &> /dev/null || return 1
- # Pull the latest commits
- echo -n "::: Updating repo in ${1}..."
+ # Let the user know what's happening
+ echo -ne " ${INFO} ${str}..."
+ # Stash any local commits as they conflict with our working code
git stash --all --quiet &> /dev/null || true # Okay for stash failure
- git clean --force -d || true # Okay for already clean directory
+ git clean --quiet --force -d || true # Okay for already clean directory
+ # Pull the latest commits
git pull --quiet &> /dev/null || return $?
- echo " done!"
+ # Show a completion message
+ echo -e "${OVER} ${TICK} ${str}"
+ # Move back into the oiginal directory
cd "${curdir}" &> /dev/null || return 1
return 0
}
+# A function that combines the functions previously made
getGitFiles() {
- # Setup git repos for directory and repository passed
- # as arguments 1 and 2
+ # Setup named variables for the git repos
+ # We need the directory
local directory="${1}"
+ # as well as the repo URL
local remoteRepo="${2}"
- echo ":::"
- echo "::: Checking for existing repository..."
+ # A local varible containing the message to be displayed
+ local str="Check for existing repository in ${1}"
+ # Show the message
+ echo -ne " ${INFO} ${str}..."
+ # Check if the directory is a repository
if is_repo "${directory}"; then
- update_repo "${directory}" || { echo "*** Error: Could not update local repository. Contact support."; exit 1; }
- echo " done!"
+ # 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; }
+ # If it's not a .git repo,
else
- make_repo "${directory}" "${remoteRepo}" || { echo "Unable to clone repository, please contact support"; exit 1; }
- echo " done!"
+ # 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; }
fi
+ # echo a blank line
+ echo ""
+ # and return success?
return 0
}
+# Reset a repo to get rid of any local changed
resetRepo() {
+ # Use named varibles for arguments
local directory="${1}"
-
+ # Move into the directory
cd "${directory}" &> /dev/null || return 1
- echo -n "::: Resetting repo in ${1}..."
+ # Store the message in a varible
+ str="Resetting repository within ${1}..."
+ # Show the message
+ echo -ne " ${INFO} ${str}"
+ # Use git to remove the local changes
git reset --hard &> /dev/null || return $?
- echo " done!"
+ # And show the status
+ echo -e "${OVER} ${TICK} ${str}"
+ # Returning success anyway?
return 0
}
+# We need to know the IPv4 information so we can effectively setup the DNS server
+# Without this information, we won't know where to Pi-hole will be found
find_IPv4_information() {
+ # Named, local variables
local route
- # Find IP used to route to outside world
+ # Find IP used to route to outside world by checking the the route to Google's public DNS server
route=$(ip route get 8.8.8.8)
+ # Use awk to strip out just the interface device as it is used in future commands
IPv4dev=$(awk '{for (i=1; i<=NF; i++) if ($i~/dev/) print $(i+1)}' <<< "${route}")
+ # Get just the IP address
IPv4bare=$(awk '{print $7}' <<< "${route}")
+ # Append the CIDR notation to the IP address
IPV4_ADDRESS=$(ip -o -f inet addr show | grep "${IPv4bare}" | awk '{print $4}' | awk 'END {print}')
+ # Get the default gateway (the way to reach the Internet)
IPv4gw=$(awk '{print $3}' <<< "${route}")
}
+# Get available interfaces that are UP
get_available_interfaces() {
- # Get available UP interfaces.
+ # There may be more than one so it's all stored in a variable
availableInterfaces=$(ip --oneline link show up | grep -v "lo" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1)
}
+# A function for displaying the dialogs the user sees when first running the installer
welcomeDialogs() {
- # Display the welcome dialog
- whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "\n\nThis installer will transform your device into a network-wide ad blocker!" ${r} ${c}
+ # 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}
- # Support for a part-time dev
- 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}
+ # 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}
# 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}
}
+# We need to make sure there is enough space before installing, so there is a function to check this
verifyFreeDiskSpace() {
# 50MB is the minimum space needed (45MB install (includes web admin bootstrap/jquery libraries etc) + 5MB one day of logs.)
# - Fourdee: Local ensures the variable is only created, and accessible within this function/void. Generally considered a "good" coding practice for non-global variables.
- echo "::: Verifying free disk space..."
+ local str="Disk space check"
+ # Reqired space in KB
local required_free_kilobytes=51200
- local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}')
+ # Calculate existing free space on this machine
+ local existing_free_kilobytes
+ existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}')
- # - Unknown free disk space , not a integer
+ # If the existing space is not an integer,
if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then
- echo "::: Unknown free disk space!"
- echo "::: We were unable to determine available free disk space on this system."
- echo "::: You may override this check and force the installation, however, it is not recommended"
- echo "::: To do so, pass the argument '--i_do_not_follow_recommendations' to the install script"
- echo "::: eg. curl -L https://install.pi-hole.net | bash /dev/stdin --i_do_not_follow_recommendations"
+ # show an error that we can't determine the free space
+ echo -e " ${CROSS} ${str}
+ Unknown free disk space!
+ We were unable to determine available free disk space on this system.
+ You may override this check, however, it is not recommended
+ The option '${COL_LIGHT_RED}--i_do_not_follow_recommendations${COL_NC}' can override this
+ e.g: curl -L https://install.pi-hole.net | bash /dev/stdin ${COL_LIGHT_RED}<option>${COL_NC}"
+ # exit with an error code
exit 1
- # - Insufficient free disk space
- elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then
- echo "::: Insufficient Disk Space!"
- echo "::: Your system appears to be low on disk space. Pi-hole recommends a minimum of $required_free_kilobytes KiloBytes."
- echo "::: You only have ${existing_free_kilobytes} KiloBytes free."
- echo "::: If this is a new install you may need to expand your disk."
- echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'"
- echo "::: After rebooting, run this installation again. (curl -L https://install.pi-hole.net | bash)"
-
- echo "Insufficient free space, exiting..."
+ # If there is insufficient free disk space,
+ elif [[ "${existing_free_kilobytes}" -lt "${required_free_kilobytes}" ]]; then
+ # show an error message
+ echo -e " ${CROSS} ${str}
+ Your system disk appears to only have ${existing_free_kilobytes} KB free
+ It is recommended to have a minimum of ${required_free_kilobytes} KB to run the Pi-hole"
+ # if the vcgencmd command exists,
+ if command -v vcgencmd &> /dev/null; then
+ # it's probably a Raspbian install, so show a message about expanding the filesystem
+ echo " If this is a new install you may need to expand your disk
+ Run 'sudo raspi-config', and choose the 'expand file system' option
+ After rebooting, run this installation again
+ e.g: curl -L https://install.pi-hole.net | bash"
+ fi
+ # Show there is not enough free space
+ echo -e "\\n ${COL_LIGHT_RED}Insufficient free space, exiting...${COL_NC}"
+ # and exit with an error
exit 1
+ # Otherwise,
+ else
+ # Show that we're running a disk space check
+ echo -e " ${TICK} ${str}"
fi
}
-
+# A function that let's the user pick an interface to use with Pi-hole
chooseInterface() {
# Turn the available interfaces into an array so it can be used with a whiptail dialog
local interfacesArray=()
@@ -305,101 +460,162 @@ chooseInterface() {
# Find out how many interfaces are available to choose from
interfaceCount=$(echo "${availableInterfaces}" | wc -l)
- if [[ ${interfaceCount} -eq 1 ]]; then
+ # If there is one interface,
+ if [[ "${interfaceCount}" -eq 1 ]]; then
+ # Set it as the interface to use since there is no other option
PIHOLE_INTERFACE="${availableInterfaces}"
+ # Otherwise,
else
+ # While reading through the available interfaces
while read -r line; do
+ # use a variable to set the option as OFF to begin with
mode="OFF"
- if [[ ${firstLoop} -eq 1 ]]; then
+ # If it's the first loop,
+ if [[ "${firstLoop}" -eq 1 ]]; then
+ # set this as the interface to use (ON)
firstLoop=0
mode="ON"
fi
+ # Put all these interfaces into an array
interfacesArray+=("${line}" "available" "${mode}")
+ # Feed the available interfaces into this while loop
done <<< "${availableInterfaces}"
-
+ # The whiptail command that will be run, stored in a variable
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount})
+ # Now run the command using the interfaces saved into the array
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) || \
- { echo "::: Cancel selected. Exiting"; exit 1; }
+ # If the user chooses Canel, exit
+ { echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; }
+ # For each interface
for desiredInterface in ${chooseInterfaceOptions}; do
+ # Set the one the user selected as the interface to use
PIHOLE_INTERFACE=${desiredInterface}
- echo "::: Using interface: $PIHOLE_INTERFACE"
+ # and show this information to the user
+ echo -e " ${INFO} Using interface: $PIHOLE_INTERFACE"
done
fi
}
+# This lets us prefer ULA addresses over GUA
+# This caused problems for some users when their ISP changed their IPv6 addresses
# See https://github.com/pi-hole/pi-hole/issues/1473#issuecomment-301745953
testIPv6() {
+ # first will contain fda2 (ULA)
first="$(cut -f1 -d":" <<< "$1")"
- value1=$(((0x$first)/256))
- value2=$(((0x$first)%256))
- ((($value1&254)==252)) && echo "ULA" || true
- ((($value1&112)==32)) && echo "GUA" || true
- ((($value1==254) && (($value2&192)==128))) && echo "Link-local" || true
+ # value1 will contain 253 which is the decimal value corresponding to 0xfd
+ value1=$(( (0x$first)/256 ))
+ # will contain 162 which is the decimal value corresponding to 0xa2
+ value2=$(( (0x$first)%256 ))
+ # the ULA test is testing for fc00::/7 according to RFC 4193
+ if (( (value1&254)==252 )); then
+ echo "ULA"
+ fi
+ # the GUA test is testing for 2000::/3 according to RFC 4291
+ if (( (value1&112)==32 )); then
+ echo "GUA"
+ fi
+ # the LL test is testing for fe80::/10 according to RFC 4193
+ if (( (value1)==254 )) && (( (value2&192)==128 )); then
+ echo "Link-local"
+ fi
}
+# A dialog for showing the user about IPv6 blocking
useIPv6dialog() {
# Determine the IPv6 address used for blocking
IPV6_ADDRESSES=($(ip -6 address | grep 'scope global' | awk '{print $2}'))
- # Determine type of found IPv6 addresses
+ # For each address in the array above, determine the type of IPv6 address it is
for i in "${IPV6_ADDRESSES[@]}"; do
+ # Check if it's ULA, GUA, or LL by using the function created earlier
result=$(testIPv6 "$i")
+ # If it's a ULA address, use it and store it as a global variable
[[ "${result}" == "ULA" ]] && ULA_ADDRESS="${i%/*}"
+ # If it's a GUA address, we can still use it si store it as a global variable
[[ "${result}" == "GUA" ]] && GUA_ADDRESS="${i%/*}"
done
# Determine which address to be used: Prefer ULA over GUA or don't use any if none found
+ # If the ULA_ADDRESS contains a value,
if [[ ! -z "${ULA_ADDRESS}" ]]; then
+ # set the IPv6 address to the ULA address
IPV6_ADDRESS="${ULA_ADDRESS}"
- echo "::: Found IPv6 ULA address, using it for blocking IPv6 ads"
+ # Show this info to the user
+ echo -e " ${INFO} Found IPv6 ULA address, using it for blocking IPv6 ads"
+ # Otherwise, if the GUA_ADDRESS has a value,
elif [[ ! -z "${GUA_ADDRESS}" ]]; then
- echo "::: Found IPv6 GUA address, using it for blocking IPv6 ads"
+ # Let the user know
+ echo -e " ${INFO} Found IPv6 GUA address, using it for blocking IPv6 ads"
+ # And assign it to the global variable
IPV6_ADDRESS="${GUA_ADDRESS}"
+ # If none of those work,
else
- echo "::: Found neither IPv6 ULA nor GUA address, blocking IPv6 ads will not be enabled"
+ # explain that IPv6 blocking will not be used
+ echo -e " ${INFO} Unable to find IPv6 ULA/GUA address, IPv6 adblocking will not be enabled"
+ # So set the variable to be empty
IPV6_ADDRESS=""
fi
+ # If the IPV6_ADDRESS contains a value
if [[ ! -z "${IPV6_ADDRESS}" ]]; then
+ # Display that IPv6 is supported and will be used
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$IPV6_ADDRESS will be used to block ads." ${r} ${c}
fi
}
+# A function to check if we should use IPv4 and/or IPv6 for blocking ads
use4andor6() {
+ # Named local variables
local useIPv4
local useIPv6
- # Let use select IPv4 and/or IPv6
+ # Let use select IPv4 and/or IPv6 via a checklist
cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" ${r} ${c} 2)
+ # In an array, show the options available:
+ # IPv4 (on by default)
options=(IPv4 "Block ads over IPv4" on
+ # or IPv6 (on by default if available)
IPv6 "Block ads over IPv6" on)
- choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) || { echo "::: Cancel selected. Exiting"; exit 1; }
+ # In a variable, show the choices available; exit if Cancel is selected
+ choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) || { echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; }
+ # For each choice available,
for choice in ${choices}
do
+ # Set the values to true
case ${choice} in
IPv4 ) useIPv4=true;;
IPv6 ) useIPv6=true;;
esac
done
- if [[ ${useIPv4} ]]; then
+ # If IPv4 is to be used,
+ if [[ "${useIPv4}" ]]; then
+ # Run our function to get the information we need
find_IPv4_information
getStaticIPv4Settings
setStaticIPv4
fi
- if [[ ${useIPv6} ]]; then
+ # If IPv6 is to be used,
+ if [[ "${useIPv6}" ]]; then
+ # Run our function to get this information
useIPv6dialog
fi
- echo "::: IPv4 address: ${IPV4_ADDRESS}"
- echo "::: IPv6 address: ${IPV6_ADDRESS}"
- if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then
- echo "::: Cannot continue, neither IPv4 or IPv6 selected"
- echo "::: Exiting"
+ # Echo the information to the user
+ echo -e " ${INFO} IPv4 address: ${IPV4_ADDRESS}"
+ echo -e " ${INFO} IPv6 address: ${IPV6_ADDRESS}"
+ # If neither protocol is selected,
+ if [[ ! "${useIPv4}" ]] && [[ ! "${useIPv6}" ]]; then
+ # Show an error in red
+ echo -e " ${COL_LIGHT_RED}Error: Neither IPv4 or IPv6 selected${COL_NC}"
+ # and exit with an error
exit 1
fi
}
+#
getStaticIPv4Settings() {
+ # Local, named variables
local ipSettingsCorrect
# Ask if the user wants to use DHCP settings as their static IP
+ # This is useful for users that are using DHCP reservations; then we can just use the information gathered via our functions
if whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
IP address: ${IPV4_ADDRESS}
Gateway: ${IPv4gw}" ${r} ${c}; then
@@ -407,29 +623,29 @@ getStaticIPv4Settings() {
whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that.
If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." ${r} ${c}
- # Nothing else to do since the variables are already set above
+ # Nothing else to do since the variables are already set above
else
# Otherwise, we need to ask the user to input their desired settings.
# 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
- until [[ ${ipSettingsCorrect} = True ]]; do
+ until [[ "${ipSettingsCorrect}" = True ]]; do
# 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) || \
# Cancelling IPv4 settings window
- { ipSettingsCorrect=False; echo "::: Cancel selected. Exiting..."; exit 1; }
- echo "::: Your static IPv4 address: ${IPV4_ADDRESS}"
+ { ipSettingsCorrect=False; echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; }
+ echo -e " ${INFO} 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) || \
# Cancelling gateway settings window
- { ipSettingsCorrect=False; echo "::: Cancel selected. Exiting..."; exit 1; }
- echo "::: Your static IPv4 gateway: ${IPv4gw}"
+ { ipSettingsCorrect=False; echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; }
+ echo -e " ${INFO} 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
+ IP address: ${IPV4_ADDRESS}
+ Gateway: ${IPv4gw}" ${r} ${c}; then
# After that's done, the loop ends and we move on
ipSettingsCorrect=True
else
@@ -441,8 +657,9 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
fi
}
+# dhcpcd is very annoying,
setDHCPCD() {
- # Append these lines to dhcpcd.conf to enable a static IP
+ # but we can append these lines to dhcpcd.conf to enable a static IP
echo "interface ${PIHOLE_INTERFACE}
static ip_address=${IPV4_ADDRESS}
static routers=${IPv4gw}
@@ -450,31 +667,40 @@ setDHCPCD() {
}
setStaticIPv4() {
+ # Local, named variables
local IFCFG_FILE
local IPADDR
local CIDR
- if [[ -f /etc/dhcpcd.conf ]]; then
- # Debian Family
+ # For the Debian family, if dhcpcd.conf exists,
+ if [[ -f "/etc/dhcpcd.conf" ]]; then
+ # check if the IP is already in the file
if grep -q "${IPV4_ADDRESS}" /etc/dhcpcd.conf; then
- echo "::: Static IP already configured"
+ echo -e " ${INFO} Static IP already configured"
+ # If it's not,
else
+ # set it using our function
setDHCPCD
+ # Then use the ip command to immediately set the new address
ip addr replace dev "${PIHOLE_INTERFACE}" "${IPV4_ADDRESS}"
- echo ":::"
- echo "::: Setting IP to ${IPV4_ADDRESS}. You may need to restart after the install is complete."
- echo ":::"
+ # Also give a warning that the user may need to reboot their system
+ echo -e " ${TICK} Set IP address to ${IPV4_ADDRESS%/*}
+ You may need to restart after the install is complete"
fi
- elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE} ]];then
- # Fedora Family
+ # If it's not Debian, check if it's the Fedora family by checking for the file below
+ elif [[ -f "/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE}" ]];then
+ # If it exists,
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE}
+ # check if the desired IP is already set
if grep -q "${IPV4_ADDRESS}" "${IFCFG_FILE}"; then
- echo "::: Static IP already configured"
+ echo -e " ${INFO} Static IP already configured"
+ # Otherwise,
else
+ # Put the IP in variables without the CIDR notation
IPADDR=$(echo "${IPV4_ADDRESS}" | cut -f1 -d/)
CIDR=$(echo "${IPV4_ADDRESS}" | cut -f2 -d/)
# Backup existing interface configuration:
cp "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig
- # Build Interface configuration file:
+ # Build Interface configuration file using the GLOBAL variables we have
{
echo "# Configured via Pi-hole installer"
echo "DEVICE=$PIHOLE_INTERFACE"
@@ -487,120 +713,172 @@ setStaticIPv4() {
echo "DNS2=$PIHOLE_DNS_2"
echo "USERCTL=no"
}> "${IFCFG_FILE}"
+ # Use ip to immediately set the new address
ip addr replace dev "${PIHOLE_INTERFACE}" "${IPV4_ADDRESS}"
+ # If NetworkMangler command line interface exists,
if command -v nmcli &> /dev/null;then
- # Tell NetworkManager to read our new sysconfig file
+ # Tell NetworkManagler to read our new sysconfig file
nmcli con load "${IFCFG_FILE}" > /dev/null
fi
- echo ":::"
- echo "::: Setting IP to ${IPV4_ADDRESS}. You may need to restart after the install is complete."
- echo ":::"
+ # Show a warning that the user may need to restart
+ echo -e " ${TICK} Set IP address to ${IPV4_ADDRESS%/*}
+ You may need to restart after the install is complete"
fi
+ # If all that fails,
else
- echo "::: Warning: Unable to locate configuration file to set static IPv4 address!"
+ # show an error and exit
+ echo -e " ${INFO} Warning: Unable to locate configuration file to set static IPv4 address"
exit 1
fi
}
+# Check an IP address to see if it is a valid one
valid_ip() {
+ # Local, named variables
local ip=${1}
local stat=1
- if [[ ${ip} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
+ # If the IP matches the format xxx.xxx.xxx.xxx,
+ if [[ "${ip}" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
+ # Save the old Interfal Field Separator in a variable
OIFS=$IFS
+ # and set the new one to a dot (period)
IFS='.'
+ # Put the IP into an array
ip=(${ip})
+ # Restore the IFS to what it was
IFS=${OIFS}
- [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
- && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
+ ## Evaluate each octet by checking if it's less than or equal to 255 (the max for each octet)
+ [[ "${ip[0]}" -le 255 && "${ip[1]}" -le 255 \
+ && "${ip[2]}" -le 255 && "${ip[3]}" -le 255 ]]
+ # Save the exit code
stat=$?
fi
+ # Return the exit code
return ${stat}
}
+# A function to choose the upstream DNS provider(s)
setDNS() {
+ # Local, named variables
local DNSSettingsCorrect
+ # In an array, list the available upstream providers
DNSChooseOptions=(Google ""
OpenDNS ""
Level3 ""
Norton ""
Comodo ""
DNSWatch ""
+ Quad9 ""
Custom "")
- DNSchoices=$(whiptail --separate-output --menu "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 6 \
+ # In a whiptail dialog, show the options
+ DNSchoices=$(whiptail --separate-output --menu "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 7 \
"${DNSChooseOptions[@]}" 2>&1 >/dev/tty) || \
- { echo "::: Cancel selected. Exiting"; exit 1; }
+ # exit if Cancel is selected
+ { echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; }
+
+ # Display the selection
+ echo -ne " ${INFO} Using "
+ # Depending on the user's choice, set the GLOBAl variables to the IP of the respective provider
case ${DNSchoices} in
Google)
- echo "::: Using Google DNS servers."
+ echo "Google DNS servers"
PIHOLE_DNS_1="8.8.8.8"
PIHOLE_DNS_2="8.8.4.4"
;;
OpenDNS)
- echo "::: Using OpenDNS servers."
+ echo "OpenDNS servers"
PIHOLE_DNS_1="208.67.222.222"
PIHOLE_DNS_2="208.67.220.220"
;;
Level3)
- echo "::: Using Level3 servers."
+ echo "Level3 servers"
PIHOLE_DNS_1="4.2.2.1"
PIHOLE_DNS_2="4.2.2.2"
;;
Norton)
- echo "::: Using Norton ConnectSafe servers."
+ echo "Norton ConnectSafe servers"
PIHOLE_DNS_1="199.85.126.10"
PIHOLE_DNS_2="199.85.127.10"
;;
Comodo)
- echo "::: Using Comodo Secure servers."
+ echo "Comodo Secure servers"
PIHOLE_DNS_1="8.26.56.26"
PIHOLE_DNS_2="8.20.247.20"
;;
DNSWatch)
- echo "::: Using DNS.WATCH servers."
+ echo "DNS.WATCH servers"
PIHOLE_DNS_1="84.200.69.80"
PIHOLE_DNS_2="84.200.70.40"
;;
+ Quad9)
+ echo "Quad9 servers"
+ PIHOLE_DNS_1="9.9.9.9"
+ ;;
Custom)
- until [[ ${DNSSettingsCorrect} = True ]]; do
+ # Until the DNS settings are selected,
+ until [[ "${DNSSettingsCorrect}" = True ]]; do
+ #
strInvalid="Invalid"
- if [ ! ${PIHOLE_DNS_1} ]; then
- if [ ! ${PIHOLE_DNS_2} ]; then
+ # If the first
+ if [[ ! "${PIHOLE_DNS_1}" ]]; then
+ # and second upstream servers do not exist
+ if [[ ! "${PIHOLE_DNS_2}" ]]; then
+ #
prePopulate=""
+ # Otherwise,
else
+ #
prePopulate=", ${PIHOLE_DNS_2}"
fi
- elif [ ${PIHOLE_DNS_1} ] && [ ! ${PIHOLE_DNS_2} ]; then
+ #
+ elif [[ "${PIHOLE_DNS_1}" ]] && [[ ! "${PIHOLE_DNS_2}" ]]; then
+ #
prePopulate="${PIHOLE_DNS_1}"
- elif [ ${PIHOLE_DNS_1} ] && [ ${PIHOLE_DNS_2} ]; then
+ #
+ elif [[ "${PIHOLE_DNS_1}" ]] && [[ "${PIHOLE_DNS_2}" ]]; then
+ #
prePopulate="${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}"
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) || \
- { echo "::: Cancel selected. Exiting"; exit 1; }
+ # 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) || \
+ { 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 ! valid_ip "${PIHOLE_DNS_1}" || [ ! "${PIHOLE_DNS_1}" ]; then
+ # If the IP is valid,
+ 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
- if ! valid_ip "${PIHOLE_DNS_2}" && [ "${PIHOLE_DNS_2}" ]; then
+ # Do the same for the secondary server
+ if ! valid_ip "${PIHOLE_DNS_2}" && [[ "${PIHOLE_DNS_2}" ]]; then
PIHOLE_DNS_2=${strInvalid}
fi
- 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}
- if [[ ${PIHOLE_DNS_1} == "${strInvalid}" ]]; then
+ # If either of the DNS servers are invalid,
+ if [[ "${PIHOLE_DNS_1}" == "${strInvalid}" ]] || [[ "${PIHOLE_DNS_2}" == "${strInvalid}" ]]; then
+ # explain this to the user
+ 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
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
DNSSettingsCorrect=False
+ # Othwerise,
else
- 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
+ # 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
+ # and break from the loop since the servers are vaid
DNSSettingsCorrect=True
+ # Otherwise,
else
- # If the settings are wrong, the loop continues
+ # If the settings are wrong, the loop continues
DNSSettingsCorrect=False
fi
fi
@@ -609,51 +887,67 @@ setDNS() {
esac
}
+# Allow the user to enable/disable logging
setLogging() {
+ # Local, named variables
local LogToggleCommand
local LogChooseOptions
local LogChoices
- LogToggleCommand=(whiptail --separate-output --radiolist "Do you want to log queries?\n (Disabling will render graphs on the Admin page useless):" ${r} ${c} 6)
+ # 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)
+ # The default selection is on
LogChooseOptions=("On (Recommended)" "" on
Off "" off)
- LogChoices=$("${LogToggleCommand[@]}" "${LogChooseOptions[@]}" 2>&1 >/dev/tty) || (echo "::: Cancel selected. Exiting..." && exit 1)
+ # Get the user's choice
+ LogChoices=$("${LogToggleCommand[@]}" "${LogChooseOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1)
case ${LogChoices} in
+ # If it's on
"On (Recommended)")
- echo "::: Logging On."
+ echo -e " ${INFO} Logging On."
+ # Set the GLOBAL variable to true so we know what they selected
QUERY_LOGGING=true
;;
+ # Othwerise, it's off,
Off)
- echo "::: Logging Off."
+ echo -e " ${INFO} Logging Off."
+ # So set it to false
QUERY_LOGGING=false
;;
esac
}
+# Funtion to ask the user if they want to install the dashboard
setAdminFlag() {
+ # Local, named variables
local WebToggleCommand
local WebChooseOptions
local WebChoices
+ # Similar to the logging function, ask what the user wants
WebToggleCommand=(whiptail --separate-output --radiolist "Do you wish to install the web admin interface?" ${r} ${c} 6)
+ # with the default being enabled
WebChooseOptions=("On (Recommended)" "" on
Off "" off)
- WebChoices=$("${WebToggleCommand[@]}" "${WebChooseOptions[@]}" 2>&1 >/dev/tty) || (echo "::: Cancel selected. Exiting..." && exit 1)
+ WebChoices=$("${WebToggleCommand[@]}" "${WebChooseOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1)
+ # Depending on their choice
case ${WebChoices} in
"On (Recommended)")
- echo "::: Web Interface On."
+ echo -e " ${INFO} Web Interface On"
+ # Set it to true
INSTALL_WEB=true
;;
Off)
- echo "::: Web Interface off."
+ echo -e " ${INFO} Web Interface Off"
+ # or false
INSTALL_WEB=false
;;
esac
}
-
+# Check if /etc/dnsmasq.conf is from pihole. If so replace with an original and install new in .d directory
version_check_dnsmasq() {
- # Check if /etc/dnsmasq.conf is from pihole. If so replace with an original and install new in .d directory
+ # Local, named variables
local dnsmasq_conf="/etc/dnsmasq.conf"
local dnsmasq_conf_orig="/etc/dnsmasq.conf.orig"
local dnsmasq_pihole_id_string="addn-hosts=/etc/pihole/gravity.list"
@@ -661,103 +955,149 @@ version_check_dnsmasq() {
local dnsmasq_pihole_01_snippet="${PI_HOLE_LOCAL_REPO}/advanced/01-pihole.conf"
local dnsmasq_pihole_01_location="/etc/dnsmasq.d/01-pihole.conf"
- if [ -f ${dnsmasq_conf} ]; then
- echo -n "::: Existing dnsmasq.conf found..."
+ # If the dnsmasq config file exists
+ if [[ -f "${dnsmasq_conf}" ]]; then
+ echo -ne " ${INFO} Existing dnsmasq.conf found..."
+ # If gravity.list is found within this file, we presume it's from older versions on Pi-hole,
if grep -q ${dnsmasq_pihole_id_string} ${dnsmasq_conf}; then
echo " it is from a previous Pi-hole install."
- echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..."
+ echo -ne " ${INFO} Backing up dnsmasq.conf to dnsmasq.conf.orig..."
+ # so backup the original file
mv -f ${dnsmasq_conf} ${dnsmasq_conf_orig}
- echo " done."
- echo -n "::: Restoring default dnsmasq.conf..."
+ echo -e "${OVER} ${TICK} Backing up dnsmasq.conf to dnsmasq.conf.orig..."
+ echo -ne " ${INFO} Restoring default dnsmasq.conf..."
+ # and replace it with the default
cp ${dnsmasq_original_config} ${dnsmasq_conf}
- echo " done."
+ echo -e "${OVER} ${TICK} Restoring default dnsmasq.conf..."
+ # Otherwise,
else
+ # Don't to anything
echo " it is not a Pi-hole file, leaving alone!"
fi
else
- echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..."
+ # If a file cannot be found,
+ echo -ne " ${INFO} No dnsmasq.conf found... restoring default dnsmasq.conf..."
+ # restore the default one
cp ${dnsmasq_original_config} ${dnsmasq_conf}
- echo " done."
+ echo -e "${OVER} ${TICK} No dnsmasq.conf found... restoring default dnsmasq.conf..."
fi
- echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..."
+ echo -en " ${INFO} Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..."
+ # Copy the new Pi-hole DNS config file into the dnsmasq.d directory
cp ${dnsmasq_pihole_01_snippet} ${dnsmasq_pihole_01_location}
- echo " done."
+ echo -e "${OVER} ${TICK} Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf"
+ # Replace our placeholder values with the GLOBAL DNS variables that we populated earlier
+ # First, swap in the interface to listen on
sed -i "s/@INT@/$PIHOLE_INTERFACE/" ${dnsmasq_pihole_01_location}
if [[ "${PIHOLE_DNS_1}" != "" ]]; then
+ # Then swap in the primary DNS server
sed -i "s/@DNS1@/$PIHOLE_DNS_1/" ${dnsmasq_pihole_01_location}
else
+ #
sed -i '/^server=@DNS1@/d' ${dnsmasq_pihole_01_location}
fi
if [[ "${PIHOLE_DNS_2}" != "" ]]; then
+ # Then swap in the primary DNS server
sed -i "s/@DNS2@/$PIHOLE_DNS_2/" ${dnsmasq_pihole_01_location}
else
+ #
sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location}
fi
+ #
sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsmasq_conf}
+ # If the user does not want to enable logging,
if [[ "${QUERY_LOGGING}" == false ]] ; then
- #Disable Logging
+ # Disable it by commenting out the directive in the DNS config file
sed -i 's/^log-queries/#log-queries/' ${dnsmasq_pihole_01_location}
+ # Otherwise,
else
- #Enable Logging
+ # enable it by uncommenting the directive in the DNS config file
sed -i 's/^#log-queries/log-queries/' ${dnsmasq_pihole_01_location}
fi
}
+# Clean an existing installation to prepare for upgrade/reinstall
clean_existing() {
- # Clean an exiting installation to prepare for upgrade/reinstall
- # ${1} Directory to clean; ${2} Array of files to remove
+ # Local, named variables
+ # ${1} Directory to clean
local clean_directory="${1}"
+ # Make ${2} the new one?
shift
+ # ${2} Array of files to remove
local old_files=( "$@" )
+ # For each script found in the old files array
for script in "${old_files[@]}"; do
+ # Remove them
rm -f "${clean_directory}/${script}.sh"
done
}
+# Install the scripts from repository to their various locations
installScripts() {
- # Install the scripts from repository to their various locations
-
- echo ":::"
- echo -n "::: Installing scripts from ${PI_HOLE_LOCAL_REPO}..."
+ # Local, named variables
+ local str="Installing scripts from ${PI_HOLE_LOCAL_REPO}"
+ echo -ne " ${INFO} ${str}..."
# Clear out script files from Pi-hole scripts directory.
clean_existing "${PI_HOLE_INSTALL_DIR}" "${PI_HOLE_FILES[@]}"
# Install files from local core repository
if is_repo "${PI_HOLE_LOCAL_REPO}"; then
+ # move into the directory
cd "${PI_HOLE_LOCAL_REPO}"
+ # Install the scripts by:
+ # -o setting the owner to the user
+ # -Dm755 create all leading components of destiantion except the last, then copy the source to the destiantion and setting the permissions to 755
+ #
+ # This first one is the directory
install -o "${USER}" -Dm755 -d "${PI_HOLE_INSTALL_DIR}"
+ # The rest are the scripts Pi-hole needs
install -o "${USER}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" gravity.sh
install -o "${USER}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" ./advanced/Scripts/*.sh
install -o "${USER}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" ./automated\ install/uninstall.sh
+ install -o "${USER}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" ./advanced/Scripts/COL_TABLE
install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole
install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole
- echo " done."
+ echo -e "${OVER} ${TICK} ${str}"
+ # Otherwise,
else
- echo " *** ERROR: Local repo ${PI_HOLE_LOCAL_REPO} not found, exiting."
+ # Show an error and exit
+ echo -e "${OVER} ${CROSS} ${str}
+ ${COL_LIGHT_RED}Error: Local repo ${PI_HOLE_LOCAL_REPO} not found, exiting installer${COL_NC}"
exit 1
fi
}
+# Install the configs from PI_HOLE_LOCAL_REPO to their various locations
installConfigs() {
- # Install the configs from PI_HOLE_LOCAL_REPO to their various locations
- echo ":::"
- echo "::: Installing configs from ${PI_HOLE_LOCAL_REPO}..."
+ echo ""
+ echo -e " ${INFO} Installing configs from ${PI_HOLE_LOCAL_REPO}..."
+ # Make sure Pi-hole's config files are in place
version_check_dnsmasq
- #Only mess with lighttpd configs if user has chosen to install web interface
- if [[ ${INSTALL_WEB} == true ]]; then
- if [ ! -d "/etc/lighttpd" ]; then
+ # If the user chose to install the dashboard,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # and if the Web server conf directory does not exist,
+ if [[ ! -d "/etc/lighttpd" ]]; then
+ # make it
mkdir /etc/lighttpd
+ # and set the owners
chown "${USER}":root /etc/lighttpd
- elif [ -f "/etc/lighttpd/lighttpd.conf" ]; then
+ # Otherwise, if the config file already exists
+ elif [[ -f "/etc/lighttpd/lighttpd.conf" ]]; then
+ # back up the original
mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
fi
+ # and copy in the config file Pi-hole needs
cp ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf
+ # if there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config
+ if [[ -f "/var/www/html/pihole/custom.php" ]]; then
+ sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"pihole\/custom\.php"/' /etc/lighttpd/lighttpd.conf
+ fi
+ # Make the directories if they do not exist and set the owners
mkdir -p /var/run/lighttpd
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd
mkdir -p /var/cache/lighttpd/compress
@@ -770,80 +1110,119 @@ installConfigs() {
stop_service() {
# Stop service passed in as argument.
# Can softfail, as process may not be installed when this is called
- echo ":::"
- echo -n "::: Stopping ${1} service..."
+ local str="Stopping ${1} service"
+ echo ""
+ echo -ne " ${INFO} ${str}..."
if command -v systemctl &> /dev/null; then
systemctl stop "${1}" &> /dev/null || true
else
service "${1}" stop &> /dev/null || true
fi
- echo " done."
+ echo -e "${OVER} ${TICK} ${str}..."
}
+# Start/Restart service passed in as argument
start_service() {
- # Start/Restart service passed in as argument
- # This should not fail, it's an error if it does
- echo ":::"
- echo -n "::: Starting ${1} service..."
+ # Local, named variables
+ local str="Starting ${1} service"
+ echo ""
+ echo -ne " ${INFO} ${str}..."
+ # If systemctl exists,
if command -v systemctl &> /dev/null; then
+ # use that to restart the service
systemctl restart "${1}" &> /dev/null
+ # Otherwise,
else
+ # fall back to the service command
service "${1}" restart &> /dev/null
fi
- echo " done."
+ echo -e "${OVER} ${TICK} ${str}"
}
+# Enable service so that it will start with next reboot
enable_service() {
- # Enable service so that it will start with next reboot
- echo ":::"
- echo -n "::: Enabling ${1} service to start on reboot..."
+ # Local, named variables
+ local str="Enabling ${1} service to start on reboot"
+ echo ""
+ echo -ne " ${INFO} ${str}..."
+ # If systemctl exists,
if command -v systemctl &> /dev/null; then
+ # use that to enable the service
systemctl enable "${1}" &> /dev/null
+ # Othwerwise,
else
+ # use update-rc.d to accomplish this
update-rc.d "${1}" defaults &> /dev/null
fi
- echo " done."
+ echo -e "${OVER} ${TICK} ${str}"
}
update_package_cache() {
- #Running apt-get update/upgrade with minimal output can cause some issues with
- #requiring user input (e.g password for phpmyadmin see #218)
+ # Running apt-get update/upgrade with minimal output can cause some issues with
+ # requiring user input (e.g password for phpmyadmin see #218)
- #Update package cache on apt based OSes. Do this every time since
- #it's quick and packages can be updated at any time.
+ # Update package cache on apt based OSes. Do this every time since
+ # it's quick and packages can be updated at any time.
- echo ":::"
- echo -n "::: Updating local cache of available packages..."
+ # Local, named variables
+ local str="Update local cache of available packages"
+ echo ""
+ echo -ne " ${INFO} ${str}..."
+ # Create a command from the package cache variable
if eval "${UPDATE_PKG_CACHE}" &> /dev/null; then
- echo " done!"
+ echo -e "${OVER} ${TICK} ${str}"
+ # Otherwise,
else
- echo -en "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\""
+ # show an error and exit
+ echo -e "${OVER} ${CROSS} ${str}"
+ echo -ne " ${COL_LIGHT_RED}Error: Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"${COL_NC}"
return 1
fi
}
+# Let user know if they have outdated packages on their system and
+# advise them to run a package update at soonest possible.
notify_package_updates_available() {
- # Let user know if they have outdated packages on their system and
- # advise them to run a package update at soonest possible.
- echo ":::"
- echo -n "::: Checking ${PKG_MANAGER} for upgraded packages...."
+ # Local, named variables
+ local str="Checking ${PKG_MANAGER} for upgraded packages"
+ echo -ne "\\n ${INFO} ${str}..."
+ # Store the list of packages in a variable
updatesToInstall=$(eval "${PKG_COUNT}")
- echo " done!"
- echo ":::"
+
if [[ -d "/lib/modules/$(uname -r)" ]]; then
- if [[ ${updatesToInstall} -eq "0" ]]; then
- echo "::: Your system is up to date! Continuing with Pi-hole installation..."
+ #
+ if [[ "${updatesToInstall}" -eq 0 ]]; then
+ #
+ echo -e "${OVER} ${TICK} ${str}... up to date!"
+ echo ""
else
- echo "::: There are ${updatesToInstall} updates available for your system!"
- echo "::: We recommend you update your OS after installing Pi-hole! "
- echo ":::"
+ #
+ echo -e "${OVER} ${TICK} ${str}... ${updatesToInstall} updates available"
+ echo -e " ${INFO} ${COL_LIGHT_GREEN}It is recommended to update your OS after installing the Pi-hole! ${COL_NC}"
+ echo ""
fi
else
- echo "::: Kernel update detected, please reboot your system and try again if your installation fails."
+ echo -e "${OVER} ${CROSS} ${str}
+ Kernel update detected. If the install fails, please reboot and try again\\n"
fi
}
+# What's this doing outside of a function in the middle of nowhere?
+counter=0
+
install_dependent_packages() {
+ # Local, named variables should be used here, especially for an iterator
+ # Add one to the counter
+ counter=$((counter+1))
+ # If it equals 1,
+ if [[ "${counter}" == 1 ]]; then
+ #
+ echo -e " ${INFO} Installer Dependency checks..."
+ else
+ #
+ echo -e " ${INFO} Main Dependency checks..."
+ fi
+
# Install packages passed in via argument array
# No spinner - conflicts with set -e
declare -a argArray1=("${!1}")
@@ -855,155 +1234,196 @@ install_dependent_packages() {
# NOTE: We may be able to use this installArray in the future to create a list of package that were
# installed by us, and remove only the installed packages, and not the entire list.
if command -v debconf-apt-progress &> /dev/null; then
+ # For each package,
for i in "${argArray1[@]}"; do
- echo -n "::: Checking for $i..."
+ echo -ne " ${INFO} Checking for $i..."
+ #
if dpkg-query -W -f='${Status}' "${i}" 2>/dev/null | grep "ok installed" &> /dev/null; then
- echo " installed!"
+ #
+ echo -e "${OVER} ${TICK} Checking for $i"
else
- echo " added to install list!"
+ #
+ echo -e "${OVER} ${CROSS} Checking for $i (will be installed)"
+ #
installArray+=("${i}")
fi
done
- if [[ ${#installArray[@]} -gt 0 ]]; then
+ #
+ if [[ "${#installArray[@]}" -gt 0 ]]; then
+ #
test_dpkg_lock
+ #
debconf-apt-progress -- "${PKG_INSTALL[@]}" "${installArray[@]}"
return
fi
+ echo ""
+ #
return 0
fi
- #Fedora/CentOS
+ # Install Fedora/CentOS packages
for i in "${argArray1[@]}"; do
- echo -n "::: Checking for $i..."
+ echo -ne " ${INFO} Checking for $i..."
+ #
if ${PKG_MANAGER} -q list installed "${i}" &> /dev/null; then
- echo " installed!"
+ echo -e "${OVER} ${TICK} Checking for $i"
else
- echo " added to install list!"
+ echo -e "${OVER} ${CROSS} Checking for $i (will be installed)"
+ #
installArray+=("${i}")
fi
done
- if [[ ${#installArray[@]} -gt 0 ]]; then
- "${PKG_INSTALL[@]}" "${installArray[@]}" &> /dev/null
- return
- fi
- return 0
+ #
+ if [[ "${#installArray[@]}" -gt 0 ]]; then
+ #
+ "${PKG_INSTALL[@]}" "${installArray[@]}" &> /dev/null
+ return
+ fi
+ echo ""
+ return 0
}
+# Create logfiles if necessary
CreateLogFile() {
- # Create logfiles if necessary
- echo ":::"
- echo -n "::: Creating log file and changing owner to dnsmasq..."
- if [ ! -f /var/log/pihole.log ]; then
+ local str="Creating log and changing owner to dnsmasq"
+ echo ""
+ echo -ne " ${INFO} ${str}..."
+ # If the pihole log does not exist,
+ if [[ ! -f "/var/log/pihole.log" ]]; then
+ # Make it,
touch /var/log/pihole.log
+ # set the permissions,
chmod 644 /var/log/pihole.log
+ # and owners
chown "${DNSMASQ_USER}":root /var/log/pihole.log
- echo " done!"
+ echo -e "${OVER} ${TICK} ${str}"
+ # Otherwise,
else
- echo " already exists!"
+ # the file should already exist
+ echo -e " ${COL_LIGHT_GREEN}log already exists!${COL_NC}"
fi
}
+# Install the Web interface dashboard
installPiholeWeb() {
- # Install the web interface
- echo ":::"
- echo "::: Installing pihole custom index page..."
- if [ -d "/var/www/html/pihole" ]; then
- if [ -f "/var/www/html/pihole/index.php" ]; then
- echo "::: Existing index.php detected, not overwriting"
- else
- echo -n "::: index.php missing, replacing... "
- cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/
- echo " done!"
- fi
+ echo ""
+ echo " ${INFO} Installing blocking page..."
+
+ local str="Creating directory for blocking page, and copying files"
+ echo -ne " ${INFO} ${str}..."
+ # Install the directory
+ install -d /var/www/html/pihole
+ # and the blockpage
+ install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/
+
+ # Remove superseded file
+ if [[ -e "/var/www/html/pihole/index.js" ]]; then
+ rm "/var/www/html/pihole/index.js"
+ fi
- if [ -f "/var/www/html/pihole/index.js" ]; then
- echo "::: Existing index.js detected, not overwriting"
- else
- echo -n "::: index.js missing, replacing... "
- cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/
- echo " done!"
- fi
-
- if [ -f "/var/www/html/pihole/blockingpage.css" ]; then
- echo "::: Existing blockingpage.css detected, not overwriting"
- else
- echo -n "::: blockingpage.css missing, replacing... "
- cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole
- echo " done!"
- fi
+ echo -e "${OVER} ${TICK} ${str}"
+ local str="Backing up index.lighttpd.html"
+ echo -ne " ${INFO} ${str}..."
+ # If the default index file exists,
+ if [[ -f "/var/www/html/index.lighttpd.html" ]]; then
+ # back it up
+ mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
+ echo -e "${OVER} ${TICK} ${str}"
+ # Othwerwise,
else
- echo "::: Creating directory for blocking page"
- install -d /var/www/html/pihole
- install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/
- if [ -f /var/www/html/index.lighttpd.html ]; then
- mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
- else
- printf "\n:::\tNo default index.lighttpd.html file found... not backing up"
- fi
- echo " done!"
+ # don't do anything
+ echo -e "${OVER} ${CROSS} ${str}
+ No default index.lighttpd.html file found... not backing up"
fi
- # Install Sudoer file
- echo ":::"
- echo -n "::: Installing sudoer file..."
+ # Install Sudoers file
+ echo ""
+ local str="Installing sudoer file"
+ echo -ne " ${INFO} ${str}..."
+ # Make the .d directory if it doesn't exist
mkdir -p /etc/sudoers.d/
+ # and copy in the pihole sudoers file
cp ${PI_HOLE_LOCAL_REPO}/advanced/pihole.sudo /etc/sudoers.d/pihole
# Add lighttpd user (OS dependent) to sudoers file
echo "${LIGHTTPD_USER} ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
+ # If the Web server user is lighttpd,
if [[ "$LIGHTTPD_USER" == "lighttpd" ]]; then
# Allow executing pihole via sudo with Fedora
# Usually /usr/local/bin is not permitted as directory for sudoable programms
echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin" >> /etc/sudoers.d/pihole
fi
-
+ # Set the strict permissions on the file
chmod 0440 /etc/sudoers.d/pihole
- echo " done!"
+ echo -e "${OVER} ${TICK} ${str}"
}
+# Installs a cron file
installCron() {
# Install the cron job
- echo ":::"
- echo -n "::: Installing latest Cron script..."
+ local str="Installing latest Cron script"
+ echo ""
+ echo -ne " ${INFO} ${str}..."
+ # Copy the cron file over from the local repo
cp ${PI_HOLE_LOCAL_REPO}/advanced/pihole.cron /etc/cron.d/pihole
- echo " done!"
+ # Randomize gravity update time
+ sed -i "s/59 1/$((1 + RANDOM % 58)) $((3 + RANDOM % 2))/" /etc/cron.d/pihole
+ echo -e "${OVER} ${TICK} ${str}"
}
+# Gravity is a very important script as it aggregates all of the domains into a single HOSTS formatted list,
+# which is what Pi-hole needs to begin blocking ads
runGravity() {
- # Run gravity.sh to build blacklists
- echo ":::"
- echo "::: Preparing to run gravity.sh to refresh hosts..."
+ echo ""
+ echo -e " ${INFO} Preparing to run gravity.sh to refresh hosts..."
+ # If cached lists exist,
if ls /etc/pihole/list* 1> /dev/null 2>&1; then
- echo "::: Cleaning up previous install (preserving whitelist/blacklist)"
+ echo -e " ${INFO} Cleaning up previous install (preserving whitelist/blacklist)"
+ # remove them
rm /etc/pihole/list.*
fi
- # Test if /etc/pihole/adlists.default exists
+ # If the default ad lists file exists,
if [[ ! -e /etc/pihole/adlists.default ]]; then
+ # copy it over from the local repo
cp ${PI_HOLE_LOCAL_REPO}/adlists.default /etc/pihole/adlists.default
fi
- echo "::: Running gravity.sh"
+ echo -e " ${INFO} Running gravity.sh"
+ # Run gravity in the current shell
{ /opt/pihole/gravity.sh; }
}
+# Check if the pihole user exists and create if it does not
create_pihole_user() {
- # Check if user pihole exists and create if not
- echo "::: Checking if user 'pihole' exists..."
+ local str="Checking for user 'pihole'"
+ echo -ne " ${INFO} ${str}..."
+ # If the user pihole exists,
if id -u pihole &> /dev/null; then
- echo "::: User 'pihole' already exists"
+ # just show a success
+ echo -ne "${OVER} ${TICK} ${str}"
+ # Othwerwise,
else
- echo "::: User 'pihole' doesn't exist. Creating..."
+ echo -ne "${OVER} ${CROSS} ${str}"
+ local str="Creating user 'pihole'"
+ echo -ne " ${INFO} ${str}..."
+ # create her with the useradd command
useradd -r -s /usr/sbin/nologin pihole
+ echo -ne "${OVER} ${TICK} ${str}"
fi
}
+# Allow HTTP and DNS traffic
configureFirewall() {
- # Allow HTTP and DNS traffic
+ echo ""
+ # If a firewall is running,
if firewall-cmd --state &> /dev/null; then
- 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 ":::\n::: Not installing firewall rulesets."; return 0; }
- echo -e ":::\n:::\n Configuring FirewallD for httpd and dnsmasq."
+ # 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} || \
+ { echo -e " ${INFO} Not installing firewall rulesets."; return 0; }
+ echo -e " ${TICK} Configuring FirewallD for httpd and dnsmasq"
+ # Allow HTTP and DNS traffice
firewall-cmd --permanent --add-service=http --add-service=dns
+ # Reload the firewall to apply these changes
firewall-cmd --reload
return 0
# Check for proper kernel modules to prevent failure
@@ -1011,9 +1431,9 @@ configureFirewall() {
# If chain Policy is not ACCEPT or last Rule is not ACCEPT
# then check and insert our Rules above the DROP/REJECT Rule.
if iptables -S INPUT | head -n1 | grep -qv '^-P.*ACCEPT$' || iptables -S INPUT | tail -n1 | grep -qv '^-\(A\|P\).*ACCEPT$'; then
- 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 ":::\n::: Not installing firewall rulesets."; return 0; }
- echo -e ":::\n::: Installing new IPTables firewall rulesets."
+ 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"
# Check chain first, otherwise a new rule will duplicate old ones
iptables -C INPUT -p tcp -m tcp --dport 80 -j ACCEPT &> /dev/null || iptables -I INPUT 1 -p tcp -m tcp --dport 80 -j ACCEPT
iptables -C INPUT -p tcp -m tcp --dport 53 -j ACCEPT &> /dev/null || iptables -I INPUT 1 -p tcp -m tcp --dport 53 -j ACCEPT
@@ -1021,29 +1441,37 @@ configureFirewall() {
iptables -C INPUT -p tcp -m tcp --dport 4711:4720 -i lo -j ACCEPT &> /dev/null || iptables -I INPUT 1 -p tcp -m tcp --dport 4711:4720 -i lo -j ACCEPT
return 0
fi
+ # Othwerwise,
else
- echo -e ":::\n::: No active firewall detected.. skipping firewall configuration."
+ # no firewall is running
+ echo -e " ${INFO} No active firewall detected.. skipping firewall configuration"
+ # so just exit
return 0
fi
- echo -e ":::\n::: Skipping firewall configuration."
+ echo -e " ${INFO} Skipping firewall configuration"
}
+#
finalExports() {
-
- if [[ ${INSTALL_WEB} == false ]]; then
- #No web interface installed, and therefore no block page set IPV4/6 to 0.0.0.0 and ::/0
- if [ ${IPV4_ADDRESS} ]; then
+ # If the Web interface is not set to be installed,
+ if [[ "${INSTALL_WEB}" == false ]]; then
+ # and if there is not an IPv4 address,
+ 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
- # Update variables in setupVars.conf file
- 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;' "${setupVars}"
+ # If the setup variable file exists,
+ 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;/LIGHTTPD_ENABLED/d;' "${setupVars}"
fi
+ # echo the information to the user
{
echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}"
echo "IPV4_ADDRESS=${IPV4_ADDRESS}"
@@ -1052,25 +1480,27 @@ finalExports() {
echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}"
echo "QUERY_LOGGING=${QUERY_LOGGING}"
echo "INSTALL_WEB=${INSTALL_WEB}"
+ echo "LIGHTTPD_ENABLED=${LIGHTTPD_ENABLED}"
}>> "${setupVars}"
- # Look for DNS server settings which would have to be reapplied
+ # Bring in the current settings and the functions to manipulate them
source "${setupVars}"
source "${PI_HOLE_LOCAL_REPO}/advanced/Scripts/webpage.sh"
- if [[ "${DNS_FQDN_REQUIRED}" != "" ]] ; then
- ProcessDNSSettings
- fi
+ # Look for DNS server settings which would have to be reapplied
+ ProcessDNSSettings
- if [[ "${DHCP_ACTIVE}" != "" ]] ; then
- ProcessDHCPSettings
- fi
+ # Look for DHCP server settings which would have to be reapplied
+ ProcessDHCPSettings
}
+# Install the logrotate script
installLogrotate() {
- # Install the logrotate script
- echo ":::"
- echo -n "::: Installing latest logrotate script..."
+
+ local str="Installing latest logrotate script"
+ echo ""
+ echo -ne " ${INFO} ${str}..."
+ # Copy the file over from the local repo
cp ${PI_HOLE_LOCAL_REPO}/advanced/logrotate /etc/pihole/logrotate
# Different operating systems have different user / group
# settings for logrotate that makes it impossible to create
@@ -1079,48 +1509,67 @@ installLogrotate() {
# customize the logrotate script here in order to reflect
# the local properties of the /var/log directory
logusergroup="$(stat -c '%U %G' /var/log)"
- if [[ ! -z $logusergroup ]]; then
+ # If the variable has a value,
+ if [[ ! -z "${logusergroup}" ]]; then
+ #
sed -i "s/# su #/su ${logusergroup}/g;" /etc/pihole/logrotate
fi
- echo " done!"
+ echo -e "${OVER} ${TICK} ${str}"
}
+# Install base files and web interface
installPihole() {
- # Install base files and web interface
+ # Create the pihole user
create_pihole_user
- if [[ ${INSTALL_WEB} == true ]]; then
- if [ ! -d "/var/www/html" ]; then
+ # If the user wants to install the Web interface,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ if [[ ! -d "/var/www/html" ]]; then
+ # make the Web directory if necessary
mkdir -p /var/www/html
fi
+ # Set the owner and permissions
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html
chmod 775 /var/www/html
+ # Give pihole access to the Web server group
usermod -a -G ${LIGHTTPD_GROUP} pihole
- if [ -x "$(command -v lighty-enable-mod)" ]; then
+ # If the lighttpd command is executable,
+ if [[ -x "$(command -v lighty-enable-mod)" ]]; then
+ # enable fastcgi and fastcgi-php
lighty-enable-mod fastcgi fastcgi-php > /dev/null || true
else
- printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n"
+ # Othweise, show info about installing them
+ echo -e " ${INFO} Warning: 'lighty-enable-mod' utility not found
+ Please ensure fastcgi is enabled if you experience issues\\n"
fi
fi
+ # Install scripts,
installScripts
+ # configs,
installConfigs
+ # and create the log file
CreateLogFile
- if [[ ${INSTALL_WEB} == true ]]; then
+ # If the user wants to install the dashboard,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # do so
installPiholeWeb
fi
+ # Install the cron file
installCron
+ # Install the logrotate file
installLogrotate
- FTLdetect || echo "::: FTL Engine not installed."
+ # Check if FTL is installed
+ FTLdetect || echo -e " ${CROSS} FTL Engine not installed"
+ # Configure the firewall
configureFirewall
+
+ #update setupvars.conf with any variables that may or may not have been changed during the install
finalExports
- #runGravity
}
+# At some point in the future this list can be pruned, for now we'll need it to ensure updates don't break.
+# Refactoring of install script has changed the name of a couple of variables. Sort them out here.
accountForRefactor() {
- # At some point in the future this list can be pruned, for now we'll need it to ensure updates don't break.
-
- # Refactoring of install script has changed the name of a couple of variables. Sort them out here.
-
sed -i 's/piholeInterface/PIHOLE_INTERFACE/g' ${setupVars}
sed -i 's/IPv4_address/IPV4_ADDRESS/g' ${setupVars}
sed -i 's/IPv4addr/IPV4_ADDRESS/g' ${setupVars}
@@ -1128,54 +1577,69 @@ accountForRefactor() {
sed -i 's/piholeIPv6/IPV6_ADDRESS/g' ${setupVars}
sed -i 's/piholeDNS1/PIHOLE_DNS_1/g' ${setupVars}
sed -i 's/piholeDNS2/PIHOLE_DNS_2/g' ${setupVars}
-
}
updatePihole() {
accountForRefactor
# Install base files and web interface
installScripts
+ # Install config files
installConfigs
+ # Create the log file
CreateLogFile
- if [[ ${INSTALL_WEB} == true ]]; then
+ # If the user wants to install the dasboard,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # do so
installPiholeWeb
fi
+ # Install the cron file
installCron
+ # Install logrotate
installLogrotate
- FTLdetect || echo "::: FTL Engine not installed."
- finalExports #re-export setupVars.conf to account for any new vars added in new versions
- #runGravity
-}
+ # Detect if FTL is installed
+ FTLdetect || echo -e " ${CROSS} FTL Engine not installed."
+ #update setupvars.conf with any variables that may or may not have been changed during the install
+ finalExports
+
+}
+# SELinux
checkSelinux() {
+ # If the getenforce command exists,
if command -v getenforce &> /dev/null; then
- echo ":::"
- echo -n "::: SELinux Support Detected... Mode: "
+ # Store the current mode in a variable
enforceMode=$(getenforce)
- echo "${enforceMode}"
+ echo -e "\\n ${INFO} SELinux mode detected: ${enforceMode}"
+
+ # If it's enforcing,
if [[ "${enforceMode}" == "Enforcing" ]]; then
- 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 ":::"; echo "::: Not continuing install after SELinux Enforcing detected."; exit 1; }
- echo ":::"
- echo "::: Continuing installation with SELinux Enforcing."
- echo "::: Please refer to official SELinux documentation to create a custom policy."
+ # Explain Pi-hole does not support it yet
+ 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} || \
+ { echo -e "\\n ${COL_LIGHT_RED}SELinux Enforcing detected, exiting installer${COL_NC}"; exit 1; }
+ echo -e " ${INFO} Continuing installation with SELinux Enforcing
+ ${INFO} Please refer to official SELinux documentation to create a custom policy"
fi
fi
}
+# Installation complete message with instructions for the user
displayFinalMessage() {
-
- if [[ ${#1} -gt 0 ]] ; then
+ # If
+ if [[ "${#1}" -gt 0 ]] ; then
pwstring="$1"
+ # else, if the dashboard password in the setup variables exists,
elif [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) -gt 0 ]]; then
+ # set a variable for evaluation later
pwstring="unchanged"
else
+ # set a variable for evaluation later
pwstring="NOT SET"
fi
-
- if [[ ${INSTALL_WEB} == true ]]; then
+ # If the user wants to install the dashboard,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # Store a message in a variable and display it
additional="View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin
Your Admin Webpage login password is ${pwstring}"
@@ -1195,12 +1659,15 @@ ${additional}" ${r} ${c}
}
update_dialogs() {
- # reconfigure
- if [ "${reconfigure}" = true ]; then
+ # If pihole -r "reconfigure" option was selected,
+ if [[ "${reconfigure}" = true ]]; then
+ # set some variables that will be used
opt1a="Repair"
opt1b="This will retain existing settings"
strAdd="You will remain on the same version"
+ # Othweise,
else
+ # set some variables with different values
opt1a="Update"
opt1b="This will retain existing settings."
strAdd="You will be updated to the latest version."
@@ -1208,161 +1675,257 @@ update_dialogs() {
opt2a="Reconfigure"
opt2b="This will allow you to enter new settings"
- 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 \
+ # 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 \
"${opt1a}" "${opt1b}" \
"${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3) || \
- { echo "::: Cancel selected. Exiting"; exit 1; }
+ { echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; }
+ # Set the variable based on if the user chooses
case ${UpdateCmd} in
+ # repair, or
${opt1a})
- echo "::: ${opt1a} option selected."
+ echo -e " ${INFO} ${opt1a} option selected"
useUpdateVars=true
;;
+ # reconfigure,
${opt2a})
- echo "::: ${opt2a} option selected"
+ echo -e " ${INFO} ${opt2a} option selected"
useUpdateVars=false
;;
esac
}
clone_or_update_repos() {
+ # If the user wants to reconfigure,
if [[ "${reconfigure}" == true ]]; then
- echo "::: --reconfigure passed to install script. Resetting changes to local repos"
+ echo " ${INFO} Performing reconfiguration, skipping download of local repos"
+ # Reset the Core repo
resetRepo ${PI_HOLE_LOCAL_REPO} || \
- { echo "!!! Unable to reset ${PI_HOLE_LOCAL_REPO}, unable to continue."; \
+ { echo -e " ${COL_LIGHT_RED}Unable to reset ${PI_HOLE_LOCAL_REPO}, exiting installer${COL_NC}"; \
exit 1; \
}
- if [[ ${INSTALL_WEB} == true ]]; then
+ # If the Web interface was installed,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # reset it's repo
resetRepo ${webInterfaceDir} || \
- { echo "!!! Unable to reset ${webInterfaceDir}, unable to continue."; \
+ { echo -e " ${COL_LIGHT_RED}Unable to reset ${webInterfaceDir}, exiting installer${COL_NC}"; \
exit 1; \
}
fi
+ # Otherwise, a repair is happening
else
- # Get Git files for Core and Admin
+ # so get git files for Core
getGitFiles ${PI_HOLE_LOCAL_REPO} ${piholeGitUrl} || \
- { echo "!!! Unable to clone ${piholeGitUrl} into ${PI_HOLE_LOCAL_REPO}, unable to continue."; \
- exit 1; \
- }
-
- if [[ ${INSTALL_WEB} == true ]]; then
- getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} || \
- { echo "!!! Unable to clone ${webInterfaceGitUrl} into ${webInterfaceDir}, unable to continue."; \
+ { echo -e " ${COL_LIGHT_RED}Unable to clone ${piholeGitUrl} into ${PI_HOLE_LOCAL_REPO}, unable to continue${COL_NC}"; \
exit 1; \
}
- fi
+ # If the Web interface was installed,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # get the Web git files
+ getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} || \
+ { echo -e " ${COL_LIGHT_RED}Unable to clone ${webInterfaceGitUrl} into ${webInterfaceDir}, exiting installer${COL_NC}"; \
+ exit 1; \
+ }
+ fi
fi
}
+# Download and install FTL binary
FTLinstall() {
- # Download and install FTL binary
+ # Local, named variables
local binary="${1}"
local latesttag
local orig_dir
- echo -n "::: Installing FTL... "
+ local str="Downloading and Installing FTL"
+ echo -ne " ${INFO} ${str}..."
+ # Get the current working directory
orig_dir="${PWD}"
+ # Find the latest version tag for FTL
latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}')
# Tags should always start with v, check for that.
if [[ ! "${latesttag}" == v* ]]; then
- echo "failed (error in getting latest release location from GitHub)"
+ echo -e "${OVER} ${CROSS} ${str}"
+ echo -e " ${COL_LIGHT_RED}Error: Unable to get latest release location from GitHub${COL_NC}"
return 1
fi
+
+ # If the download worked,
if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}" -o "/tmp/${binary}"; then
- # Get sha1 of the binary we just downloaded for verification.
+ # get sha1 of the binary we just downloaded for verification.
curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}.sha1" -o "/tmp/${binary}.sha1"
- # Check if we just downloaded text, or a binary file.
+
+ # Move into the temp directory
cd /tmp
+ # If we downloaded binary file (as opposed to text),
if sha1sum --status --quiet -c "${binary}".sha1; then
echo -n "transferred... "
+ # Stop FTL
stop_service pihole-FTL &> /dev/null
+ # Install the new version with the correct permissions
install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL
+ # Remove the tempoary file
rm /tmp/${binary} /tmp/${binary}.sha1
+ # Move back into the original directory the user was in
cd "${orig_dir}"
+ # Install the FTL service
install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL"
- echo "done."
+ echo -e "${OVER} ${TICK} ${str}"
return 0
+ # Otherise,
else
- echo "failed (download of binary from Github failed)"
+ echo -e "${OVER} ${CROSS} ${str}"
+ echo -e " ${COL_LIGHT_RED}Error: Download of binary from Github failed${COL_NC}"
+ # the download failed, so just go back to the original directory
cd "${orig_dir}"
return 1
fi
+ # Otherwise,
else
cd "${orig_dir}"
- echo "failed (URL not found.)"
+ echo -e "${OVER} ${CROSS} ${str}"
+ # The URL could not be found
+ echo -e " ${COL_LIGHT_RED}Error: URL not found${COL_NC}"
fi
}
+# Detect suitable FTL binary platform
FTLdetect() {
- # Detect suitable FTL binary platform
- echo ":::"
- echo "::: Downloading latest version of FTL..."
+ echo ""
+ echo -e " ${INFO} FTL Checks..."
+ # Local, named variables
local machine
local binary
+ # Store architecture in a variable
machine=$(uname -m)
- if [[ $machine == arm* || $machine == *aarch* ]]; then
+ local str="Detecting architecture"
+ echo -ne " ${INFO} ${str}..."
+ # If the machine is arm or aarch
+ if [[ "${machine}" == "arm"* || "${machine}" == *"aarch"* ]]; then
# ARM
- local rev=$(uname -m | sed "s/[^0-9]//g;")
- local lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }')
- if [[ "$lib" == "/lib/ld-linux-aarch64.so.1" ]]; then
- echo "::: Detected ARM-aarch64 architecture"
+ #
+ local rev
+ rev=$(uname -m | sed "s/[^0-9]//g;")
+ #
+ local lib
+ lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }')
+ #
+ if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then
+ echo -e "${OVER} ${TICK} Detected ARM-aarch64 architecture"
+ # set the binary to be used
binary="pihole-FTL-aarch64-linux-gnu"
- elif [[ "$lib" == "/lib/ld-linux-armhf.so.3" ]]; then
- if [ "$rev" -gt "6" ]; then
- echo "::: Detected ARM-hf architecture (armv7+)"
+ #
+ elif [[ "${lib}" == "/lib/ld-linux-armhf.so.3" ]]; then
+ #
+ if [[ "${rev}" -gt 6 ]]; then
+ echo -e "${OVER} ${TICK} Detected ARM-hf architecture (armv7+)"
+ # set the binary to be used
binary="pihole-FTL-arm-linux-gnueabihf"
+ # Otherwise,
else
- echo "::: Detected ARM-hf architecture (armv6 or lower)"
- echo "::: Using ARM binary"
+ echo -e "${OVER} ${TICK} Detected ARM-hf architecture (armv6 or lower) Using ARM binary"
+ # set the binary to be used
binary="pihole-FTL-arm-linux-gnueabi"
fi
else
- echo "::: Detected ARM architecture"
+ echo -e "${OVER} ${TICK} Detected ARM architecture"
+ # set the binary to be used
binary="pihole-FTL-arm-linux-gnueabi"
fi
- elif [[ $machine == x86_64 ]]; then
+ elif [[ "${machine}" == "ppc" ]]; then
+ # PowerPC
+ echo -e "${OVER} ${TICK} Detected PowerPC architecture"
+ # set the binary to be used
+ binary="pihole-FTL-powerpc-linux-gnu"
+ elif [[ "${machine}" == "x86_64" ]]; then
# 64bit
- echo "::: Detected x86_64 architecture"
+ echo -e "${OVER} ${TICK} Detected x86_64 architecture"
+ # set the binary to be used
binary="pihole-FTL-linux-x86_64"
else
# Something else - we try to use 32bit executable and warn the user
- if [[ ! $machine == i686 ]]; then
- echo "::: Not able to detect architecture (unknown: ${machine}), trying 32bit executable"
- echo "::: Contact Pi-hole support if you experience problems (like FTL not running)"
+ if [[ ! "${machine}" == "i686" ]]; then
+ echo -e "${OVER} ${CROSS} ${str}...
+ ${COL_LIGHT_RED}Not able to detect architecture (unknown: ${machine}), trying 32bit executable${COL_NC}
+ Contact Pi-hole Support if you experience issues (e.g: FTL not running)"
else
- echo "::: Detected 32bit (i686) architecture"
+ echo -e "${OVER} ${TICK} Detected 32bit (i686) architecture"
fi
binary="pihole-FTL-linux-x86_32"
fi
- FTLinstall "${binary}" || return 1
+ #In the next section we check to see if FTL is already installed (in case of pihole -r).
+ #If the installed version matches the latest version, then check the installed sha1sum of the binary vs the remote sha1sum. If they do not match, then download
+ echo -e " ${INFO} Checking for existing FTL binary..."
+
+ local ftlLoc=$(which pihole-FTL 2>/dev/null)
+
+ if [[ ${ftlLoc} ]]; then
+ local FTLversion=$(/usr/bin/pihole-FTL tag)
+ local FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n')
+
+ if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then
+ # Install FTL
+ FTLinstall "${binary}" || return 1
+ else
+ echo -e " ${INFO} Latest FTL Binary already installed (${FTLlatesttag}). Confirming Checksum..."
+
+ local remoteSha1=$(curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${FTLversion%$'\r'}/${binary}.sha1" | cut -d ' ' -f 1)
+ local localSha1=$(sha1sum "$(which pihole-FTL)" | cut -d ' ' -f 1)
+
+ if [[ "${remoteSha1}" != "${localSha1}" ]]; then
+ echo -e " ${INFO} Corruption detected..."
+ FTLinstall "${binary}" || return 1
+ else
+ echo -e " ${INFO} Checksum correct. No need to download!"
+ fi
+ fi
+ else
+ # Install FTL
+ FTLinstall "${binary}" || return 1
+ fi
+
}
main() {
-
######## FIRST CHECK ########
- # Must be root to install
+ # Show the Pi-hole logo so people know it's genuine since the logo and name are trademarked
show_ascii_berry
- echo ":::"
- if [[ ${EUID} -eq 0 ]]; then
- echo "::: You are root."
+ # Must be root to install
+ local str="Root user check"
+ echo ""
+
+ # If the user's id is zero,
+ if [[ "${EUID}" -eq 0 ]]; then
+ # they are root and all is good
+ echo -e " ${TICK} ${str}"
+ # Otherwise,
else
- echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures"
- echo "::: system networking, it requires elevated rights. Please check the contents of the script for"
- echo "::: any concerns with this requirement. Please be sure to download this script from a trusted source."
- echo ":::"
- echo "::: Detecting the presence of the sudo utility for continuation of this install..."
-
+ # They do not have enough privileges, so let the user know
+ echo -e " ${CROSS} ${str}
+ ${COL_LIGHT_RED}Script called with non-root privileges${COL_NC}
+ The Pi-hole requires elevated privleges to install and run
+ Please check the installer for any concerns regarding this requirement
+ Make sure to download this script from a trusted source\\n"
+ echo -ne " ${INFO} Sudo utility check"
+
+ # If the sudo command exists,
if command -v sudo &> /dev/null; then
- echo "::: Utility sudo located."
+ echo -e "${OVER} ${TICK} Sudo utility check"
+ # Download the install script and run it with admin rights
exec curl -sSL https://raw.githubusercontent.com/pi-hole/pi-hole/master/automated%20install/basic-install.sh | sudo bash "$@"
exit $?
+ # Otherwise,
else
- echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed."
+ # Let them know they need to run it as root
+ echo -e "${OVER} ${CROSS} Sudo utility check
+ Sudo is needed for the Web Interface to run pihole commands\\n
+ ${COL_LIGHT_RED}Please re-run this installer as root${COL_NC}"
exit 1
fi
fi
@@ -1373,17 +1936,22 @@ main() {
# Check arguments for the undocumented flags
for var in "$@"; do
case "$var" in
- "--reconfigure" ) reconfigure=true;;
- "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;;
- "--unattended" ) runUnattended=true;;
+ "--reconfigure" ) reconfigure=true;;
+ "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;;
+ "--unattended" ) runUnattended=true;;
esac
done
- if [[ -f ${setupVars} ]]; then
+ # If the setup variable file exists,
+ if [[ -f "${setupVars}" ]]; then
+ # if it's running unattended,
if [[ "${runUnattended}" == true ]]; then
- echo "::: --unattended passed to install script, no whiptail dialogs will be displayed"
+ echo -e " ${INFO} Performing unattended setup, no whiptail dialogs will be displayed"
+ # Use the setup variables
useUpdateVars=true
+ # Otherwise,
else
+ # show the available options (repair/reconfigure)
update_dialogs
fi
fi
@@ -1391,7 +1959,7 @@ main() {
# Start the installer
# Verify there is enough disk space for the install
if [[ "${skipSpaceCheck}" == true ]]; then
- echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!"
+ echo -e " ${INFO} Skipping free disk space verification"
else
verifyFreeDiskSpace
fi
@@ -1408,15 +1976,14 @@ main() {
# Check if SELinux is Enforcing
checkSelinux
-
- if [[ ${useUpdateVars} == false ]]; then
+ if [[ "${useUpdateVars}" == false ]]; then
# Display welcome dialogs
welcomeDialogs
# Create directory for Pi-hole storage
mkdir -p /etc/pihole/
stop_service dnsmasq
- if [[ ${INSTALL_WEB} == true ]]; then
+ if [[ "${INSTALL_WEB}" == true ]]; then
stop_service lighttpd
fi
# Determine available interfaces
@@ -1434,14 +2001,31 @@ main() {
# Clone/Update the repos
clone_or_update_repos
- # Install packages used by the Pi-hole
- if [[ ${INSTALL_WEB} == true ]]; then
+ # Install packages used by the Pi-hole
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # Install the Web dependencies
DEPS=("${PIHOLE_DEPS[@]}" "${PIHOLE_WEB_DEPS[@]}")
+ # Otherwise,
else
+ # just install the Core dependencies
DEPS=("${PIHOLE_DEPS[@]}")
fi
+
install_dependent_packages DEPS[@]
+ # On some systems, lighttpd is not enabled on first install. We need to enable it here if the user
+ # has chosen to install the web interface, else the `LIGHTTPD_ENABLED` check will fail
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ enable_service lighttpd
+ fi
+
+ if [[ -x "$(command -v systemctl)" ]]; then
+ # Value will either be 1, if true, or 0
+ LIGHTTPD_ENABLED=$(systemctl is-enabled lighttpd | grep -c 'enabled' || true)
+ else
+ # Value will either be 1, if true, or 0
+ LIGHTTPD_ENABLED=$(service lighttpd status | awk '/Loaded:/ {print $0}' | grep -c 'enabled' || true)
+ fi
# Install and log everything to a file
installPihole | tee ${tmpLog}
@@ -1449,84 +2033,114 @@ main() {
# Clone/Update the repos
clone_or_update_repos
- # Source ${setupVars} for use in the rest of the functions.
+ # Source ${setupVars} for use in the rest of the functions
source ${setupVars}
# Install packages used by the Pi-hole
- if [[ ${INSTALL_WEB} == true ]]; then
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # Install the Web dependencies
DEPS=("${PIHOLE_DEPS[@]}" "${PIHOLE_WEB_DEPS[@]}")
+ # Otherwise,
else
+ # just install the Core dependencies
DEPS=("${PIHOLE_DEPS[@]}")
fi
install_dependent_packages DEPS[@]
+ if [[ -x "$(command -v systemctl)" ]]; then
+ # Value will either be 1, if true, or 0
+ LIGHTTPD_ENABLED=$(systemctl is-enabled lighttpd | grep -c 'enabled' || true)
+ else
+ # Value will either be 1, if true, or 0
+ LIGHTTPD_ENABLED=$(service lighttpd status | awk '/Loaded:/ {print $0}' | grep -c 'enabled' || true)
+ fi
+
updatePihole | tee ${tmpLog}
fi
# Move the log file into /etc/pihole for storage
mv ${tmpLog} ${instalLogLoc}
- if [[ ${INSTALL_WEB} == true ]]; then
+ if [[ "${INSTALL_WEB}" == true ]]; then
# Add password to web UI if there is none
pw=""
+ # If no password is set,
if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then
+ # generate a random password
pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
+ # shellcheck disable=SC1091
. /opt/pihole/webpage.sh
echo "WEBPASSWORD=$(HashPassword ${pw})" >> ${setupVars}
fi
fi
- echo "::: Restarting services..."
+ echo -e " ${INFO} Restarting services..."
# Start services
start_service dnsmasq
enable_service dnsmasq
- if [[ ${INSTALL_WEB} == true ]]; then
- start_service lighttpd
- enable_service lighttpd
- fi
+ # If the Web server was installed,
+ if [[ "${INSTALL_WEB}" == true ]]; then
- runGravity
+ if [[ "${LIGHTTPD_ENABLED}" == "1" ]]; then
+ start_service lighttpd
+ enable_service lighttpd
+ else
+ echo -e " ${INFO} Lighttpd is disabled, skipping service restart"
+ fi
+ fi
+ # Enable FTL
start_service pihole-FTL
enable_service pihole-FTL
- echo "::: done."
+ # Download and compile the aggregated block list
+ runGravity
+ # Force an update of the updatechecker
+ . /opt/pihole/updatecheck.sh
+
+ #
if [[ "${useUpdateVars}" == false ]]; then
displayFinalMessage "${pw}"
fi
- echo ":::"
- if [[ "${useUpdateVars}" == false ]]; then
- echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
- echo "::: ${IPV4_ADDRESS%/*}"
- echo "::: ${IPV6_ADDRESS}"
- echo ":::"
- echo "::: If you set a new IP address, you should restart the Pi."
- if [[ ${INSTALL_WEB} == true ]]; then
- echo "::: View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin"
+ # If the Web interface was installed,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ # If there is a password,
+ if (( ${#pw} > 0 )) ; then
+ # display the password
+ echo -e " ${INFO} Web Interface password: ${COL_LIGHT_GREEN}${pw}${COL_NC}
+ This can be changed using 'pihole -a -p'\\n"
fi
- else
- echo "::: Update complete!"
fi
- if [[ ${INSTALL_WEB} == true ]]; then
- if (( ${#pw} > 0 )) ; then
- echo ":::"
- echo "::: Note: As security measure a password has been installed for your web interface"
- echo "::: The currently set password is"
- echo "::: ${pw}"
- echo ":::"
- echo "::: You can always change it using"
- echo "::: pihole -a -p"
+
+ #
+ if [[ "${useUpdateVars}" == false ]]; then
+ # If the Web interface was installed,
+ if [[ "${INSTALL_WEB}" == true ]]; then
+ echo -e " View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin"
+ echo ""
fi
+ # Explain to the user how to use Pi-hole as their DNS server
+ echo " You may now configure your devices to use the Pi-hole as their DNS server"
+ [[ -n "${IPV4_ADDRESS%/*}" ]] && echo -e " ${INFO} Pi-hole DNS (IPv4): ${IPV4_ADDRESS%/*}"
+ [[ -n "${IPV6_ADDRESS}" ]] && echo -e " ${INFO} Pi-hole DNS (IPv6): ${IPV6_ADDRESS}"
+ echo -e " If you set a new IP address, please restart the server running the Pi-hole"
+ #
+ INSTALL_TYPE="Installation"
+ else
+ #
+ INSTALL_TYPE="Update"
fi
- echo ":::"
- echo "::: The install log is located at: /etc/pihole/install.log
- "
+ # Display where the log file is
+ echo -e "\\n ${INFO} The install log is located at: /etc/pihole/install.log
+ ${COL_LIGHT_GREEN}${INSTALL_TYPE} Complete! ${COL_NC}"
+
}
+#
if [[ "${PH_TEST}" != true ]] ; then
main "$@"
fi