Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilise FTL's native config upgrade functionality #1683

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ migrate_gravity() {
echo " [i] Gravity will now be run to create the database"
pihole -g
else
echo " [i] Existing gravity database found"
echo " [i] Existing gravity database found - schema will be upgraded if necessary"
# source the migration script and run the upgrade function
source /etc/.pihole/advanced/Scripts/database_migration/gravity-db.sh
upgrade_gravityDB "${gravityDBfile}" "/etc/pihole"
local upgradeOutput
upgradeOutput=$(upgrade_gravityDB "${gravityDBfile}" "/etc/pihole")
printf "%b" "${upgradeOutput}\\n" | sed 's/^/ /'
fi
echo ""
}
Expand Down Expand Up @@ -147,7 +149,7 @@ ftl_config() {
setup_web_password
}

migrate_dnsmasq_d_contents() {
migrate_v5_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
Expand All @@ -168,6 +170,22 @@ migrate_dnsmasq_d_contents() {
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 ""

# Finally, after everything is in place, we can create the new config file
# /etc/pihole/pihole.toml
# This file will be created with the default settings unless the user has
# changed settings via setupVars.conf or the other dnsmasq files moved above
# During migration, setupVars.conf is moved to /etc/pihole/migration_backup_v6
local FTLoutput
FTLoutput=$(pihole-FTL migrate v6)

# Print the output of the FTL migration prefacing every line with six
# spaces for alignment with other container output. Replace the first line to match the style of the other messages
# We suppress the message about environment variables as these will be set on FTL's first real start
printf "%b" "${FTLoutput}\\n" | sed 's/^/ /' | sed 's/ Migrating config to Pi-hole v6.0 format/ [i] Migrating config to Pi-hole v6.0 format/' | sed 's/- 0 entries are forced through environment//'

# Print a blank line for separation
echo ""
}

setup_web_password() {
Expand Down
31 changes: 9 additions & 22 deletions src/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ start() {
# 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

migrate_v5_configs
fi

# ===========================
Expand All @@ -37,12 +32,9 @@ start() {
# If PIHOLE_UID is set, modify the pihole user's id to match
set_uid_gid

# Only run the next step if we are not migrating from v5 to v6
if [[ ${v5_volume} -eq 0 ]]; then
# Configure FTL with any environment variables if needed
echo " [i] Starting FTL configuration"
ftl_config
fi
# Configure FTL with any environment variables if needed
echo " [i] Starting FTL configuration"
ftl_config

# Install additional packages inside the container if requested
install_additional_packages
Expand Down Expand Up @@ -85,17 +77,12 @@ start() {
while ! grep -q '########## FTL started' /var/log/pihole/FTL.log; do
sleep 0.5
done

# If we are migrating from v5 to v6, we now need to run the basic configuration step that we deferred earlier
# This is because pihole-FTL needs to migrate the config files before we can perform the basic configuration checks
if [[ ${v5_volume} -eq 1 ]]; then
echo " [i] Starting deferred FTL Configuration"
ftl_config
echo ""
fi


pihole updatechecker
pihole -v
local versionsOutput
versionsOutput=$(pihole -v)
echo " [i] Version info:"
printf "%b" "${versionsOutput}\\n" | sed 's/^/ /'
echo ""

if [ "${TAIL_FTL_LOG:-1}" -eq 1 ]; then
Expand Down