From 87edbeaf5812d229ac4c931cbfa72448934f2818 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 08:24:19 -0800 Subject: [PATCH] Factor out downloader from detector function. Signed-off-by: Dan Schaper --- .pullapprove.yml | 38 ------------------ automated install/basic-install.sh | 64 +++++++++++++++--------------- test/test_automated_install.py | 10 ++--- 3 files changed, 38 insertions(+), 74 deletions(-) delete mode 100644 .pullapprove.yml diff --git a/.pullapprove.yml b/.pullapprove.yml deleted file mode 100644 index f9d10062..00000000 --- a/.pullapprove.yml +++ /dev/null @@ -1,38 +0,0 @@ -version: 2 - -always_pending: - title_regex: '(WIP|wip)' - labels: - - wip - explanation: 'This PR is a work in progress...' - -group_defaults: - reset_on_push: - enabled: true - reject_value: -2 - approve_regex: '^(Approved|:shipit:|:\+1:|Engage)' - reject_regex: '^(Rejected|:-1:|Borg)' - author_approval: - auto: true - - -groups: - development: - approve_by_comment: - enabled: true - conditions: - branches: - - development - required: 2 - teams: - - approvers - - master: - approve_by_comment: - enabled: true - conditions: - branches: - - master - required: -1 - teams: - - admin diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index dc302f48..aead0583 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1026,9 +1026,7 @@ installPihole() { fi installCron installLogrotate - if FTLdownload; then - FTLinstall - fi + FTLdetect || echo "::: FTL Engine not installed." configureFirewall finalExports #runGravity @@ -1060,9 +1058,7 @@ updatePihole() { fi installCron installLogrotate - if FTLdownload; then - FTLinstall - fi + FTLdetect || echo "::: FTL Engine not installed." finalExports #re-export setupVars.conf to account for any new vars added in new versions #runGravity } @@ -1156,12 +1152,40 @@ if [[ "${reconfigure}" == true ]]; then fi } -FTLdownload() { +FTLinstall() { + # Download and Install FTL binary + local binary="${1}" + local latesttag + echo ":::" + echo -n "::: Installing FTL ... " + + latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") + if [ ! "${latesttag}" ]; then + echo "::: failed (error in getting latest release tag from GitHub)" + return 1 + fi + if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL"; then + echo "::: done" + install -m 0755 /opt/pihole/pihole-FTL /usr/bin + touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + return 0 + else + echo "::: failed (download of binary from Github failed)" + return 1 + fi + echo "done" +} + +FTLdetect() { # Download suitable FTL binary echo ":::" echo "::: Downloading latest version of FTL..." - local machine=$(arch) + local machine + local binary + + machine=$(arch) if [[ $machine == arm* || $machine == *aarch* ]]; then # ARM @@ -1198,30 +1222,8 @@ FTLdownload() { binary="pihole-FTL-linux-x86_32" fi - latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") - if [ ! "${latesttag}" ]; then - echo "::: failed (error in getting latest release tag from GitHub)" - return 1 - fi - if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL"; then - echo "::: done" - return 0 - else - echo "::: failed (download of binary from Github failed)" - return 1 - fi -} + FTLinstall "${binary}" || return 1 -FTLinstall() { - # Install FTL binary - echo ":::" - echo -n "::: Installing FTL ... " - - install -m 0755 /opt/pihole/pihole-FTL /usr/bin - touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port - chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port - - echo "done" } main() { diff --git a/test/test_automated_install.py b/test/test_automated_install.py index a4488239..b0dded5c 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -305,7 +305,7 @@ def test_FTL_detect_aarch64_no_errors(Pihole): mock_command('ldd', {'/bin/ls':('/lib/ld-linux-aarch64.so.1', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected ARM-aarch64 architecture' assert expected_stdout in detectPlatform.stdout @@ -318,7 +318,7 @@ def test_FTL_detect_armv6l_no_errors(Pihole): mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected ARM-hf architecture (armv6 or lower)' assert expected_stdout in detectPlatform.stdout @@ -331,7 +331,7 @@ def test_FTL_detect_armv7l_no_errors(Pihole): mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected ARM-hf architecture (armv7+)' assert expected_stdout in detectPlatform.stdout @@ -340,7 +340,7 @@ def test_FTL_detect_x86_64_no_errors(Pihole): ''' confirms only x86_64 package is downloaded for FTL engine ''' detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected x86_64 architecture' assert expected_stdout in detectPlatform.stdout @@ -351,7 +351,7 @@ def test_FTL_detect_unknown_no_errors(Pihole): mock_command('arch', {'*':('mips', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Not able to detect architecture (unknown: mips)' assert expected_stdout in detectPlatform.stdout