Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
3.3.3 is 3.4.0 (#185)
Browse files Browse the repository at this point in the history
* new first line of script

* no requested

* Abort!

* Test silent folder validation

* sameline

* echo newline

* echo_sameline

* what happened?

* sameline for ssh

* sqlite sameline

* Lower case

* Reset line

* clear line

* Flip the line

* version update

* Backup lowercase

* More lowercase

* Remove file names from standard messages

* Breakout backup message

* Output backup folder size

* Just H

* Invalid replication settings

* Compare updated

* Colors and updates

* Lower case for version output

* For Pihole

* Cron cleanup

* Sudo, or no sudo.

* Branch!

* Silent error validate

* Silent error validate

* Clearing up status messages

* Records

* Primary and secondary

* Gravity database

* Domain Database

* Backup output cleanup

* Move file permission validation into new functions

* Change restart

* UI variables test

* Breakout UI variables into new file

* Unified validation functions

* Replace text strings with variables

* Replace text strings with variables

* Replace logging with variables

* Convert backup to UI variables

* Switch restore to UI variables

* Fix bug where gravity database did not restore

* App validation checks

* Rev to 3.4.0

* Convert Push functions to new strings

* Completing push UI changes

* remove added line

* Move purge to UI strings

* Move automation to UI strings

* Move core strings into UI

* Exit strings

* First pass at hashing UI

* Escape the remote system query (#179)

* hashing committed

Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local>
Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 1, 2021
1 parent 6466e5a commit d97f92c
Show file tree
Hide file tree
Showing 23 changed files with 571 additions and 586 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<p align="center">
<img src="https://vmstan.com/content/images/2021/02/gs-logo.svg" width="40%" alt="Gravity Sync">
<img src="https://vmstan.com/content/images/2021/02/gs-logo.svg" width="300" alt="Gravity Sync">
</p>

What is better than a [Pi-hole](https://github.com/pi-hole/pi-hole) blocking ads via DNS on your network? That's right, **two** Pi-hole blocking ads on your network!
<span align="center">

- [Seriously. Why two Pi-hole?](https://github.com/vmstan/gravity-sync/wiki/Frequent-Questions#why-do-i-need-more-than-one-pi-hole)
# Gravity Sync

</span>

###

But if you have more than one Pi-hole in your network you'll want a simple way to keep the list configurations and local DNS settings identical between the two. That's Gravity Sync. With proper preparation it should only take a few minutes to install. Ideally you set up Gravity Sync and forget about it -- and in the long term, it would be awesome if the Pi-hole team made this entire script unnecessary.
What is better than a [Pi-hole](https://github.com/pi-hole/pi-hole) blocking trackers, advertisements, and other malicious domains on your network? That's right, **two** Pi-hole blocking all that junk on your network!

# Features
- [Seriously. Why two Pi-hole?](https://github.com/vmstan/gravity-sync/wiki/Frequent-Questions#why-do-i-need-more-than-one-pi-hole)

But if you have more than one Pi-hole in your network you'll want a simple way to keep the list configurations and local DNS settings identical between the two. That's where Gravity Sync comes in. With proper preparation, it should only take a few minutes to install. Ideally you setup Gravity Sync and forget about it -- and in the long term, it would be awesome if the Pi-hole team made this entire script unnecessary.

Gravity Sync replicates the `gravity.db` database, which includes:
## Features

Gravity Sync replicates the Pi-hole Domain Database (`gravity.db`), which includes:
- Blocklist settings with status and comments.
- Domain whitelist and blacklist along with status with comments.
- Custom RegEx whitelist and blacklists.
- Clients and groups along with any list assignments.

Gravity Sync can also (optionally) replicate FTLDNS/DNSMASQ configuration files, including:

- Local DNS (A Records) which are stored in a separate `custom.list` file within the `/etc/pihole` directory.
- CNAME Records which are stored in a separate `05-pihole-custom-cname.conf` file in the `/etc/dnsmasq.d` directory.
Gravity Sync can also (optionally) replicate the Local DNS Records and CNAMEs configuration files.

### Limitations

Expand All @@ -32,7 +36,7 @@ Gravity Sync will **not**:
- Sync DHCP settings or monitor device leases.
- Merge long term data, query logs, or statistics.

# Setup Steps
## Setup Steps

1. [Review System Requirements](https://github.com/vmstan/gravity-sync/wiki/System-Requirements)
2. [Prepare Your Pi-hole](https://github.com/vmstan/gravity-sync/wiki/Installing#primary-pi-hole)
Expand All @@ -42,16 +46,16 @@ Gravity Sync will **not**:
6. [Automate Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Installing#automation)
7. [Profit](https://memory-alpha.fandom.com/wiki/Rules_of_Acquisition)

# Disclaimer
## Disclaimer

Gravity Sync is not developed by or affiliated with the Pi-hole project. This is project an unofficial, community effort, that seeks to implement replication (which is currently not a part of the core Pi-hole product) in a way that provides stability and value to Pi-hole users. The code has been tested across multiple user environments but there always is an element of risk involved with running any arbitrary software you find on the Internet.

Pi-hole is and the Pi-hole logo are [registered trademarks](https://pi-hole.net/trademark-rules-and-brand-guidelines/) of Pi-hole LLC.

# Additional Documentation
## Additional Documentation

Please refer to the [Wiki](https://github.com/vmstan/gravity-sync/wiki) for more information:

- [Frequently Asked Questions](https://github.com/vmstan/gravity-sync/wiki/Frequent-Questions)
- [Advanced Installation Options](https://github.com/vmstan/gravity-sync/wiki/Under-The-Covers)
- [Changelog](https://github.com/vmstan/gravity-sync/blob/master/CHANGELOG.md)
- [Changelog](https://github.com/vmstan/gravity-sync/wiki/Changelog)
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.2
3.4.0
5 changes: 4 additions & 1 deletion gravity-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS

# GRAVITY SYNC BY VMSTAN #####################
PROGRAM='Gravity Sync'
VERSION='3.3.2'
VERSION='3.4.0'


# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
Expand Down Expand Up @@ -76,6 +76,9 @@ BASH_PATH='/bin/bash' # default OS bash path
### NEVER CHANGE ANYTHING BELOW THIS LINE! ###
##############################################

# Import UI Fields
source ${LOCAL_FOLDR}/includes/gs-ui.sh

# Import Color/Message Includes
source ${LOCAL_FOLDR}/includes/gs-colors.sh

Expand Down
52 changes: 12 additions & 40 deletions includes/gs-automate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
## Automate Task
function task_automate {
TASKTYPE='AUTOMATE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
MESSAGE="${MESSAGE}: ${TASKTYPE}"
echo_good

CRON_EXIST='0'
CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0')
if [ ${CRON_CHECK} == 1 ]
then
MESSAGE="Automation Task Already Exists"
echo_info
MESSAGE="${UI_AUTO_CRON_EXISTS}"
echo_warn
CRON_EXIST='1'
fi

MESSAGE="Configuring Automated Synchronization"
MESSAGE="${UI_AUTO_CRON_DISPLAY_FREQ}"
echo_info

if [[ $1 =~ ^[0-9][0-9]?$ ]]
then
INPUT_AUTO_FREQ=$1
else
MESSAGE="Synchronization Frequency in Minutes (5, 10, 15, 30) or 0 to Disable (default 15)"
MESSAGE="${UI_AUTO_CRON_SELECT_FREQ}"
echo_need
read INPUT_AUTO_FREQ
INPUT_AUTO_FREQ="${INPUT_AUTO_FREQ:-15}"
Expand All @@ -39,7 +39,7 @@ function task_automate {
clear_cron
fi

MESSAGE="Saving New Synchronization Automation"
MESSAGE="${UI_AUTO_CRON_SAVING}"
echo_stat
(crontab -l 2>/dev/null; echo "*/${INPUT_AUTO_FREQ} * * * * ${BASH_PATH} ${LOCAL_FOLDR}/${GS_FILENAME} smart > ${LOG_PATH}/${CRONJOB_LOG}") | crontab -
error_validate
Expand All @@ -49,52 +49,24 @@ function task_automate {
then
clear_cron

MESSAGE="Synchronization Automation Disabled"
echo_warn
# MESSAGE="Synchronization automation has been disabled"
# echo_warn
else
MESSAGE="No Synchronization Automation Scheduled"
MESSAGE="${UI_AUTO_CRON_DISABLED}"
echo_warn
fi
else
MESSAGE="Invalid Frequency Range"
MESSAGE="${UI_INVALID_SELECTION}"
echo_fail
exit_nochange
fi

# MESSAGE="Configuring Daily Backup Frequency"
# echo_info

# if [[ $2 =~ ^[0-9][0-9]?$ ]]
# then
# INPUT_AUTO_BACKUP=$2
# else
# MESSAGE="Hour of Day to Backup (1-24) or 0 to Disable"
# echo_need
# read INPUT_AUTO_BACKUP
# fi

# if [ $INPUT_AUTO_BACKUP -gt 24 ]
# then
# MESSAGE="Invalid Frequency Range"
# echo_fail
# exit_nochange
# elif [ $INPUT_AUTO_BACKUP -lt 1 ]
# then
# MESSAGE="No Backup Automation Scheduled"
# echo_warn
# else
# MESSAGE="Saving New Backup Automation"
# echo_stat
# (crontab -l 2>/dev/null; echo "0 ${INPUT_AUTO_BACKUP} * * * ${BASH_PATH} ${LOCAL_FOLDR}/${GS_FILENAME} backup >/dev/null 2>&1") | crontab -
# error_validate
# fi

exit_withchange
}

## Clear Existing Automation Settings
function clear_cron {
MESSAGE="Removing Existing Automation"
MESSAGE="${UI_AUTO_CRON_DISABLED}"
echo_stat

crontab -l > cronjob-old.tmp
Expand All @@ -108,7 +80,7 @@ function clear_cron {
## Cron Task
function task_cron {
TASKTYPE='CRON'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
MESSAGE="${MESSAGE}: ${TASKTYPE}"
echo_good

show_crontab
Expand Down
43 changes: 24 additions & 19 deletions includes/gs-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# This code is called from the main gravity-sync.sh file and should not execute directly!

## Backup Task
function task_backup {
function task_backup() {
TASKTYPE='BACKUP'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
MESSAGE="${MESSAGE}: ${TASKTYPE}"
echo_good

backup_settime
Expand All @@ -20,65 +20,65 @@ function task_backup {
exit_withchange
}

function backup_settime {
function backup_settime() {
BACKUPTIMESTAMP=$(date +%F-%H%M%S)
}

function backup_local_gravity {
MESSAGE="Performing Backup of Local ${GRAVITY_FI}"
function backup_local_gravity() {
MESSAGE="${UI_BACKUP_SECONDARY} ${UI_GRAVITY_NAME}"
echo_stat

sqlite3 ${PIHOLE_DIR}/${GRAVITY_FI} ".backup '${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup'"
error_validate
}

function backup_local_custom {
function backup_local_custom() {
if [ "$SKIP_CUSTOM" != '1' ]
then
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then
MESSAGE="Performing Backup Up Local ${CUSTOM_DNS}"
MESSAGE="${UI_BACKUP_SECONDARY} ${UI_CUSTOM_NAME}"
echo_stat

cp ${PIHOLE_DIR}/${CUSTOM_DNS} ${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CUSTOM_DNS}.backup
error_validate
else
MESSAGE="No Local ${CUSTOM_DNS} Detected"
MESSAGE="No local ${CUSTOM_DNS} detected"
echo_info
fi
fi
}

function backup_local_cname {
function backup_local_cname() {
if [ "${INCLUDE_CNAME}" == '1' ]
then
if [ -f ${DNSMAQ_DIR}/${CNAME_CONF} ]
then
MESSAGE="Performing Backup Up Local ${CNAME_CONF}"
MESSAGE="${UI_BACKUP_SECONDARY} ${UI_CNAME_NAME}"
echo_stat

cp ${DNSMAQ_DIR}/${CNAME_CONF} ${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CNAME_CONF}.backup
error_validate
else
MESSAGE="No Local ${CNAME_CONF} Detected"
MESSAGE="No local ${CNAME_CONF} detected"
echo_info
fi
fi
}

function backup_remote_gravity {
MESSAGE="Performing Backup of Remote ${GRAVITY_FI}"
function backup_remote_gravity() {
MESSAGE="${UI_BACKUP_PRIMARY} ${UI_GRAVITY_NAME}"
echo_stat

CMD_TIMEOUT='60'
CMD_REQUESTED="sudo sqlite3 ${RIHOLE_DIR}/${GRAVITY_FI} \".backup '${RIHOLE_DIR}/${GRAVITY_FI}.backup'\""
create_sshcmd
}

function backup_remote_custom {
function backup_remote_custom() {
if [ "$SKIP_CUSTOM" != '1' ]
then
MESSAGE="Performing Backup of Remote ${CUSTOM_DNS}"
MESSAGE="${UI_BACKUP_PRIMARY} ${UI_CUSTOM_NAME}"
echo_stat

CMD_TIMEOUT='15'
Expand All @@ -87,10 +87,10 @@ function backup_remote_custom {
fi
}

function backup_remote_cname {
function backup_remote_cname() {
if [ "$INCLUDE_CNAME" == '1' ]
then
MESSAGE="Performing Backup of Remote ${CNAME_CONF}"
MESSAGE="${UI_BACKUP_PRIMARY} ${UI_CNAME_NAME}"
echo_stat

CMD_TIMEOUT='15'
Expand All @@ -99,10 +99,15 @@ function backup_remote_cname {
fi
}

function backup_cleanup {
MESSAGE="Scrubbing ${BACKUP_RETAIN} Redundant Antimatter Containment Pods"
function backup_cleanup() {
MESSAGE="${UI_BACKUP_PURGE}"
echo_stat

find ${LOCAL_FOLDR}/${BACKUP_FOLD}/*.backup -mtime +${BACKUP_RETAIN} -type f -delete
error_validate

BACKUP_FOLDER_SIZE=$(du -h ${LOCAL_FOLDR}/${BACKUP_FOLD} | sed 's/\s.*$//')

MESSAGE="${BACKUP_RETAIN} ${UI_BACKUP_REMAIN} (${BACKUP_FOLDER_SIZE})"
echo_info
}
6 changes: 6 additions & 0 deletions includes/gs-colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ function echo_good {
echo -e "\r${GOOD} ${MESSAGE}"
}

### Success
function echo_sameline {
echo -en " "
echo -en "\r"
}

### Failure
function echo_fail {
echo -e "\r${FAIL} ${MESSAGE}"
Expand Down
2 changes: 1 addition & 1 deletion includes/gs-compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Compare Task
function task_compare {
TASKTYPE='COMPARE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
MESSAGE="${MESSAGE}: ${TASKTYPE}"
echo_good

show_target
Expand Down
2 changes: 1 addition & 1 deletion includes/gs-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Configure Task
function task_configure {
TASKTYPE='CONFIGURE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
MESSAGE="${MESSAGE}: ${TASKTYPE}"
echo_good

relocate_config_gs
Expand Down
Loading

0 comments on commit d97f92c

Please sign in to comment.