2020-05-21 18:00:42 +00:00
|
|
|
#!/bin/bash
|
2020-06-02 15:44:16 +00:00
|
|
|
SCRIPT_START=$SECONDS
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-22 17:18:16 +00:00
|
|
|
# GRAVITY SYNC BY VMSTAN #####################
|
2020-05-23 23:37:08 +00:00
|
|
|
PROGRAM='Gravity Sync'
|
2020-10-10 16:30:40 +00:00
|
|
|
VERSION='3.0.2'
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-28 01:51:21 +00:00
|
|
|
# Execute from the home folder of the user who owns it (ex: 'cd ~/gravity-sync')
|
|
|
|
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
|
2020-10-07 22:45:39 +00:00
|
|
|
# Requires Pi-Hole 5.x or higher already be installed, for help visit https://pi-hole.net
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-22 17:18:16 +00:00
|
|
|
# REQUIRED SETTINGS ##########################
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# Run './gravity-sync.sh config' to get started
|
2020-05-22 17:18:16 +00:00
|
|
|
|
2020-05-22 17:25:30 +00:00
|
|
|
# STANDARD VARIABLES #########################
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-22 15:44:38 +00:00
|
|
|
# GS Folder/File Locations
|
2020-05-27 03:20:36 +00:00
|
|
|
LOCAL_FOLDR='gravity-sync' # must exist in running user home folder
|
2020-05-27 15:00:30 +00:00
|
|
|
CONFIG_FILE='gravity-sync.conf' # must exist with primary host/user configured
|
2020-05-28 18:05:22 +00:00
|
|
|
GS_FILENAME='gravity-sync.sh' # must exist because it's this script
|
2020-05-27 03:20:36 +00:00
|
|
|
BACKUP_FOLD='backup' # must exist as subdirectory in LOCAL_FOLDR
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-27 15:00:30 +00:00
|
|
|
# Logging Folder/File Locations
|
|
|
|
LOG_PATH="$HOME/${LOCAL_FOLDR}" # replace in gravity-sync.conf to overwrite
|
|
|
|
SYNCING_LOG='gravity-sync.log' # replace in gravity-sync.conf to overwrite
|
|
|
|
CRONJOB_LOG='gravity-sync.cron' # replace in gravity-sync.conf to overwrite
|
2020-06-29 19:03:47 +00:00
|
|
|
HISTORY_MD5='gravity-sync.md5' # replace in gravity-sync.conf to overwrite
|
2020-05-27 15:00:30 +00:00
|
|
|
|
2020-05-29 02:43:58 +00:00
|
|
|
# Interaction Customization
|
|
|
|
VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite
|
2020-05-29 19:43:36 +00:00
|
|
|
SKIP_CUSTOM='0' # replace in gravity-sync.conf to overwrite
|
|
|
|
DATE_OUTPUT='0' # replace in gravity-sync.conf to overwrite
|
2020-06-02 14:43:58 +00:00
|
|
|
PING_AVOID='0' # replace in gravity-sync.conf to overwrite
|
2020-07-16 18:09:44 +00:00
|
|
|
ROOT_CHECK_AVOID='0' # replace in gravity-sync.conf to overwrite
|
2020-05-29 02:43:58 +00:00
|
|
|
|
2020-07-11 03:13:49 +00:00
|
|
|
# Backup Customization
|
|
|
|
BACKUP_RETAIN='7' # replace in gravity-sync.conf to overwrite
|
|
|
|
|
2020-05-29 03:01:08 +00:00
|
|
|
# Pi-hole Folder/File Locations
|
|
|
|
PIHOLE_DIR='/etc/pihole' # default Pi-hole data directory
|
|
|
|
GRAVITY_FI='gravity.db' # default Pi-hole database file
|
2020-05-29 15:58:06 +00:00
|
|
|
CUSTOM_DNS='custom.list' # default Pi-hole local DNS lookups
|
2020-08-18 15:09:13 +00:00
|
|
|
PIHOLE_BIN='/usr/local/bin/pihole' # default Pi-hole binary directory (local)
|
|
|
|
RIHOLE_BIN='/usr/local/bin/pihole' # default Pi-hole binary directory (remote)
|
2020-10-02 19:01:17 +00:00
|
|
|
FILE_OWNER='pihole:pihole' # default Pi-hole file owner and group (local)
|
|
|
|
REMOTE_FILE_OWNER='pihole:pihole' # default Pi-hole file owner and group (remote)
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-28 15:54:32 +00:00
|
|
|
# OS Settings
|
|
|
|
BASH_PATH='/bin/bash' # default OS bash path
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# SSH CONFIGURATION ##########################
|
|
|
|
|
|
|
|
# Suggested not to replace these values here
|
|
|
|
# Add replacement variables to gravity-sync.conf
|
|
|
|
|
|
|
|
SSH_PORT='22' # default SSH port
|
2020-05-27 21:09:41 +00:00
|
|
|
SSH_PKIF='.ssh/id_rsa' # default local SSH key
|
2020-05-26 21:51:31 +00:00
|
|
|
|
2020-05-24 18:39:21 +00:00
|
|
|
##############################################
|
|
|
|
### DO NOT CHANGE ANYTHING BELOW THIS LINE ###
|
|
|
|
##############################################
|
|
|
|
|
2020-10-07 22:45:39 +00:00
|
|
|
# Import Color/Message Includes
|
2020-10-10 16:30:40 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-colors.sh
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-10-07 22:45:39 +00:00
|
|
|
# FUNCTION DEFINITIONS #######################
|
2020-05-28 15:54:32 +00:00
|
|
|
|
2020-10-10 16:30:40 +00:00
|
|
|
# Core Functions
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-core.sh
|
2020-06-03 20:43:36 +00:00
|
|
|
|
2020-10-10 16:30:40 +00:00
|
|
|
# Gravity Replication Functions
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-compare.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-pull.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-push.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-smart.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-restore.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-backup.sh
|
2020-10-09 01:39:30 +00:00
|
|
|
|
|
|
|
# Hashing & SSH Functions
|
2020-10-10 16:30:40 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-hashing.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-ssh.sh
|
2020-10-09 01:39:30 +00:00
|
|
|
|
|
|
|
# Logging Functions
|
2020-10-10 16:30:40 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-logging.sh
|
2020-10-09 01:39:30 +00:00
|
|
|
|
|
|
|
# Validation Functions
|
2020-10-10 16:30:40 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-validate.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-intent.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-root.sh
|
2020-10-09 01:39:30 +00:00
|
|
|
|
|
|
|
# Configuration Management
|
2020-10-10 16:30:40 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-config.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-update.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-automate.sh
|
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-purge.sh
|
2020-10-09 01:39:30 +00:00
|
|
|
|
|
|
|
# Exit Codes
|
2020-10-10 16:30:40 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/includes/gs-exit.sh
|
2020-10-09 01:39:30 +00:00
|
|
|
|
|
|
|
# SCRIPT EXECUTION ###########################
|
|
|
|
|
2020-05-21 18:00:42 +00:00
|
|
|
case $# in
|
2020-05-22 02:42:37 +00:00
|
|
|
0)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_smart ;;
|
2020-05-22 02:42:37 +00:00
|
|
|
1)
|
2020-10-10 16:30:40 +00:00
|
|
|
case $1 in
|
2020-10-07 22:45:39 +00:00
|
|
|
smart|sync)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_smart ;;
|
2020-10-10 16:30:40 +00:00
|
|
|
pull)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_pull ;;
|
2020-10-08 03:16:45 +00:00
|
|
|
push)
|
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_push ;;
|
2020-10-08 03:16:45 +00:00
|
|
|
restore)
|
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_restore ;;
|
2020-05-22 02:42:37 +00:00
|
|
|
version)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_version ;;
|
|
|
|
update|upgrade)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_update ;;
|
|
|
|
dev|devmode|development|develop)
|
2020-10-09 01:45:03 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_devmode ;;
|
|
|
|
logs|log)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_logs ;;
|
2020-05-25 01:19:40 +00:00
|
|
|
compare)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_compare ;;
|
2020-05-24 18:39:21 +00:00
|
|
|
cron)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_cron ;;
|
|
|
|
config|configure)
|
2020-10-10 16:30:40 +00:00
|
|
|
start_gs_noconfig
|
2020-10-07 22:45:39 +00:00
|
|
|
task_configure ;;
|
|
|
|
auto|automate)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_automate ;;
|
2020-07-11 02:43:05 +00:00
|
|
|
backup)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_backup ;;
|
2020-07-21 05:14:20 +00:00
|
|
|
purge)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_purge ;;
|
2020-10-02 19:01:17 +00:00
|
|
|
sudo)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-10 16:30:40 +00:00
|
|
|
task_sudo ;;
|
2020-05-22 02:42:37 +00:00
|
|
|
*)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_invalid ;;
|
2020-05-22 02:42:37 +00:00
|
|
|
esac
|
2020-05-22 02:08:31 +00:00
|
|
|
;;
|
2020-07-16 18:09:44 +00:00
|
|
|
|
|
|
|
2)
|
2020-10-10 16:30:40 +00:00
|
|
|
case $1 in
|
2020-10-07 22:45:39 +00:00
|
|
|
auto|automate)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_automate ;;
|
2020-07-16 18:09:44 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
3)
|
2020-10-10 16:30:40 +00:00
|
|
|
case $1 in
|
2020-10-07 22:45:39 +00:00
|
|
|
auto|automate)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_automate $2 $3 ;;
|
2020-07-16 18:09:44 +00:00
|
|
|
esac
|
|
|
|
;;
|
2020-05-22 16:39:31 +00:00
|
|
|
|
2020-05-21 18:00:42 +00:00
|
|
|
*)
|
2020-10-08 03:16:45 +00:00
|
|
|
start_gs
|
2020-10-07 22:45:39 +00:00
|
|
|
task_invalid ;;
|
2020-07-21 05:14:20 +00:00
|
|
|
esac
|
2020-10-07 22:45:39 +00:00
|
|
|
|
|
|
|
# END OF SCRIPT ##############################
|