From 40798da6b1538150a8a5eaf0100b739ffa38623c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 12:49:04 +0000 Subject: Add blacklisting wildcard support --- advanced/Scripts/list.sh | 113 +++++++++++++++++++++++++++++++++++------------ pihole | 6 +++ 2 files changed, 90 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index bb3a8a43..6efb7e0b 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -15,6 +15,7 @@ basename=pihole piholeDir=/etc/${basename} whitelist=${piholeDir}/whitelist.txt blacklist=${piholeDir}/blacklist.txt +readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard" reload=false addmode=true verbose=true @@ -47,13 +48,17 @@ helpFunc() { ::: -h, --help Show this help dialog ::: -l, --list Display your ${word}listed domains EOM +if [[ "letter" == "b" ]]; then + echo "::: -wild, --wildcard Add whitecard entry (only blacklist)" +fi exit 0 } EscapeRegexp() { # This way we may safely insert an arbitrary # string in our regular expressions - echo $* | sed "s/[]\\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g" + # Also remove leading "." if present + echo $* | sed 's/^\.//' | sed "s/[]\\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g" } HandleOther(){ @@ -89,22 +94,51 @@ AddDomain() { list="$2" domain=$(EscapeRegexp "$1") - bool=true - #Is the domain in the list we want to add it to? - grep -Ex -q "${domain}" ${list} > /dev/null 2>&1 || bool=false - - if [[ "${bool}" == false ]]; then - #domain not found in the whitelist file, add it! - if [[ "${verbose}" == true ]]; then - echo "::: Adding $1 to $list..." - fi - reload=true - # Add it to the list we want to add it to - echo "$1" >> ${list} - else - if [[ "${verbose}" == true ]]; then - echo "::: ${1} already exists in ${list}, no need to add!" - fi + if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then + + bool=true + #Is the domain in the list we want to add it to? + grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false + + if [[ "${bool}" == false ]]; then + #domain not found in the whitelist file, add it! + if [[ "${verbose}" == true ]]; then + echo "::: Adding $1 to $list..." + fi + reload=true + # Add it to the list we want to add it to + echo "$1" >> "${list}" + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} already exists in ${list}, no need to add!" + fi + fi + + elif [[ "${list}" == "${wildcardlist}" ]]; then + + source "${piholeDir}/setupVars.conf" + #Remove the /* from the end of the IPv4addr. + IPV4_ADDRESS=${IPV4_ADDRESS%/*} + IPV6_ADDRESS=${IPV6_ADDRESS} + + bool=true + #Is the domain in the list? + grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false + + if [[ "${bool}" == false ]]; then + if [[ "${verbose}" == true ]]; then + echo "::: Adding $1 to wildcard blacklist..." + fi + reload=true + echo "address=/$1/${IPV4_ADDRESS}" >> "${wildcardlist}" + if [[ ${#IPV6_ADDRESS} > 0 ]] ; then + echo "address=/$1/${IPV6_ADDRESS}" >> "${wildcardlist}" + fi + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} already exists in wildcard blacklist, no need to add!" + fi + fi fi } @@ -112,18 +146,38 @@ RemoveDomain() { list="$2" domain=$(EscapeRegexp "$1") - bool=true - #Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa - grep -Ex -q "${domain}" ${list} > /dev/null 2>&1 || bool=false - if [[ "${bool}" == true ]]; then - # Remove it from the other one - echo "::: Removing $1 from $list..." - # /I flag: search case-insensitive - sed -i "/${domain}/Id" ${list} - reload=true - else - if [[ "${verbose}" == true ]]; then - echo "::: ${1} does not exist in ${list}, no need to remove!" + if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then + + bool=true + #Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa + grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false + if [[ "${bool}" == true ]]; then + # Remove it from the other one + echo "::: Removing $1 from $list..." + # /I flag: search case-insensitive + sed -i "/${domain}/Id" "${list}" + reload=true + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} does not exist in ${list}, no need to remove!" + fi + fi + + elif [[ "${list}" == "${wildcardlist}" ]]; then + + bool=true + #Is it in the list? + grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false + if [[ "${bool}" == true ]]; then + # Remove it from the other one + echo "::: Removing $1 from $list..." + # /I flag: search case-insensitive + sed -i "/address=\/${domain}/Id" "${list}" + reload=true + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} does not exist in ${list}, no need to remove!" + fi fi fi } @@ -153,6 +207,7 @@ for var in "$@"; do case "${var}" in "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; "-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";; + "-wild" | "wildcard" ) listMain="${wildcardlist}";; "-nr"| "--noreload" ) reload=false;; "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; diff --git a/pihole b/pihole index a8442edd..dcb94a28 100755 --- a/pihole +++ b/pihole @@ -37,6 +37,11 @@ blacklistFunc() { exit 0 } +wildcardFunc() { + "${PI_HOLE_SCRIPT_DIR}"/list.sh "$@" + exit 0 +} + debugFunc() { "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh exit 0 @@ -274,6 +279,7 @@ fi case "${1}" in "-w" | "whitelist" ) whitelistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";; + "-wild" | "wildcard" ) wildcardFunc "$@";; "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-up" | "updatePihole" ) updatePiholeFunc;; -- cgit v1.2.3 From 9ac265980f7b0785c658e1725522ca26ede06c4e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 13:41:19 +0000 Subject: Add .conf to filename --- advanced/Scripts/list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 6efb7e0b..da03698d 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -15,7 +15,7 @@ basename=pihole piholeDir=/etc/${basename} whitelist=${piholeDir}/whitelist.txt blacklist=${piholeDir}/blacklist.txt -readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard" +readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" reload=false addmode=true verbose=true -- cgit v1.2.3 From ebf0db4bbfd7551e2738cbb8ed47baa129b20a07 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 17:17:46 +0000 Subject: Typo fixed --- advanced/Scripts/list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index da03698d..fcc3a4aa 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -48,7 +48,7 @@ helpFunc() { ::: -h, --help Show this help dialog ::: -l, --list Display your ${word}listed domains EOM -if [[ "letter" == "b" ]]; then +if [[ "${letter}" == "b" ]]; then echo "::: -wild, --wildcard Add whitecard entry (only blacklist)" fi exit 0 -- cgit v1.2.3 From 2b778695b1a6c5f1cd3f99bda20273de0514e306 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 2 Jan 2017 14:27:13 +0100 Subject: Implement querying ad lists support for wildcards (what hell of a bash experience) --- pihole | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/pihole b/pihole index dcb94a28..e775ca61 100755 --- a/pihole +++ b/pihole @@ -11,6 +11,7 @@ # (at your option) any later version. PI_HOLE_SCRIPT_DIR="/opt/pihole" +readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then if [ -x "$(command -v sudo)" ];then @@ -83,19 +84,52 @@ scanList(){ fi } +processWildcards() { + IFS="." read -r -a array <<< "${1}" + for (( i=${#array[@]}-1; i>=0; i-- )); do + ar="" + for (( j=${#array[@]}-1; j>${#array[@]}-i-2; j-- )); do + if [[ $j == $((${#array[@]}-1)) ]]; then + ar="${array[$j]}" + else + ar="${array[$j]}.${ar}" + fi + done + echo "${ar}" + done +} + queryFunc() { domain="${2}" method="${3}" lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt) for list in ${lists[@]}; do - result=$(scanList ${domain} ${list} ${method}) + if [ -e "${list}" ]; then + result=$(scanList ${domain} ${list} ${method}) + # Remove empty lines before couting number of results + count=$(sed '/^\s*$/d' <<< "$result" | wc -l) + echo "::: ${list} (${count} results)" + if [[ ${count} > 0 ]]; then + echo "${result}" + fi + echo "" + else + echo "::: ${list} does not exist" + echo "" + fi + done + + # Scan for possible wildcard matches + local wildcards=($(processWildcards "${domain}")) + for domain in ${wildcards[@]}; do + result=$(scanList "\/${domain}\/" ${wildcardlist}) # Remove empty lines before couting number of results count=$(sed '/^\s*$/d' <<< "$result" | wc -l) - echo "::: ${list} (${count} results)" if [[ ${count} > 0 ]]; then + echo "::: Wildcard blocking ${domain} (${count} results)" echo "${result}" + echo "" fi - echo "" done exit 0 } -- cgit v1.2.3 From 52d06d906e6804b2f9e58e7c9ae4e8e3f007fa99 Mon Sep 17 00:00:00 2001 From: trick77 Date: Sun, 8 Jan 2017 10:14:40 +0100 Subject: Bugfix if multiple interfaces are present --- 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 e5142915..76335696 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -235,7 +235,7 @@ chooseInterface() { # Loop sentinel variable local firstLoop=1 - if [[ $(echo ${availableInterfaces} | wc -l) -eq 1 ]]; then + if [[ $(echo "${availableInterfaces}" | wc -l) -eq 1 ]]; then PIHOLE_INTERFACE=${availableInterfaces} return fi -- cgit v1.2.3 From 3b54cab3bcb6198ecff568a5823429efa36d648f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 11:17:25 +0100 Subject: Show branches and revisions (incl. possible dirty state) in debug log --- advanced/Scripts/piholeDebug.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index d0e60177..999948c7 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -122,6 +122,13 @@ version_check() { && log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) local php_ver="$(php -v |& head -n1)" \ && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) + + local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}" || log_echo "Unable to obtain Pi-hole branch" + local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}" || log_echo "Unable to obtain Pi-hole revision" + + local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AminLTE branch: ${admin_branch}" || log_echo "Unable to obtain AminLTE branch" + local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AminLTE rev: ${admin_rev}" || log_echo "Unable to obtain AminLTE revision" + return "${error_found}" } -- cgit v1.2.3 From 7d1f5091a7abb4e4124fe0422165c50e3875825c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 11:21:10 +0100 Subject: Fixed small typo --- 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 999948c7..0258fbc6 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -126,8 +126,8 @@ version_check() { local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}" || log_echo "Unable to obtain Pi-hole branch" local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}" || log_echo "Unable to obtain Pi-hole revision" - local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AminLTE branch: ${admin_branch}" || log_echo "Unable to obtain AminLTE branch" - local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AminLTE rev: ${admin_rev}" || log_echo "Unable to obtain AminLTE revision" + local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AdminLTE branch: ${admin_branch}" || log_echo "Unable to obtain AdminLTE branch" + local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AdminLTE rev: ${admin_rev}" || log_echo "Unable to obtain AdminLTE revision" return "${error_found}" } -- cgit v1.2.3 From 63a414a544ffe6022c9d99f6226b92eea9f661fa Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 11:21:50 +0100 Subject: Align outputs --- 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 0258fbc6..43986351 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -123,8 +123,8 @@ version_check() { local php_ver="$(php -v |& head -n1)" \ && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) - local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}" || log_echo "Unable to obtain Pi-hole branch" - local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}" || log_echo "Unable to obtain Pi-hole revision" + local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}" || log_echo "Unable to obtain Pi-hole branch" + local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}" || log_echo "Unable to obtain Pi-hole revision" local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AdminLTE branch: ${admin_branch}" || log_echo "Unable to obtain AdminLTE branch" local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AdminLTE rev: ${admin_rev}" || log_echo "Unable to obtain AdminLTE revision" -- cgit v1.2.3 From 74a4e62cc9dd09c8dc9c9d6069856f358503b4e7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 11:26:56 +0100 Subject: Codacy fix --- advanced/Scripts/piholeDebug.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 43986351..09d9a786 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -123,11 +123,11 @@ version_check() { local php_ver="$(php -v |& head -n1)" \ && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) - local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}" || log_echo "Unable to obtain Pi-hole branch" - local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}" || log_echo "Unable to obtain Pi-hole revision" + (local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}") || log_echo "Unable to obtain Pi-hole branch" + (local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}") || log_echo "Unable to obtain Pi-hole revision" - local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AdminLTE branch: ${admin_branch}" || log_echo "Unable to obtain AdminLTE branch" - local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AdminLTE rev: ${admin_rev}" || log_echo "Unable to obtain AdminLTE revision" + (local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AdminLTE branch: ${admin_branch}") || log_echo "Unable to obtain AdminLTE branch" + (local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AdminLTE rev: ${admin_rev}") || log_echo "Unable to obtain AdminLTE revision" return "${error_found}" } -- cgit v1.2.3 From f599bcfef97f3b94c455596a274009839a1a3788 Mon Sep 17 00:00:00 2001 From: trick77 Date: Sun, 8 Jan 2017 13:56:08 +0100 Subject: Bugfix if multiple interfaces are present --- 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 76335696..0307bd2e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -236,7 +236,7 @@ chooseInterface() { local firstLoop=1 if [[ $(echo "${availableInterfaces}" | wc -l) -eq 1 ]]; then - PIHOLE_INTERFACE=${availableInterfaces} + PIHOLE_INTERFACE="${availableInterfaces}" return fi -- cgit v1.2.3 From a299a2cc5fb0ac9713287e32271d64ff4cd4ee96 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 18:04:24 -0800 Subject: Repetitive `ip route get` was resetting counts. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0307bd2e..37d0f544 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -168,10 +168,13 @@ getGitFiles() { } find_IPv4_information() { + local route # Find IP used to route to outside world - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - IPV4_ADDRESS=$(ip route get 8.8.8.8| awk '{print $7}') - IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') + 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}") + IPv4gw=$(awk '{print $3}' <<< "${route}") + } get_available_interfaces() { -- cgit v1.2.3 From a122fb2900db8b0d19d964de3d28487ab484c733 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 18:46:15 -0800 Subject: Shellcheck for Test for $? -eq 0 Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 136 +++++++++++++++---------------------- 1 file changed, 56 insertions(+), 80 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0307bd2e..e8538a18 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -252,16 +252,13 @@ chooseInterface() { # 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) - if [[ $? = 0 ]]; then - for desiredInterface in ${chooseInterfaceOptions}; do - PIHOLE_INTERFACE=${desiredInterface} - echo "::: Using interface: $PIHOLE_INTERFACE" - done - else - echo "::: Cancel selected, exiting...." - exit 1 - fi + 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 + } useIPv6dialog() { @@ -281,32 +278,27 @@ use4andor6() { cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" ${r} ${c} 2) options=(IPv4 "Block ads over IPv4" on IPv6 "Block ads over IPv6" on) - choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]];then - for choice in ${choices} - do - case ${choice} in - IPv4 ) useIPv4=true;; - IPv6 ) useIPv6=true;; - esac - done - if [[ ${useIPv4} ]]; then - find_IPv4_information - getStaticIPv4Settings - setStaticIPv4 - fi - if [[ ${useIPv6} ]]; then - 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" - exit 1 - fi - else - echo "::: Cancel selected. Exiting..." + choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) || { echo "::: Cancel selected. Exiting"; exit 1; } + for choice in ${choices} + do + case ${choice} in + IPv4 ) useIPv4=true;; + IPv6 ) useIPv6=true;; + esac + done + if [[ ${useIPv4} ]]; then + find_IPv4_information + getStaticIPv4Settings + setStaticIPv4 + fi + if [[ ${useIPv6} ]]; then + 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" exit 1 fi } @@ -326,36 +318,29 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) # Start a loop to let the user enter their information with the chance to go back and edit it if necessary 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) - if [[ $? = 0 ]]; then + 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}" + # Ask for the gateway - IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]]; then - echo "::: Your static IPv4 gateway: ${IPv4gw}" - # Give the user a chance to review their settings before moving on - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? - IP address: ${IPV4_ADDRESS} - Gateway: ${IPv4gw}" ${r} ${c}); then - # After that's done, the loop ends and we move on - ipSettingsCorrect=True + IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) || \ + # Cancelling gateway settings window + { ipSettingsCorrect=False; echo "::: Cancel selected. Exiting..."; exit 1; } + echo "::: Your static IPv4 gateway: ${IPv4gw}" + + # Give the user a chance to review their settings before moving on + if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? + IP address: ${IPV4_ADDRESS} + Gateway: ${IPv4gw}" ${r} ${c}); then + # After that's done, the loop ends and we move on + ipSettingsCorrect=True else - # If the settings are wrong, the loop continues - ipSettingsCorrect=False - fi - else - # Cancelling gateway settings window + # If the settings are wrong, the loop continues ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 fi - else - # Cancelling IPv4 settings window - ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 - fi done # End the if statement for DHCP vs. static fi @@ -446,8 +431,8 @@ setDNS() { Norton "" off Comodo "" off Custom "" off) - DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]];then + DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) || \ + { echo "::: Cancel selected. Exiting"; exit 1; } case ${DNSchoices} in Google) echo "::: Using Google DNS servers." @@ -489,20 +474,15 @@ setDNS() { 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) - - if [[ $? = 0 ]]; then - 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 - PIHOLE_DNS_1=${strInvalid} - fi - if ! valid_ip "${PIHOLE_DNS_2}" && [ "${PIHOLE_DNS_2}" ]; then - PIHOLE_DNS_2=${strInvalid} - fi - else - echo "::: Cancel selected, exiting...." - exit 1 + 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; } + 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 + PIHOLE_DNS_1=${strInvalid} + fi + 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} @@ -524,10 +504,6 @@ setDNS() { done ;; esac - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi } setLogging() { -- cgit v1.2.3 From 8f7b0237695ec972f4116cafcea610b4e66e923a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 18:48:54 -0800 Subject: Shellcheck for Test for $? -eq 0 Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e8538a18..d8006dc4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1013,23 +1013,19 @@ update_dialogs() { 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) + "${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3) || \ + { echo "::: Cancel selected. Exiting"; exit 1; } - if [[ $? = 0 ]];then - case ${UpdateCmd} in - ${opt1a}) - echo "::: ${opt1a} option selected." - useUpdateVars=true - ;; - ${opt2a}) - echo "::: ${opt2a} option selected" - useUpdateVars=false - ;; + case ${UpdateCmd} in + ${opt1a}) + echo "::: ${opt1a} option selected." + useUpdateVars=true + ;; + ${opt2a}) + echo "::: ${opt2a} option selected" + useUpdateVars=false + ;; esac - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi } main() { -- cgit v1.2.3 From b785213c3a4568b8c3153476449a7427aa607a2e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 18:46:15 -0800 Subject: Shellcheck for Test for $? -eq 0 Signed-off-by: Dan Schaper Shellcheck for Test for $? -eq 0 Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 162 +++++++++++++++---------------------- 1 file changed, 67 insertions(+), 95 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0307bd2e..d8006dc4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -252,16 +252,13 @@ chooseInterface() { # 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) - if [[ $? = 0 ]]; then - for desiredInterface in ${chooseInterfaceOptions}; do - PIHOLE_INTERFACE=${desiredInterface} - echo "::: Using interface: $PIHOLE_INTERFACE" - done - else - echo "::: Cancel selected, exiting...." - exit 1 - fi + 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 + } useIPv6dialog() { @@ -281,32 +278,27 @@ use4andor6() { cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" ${r} ${c} 2) options=(IPv4 "Block ads over IPv4" on IPv6 "Block ads over IPv6" on) - choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]];then - for choice in ${choices} - do - case ${choice} in - IPv4 ) useIPv4=true;; - IPv6 ) useIPv6=true;; - esac - done - if [[ ${useIPv4} ]]; then - find_IPv4_information - getStaticIPv4Settings - setStaticIPv4 - fi - if [[ ${useIPv6} ]]; then - 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" - exit 1 - fi - else - echo "::: Cancel selected. Exiting..." + choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) || { echo "::: Cancel selected. Exiting"; exit 1; } + for choice in ${choices} + do + case ${choice} in + IPv4 ) useIPv4=true;; + IPv6 ) useIPv6=true;; + esac + done + if [[ ${useIPv4} ]]; then + find_IPv4_information + getStaticIPv4Settings + setStaticIPv4 + fi + if [[ ${useIPv6} ]]; then + 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" exit 1 fi } @@ -326,36 +318,29 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) # Start a loop to let the user enter their information with the chance to go back and edit it if necessary 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) - if [[ $? = 0 ]]; then + 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}" + # Ask for the gateway - IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]]; then - echo "::: Your static IPv4 gateway: ${IPv4gw}" - # Give the user a chance to review their settings before moving on - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? - IP address: ${IPV4_ADDRESS} - Gateway: ${IPv4gw}" ${r} ${c}); then - # After that's done, the loop ends and we move on - ipSettingsCorrect=True + IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) || \ + # Cancelling gateway settings window + { ipSettingsCorrect=False; echo "::: Cancel selected. Exiting..."; exit 1; } + echo "::: Your static IPv4 gateway: ${IPv4gw}" + + # Give the user a chance to review their settings before moving on + if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? + IP address: ${IPV4_ADDRESS} + Gateway: ${IPv4gw}" ${r} ${c}); then + # After that's done, the loop ends and we move on + ipSettingsCorrect=True else - # If the settings are wrong, the loop continues - ipSettingsCorrect=False - fi - else - # Cancelling gateway settings window + # If the settings are wrong, the loop continues ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 fi - else - # Cancelling IPv4 settings window - ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 - fi done # End the if statement for DHCP vs. static fi @@ -446,8 +431,8 @@ setDNS() { Norton "" off Comodo "" off Custom "" off) - DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]];then + DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) || \ + { echo "::: Cancel selected. Exiting"; exit 1; } case ${DNSchoices} in Google) echo "::: Using Google DNS servers." @@ -489,20 +474,15 @@ setDNS() { 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) - - if [[ $? = 0 ]]; then - 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 - PIHOLE_DNS_1=${strInvalid} - fi - if ! valid_ip "${PIHOLE_DNS_2}" && [ "${PIHOLE_DNS_2}" ]; then - PIHOLE_DNS_2=${strInvalid} - fi - else - echo "::: Cancel selected, exiting...." - exit 1 + 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; } + 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 + PIHOLE_DNS_1=${strInvalid} + fi + 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} @@ -524,10 +504,6 @@ setDNS() { done ;; esac - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi } setLogging() { @@ -1037,23 +1013,19 @@ update_dialogs() { 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) + "${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3) || \ + { echo "::: Cancel selected. Exiting"; exit 1; } - if [[ $? = 0 ]];then - case ${UpdateCmd} in - ${opt1a}) - echo "::: ${opt1a} option selected." - useUpdateVars=true - ;; - ${opt2a}) - echo "::: ${opt2a} option selected" - useUpdateVars=false - ;; + case ${UpdateCmd} in + ${opt1a}) + echo "::: ${opt1a} option selected." + useUpdateVars=true + ;; + ${opt2a}) + echo "::: ${opt2a} option selected" + useUpdateVars=false + ;; esac - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi } main() { -- cgit v1.2.3 From 27e90cc4e611278b7a5f680579717f0d9a2e5fc1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 18:04:24 -0800 Subject: Repetitive `ip route get` was resetting counts. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d8006dc4..2482495f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -168,10 +168,13 @@ getGitFiles() { } find_IPv4_information() { + local route # Find IP used to route to outside world - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - IPV4_ADDRESS=$(ip route get 8.8.8.8| awk '{print $7}') - IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') + 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}") + IPv4gw=$(awk '{print $3}' <<< "${route}") + } get_available_interfaces() { -- cgit v1.2.3 From 0966d7660e1d30530d03aa00963c67f0710e8ae2 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 21:30:38 -0800 Subject: Take out some whiptail subshells that aren't needed. Signed-off-by: Dan Schaper Take out some whiptail subshells that aren't needed. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2482495f..367bdfb5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -308,9 +308,9 @@ use4andor6() { getStaticIPv4Settings() { # Ask if the user wants to use DHCP settings as their static IP - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? + 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 + Gateway: ${IPv4gw}" ${r} ${c}; then # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. 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. @@ -335,9 +335,9 @@ It is also possible to use a DHCP reservation, but if you are going to do that, echo "::: Your static IPv4 gateway: ${IPv4gw}" # Give the user a chance to review their settings before moving on - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? + if whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? IP address: ${IPV4_ADDRESS} - Gateway: ${IPv4gw}" ${r} ${c}); then + Gateway: ${IPv4gw}" ${r} ${c}; then # After that's done, the loop ends and we move on ipSettingsCorrect=True else @@ -972,15 +972,11 @@ checkSelinux() { enforceMode=$(getenforce) echo "${enforceMode}" if [[ "${enforceMode}" == "Enforcing" ]]; then - if (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}); then - echo ":::" - echo "::: Continuing installation with SELinux Enforcing." - echo "::: Please refer to official SELinux documentation to create a custom policy." - else - echo ":::" - echo "::: Not continuing install after SELinux Enforcing detected." - exit 1 - fi + 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." fi fi } -- cgit v1.2.3 From 6f0289de49adb0d837dde30d88611e2fc676dffe Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 22:54:45 -0800 Subject: Vestigial variable that was never populated. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 367bdfb5..e6723b93 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -609,15 +609,15 @@ installScripts() { # Install files from local core repository if is_repo "${PI_HOLE_LOCAL_REPO}"; then cd "${PI_HOLE_LOCAL_REPO}" - install -o "${USER}" -Dm755 -d /opt/pihole - install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh - install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh - install -o "${USER}" -Dm755 -t /opt/pihole/ ./automated\ install/uninstall.sh + install -o "${USER}" -Dm755 -d "${install_dir}" + install -o "${USER}" -Dm755 -t "${install_dir}" gravity.sh + install -o "${USER}" -Dm755 -t "${install_dir}" ./advanced/Scripts/*.sh + install -o "${USER}" -Dm755 -t "${install_dir}" ./automated\ install/uninstall.sh install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole echo " done." else - echo " *** ERROR: Local repo ${core_repo} not found, exiting." + echo " *** ERROR: Local repo ${PI_HOLE_LOCAL_REPO} not found, exiting." exit 1 fi } -- cgit v1.2.3 From 80a3bce6d5dd4d9aec5380c07e40ec39b5690b70 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 23:01:18 -0800 Subject: PI_HOLE_INSTALL_DIR global variable Signed-off-by: Dan Schaper `"${pw}"` Signed-off-by: Dan Schaper Absolute path for pihole Signed-off-by: Dan Schaper Debian PKG_INSTALL as array Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e6723b93..047ed2df 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -28,6 +28,7 @@ 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_INSTALL_DIR="/opt/pihole" useUpdateVars=false IPV4_ADDRESS="" @@ -58,7 +59,7 @@ if command -v apt-get &> /dev/null; then ############################################# PKG_MANAGER="apt-get" UPDATE_PKG_CACHE="${PKG_MANAGER} update" - PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" + 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" # ######################################### @@ -307,6 +308,7 @@ use4andor6() { } getStaticIPv4Settings() { + local ipSettingsCorrect # Ask if the user wants to use DHCP settings as their static IP 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} @@ -598,21 +600,20 @@ clean_existing() { installScripts() { # Install the scripts from repository to their various locations - readonly install_dir="/opt/pihole/" echo ":::" echo -n "::: Installing scripts from ${PI_HOLE_LOCAL_REPO}..." # Clear out script files from Pi-hole scripts directory. - clean_existing "${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 cd "${PI_HOLE_LOCAL_REPO}" - install -o "${USER}" -Dm755 -d "${install_dir}" - install -o "${USER}" -Dm755 -t "${install_dir}" gravity.sh - install -o "${USER}" -Dm755 -t "${install_dir}" ./advanced/Scripts/*.sh - install -o "${USER}" -Dm755 -t "${install_dir}" ./automated\ install/uninstall.sh + install -o "${USER}" -Dm755 -d "${PI_HOLE_INSTALL_DIR}" + 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 /usr/local/bin/ pihole install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole echo " done." @@ -736,7 +737,7 @@ install_dependent_packages() { fi done if [[ ${#installArray[@]} -gt 0 ]]; then - debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" + debconf-apt-progress -- "${PKG_INSTALL[@]}" "${installArray[@]}" return fi return 0 @@ -1141,11 +1142,11 @@ main() { pw="" if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) - pihole -a -p ${pw} + /usr/local/bin/pihole -a -p "${pw}" fi if [[ "${useUpdateVars}" == false ]]; then - displayFinalMessage ${pw} + displayFinalMessage "${pw}" fi echo "::: Restarting services..." -- cgit v1.2.3 From c58a95ca2e483ff8cbfae7753b0d0e4baa616379 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 8 Jan 2017 23:40:19 -0800 Subject: `setDNS` whiptail direct, not in array. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 140 +++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 047ed2df..1d9adcc4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -429,86 +429,88 @@ valid_ip() { } setDNS() { - DNSChooseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 6) + local DNSSettingsCorrect + DNSChooseOptions=(Google "" on OpenDNS "" off Level3 "" off Norton "" off Comodo "" off Custom "" off) - DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) || \ - { echo "::: Cancel selected. Exiting"; exit 1; } - case ${DNSchoices} in - Google) - echo "::: Using Google DNS servers." - PIHOLE_DNS_1="8.8.8.8" - PIHOLE_DNS_2="8.8.4.4" - ;; - OpenDNS) - echo "::: Using OpenDNS servers." - PIHOLE_DNS_1="208.67.222.222" - PIHOLE_DNS_2="208.67.220.220" - ;; - Level3) - echo "::: Using Level3 servers." - PIHOLE_DNS_1="4.2.2.1" - PIHOLE_DNS_2="4.2.2.2" - ;; - Norton) - echo "::: Using Norton ConnectSafe servers." - PIHOLE_DNS_1="199.85.126.10" - PIHOLE_DNS_2="199.85.127.10" - ;; - Comodo) - echo "::: Using Comodo Secure servers." - PIHOLE_DNS_1="8.26.56.26" - PIHOLE_DNS_2="8.20.247.20" - ;; - Custom) - until [[ ${DNSSettingsCorrect} = True ]]; do - strInvalid="Invalid" - if [ ! ${PIHOLE_DNS_1} ]; then - if [ ! ${PIHOLE_DNS_2} ]; then - prePopulate="" - else - prePopulate=", ${PIHOLE_DNS_2}" - fi - elif [ ${PIHOLE_DNS_1} ] && [ ! ${PIHOLE_DNS_2} ]; then - prePopulate="${PIHOLE_DNS_1}" - elif [ ${PIHOLE_DNS_1} ] && [ ${PIHOLE_DNS_2} ]; then - prePopulate="${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}" + DNSchoices=$(whiptail --separate-output --radiolist "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 + Google) + echo "::: Using Google DNS servers." + PIHOLE_DNS_1="8.8.8.8" + PIHOLE_DNS_2="8.8.4.4" + ;; + OpenDNS) + echo "::: Using OpenDNS servers." + PIHOLE_DNS_1="208.67.222.222" + PIHOLE_DNS_2="208.67.220.220" + ;; + Level3) + echo "::: Using Level3 servers." + PIHOLE_DNS_1="4.2.2.1" + PIHOLE_DNS_2="4.2.2.2" + ;; + Norton) + echo "::: Using Norton ConnectSafe servers." + PIHOLE_DNS_1="199.85.126.10" + PIHOLE_DNS_2="199.85.127.10" + ;; + Comodo) + echo "::: Using Comodo Secure servers." + PIHOLE_DNS_1="8.26.56.26" + PIHOLE_DNS_2="8.20.247.20" + ;; + Custom) + until [[ ${DNSSettingsCorrect} = True ]]; do + strInvalid="Invalid" + if [ ! ${PIHOLE_DNS_1} ]; then + if [ ! ${PIHOLE_DNS_2} ]; then + prePopulate="" + else + prePopulate=", ${PIHOLE_DNS_2}" fi + elif [ ${PIHOLE_DNS_1} ] && [ ! ${PIHOLE_DNS_2} ]; then + prePopulate="${PIHOLE_DNS_1}" + 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; } - 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 - PIHOLE_DNS_1=${strInvalid} + 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; } + 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 + PIHOLE_DNS_1=${strInvalid} + fi + 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 + PIHOLE_DNS_1="" fi - if ! valid_ip "${PIHOLE_DNS_2}" && [ "${PIHOLE_DNS_2}" ]; then - PIHOLE_DNS_2=${strInvalid} + if [[ ${PIHOLE_DNS_2} == "${strInvalid}" ]]; then + PIHOLE_DNS_2="" 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 - PIHOLE_DNS_1="" - fi - if [[ ${PIHOLE_DNS_2} == "${strInvalid}" ]]; then - PIHOLE_DNS_2="" - fi - DNSSettingsCorrect=False - 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 - DNSSettingsCorrect=True - else - # If the settings are wrong, the loop continues - DNSSettingsCorrect=False - fi + DNSSettingsCorrect=False + 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 + DNSSettingsCorrect=True + else + # If the settings are wrong, the loop continues + DNSSettingsCorrect=False fi - done - ;; - esac + fi + done + ;; + esac } setLogging() { -- cgit v1.2.3 From 6b3aea933dc5e0d86a6393f4e5717b0f70d287b9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 9 Jan 2017 15:02:31 +0100 Subject: Add info that whitelisting blocked pages does not work --- advanced/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index 1434025a..7fd42cd2 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -74,7 +74,9 @@ if($uri == "/") Whitelist this page Close window -