mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-03-04 07:48:34 +00:00
Improve update/fresh install detection (#6034)
This commit is contained in:
commit
978694f262
2 changed files with 43 additions and 76 deletions
|
@ -81,9 +81,7 @@ PI_HOLE_INSTALL_DIR="/opt/pihole"
|
||||||
PI_HOLE_CONFIG_DIR="/etc/pihole"
|
PI_HOLE_CONFIG_DIR="/etc/pihole"
|
||||||
PI_HOLE_BIN_DIR="/usr/local/bin"
|
PI_HOLE_BIN_DIR="/usr/local/bin"
|
||||||
PI_HOLE_V6_CONFIG="${PI_HOLE_CONFIG_DIR}/pihole.toml"
|
PI_HOLE_V6_CONFIG="${PI_HOLE_CONFIG_DIR}/pihole.toml"
|
||||||
if [ -z "$useUpdateVars" ]; then
|
fresh_install=true
|
||||||
useUpdateVars=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
adlistFile="/etc/pihole/adlists.list"
|
adlistFile="/etc/pihole/adlists.list"
|
||||||
# Pi-hole needs an IP address; to begin, these variables are empty since we don't know what the IP is until this script can run
|
# Pi-hole needs an IP address; to begin, these variables are empty since we don't know what the IP is until this script can run
|
||||||
|
@ -91,9 +89,7 @@ IPV4_ADDRESS=${IPV4_ADDRESS}
|
||||||
IPV6_ADDRESS=${IPV6_ADDRESS}
|
IPV6_ADDRESS=${IPV6_ADDRESS}
|
||||||
# Give settings their default values. These may be changed by prompts later in the script.
|
# Give settings their default values. These may be changed by prompts later in the script.
|
||||||
QUERY_LOGGING=
|
QUERY_LOGGING=
|
||||||
WEBPORT=
|
|
||||||
PRIVACY_LEVEL=
|
PRIVACY_LEVEL=
|
||||||
v5_to_v6_update=false
|
|
||||||
|
|
||||||
# Where old configs go to if a v6 migration is performed
|
# Where old configs go to if a v6 migration is performed
|
||||||
V6_CONF_MIGRATION_DIR="/etc/pihole/migration_backup_v6"
|
V6_CONF_MIGRATION_DIR="/etc/pihole/migration_backup_v6"
|
||||||
|
@ -1752,34 +1748,6 @@ checkSelinux() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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 [[ -n $(pihole-FTL --config webserver.api.pwhash) ]]; then
|
|
||||||
# Else if the password exists from previous setup, we'll load it later
|
|
||||||
pwstring="unchanged"
|
|
||||||
else
|
|
||||||
# Else, inform the user that there is no set password.
|
|
||||||
pwstring="NOT SET"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Store a message in a variable and display it
|
|
||||||
additional="View the web interface at http://pi.hole/admin:${WEBPORT} or http://${IPV4_ADDRESS%/*}:${WEBPORT}/admin\\n\\nYour Admin Webpage login password is ${pwstring}"
|
|
||||||
|
|
||||||
# Final completion message to user
|
|
||||||
dialog --no-shadow --keep-tite \
|
|
||||||
--title "Installation Complete!" \
|
|
||||||
--msgbox "Configure your devices to use the Pi-hole as their DNS server using:\
|
|
||||||
\\n\\nIPv4: ${IPV4_ADDRESS%/*}\
|
|
||||||
\\nIPv6: ${IPV6_ADDRESS:-"Not Configured"}\
|
|
||||||
\\nIf you have not done so already, the above IP should be set to static.\
|
|
||||||
\\n${additional}" "${r}" "${c}"
|
|
||||||
}
|
|
||||||
|
|
||||||
check_download_exists() {
|
check_download_exists() {
|
||||||
# Check if the download exists and we can reach the server
|
# Check if the download exists and we can reach the server
|
||||||
local status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
|
local status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
|
||||||
|
@ -2285,8 +2253,6 @@ migrate_dnsmasq_configs() {
|
||||||
|
|
||||||
# Print a blank line for separation
|
# Print a blank line for separation
|
||||||
printf "\\n"
|
printf "\\n"
|
||||||
|
|
||||||
v5_to_v6_update=true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for availability of either the "service" or "systemctl" commands
|
# Check for availability of either the "service" or "systemctl" commands
|
||||||
|
@ -2379,7 +2345,7 @@ main() {
|
||||||
# in case of an update (can be a v5 -> v6 or v6 -> v6 update) or repair
|
# in case of an update (can be a v5 -> v6 or v6 -> v6 update) or repair
|
||||||
if [[ -f "${PI_HOLE_V6_CONFIG}" ]] || [[ -f "/etc/pihole/setupVars.conf" ]]; then
|
if [[ -f "${PI_HOLE_V6_CONFIG}" ]] || [[ -f "/etc/pihole/setupVars.conf" ]]; then
|
||||||
# retain settings
|
# retain settings
|
||||||
useUpdateVars=true
|
fresh_install=false
|
||||||
# if it's running unattended,
|
# if it's running unattended,
|
||||||
if [[ "${runUnattended}" == true ]]; then
|
if [[ "${runUnattended}" == true ]]; then
|
||||||
printf " %b Performing unattended setup, no dialogs will be displayed\\n" "${INFO}"
|
printf " %b Performing unattended setup, no dialogs will be displayed\\n" "${INFO}"
|
||||||
|
@ -2388,7 +2354,7 @@ main() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${useUpdateVars}" == false ]]; then
|
if [[ "${fresh_install}" == true ]]; then
|
||||||
# Display welcome dialogs
|
# Display welcome dialogs
|
||||||
welcomeDialogs
|
welcomeDialogs
|
||||||
# Create directory for Pi-hole storage (/etc/pihole/)
|
# Create directory for Pi-hole storage (/etc/pihole/)
|
||||||
|
@ -2414,7 +2380,6 @@ main() {
|
||||||
# Download or reset the appropriate git repos depending on the 'repair' flag
|
# Download or reset the appropriate git repos depending on the 'repair' flag
|
||||||
clone_or_reset_repos
|
clone_or_reset_repos
|
||||||
|
|
||||||
|
|
||||||
# Create the pihole user
|
# Create the pihole user
|
||||||
create_pihole_user
|
create_pihole_user
|
||||||
|
|
||||||
|
@ -2443,11 +2408,9 @@ main() {
|
||||||
# Copy the temp log file into final log location for storage
|
# Copy the temp log file into final log location for storage
|
||||||
copy_to_install_log
|
copy_to_install_log
|
||||||
|
|
||||||
|
|
||||||
# Migrate existing install to v6.0
|
# Migrate existing install to v6.0
|
||||||
migrate_dnsmasq_configs
|
migrate_dnsmasq_configs
|
||||||
|
|
||||||
|
|
||||||
# Check for and disable systemd-resolved-DNSStubListener before reloading resolved
|
# Check for and disable systemd-resolved-DNSStubListener before reloading resolved
|
||||||
# DNSStubListener needs to remain in place for installer to download needed files,
|
# DNSStubListener needs to remain in place for installer to download needed files,
|
||||||
# so this change needs to be made after installation is complete,
|
# so this change needs to be made after installation is complete,
|
||||||
|
@ -2470,29 +2433,26 @@ main() {
|
||||||
|
|
||||||
restart_service pihole-FTL
|
restart_service pihole-FTL
|
||||||
|
|
||||||
# Add password to web UI if there is none
|
if [[ "${fresh_install}" == true ]]; then
|
||||||
pw=""
|
|
||||||
# If this is a fresh installation and no password is set,
|
|
||||||
if [[ ${v5_to_v6_update} = false && -z $(getFTLConfigValue webserver.api.pwhash) ]]; then
|
|
||||||
# generate a random password
|
|
||||||
pw=$(tr -dc _A-Z-a-z-0-9 </dev/urandom | head -c 8)
|
|
||||||
pihole setpassword "${pw}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# apply settings to pihole.toml
|
# apply settings to pihole.toml
|
||||||
# needs to be done after FTL service has been started, otherwise pihole.toml does not exist
|
# needs to be done after FTL service has been started, otherwise pihole.toml does not exist
|
||||||
# set on fresh installations by setDNS() and setPrivacyLevel() and setLogging()
|
# set on fresh installations by setDNS() and setPrivacyLevel() and setLogging()
|
||||||
|
|
||||||
|
# Upstreams may be needed in order to run gravity.sh
|
||||||
if [ -n "${PIHOLE_DNS_1}" ]; then
|
if [ -n "${PIHOLE_DNS_1}" ]; then
|
||||||
local string="\"${PIHOLE_DNS_1}\""
|
local string="\"${PIHOLE_DNS_1}\""
|
||||||
[ -n "${PIHOLE_DNS_2}" ] && string+=", \"${PIHOLE_DNS_2}\""
|
[ -n "${PIHOLE_DNS_2}" ] && string+=", \"${PIHOLE_DNS_2}\""
|
||||||
setFTLConfigValue "dns.upstreams" "[ $string ]"
|
setFTLConfigValue "dns.upstreams" "[ $string ]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${QUERY_LOGGING}" ]; then
|
if [ -n "${QUERY_LOGGING}" ]; then
|
||||||
setFTLConfigValue "dns.queryLogging" "${QUERY_LOGGING}"
|
setFTLConfigValue "dns.queryLogging" "${QUERY_LOGGING}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${PRIVACY_LEVEL}" ]; then
|
if [ -n "${PRIVACY_LEVEL}" ]; then
|
||||||
setFTLConfigValue "misc.privacylevel" "${PRIVACY_LEVEL}"
|
setFTLConfigValue "misc.privacylevel" "${PRIVACY_LEVEL}"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Download and compile the aggregated block list
|
# Download and compile the aggregated block list
|
||||||
runGravity
|
runGravity
|
||||||
|
@ -2500,28 +2460,35 @@ main() {
|
||||||
# Update local and remote versions via updatechecker
|
# Update local and remote versions via updatechecker
|
||||||
/opt/pihole/updatecheck.sh
|
/opt/pihole/updatecheck.sh
|
||||||
|
|
||||||
# If there is a password
|
if [[ "${fresh_install}" == true ]]; then
|
||||||
if ((${#pw} > 0)); then
|
|
||||||
# display the password
|
|
||||||
printf " %b Web Interface password: %b%s%b\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${pw}" "${COL_NC}"
|
|
||||||
printf " %b This can be changed using 'pihole setpassword'\\n\\n" "${INFO}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${useUpdateVars}" == false ]]; then
|
|
||||||
# Get the Web interface port, return only the first port and strip all non-numeric characters
|
# Get the Web interface port, return only the first port and strip all non-numeric characters
|
||||||
WEBPORT=$(getFTLConfigValue webserver.port|cut -d, -f1 | tr -cd '0-9')
|
WEBPORT=$(getFTLConfigValue webserver.port|cut -d, -f1 | tr -cd '0-9')
|
||||||
|
|
||||||
# Display the completion dialog
|
# If this is a fresh install, we will set a random password.
|
||||||
displayFinalMessage "${pw}"
|
# Users can change this password after installation if they wish
|
||||||
|
pw=$(tr -dc _A-Z-a-z-0-9 </dev/urandom | head -c 8)
|
||||||
# If the Web interface was installed,
|
pihole setpassword "${pw}" > /dev/null
|
||||||
printf " %b View the web interface at http://pi.hole:${WEBPORT}/admin or http://%s/admin\\n\\n" "${INFO}" "${IPV4_ADDRESS%/*}:${WEBPORT}"
|
|
||||||
|
|
||||||
# Explain to the user how to use Pi-hole as their DNS server
|
# Explain to the user how to use Pi-hole as their DNS server
|
||||||
printf " %b You may now configure your devices to use the Pi-hole as their DNS server\\n" "${INFO}"
|
printf "\\n %b You may now configure your devices to use the Pi-hole as their DNS server\\n" "${INFO}"
|
||||||
[[ -n "${IPV4_ADDRESS%/*}" ]] && printf " %b Pi-hole DNS (IPv4): %s\\n" "${INFO}" "${IPV4_ADDRESS%/*}"
|
[[ -n "${IPV4_ADDRESS%/*}" ]] && printf " %b Pi-hole DNS (IPv4): %s\\n" "${INFO}" "${IPV4_ADDRESS%/*}"
|
||||||
[[ -n "${IPV6_ADDRESS}" ]] && printf " %b Pi-hole DNS (IPv6): %s\\n" "${INFO}" "${IPV6_ADDRESS}"
|
[[ -n "${IPV6_ADDRESS}" ]] && printf " %b Pi-hole DNS (IPv6): %s\\n" "${INFO}" "${IPV6_ADDRESS}"
|
||||||
printf " %b If you have not done so already, the above IP should be set to static.\\n" "${INFO}"
|
printf " %b If you have not done so already, the above IP should be set to static.\\n" "${INFO}"
|
||||||
|
|
||||||
|
printf " %b View the web interface at http://pi.hole:${WEBPORT}/admin or http://%s/admin\\n\\n" "${INFO}" "${IPV4_ADDRESS%/*}:${WEBPORT}"
|
||||||
|
printf " %b Web Interface password: %b%s%b\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${pw}" "${COL_NC}"
|
||||||
|
printf " %b This can be changed using 'pihole setpassword'\\n\\n" "${INFO}"
|
||||||
|
|
||||||
|
# Final dialog message to the user
|
||||||
|
dialog --no-shadow --keep-tite \
|
||||||
|
--title "Installation Complete!" \
|
||||||
|
--msgbox "Configure your devices to use the Pi-hole as their DNS server using:\
|
||||||
|
\\n\\nIPv4: ${IPV4_ADDRESS%/*}\
|
||||||
|
\\nIPv6: ${IPV6_ADDRESS:-"Not Configured"}\
|
||||||
|
\\nIf you have not done so already, the above IP should be set to static.\
|
||||||
|
\\nView the web interface at http://pi.hole/admin:${WEBPORT} or http://${IPV4_ADDRESS%/*}:${WEBPORT}/admin\\n\\nYour Admin Webpage login password is ${pw}" "${r}" "${c}"
|
||||||
|
|
||||||
INSTALL_TYPE="Installation"
|
INSTALL_TYPE="Installation"
|
||||||
else
|
else
|
||||||
INSTALL_TYPE="Update"
|
INSTALL_TYPE="Update"
|
||||||
|
|
|
@ -89,10 +89,10 @@ def test_installPihole_fresh_install_readableFiles(host):
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
umask 0027
|
umask 0027
|
||||||
runUnattended=true
|
runUnattended=true
|
||||||
useUpdateVars=true
|
fresh_install=false
|
||||||
source /opt/pihole/basic-install.sh > /dev/null
|
source /opt/pihole/basic-install.sh > /dev/null
|
||||||
runUnattended=true
|
runUnattended=true
|
||||||
useUpdateVars=true
|
fresh_install=false
|
||||||
main
|
main
|
||||||
/opt/pihole/pihole-FTL-prestart.sh
|
/opt/pihole/pihole-FTL-prestart.sh
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue