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

Commit

Permalink
3.2.2 (#132)
Browse files Browse the repository at this point in the history
* start 3.2.2

* -z

* !=

* “”

* headers

* Change to new PH_EXEC run

* Empty list detection for CNAME

* IGNORE list

* Skip Gravity logic

* oops

* Two == to be super serious

* variables are hard

* change colors

* the colors

* I’m getting rusty

* echo_lines

* 3.2.2

Co-authored-by: Michael Stanclift <vmstan@sovereign.local>
  • Loading branch information
vmstan and Michael Stanclift authored Jan 10, 2021
1 parent 1c033ef commit b912f74
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 87 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ An example would be setting different caching options for Pi-hole, or specifying
- Changes application of permissions for Docker instances to UID:GID instead of names. (#99/#128)
- Adds `./gravity-sync info` function to help with troubleshooting installation/configuration settings.

#### 3.2.2

- Restore process completely revamped. You can now choose to ignore any of the three elements during restore. The prompts are clearer and more consistent with Gravity Sync script styling. Importantly, lack of backup files in an element will not cause the restoration to fail.

## 3.1

### The Container Release
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1
3.2.2
2 changes: 1 addition & 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.2.1'
VERSION='3.2.2'

# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
# Requires Pi-Hole 5.x or higher already be installed, for help visit https://pi-hole.net
Expand Down
7 changes: 6 additions & 1 deletion includes/gs-colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ function echo_fail {
### Request
function echo_need {
echo -en "${NEED} ${MESSAGE}: "
}
}

### Lines
function echo_lines {
echo -e "========================================================"
}
4 changes: 2 additions & 2 deletions includes/gs-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ function config_delete {
MESSAGE="Configuration File Exists"
echo_warn

echo -e "========================================================"
echo_lines
cat ${LOCAL_FOLDR}/${CONFIG_FILE}
echo -e "========================================================"
echo_lines

MESSAGE="Are you sure you want to erase this configuration?"
echo_warn
Expand Down
235 changes: 157 additions & 78 deletions includes/gs-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,76 +30,152 @@ function restore_gs {
MESSAGE="This will restore your settings on $HOSTNAME with a previous version!"
echo_warn

MESSAGE="PREVIOUS BACKUPS AVAILABLE FOR RESTORATION"
echo_info
ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18

MESSAGE="Select backup date to restore ${GRAVITY_FI} from"
echo_need
read INPUT_BACKUP_DATE
GRAVITY_DATE_LIST=$(ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18)

if [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ]
if [ "${GRAVITY_DATE_LIST}" != "" ]
then
MESSAGE="Backup File Selected"
else
MESSAGE="Invalid Request"
MESSAGE="Previous ${GRAVITY_FI} Versions Available to Restore"
echo_info

exit_nochange
echo_lines
ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18
echo -e "IGNORE-GRAVITY"
echo_lines

MESSAGE="Select backup date to restore ${GRAVITY_FI} from"
echo_need
read INPUT_BACKUP_DATE

if [ "$INPUT_BACKUP_DATE" == "IGNORE-GRAVITY" ]
then
MESSAGE="Skipping Gravity"
echo_warn
elif [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ]
then
MESSAGE="Backup Selected"
echo_good

DO_GRAVITY_RESTORE='1'
else
MESSAGE="Invalid Request"
echo_info

exit_nochange
fi
fi

if [ "$SKIP_CUSTOM" != '1' ]
then

if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then
ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CUSTOM_DNS} | colrm 18

MESSAGE="Select backup date to restore ${CUSTOM_DNS} from"
echo_need
read INPUT_DNSBACKUP_DATE
CUSTOM_DATE_LIST=$(ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CUSTOM_DNS} | colrm 18)

if [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ]
if [ "${CUSTOM_DATE_LIST}" != "" ]
then
MESSAGE="Backup File Selected"
else
MESSAGE="Invalid Request"
MESSAGE="Previous ${CUSTOM_DNS} Versions Available to Restore"
echo_info

exit_nochange
echo_lines
ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CUSTOM_DNS} | colrm 18
echo -e "IGNORE-CUSTOM"
echo_lines

MESSAGE="Select backup date to restore ${CUSTOM_DNS} from"
echo_need
read INPUT_DNSBACKUP_DATE

if [ "$INPUT_DNSBACKUP_DATE" == "IGNORE-CUSTOM" ]
then
MESSAGE="Skipping DNS"
echo_warn
elif [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ]
then
MESSAGE="Backup Selected"
echo_good

DO_CUSTOM_RESTORE='1'
else
MESSAGE="Invalid Request"
echo_fail

exit_nochange
fi
else
MESSAGE="No ${CUSTOM_DNS} Backups"
echo_info
fi
fi
fi

if [ "$INCLUDE_CNAME" == '1' ]
then

if [ -f ${DNSMAQ_DIR}/${CNAME_CONF} ]
then
ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CNAME_CONF} | colrm 18

MESSAGE="Select backup date to restore ${CNAME_CONF} from"
echo_need
read INPUT_CNAMEBACKUP_DATE
CNAME_DATE_LIST=$(ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CNAME_CONF} | colrm 18)

if [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_CNAMEBACKUP_DATE}-${CNAME_CONF}.backup ]
if [ "${CNAME_DATE_LIST}" != "" ]
then
MESSAGE="Backup File Selected"
else
MESSAGE="Invalid Request"
MESSAGE="Previous ${CNAME_CONF} Versions Available to Restore"
echo_info

