mirror of
https://github.com/vmstan/gravity-sync.git
synced 2024-08-30 18:22:11 +00:00
9dae851a9c
* first! * folders * break out colors * home * seperate update * breakout pull * move file * breakout push * breakout smart * restore breakout * include restore * breakout logs validate ssh * breakout config exit intent * source exit * breakout backup automation and purge * breakout root * file headers * create push pull restore smart functions * consolidate options * include root check * includes * includes 2 * automate * rearrange imports * header * ssh rsync * new install steps * ticks * yellow * host check * check for git * ticks * check for pihole * check sudo powers * create sudo file * write output * pihole directory * install sudo file * purge error message * comment cleanup * installer * header * instructions * l * read p * header * skip prompts * sudo no longer in config * compare exit code * exit with change * 3.0 Co-authored-by: Michael Stanclift <vmstan@Sovereign.vmstan.net> Co-authored-by: Michael Stanclift <vmstan@Sovereign.local>
114 lines
2.5 KiB
Bash
114 lines
2.5 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} $HOME/${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} $HOME/${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
|
|
} |