Skip to content

Commit

Permalink
Migrate the dnsmasq.d configs that are owned by Pi-hole into /etc/pih…
Browse files Browse the repository at this point in the history
…ole/migration_backup_v6, where FTL expects to find them

Signed-off-by: Adam Warner <[email protected]>
  • Loading branch information
PromoFaux committed Sep 5, 2024
1 parent a5d4e07 commit df97235
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ ftl_config() {
setup_web_password
}

migrate_dnsmasq_d_contents() {
# 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
echo " [i] Migrating dnsmasq configuration files"
V6_CONF_MIGRATION_DIR="/etc/pihole/migration_backup_v6"
# Create target directory 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_CONF_MIGRATION_DIR}/" 2>/dev/null || true
mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true
echo ""
}

setup_web_password() {
# If FTLCONF_webserver_api_password is not set
if [ -z "${FTLCONF_webserver_api_password+x}" ]; then
Expand Down
17 changes: 10 additions & 7 deletions src/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ start() {

local v5_volume=0

# The below functions are all contained in bash_functions.sh
# shellcheck source=/dev/null
. /usr/bin/bash_functions.sh

# If the file /etc/pihole/setupVars.conf exists, but /etc/pihole/pihole.toml does not, then we are migrating v5->v6
# FTL Will handle the migration of the config files
if [[ -f /etc/pihole/setupVars.conf && ! -f /etc/pihole/pihole.toml ]]; then
echo " [i] v5 files detected that have not yet been migrated to v6"
echo " [i] Deferring additional configuration until after FTL has started"
echo " [i] Note: It is normal to see \"Config file /etc/pihole/pihole.toml not available (r): No such file or directory\" in the logs at this point"
echo ""
# We need to migrate the dnsmasq.d contents so that FTL can read them in properly
migrate_dnsmasq_d_contents
v5_volume=1
fi

# The below functions are all contained in bash_functions.sh
# shellcheck source=/dev/null
. /usr/bin/bash_functions.sh
fi

# ===========================
# Initial checks
Expand Down Expand Up @@ -50,7 +53,7 @@ start() {
#migrate Gravity Database if needed:
migrate_gravity

# Start pihole-FTL
# Start pihole-FTL
start_ftl

# Give FTL a couple of seconds to start up
Expand All @@ -61,7 +64,7 @@ start() {
if [[ ${v5_volume} -eq 1 ]]; then
echo " [i] Starting deferred FTL Configuration"
ftl_config
echo ""
echo ""
fi

pihole updatechecker
Expand All @@ -71,7 +74,7 @@ start() {
if [ "${TAIL_FTL_LOG:-1}" -eq 1 ]; then
# Start tailing the FTL log from the most recent "FTL Started" message
# Get the line number
startFrom=$(grep -n '########## FTL started' /var/log/pihole/FTL.log | tail -1 | cut -d: -f1)
startFrom=$(grep -n '########## FTL started' /var/log/pihole/FTL.log | tail -1 | cut -d: -f1)
# Start the tail from the line number
tail -f -n +${startFrom} /var/log/pihole/FTL.log &
else
Expand Down

0 comments on commit df97235

Please sign in to comment.