Skip to content

Commit

Permalink
Uses better data source
Browse files Browse the repository at this point in the history
- pulls data frmo /etc/os-release, if available
- OS Details Title - dynamically switches between KERNEL (linux) and OS
VERSION (Mac)
- eliminated title/version in output
  • Loading branch information
robertpeteuil committed Oct 17, 2017
1 parent 41eb6fd commit f3dd349
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions sysis
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#

scriptname="sysis"
scriptbuildnum="3.4.11"
scriptbuilddate="2017-09-07"
scriptbuildnum="3.5.0"
scriptbuilddate="2017-10-17"

############################################################
### VARS INITS
Expand Down Expand Up @@ -141,6 +141,7 @@ cleanCPUname() {
tempCPUname=${tempCPUname/' CPU'/} # remove ' CPU'
tempCPUname=${tempCPUname/' Processor'/} # remove ' Processor'
tempCPUname=${tempCPUname%' @'*} # remove speed
tempCPUname=${tempCPUname%' '*} # remove model #
tempCPUname=$(cleanText "$tempCPUname") # remove leading / trailine space
echo -n "$tempCPUname"
}
Expand Down Expand Up @@ -203,34 +204,49 @@ getSystem() {
if [[ $(dpkg --help 2> /dev/null) ]]; then
PROCarch=$(dpkg --print-architecture)
fi
if [[ $(lsb_release -h 2> /dev/null) ]]; then
LSBset="TRUE"
if [ -r /etc/os-release ]; then
VALUESvia="FILE"
# LSBid="$(. /etc/os-release && echo "$NAME")"
# LSBdescrPRE=$(lsb_release -d 2> /dev/null)
LSBrel="$(. /etc/os-release && echo "$PRETTY_NAME")"
# LSBrelPRE=$(lsb_release -r 2> /dev/null)
LSBcodename="$(. /etc/os-release && echo "$VERSION")"
LSBcodename=${LSBcodename#* (}
LSBcodename=${LSBcodename%)}
# LSBallPRE=$(lsb_release -a 2> /dev/null)
elif [[ $(lsb_release -h 2> /dev/null) ]]; then
VALUESvia="LSB"
LSBidPRE=$(lsb_release -i 2> /dev/null)
LSBdescrPRE=$(lsb_release -d 2> /dev/null)
# LSBdescrPRE=$(lsb_release -d 2> /dev/null)
LSBrelPRE=$(lsb_release -r 2> /dev/null)
LSBcodenamePRE=$(lsb_release -c 2> /dev/null)
LSBallPRE=$(lsb_release -a 2> /dev/null)
# LSBallPRE=$(lsb_release -a 2> /dev/null)
[[ -n $LSBidPRE ]] && LSBid=${LSBidPRE#*":"} && LSBid=$(cleanText "$LSBid")
[[ -n $LSBdescrPRE ]] && LSBdescr=${LSBdescrPRE#*":"} && LSBdescr=$(cleanText "$LSBdescr")
# [[ -n $LSBdescrPRE ]] && LSBdescr=${LSBdescrPRE#*":"} && LSBdescr=$(cleanText "$LSBdescr")
[[ -n $LSBrelPRE ]] && LSBrel=${LSBrelPRE#*":"} && LSBrel=$(cleanText "$LSBrel")
[[ -n $LSBcodenamePRE ]] && LSBcodename=${LSBcodenamePRE#*":"} && LSBcodename=$(cleanText "$LSBcodename")
[[ -n $LSBallPRE ]] && LSBall=${LSBallPRE#*":"} && LSBall=$(cleanText "$LSBall")
# [[ -n $LSBallPRE ]] && LSBall=${LSBallPRE#*":"} && LSBall=$(cleanText "$LSBall")
fi
return 0
}

setLinuxCommon() {
if [[ $LSBset == "TRUE" ]]; then # plan a - use vals from lsb_release
OSfullname="${LSBid} ${SYSkernal} ${LSBrel}"
if [[ $VALUESvia == "FILE" ]]; then # plan a - use vals from file
OSfullname="${LSBrel}"
OScodename="${LSBcodename}"
elif [[ $VALUESvia == "LSB" ]]; then # plan b - use vals from lsb_release
# OSfullname="${LSBid} ${SYSkernal} ${LSBrel}"
# SYSkernal was always Linux, so commented out
OSfullname="${LSBid} ${LSBrel}"
OScodename="${LSBcodename}"
else # plan b - get vals from release doc
if [ -e "/etc/*release" ]; then
OSrelease=$(awk '/^VERSION_ID=/ {split($1, ary, /"/); print ary[2]}' /etc/*release)
OSfullname="$(awk '/^ID=/ { print toupper(substr($name,4,1)) tolower(substr($name,5))}' /etc/*release) ${SYSkernal} ${OSrelease}"
OScodename=$(awk '/^VERSION=/ {split($0, ary, /(\()||(\))/); print toupper(substr(ary[2],1,1)) tolower(substr(ary[2],2)) }' /etc/*release)
else # plan c - get OS name from uname
OSfullname="${SYSkernal}"
fi
# if [ -e "/etc/*release" ]; then
# OSrelease=$(awk '/^VERSION_ID=/ {split($1, ary, /"/); print ary[2]}' /etc/*release)
# OSfullname="$(awk '/^ID=/ { print toupper(substr($name,4,1)) tolower(substr($name,5))}' /etc/*release) ${SYSkernal} ${OSrelease}"
# OScodename=$(awk '/^VERSION=/ {split($0, ary, /(\()||(\))/); print toupper(substr(ary[2],1,1)) tolower(substr(ary[2],2)) }' /etc/*release)
# else # plan c - get OS name from uname
OSfullname="${SYSkernal}"
# fi
fi
if [ -e "/sys/devices/system/cpu/possible" ]; then
DEVICEinfoExists=true
Expand All @@ -251,6 +267,7 @@ setLinuxCommon() {

setRPI() {
DeviceType="RPI"
OSdetails="KERNEL\t"
setLinuxCommon
if [ -e "/proc/cpuinfo" ]; then
DEVICEinfoExists=true
Expand Down Expand Up @@ -306,8 +323,9 @@ setRPI() {

setLinux() {
DeviceType="Linux"
OSdetails="KERNEL\t"
setLinuxCommon
OSversion=${SYSkernalVer%%"-"*}
OSversion=${SYSkernalVer%"-"*}
HWdevice=""
HWrelease=""
if [ -e "/proc/cpuinfo" ]; then
Expand All @@ -325,6 +343,7 @@ setLinux() {

setMac() {
DeviceType="Mac"
OSdetails="OS VERSION"
DEVICEinfoExists=true
MacOSinitialVer=${SYSkernalVer%%.*}
MacOSadjustedVer=$((MacOSinitialVer-4))
Expand Down Expand Up @@ -402,9 +421,15 @@ reportDebug() {
echo -e "\t${CLRtitle}SYSkernalVer = \t${CLRwhite}${SYSkernalVer}"
echo -e "\t${CLRtitle}SYSmachine = \t${CLRwhite}${SYSmachine}"
echo -e "\t${CLRtitle}SYSplatform = \t${CLRwhite}${SYSplatform}\n"
if [[ "$LSBset" == "TRUE" ]]; then
if [[ "$VALUESvia" == "FILE" ]]; then
echo -e "\t${CLRheading}/ETC/OS-RELEASE${CLRwhite}"
# echo -e "\t${CLRtitle}LSBdescr = \t${CLRwhite}${LSBdescr}"
# echo -e "\t${CLRtitle}LSBid = \t${CLRwhite}${LSBid}"
echo -e "\t${CLRtitle}LSBrel = \t${CLRwhite}${LSBrel}"
echo -e "\t${CLRtitle}LSBcodename = \t${CLRwhite}${LSBcodename}${CLRnormal}\n"
elif [[ "$VALUESvia" == "LSB" ]]; then
echo -e "\t${CLRheading}LSB_RELEASE${CLRwhite}"
echo -e "\t${CLRtitle}LSBdescr = \t${CLRwhite}${LSBdescr}"
# echo -e "\t${CLRtitle}LSBdescr = \t${CLRwhite}${LSBdescr}"
echo -e "\t${CLRtitle}LSBid = \t${CLRwhite}${LSBid}"
echo -e "\t${CLRtitle}LSBrel = \t${CLRwhite}${LSBrel}"
echo -e "\t${CLRtitle}LSBcodename = \t${CLRwhite}${LSBcodename}${CLRnormal}\n"
Expand All @@ -426,7 +451,7 @@ reportDebug() {
}

reportNetwork() {
printTitle
# printTitle
echo -e "\t${CLRheading}HOST\t\t${CLRheading2}${MACHINE_NAME}"
[[ -n $SYSnode ]] && [[ "$SYSnode" != "$HOSTNAME" ]] && echo -e "\t${CLRheading}NODE\t\t${CLRheading2}${SYSnode}"
if [[ $lanIP != "Unknown" ]]; then
Expand All @@ -442,7 +467,8 @@ reportNetwork() {
reportSystem() {
echo -e "\t${CLRheading}OS\t\t${CLRheading2}${OSfullname}"
[[ -n $OScodename ]] && echo -e "\t${CLRtitle}CODENAME\t${CLRwhite}${OScodename}"
[[ -n $OSversion ]] && echo -e "\t${CLRtitle}OS VERSION\t${CLRwhite}${OSversion}"
# [[ -n $OSversion ]] && echo -e "\t${CLRtitle}OS VERSION\t${CLRwhite}${OSversion}"
[[ -n $OSversion ]] && echo -e "\t${CLRtitle}${OSdetails}\t${CLRwhite}${OSversion}"
if [ $DEVICEinfoExists ]; then
echo -e "\n\t${CLRheading}DEVICE\t\t${CLRheading2}${HWdevice}"
[[ -n $HWrelease ]] && echo -e "\t${CLRtitle}RELEASE DATE\t${CLRwhite}${HWrelease}"
Expand All @@ -451,7 +477,6 @@ reportSystem() {
[[ -n $MEMusage ]] && echo -e "\t${CLRtitle}MEM USAGE\t${CLRwhite}${MEMusage}"
[[ -n $DISKusage ]] && echo -e "\t${CLRtitle}DISK USAGE\t${CLRwhite}${DISKusage}$CLRnormal"
fi
echo
return 0
}

Expand All @@ -464,6 +489,7 @@ reportMain() {
[[ "$SYSplatform" != "unknown" ]] && HWdevice=${SYSplatform}
fi
reportSystem
echo
return 0
}

Expand Down

0 comments on commit f3dd349

Please sign in to comment.