From 2335097c99432d874899426444f106cc2832f1e6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 21 Dec 2016 22:20:23 -0800 Subject: [PATCH 01/13] Find which packages already exist and only install new packages. Set up for unintall to know what packages we installed for later removal. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3dacdfff..eb897319 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -97,8 +97,9 @@ if [[ $(command -v apt-get) ]]; then LIGHTTPD_CFG="lighttpd.conf.debian" DNSMASQ_USER="dnsmasq" - package_check_install() { - dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}" + package_check() { + dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep "ok installed" + return } elif [ $(command -v rpm) ]; then # Fedora Family @@ -738,15 +739,24 @@ install_dependent_packages() { # Install packages passed in via argument array # No spinner - conflicts with set -e declare -a argArray1=("${!1}") + declare -a installArray + # Debian based package install - debconf will download the entire package list + # so we just create an array of packages not currently installed to cut down on the + # amount of download traffic. + # 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 - debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" - else for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." - package_check_install "${i}" &> /dev/null - echo " installed!" + if package_check "${i}" &> /dev/null; then + echo " installed!" + else + echo " added to install list!" + installArray+=("${i}") + fi done + debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" fi } From 07a4f970d4abb3b7378d4f797695ab2efd079bee Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 21 Dec 2016 22:57:42 -0800 Subject: [PATCH 02/13] Check for installation status within the parent function. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index eb897319..d47034c2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -97,10 +97,6 @@ if [[ $(command -v apt-get) ]]; then LIGHTTPD_CFG="lighttpd.conf.debian" DNSMASQ_USER="dnsmasq" - package_check() { - dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep "ok installed" - return - } elif [ $(command -v rpm) ]; then # Fedora Family if [ $(command -v dnf) ]; then @@ -116,8 +112,7 @@ elif [ $(command -v rpm) ]; then PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq epel-release findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) if grep -q 'Fedora' /etc/redhat-release; then - remove_deps=(epel-release); - PIHOLE_DEPS=( ${PIHOLE_DEPS[@]/$remove_deps} ); + PIHOLE_DEPS=(${PIHOLE_DEPS#epel-release}); fi LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd" @@ -749,7 +744,7 @@ install_dependent_packages() { if command -v debconf-apt-progress &> /dev/null; then for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." - if package_check "${i}" &> /dev/null; then + if dpkg-query -W -f='${Status}' "${i}" 2>/dev/null | grep "ok installed" &> /dev/null; then echo " installed!" else echo " added to install list!" From fb5578c0d41c5668e28009138f811db335f1cf54 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 21 Dec 2016 23:38:31 -0800 Subject: [PATCH 03/13] Fedora dependency installer overhaul Signed-off-by: Dan Schaper Modify Fedora dependency installer Signed-off-by: Dan Schaper Fedora now installs and arrays only non-installed packages. Fedora also noops the cache update, since it updates at every dnf call anyays. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d47034c2..8f58fa7b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -105,23 +105,22 @@ elif [ $(command -v rpm) ]; then PKG_MANAGER="yum" fi PKG_CACHE="/var/cache/${PKG_MANAGER}" - UPDATE_PKG_CACHE="${PKG_MANAGER} check-update" + #Every yum/dnf call will autmomatically update the cache. No-op here, cach updates when + #We get available package count. + #Also a bare `dnf check-update will return 100 as a retval, blows up set -e + 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=(git iproute net-tools newt procps-ng) - PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq epel-release findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) + PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) - if grep -q 'Fedora' /etc/redhat-release; then - PIHOLE_DEPS=(${PIHOLE_DEPS#epel-release}); + if ! grep -q 'Fedora' /etc/redhat-release; then + PIHOLE_DEPS=("${PIHOLE_DEPS[@]}" "epel-release"); fi LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd" LIGHTTPD_CFG="lighttpd.conf.fedora" DNSMASQ_USER="nobody" - - package_check_install() { - rpm -qa | grep ^"${1}"- > /dev/null || ${PKG_INSTALL} "${1}" - } else echo "OS distribution not supported" exit @@ -708,7 +707,7 @@ update_pacakge_cache() { #update package lists echo ":::" echo -n "::: ${PKG_MANAGER} update has not been run today. Running now..." - ${UPDATE_PKG_CACHE} &> /dev/null + ${UPDATE_PKG_CACHE} echo " done!" fi } @@ -751,8 +750,22 @@ install_dependent_packages() { installArray+=("${i}") fi done - debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" + debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" + return 0 fi + + #Fedora + for i in "${argArray1[@]}"; do + echo -n "::: Checking for $i..." + if dnf -q list installed "${i}" &> /dev/null; then + echo " installed!" + else + echo " added to install list!" + installArray+=("${i}") + fi + done + ${PKG_INSTALL} "${installArray[@]}" + return 0 } CreateLogFile() { From 9073f34b30a7b119e91a188a6058371ee25a0bb6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 22 Dec 2016 00:44:10 -0800 Subject: [PATCH 04/13] Quiet DNF Signed-off-by: Dan Schaper --- 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 8f58fa7b..e5cf3f81 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -764,7 +764,7 @@ install_dependent_packages() { installArray+=("${i}") fi done - ${PKG_INSTALL} "${installArray[@]}" + ${PKG_INSTALL} "${installArray[@]}" &> /dev/null return 0 } From ab7d193f9881cf4e18e73177c7fe70e4ed5a88b1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 22 Dec 2016 03:21:37 -0800 Subject: [PATCH 05/13] Still causing problems with Fedora and CentOS Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e5cf3f81..4da72c62 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -754,10 +754,10 @@ install_dependent_packages() { return 0 fi - #Fedora + #Fedora/CentOS for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." - if dnf -q list installed "${i}" &> /dev/null; then + if ${PKG_MANAGER} -q list installed "${i}" &> /dev/null; then echo " installed!" else echo " added to install list!" @@ -938,7 +938,7 @@ configureSelinux() { if [ -x "$(command -v getenforce)" ]; then printf "\n::: SELinux Detected\n" printf ":::\tChecking for SELinux policy development packages..." - package_check_install "selinux-policy-devel" > /dev/null + install_dependent_packages "selinux-policy-devel" > /dev/null echo " installed!" printf ":::\tEnabling httpd server side includes (SSI).. " setsebool -P httpd_ssi_exec on &> /dev/null && echo "Success" || echo "SELinux not enabled" @@ -1140,4 +1140,4 @@ main() { if [[ "${PH_TEST}" != true ]] ; then main "$@" -fi +fi \ No newline at end of file From 2919f852adf320ab3a20991a1dbaa02c62d59c2c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 23 Dec 2016 16:30:26 -0800 Subject: [PATCH 06/13] Import `checkSelinux` from master Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9379a5c2..659fa08f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -952,17 +952,22 @@ updatePihole() { runGravity } -configureSelinux() { +checkSelinux() { if [ -x "$(command -v getenforce)" ]; then - printf "\n::: SELinux Detected\n" - printf ":::\tChecking for SELinux policy development packages..." - package_check_install "selinux-policy-devel" > /dev/null - echo " installed!" - printf ":::\tEnabling httpd server side includes (SSI).. " - setsebool -P httpd_ssi_exec on &> /dev/null && echo "Success" || echo "SELinux not enabled" - printf "\n:::\tCompiling Pi-Hole SELinux policy..\n" - if ! [ -x "$(command -v systemctl)" ]; then - sed -i.bak '/systemd/d' /etc/.pihole/advanced/selinux/pihole.te + echo ":::" + echo -n "::: SELinux Support Detected... Mode: " + 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 fi fi } From d5ed6c190108aac70108dae9e388fc6b343d3edf Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 21 Dec 2016 22:20:23 -0800 Subject: [PATCH 07/13] Find which packages already exist and only install new packages. Set up for unintall to know what packages we installed for later removal. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0a56b06e..9e6383ee 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -97,8 +97,9 @@ if [[ $(command -v apt-get) ]]; then LIGHTTPD_CFG="lighttpd.conf.debian" DNSMASQ_USER="dnsmasq" - package_check_install() { - dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}" + package_check() { + dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep "ok installed" + return } elif [ $(command -v rpm) ]; then # Fedora Family @@ -745,15 +746,24 @@ install_dependent_packages() { # Install packages passed in via argument array # No spinner - conflicts with set -e declare -a argArray1=("${!1}") + declare -a installArray + # Debian based package install - debconf will download the entire package list + # so we just create an array of packages not currently installed to cut down on the + # amount of download traffic. + # 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 - debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" - else for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." - package_check_install "${i}" &> /dev/null - echo " installed!" + if package_check "${i}" &> /dev/null; then + echo " installed!" + else + echo " added to install list!" + installArray+=("${i}") + fi done + debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" fi } From 852341c601fba5571246f03d7b36de185d7a4c1b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 21 Dec 2016 22:57:42 -0800 Subject: [PATCH 08/13] Check for installation status within the parent function. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9e6383ee..cc7d04dd 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -97,10 +97,6 @@ if [[ $(command -v apt-get) ]]; then LIGHTTPD_CFG="lighttpd.conf.debian" DNSMASQ_USER="dnsmasq" - package_check() { - dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep "ok installed" - return - } elif [ $(command -v rpm) ]; then # Fedora Family if [ $(command -v dnf) ]; then @@ -116,8 +112,7 @@ elif [ $(command -v rpm) ]; then PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq epel-release findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) if grep -q 'Fedora' /etc/redhat-release; then - remove_deps=(epel-release); - PIHOLE_DEPS=( ${PIHOLE_DEPS[@]/$remove_deps} ); + PIHOLE_DEPS=(${PIHOLE_DEPS#epel-release}); fi LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd" @@ -756,7 +751,7 @@ install_dependent_packages() { if command -v debconf-apt-progress &> /dev/null; then for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." - if package_check "${i}" &> /dev/null; then + if dpkg-query -W -f='${Status}' "${i}" 2>/dev/null | grep "ok installed" &> /dev/null; then echo " installed!" else echo " added to install list!" From dc22a50dcc8c125befd74e13234175ea77f8f66d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 21 Dec 2016 23:38:31 -0800 Subject: [PATCH 09/13] Fedora dependency installer overhaul Signed-off-by: Dan Schaper Modify Fedora dependency installer Signed-off-by: Dan Schaper Fedora now installs and arrays only non-installed packages. Fedora also noops the cache update, since it updates at every dnf call anyays. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index cc7d04dd..0b48b5e7 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -105,23 +105,22 @@ elif [ $(command -v rpm) ]; then PKG_MANAGER="yum" fi PKG_CACHE="/var/cache/${PKG_MANAGER}" - UPDATE_PKG_CACHE="${PKG_MANAGER} check-update" + #Every yum/dnf call will autmomatically update the cache. No-op here, cach updates when + #We get available package count. + #Also a bare `dnf check-update will return 100 as a retval, blows up set -e + 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=(git iproute net-tools newt procps-ng) - PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq epel-release findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) + PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) - if grep -q 'Fedora' /etc/redhat-release; then - PIHOLE_DEPS=(${PIHOLE_DEPS#epel-release}); + if ! grep -q 'Fedora' /etc/redhat-release; then + PIHOLE_DEPS=("${PIHOLE_DEPS[@]}" "epel-release"); fi LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd" LIGHTTPD_CFG="lighttpd.conf.fedora" DNSMASQ_USER="nobody" - - package_check_install() { - rpm -qa | grep ^"${1}"- > /dev/null || ${PKG_INSTALL} "${1}" - } else echo "OS distribution not supported" exit @@ -715,7 +714,7 @@ update_pacakge_cache() { #update package lists echo ":::" echo -n "::: ${PKG_MANAGER} update has not been run today. Running now..." - ${UPDATE_PKG_CACHE} &> /dev/null + ${UPDATE_PKG_CACHE} echo " done!" fi } @@ -758,8 +757,22 @@ install_dependent_packages() { installArray+=("${i}") fi done - debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" + debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" + return 0 fi + + #Fedora + for i in "${argArray1[@]}"; do + echo -n "::: Checking for $i..." + if dnf -q list installed "${i}" &> /dev/null; then + echo " installed!" + else + echo " added to install list!" + installArray+=("${i}") + fi + done + ${PKG_INSTALL} "${installArray[@]}" + return 0 } CreateLogFile() { From 8ad52806de14f2d5679caa95cc2d1074d43c42f0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 22 Dec 2016 00:44:10 -0800 Subject: [PATCH 10/13] Quiet DNF Signed-off-by: Dan Schaper --- 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 0b48b5e7..675d2302 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -771,7 +771,7 @@ install_dependent_packages() { installArray+=("${i}") fi done - ${PKG_INSTALL} "${installArray[@]}" + ${PKG_INSTALL} "${installArray[@]}" &> /dev/null return 0 } From f458780ba738979dcfeb22417b104a70ea695cda Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 22 Dec 2016 03:21:37 -0800 Subject: [PATCH 11/13] Rebase onto development 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 675d2302..a9b3355a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -761,10 +761,10 @@ install_dependent_packages() { return 0 fi - #Fedora + #Fedora/CentOS for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." - if dnf -q list installed "${i}" &> /dev/null; then + if ${PKG_MANAGER} -q list installed "${i}" &> /dev/null; then echo " installed!" else echo " added to install list!" From 7eb612472173e787036ff7efd767baf585ff623d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 24 Dec 2016 16:52:46 -0800 Subject: [PATCH 12/13] Don't call for package installs if there are no packages to install. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a9b3355a..4edec877 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -757,7 +757,10 @@ install_dependent_packages() { installArray+=("${i}") fi done + if [[ ${#installArray[@]} -gt 0 ]]; then debconf-apt-progress -- ${PKG_INSTALL} "${installArray[@]}" + return + fi return 0 fi @@ -771,7 +774,10 @@ install_dependent_packages() { installArray+=("${i}") fi done - ${PKG_INSTALL} "${installArray[@]}" &> /dev/null + if [[ ${#installArray[@]} -gt 0 ]]; then + ${PKG_INSTALL} "${installArray[@]}" &> /dev/null + return + fi return 0 } From 9a9cb6134551bedc327ba4e256220997c9c40798 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 27 Dec 2016 12:59:53 -0800 Subject: [PATCH 13/13] Shift `epel-release` to installer dependencies for CentOS Signed-off-by: Dan Schaper --- 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 97cd0d98..0e251575 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -113,7 +113,7 @@ elif [ $(command -v rpm) ]; then PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli sudo unzip wget) if ! grep -q 'Fedora' /etc/redhat-release; then - PIHOLE_DEPS=("${PIHOLE_DEPS[@]}" "epel-release"); + INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release"); fi LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd"