Shuffle some files around, change dependencies to make output clearer, change ::: for [i] to further clarify output.

Allow for  PH_VERBOSE to set -x on all scripts that it would be useful for

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner
2022-08-29 13:17:22 +01:00
parent 2b60df6d2b
commit 97f81bae21
11 changed files with 73 additions and 75 deletions

View File

@@ -1,5 +1,3 @@
#!/command/with-contenv bash #!/command/with-contenv bash
s6-echo "Starting crond"
exec -c exec -c
fdmove -c 2 1 /usr/sbin/cron -f fdmove -c 2 1 /usr/sbin/cron -f

View File

@@ -1,6 +1,8 @@
#!/command/with-contenv bash #!/command/with-contenv bash
s6-echo "Starting lighttpd" if [ "${PH_VERBOSE:-0}" -gt 0 ] ; then
set -x ;
fi
if [[ 1 -eq ${WEBLOGS_STDOUT:-0} ]]; then if [[ 1 -eq ${WEBLOGS_STDOUT:-0} ]]; then
#lighthttpd cannot use /dev/stdout https://redmine.lighttpd.net/issues/2731 #lighthttpd cannot use /dev/stdout https://redmine.lighttpd.net/issues/2731

View File

@@ -1,6 +1,9 @@
#!/command/with-contenv bash #!/command/with-contenv bash
s6-echo "Starting pihole-FTL ($FTL_CMD) as ${DNSMASQ_USER}" if [ "${PH_VERBOSE:-0}" -gt 0 ] ; then
set -x ;
fi
# Remove possible leftovers from previous pihole-FTL processes # Remove possible leftovers from previous pihole-FTL processes
rm -f /dev/shm/FTL-* 2> /dev/null rm -f /dev/shm/FTL-* 2> /dev/null
rm /run/pihole/FTL.sock 2> /dev/null rm /run/pihole/FTL.sock 2> /dev/null

View File

@@ -1,4 +1,9 @@
#!/bin/bash #!/bin/bash
if [ "${PH_VERBOSE:-0}" -gt 0 ] ; then
set -x ;
fi
gravityDBfile="/etc/pihole/gravity.db" gravityDBfile="/etc/pihole/gravity.db"
config_file="/etc/pihole/pihole-FTL.conf" config_file="/etc/pihole/pihole-FTL.conf"
# make a point to mention which config file we're checking, as breadcrumb to revisit if/when pihole-FTL.conf is succeeded by TOML # make a point to mention which config file we're checking, as breadcrumb to revisit if/when pihole-FTL.conf is succeeded by TOML

View File

@@ -11,11 +11,11 @@ fi
# shellcheck source=/dev/null # shellcheck source=/dev/null
SKIP_INSTALL=true . "${PIHOLE_INSTALL}" SKIP_INSTALL=true . "${PIHOLE_INSTALL}"
echo " ::: Starting docker specific checks & setup for docker pihole/pihole" echo " [i] Starting docker specific checks & setup for docker pihole/pihole"
# TODO: # TODO:
#if [ ! -f /.piholeFirstBoot ] ; then #if [ ! -f /.piholeFirstBoot ] ; then
# echo " ::: Not first container startup so not running docker's setup, re-create container to run setup again" # echo " [i] Not first container startup so not running docker's setup, re-create container to run setup again"
#else #else
# regular_setup_functions # regular_setup_functions
#fi #fi
@@ -66,8 +66,12 @@ test_configs
[ -f /.piholeFirstBoot ] && rm /.piholeFirstBoot [ -f /.piholeFirstBoot ] && rm /.piholeFirstBoot
echo "::: Docker start setup complete" echo " [i] Docker start setup complete"
echo ""
pihole -v pihole -v
echo " Container tag is: ${PIHOLE_DOCKER_TAG}" echo " Container tag is: ${PIHOLE_DOCKER_TAG}"
echo ""
echo " [i] pihole-FTL ($FTL_CMD) will be started as ${DNSMASQ_USER}"
echo ""

View File

