1
0
mirror of https://github.com/pi-hole/pi-hole synced 2025-01-03 12:40:56 +00:00

Only migrate legacy list files when we create gravity.db in the same gravity run

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-05-01 18:04:31 +02:00
parent 2f698904e4
commit 008e88b84b
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD

View File

@ -93,12 +93,6 @@ database_table_from_file() {
backup_path="${piholeDir}/migration_backup" backup_path="${piholeDir}/migration_backup"
backup_file="${backup_path}/$(basename "${2}")" backup_file="${backup_path}/$(basename "${2}")"
# Create database file if not present
if [ ! -e "${gravityDBfile}" ]; then
echo -e " ${INFO} Creating new gravity database"
generate_gravity_database
fi
# Truncate table # Truncate table
output=$( { sqlite3 "${gravityDBfile}" <<< "DELETE FROM ${table};"; } 2>&1 ) output=$( { sqlite3 "${gravityDBfile}" <<< "DELETE FROM ${table};"; } 2>&1 )
status="$?" status="$?"
@ -155,25 +149,32 @@ database_table_from_file() {
# Migrate pre-v5.0 list files to database-based Pi-hole versions # Migrate pre-v5.0 list files to database-based Pi-hole versions
migrate_to_database() { migrate_to_database() {
if [[ -e "${adListFile}" ]]; then # Create database file if not present
# Store adlists domains in database if [ ! -e "${gravityDBfile}" ]; then
echo -e " ${INFO} Pi-hole upgrade: Moving content of ${adListFile} into database" echo -e " ${INFO} Creating new gravity database"
database_table_from_file "adlists" "${adListFile}" generate_gravity_database
fi
if [[ -e "${blacklistFile}" ]]; then # Migrate list files to new database
# Store blacklisted domains in database if [[ -e "${adListFile}" ]]; then
echo -e " ${INFO} Pi-hole upgrade: Moving content of ${blacklistFile} into database" # Store adlists domains in database
database_table_from_file "blacklist" "${blacklistFile}" echo -e " ${INFO} Migrating content of ${adListFile} into new database"
fi database_table_from_file "adlists" "${adListFile}"
if [[ -e "${whitelistFile}" ]]; then fi
# Store whitelisted domains in database if [[ -e "${blacklistFile}" ]]; then
echo -e " ${INFO} Pi-hole upgrade: Moving content of ${whitelistFile} into database" # Store blacklisted domains in database
database_table_from_file "whitelist" "${whitelistFile}" echo -e " ${INFO} Migrating content of ${blacklistFile} into new database"
fi database_table_from_file "blacklist" "${blacklistFile}"
if [[ -e "${regexFile}" ]]; then fi
# Store regex domains in database if [[ -e "${whitelistFile}" ]]; then
echo -e " ${INFO} Pi-hole upgrade: Moving content of ${regexFile} into database" # Store whitelisted domains in database
database_table_from_file "regex" "${regexFile}" echo -e " ${INFO} Migrating content of ${whitelistFile} into new database"
database_table_from_file "whitelist" "${whitelistFile}"
fi
if [[ -e "${regexFile}" ]]; then
# Store regex domains in database
echo -e " ${INFO} Migrating content of ${regexFile} into new database"
database_table_from_file "regex" "${regexFile}"
fi
fi fi
} }