mirror of
https://github.com/vmstan/gravity-sync.git
synced 2024-08-30 18:22:11 +00:00
Create logging function
This commit is contained in:
parent
138a4cfdfc
commit
0b2d031109
@ -32,7 +32,6 @@ NC='\033[0m'
|
|||||||
# FUNCTION DEFINITIONS #######################
|
# FUNCTION DEFINITIONS #######################
|
||||||
|
|
||||||
# Import Settings
|
# Import Settings
|
||||||
|
|
||||||
function import_gs {
|
function import_gs {
|
||||||
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 ]
|
||||||
@ -47,7 +46,6 @@ function import_gs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Update Function
|
# Update Function
|
||||||
|
|
||||||
function update_gs {
|
function update_gs {
|
||||||
echo -e "${YELLOW}This update will fail if Gravity Sync was not installed via GitHub${NC}"
|
echo -e "${YELLOW}This update will fail if Gravity Sync was not installed via GitHub${NC}"
|
||||||
git reset --hard
|
git reset --hard
|
||||||
@ -55,7 +53,6 @@ function update_gs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Pull Function
|
# 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,12 +68,11 @@ function pull_gs {
|
|||||||
pihole restartdns
|
pihole restartdns
|
||||||
echo -e "${CYAN}Retaining additional copy of remote ${GRAVITY_FI}${NC}"
|
echo -e "${CYAN}Retaining additional copy of remote ${GRAVITY_FI}${NC}"
|
||||||
mv -v ~/${LOCAL_FOLDR}/${GRAVITY_FI} ~/${LOCAL_FOLDR}/${GRAVITY_FI}.last
|
mv -v ~/${LOCAL_FOLDR}/${GRAVITY_FI} ~/${LOCAL_FOLDR}/${GRAVITY_FI}.last
|
||||||
date >> ~/${LOCAL_FOLDR}/${SYNCING_LOG}
|
logs_export
|
||||||
echo -e "${GREEN}gravity.db pull completed${NC}"
|
echo -e "${GREEN}gravity.db pull completed${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Push Function
|
# 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"
|
||||||
@ -106,15 +102,21 @@ function push_gs {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Logging Functions
|
||||||
|
## Check Log Function
|
||||||
function logs_gs {
|
function logs_gs {
|
||||||
echo -e "These are the last three valid PULL timestamps"
|
echo -e "These are the last three valid PULL timestamps"
|
||||||
tail -n 3 ${SYNCING_LOG}
|
tail -n 3 ${SYNCING_LOG}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Log Out
|
||||||
|
function logs_export {
|
||||||
|
echo -e "Logging timestamps to ${SYNCING_LOG}"
|
||||||
|
date >> ~/${LOCAL_FOLDR}/${SYNCING_LOG}
|
||||||
|
}
|
||||||
|
|
||||||
# Validate Functions
|
# Validate Functions
|
||||||
|
|
||||||
## Validate GS Folders
|
## Validate GS Folders
|
||||||
|
|
||||||
function validate_gs_folders {
|
function validate_gs_folders {
|
||||||
if [ -d ~/${LOCAL_FOLDR} ]
|
if [ -d ~/${LOCAL_FOLDR} ]
|
||||||
then
|
then
|
||||||
@ -126,7 +128,6 @@ function validate_gs_folders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
## Validate PH Folders
|
## Validate PH Folders
|
||||||
|
|
||||||
function validate_ph_folders {
|
function validate_ph_folders {
|
||||||
if [ -d ${PIHOLE_DIR} ]
|
if [ -d ${PIHOLE_DIR} ]
|
||||||
then
|
then
|
||||||
@ -138,7 +139,6 @@ function validate_ph_folders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
## Validate GS Argument Used
|
## Validate GS Argument Used
|
||||||
|
|
||||||
function validate_gs_arguments {
|
function validate_gs_arguments {
|
||||||
echo "Usage: $0 {pull|push}"
|
echo "Usage: $0 {pull|push}"
|
||||||
echo -e "> ${YELLOW}Pull${NC} will copy the ${GRAVITY_FI} configuration on a remote host to this server"
|
echo -e "> ${YELLOW}Pull${NC} will copy the ${GRAVITY_FI} configuration on a remote host to this server"
|
||||||
@ -208,9 +208,10 @@ case $# in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo -e "${RED}Too many arguments provided ($#)${NC}"
|
echo -e "${RED}Too many arguments provided ($#)${NC}"
|
||||||
echo "Usage: $0 {pull|push}"
|
echo "Usage: $0 {pull|push}"
|
||||||
exit 3
|
exit 3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
Loading…
Reference in New Issue
Block a user