Fix #364
Signed-off-by: Adam Hill <adam@diginc.us> Signed-off-by: Martin Buchleitner <mabunixda@gmail.com>
This commit is contained in:
parent
41289bdd58
commit
8ce0aafcd3
|
@ -1,4 +1,6 @@
|
|||
#!/bin/bash
|
||||
# Some of the bash_functions use variables these core pi-hole/web scripts
|
||||
. /opt/pihole/webpage.sh
|
||||
|
||||
docker_checks() {
|
||||
warn_msg='WARNING Misconfigured DNS in /etc/resolv.conf'
|
||||
|
@ -26,8 +28,6 @@ docker_checks() {
|
|||
}
|
||||
|
||||
fix_capabilities() {
|
||||
[ ! -f /.piholeFirstBoot ] && return
|
||||
|
||||
setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN+ei $(which pihole-FTL) || ret=$?
|
||||
|
||||
if [[ $ret -ne 0 && "${DNSMASQ_USER:-root}" != "root" ]]; then
|
||||
|
@ -69,10 +69,9 @@ prepare_configs() {
|
|||
# Stash and pop the user password to avoid setting the password to the hashed setupVar variable
|
||||
WEBPASSWORD="${USERWEBPASSWORD}"
|
||||
# Clean up old before re-writing the required setupVars
|
||||
sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;' "${setupVars}"
|
||||
sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;' "${setupVars}"
|
||||
fi
|
||||
# echo the information to the user
|
||||
# P
|
||||
{
|
||||
echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}"
|
||||
echo "IPV4_ADDRESS=${IPV4_ADDRESS}"
|
||||
|
@ -117,6 +116,7 @@ setup_dnsmasq_dns() {
|
|||
dnsType='custom'
|
||||
fi;
|
||||
|
||||
# TODO With the addition of this to /start.sh this needs a refactor
|
||||
if [ ! -f /.piholeFirstBoot ] ; then
|
||||
local setupDNS1="$(grep 'PIHOLE_DNS_1' ${setupVars})"
|
||||
local setupDNS2="$(grep 'PIHOLE_DNS_2' ${setupVars})"
|
||||
|
@ -299,6 +299,8 @@ generate_password() {
|
|||
}
|
||||
|
||||
setup_web_password() {
|
||||
setup_var_exists "WEBPASSWORD" && return
|
||||
|
||||
PASS="$1"
|
||||
# Turn bash debug on while setting up password (to print it)
|
||||
if [[ "$PASS" == "" ]] ; then
|
||||
|
@ -342,11 +344,11 @@ test_configs() {
|
|||
setup_blocklists() {
|
||||
local blocklists="$1"
|
||||
# Exit/return early without setting up adlists with defaults for any of the following conditions:
|
||||
# 1. NO_SETUP env is set
|
||||
# 1. skip_setup_blocklists env is set
|
||||
exit_string="(exiting ${FUNCNAME[0]} early)"
|
||||
|
||||
if [ -n "${NO_SETUP}" ]; then
|
||||
echo "::: NO_SETUP requested ($exit_string)"
|
||||
if [ -n "${skip_setup_blocklists}" ]; then
|
||||
echo "::: skip_setup_blocklists requested ($exit_string)"
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -364,3 +366,16 @@ setup_blocklists() {
|
|||
echo "::: Blocklists (${adlistFile}) now set to:"
|
||||
cat "${adlistFile}"
|
||||
}
|
||||
|
||||
setup_var_exists() {
|
||||
local KEY="$1"
|
||||
if [ -n "$2" ]; then
|
||||
local REQUIRED_VALUE="[^\n]+"
|
||||
fi
|
||||
if grep -Pq "^${KEY}=${REQUIRED_VALUE}" "$setupVars"; then
|
||||
echo "::: Pre existing ${KEY} found"
|
||||
true
|
||||
else
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
|
13
start.sh
13
start.sh
|
@ -20,13 +20,20 @@ export adlistFile='/etc/pihole/adlists.list'
|
|||
# The below functions are all contained in bash_functions.sh
|
||||
. /bash_functions.sh
|
||||
|
||||
# Some of the bash_functions use variables these core pi-hole/web scripts
|
||||
. /opt/pihole/webpage.sh
|
||||
# PH_TEST prevents the install from actually running (someone should rename that)
|
||||
PH_TEST=true . $PIHOLE_INSTALL
|
||||
|
||||
echo " ::: Starting docker specific setup for docker pihole/pihole"
|
||||
echo " ::: Starting docker specific checks & setup for docker pihole/pihole"
|
||||
|
||||
docker_checks
|
||||
|
||||
# TODO:
|
||||
#if [ ! -f /.piholeFirstBoot ] ; then
|
||||
# echo " ::: Not first container startup so not running docker's setup, re-create container to run setup again"
|
||||
#else
|
||||
# regular_setup_functions
|
||||
#fi
|
||||
|
||||
fix_capabilities
|
||||
generate_password
|
||||
validate_env || exit 1
|
||||
|
|
|
@ -173,6 +173,17 @@ def test_webPassword_env_assigns_password_to_file_or_removes_if_empty(Docker, ar
|
|||
assert Docker.run('grep -q \'^WEBPASSWORD=$\' /etc/pihole/setupVars.conf').rc == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('entrypoint,cmd', [('--entrypoint=tail','-f /dev/null')])
|
||||
@pytest.mark.parametrize('test_args', ['-e WEBPASSWORD=login', '-e WEBPASSWORD=""'])
|
||||
def test_webPassword_pre_existing_trumps_all_envs(Docker, args_env, test_args):
|
||||
'''When a user setup webPassword in the volume prior to first container boot,
|
||||
during prior container boot, the prior volume password is left intact / setup skipped'''
|
||||
Docker.run('. /opt/pihole/webpage.sh ; add_setting WEBPASSWORD volumepass')
|
||||
function = Docker.run('. /bash_functions.sh ; eval `grep setup_web_password /start.sh`')
|
||||
|
||||
assert '::: Pre existing WEBPASSWORD found' in function.stdout
|
||||
assert Docker.run('grep -q \'{}\' {}'.format('WEBPASSWORD=volumepass', '/etc/pihole/setupVars.conf')).rc == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('args_dns, expected_stdout', [
|
||||
# No DNS passed will vary by the host this is ran on, bad idea for a test
|
||||
|
|
Loading…
Reference in New Issue