mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Upgrade database if necessary and store audit domains therein.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
1dbe6c83c3
commit
4f4a12bb40
2 changed files with 40 additions and 18 deletions
|
@ -11,8 +11,8 @@
|
||||||
# Please see LICENSE file for your rights under this license.
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
|
||||||
upgrade_gravityDB(){
|
upgrade_gravityDB(){
|
||||||
version=$(sqlite3 "$1" "SELECT "value" FROM "info" WHERE "property" = 'version';")
|
local version=$(sqlite3 "$1" "SELECT "value" FROM "info" WHERE "property" = 'version';")
|
||||||
echo $version
|
|
||||||
case "$version" in
|
case "$version" in
|
||||||
1)
|
1)
|
||||||
sqlite3 "$1" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql"
|
sqlite3 "$1" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql"
|
||||||
|
|
54
gravity.sh
54
gravity.sh
|
@ -17,6 +17,8 @@ coltable="/opt/pihole/COL_TABLE"
|
||||||
source "${coltable}"
|
source "${coltable}"
|
||||||
regexconverter="/opt/pihole/wildcard_regex_converter.sh"
|
regexconverter="/opt/pihole/wildcard_regex_converter.sh"
|
||||||
source "${regexconverter}"
|
source "${regexconverter}"
|
||||||
|
readonly databaseMigrationScript="/etc/.pihole/advanced/Scripts/database_migration/gravity-db.sh"
|
||||||
|
source "${databaseMigrationScript}"
|
||||||
|
|
||||||
basename="pihole"
|
basename="pihole"
|
||||||
PIHOLE_COMMAND="/usr/local/bin/${basename}"
|
PIHOLE_COMMAND="/usr/local/bin/${basename}"
|
||||||
|
@ -28,6 +30,7 @@ whitelistFile="${piholeDir}/whitelist.txt"
|
||||||
blacklistFile="${piholeDir}/blacklist.txt"
|
blacklistFile="${piholeDir}/blacklist.txt"
|
||||||
regexFile="${piholeDir}/regex.list"
|
regexFile="${piholeDir}/regex.list"
|
||||||
adListFile="${piholeDir}/adlists.list"
|
adListFile="${piholeDir}/adlists.list"
|
||||||
|
auditFile="${piholeDir}/audit.list"
|
||||||
|
|
||||||
localList="${piholeDir}/local.list"
|
localList="${piholeDir}/local.list"
|
||||||
VPNList="/etc/openvpn/ipp.txt"
|
VPNList="/etc/openvpn/ipp.txt"
|
||||||
|
@ -116,14 +119,27 @@ database_table_from_file() {
|
||||||
declare -i rowid
|
declare -i rowid
|
||||||
rowid=1
|
rowid=1
|
||||||
# Read file line by line
|
# Read file line by line
|
||||||
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
if [[ "${table}" == "audit" ]]; then
|
||||||
do
|
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
||||||
# Only add non-empty lines
|
do
|
||||||
if [[ ! -z "${domain}" ]]; then
|
# Only add non-empty lines
|
||||||
echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}"
|
if [[ ! -z "${domain}" ]]; then
|
||||||
rowid+=1
|
# Audit table format
|
||||||
fi
|
echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}"
|
||||||
done
|
rowid+=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
||||||
|
do
|
||||||
|
# Only add non-empty lines
|
||||||
|
if [[ ! -z "${domain}" ]]; then
|
||||||
|
# White-, black-, and regexlist format
|
||||||
|
echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}"
|
||||||
|
rowid+=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
inputfile="${tmpFile}"
|
inputfile="${tmpFile}"
|
||||||
fi
|
fi
|
||||||
# Store domains in database table specified by ${table}
|
# Store domains in database table specified by ${table}
|
||||||
|
@ -150,34 +166,40 @@ 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() {
|
||||||
# Create database file only if not present
|
# Create database file only if not present
|
||||||
if [ -e "${gravityDBfile}" ]; then
|
if [ ! -e "${gravityDBfile}" ]; then
|
||||||
return 0
|
echo -e " ${INFO} Creating new gravity database"
|
||||||
|
generate_gravity_database
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e " ${INFO} Creating new gravity database"
|
# Check if gravity database needs to be updated
|
||||||
generate_gravity_database
|
upgrade_gravityDB "${gravityDBfile}"
|
||||||
|
|
||||||
# Migrate list files to new database
|
# Migrate list files to new database
|
||||||
if [[ -e "${adListFile}" ]]; then
|
if [ -e "${adListFile}" ]; then
|
||||||
# Store adlist domains in database
|
# Store adlist domains in database
|
||||||
echo -e " ${INFO} Migrating content of ${adListFile} into new database"
|
echo -e " ${INFO} Migrating content of ${adListFile} into new database"
|
||||||
database_table_from_file "adlist" "${adListFile}"
|
database_table_from_file "adlist" "${adListFile}"
|
||||||
fi
|
fi
|
||||||
if [[ -e "${blacklistFile}" ]]; then
|
if [ -e "${blacklistFile}" ]; then
|
||||||
# Store blacklisted domains in database
|
# Store blacklisted domains in database
|
||||||
echo -e " ${INFO} Migrating content of ${blacklistFile} into new database"
|
echo -e " ${INFO} Migrating content of ${blacklistFile} into new database"
|
||||||
database_table_from_file "blacklist" "${blacklistFile}"
|
database_table_from_file "blacklist" "${blacklistFile}"
|
||||||
fi
|
fi
|
||||||
if [[ -e "${whitelistFile}" ]]; then
|
if [ -e "${whitelistFile}" ]; then
|
||||||
# Store whitelisted domains in database
|
# Store whitelisted domains in database
|
||||||
echo -e " ${INFO} Migrating content of ${whitelistFile} into new database"
|
echo -e " ${INFO} Migrating content of ${whitelistFile} into new database"
|
||||||
database_table_from_file "whitelist" "${whitelistFile}"
|
database_table_from_file "whitelist" "${whitelistFile}"
|
||||||
fi
|
fi
|
||||||
if [[ -e "${regexFile}" ]]; then
|
if [ -e "${regexFile}" ]; then
|
||||||
# Store regex domains in database
|
# Store regex domains in database
|
||||||
echo -e " ${INFO} Migrating content of ${regexFile} into new database"
|
echo -e " ${INFO} Migrating content of ${regexFile} into new database"
|
||||||
database_table_from_file "regex" "${regexFile}"
|
database_table_from_file "regex" "${regexFile}"
|
||||||
fi
|
fi
|
||||||
|
if [ -e "${auditFile}" ]; then
|
||||||
|
# Store audit domains in database
|
||||||
|
echo -e " ${INFO} Migrating content of ${auditFile} into new database"
|
||||||
|
database_table_from_file "audit" "${auditFile}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine if DNS resolution is available before proceeding
|
# Determine if DNS resolution is available before proceeding
|
||||||
|
|
Loading…
Reference in a new issue