Commit 3073a0d8 authored by clewsy's avatar clewsy

Consolidated ssh options. Added batchmode and disabled hostkeychecking and...

Consolidated ssh options.  Added batchmode and disabled hostkeychecking and send new userknownhost entries to null.
parent dc09ecf2
......@@ -50,16 +50,18 @@ DEST="/dev/null" ## Default destination for command output. I.e. don't displa
APT_GET_VERBOSITY="--quiet=3" ## Default verbosity setting for apt-get commands. Removed by "-v" option.
QUIET=false
######### Define protocol to be used by ssh.
## Options are: "-4" : IPV4
## "-6" : IPV6
## "" : System default.
PROTOCOL="-4"
######### Define path override used with sudo over ssh.
######### Define options to be used by ssh.
## Options are: "-4" : IPV4
## "-6" : IPV6
## "-o StrictHostKeyChecking=no" : Disable user verification for connecting to unknown (not yet authenticated) host.
## "-o UserKnownHostsFile=/dev/null" : Disable automatically saving "newly discovered" hosts to the default knownhosts file.
## "-0 BatchMode=yes" : Disable password prompts and host key confirmation requests.
SSH_OPTIONS="-4 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o ConnectTimeout=4"
######### Define remote path override used with sudo over ssh.
## Fixes an error that otherwise arises if sudo default PATH does not include paths of commands needed by apt-get.
## E.g. Default sudo PATH is negated on an OSMC installation by the /etc/sudoers.d/osmc-no-secure-path file.
PATH_DEF="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
REM_PATH_DEF="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
########## Interpret options
while getopts 'vqh' OPTION; do ## Call getopts to identify selected options and set corresponding flags.
......@@ -145,7 +147,7 @@ while read -r REM_SYS <&2; do ## Loop to repeat commands for each file name entr
###### Attempt connection.
echo -e "Testing ssh connection: ${BLUE}${REM_SYS}${RESET}" > ${DEST}
if [ ${QUIET} = false ]; then echo -e -n "${BOLD}ssh connection...\t${RESET}"; fi
if ! ssh "${PROTOCOL}" -o "BatchMode=yes" -o "ConnectTimeout=4" "${REM_SYS}" "exit" > /dev/null 2>&1; then ## Test ssh connection to current host machine. If it fails...
if ! ssh "${SSH_OPTIONS}" ${REM_SYS} "exit" > /dev/null 2>&1; then ## Test ssh connection to current host machine. If it fails...
{
echo -E "${BOLD}${RED}System not found.${RESET}\t\t${BOLD}${RESET}"
echo -E "${BOLD}${RESET}Skipped.\t\t\t${BOLD}${RESET}"
......@@ -165,7 +167,7 @@ while read -r REM_SYS <&2; do ## Loop to repeat commands for each file name entr
###### Attempt update.
if [ ${QUIET} = false ]; then echo -e -n "${BOLD}update... \t\t${RESET}"; fi
if ! ssh "${PROTOCOL}" -o "BatchMode=yes" "${REM_SYS}" "${PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes update" > ${DEST}; then
if ! ssh ${SSH_OPTIONS} ${REM_SYS} "${REM_PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes update" > ${DEST}; then
{
echo -E "${BOLD}${RESET}apt-get update\t\t${RED}Failure.${RESET}${BOLD}${RESET}"
echo -E "${BOLD}╠═══════════════════════════════╣${RESET}"
......@@ -180,7 +182,7 @@ while read -r REM_SYS <&2; do ## Loop to repeat commands for each file name entr
fi
###### Use apt to check if any packages can be upgraded.
NEW=$(ssh "${PROTOCOL}" -o "BatchMode=yes" "${REM_SYS}" "${PATH_DEF} sudo apt list --upgradable --quiet=2")
NEW=$(ssh ${SSH_OPTIONS} ${REM_SYS} "${REM_PATH_DEF} sudo apt list --upgradable --quiet=2")
if [[ ! ${NEW} ]]; then ## There are no new packages to update.
{
echo -E "${BOLD}${RESET}Up-to-date\t\t${GREEN}Skipped.${RESET}${BOLD}${RESET}"
......@@ -192,7 +194,7 @@ while read -r REM_SYS <&2; do ## Loop to repeat commands for each file name entr
else ## There are new packages to update.
###### Attempt dist-upgrade.
if [ ${QUIET} = false ]; then echo -e -n "${BOLD}dist-upgrade... \t${RESET}"; fi
if ! ssh "${PROTOCOL}" -o "BatchMode=yes" "${REM_SYS}" "${PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes --show-progress dist-upgrade" > ${DEST}; then
if ! ssh ${SSH_OPTIONS} ${REM_SYS} "${REM_PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes --show-progress dist-upgrade" > ${DEST}; then
{
echo -E "${BOLD}${RESET}apt-get dist-upgrade\t${RED}Failure.${RESET}${BOLD}${RESET}"
echo -E "${BOLD}╠═══════════════════════════════╣${RESET}"
......@@ -208,7 +210,7 @@ while read -r REM_SYS <&2; do ## Loop to repeat commands for each file name entr
###### Attempt autoremove.
if [ ${QUIET} = false ]; then echo -e -n "${BOLD}autoremove... \t\t${RESET}"; fi
if ! ssh "${PROTOCOL}" -o "BatchMode=yes" "${REM_SYS}" "${PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes --show-progress autoremove" > ${DEST}; then
if ! ssh ${SSH_OPTIONS} ${REM_SYS} "${REM_PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes --show-progress autoremove" > ${DEST}; then
{
echo -E "${BOLD}${RESET}apt-get autoremove\t${RED}Failure.${RESET}${BOLD}${RESET}"
echo -E "${BOLD}╠═══════════════════════════════╣${RESET}"
......@@ -224,7 +226,7 @@ while read -r REM_SYS <&2; do ## Loop to repeat commands for each file name entr
###### Attempt autoclean.
if [ ${QUIET} = false ]; then echo -e -n "${BOLD}autoclean... \t\t${RESET}"; fi
if ! ssh "${PROTOCOL}" -o "BatchMode=yes" "${REM_SYS}" "${PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes autoclean" > ${DEST}; then
if ! ssh ${SSH_OPTIONS} ${REM_SYS} "${REM_PATH_DEF} sudo apt-get ${APT_GET_VERBOSITY} --assume-yes autoclean" > ${DEST}; then
{
echo -E "${BOLD}${RESET}apt-get autoclean\t${RED}Failure.${RESET}${BOLD}${RESET}"
echo -E "${BOLD}╠═══════════════════════════════╣${RESET}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment