From 9b6427144fcc65db87b612e3d04f10d5256d575a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 14 Jan 2017 17:01:47 -0800 Subject: [PATCH 01/15] || && conversion. Fedora deps array. Use full name of `source` Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 80943739..4cad2d63 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -86,7 +86,7 @@ elif command -v rpm &> /dev/null; then # 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_INSTALL=(${PKG_MANAGER} install -y) PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" INSTALLER_DEPS=(git iproute net-tools newt procps-ng) PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) @@ -239,7 +239,7 @@ chooseInterface() { # Loop sentinel variable local firstLoop=1 - if [[ $(echo "${availableInterfaces}" | wc -l) -eq 1 ]]; then + if [[ "${#availableInterfaces[@]}" -eq 1 ]]; then PIHOLE_INTERFACE="${availableInterfaces}" return fi @@ -756,7 +756,7 @@ install_dependent_packages() { fi done if [[ ${#installArray[@]} -gt 0 ]]; then - ${PKG_INSTALL} "${installArray[@]}" &> /dev/null + "${PKG_INSTALL[@]}" "${installArray[@]}" &> /dev/null return fi return 0 @@ -860,7 +860,12 @@ runGravity() { create_pihole_user() { # Check if user pihole exists and create if not echo "::: Checking if user 'pihole' exists..." - id -u pihole &> /dev/null && echo "::: User 'pihole' already exists" || (echo "::: User 'pihole' doesn't exist. Creating..." && useradd -r -s /usr/sbin/nologin pihole) + if id -u pihole &> /dev/null; then + echo "::: User 'pihole' already exists" + else + echo "::: User 'pihole' doesn't exist. Creating..." + useradd -r -s /usr/sbin/nologin pihole + fi } configureFirewall() { @@ -954,7 +959,7 @@ accountForRefactor() { updatePihole() { accountForRefactor # Source ${setupVars} for use in the rest of the functions. - . ${setupVars} + source ${setupVars} # Install base files and web interface installScripts installConfigs From 2689b37c35fd24147681c44fd314b20faacee135 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 14 Jan 2017 18:23:52 -0800 Subject: [PATCH 02/15] Combine multiple calls to interface length code. && || Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 55 +++++++++++++++++------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4cad2d63..7e6572b0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -65,12 +65,20 @@ if command -v apt-get &> /dev/null; then # ######################################### # fixes for dependancy differences # Debian 7 doesn't have iproute2 use iproute - ${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1 && IPROUTE_PKG="iproute2" || IPROUTE_PKG="iproute" + if ${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1; then + iproute_pkg="iproute2" + else + iproute_pkg="iproute" + fi # Prefer the php metapackage if it's there, fall back on the php5 pacakges - ${PKG_MANAGER} install --dry-run php > /dev/null 2>&1 && phpVer="php" || phpVer="php5" + if ${PKG_MANAGER} install --dry-run php > /dev/null 2>&1; then + phpVer="php" + else + phpVer="php5" + fi # ######################################### INSTALLER_DEPS=(apt-utils debconf dhcpcd5 git whiptail) - PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils ${IPROUTE_PKG} iputils-ping lighttpd lsof netcat ${phpVer}-common ${phpVer}-cgi sudo unzip wget) + PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils ${iproute_pkg} iputils-ping lighttpd lsof netcat ${phpVer}-common ${phpVer}-cgi sudo unzip wget) LIGHTTPD_USER="www-data" LIGHTTPD_GROUP="www-data" LIGHTTPD_CFG="lighttpd.conf.debian" @@ -239,30 +247,29 @@ chooseInterface() { # Loop sentinel variable local firstLoop=1 - if [[ "${#availableInterfaces[@]}" -eq 1 ]]; then - PIHOLE_INTERFACE="${availableInterfaces}" - return - fi - - while read -r line; do - mode="OFF" - if [[ ${firstLoop} -eq 1 ]]; then - firstLoop=0 - mode="ON" - fi - interfacesArray+=("${line}" "available" "${mode}") - done <<< "${availableInterfaces}" - # Find out how many interfaces are available to choose from interfaceCount=$(echo "${availableInterfaces}" | wc -l) - chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount}) - chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) || \ - { echo "::: Cancel selected. Exiting"; exit 1; } - for desiredInterface in ${chooseInterfaceOptions}; do - PIHOLE_INTERFACE=${desiredInterface} - echo "::: Using interface: $PIHOLE_INTERFACE" - done + if [[ ${interfaceCount} -eq 1 ]]; then + PIHOLE_INTERFACE="${availableInterfaces}" + else + while read -r line; do + mode="OFF" + if [[ ${firstLoop} -eq 1 ]]; then + firstLoop=0 + mode="ON" + fi + interfacesArray+=("${line}" "available" "${mode}") + done <<< "${availableInterfaces}" + + chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount}) + chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) || \ + { echo "::: Cancel selected. Exiting"; exit 1; } + for desiredInterface in ${chooseInterfaceOptions}; do + PIHOLE_INTERFACE=${desiredInterface} + echo "::: Using interface: $PIHOLE_INTERFACE" + done + fi } useIPv6dialog() { From 34df34ba2759d4addd8f0248b243eb33e8f04e9d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 14 Jan 2017 20:16:27 -0800 Subject: [PATCH 03/15] Actually rm the Pi-hole scripts. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7e6572b0..09c58014 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -27,7 +27,7 @@ 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" -PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update version) +PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update version gravity uninstall webpage) PI_HOLE_INSTALL_DIR="/opt/pihole" useUpdateVars=false @@ -600,10 +600,11 @@ clean_existing() { # Clean an exiting installation to prepare for upgrade/reinstall # ${1} Directory to clean; ${2} Array of files to remove local clean_directory="${1}" - local old_files=${2} + shift + local old_files=( "$@" ) for script in "${old_files[@]}"; do - rm -f "${clean_directory}${script}.sh" + rm -f "${clean_directory}/${script}.sh" done } @@ -614,7 +615,7 @@ installScripts() { echo -n "::: Installing scripts from ${PI_HOLE_LOCAL_REPO}..." # Clear out script files from Pi-hole scripts directory. - clean_existing "${PI_HOLE_INSTALL_DIR}" "${PI_HOLE_FILES}" + clean_existing "${PI_HOLE_INSTALL_DIR}" "${PI_HOLE_FILES[@]}" # Install files from local core repository if is_repo "${PI_HOLE_LOCAL_REPO}"; then From ec8c40b69b3f1066ed9da0fd08b77dfa7071a794 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 17 Jan 2017 13:00:17 -0800 Subject: [PATCH 04/15] Fix array declaration for Fedora package management. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6448aa0f..a0452c5a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -86,7 +86,7 @@ elif command -v rpm &> /dev/null; then # 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_INSTALL=(${PKG_MANAGER} install -y) PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" INSTALLER_DEPS=(git iproute net-tools newt procps-ng) PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) @@ -756,7 +756,7 @@ install_dependent_packages() { fi done if [[ ${#installArray[@]} -gt 0 ]]; then - ${PKG_INSTALL} "${installArray[@]}" &> /dev/null + "${PKG_INSTALL[@]}" "${installArray[@]}" &> /dev/null return fi return 0 From 8bb9dd460b34706c978eda12b2667fa899a0ed4a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 18 Jan 2017 12:22:03 +0100 Subject: [PATCH 05/15] Be able to disable the DHCP domain name --- advanced/Scripts/webpage.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 8e51ea7d..314361c3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -232,10 +232,13 @@ dhcp-authoritative dhcp-range=${DHCP_START},${DHCP_END},${leasetime} dhcp-option=option:router,${DHCP_ROUTER} dhcp-leasefile=/etc/pihole/dhcp.leases -domain=${PIHOLE_DOMAIN} #quiet-dhcp " > "${dhcpconfig}" +if [[ "${PIHOLE_DOMAIN}" != "none" ]]; then + echo "domain=${PIHOLE_DOMAIN}" >> "${dhcpconfig}" +fi + if [[ "${DHCP_IPv6}" == "true" ]]; then echo "#quiet-dhcp6 #enable-ra From 86052540d9d8dfd9931c654f75cce96491dfad5a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 19 Jan 2017 13:50:42 -0800 Subject: [PATCH 06/15] Add back CIDR notation for non-natural blocks. Includes multi-address configs. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6448aa0f..229cc2e4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -173,7 +173,8 @@ find_IPv4_information() { # Find IP used to route to outside world route=$(ip route get 8.8.8.8) IPv4dev=$(awk '{for (i=1; i<=NF; i++) if ($i~/dev/) print $(i+1)}' <<< "${route}") - IPV4_ADDRESS=$(awk '{print $7}' <<< "${route}") + IPv4bare=$(awk '{print $7}' <<< "${route}") + IPV4_ADDRESS=$(ip -o -f inet addr show | grep "${IPv4bare}" | awk '{print $4}' | awk 'END {print}') IPv4gw=$(awk '{print $3}' <<< "${route}") } From eddca8f127d2b133f680d6983d34c1c8d3d39da9 Mon Sep 17 00:00:00 2001 From: John Wiebalk Date: Thu, 19 Jan 2017 21:40:52 -0500 Subject: [PATCH 07/15] Correct path for automated installer basic-install.sh is in the `automated install` dir instead of `automated_installer` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9da58540..4ffef079 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ _If you wish to read over the script before running it, run `nano basic-install. ``` git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole -cd Pi-hole/automated_installer/ +cd Pi-hole/automated\ install/ bash basic-install.sh ``` From 0635309f23d4f61df9230b4018db7c2293c86d05 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 21 Jan 2017 12:34:47 -0800 Subject: [PATCH 08/15] Move distribution check to function. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ad7924a4..9a4ced19 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -53,7 +53,7 @@ reconfigure=false runUnattended=false # Compatibility - +distro_check() { if command -v apt-get &> /dev/null; then #Debian Family ############################################# @@ -103,8 +103,8 @@ else echo "OS distribution not supported" exit fi +} -####### FUNCTIONS ########## 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. @@ -1055,6 +1055,9 @@ main() { fi fi + # Check for supported distribution + distro_check + # Check arguments for the undocumented flags for var in "$@"; do case "$var" in From eaf6938c35eebf5a8dffd9b73e93f025cec94b58 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 21 Jan 2017 16:14:05 -0800 Subject: [PATCH 09/15] DNS whiptail from radio to menu --- automated install/basic-install.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9a4ced19..c9e7a3b2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -432,13 +432,13 @@ valid_ip() { setDNS() { local DNSSettingsCorrect - DNSChooseOptions=(Google "" on - OpenDNS "" off - Level3 "" off - Norton "" off - Comodo "" off - Custom "" off) - DNSchoices=$(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 6 \ + DNSChooseOptions=(Google "" + OpenDNS "" + Level3 "" + Norton "" + Comodo "" + Custom "") + DNSchoices=$(whiptail --separate-output --menu "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 6 \ "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) || \ { echo "::: Cancel selected. Exiting"; exit 1; } case ${DNSchoices} in From de102fde5c2007d9c6ca649394a62cea8b9558f7 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 22 Jan 2017 20:38:09 +0000 Subject: [PATCH 10/15] Add line count and size check for pihole.log --- advanced/Scripts/piholeDebug.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 09d9a786..c961f103 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -365,6 +365,17 @@ header_write "Analyzing gravity.list" && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ || log_echo "Warning: No gravity.list file found!" +header_write "Analyzing pihole.log" + + pihole_length=$(wc -l "${PIHOLELOG}") \ + && log_write "${PIHOLELOG} is ${pihole_length} lines long." \ + || log_echo "Warning: No pihole.log file found!" + + pihole_size=$(du -h "${PIHOLELOG}") \ + && log_write "${PIHOLELOG} is ${pihole_length}." \ + || log_echo "Warning: No pihole.log file found!" + + # Continuously append the pihole.log file to the pihole_debug.log file dumpPiHoleLog() { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT From 1ad23a065eca674b530b26542c12095045db9cbc Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 22 Jan 2017 20:38:46 +0000 Subject: [PATCH 11/15] switch out `wc -l` with `grep -c ^` --- advanced/Scripts/piholeDebug.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c961f103..fae667ce 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -361,13 +361,13 @@ files_check "${ADLISTFILE}" header_write "Analyzing gravity.list" - gravity_length=$(wc -l "${GRAVITYFILE}") \ + gravity_length=$(grep -c ^ "${GRAVITYFILE}") \ && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ || log_echo "Warning: No gravity.list file found!" header_write "Analyzing pihole.log" - pihole_length=$(wc -l "${PIHOLELOG}") \ + pihole_length=$(grep -c ^ "${PIHOLELOG}") \ && log_write "${PIHOLELOG} is ${pihole_length} lines long." \ || log_echo "Warning: No pihole.log file found!" From 9acc3aac0176d38dc3b8a265c43a21dd7e0ebc2f Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 22 Jan 2017 20:44:07 +0000 Subject: [PATCH 12/15] pipe `du -h` output to awk to ensure we only get the file size, and not the filename too. Yeah that's right Dom, pipe. --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index fae667ce..08f69943 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -371,7 +371,7 @@ header_write "Analyzing pihole.log" && log_write "${PIHOLELOG} is ${pihole_length} lines long." \ || log_echo "Warning: No pihole.log file found!" - pihole_size=$(du -h "${PIHOLELOG}") \ + pihole_size=$(du -h "${PIHOLELOG}" | awk '{ print $1 }') \ && log_write "${PIHOLELOG} is ${pihole_length}." \ || log_echo "Warning: No pihole.log file found!" From fe8c365d1728398f5f2ad604276ae84d48e76245 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 22 Jan 2017 20:53:30 +0000 Subject: [PATCH 13/15] codacy never lies --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 08f69943..f763d2b8 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -372,7 +372,7 @@ header_write "Analyzing pihole.log" || log_echo "Warning: No pihole.log file found!" pihole_size=$(du -h "${PIHOLELOG}" | awk '{ print $1 }') \ - && log_write "${PIHOLELOG} is ${pihole_length}." \ + && log_write "${PIHOLELOG} is ${pihole_size}." \ || log_echo "Warning: No pihole.log file found!" From 6a89c6bf3b5095e166cce7ccfc82ed75762ebbb9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 23 Jan 2017 15:06:36 +0100 Subject: [PATCH 14/15] Silence rm warning if no DHCP server is used --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 314361c3..02610d85 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -249,7 +249,7 @@ ra-param=*,0,0 fi else - rm "${dhcpconfig}" + rm "${dhcpconfig}" &> /dev/null fi } From 31aa42c35e97c58717baac3e0c49e2478129962d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 23 Jan 2017 14:28:56 -0800 Subject: [PATCH 15/15] Transparency in `sudo` refire. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e687549b..cf2aa5eb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1060,7 +1060,7 @@ main() { if command -v sudo &> /dev/null; then echo "::: Utility sudo located." - exec curl -sSL https://install.pi-hole.net | sudo bash "$@" + exec curl -sSL https://raw.githubusercontent.com/pi-hole/pi-hole/master/automated%20install/basic-install.sh | sudo bash "$@" exit $? 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."