mirror of
https://github.com/vmstan/gravity-sync.git
synced 2024-08-30 18:22:11 +00:00
Function all the things
This commit is contained in:
parent
223884f571
commit
9b60ea604a
@ -11,17 +11,17 @@ VERSION='1.2.0'
|
|||||||
|
|
||||||
# You must define REMOTE_HOST and REMOTE_USER in a file called 'gravity-sync.conf' -- see above documentation
|
# You must define REMOTE_HOST and REMOTE_USER in a file called 'gravity-sync.conf' -- see above documentation
|
||||||
|
|
||||||
# PUSH SETTINGS
|
# CUSTOMIZATION ##############################
|
||||||
|
|
||||||
# CUSTOMIZATION
|
# GS Folder/File Locations
|
||||||
LOCAL_FOLDR='gravity-sync' # must exist in running user home folder
|
LOCAL_FOLDR='gravity-sync' # must exist in running user home folder
|
||||||
SYNCING_LOG='gravity-sync.log' # will be created in above folder
|
SYNCING_LOG='gravity-sync.log' # will be created in above folder
|
||||||
|
|
||||||
# PIHOLE DEFAULTS
|
# PH Folder/File Locations
|
||||||
PIHOLE_DIR='/etc/pihole' # default install directory
|
PIHOLE_DIR='/etc/pihole' # default install directory
|
||||||
GRAVITY_FI='gravity.db' # this should not change
|
GRAVITY_FI='gravity.db' # this should not change
|
||||||
|
|
||||||
# SCRIPT COLORS
|
# Script Colors
|
||||||
RED='\033[0;91m'
|
RED='\033[0;91m'
|
||||||
GREEN='\033[0;92m'
|
GREEN='\033[0;92m'
|
||||||
CYAN='\033[0;96m'
|
CYAN='\033[0;96m'
|
||||||
@ -32,6 +32,7 @@ NC='\033[0m'
|
|||||||
##############################################
|
##############################################
|
||||||
|
|
||||||
# IMPORT SETTINGS
|
# IMPORT SETTINGS
|
||||||
|
|
||||||
echo -e "${CYAN}Importing gravity-sync.conf settings${NC}"
|
echo -e "${CYAN}Importing gravity-sync.conf settings${NC}"
|
||||||
if [ -f ~/${LOCAL_FOLDR}/gravity-sync.conf ]
|
if [ -f ~/${LOCAL_FOLDR}/gravity-sync.conf ]
|
||||||
then
|
then
|
||||||
@ -43,15 +44,17 @@ else
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##############################################
|
# FUNCTION DEFINITIONS #######################
|
||||||
|
|
||||||
# FUNCTIONS
|
# Update Function
|
||||||
|
|
||||||
function update_gs {
|
function update_gs {
|
||||||
git reset --hard
|
git reset --hard
|
||||||
git pull
|
git pull
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Pull Function
|
||||||
|
|
||||||
function pull_gs {
|
function pull_gs {
|
||||||
echo -e "${CYAN}Copying ${GRAVITY_FI} from remote server ${REMOTE_HOST}${NC}"
|
echo -e "${CYAN}Copying ${GRAVITY_FI} from remote server ${REMOTE_HOST}${NC}"
|
||||||
rsync -v --progress -e 'ssh -p 22' ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} ~/${LOCAL_FOLDR}/${GRAVITY_FI}
|
rsync -v --progress -e 'ssh -p 22' ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} ~/${LOCAL_FOLDR}/${GRAVITY_FI}
|
||||||
@ -71,6 +74,8 @@ function pull_gs {
|
|||||||
echo -e "${GREEN}gravity.db pull completed${NC}"
|
echo -e "${GREEN}gravity.db pull completed${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Push Function
|
||||||
|
|
||||||
function push_gs {
|
function push_gs {
|
||||||
echo -e "${YELLOW}WARNING: DATA LOSS IS POSSIBLE${NC}"
|
echo -e "${YELLOW}WARNING: DATA LOSS IS POSSIBLE${NC}"
|
||||||
echo -e "This will send the running ${GRAVITY_FI} from this server to your primary Pihole"
|
echo -e "This will send the running ${GRAVITY_FI} from this server to your primary Pihole"
|
||||||
@ -100,14 +105,16 @@ function push_gs {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################
|
function logs_gs{
|
||||||
|
echo -e "These are the last three valid PULL timestamps"
|
||||||
|
tail -n 3 ${SYNCING_LOG}
|
||||||
|
}
|
||||||
|
|
||||||
# print title
|
# Validate Functions
|
||||||
# echo -e "${GREEN}Gravity Sync ${VERSION}${NC}"
|
|
||||||
|
|
||||||
echo -e "${CYAN}Validating sync folder configuration${NC}"
|
## Validate GS Folders
|
||||||
|
|
||||||
# check to see if logging/backup directory is available
|
function validate_gs_folders {
|
||||||
if [ -d ~/${LOCAL_FOLDR} ]
|
if [ -d ~/${LOCAL_FOLDR} ]
|
||||||
then
|
then
|
||||||
echo -e "${GREEN}Success${NC}: Required directory ~/${LOCAL_FOLDR} is present"
|
echo -e "${GREEN}Success${NC}: Required directory ~/${LOCAL_FOLDR} is present"
|
||||||
@ -115,8 +122,11 @@ else
|
|||||||
echo -e "${RED}Failure${NC}: Required directory ~/${LOCAL_FOLDR} is missing"
|
echo -e "${RED}Failure${NC}: Required directory ~/${LOCAL_FOLDR} is missing"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# check to see if current pihole directory is correct
|
## Validate PH Folders
|
||||||
|
|
||||||
|
function validate_ph_folders {
|
||||||
if [ -d ${PIHOLE_DIR} ]
|
if [ -d ${PIHOLE_DIR} ]
|
||||||
then
|
then
|
||||||
echo -e "${GREEN}Success${NC}: Required directory ${PIHOLE_DIR} is present"
|
echo -e "${GREEN}Success${NC}: Required directory ${PIHOLE_DIR} is present"
|
||||||
@ -124,6 +134,21 @@ else
|
|||||||
echo -e "${RED}Failure${NC}: Required directory ${PIHOLE_DIR} is missing"
|
echo -e "${RED}Failure${NC}: Required directory ${PIHOLE_DIR} is missing"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate_gs_arguments {
|
||||||
|
echo "Usage: $0 {pull|push}"
|
||||||
|
echo -e "> ${YELLOW}Pull${NC} will copy the ${GRAVITY_FI} configuration on $REMOTE_HOST to this server"
|
||||||
|
echo -e "> ${YELLOW}Push${NC} will force any changes made on this server to the primary"
|
||||||
|
echo -e "No changes have been made to the system"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# SCRIPT EXECUTION ###########################
|
||||||
|
|
||||||
|
echo -e "${CYAN}Validating sync folder configuration${NC}"
|
||||||
|
validate_gs_folders
|
||||||
|
validate_ph_folders
|
||||||
|
|
||||||
echo -e "${CYAN}Evaluating $0 script arguments${NC}"
|
echo -e "${CYAN}Evaluating $0 script arguments${NC}"
|
||||||
|
|
||||||
@ -131,11 +156,7 @@ case $# in
|
|||||||
|
|
||||||
0)
|
0)
|
||||||
echo -e "${RED}Failure${NC}: ${GRAVITY_FI} replication direction required"
|
echo -e "${RED}Failure${NC}: ${GRAVITY_FI} replication direction required"
|
||||||
echo "Usage: $0 {pull|push}"
|
validate_gs_arguments
|
||||||
echo -e "> ${YELLOW}Pull${NC} will copy the ${GRAVITY_FI} configuration on $REMOTE_HOST to this server"
|
|
||||||
echo -e "> ${YELLOW}Push${NC} will force any changes made on this server to the primary"
|
|
||||||
echo -e "No changes have been made to the system"
|
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
1)
|
1)
|
||||||
@ -166,8 +187,7 @@ case $# in
|
|||||||
|
|
||||||
logs)
|
logs)
|
||||||
echo -e "${GREEN}Success:${NC} Logs Requested"
|
echo -e "${GREEN}Success:${NC} Logs Requested"
|
||||||
echo -e "These are the last three valid PULL timestamps"
|
logs_gs
|
||||||
tail -n 3 ${SYNCING_LOG}
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
Loading…
Reference in New Issue
Block a user