From 9b6427144fcc65db87b612e3d04f10d5256d575a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 14 Jan 2017 17:01:47 -0800 Subject: [PATCH 1/3] || && 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 2/3] 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 3/3] 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