mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-22 06:03:43 +00:00
REVISIT: Don't rely on existence of setupVars.conf
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
0e8f285f4f
commit
7cbe713873
5 changed files with 15 additions and 111 deletions
|
@ -104,9 +104,6 @@ main() {
|
|||
web_update=false
|
||||
FTL_update=false
|
||||
|
||||
# shellcheck disable=1090,2154
|
||||
source "${setupVars}"
|
||||
|
||||
# Install packages used by this installation script (necessary if users have removed e.g. git from their systems)
|
||||
package_manager_detect
|
||||
install_dependent_packages "${INSTALLER_DEPS[@]}"
|
||||
|
|
|
@ -162,8 +162,8 @@ getFTLConfigValue(){
|
|||
# Takes two arguments: key and value
|
||||
# Example setFTLConfigValue dns.piholePTR PI.HOLE
|
||||
#
|
||||
# Note, for complex values such as dnsmasq.upstreams, you should wrap the value in single quotes:
|
||||
# setFTLConfigValue dnsmasq.upstreams '[ "8.8.8.8" , "8.8.4.4" ]'
|
||||
# Note, for complex values such as dns.upstreams, you should wrap the value in single quotes:
|
||||
# setFTLConfigValue dns.upstreams '[ "8.8.8.8" , "8.8.4.4" ]'
|
||||
#######################
|
||||
setFTLConfigValue(){
|
||||
pihole-FTL --config "${1}" "${2}" >/dev/null
|
||||
|
|
|
@ -56,8 +56,6 @@ EOM
|
|||
|
||||
# Location for final installation log storage
|
||||
installLogLoc="/etc/pihole/install.log"
|
||||
# This is an important file as it contains information specific to the machine it's being installed on
|
||||
setupVars="/etc/pihole/setupVars.conf"
|
||||
# This is a file used for the colorized output
|
||||
coltable="/opt/pihole/COL_TABLE"
|
||||
|
||||
|
@ -1566,29 +1564,7 @@ create_pihole_user() {
|
|||
fi
|
||||
}
|
||||
|
||||
# This function saves any changes to the setup variables into the setupvars.conf file for future runs
|
||||
finalExports() {
|
||||
# set or update the variables in the file
|
||||
|
||||
addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}"
|
||||
addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}"
|
||||
addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}"
|
||||
addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "${QUERY_LOGGING}"
|
||||
addOrEditKeyValPair "${setupVars}" "CACHE_SIZE" "${CACHE_SIZE}"
|
||||
addOrEditKeyValPair "${setupVars}" "DNS_FQDN_REQUIRED" "${DNS_FQDN_REQUIRED:-true}"
|
||||
addOrEditKeyValPair "${setupVars}" "DNS_BOGUS_PRIV" "${DNS_BOGUS_PRIV:-true}"
|
||||
addOrEditKeyValPair "${setupVars}" "DNSMASQ_LISTENING" "${DNSMASQ_LISTENING:-local}"
|
||||
|
||||
chmod 644 "${setupVars}"
|
||||
|
||||
# Set the privacy level
|
||||
addOrEditKeyValPair "${FTL_CONFIG_FILE}" "PRIVACYLEVEL" "${PRIVACY_LEVEL}"
|
||||
|
||||
# Set the web port
|
||||
addOrEditKeyValPair "${FTL_CONFIG_FILE}" "WEBPORT" "${WEBPORT}"
|
||||
|
||||
# Bring in the current settings and the functions to manipulate them
|
||||
source "${setupVars}"
|
||||
# shellcheck source=advanced/Scripts/webpage.sh
|
||||
source "${PI_HOLE_LOCAL_REPO}/advanced/Scripts/webpage.sh"
|
||||
|
||||
|
@ -1672,7 +1648,6 @@ installPihole() {
|
|||
# install a man page entry for pihole
|
||||
install_manpage
|
||||
|
||||
# Update setupvars.conf with any variables that may or may not have been changed during the install
|
||||
finalExports
|
||||
}
|
||||
|
||||
|
@ -1724,11 +1699,12 @@ checkSelinux() {
|
|||
|
||||
# Installation complete message with instructions for the user
|
||||
displayFinalMessage() {
|
||||
# TODO: COME BACK TO THIS, WHAT IS GOING ON?
|
||||
# If the number of arguments is > 0,
|
||||
if [[ "${#1}" -gt 0 ]] ; then
|
||||
# set the password to the first argument.
|
||||
pwstring="$1"
|
||||
elif [[ $(grep 'WEBPASSWORD' -c "${setupVars}") -gt 0 ]]; then
|
||||
elif [[ $(pihole-FTL --config webserver.api.pwhash) == '""' ]] ; then
|
||||
# Else if the password exists from previous setup, we'll load it later
|
||||
pwstring="unchanged"
|
||||
else
|
||||
|
@ -2242,8 +2218,6 @@ main() {
|
|||
printf " %b Checking for / installing Required dependencies for this install script...\\n" "${INFO}"
|
||||
install_dependent_packages "${INSTALLER_DEPS[@]}"
|
||||
|
||||
# If the setup variable file exists,
|
||||
if [[ -f "${setupVars}" ]]; then
|
||||
# if it's running unattended,
|
||||
if [[ "${runUnattended}" == true ]]; then
|
||||
printf " %b Performing unattended setup, no dialogs will be displayed\\n" "${INFO}"
|
||||
|
@ -2255,7 +2229,6 @@ main() {
|
|||
# If running attended, show the available options (repair/reconfigure)
|
||||
update_dialogs
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${useUpdateVars}" == false ]]; then
|
||||
# Display welcome dialogs
|
||||
|
@ -2279,18 +2252,6 @@ main() {
|
|||
else
|
||||
# Setup adlist file if not exists
|
||||
installDefaultBlocklists
|
||||
|
||||
# Source ${setupVars} to use predefined user variables in the functions
|
||||
source "${setupVars}"
|
||||
|
||||
# Get the privacy level if it exists (default is 0)
|
||||
if [[ -f "${FTL_CONFIG_FILE}" ]]; then
|
||||
# get the value from $FTL_CONFIG_FILE (and ignoring all commented lines)
|
||||
PRIVACY_LEVEL=$(sed -e '/^[[:blank:]]*#/d' "${FTL_CONFIG_FILE}" | grep "PRIVACYLEVEL" | awk -F "=" 'NR==1{printf$2}')
|
||||
|
||||
# If no setting was found, default to 0
|
||||
PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}"
|
||||
fi
|
||||
fi
|
||||
# Download or update the scripts by updating the appropriate git repos
|
||||
clone_or_update_repos
|
||||
|
@ -2327,7 +2288,7 @@ main() {
|
|||
# Add password to web UI if there is none
|
||||
pw=""
|
||||
# If no password is set,
|
||||
if [[ $(pihole-FTL --config webserver.api.pwhash) == "${pw}" ]] ; then
|
||||
if [[ $(pihole-FTL --config webserver.api.pwhash) == '""' ]] ; then
|
||||
# generate a random password
|
||||
pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
|
||||
pihole -a -p "${pw}"
|
||||
|
|
|
@ -4,13 +4,6 @@ import testinfra.backend.docker
|
|||
import subprocess
|
||||
from textwrap import dedent
|
||||
|
||||
|
||||
SETUPVARS = {
|
||||
"PIHOLE_INTERFACE": "eth99",
|
||||
"PIHOLE_DNS_1": "4.2.2.1",
|
||||
"PIHOLE_DNS_2": "4.2.2.2",
|
||||
}
|
||||
|
||||
IMAGE = "pytest_pihole:test_container"
|
||||
|
||||
tick_box = "[\x1b[1;32m\u2713\x1b[0m]"
|
||||
|
|
|
@ -2,7 +2,6 @@ import pytest
|
|||
from textwrap import dedent
|
||||
import re
|
||||
from .conftest import (
|
||||
SETUPVARS,
|
||||
tick_box,
|
||||
info_box,
|
||||
cross_box,
|
||||
|
@ -32,42 +31,6 @@ def test_supported_package_manager(host):
|
|||
# assert package_manager_detect.rc == 1
|
||||
|
||||
|
||||
def test_setupVars_are_sourced_to_global_scope(host):
|
||||
"""
|
||||
currently update_dialogs sources setupVars with a dot,
|
||||
then various other functions use the variables.
|
||||
This confirms the sourced variables are in scope between functions
|
||||
"""
|
||||
setup_var_file = "cat <<EOF> /etc/pihole/setupVars.conf\n"
|
||||
for k, v in SETUPVARS.items():
|
||||
setup_var_file += "{}={}\n".format(k, v)
|
||||
setup_var_file += "EOF\n"
|
||||
host.run(setup_var_file)
|
||||
|
||||
script = dedent(
|
||||
"""\
|
||||
set -e
|
||||
printSetupVars() {
|
||||
# Currently debug test function only
|
||||
echo "Outputting sourced variables"
|
||||
echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}"
|
||||
echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}"
|
||||
echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}"
|
||||
}
|
||||
update_dialogs() {
|
||||
. /etc/pihole/setupVars.conf
|
||||
}
|
||||
update_dialogs
|
||||
printSetupVars
|
||||
"""
|
||||
)
|
||||
|
||||
output = run_script(host, script).stdout
|
||||
|
||||
for k, v in SETUPVARS.items():
|
||||
assert "{}={}".format(k, v) in output
|
||||
|
||||
|
||||
def test_selinux_not_detected(host):
|
||||
"""
|
||||
confirms installer continues when SELinux configuration file does not exist
|
||||
|
@ -116,12 +79,6 @@ def test_installPihole_fresh_install_readableFiles(host):
|
|||
host.run("command -v apt-get > /dev/null && apt-get install -qq man")
|
||||
host.run("command -v dnf > /dev/null && dnf install -y man")
|
||||
host.run("command -v yum > /dev/null && yum install -y man")
|
||||
# create configuration file
|
||||
setup_var_file = "cat <<EOF> /etc/pihole/setupVars.conf\n"
|
||||
for k, v in SETUPVARS.items():
|
||||
setup_var_file += "{}={}\n".format(k, v)
|
||||
setup_var_file += "EOF\n"
|
||||
host.run(setup_var_file)
|
||||
install = host.run(
|
||||
"""
|
||||
export TERM=xterm
|
||||
|
@ -185,10 +142,6 @@ def test_installPihole_fresh_install_readableFiles(host):
|
|||
check_FTLconf = test_cmd.format("w", "/etc/pihole/pihole-FTL.conf", piholeuser)
|
||||
actual_rc = host.run(check_FTLconf).rc
|
||||
assert exit_status_success == actual_rc
|
||||
# readable setupVars.conf
|
||||
check_setup = test_cmd.format("r", "/etc/pihole/setupVars.conf", piholeuser)
|
||||
actual_rc = host.run(check_setup).rc
|
||||
assert exit_status_success == actual_rc
|
||||
# check readable and executable /etc/init.d/pihole-FTL
|
||||
check_init = test_cmd.format("x", "/etc/init.d/pihole-FTL", piholeuser)
|
||||
actual_rc = host.run(check_init).rc
|
||||
|
|
Loading…
Reference in a new issue