2017-02-09 20:01:34 +01:00
|
|
|
#!/bin/bash -e
|
2016-10-07 02:46:20 +02:00
|
|
|
# Dockerfile variables
|
2017-10-04 18:05:27 +02:00
|
|
|
export TAG
|
2016-10-07 02:46:20 +02:00
|
|
|
export ServerIP
|
|
|
|
export ServerIPv6
|
|
|
|
export PYTEST
|
|
|
|
export PHP_ENV_CONFIG
|
2020-05-04 23:15:35 +02:00
|
|
|
export PHP_ERROR_LOG
|
2016-10-30 18:13:52 +01:00
|
|
|
export HOSTNAME
|
2016-11-06 20:41:14 +01:00
|
|
|
export WEBLOGDIR
|
2017-01-18 05:49:42 +01:00
|
|
|
export DNS1
|
|
|
|
export DNS2
|
2019-08-31 20:17:19 +02:00
|
|
|
export DNSSEC
|
|
|
|
export DNS_BOGUS_PRIV
|
2019-10-16 06:29:40 +02:00
|
|
|
export DNS_FQDN_REQUIRED
|
2017-03-05 00:31:09 +01:00
|
|
|
export INTERFACE
|
2018-09-29 22:17:21 +02:00
|
|
|
export DNSMASQ_LISTENING_BEHAVIOUR="$DNSMASQ_LISTENING"
|
2016-11-06 20:41:14 +01:00
|
|
|
export IPv6
|
2017-11-15 05:33:05 +01:00
|
|
|
export WEB_PORT
|
2020-11-30 22:46:50 +01:00
|
|
|
export REV_SERVER
|
|
|
|
export REV_SERVER_DOMAIN
|
|
|
|
export REV_SERVER_TARGET
|
|
|
|
export REV_SERVER_CIDR
|
2019-08-31 20:17:19 +02:00
|
|
|
export CONDITIONAL_FORWARDING
|
|
|
|
export CONDITIONAL_FORWARDING_IP
|
|
|
|
export CONDITIONAL_FORWARDING_DOMAIN
|
|
|
|
export CONDITIONAL_FORWARDING_REVERSE
|
2020-05-04 23:15:35 +02:00
|
|
|
export TEMPERATUREUNIT
|
|
|
|
export ADMIN_EMAIL
|
|
|
|
export WEBUIBOXEDLAYOUT
|
2020-10-11 17:23:03 +02:00
|
|
|
export QUERY_LOGGING
|
2020-12-16 22:31:04 +01:00
|
|
|
export PIHOLE_DNS_
|
2016-11-06 20:41:14 +01:00
|
|
|
|
2019-06-01 19:16:05 +02:00
|
|
|
export adlistFile='/etc/pihole/adlists.list'
|
2018-07-30 01:14:24 +02:00
|
|
|
|
2021-01-09 22:45:17 +01:00
|
|
|
# If user has set QUERY_LOGGING Env Var, copy it out to _OVERRIDE, else it will get reset when we source the next two files
|
|
|
|
# Come back to it at the end of the file
|
|
|
|
[ -n "${QUERY_LOGGING}" ] && QUERY_LOGGING_OVERRIDE="${QUERY_LOGGING}"
|
|
|
|
|
2018-07-30 01:14:24 +02:00
|
|
|
# The below functions are all contained in bash_functions.sh
|
2017-01-18 05:49:42 +01:00
|
|
|
. /bash_functions.sh
|
2016-10-07 02:46:20 +02:00
|
|
|
|
2020-05-04 23:15:35 +02:00
|
|
|
# Ensure we have all functions available to update our configurations
|
|
|
|
. /opt/pihole/webpage.sh
|
|
|
|
|
2018-07-30 01:14:24 +02:00
|
|
|
# PH_TEST prevents the install from actually running (someone should rename that)
|
|
|
|
PH_TEST=true . $PIHOLE_INSTALL
|
|
|
|
|
2019-02-17 07:18:28 +01:00
|
|
|
echo " ::: Starting docker specific checks & setup for docker pihole/pihole"
|
|
|
|
|
2019-06-01 19:16:05 +02:00
|
|
|
# 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
|
2019-05-08 08:12:58 +02:00
|
|
|
|
2019-06-01 19:16:05 +02:00
|
|
|
fix_capabilities
|
2020-02-26 18:27:42 +01:00
|
|
|
load_web_password_secret
|
2019-05-08 08:12:58 +02:00
|
|
|
generate_password
|
2019-06-01 19:16:05 +02:00
|
|
|
validate_env || exit 1
|
2018-08-03 05:49:55 +02:00
|
|
|
prepare_configs
|
2020-12-04 12:20:16 +01:00
|
|
|
|
|
|
|
[ -n "${PIHOLE_INTERFACE}" ] && change_setting "PIHOLE_INTERFACE" "$PIHOLE_INTERFACE"
|
|
|
|
[ -n "${IPV4_ADDRESS}" ] && change_setting "IPV4_ADDRESS" "$IPV4_ADDRESS"
|
|
|
|
[ -n "${INSTALL_WEB_SERVER}" ] && change_setting "INSTALL_WEB_SERVER" "$INSTALL_WEB_SERVER"
|
|
|
|
[ -n "${INSTALL_WEB_INTERFACE}" ] && change_setting "INSTALL_WEB_INTERFACE" "$INSTALL_WEB_INTERFACE"
|
|
|
|
[ -n "${LIGHTTPD_ENABLED}" ] && change_setting "LIGHTTPD_ENABLED" "$LIGHTTPD_ENABLED"
|
|
|
|
[ -n "${ServerIP}" ] && change_setting "IPV4_ADDRESS" "$ServerIP"
|
|
|
|
[ -n "${ServerIPv6}" ] && change_setting "IPV6_ADDRESS" "$ServerIPv6"
|
|
|
|
[ -n "${DNS_BOGUS_PRIV}" ] && change_setting "DNS_BOGUS_PRIV" "$DNS_BOGUS_PRIV"
|
|
|
|
[ -n "${DNS_FQDN_REQUIRED}" ] && change_setting "DNS_FQDN_REQUIRED" "$DNS_FQDN_REQUIRED"
|
|
|
|
[ -n "${DNSSEC}" ] && change_setting "DNSSEC" "$DNSSEC"
|
|
|
|
[ -n "${REV_SERVER}" ] && change_setting "REV_SERVER" "$REV_SERVER"
|
|
|
|
[ -n "${REV_SERVER_DOMAIN}" ] && change_setting "REV_SERVER_DOMAIN" "$REV_SERVER_DOMAIN"
|
|
|
|
[ -n "${REV_SERVER_TARGET}" ] && change_setting "REV_SERVER_TARGET" "$REV_SERVER_TARGET"
|
|
|
|
[ -n "${REV_SERVER_CIDR}" ] && change_setting "REV_SERVER_CIDR" "$REV_SERVER_CIDR"
|
|
|
|
|
2020-11-30 22:46:50 +01:00
|
|
|
if [ -z "$REV_SERVER" ];then
|
|
|
|
# If the REV_SERVER* variables are set, then there is no need to add these.
|
|
|
|
# If it is not set, then adding these variables is fine, and they will be converted by the Pi-hole install script
|
2020-12-04 12:20:16 +01:00
|
|
|
[ -n "${CONDITIONAL_FORWARDING}" ] && change_setting "CONDITIONAL_FORWARDING" "$CONDITIONAL_FORWARDING"
|
|
|
|
[ -n "${CONDITIONAL_FORWARDING_IP}" ] && change_setting "CONDITIONAL_FORWARDING_IP" "$CONDITIONAL_FORWARDING_IP"
|
|
|
|
[ -n "${CONDITIONAL_FORWARDING_DOMAIN}" ] && change_setting "CONDITIONAL_FORWARDING_DOMAIN" "$CONDITIONAL_FORWARDING_DOMAIN"
|
|
|
|
[ -n "${CONDITIONAL_FORWARDING_REVERSE}" ] && change_setting "CONDITIONAL_FORWARDING_REVERSE" "$CONDITIONAL_FORWARDING_REVERSE"
|
2020-11-30 22:46:50 +01:00
|
|
|
fi
|
2020-12-04 12:20:16 +01:00
|
|
|
|
2020-12-16 23:19:20 +01:00
|
|
|
if [ -z "${PIHOLE_DNS_}" ]; then
|
2020-12-16 22:31:04 +01:00
|
|
|
# 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_
|
|
|
|
# They are not used anywhere if PIHOLE_DNS_ is set already
|
2020-12-16 23:19:20 +01:00
|
|
|
[ -n "${DNS1}" ] && echo "Converting DNS1 to PIHOLE_DNS_" && PIHOLE_DNS_="$DNS1"
|
|
|
|
[[ -n "${DNS2}" && "${DNS2}" != "no" ]] && echo "Converting DNS2 to PIHOLE_DNS_" && PIHOLE_DNS_="$PIHOLE_DNS_;$DNS2"
|
2020-12-16 22:31:04 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Parse the PIHOLE_DNS variable, if it exists, and apply upstream servers to Pi-hole config
|
|
|
|
if [ -n "${PIHOLE_DNS_}" ]; then
|
2020-12-16 23:19:20 +01:00
|
|
|
echo "Setting DNS servers based on PIHOLE_DNS_ variable"
|
2020-12-16 22:31:04 +01:00
|
|
|
# Split into an array (delimited by ;)
|
|
|
|
PIHOLE_DNS_ARR=(${PIHOLE_DNS_//;/ })
|
|
|
|
count=1
|
|
|
|
for i in "${PIHOLE_DNS_ARR[@]}"; do
|
|
|
|
change_setting "PIHOLE_DNS_$count" "$i"
|
|
|
|
((count=count+1))
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# Environment variable has not been set, but there may be existing values in an existing setupVars.conf
|
|
|
|
# if this is the case, we do not want to overwrite these with the defaults of 8.8.8.8 and 8.8.4.4
|
|
|
|
# Pi-hole can run with only one upstream configured, so we will just check for one.
|
2020-12-16 23:19:20 +01:00
|
|
|
setupVarsDNS="$(grep 'PIHOLE_DNS_' /etc/pihole/setupVars.conf || true)"
|
|
|
|
|
|
|
|
if [ -z "${setupVarsDNS}" ]; then
|
|
|
|
echo "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_2" "8.8.4.4"
|
|
|
|
else
|
|
|
|
echo "Existing DNS servers detected in setupVars.conf. Leaving them alone"
|
|
|
|
fi
|
2020-12-16 22:31:04 +01:00
|
|
|
fi
|
|
|
|
|
2017-11-15 05:33:05 +01:00
|
|
|
setup_web_port "$WEB_PORT"
|
2018-09-18 07:11:26 +02:00
|
|
|
setup_web_password "$WEBPASSWORD"
|
2020-05-04 23:15:35 +02:00
|
|
|
setup_temp_unit "$TEMPERATUREUNIT"
|
|
|
|
setup_ui_layout "$WEBUIBOXEDLAYOUT"
|
|
|
|
setup_admin_email "$ADMIN_EMAIL"
|
2020-12-16 23:19:20 +01:00
|
|
|
setup_dnsmasq "$INTERFACE" "$DNSMASQ_LISTENING_BEHAVIOUR"
|
2017-01-18 05:49:42 +01:00
|
|
|
setup_php_env
|
2016-10-30 18:13:52 +01:00
|
|
|
setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME"
|
2016-10-21 05:36:55 +02:00
|
|
|
setup_ipv4_ipv6
|
2018-07-30 01:14:24 +02:00
|
|
|
setup_lighttpd_bind "$ServerIP"
|
|
|
|
setup_blocklists
|
2016-10-07 02:46:20 +02:00
|
|
|
test_configs
|
2016-03-28 16:23:37 +02:00
|
|
|
|
2019-06-01 19:16:05 +02:00
|
|
|
[ -f /.piholeFirstBoot ] && rm /.piholeFirstBoot
|
2017-11-20 06:15:44 +01:00
|
|
|
|
2021-01-09 22:45:17 +01:00
|
|
|
# Set QUERY_LOGGING value in setupVars to be that which the user has passed in as an ENV var (if they have)
|
|
|
|
[ -n "${QUERY_LOGGING_OVERRIDE}" ] && change_setting "QUERY_LOGGING" "$QUERY_LOGGING_OVERRIDE"
|
|
|
|
|
|
|
|
# Source setupVars.conf to get the true value of QUERY_LOGGING
|
|
|
|
. ${setupVars}
|
|
|
|
|
|
|
|
if [ ${QUERY_LOGGING} == "false" ]; then
|
|
|
|
echo "::: Disabling Query Logging"
|
|
|
|
pihole logging off
|
|
|
|
else
|
|
|
|
# If it is anything other than false, set it to true
|
|
|
|
change_setting "QUERY_LOGGING" "true"
|
|
|
|
# Set pihole logging on for good measure
|
|
|
|
echo "::: Enabling Query Logging"
|
|
|
|
pihole logging on
|
|
|
|
fi
|
|
|
|
|
2018-08-03 05:49:55 +02:00
|
|
|
echo " ::: Docker start setup complete"
|