@@ -13,7 +13,7 @@ modifyUser()
local currentId=$(id -u ${username}) local currentId=$(id -u ${username})
[[ ${currentId} -eq ${newId} ]] && return [[ ${currentId} -eq ${newId} ]] && return
echo "Changing ID for user: ${username} (${currentId} => ${newId})" echo " [i] Changing ID for user: ${username} (${currentId} => ${newId})"
usermod -o -u ${newId} ${username} usermod -o -u ${newId} ${username}
} }
@@ -25,7 +25,7 @@ modifyGroup()
local currentId=$(id -g ${groupname}) local currentId=$(id -g ${groupname})
[[ ${currentId} -eq ${newId} ]] && return [[ ${currentId} -eq ${newId} ]] && return
echo "Changing ID for group: ${groupname} (${currentId} => ${newId})" echo " [i] Changing ID for group: ${groupname} (${currentId} => ${newId})"
groupmod -o -g ${newId} ${groupname} groupmod -o -g ${newId} ${groupname}
} }

View File

@@ -34,7 +34,7 @@ fix_capabilities() {
# Testing on Docker 20.10.14 with no caps set shows the following caps available to the container: # Testing on Docker 20.10.14 with no caps set shows the following caps available to the container:
# Current: cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap=ep # Current: cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap=ep
# FTL can also use CAP_NET_ADMIN and CAP_SYS_NICE. If we try to set them when they haven't been explicitly enabled, FTL will not start. Test for them first: # FTL can also use CAP_NET_ADMIN and CAP_SYS_NICE. If we try to set them when they haven't been explicitly enabled, FTL will not start. Test for them first:
echo " [i] Setting capabilites on pihole-FTL where possible"
/sbin/capsh --has-p=cap_chown 2>/dev/null && CAP_STR+=',CAP_CHOWN' /sbin/capsh --has-p=cap_chown 2>/dev/null && CAP_STR+=',CAP_CHOWN'
/sbin/capsh --has-p=cap_net_bind_service 2>/dev/null && CAP_STR+=',CAP_NET_BIND_SERVICE' /sbin/capsh --has-p=cap_net_bind_service 2>/dev/null && CAP_STR+=',CAP_NET_BIND_SERVICE'
/sbin/capsh --has-p=cap_net_raw 2>/dev/null && CAP_STR+=',CAP_NET_RAW' /sbin/capsh --has-p=cap_net_raw 2>/dev/null && CAP_STR+=',CAP_NET_RAW'
@@ -43,6 +43,8 @@ fix_capabilities() {
if [[ ${CAP_STR} ]]; then if [[ ${CAP_STR} ]]; then
# We have the (some of) the above caps available to us - apply them to pihole-FTL # We have the (some of) the above caps available to us - apply them to pihole-FTL
echo " [i] Applying the following caps to pihole-FTL:"
echo " ${CAP_STR:1}"
setcap ${CAP_STR:1}+ep "$(which pihole-FTL)" || ret=$? setcap ${CAP_STR:1}+ep "$(which pihole-FTL)" || ret=$?
if [[ $DHCP_READY == false ]] && [[ $DHCP_ACTIVE == true ]]; then if [[ $DHCP_READY == false ]] && [[ $DHCP_ACTIVE == true ]]; then
@@ -54,13 +56,13 @@ fix_capabilities() {
fi fi
if [[ $ret -ne 0 && "${DNSMASQ_USER:-pihole}" != "root" ]]; then if [[ $ret -ne 0 && "${DNSMASQ_USER:-pihole}" != "root" ]]; then
echo "ERROR: Unable to set capabilities for pihole-FTL. Cannot run as non-root." echo " [!] ERROR: Unable to set capabilities for pihole-FTL. Cannot run as non-root."
echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'" echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'"
exit 1 exit 1
fi fi
else else
echo "WARNING: Unable to set capabilities for pihole-FTL." echo " [!] WARNING: Unable to set capabilities for pihole-FTL."
echo " Please ensure that the container has the required capabilities." echo " Please ensure that the container has the required capabilities."
exit 1 exit 1
fi fi
} }
@@ -68,7 +70,7 @@ fix_capabilities() {
# shellcheck disable=SC2034 # shellcheck disable=SC2034
ensure_basic_configuration() { ensure_basic_configuration() {
echo " [i] Ensuring basic configuration by re-running select functions from basic-install.sh"
# Set Debian webserver variables for installConfigs # Set Debian webserver variables for installConfigs
LIGHTTPD_USER="www-data" LIGHTTPD_USER="www-data"
LIGHTTPD_GROUP="www-data" LIGHTTPD_GROUP="www-data"
@@ -78,7 +80,7 @@ ensure_basic_configuration() {
if [ ! -f "${setupVars}" ]; then if [ ! -f "${setupVars}" ]; then
install -m 644 /dev/null "${setupVars}" install -m 644 /dev/null "${setupVars}"
echo "Creating empty ${setupVars} file." echo " [i] Creating empty ${setupVars} file."
# The following setting needs to exist else the web interface version won't show in pihole -v # The following setting needs to exist else the web interface version won't show in pihole -v
change_setting "INSTALL_WEB_INTERFACE" "true" change_setting "INSTALL_WEB_INTERFACE" "true"
fi fi
@@ -129,13 +131,13 @@ validate_env() {
# Optional IPv6 is a valid address # Optional IPv6 is a valid address
if [[ -n "$FTLCONF_LOCAL_IPV6" ]] ; then if [[ -n "$FTLCONF_LOCAL_IPV6" ]] ; then
if [[ "$FTLCONF_LOCAL_IPV6" == 'kernel' ]] ; then if [[ "$FTLCONF_LOCAL_IPV6" == 'kernel' ]] ; then
echo "ERROR: You passed in IPv6 with a value of 'kernel', this maybe because you do not have IPv6 enabled on your network" echo " [!] ERROR: You passed in IPv6 with a value of 'kernel', this maybe because you do not have IPv6 enabled on your network"
unset FTLCONF_LOCAL_IPV6 unset FTLCONF_LOCAL_IPV6
exit 1 exit 1
fi fi
if [[ "$(nc -6 -w1 -z "$FTLCONF_LOCAL_IPV6" 53 2>&1)" != "" ]] && ! ip route get "$FTLCONF_LOCAL_IPV6" > /dev/null ; then if [[ "$(nc -6 -w1 -z "$FTLCONF_LOCAL_IPV6" 53 2>&1)" != "" ]] && ! ip route get "$FTLCONF_LOCAL_IPV6" > /dev/null ; then
echo "ERROR: FTLCONF_LOCAL_IPV6 Environment variable ($FTLCONF_LOCAL_IPV6) doesn't appear to be a valid IPv6 address" echo " [!] ERROR: FTLCONF_LOCAL_IPV6 Environment variable ($FTLCONF_LOCAL_IPV6) doesn't appear to be a valid IPv6 address"
echo " TIP: If your server is not IPv6 enabled just remove '-e FTLCONF_LOCAL_IPV6' from your docker container" echo " TIP: If your server is not IPv6 enabled just remove '-e FTLCONF_LOCAL_IPV6' from your docker container"
exit 1 exit 1
fi fi
fi; fi;
@@ -161,12 +163,12 @@ setup_FTL_Interface(){
if [ "$interface" != 'eth0' ] ; then if [ "$interface" != 'eth0' ] ; then
interfaceType='custom' interfaceType='custom'
fi; fi;
echo "FTL binding to $interfaceType interface: $interface" echo " [i] FTL binding to $interfaceType interface: $interface"
change_setting "PIHOLE_INTERFACE" "${interface}" change_setting "PIHOLE_INTERFACE" "${interface}"
} }
setup_FTL_CacheSize() { setup_FTL_CacheSize() {
local warning="WARNING: CUSTOM_CACHE_SIZE not used" local warning=" [i] WARNING: CUSTOM_CACHE_SIZE not used"
local dnsmasq_pihole_01_location="/etc/dnsmasq.d/01-pihole.conf" local dnsmasq_pihole_01_location="/etc/dnsmasq.d/01-pihole.conf"
# Quietly exit early for empty or default # Quietly exit early for empty or default
if [[ -z "${CUSTOM_CACHE_SIZE}" || "${CUSTOM_CACHE_SIZE}" == '10000' ]] ; then return ; fi if [[ -z "${CUSTOM_CACHE_SIZE}" || "${CUSTOM_CACHE_SIZE}" == '10000' ]] ; then return ; fi
@@ -186,7 +188,7 @@ setup_FTL_CacheSize() {
echo "$warning - $custom_cache_size is not a positive integer or zero" echo "$warning - $custom_cache_size is not a positive integer or zero"
return return
fi fi
echo "Custom CUSTOM_CACHE_SIZE set to $custom_cache_size" echo " [i] Custom CUSTOM_CACHE_SIZE set to $custom_cache_size"
change_setting "CACHE_SIZE" "$custom_cache_size" change_setting "CACHE_SIZE" "$custom_cache_size"
sed -i "s/^cache-size=\s*[0-9]*/cache-size=$custom_cache_size/" ${dnsmasq_pihole_01_location} sed -i "s/^cache-size=\s*[0-9]*/cache-size=$custom_cache_size/" ${dnsmasq_pihole_01_location}
@@ -198,14 +200,14 @@ apply_FTL_Configs_From_Env(){
# setting defined here: https://docs.pi-hole.net/ftldns/configfile/ # setting defined here: https://docs.pi-hole.net/ftldns/configfile/
declare -px | grep FTLCONF_ | sed -E 's/declare -x FTLCONF_([^=]+)=\"(.+)\"/\1 \2/' | while read -r name value declare -px | grep FTLCONF_ | sed -E 's/declare -x FTLCONF_([^=]+)=\"(.+)\"/\1 \2/' | while read -r name value
do do
echo "Applying pihole-FTL.conf setting $name=$value" echo " [i] Applying pihole-FTL.conf setting $name=$value"
changeFTLsetting "$name" "$value" changeFTLsetting "$name" "$value"
done done
} }
setup_FTL_dhcp() { setup_FTL_dhcp() {
if [ -z "${DHCP_START}" ] || [ -z "${DHCP_END}" ] || [ -z "${DHCP_ROUTER}" ]; then if [ -z "${DHCP_START}" ] || [ -z "${DHCP_END}" ] || [ -z "${DHCP_ROUTER}" ]; then
echo "ERROR: Won't enable DHCP server because mandatory Environment variables are missing: DHCP_START, DHCP_END and/or DHCP_ROUTER" echo " [!] ERROR: Won't enable DHCP server because mandatory Environment variables are missing: DHCP_START, DHCP_END and/or DHCP_ROUTER"
change_setting "DHCP_ACTIVE" "false" change_setting "DHCP_ACTIVE" "false"
else else
change_setting "DHCP_ACTIVE" "${DHCP_ACTIVE}" change_setting "DHCP_ACTIVE" "${DHCP_ACTIVE}"
@@ -221,14 +223,14 @@ setup_FTL_dhcp() {
setup_FTL_query_logging(){ setup_FTL_query_logging(){
if [ "${QUERY_LOGGING_OVERRIDE}" == "false" ]; then if [ "${QUERY_LOGGING_OVERRIDE}" == "false" ]; then
echo "::: Disabling Query Logging" echo " [i] Disabling Query Logging"
change_setting "QUERY_LOGGING" "$QUERY_LOGGING_OVERRIDE" change_setting "QUERY_LOGGING" "$QUERY_LOGGING_OVERRIDE"
removeKey "${dnsmasqconfig}" log-queries removeKey "${dnsmasqconfig}" log-queries
else else
# If it is anything other than false, set it to true # If it is anything other than false, set it to true
change_setting "QUERY_LOGGING" "true" change_setting "QUERY_LOGGING" "true"
# Set pihole logging on for good measure # Set pihole logging on for good measure
echo "::: Enabling Query Logging" echo " [i] Enabling Query Logging"
addKey "${dnsmasqconfig}" log-queries addKey "${dnsmasqconfig}" log-queries
fi fi
@@ -255,13 +257,13 @@ setup_FTL_upstream_DNS(){
# For backward compatibility, if DNS1 and/or DNS2 are set, but PIHOLE_DNS_ is not, convert them to # For backward compatibility, if DNS1 and/or DNS2 are set, but PIHOLE_DNS_ is not, convert them to
# a semi-colon delimited string and store in PIHOLE_DNS_ # a semi-colon delimited string and store in PIHOLE_DNS_
# They are not used anywhere if PIHOLE_DNS_ is set already # They are not used anywhere if PIHOLE_DNS_ is set already
[ -n "${DNS1}" ] && echo "Converting DNS1 to PIHOLE_DNS_" && PIHOLE_DNS_="$DNS1" [ -n "${DNS1}" ] && echo " [i] Converting DNS1 to PIHOLE_DNS_" && PIHOLE_DNS_="$DNS1"
[[ -n "${DNS2}" && "${DNS2}" != "no" ]] && echo "Converting DNS2 to PIHOLE_DNS_" && PIHOLE_DNS_="$PIHOLE_DNS_;$DNS2" [[ -n "${DNS2}" && "${DNS2}" != "no" ]] && echo " [i] Converting DNS2 to PIHOLE_DNS_" && PIHOLE_DNS_="$PIHOLE_DNS_;$DNS2"
fi fi
# Parse the PIHOLE_DNS variable, if it exists, and apply upstream servers to Pi-hole config # Parse the PIHOLE_DNS variable, if it exists, and apply upstream servers to Pi-hole config
if [ -n "${PIHOLE_DNS_}" ]; then if [ -n "${PIHOLE_DNS_}" ]; then
echo "Setting DNS servers based on PIHOLE_DNS_ variable" echo " [i] Setting DNS servers based on PIHOLE_DNS_ variable"
# Remove any PIHOLE_DNS_ entries from setupVars.conf, if they exist # Remove any PIHOLE_DNS_ entries from setupVars.conf, if they exist
sed -i '/PIHOLE_DNS_/d' /etc/pihole/setupVars.conf sed -i '/PIHOLE_DNS_/d' /etc/pihole/setupVars.conf
# Split into an array (delimited by ;) # Split into an array (delimited by ;)
@@ -295,12 +297,12 @@ setup_FTL_upstream_DNS(){
fi fi
fi fi
# If the above tests fail then this is an invalid DNS server # If the above tests fail then this is an invalid DNS server
echo "Invalid entry detected in PIHOLE_DNS_: ${i}" echo " [!] Invalid entry detected in PIHOLE_DNS_: ${i}"
fi fi
done done
if [ $valid_entries -eq 0 ]; then if [ $valid_entries -eq 0 ]; then
echo "No Valid entries detected in PIHOLE_DNS_. Aborting" echo " [!] No Valid entries detected in PIHOLE_DNS_. Aborting"
exit 1 exit 1
fi fi
else else
@@ -310,11 +312,11 @@ setup_FTL_upstream_DNS(){
setupVarsDNS="$(grep 'PIHOLE_DNS_' /etc/pihole/setupVars.conf || true)" setupVarsDNS="$(grep 'PIHOLE_DNS_' /etc/pihole/setupVars.conf || true)"
if [ -z "${setupVarsDNS}" ]; then if [ -z "${setupVarsDNS}" ]; then
echo "Configuring default DNS servers: 8.8.8.8, 8.8.4.4" echo " [i] Configuring default DNS servers: 8.8.8.8, 8.8.4.4"
change_setting "PIHOLE_DNS_1" "8.8.8.8" change_setting "PIHOLE_DNS_1" "8.8.8.8"
change_setting "PIHOLE_DNS_2" "8.8.4.4" change_setting "PIHOLE_DNS_2" "8.8.4.4"
else else
echo "Existing DNS servers detected in setupVars.conf. Leaving them alone" echo " [i] Existing DNS servers detected in setupVars.conf. Leaving them alone"
fi fi
fi fi
} }
@@ -353,12 +355,12 @@ setup_web_php_env() {
fi fi
done done
echo "Added ENV to php:" echo " [i] Added ENV to php:"
grep -E '(VIRTUAL_HOST|CORS_HOSTS|PHP_ERROR_LOG|PIHOLE_DOCKER_TAG|TZ)' "$PHP_ENV_CONFIG" grep -E '(VIRTUAL_HOST|CORS_HOSTS|PHP_ERROR_LOG|PIHOLE_DOCKER_TAG|TZ)' "$PHP_ENV_CONFIG"
} }
setup_web_port() { setup_web_port() {
local warning="WARNING: Custom WEB_PORT not used" local warning=" [!] WARNING: Custom WEB_PORT not used"
# Quietly exit early for empty or default # Quietly exit early for empty or default
if [[ -z "${WEB_PORT}" || "${WEB_PORT}" == '80' ]] ; then return ; fi if [[ -z "${WEB_PORT}" || "${WEB_PORT}" == '80' ]] ; then return ; fi
@@ -372,8 +374,8 @@ setup_web_port() {
echo "$warning - $web_port is not within valid port range of 1-65535" echo "$warning - $web_port is not within valid port range of 1-65535"
return return
fi fi
echo "Custom WEB_PORT set to $web_port" echo " [i] Custom WEB_PORT set to $web_port"
echo "INFO: Without proper router DNAT forwarding to $FTLCONF_LOCAL_IPV4:$web_port, you may not get any blocked websites on ads" echo " [i] Without proper router DNAT forwarding to $FTLCONF_LOCAL_IPV4:$web_port, you may not get any blocked websites on ads"
# Update lighttpd's port # Update lighttpd's port
sed -i '/server.port\s*=\s*80\s*$/ s/80/'"${WEB_PORT}"'/g' /etc/lighttpd/lighttpd.conf sed -i '/server.port\s*=\s*80\s*$/ s/80/'"${WEB_PORT}"'/g' /etc/lighttpd/lighttpd.conf
@@ -386,11 +388,11 @@ setup_web_theme(){
if [ -n "${WEBTHEME}" ]; then if [ -n "${WEBTHEME}" ]; then
case "${WEBTHEME}" in case "${WEBTHEME}" in
"default-dark" | "default-darker" | "default-light" | "default-auto" | "lcars") "default-dark" | "default-darker" | "default-light" | "default-auto" | "lcars")
echo "Setting Web Theme based on WEBTHEME variable, using value ${WEBTHEME}" echo " [i] Setting Web Theme based on WEBTHEME variable, using value ${WEBTHEME}"
change_setting "WEBTHEME" "${WEBTHEME}" change_setting "WEBTHEME" "${WEBTHEME}"
;; ;;
*) *)
echo "Invalid theme name supplied: ${WEBTHEME}, falling back to default-light." echo " [!] Invalid theme name supplied: ${WEBTHEME}, falling back to default-light."
change_setting "WEBTHEME" "default-light" change_setting "WEBTHEME" "default-light"
;; ;;
esac esac
@@ -413,10 +415,10 @@ setup_web_password() {
setup_var_exists "WEBPASSWORD" && return setup_var_exists "WEBPASSWORD" && return
# Generate new random password # Generate new random password
WEBPASSWORD=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) WEBPASSWORD=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
echo "Assigning random password: $WEBPASSWORD" echo " [i] Assigning random password: $WEBPASSWORD"
else else
# ENV WEBPASSWORD_OVERRIDE is set and will be used # ENV WEBPASSWORD_OVERRIDE is set and will be used
echo "::: Assigning password defined by Environment Variable" echo " [i] Assigning password defined by Environment Variable"
# WEBPASSWORD="$WEBPASSWORD" # WEBPASSWORD="$WEBPASSWORD"
fi fi
@@ -442,15 +444,15 @@ setup_ipv4_ipv6() {
ip_versions="IPv4" ip_versions="IPv4"
sed -i '/use-ipv6.pl/ d' /etc/lighttpd/lighttpd.conf sed -i '/use-ipv6.pl/ d' /etc/lighttpd/lighttpd.conf
fi; fi;
echo "Using $ip_versions" echo " [i] Using $ip_versions"
} }
test_configs() { test_configs() {
set -e set -e
echo -n '::: Testing lighttpd config: ' echo -n ' [i] Testing lighttpd config: '
lighttpd -t -f /etc/lighttpd/lighttpd.conf || exit 1 lighttpd -t -f /etc/lighttpd/lighttpd.conf || exit 1
set +e set +e
echo "::: All config checks passed, cleared for startup ..." echo " [i] All config checks passed, cleared for startup ..."
} }
setup_blocklists() { setup_blocklists() {
@@ -459,22 +461,21 @@ setup_blocklists() {
exit_string="(exiting ${FUNCNAME[0]} early)" exit_string="(exiting ${FUNCNAME[0]} early)"
if [ -n "${skip_setup_blocklists}" ]; then if [ -n "${skip_setup_blocklists}" ]; then
echo "::: skip_setup_blocklists requested ($exit_string)" echo " [i] skip_setup_blocklists requested $exit_string"
return return
fi fi
# 2. The adlist file exists already (restarted container or volume mounted list) # 2. The adlist file exists already (restarted container or volume mounted list)
if [ -f "${adlistFile}" ]; then if [ -f "${adlistFile}" ]; then
echo "::: Preexisting ad list ${adlistFile} detected ($exit_string)" echo " [i] Preexisting ad list ${adlistFile} detected $exit_string"
cat "${adlistFile}"
return return
fi fi
echo "::: ${FUNCNAME[0]} now setting default blocklists up: " echo " [i] ${FUNCNAME[0]} now setting default blocklists up: "
echo "::: TIP: Use a docker volume for ${adlistFile} if you want to customize for first boot" echo " [i] TIP: Use a docker volume for ${adlistFile} if you want to customize for first boot"
installDefaultBlocklists installDefaultBlocklists
echo "::: Blocklists (${adlistFile}) now set to:" echo " [i] Blocklists (${adlistFile}) now set to:"
cat "${adlistFile}" cat "${adlistFile}"
} }
@@ -484,7 +485,7 @@ setup_var_exists() {
local REQUIRED_VALUE="[^\n]+" local REQUIRED_VALUE="[^\n]+"
fi fi
if grep -Pq "^${KEY}=${REQUIRED_VALUE}" "$setupVars"; then if grep -Pq "^${KEY}=${REQUIRED_VALUE}" "$setupVars"; then
echo "::: Pre existing ${KEY} found" echo " [i] Pre existing ${KEY} found"
true true
else else
false false

View File

@@ -1,15 +0,0 @@
#!/bin/bash
# A shim to make busybox timeout take in debian style args
# v1 only need support for this style: `timeout 1 getent hosts github.com`
# Busybox args:
# Usage: timeout [-t SECS] [-s SIG] PROG ARGS
# Debian args:
# Usage: timeout [OPTION] DURATION COMMAND [ARG]...
# or: timeout [OPTION]
TIMEOUT=/usr/bin/timeout
SECS="${1}"
ARGS="${@:2}"
$TIMEOUT -t $SECS $ARGS

View File

@@ -22,7 +22,7 @@ def run_and_stream_command_output():
print(line, end='') print(line, end='')
build_result.wait() build_result.wait()
if build_result.returncode != 0: if build_result.returncode != 0:
print(f' ::: Error running: {command}') print(f' [i] Error running: {command}')
print(build_result.stderr) print(build_result.stderr)
return run_and_stream_command_output_inner return run_and_stream_command_output_inner

View File

@@ -26,7 +26,7 @@ def test_ipv6_not_true_removes_ipv6(docker, slow, test_args, expected_ipv6, expe
IPV6_LINE = 'use-ipv6.pl' IPV6_LINE = 'use-ipv6.pl'
WEB_CONFIG = '/etc/lighttpd/lighttpd.conf' WEB_CONFIG = '/etc/lighttpd/lighttpd.conf'
function = docker.run('. /bash_functions.sh ; setup_ipv4_ipv6') function = docker.run('. /usr/local/bin/bash_functions.sh ; setup_ipv4_ipv6')
assert "Using {}".format(expected_stdout) in function.stdout assert "Using {}".format(expected_stdout) in function.stdout
if expected_stdout == 'IPv4': if expected_stdout == 'IPv4':
assert 'IPv6' not in function.stdout assert 'IPv6' not in function.stdout
@@ -43,9 +43,9 @@ def test_overrides_default_web_port(docker, slow, test_args):
CONFIG_LINE = r'server.port\s*=\s*999' CONFIG_LINE = r'server.port\s*=\s*999'
WEB_CONFIG = '/etc/lighttpd/lighttpd.conf' WEB_CONFIG = '/etc/lighttpd/lighttpd.conf'
function = docker.run('. /bash_functions.sh ; eval `grep setup_web_port /usr/local/bin/_startup.sh`') function = docker.run('. /usr/local/bin/bash_functions.sh ; eval `grep setup_web_port /usr/local/bin/_startup.sh`')
assert "Custom WEB_PORT set to 999" in function.stdout assert " [i] Custom WEB_PORT set to 999" in function.stdout
assert "INFO: Without proper router DNAT forwarding to 127.0.0.1:999, you may not get any blocked websites on ads" in function.stdout assert " [i] Without proper router DNAT forwarding to 127.0.0.1:999, you may not get any blocked websites on ads" in function.stdout
slow(lambda: re.search(CONFIG_LINE, docker.run(_cat(WEB_CONFIG)).stdout) != None) slow(lambda: re.search(CONFIG_LINE, docker.run(_cat(WEB_CONFIG)).stdout) != None)
@@ -55,7 +55,7 @@ def test_overrides_default_web_port(docker, slow, test_args):
('-e WEB_PORT="99999"', 'WARNING: Custom WEB_PORT not used - 99999 is not within valid port range of 1-65535'), ('-e WEB_PORT="99999"', 'WARNING: Custom WEB_PORT not used - 99999 is not within valid port range of 1-65535'),
]) ])
def test_bad_input_to_web_port(docker, test_args, expected_error): def test_bad_input_to_web_port(docker, test_args, expected_error):
function = docker.run('. /bash_functions.sh ; eval `grep setup_web_port /usr/local/bin/_startup.sh`') function = docker.run('. /usr/local/bin/bash_functions.sh ; eval `grep setup_web_port /usr/local/bin/_startup.sh`')
assert expected_error in function.stdout assert expected_error in function.stdout
@@ -64,7 +64,7 @@ def test_overrides_default_custom_cache_size(docker, slow, test_args, cache_size
''' Changes the cache_size setting to increase or decrease the cache size for dnsmasq''' ''' Changes the cache_size setting to increase or decrease the cache size for dnsmasq'''
CONFIG_LINE = r'cache-size\s*=\s*{}'.format(cache_size) CONFIG_LINE = r'cache-size\s*=\s*{}'.format(cache_size)
function = docker.run('echo ${CUSTOM_CACHE_SIZE};. ./bash_functions.sh; echo ${CUSTOM_CACHE_SIZE}; eval `grep setup_FTL_CacheSize /usr/local/bin/_startup.sh`') function = docker.run('echo ${CUSTOM_CACHE_SIZE};. ./usr/local/bin/bash_functions.sh; echo ${CUSTOM_CACHE_SIZE}; eval `grep setup_FTL_CacheSize /usr/local/bin/_startup.sh`')
assert "Custom CUSTOM_CACHE_SIZE set to {}".format(cache_size) in function.stdout assert "Custom CUSTOM_CACHE_SIZE set to {}".format(cache_size) in function.stdout
slow(lambda: re.search(CONFIG_LINE, docker.run(_cat(DNSMASQ_CONFIG_LOC)).stdout) != None) slow(lambda: re.search(CONFIG_LINE, docker.run(_cat(DNSMASQ_CONFIG_LOC)).stdout) != None)
@@ -113,7 +113,7 @@ expected_debian_lines = [
def test_debian_setup_php_env(docker, expected_lines, repeat_function): def test_debian_setup_php_env(docker, expected_lines, repeat_function):
''' confirm all expected output is there and nothing else ''' ''' confirm all expected output is there and nothing else '''
for _ in range(repeat_function): for _ in range(repeat_function):
docker.run('. /bash_functions.sh ; eval `grep setup_php_env /usr/local/bin/_startup.sh`').stdout docker.run('. /usr/local/bin/bash_functions.sh ; eval `grep setup_php_env /usr/local/bin/_startup.sh`').stdout
for expected_line in expected_lines: for expected_line in expected_lines:
search_config_cmd = "grep -c '{}' /etc/lighttpd/conf-enabled/15-fastcgi-php.conf".format(expected_line) search_config_cmd = "grep -c '{}' /etc/lighttpd/conf-enabled/15-fastcgi-php.conf".format(expected_line)
search_config_count = docker.run(search_config_cmd) search_config_count = docker.run(search_config_cmd)
@@ -152,7 +152,7 @@ def test_env_always_updates_password(docker, args_env, test_args):
'''When a user sets the WEBPASSWORD environment variable, ensure it always sets the password''' '''When a user sets the WEBPASSWORD environment variable, ensure it always sets the password'''
function = docker.run(CMD_SETUP_WEB_PASSWORD) function = docker.run(CMD_SETUP_WEB_PASSWORD)
assert '::: Assigning password defined by Environment Variable' in function.stdout assert ' [i] Assigning password defined by Environment Variable' in function.stdout
@pytest.mark.parametrize('entrypoint,cmd', [('--entrypoint=tail','-f /dev/null')]) @pytest.mark.parametrize('entrypoint,cmd', [('--entrypoint=tail','-f /dev/null')])