Move config section to functions

This commit is contained in:
Michael Stanclift 2020-05-26 21:21:02 -05:00
parent 914af5cd1c
commit 2204497da6

View File

@ -446,147 +446,8 @@ function md5_compare {
} }
# SCRIPT EXECUTION ########################### # Generate Config
SCRIPT_START=$SECONDS function config_generate {
MESSAGE="Evaluating Script Arguments"
echo -en "${STAT} ${MESSAGE}"
case $# in
0)
echo -e "\r${FAIL} ${MESSAGE}"
list_gs_arguments
;;
1)
case $1 in
pull)
echo -e "\r${GOOD} ${MESSAGE}"
import_gs
MESSAGE="Validating Folder Configuration"
echo -e "${INFO} ${MESSAGE}"
validate_gs_folders
validate_ph_folders
validate_os_sshpass
pull_gs
exit
;;
push)
echo -e "\r${GOOD} ${MESSAGE}"
import_gs
echo -e "${INFO} Validating Folder Configuration"
validate_gs_folders
validate_ph_folders
validate_os_sshpass
push_gs
exit
;;
version)
TASKTYPE='VERSION'
show_version
exit_nochange
;;
update)
# TASKTYPE='UPDATE'
echo -e "\r${GOOD} ${MESSAGE}"
echo -e "${INFO} Update Requested"
update_gs
exit_nochange
;;
beta)
# TASKTYPE='BETA'
echo -e "\r${GOOD} ${MESSAGE}"
echo -e "${INFO} Beta Update Requested"
beta_gs
exit_nochange
;;
logs)
TASKTYPE='LOGS'
echo -e "\r${GOOD} ${MESSAGE}"
MESSAGE="Logs Requested"
echo -e "${INFO} ${MESSAGE}"
logs_gs
;;
compare)
TASKTYPE='COMPARE'
echo -e "\r${GOOD} ${MESSAGE}"
import_gs
echo -e "${INFO} Validating Folder Configuration"
validate_gs_folders
validate_ph_folders
validate_os_sshpass
md5_compare
;;
cron)
TASKTYPE='CRON'
echo -e "\r${GOOD} ${MESSAGE}"
show_crontab
;;
config)
TASKTYPE='CONFIG'
echo -e "\r${GOOD} ${MESSAGE}"
echo -e "${INFO} Entering ${TASKTYPE} Mode"
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
then
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
MESSAGE="Configuration File Exists"
echo -e "${WARN} ${MESSAGE}"
echo -e "========================================================"
echo -e "========================================================"
echo -e ""
cat $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
echo -e ""
echo -e "========================================================"
echo -e "========================================================"
MESSAGE="Are you sure you want to erase this configuration?"
echo -e "${WARN} ${MESSAGE}"
select yn in "Yes" "No"; do
case $yn in
Yes )
MESSAGE="Erasing Existing Configuration"
echo -en "${STAT} ${MESSAGE}"
rm -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
error_validate
;;
No )
exit_nochange
;;
esac
done
else
MESSAGE="${CONFIG_FILE} Missing"
echo -e "${INFO} ${MESSAGE}"
MESSAGE="Creating ${CONFIG_FILE} from Template" MESSAGE="Creating ${CONFIG_FILE} from Template"
echo -en "${STAT} ${MESSAGE}" echo -en "${STAT} ${MESSAGE}"
cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
@ -697,6 +558,158 @@ case $# in
validate_os_sshpass validate_os_sshpass
exit_withchange exit_withchange
}
# Delete Existing Configuration
function config_delete {
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
MESSAGE="Configuration File Exists"
echo -e "${WARN} ${MESSAGE}"
echo -e "========================================================"
echo -e "========================================================"
echo -e ""
cat $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
echo -e ""
echo -e "========================================================"
echo -e "========================================================"
MESSAGE="Are you sure you want to erase this configuration?"
echo -e "${WARN} ${MESSAGE}"
select yn in "Yes" "No"; do
case $yn in
Yes )
MESSAGE="Erasing Existing Configuration"
echo -en "${STAT} ${MESSAGE}"
rm -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
error_validate
config_generate
;;
No )
exit_nochange
;;
esac
done
}
# SCRIPT EXECUTION ###########################
SCRIPT_START=$SECONDS
MESSAGE="Evaluating Script Arguments"
echo -en "${STAT} ${MESSAGE}"
case $# in
0)
echo -e "\r${FAIL} ${MESSAGE}"
list_gs_arguments
;;
1)
case $1 in
pull)
echo -e "\r${GOOD} ${MESSAGE}"
import_gs
MESSAGE="Validating Folder Configuration"
echo -e "${INFO} ${MESSAGE}"
validate_gs_folders
validate_ph_folders
validate_os_sshpass
pull_gs
exit
;;
push)
echo -e "\r${GOOD} ${MESSAGE}"
import_gs
echo -e "${INFO} Validating Folder Configuration"
validate_gs_folders
validate_ph_folders
validate_os_sshpass
push_gs
exit
;;
version)
TASKTYPE='VERSION'
show_version
exit_nochange
;;
update)
# TASKTYPE='UPDATE'
echo -e "\r${GOOD} ${MESSAGE}"
echo -e "${INFO} Update Requested"
update_gs
exit_nochange
;;
beta)
# TASKTYPE='BETA'
echo -e "\r${GOOD} ${MESSAGE}"
echo -e "${INFO} Beta Update Requested"
beta_gs
exit_nochange
;;
logs)
TASKTYPE='LOGS'
echo -e "\r${GOOD} ${MESSAGE}"
MESSAGE="Logs Requested"
echo -e "${INFO} ${MESSAGE}"
logs_gs
;;
compare)
TASKTYPE='COMPARE'
echo -e "\r${GOOD} ${MESSAGE}"
import_gs
echo -e "${INFO} Validating Folder Configuration"
validate_gs_folders
validate_ph_folders
validate_os_sshpass
md5_compare
;;
cron)
TASKTYPE='CRON'
echo -e "\r${GOOD} ${MESSAGE}"
show_crontab
;;
config)
TASKTYPE='CONFIG'
echo -e "\r${GOOD} ${MESSAGE}"
echo -e "${INFO} Entering ${TASKTYPE} Mode"
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
then
config_delete
else
MESSAGE="${CONFIG_FILE} Missing"
echo -e "${INFO} ${MESSAGE}"
config_generate
fi fi
;; ;;