Merge branch 'release/v4.2' into development

# Conflicts:
#	automated install/basic-install.sh
This commit is contained in:
Mcat12 2019-02-03 11:14:09 -08:00
commit 680d6e2d31
No known key found for this signature in database
GPG key ID: ABB8FC9789AF524D
5 changed files with 72 additions and 35 deletions

View file

@ -167,7 +167,7 @@ checkout() {
echo " ${TICK} Branch ${2} exists"
echo "${2}" > /etc/pihole/ftlbranch
FTLinstall "${binary}"
start_service pihole-FTL
restart_service pihole-FTL
enable_service pihole-FTL
else
echo " ${CROSS} Requested branch \"${2}\" is not available"

View file

@ -76,7 +76,7 @@ WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd"
HTML_DIRECTORY="/var/www/html"
WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin"
#BLOCK_PAGE_DIRECTORY="${HTML_DIRECTORY}/pihole"
SHM_DIRECTORY="/var/run/shm"
SHM_DIRECTORY="/dev/shm"
# Files required by Pi-hole
# https://discourse.pi-hole.net/t/what-files-does-pi-hole-use/1684

View file

@ -129,6 +129,9 @@ else
OVER="\\r\\033[K"
fi
# Define global binary variable
binary="tbd"
# A simple function that just echoes out our logo in ASCII format
# This lets users know that it is a Pi-hole, LLC product
show_ascii_berry() {
@ -1442,9 +1445,9 @@ stop_service() {
}
# Start/Restart service passed in as argument
start_service() {
restart_service() {
# Local, named variables
local str="Starting ${1} service"
local str="Restarting ${1} service"
printf " %b %s..." "${INFO}" "${str}"
# If systemctl exists,
if is_command systemctl ; then
@ -1914,8 +1917,9 @@ installPihole() {
installCron
# Install the logrotate file
installLogrotate
# Check if FTL is installed
FTLdetect || printf " %b FTL Engine not installed\\n" "${CROSS}"
# Check if dnsmasq is present. If so, disable it and back up any possible
# config file
disable_dnsmasq
# Configure the firewall
if [[ "${useUpdateVars}" == false ]]; then
configureFirewall
@ -2138,7 +2142,6 @@ clone_or_update_repos() {
# Download FTL binary to random temp directory and install FTL binary
FTLinstall() {
# Local, named variables
local binary="${1}"
local latesttag
local str="Downloading and Installing FTL"
printf " %b %s..." "${INFO}" "${str}"
@ -2186,14 +2189,37 @@ FTLinstall() {
# Before stopping FTL, we download the macvendor database
curl -sSL "https://ftl.pi-hole.net/macvendor.db" -o "${PI_HOLE_CONFIG_DIR}/macvendor.db" || true
# Stop FTL
# Stop pihole-FTL service if available
stop_service pihole-FTL &> /dev/null
# Install the new version with the correct permissions
install -T -m 0755 "${binary}" /usr/bin/pihole-FTL
# Move back into the original directory the user was in
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; }
# Install the FTL service
# Installed the FTL service
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
return 0
# Otherwise,
else
# the download failed, so just go back to the original directory
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; }
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
printf " %bError: Download of %s/%s failed (checksum error)%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}"
return 1
fi
# Otherwise,
else
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; }
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
# The URL could not be found
printf " %bError: URL %s/%s not found%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}"
return 1
fi
}
disable_dnsmasq() {
# dnsmasq can now be stopped and disabled if it exists
if which dnsmasq &> /dev/null; then
if check_service_active "dnsmasq";then
@ -2212,24 +2238,6 @@ FTLinstall() {
fi
# Create /etc/dnsmasq.conf
echo "conf-dir=/etc/dnsmasq.d" > "${conffile}"
return 0
# Otherwise,
else
# the download failed, so just go back to the original directory
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; }
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
printf " %bError: Download of %s/%s failed (checksum error)%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}"
return 1
fi
# Otherwise,
else
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; }
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
# The URL could not be found
printf " %bError: URL %s/%s not found%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}"
return 1
fi
}
get_binary_name() {
@ -2389,7 +2397,7 @@ FTLdetect() {
printf "\\n %b FTL Checks...\\n\\n" "${INFO}"
if FTLcheckUpdate ; then
FTLinstall "${binary}" || return 1
FTLinstall || return 1
fi
}
@ -2549,6 +2557,11 @@ main() {
else
LIGHTTPD_ENABLED=false
fi
# Check if FTL is installed - do this early on as FTL is a hard dependency for Pi-hole
if ! FTLdetect; then
printf " %b FTL Engine not installed\\n" "${CROSS}"
exit 1
fi
# Install and log everything to a file
installPihole | tee -a /proc/$$/fd/3
@ -2579,7 +2592,7 @@ main() {
if [[ "${INSTALL_WEB_SERVER}" == true ]]; then
if [[ "${LIGHTTPD_ENABLED}" == true ]]; then
start_service lighttpd
restart_service lighttpd
enable_service lighttpd
else
printf " %b Lighttpd is disabled, skipping service restart\\n" "${INFO}"
@ -2594,7 +2607,7 @@ main() {
# Fixes a problem reported on Ubuntu 18.04 where trying to start
# the service before enabling causes installer to exit
enable_service pihole-FTL
start_service pihole-FTL
restart_service pihole-FTL
# Download and compile the aggregated block list
runGravity

8
pihole
View file

@ -144,6 +144,10 @@ Time:
elif [[ "${1}" == "0" ]]; then
# Disable Pi-hole
if grep -cq "BLOCKING_ENABLED=false" "${setupVars}"; then
echo -e " ${INFO} Blocking already disabled, nothing to do"
exit 0
fi
if [[ -e "${gravitylist}" ]]; then
mv "${gravitylist}" "${gravitylist}.bck"
echo "" > "${gravitylist}"
@ -193,6 +197,10 @@ Time:
fi
else
# Enable Pi-hole
if grep -cq "BLOCKING_ENABLED=true" "${setupVars}"; then
echo -e " ${INFO} Blocking already enabled, nothing to do"
exit 0
fi
echo -e " ${INFO} Enabling blocking"
local str="Pi-hole Enabled"

View file

@ -481,10 +481,10 @@ def test_FTL_download_aarch64_no_errors(Pihole):
'''
confirms only aarch64 package is downloaded for FTL engine
'''
# mock uname to return generic platform
download_binary = Pihole.run('''
source /opt/pihole/basic-install.sh
FTLinstall pihole-FTL-aarch64-linux-gnu
binary="pihole-FTL-aarch64-linux-gnu"
FTLinstall
''')
expected_stdout = tick_box + ' Downloading and Installing FTL'
assert expected_stdout in download_binary.stdout
@ -495,10 +495,26 @@ def test_FTL_download_unknown_fails_no_errors(Pihole):
'''
confirms unknown binary is not downloaded for FTL engine
'''
# mock uname to return generic platform
download_binary = Pihole.run('''
source /opt/pihole/basic-install.sh
FTLinstall pihole-FTL-mips
binary="pihole-FTL-mips"
FTLinstall
''')
expected_stdout = cross_box + ' Downloading and Installing FTL'
assert expected_stdout in download_binary.stdout
error1 = 'Error: URL https://github.com/pi-hole/FTL/releases/download/'
assert error1 in download_binary.stdout
error2 = 'not found'
assert error2 in download_binary.stdout
def test_FTL_download_binary_unset_no_errors(Pihole):
'''
confirms unset binary variable does not download FTL engine
'''
download_binary = Pihole.run('''
source /opt/pihole/basic-install.sh
FTLinstall
''')
expected_stdout = cross_box + ' Downloading and Installing FTL'
assert expected_stdout in download_binary.stdout