gravity-sync/includes/gs-validate.sh

161 lines
4.0 KiB
Bash
Raw Normal View History

# GRAVITY SYNC BY VMSTAN #####################
# gs-validate.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!
## Validate GS Folders
function validate_gs_folders {
2020-12-31 02:45:47 +00:00
MESSAGE="Validating ${PROGRAM} Folders on $HOSTNAME"
echo_stat
2020-12-31 02:49:54 +00:00
if [ ! -d ${LOCAL_FOLDR} ]
then
MESSAGE="Unable to Validate ${PROGRAM} Folders on $HOSTNAME"
echo_fail
exit_nochange
fi
2020-12-31 02:45:47 +00:00
2020-12-31 02:49:54 +00:00
if [ ! -d ${LOCAL_FOLDR}/${BACKUP_FOLD} ]
then
MESSAGE="Unable to Validate ${PROGRAM} Backup Folder on $HOSTNAME"
echo_fail
exit_nochange
fi
2020-12-31 02:45:47 +00:00
echo_good
}
## Validate Pi-hole Folders
function validate_ph_folders {
2020-12-31 02:45:47 +00:00
MESSAGE="Validating Pi-hole Configuration"
echo_stat
2020-12-31 02:49:54 +00:00
if [ "$PH_IN_TYPE" == "default" ]
then
if [ ! -f ${PIHOLE_BIN} ]
2020-12-31 02:45:47 +00:00
then
2020-12-31 02:49:54 +00:00
MESSAGE="Unable to Validate that Pi-Hole is Installed"
echo_fail
exit_nochange
2020-12-31 02:45:47 +00:00
fi
2020-12-31 02:49:54 +00:00
elif [ "$PH_IN_TYPE" == "docker" ]
then
FTLCHECK=$(sudo docker container ls | grep 'pihole/pihole')
if [ "$FTLCHECK" == "" ]
2020-12-31 02:45:47 +00:00
then
2020-12-31 02:49:54 +00:00
MESSAGE="Unable to Validate that Pi-Hole is Installed"
2020-12-31 02:45:47 +00:00
echo_fail
exit_nochange
fi
2020-12-31 02:49:54 +00:00
fi
if [ ! -d ${PIHOLE_DIR} ]
then
MESSAGE="Unable to Validate Pi-Hole Configuration Directory"
echo_fail
exit_nochange
fi
2020-12-31 02:45:47 +00:00
echo_good
}
## Validate SQLite3
function validate_sqlite3 {
2020-12-31 02:45:47 +00:00
MESSAGE="Validating SQLITE Installed on $HOSTNAME"
echo_stat
2020-12-31 02:49:54 +00:00
if hash sqlite3 2>/dev/null
then
# MESSAGE="SQLITE3 Utility Detected"
echo_good
else
MESSAGE="Unable to Validate SQLITE Install on $HOSTNAME"
echo_warn
MESSAGE="Installing SQLLITE3 with ${PKG_MANAGER}"
echo_stat
${PKG_INSTALL} sqllite3 >/dev/null 2>&1
error_validate
fi
}
## Validate SSHPASS
function validate_os_sshpass {
2020-12-31 02:45:47 +00:00
# SSHPASSWORD=''
2020-12-31 02:49:54 +00:00
2020-12-31 02:45:47 +00:00
# if hash sshpass 2>/dev/null
3.1.0 (#105) * 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>
2020-10-19 18:48:23 +00:00
# then
2020-12-31 02:45:47 +00:00
# MESSAGE="SSHPASS Utility Detected"
# echo_warn
# if [ -z "$REMOTE_PASS" ]
# then
# MESSAGE="Using SSH Key-Pair Authentication"
# echo_info
# else
# MESSAGE="Testing Authentication Options"
# echo_stat
2020-12-31 02:49:54 +00:00
2020-12-31 02:45:47 +00:00
# timeout 5 ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1
# if [ "$?" != "0" ]
# then
# SSHPASSWORD="sshpass -p ${REMOTE_PASS}"
# MESSAGE="Using SSH Password Authentication"
# echo_warn
# else
# MESSAGE="Valid Key-Pair Detected ${NC}(${RED}Password Ignored${NC})"
# echo_info
# fi
# fi
3.1.0 (#105) * 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>
2020-10-19 18:48:23 +00:00
# else
# SSHPASSWORD=''
2020-12-31 02:45:47 +00:00
# MESSAGE="Using SSH Key-Pair Authentication"
# echo_info
3.1.0 (#105) * 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>
2020-10-19 18:48:23 +00:00
# fi
2020-12-31 02:45:47 +00:00
MESSAGE="Validating Connection to ${REMOTE_HOST}"
echo_stat
2020-12-31 02:49:54 +00:00
2020-12-31 02:45:47 +00:00
CMD_TIMEOUT='5'
CMD_REQUESTED="exit"
2020-12-31 02:49:54 +00:00
create_sshcmd
2020-12-31 02:45:47 +00:00
}
## Detect Package Manager
2020-12-31 02:49:54 +00:00
function distro_check {
2020-12-31 02:45:47 +00:00
if hash apt-get 2>/dev/null
then
PKG_MANAGER="apt-get"
PKG_INSTALL="sudo apt-get --yes --no-install-recommends --quiet install"
elif hash rpm 2>/dev/null
then
if hash dnf 2>/dev/null
then
PKG_MANAGER="dnf"
elif hash yum 2>/dev/null
then
PKG_MANAGER="yum"
else
MESSAGE="Unable to find OS Package Manager"
echo_info
exit_nochange
fi
PKG_INSTALL="sudo ${PKG_MANAGER} install -y"
else
MESSAGE="Unable to find OS Package Manager"
echo_info
exit_nochange
fi
}
## Dropbear Warning
function dbclient_warning {
2020-12-31 02:45:47 +00:00
if hash dbclient 2>/dev/null
then
if hash ssh 2>/dev/null
then
NOEMPTYBASHIF="1"
else
MESSAGE="Dropbear support has been deprecated - please convert to OpenSSH"
echo_warn
fi
fi
}