From 98afb0e9980a716666031206d9955830e9f727f5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 27 Jun 2017 14:28:05 +0200 Subject: [PATCH 1/6] pihole checkout ftl --- advanced/Scripts/piholeCheckout.sh | 125 +++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 102db2ba..d4a85e8a 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -24,6 +24,93 @@ update="false" coltable="/opt/pihole/COL_TABLE" source ${coltable} +check_download_exists() { + status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1) + if echo "$status" | grep -q "404"; then + return 1 + else + return 0 + fi +} + +FTLinstall() { + # Download and install FTL binary + local binary="${1}" + local path="${2}" + local str="Installing FTL" + echo -ne " ${INFO} ${str}..." + + if curl -sSL --fail "https://ftl.pi-hole.net/${path}" -o "/tmp/${binary}"; then + # Get sha1 of the binary we just downloaded for verification. + curl -sSL --fail "https://ftl.pi-hole.net/${path}.sha1" -o "/tmp/${binary}.sha1" + # Check if we just downloaded text, or a binary file. + cd /tmp + if sha1sum --status --quiet -c "${binary}".sha1; then + echo -n "transferred... " + stop_service pihole-FTL &> /dev/null + install -T -m 0755 "/tmp/${binary}" "/usr/bin/pihole-FTL" + rm "/tmp/${binary}" "/tmp/${binary}.sha1" + start_service pihole-FTL &> /dev/null + echo -e "${OVER} ${TICK} ${str}" + return 0 + else + echo -e "${OVER} ${CROSS} ${str}" + echo -e " ${COL_LIGHT_RED}Error: Download of binary from ftl.pi-hole.net failed${COL_NC}" + return 1 + fi + else + echo -e "${OVER} ${CROSS} ${str}" + echo -e " ${COL_LIGHT_RED}Error: URL not found${COL_NC}" + fi +} + +get_binary_name() { + local machine + + machine=$(uname -m) + + local str="Detecting architecture" + echo -ne " ${INFO} ${str}..." + if [[ ${machine} == arm* || ${machine} == *aarch* ]]; then + # ARM + local rev=$(uname -m | sed "s/[^0-9]//g;") + local lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') + if [[ "$lib" == "/lib/ld-linux-aarch64.so.1" ]]; then + echo -e "${OVER} ${TICK} Detected ARM-aarch64 architecture" + binary="pihole-FTL-aarch64-linux-gnu" + elif [[ "$lib" == "/lib/ld-linux-armhf.so.3" ]]; then + if [ "$rev" -gt "6" ]; then + echo -e "${OVER} ${TICK} Detected ARM-hf architecture (armv7+)" + binary="pihole-FTL-arm-linux-gnueabihf" + else + echo -e "${OVER} ${TICK} Detected ARM-hf architecture (armv6 or lower) Using ARM binary" + binary="pihole-FTL-arm-linux-gnueabi" + fi + else + echo -e "${OVER} ${TICK} Detected ARM architecture" + binary="pihole-FTL-arm-linux-gnueabi" + fi + elif [[ $machine == ppc ]]; then + # PowerPC + echo "::: Detected PowerPC architecture" + binary="pihole-FTL-powerpc-linux-gnu" + elif [[ ${machine} == x86_64 ]]; then + # 64bit + echo -e "${OVER} ${TICK} Detected x86_64 architecture" + binary="pihole-FTL-linux-x86_64" + else + # Something else - we try to use 32bit executable and warn the user + if [[ ! ${machine} == i686 ]]; then + echo -e "${OVER} ${CROSS} ${str}... + ${COL_LIGHT_RED}Not able to detect architecture (unknown: ${machine}), trying 32bit executable + Contact support if you experience issues (e.g: FTL not running)${COL_NC}" + else + echo -e "${OVER} ${TICK} Detected 32bit (i686) architecture" + fi + binary="pihole-FTL-linux-x86_32" + fi +} + fully_fetch_repo() { # Add upstream branches to shallow clone local directory="${1}" @@ -50,7 +137,6 @@ get_available_branches() { return } - fetch_checkout_pull_branch() { # Check out specified branch local directory="${1}" @@ -74,7 +160,7 @@ checkout_pull_branch() { cd "${directory}" || return 1 oldbranch="$(git symbolic-ref HEAD)" - + git checkout "${branch}" || return 1 if [[ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]]; then @@ -82,13 +168,13 @@ checkout_pull_branch() { fi git_pull=$(git pull || return 1) - + if [[ "$git_pull" == *"up-to-date"* ]]; then echo -e "\n ${INFO} $(git pull)" else echo -e "$git_pull\n" fi - + return 0 } @@ -150,6 +236,12 @@ checkout() { fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; } fi echo -e " ${TICK} Pi-hole core" + + get_binary_name + local path + path="development/${binary}" + FTLinstall "${binary}" "${path}" + elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo -e " ${INFO} Shortcut \"master\" detected - checking out master branches..." @@ -160,7 +252,12 @@ checkout() { fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; } fi echo -e " ${TICK} Web interface" - + + get_binary_name + local path + path="master/${binary}" + FTLinstall "${binary}" "${path}" + elif [[ "${1}" == "core" ]] ; then str="Fetching branches from ${piholeGitUrl}" echo -ne " ${INFO} $str" @@ -196,7 +293,7 @@ checkout() { exit 1 fi webbranches=($(get_available_branches "${webInterfaceDir}")) - + if [[ "${corebranches[@]}" == *"master"* ]]; then echo -e "${OVER} ${TICK} $str ${INFO} ${#webbranches[@]} branches available for Web Admin" @@ -215,13 +312,27 @@ checkout() { exit 1 fi checkout_pull_branch "${webInterfaceDir}" "${2}" + elif [[ "${1}" == "ftl" ]] ; then + + get_binary_name + local path + path="${2}/${binary}" + + if check_download_exists "$path"; then + echo " ${TICK} Branch ${2} exists" + else + echo " ${CROSS} Branch ${2} doesn't exist" + fi + + FTLinstall "${binary}" "${path}" + else echo -e " ${INFO} Requested option \"${1}\" is not available" exit 1 fi # Force updating everything - if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then + if [[ ( ! "${1}" == "web" && ! "${1}" == "ftl" ) && "${update}" == "true" ]]; then echo -e " ${INFO} Running installer to upgrade your installation" if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then exit 0 From 70fd94edb3ebcfaf16ea9d453e7ca10d7318c9ed Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 5 Jul 2017 19:30:05 +0200 Subject: [PATCH 2/6] Edit message when requested branch of FTL is not available --- advanced/Scripts/piholeCheckout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index d4a85e8a..7a84f588 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -321,7 +321,7 @@ checkout() { if check_download_exists "$path"; then echo " ${TICK} Branch ${2} exists" else - echo " ${CROSS} Branch ${2} doesn't exist" + echo " ${CROSS} Requested branch \"${2}\" is not available" fi FTLinstall "${binary}" "${path}" From bb8a263d70766863d73d077578ebe041f10793d1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 5 Jul 2017 19:34:20 +0200 Subject: [PATCH 3/6] ShellCheck --- advanced/Scripts/piholeCheckout.sh | 38 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 7a84f588..657bde83 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -35,16 +35,19 @@ check_download_exists() { FTLinstall() { # Download and install FTL binary - local binary="${1}" - local path="${2}" - local str="Installing FTL" + local binary + binary="${1}" + local path + path="${2}" + local str + str="Installing FTL" echo -ne " ${INFO} ${str}..." if curl -sSL --fail "https://ftl.pi-hole.net/${path}" -o "/tmp/${binary}"; then # Get sha1 of the binary we just downloaded for verification. curl -sSL --fail "https://ftl.pi-hole.net/${path}.sha1" -o "/tmp/${binary}.sha1" # Check if we just downloaded text, or a binary file. - cd /tmp + cd /tmp || return 1 if sha1sum --status --quiet -c "${binary}".sha1; then echo -n "transferred... " stop_service pihole-FTL &> /dev/null @@ -66,15 +69,17 @@ FTLinstall() { get_binary_name() { local machine - machine=$(uname -m) - local str="Detecting architecture" + local str + str="Detecting architecture" echo -ne " ${INFO} ${str}..." if [[ ${machine} == arm* || ${machine} == *aarch* ]]; then # ARM - local rev=$(uname -m | sed "s/[^0-9]//g;") - local lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') + local rev + rev=$(uname -m | sed "s/[^0-9]//g;") + local lib + lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') if [[ "$lib" == "/lib/ld-linux-aarch64.so.1" ]]; then echo -e "${OVER} ${TICK} Detected ARM-aarch64 architecture" binary="pihole-FTL-aarch64-linux-gnu" @@ -127,7 +132,8 @@ fully_fetch_repo() { get_available_branches() { # Return available branches - local directory="${1}" + local directory + directory="${1}" local output cd "${directory}" || return 1 @@ -139,11 +145,13 @@ get_available_branches() { fetch_checkout_pull_branch() { # Check out specified branch - local directory="${1}" - local branch="${2}" + local directory + directory="${1}" + local branch + branch="${2}" # Set the reference for the requested branch, fetch, check it put and pull it - cd "${directory}" + cd "${directory}" || return 1 git remote set-branches origin "${branch}" || return 1 git stash --all --quiet &> /dev/null || true git clean --force -d || true @@ -153,8 +161,10 @@ fetch_checkout_pull_branch() { checkout_pull_branch() { # Check out specified branch - local directory="${1}" - local branch="${2}" + local directory + directory="${1}" + local branch + branch="${2}" local oldbranch cd "${directory}" || return 1 From 8af9853b9a516367031178ba836246f196e1ef55 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Sun, 16 Jul 2017 22:32:34 +1000 Subject: [PATCH 4/6] Fixed minor formatting issues * Removed useless echo * Quoted and braced conditionals * Explicit escaping of newline * Fixed arrays implicitly concatenating (SC2199) * Fixed incorrect variable used in checkout web --- advanced/Scripts/piholeCheckout.sh | 39 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index f9add489..44058111 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -26,7 +26,7 @@ source ${coltable} check_download_exists() { status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1) - if echo "$status" | grep -q "404"; then + if grep -q "404" <<< "$status"; then return 1 else return 0 @@ -74,17 +74,17 @@ get_binary_name() { local str str="Detecting architecture" echo -ne " ${INFO} ${str}..." - if [[ ${machine} == arm* || ${machine} == *aarch* ]]; then + if [[ "${machine}" == "arm"* || "${machine}" == *"aarch"* ]]; then # ARM local rev rev=$(uname -m | sed "s/[^0-9]//g;") local lib lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') - if [[ "$lib" == "/lib/ld-linux-aarch64.so.1" ]]; then + if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then echo -e "${OVER} ${TICK} Detected ARM-aarch64 architecture" binary="pihole-FTL-aarch64-linux-gnu" - elif [[ "$lib" == "/lib/ld-linux-armhf.so.3" ]]; then - if [ "$rev" -gt "6" ]; then + elif [[ "${lib}" == "/lib/ld-linux-armhf.so.3" ]]; then + if [[ "$rev" -gt "6" ]]; then echo -e "${OVER} ${TICK} Detected ARM-hf architecture (armv7+)" binary="pihole-FTL-arm-linux-gnueabihf" else @@ -95,17 +95,17 @@ get_binary_name() { echo -e "${OVER} ${TICK} Detected ARM architecture" binary="pihole-FTL-arm-linux-gnueabi" fi - elif [[ $machine == ppc ]]; then + elif [[ "${machine}" == "ppc" ]]; then # PowerPC - echo "::: Detected PowerPC architecture" + echo -e "${OVER} ${TICK} Detected PowerPC architecture" binary="pihole-FTL-powerpc-linux-gnu" - elif [[ ${machine} == x86_64 ]]; then + elif [[ "${machine}" == "x86_64" ]]; then # 64bit echo -e "${OVER} ${TICK} Detected x86_64 architecture" binary="pihole-FTL-linux-x86_64" else # Something else - we try to use 32bit executable and warn the user - if [[ ! ${machine} == i686 ]]; then + if [[ ! "${machine}" == "i686" ]]; then echo -e "${OVER} ${CROSS} ${str}... ${COL_LIGHT_RED}Not able to detect architecture (unknown: ${machine}), trying 32bit executable Contact support if you experience issues (e.g: FTL not running)${COL_NC}" @@ -182,7 +182,7 @@ checkout_pull_branch() { if [[ "$git_pull" == *"up-to-date"* ]]; then echo -e " ${INFO} $(git pull)" else - echo -e "$git_pull\n" + echo -e "$git_pull\\n" fi return 0 @@ -193,13 +193,13 @@ warning1() { echo " Features that work on the master branch, may not on a development branch" echo -e " ${COL_LIGHT_RED}This feature is NOT supported unless a Pi-hole developer explicitly asks!${COL_NC}" read -r -p " Have you read and understood this? [y/N] " response - case ${response} in + case "${response}" in [yY][eE][sS]|[yY]) echo "" return 0 ;; *) - echo -e "\n ${INFO} Branch change has been cancelled" + echo -e "\\n ${INFO} Branch change has been cancelled" return 1 ;; esac @@ -218,7 +218,7 @@ checkout() { Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}" exit 1; fi - if [[ ${INSTALL_WEB} == "true" ]]; then + if [[ "${INSTALL_WEB}" == "true" ]]; then if ! is_repo "${webInterfaceDir}" ; then echo -e " ${COL_LIGHT_RED}Error: Web Admin repo is missing from system! Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}" @@ -242,7 +242,7 @@ checkout() { echo "" echo -e " ${INFO} Pi-hole Core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo " ${CROSS} Unable to pull Core developement branch"; exit 1; } - if [[ ${INSTALL_WEB} == "true" ]]; then + if [[ "${INSTALL_WEB}" == "true" ]]; then echo "" echo -e " ${INFO} Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; } @@ -263,7 +263,7 @@ checkout() { fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; } fi #echo -e " ${TICK} Web Interface" - get_binary_name + get_binary_name local path path="master/${binary}" FTLinstall "${binary}" "${path}" @@ -276,12 +276,12 @@ checkout() { fi corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) - if [[ "${corebranches[@]}" == *"master"* ]]; then + if [[ "${corebranches[*]}" == *"master"* ]]; then echo -e "${OVER} ${TICK} $str ${INFO} ${#corebranches[@]} branches available for Pi-hole Core" else # Print STDERR output from get_available_branches - echo -e "${OVER} ${CROSS} $str\n\n${corebranches[*]}" + echo -e "${OVER} ${CROSS} $str\\n\\n${corebranches[*]}" exit 1 fi @@ -303,12 +303,12 @@ checkout() { fi webbranches=($(get_available_branches "${webInterfaceDir}")) - if [[ "${corebranches[@]}" == *"master"* ]]; then + if [[ "${webbranches[*]}" == *"master"* ]]; then echo -e "${OVER} ${TICK} $str ${INFO} ${#webbranches[@]} branches available for Web Admin" else # Print STDERR output from get_available_branches - echo -e "${OVER} ${CROSS} $str\n\n${corebranches[*]}" + echo -e "${OVER} ${CROSS} $str\\n\\n${webbranches[*]}" exit 1 fi @@ -322,7 +322,6 @@ checkout() { fi checkout_pull_branch "${webInterfaceDir}" "${2}" elif [[ "${1}" == "ftl" ]] ; then - get_binary_name local path path="${2}/${binary}" From f2e9d585f79f757302eaf7417f6e7209bc848352 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 16 Jul 2017 13:22:59 +0100 Subject: [PATCH 5/6] * Add helptext for `pihole checkout ftl` * Only attempt to install FTL if branch was found * ~~corebranches~~ webbranches (web branches now actually listed) Signed-off-by: Adam Warner --- advanced/Scripts/piholeCheckout.sh | 7 +++---- pihole | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index f9add489..b786ba0c 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -303,12 +303,12 @@ checkout() { fi webbranches=($(get_available_branches "${webInterfaceDir}")) - if [[ "${corebranches[@]}" == *"master"* ]]; then + if [[ "${webbranches[@]}" == *"master"* ]]; then echo -e "${OVER} ${TICK} $str ${INFO} ${#webbranches[@]} branches available for Web Admin" else # Print STDERR output from get_available_branches - echo -e "${OVER} ${CROSS} $str\n\n${corebranches[*]}" + echo -e "${OVER} ${CROSS} $str\n\n${webbranches[*]}" exit 1 fi @@ -329,12 +329,11 @@ checkout() { if check_download_exists "$path"; then echo " ${TICK} Branch ${2} exists" + FTLinstall "${binary}" "${path}" else echo " ${CROSS} Requested branch \"${2}\" is not available" fi - FTLinstall "${binary}" "${path}" - else echo -e " ${INFO} Requested option \"${1}\" is not available" exit 1 diff --git a/pihole b/pihole index 1bd35dbb..8da911d8 100755 --- a/pihole +++ b/pihole @@ -429,15 +429,15 @@ Time: # Enable Pi-hole echo -e " ${INFO} Enabling blocking" local str="Pi-hole Enabled" - + sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf if [[ -e "/etc/pihole/wildcard.list" ]]; then mv "/etc/pihole/wildcard.list" "$wildcardlist" fi fi - + restartDNS - + echo -e "${OVER} ${TICK} ${str}" } @@ -535,6 +535,7 @@ Switch Pi-hole subsystems to a different Github branch Repositories: core [branch] Change the branch of Pi-hole's core subsystem web [branch] Change the branch of Admin Console subsystem + ftl [branch] Change the branch of Pi-hole's FTL subsystem Branches: master Update subsystems to the latest stable release From 247d3ed7299822cad1c3a71a9c999ffd6ff6e8dc Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 16 Jul 2017 13:54:23 +0100 Subject: [PATCH 6/6] list availible branches for FTL Signed-off-by: Adam Warner --- advanced/Scripts/piholeCheckout.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index c6f55dd9..f214d2ce 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -331,6 +331,10 @@ checkout() { FTLinstall "${binary}" "${path}" else echo " ${CROSS} Requested branch \"${2}\" is not available" + ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') ) + echo -e " ${INFO} Available branches for FTL are:" + for e in "${ftlbranches[@]}"; do echo " - $e"; done + exit 1 fi else