Removing hard tabs, adding group table relations for domains since import is missing group mapping which breaks additional allowlist since it's not in default

This commit is contained in:
Jon Stephens 2021-12-08 23:44:44 -08:00
parent 08b14d7a5d
commit 4c22df559e

View File

@ -73,6 +73,19 @@ if [ -n "${DOCKER_CMD}" ]; then
fi
fi
export_table () {
table="$1"
$SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM \"$table\"" >"${table}.csv"
}
import_table () {
table="$1"
$SUDO sqlite3 $gravity_db "DROP TABLE \"$table\";"
$SUDO sqlite3 $gravity_db -header -csv ".import \"${table}.csv\" \"$table\""
}
# FUNCTIONS
push_initialize () {
# Go to Pi-hole directory, exit if doesn't exist
@ -90,8 +103,10 @@ push_initialize () {
cd $personal_git_dir || exit
# Export Ad and Domain lists from Gravity database
$SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM adlist" >$ad_list
$SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM domainlist" >$domain_list
export_table "adlist"
export_table "domainlist"
export_table "group"
export_table "domainlist_by_group"
# Add all lists to local Git repo
$SUDO git add .
@ -121,10 +136,10 @@ pull_initialize () {
$SUDO cp $cname_list $dnsmasq_dir
# Overwrite local database tables
$SUDO sqlite3 $gravity_db "DROP TABLE adlist;"
$SUDO sqlite3 $gravity_db -header -csv ".import adlist.csv adlist"
$SUDO sqlite3 $gravity_db "DROP TABLE domainlist;"
$SUDO sqlite3 $gravity_db -header -csv ".import domainlist.csv domainlist"
import_table "adlist"
import_table "domainlist"
import_table "group"
import_table "domainlist_by_group"
# Restart Pi-hole to pick up changes
$SUDO ${DOCKER} pihole -g
@ -145,8 +160,10 @@ push () {
cd $personal_git_dir || exit
# Export Ad and Domain lists from Gravity database
$SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM adlist" >$ad_list
$SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM domainlist" >$domain_list
export_table "adlist"
export_table "domainlist"
export_table "group"
export_table "domainlist_by_group"
# Compare local files to remote Git repo
$SUDO git remote update > /dev/null
@ -187,10 +204,10 @@ pull () {
$SUDO ${DOCKER} service pihole-FTL stop
$SUDO cp $custom_list $pihole_dir
$SUDO cp $cname_list $dnsmasq_dir
$SUDO sqlite3 $gravity_db "DROP TABLE adlist;"
$SUDO sqlite3 $gravity_db -header -csv ".import adlist.csv adlist"
$SUDO sqlite3 $gravity_db "DROP TABLE domainlist;"
$SUDO sqlite3 $gravity_db -header -csv ".import domainlist.csv domainlist"
import_table "adlist"
import_table "domainlist"
import_table "group"
import_table "domainlist_by_group"
$SUDO ${DOCKER} pihole -g
echo 'Done!';
exit 0