Skip to content

Commit

Permalink
Added initial support for gravity.db in Pi-hole v5
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejenkins committed Mar 28, 2020
1 parent 7e0b2cb commit e3a59b3
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions pihole-cloudsync
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# pihole-cloudsync
# Helper script to keep multiple Pi-holes' lists synchronized via Git

# Version 3.0 - August 10, 2019 - Steve Jenkins (stevejenkins.com)
version='3.0'
update='August 10, 2019'
# Version 4.0 - March 28, 2020 - Steve Jenkins (stevejenkins.com)
version='4.0'
update='March 28, 2020'

# SETUP
# Follow the instructions in the README to set up your own private Git
Expand All @@ -30,13 +30,15 @@ update='August 10, 2019'
# Project Home: https://github.com/stevejenkins/pihole-cloudsync
###########################################################################
# CONSTANTS
pihole_version=4
personal_git_dir='/usr/local/bin/my-pihole-lists'
pihole_dir='/etc/pihole'
ad_list='adlists.list'
black_list='black.list'
blacklist_list='blacklist.txt'
whitelist_list='whitelist.txt'
regex_list='regex.list'
gravity_db='gravity.db'
###########################################################################
# FOR SHARED HOSTS MODE ONLY
# RE-INITIALIZE WITH --initpush OR --initpull AFTER ENABLING THIS MODE
Expand Down Expand Up @@ -64,8 +66,14 @@ fi
# FUNCTIONS
push_initialize () {
cd $pihole_dir || exit
$SUDO touch $ad_list $black_list $blacklist_list $whitelist_list $regex_list
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $personal_git_dir
if [ "$pihole_version" == "5" ]; then
$SUDO touch $gravity_db
$SUDO cp $gravity_db $personal_git_dir
else
$SUDO touch $ad_list $black_list $blacklist_list $whitelist_list $regex_list
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $personal_git_dir
fi

if [ "$shared_hosts_mode" ]; then
$SUDO sed -n '/# SHARED HOSTS - START/,/# SHARED HOSTS - END/p' $local_hosts | $SUDO sed '1d;$d' > /tmp/$shared_hosts
$SUDO cp /tmp/$shared_hosts $personal_git_dir
Expand All @@ -80,7 +88,14 @@ pull_initialize () {
# Remove -q option if you don't want to run in "quiet" mode
$SUDO git fetch --all -q
$SUDO git reset --hard origin/master -q
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $pihole_dir
if [ "$pihole_version" == "5" ]; then
$SUDO service pihole-FTL stop
$SUDO cp $gravity_db $pihole_dir
$SUDO service pihole-FTL start
else
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $pihole_dir
fi

if [ "$shared_hosts_mode" ]; then
$SUDO cp $local_hosts /tmp/hosts
$SUDO sed -e '/# SHARED HOSTS - START/,/# SHARED HOSTS - END/{/^# SHARED HOSTS/!d}' \
Expand All @@ -94,7 +109,12 @@ pull_initialize () {
}
push () {
cd $pihole_dir || exit
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $personal_git_dir
if [ "$pihole_version" == "5" ]; then
$SUDO cp $gravity_db $personal_git_dir
else
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $personal_git_dir
fi

if [ "$shared_hosts_mode" ]; then
$SUDO sed -n '/# SHARED HOSTS - START/,/# SHARED HOSTS - END/p' $local_hosts | $SUDO sed '1d;$d' > /tmp/$shared_hosts
$SUDO cp /tmp/$shared_hosts $personal_git_dir
Expand Down Expand Up @@ -124,7 +144,14 @@ pull () {
# Remove -q option if you don't want to run in "quiet" mode
$SUDO git fetch --all -q
$SUDO git reset --hard origin/master -q
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $pihole_dir
if [ "$pihole_version" == "5" ]; then
$SUDO service pihole-FTL stop
$SUDO cp $gravity_db $pihole_dir
$SUDO service pihole-FTL start
else
$SUDO cp $ad_list $black_list $blacklist_list $whitelist_list $regex_list $pihole_dir
fi

if [ "$shared_hosts_mode" ]; then
$SUDO cp $local_hosts /tmp/hosts
$SUDO sed -e '/# SHARED HOSTS - START/,/# SHARED HOSTS - END/{/^# SHARED HOSTS/!d}' \
Expand Down

0 comments on commit e3a59b3

Please sign in to comment.