From 0b4131189d1eb83974967d818334838b41b8be9e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Nov 2023 14:55:34 +0100 Subject: [PATCH 1/3] Migrate Pi-hole created files out of /etc/dnsmasq.d into a pihole owned directory Signed-off-by: DL6ER --- automated install/basic-install.sh | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ef5add0e..704a736d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -91,6 +91,9 @@ QUERY_LOGGING=true WEBPORT=8080 PRIVACY_LEVEL=0 +# Where old configs go to if a v6 migration is performed +V6_CONF_MIGRATION_DIR="/etc/pihole/migration_backup_v6" + if [ -z "${USER}" ]; then USER="$(id -un)" fi @@ -2070,6 +2073,34 @@ copy_to_install_log() { chown pihole:pihole "${installLogLoc}" } +migrate_dnsmasq_configs() { + # Previously, Pi-hole created a number of files in /etc/dnsmasq.d + # During migration, their content is copied into the new single source of + # truth file /etc/pihole/pihole.toml and the old files are moved away to + # avoid conflicts with other services on this system + + # Exit early if this is already Pi-hole v6.0 + # We decide this on the presence of the file /etc/pihole/pihole.toml + if [[ -f /etc/pihole/pihole.toml ]]; then + return 0 + fi + + # Create target directory /etc/pihole/migration_backup_v6 + # and make it owned by pihole:pihole + mkdir -p "${V6_CONF_MIGRATION_DIR} + chown pihole:pihole "${V6_CONF_MIGRATION_DIR} + + # Move all conf files originally created by Pi-hole into this directory + # - 01-pihole.conf + # - 02-pihole-dhcp.conf + # - 04-pihole-static-dhcp.conf + # - 05-pihole-custom-cname.conf + # - 06-rfc6761.conf + + mv /etc/dnsmasq.d/0{1,2,4,5}-pihole*.conf "${V6_MIGRATION_DIR}/ CONF_2>/dev/null || true + mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_MIGRATION_DIR}/ CONF_2>/dev/null || true +} + main() { ######## FIRST CHECK ######## # Must be root to install @@ -2219,6 +2250,9 @@ main() { pihole -a -p "${pw}" fi + # Migrate existing install to v6.0 + migrate_dnsmasq_configs + # Check for and disable systemd-resolved-DNSStubListener before reloading resolved # DNSStubListener needs to remain in place for installer to download needed files, # so this change needs to be made after installation is complete, From e3c6f162d84a3cf78e6e50969424b1e6cebe742f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Nov 2023 08:57:56 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Adam Warner Co-authored-by: RD WebDesign Signed-off-by: DL6ER --- automated install/basic-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 704a736d..e743a071 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2087,8 +2087,8 @@ migrate_dnsmasq_configs() { # Create target directory /etc/pihole/migration_backup_v6 # and make it owned by pihole:pihole - mkdir -p "${V6_CONF_MIGRATION_DIR} - chown pihole:pihole "${V6_CONF_MIGRATION_DIR} + mkdir -p "${V6_CONF_MIGRATION_DIR}" + chown pihole:pihole "${V6_CONF_MIGRATION_DIR}" # Move all conf files originally created by Pi-hole into this directory # - 01-pihole.conf @@ -2097,8 +2097,8 @@ migrate_dnsmasq_configs() { # - 05-pihole-custom-cname.conf # - 06-rfc6761.conf - mv /etc/dnsmasq.d/0{1,2,4,5}-pihole*.conf "${V6_MIGRATION_DIR}/ CONF_2>/dev/null || true - mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_MIGRATION_DIR}/ CONF_2>/dev/null || true + mv /etc/dnsmasq.d/0{1,2,4,5}-pihole*.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true + mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_MIGRATION_DIR}/" 2>/dev/null || true } main() { From e8884083ef1f10229629e80021107f807a7fd584 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Nov 2023 08:58:31 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Signed-off-by: DL6ER --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e743a071..da0133b1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2098,7 +2098,7 @@ migrate_dnsmasq_configs() { # - 06-rfc6761.conf mv /etc/dnsmasq.d/0{1,2,4,5}-pihole*.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true - mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_MIGRATION_DIR}/" 2>/dev/null || true + mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true } main() {