exit_nochange
echo_lines
ls ${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CNAME_CONF} | colrm 18
echo -e "IGNORE-CNAME"
echo_lines

MESSAGE="Select backup date to restore ${CNAME_CONF} from"
echo_need
read INPUT_CNAMEBACKUP_DATE

if [ "$INPUT_CNAMEBACKUP_DATE" == "IGNORE-CNAME" ]
then
MESSAGE="Skipping CNAME"
echo_warn
elif [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_CNAMEBACKUP_DATE}-${CNAME_CONF}.backup ]
then
MESSAGE="Backup Selected"
echo_good

DO_CNAME_RESTORE='1'
else
MESSAGE="Invalid Request"
echo_fail

exit_nochange
fi
else
MESSAGE="No ${CNAME_CONF} Backups"
echo_info
fi
fi
fi

MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected"
echo_info
MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected"
echo_info
MESSAGE="${CNAME_CONF} from ${INPUT_CNAMEBACKUP_DATE} Selected"
echo_info
if [ "$DO_GRAVITY_RESTORE" == "1" ]
then
MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected"
echo_info
else
MESSAGE="${GRAVITY_FI} Restore Unavailable"
echo_info
fi

if [ "$DO_CUSTOM_RESTORE" == "1" ]
then
MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected"
echo_info
else
MESSAGE="${CUSTOM_DNS} Restore Unavailable"
echo_info
fi

if [ "$DO_CNAME_RESTORE" == "1" ]
then
MESSAGE="${CNAME_CONF} from ${INPUT_CNAMEBACKUP_DATE} Selected"
echo_info
else
MESSAGE="${CNAME_CONF} Restore Unavailable"
echo_info
fi

intent_validate

Expand All @@ -109,53 +185,56 @@ function restore_gs {
MESSAGE="Stopping Pi-hole Services"
echo_stat

sudo service pihole-FTL stop >/dev/null 2>&1
${PH_EXEC} stop >/dev/null 2>&1
error_validate

MESSAGE="Restoring ${GRAVITY_FI} on $HOSTNAME"
echo_stat
sudo cp ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate

MESSAGE="Validating Ownership on ${GRAVITY_FI}"
echo_stat

GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk 'OFS=":" {print $3,$4}')
if [ "$GRAVDB_OWN" == "$FILE_OWNER" ]
if [ "$DO_CUSTOM_RESTORE" == "1" ]
then
echo_good
else
echo_fail

MESSAGE="Attempting to Compensate"
echo_warn

MESSAGE="Setting Ownership on ${GRAVITY_FI}"
MESSAGE="Restoring ${GRAVITY_FI} on $HOSTNAME"
echo_stat
sudo chown ${FILE_OWNER} ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
sudo cp ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate
fi

MESSAGE="Validating Permissions on ${GRAVITY_FI}"
echo_stat

GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}')
if [ "$GRAVDB_RWE" = "-rw-rw-r--" ]
then
echo_good
else
echo_fail

MESSAGE="Attempting to Compensate"
echo_warn
MESSAGE="Validating Ownership on ${GRAVITY_FI}"
echo_stat

GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk 'OFS=":" {print $3,$4}')
if [ "$GRAVDB_OWN" == "$FILE_OWNER" ]
then
echo_good
else
echo_fail

MESSAGE="Attempting to Compensate"
echo_warn

MESSAGE="Setting Ownership on ${GRAVITY_FI}"
echo_stat
sudo chown ${FILE_OWNER} ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate
fi

MESSAGE="Setting Ownership on ${GRAVITY_FI}"
MESSAGE="Validating Permissions on ${GRAVITY_FI}"
echo_stat
sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate

GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}')
if [ "$GRAVDB_RWE" = "-rw-rw-r--" ]
then
echo_good
else
echo_fail

MESSAGE="Attempting to Compensate"
echo_warn

MESSAGE="Setting Ownership on ${GRAVITY_FI}"
echo_stat
sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate
fi
fi

if [ "$SKIP_CUSTOM" != '1' ]
if [ "$DO_CUSTOM_RESTORE" == '1' ]
then
if [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ]
then
Expand Down Expand Up @@ -204,7 +283,7 @@ function restore_gs {
fi
fi

if [ "$INCLUDE_CNAME" == '1' ]
if [ "$DO_CNAME_RESTORE" == '1' ]
then
if [ -f ${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_CNAMEBACKUP_DATE}-${CNAME_CONF}.backup ]
then
Expand Down
8 changes: 4 additions & 4 deletions includes/gs-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function update_gs {

## Show Version
function show_version {
echo -e "========================================================"
echo_lines
MESSAGE="${BOLD}${PROGRAM}${NC} by ${CYAN}@vmstan${NC}"
echo_info

Expand Down Expand Up @@ -72,7 +72,7 @@ function show_version {
fi
fi
echo_info
echo -e "========================================================"
echo_lines
}

function show_info() {
Expand All @@ -87,7 +87,7 @@ function show_info() {
DEVVERSION=""
fi

echo -e "========================================================"
echo_lines
echo -e "${YELLOW}Local Software Versions${NC}"
echo -e "${RED}Gravity Sync${NC} ${VERSION}${DEVVERSION}"
echo -e "${BLUE}Pi-hole${NC}"
Expand Down Expand Up @@ -199,7 +199,7 @@ function show_info() {
fi

echo -e "Remote File Owner Settings: ${RILE_OWNER}"
echo -e "========================================================"
echo_lines
}

## Devmode Task
Expand Down

0 comments on commit b912f74

Please sign in to comment.