mirror of
				https://github.com/vmstan/gravity-sync.git
				synced 2025-11-03 17:17:03 -05:00 
			
		
		
		
	* Begin work on Docker support * rewrite permission detection * wrong else * Change pihole detection based on sudo results * Write out to devnull * nosodo handle * AND then * scanning * nosudo more * clearer wording on failures * headers * handle nosudo on docker detection better * SUDO sudo * AND THEN * status report rewrite * link * alert on no local install detected * yellow headers like the rest of GS * semi critical issues * purple instead of red * clean up output of sudo detection * give me space * Auto run config script * added logo * center logo * move intro * trying dev/tty * advanced config generate * != * logic is hard * new logo * image * fonts * svg image * remove h1 * use rihole variable * New root check * better method of checking sudo * remove messages * rihole * attempting realpath * GS_FILEPATH * remove $HOME call * remove config requirement for updates * no config for updates * all the variables * all kinds of variable replacements * double quotes * it’s like I’ve forgotten how to write this stuff * removals * updated requirements * variable rearrangement * validation check for docker * riholes * placeholder * more riholes * even more riholes * docker examples * docker rewrite * docker docker docker * docker custom checks * update from anywhere * correct validation error * check for current owner only if local install * give me space * stuff * more stuff * bash alias creation * cleanup installer * fix .sh * config errors, remove sshpass validation * skip directories if done * limit config script * fix for changes when both targets have changed * RIHOLE * cleanup warning messages * stop sign * big red * documenting new variables * master Co-authored-by: Michael Stanclift <vmstan@sovereign.vmstan.net> Co-authored-by: Michael Stanclift <vmstan@sovereign.local>
		
			
				
	
	
		
			114 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
# GRAVITY SYNC BY VMSTAN #####################
 | 
						|
# gs-automate.sh #############################
 | 
						|
 | 
						|
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
 | 
						|
# This code is called from the main gravity-sync.sh file and should not execute directly!
 | 
						|
 | 
						|
## Automate Task
 | 
						|
function task_automate {
 | 
						|
	TASKTYPE='AUTOMATE'
 | 
						|
	MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
 | 
						|
	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
 | 
						|
		CRON_EXIST='1'
 | 
						|
	fi
 | 
						|
	
 | 
						|
	MESSAGE="Configuring Hourly Smart Sync"
 | 
						|
	echo_info
 | 
						|
 | 
						|
	if [[ $1 =~ ^[0-9][0-9]?$ ]]
 | 
						|
	then
 | 
						|
		INPUT_AUTO_FREQ=$1
 | 
						|
	else
 | 
						|
		MESSAGE="Sync Frequency in Minutes (1-30) or 0 to Disable"
 | 
						|
		echo_need
 | 
						|
		read INPUT_AUTO_FREQ
 | 
						|
	fi
 | 
						|
 | 
						|
	if [ $INPUT_AUTO_FREQ -gt 30 ]
 | 
						|
	then
 | 
						|
		MESSAGE="Invalid Frequency Range"
 | 
						|
		echo_fail
 | 
						|
		exit_nochange
 | 
						|
	elif [ $INPUT_AUTO_FREQ -lt 1 ]
 | 
						|
	then
 | 
						|
		if [ $CRON_EXIST == 1 ]
 | 
						|
		then
 | 
						|
			clear_cron
 | 
						|
 | 
						|
			MESSAGE="Sync Automation Disabled"
 | 
						|
			echo_warn
 | 
						|
		else
 | 
						|
			MESSAGE="No Sync Automation Scheduled"
 | 
						|
			echo_warn
 | 
						|
		fi
 | 
						|
	else
 | 
						|
		if [ $CRON_EXIST == 1 ]
 | 
						|
		then
 | 
						|
			clear_cron
 | 
						|
		fi
 | 
						|
 | 
						|
		MESSAGE="Saving New Sync Automation"
 | 
						|
		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
 | 
						|
	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"
 | 
						|
	echo_stat
 | 
						|
 | 
						|
	crontab -l > cronjob-old.tmp
 | 
						|
	sed "/${GS_FILENAME}/d" cronjob-old.tmp > cronjob-new.tmp
 | 
						|
	crontab cronjob-new.tmp 2>/dev/null
 | 
						|
		error_validate
 | 
						|
	rm cronjob-old.tmp
 | 
						|
	rm cronjob-new.tmp
 | 
						|
}
 | 
						|
 | 
						|
## Cron Task
 | 
						|
function task_cron {
 | 
						|
	TASKTYPE='CRON'
 | 
						|
	MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
 | 
						|
	echo_good
 | 
						|
	
 | 
						|
	show_crontab
 | 
						|
} |