Refactor GetRemoteOS

pull/84/head
deajan 8 years ago
parent e4188b0f4c
commit 9cafba436d

@ -1,6 +1,6 @@
#### MINIMAL-FUNCTION-SET BEGIN ####
## FUNC_BUILD=2016111403
## FUNC_BUILD=2016111404
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
## To use in a program, define the following variables:
@ -501,7 +501,7 @@ function LoadConfigFile {
}
function Spinner {
if [ $_SILENT == true ] || [ $_LOGGER_ERR_ONLY == true ]; then
if [ $_SILENT == true ] || [ "$_LOGGER_ERR_ONLY" == true ]; then
return 0
fi
@ -915,8 +915,7 @@ function GetLocalOS {
local localOsVar
# There's no good way to tell if currently running in BusyBox shell. Using sluggish way.
ls --help 2>&1 | grep -i BusyBox > /dev/null
if [ $? == 0 ]; then
if ls --help 2>&1 | grep -i "BusyBox" > /dev/null; then
localOsVar="BusyBox"
else
localOsVar="$(uname -spio 2>&1)"
@ -961,6 +960,73 @@ function GetLocalOS {
function GetRemoteOS {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local remoteOsVar
$SSH_CMD bash -s << 'ENDSSH' >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" 2>&1
function GetOs {
local localOsVar
# There's no good way to tell if currently running in BusyBox shell. Using sluggish way.
if ls --help 2>&1 | grep -i "BusyBox" > /dev/null; then
localOsVar="BusyBox"
else
localOsVar="$(uname -spio 2>&1)"
if [ $? != 0 ]; then
localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then
localOsVar="$(uname)"
fi
fi
fi
echo "$localOsVar"
}
GetOs
ENDSSH
if [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" ]; then
remoteOsVar=$(cat "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID")
case $remoteOsVar in
*"Linux"*)
REMOTE_OS="Linux"
;;
*"BSD"*)
REMOTE_OS="BSD"
;;
*"MINGW32"*|*"CYGWIN"*)
REMOTE_OS="msys"
;;
*"Darwin"*)
REMOTE_OS="MacOSX"
;;
*"BusyBox"*)
REMOTE_OS="BUSYBOX"
;;
*"ssh"*|*"SSH"*)
Logger "Cannot connect to remote system." "CRITICAL"
exit 1
;;
*)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented debug only setting
Logger "Running on unknown remote OS [$remoteOsVar]." "WARN"
return
fi
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL"
Logger "Remote OS said:\n$remoteOsVar" "CRITICAL"
exit 1
esac
Logger "Remote OS: [$remoteOsVar]." "DEBUG"
else
Logge "Cannot get Remote OS" "CRITICAL"
fi
}
function OldGetRemoteOS {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local retval
local cmd
local remoteOsVar
@ -969,7 +1035,7 @@ function GetRemoteOS {
CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost
cmd=$SSH_CMD' "ls --help 2>&1 | grep -i BusyBox > /dev/null"'
cmd=$SSH_CMD' "if [ ls --help 2>&1 | grep -i BusyBox > /dev/null ]; then exit 0; else exit 1"'
Logger "cmd: $cmd" "DEBUG"
eval "$cmd" &
WaitForTaskCompletion $! 120 240 ${FUNCNAME[0]}"-0" true $KEEP_LOGGING

Loading…
Cancel
Save