mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Factor out downloader from detector function.
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
parent
339f95b00c
commit
87edbeaf58
3 changed files with 38 additions and 74 deletions
|
@ -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
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue