gravity-sync/includes/gs-automate.sh

95 lines
2.4 KiB
Bash
Raw Normal View History

# 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 {
2020-12-31 02:45:47 +00:00
TASKTYPE='AUTOMATE'
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${MESSAGE}: ${TASKTYPE}"
2020-12-31 02:45:47 +00:00
echo_good
2020-12-31 02:49:54 +00:00
2020-12-31 02:45:47 +00:00
CRON_EXIST='0'
CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0')
if [ ${CRON_CHECK} == 1 ]
then
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${UI_AUTO_CRON_EXISTS}"
echo_warn
2020-12-31 02:45:47 +00:00
CRON_EXIST='1'
fi
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${UI_AUTO_CRON_DISPLAY_FREQ}"
2020-12-31 02:45:47 +00:00
echo_info
2020-12-31 02:49:54 +00:00
2020-12-31 02:45:47 +00:00
if [[ $1 =~ ^[0-9][0-9]?$ ]]
then
INPUT_AUTO_FREQ=$1
else
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${UI_AUTO_CRON_SELECT_FREQ}"
2020-12-31 02:45:47 +00:00
echo_need
read INPUT_AUTO_FREQ
INPUT_AUTO_FREQ="${INPUT_AUTO_FREQ:-15}"
2020-12-31 02:45:47 +00:00
fi
2020-12-31 02:49:54 +00:00
if [ $INPUT_AUTO_FREQ == 5 ] || [ $INPUT_AUTO_FREQ == 10 ] || [ $INPUT_AUTO_FREQ == 15 ] || [ $INPUT_AUTO_FREQ == 30 ]
2020-12-31 02:45:47 +00:00
then
if [ $CRON_EXIST == 1 ]
then
clear_cron
fi
2020-12-31 02:49:54 +00:00
if [[ ${PATH} != *"/usr/sbin"* ]]
then
CRON_ENV_PATH=$'PATH=/bin:/usr/bin:/usr/sbin\n'
else
CRON_ENV_PATH=""
fi
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${UI_AUTO_CRON_SAVING}"
2020-12-31 02:45:47 +00:00
echo_stat
(crontab -l 2>/dev/null; echo "${CRON_ENV_PATH}*/${INPUT_AUTO_FREQ} * * * * ${BASH_PATH} ${LOCAL_FOLDR}/${GS_FILENAME} smart > ${LOG_PATH}/${CRONJOB_LOG}") | crontab -
2020-12-31 02:49:54 +00:00
error_validate
elif [ $INPUT_AUTO_FREQ == 0 ]
2020-12-31 02:45:47 +00:00
then
if [ $CRON_EXIST == 1 ]
then
clear_cron
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
# MESSAGE="Synchronization automation has been disabled"
# echo_warn
else
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${UI_AUTO_CRON_DISABLED}"
echo_warn
fi
2020-12-31 02:45:47 +00:00
else
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${UI_INVALID_SELECTION}"
2020-12-31 02:45:47 +00:00
echo_fail
exit_nochange
fi
2020-12-31 02:49:54 +00:00
2020-12-31 02:45:47 +00:00
exit_withchange
}
## Clear Existing Automation Settings
function clear_cron {
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${UI_AUTO_CRON_DISABLED}"
2020-12-31 02:45:47 +00:00
echo_stat
2020-12-31 02:49:54 +00:00
2020-12-31 02:45:47 +00:00
crontab -l > cronjob-old.tmp
sed "/${GS_FILENAME}/d" cronjob-old.tmp > cronjob-new.tmp
crontab cronjob-new.tmp 2>/dev/null
2020-12-31 02:49:54 +00:00
error_validate
2020-12-31 02:45:47 +00:00
rm cronjob-old.tmp
rm cronjob-new.tmp
}
## Cron Task
function task_cron {
2020-12-31 02:45:47 +00:00
TASKTYPE='CRON'
3.3.3 is 3.4.0 (#185) * new first line of script * no requested * Abort! * Test silent folder validation * sameline * echo newline * echo_sameline * what happened? * sameline for ssh * sqlite sameline * Lower case * Reset line * clear line * Flip the line * version update * Backup lowercase * More lowercase * Remove file names from standard messages * Breakout backup message * Output backup folder size * Just H * Invalid replication settings * Compare updated * Colors and updates * Lower case for version output * For Pihole * Cron cleanup * Sudo, or no sudo. * Branch! * Silent error validate * Silent error validate * Clearing up status messages * Records * Primary and secondary * Gravity database * Domain Database * Backup output cleanup * Move file permission validation into new functions * Change restart * UI variables test * Breakout UI variables into new file * Unified validation functions * Replace text strings with variables * Replace text strings with variables * Replace logging with variables * Convert backup to UI variables * Switch restore to UI variables * Fix bug where gravity database did not restore * App validation checks * Rev to 3.4.0 * Convert Push functions to new strings * Completing push UI changes * remove added line * Move purge to UI strings * Move automation to UI strings * Move core strings into UI * Exit strings * First pass at hashing UI * Escape the remote system query (#179) * hashing committed Co-authored-by: Michael Stanclift <vmstan@mstanclift-a03.local> Co-authored-by: Veduco <59983694+Veduco@users.noreply.github.com>
2021-04-01 20:16:20 +00:00
MESSAGE="${MESSAGE}: ${TASKTYPE}"
2020-12-31 02:45:47 +00:00
echo_good
show_crontab
}