first draft of sensors output

This commit is contained in:
inxi-svn 2009-07-27 04:27:01 +00:00
parent 36cf99d1a9
commit e0f4f067a1

236
inxi
View file

@ -1,13 +1,13 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 1.0.16-b1 #### version: 1.1.0-b1
#### Date: 6 June 2009 #### Date: 7 July 2009
######################################################################## ########################################################################
#### SPECIAL THANKS #### SPECIAL THANKS
######################################################################## ########################################################################
#### Special thanks to all those in lsc for their tireless dedication #### Special thanks to all those in #lsc and #smxi for their tireless
#### with helping test inxi modules #### dedication helping test inxi modules.
######################################################################## ########################################################################
#### ABOUT INXI #### ABOUT INXI
######################################################################## ########################################################################
@ -104,6 +104,23 @@
#### ####
#### As with all 'rules' there are acceptions, these are noted where used. #### As with all 'rules' there are acceptions, these are noted where used.
#### ####
###################################################################################
#### KDE Konversation information. Moving from dcop(qt3/KDE3) to dbus(qt4/KDE4)
###################################################################################
#### dcop and dbus -- these talk back to Konversation from this script
####
#### Scripting info -- http://konversation.berlios.de/docs/scripting.html
#### -- http://www.kde.org.uk/apps/konversation/
####
#### dbus info -- http://dbus.freedesktop.org/doc/dbus-tutorial.html
#### view dbus info -- https://fedorahosted.org/d-feet/
#### -- or run qdbus
#### Konvi dbus/usage-- qdbus org.kde.konversation /irc say <server> <target-channel> <output>
####
#### Python usage -- http://wiki.python.org/moin/DbusExamples (just in case)
####
#### Because webpages come and go, the above information needs to be moved to inxi's wiki
####
######################################################################## ########################################################################
#### Valuable Resources #### Valuable Resources
#### gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html #### gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
@ -150,6 +167,7 @@ A_HDD_DATA=''
A_INTERFACES_DATA='' A_INTERFACES_DATA=''
A_NETWORK_DATA='' A_NETWORK_DATA=''
A_PARTITION_DATA='' A_PARTITION_DATA=''
A_SENSORS_DATA=''
A_X_DATA='' A_X_DATA=''
### Boolean true/false globals ## usage: 'B_<var>' ### Boolean true/false globals ## usage: 'B_<var>'
@ -171,6 +189,8 @@ B_ROOT='false'
B_RUNNING_IN_SHELL='false' B_RUNNING_IN_SHELL='false'
# this sets the debug buffer # this sets the debug buffer
B_SCRIPT_UP='false' B_SCRIPT_UP='false'
# sensors only if installed
B_SENSORS='false'
# Show sound card data # Show sound card data
B_SHOW_AUDIO='false' B_SHOW_AUDIO='false'
B_SHOW_CPU='false' B_SHOW_CPU='false'
@ -187,6 +207,7 @@ B_SHOW_NETWORK='false'
# either -v > 3 or -P will show partitions # either -v > 3 or -P will show partitions
B_SHOW_PARTITIONS='false' B_SHOW_PARTITIONS='false'
B_SHOW_PARTITIONS_FULL='false' B_SHOW_PARTITIONS_FULL='false'
B_SHOW_SENSORS='false'
# triggers only short inxi output # triggers only short inxi output
B_SHOW_SHORT_OUTPUT='false' B_SHOW_SHORT_OUTPUT='false'
B_SHOW_SYSTEM='false' B_SHOW_SYSTEM='false'
@ -198,6 +219,8 @@ B_TESTING_2='false'
B_USE_LOGGING='false' B_USE_LOGGING='false'
# Test for X running # Test for X running
B_X_RUNNING='false' B_X_RUNNING='false'
# test for dbus irc client
B_DBUS_CLIENT='false'
### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]] ### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
B_PROC='false' B_PROC='false'
@ -248,7 +271,8 @@ LOGFE=''
# LOGFS=$LOGFS_STRING # LOGFS=$LOGFS_STRING
# LOGFE=$LOGFE_STRING # LOGFE=$LOGFE_STRING
# default to false, no konversation found, 1 is /cmd inxi start, 2 is native konvi script mode # default to false, no konversation found, 1 is native konvi (qt3/KDE3) script mode, 2 is /cmd inxi start,
## 3 is Konversation > 1.2 (qt4/KDE4)
KONVI=0 KONVI=0
# NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups. # NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
# This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping. # This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
@ -303,6 +327,7 @@ IRC_COLORS=" \x0314 \x0301 \x0304 \x0305 \x0309 \x0303 \x0308 \x
# BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL # BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL
ANSI_COLORS="$ANSI_COLORS         " ANSI_COLORS="$ANSI_COLORS         "
IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300 \x0315 \x03" IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300 \x0315 \x03"
#ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS) #ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL ) A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL )
# See above for notes on EMPTY # See above for notes on EMPTY
@ -347,6 +372,8 @@ main()
{ {
eval $LOGFS eval $LOGFS
# This function just initializes variables
initialize_script_data
# Check for dependencies BEFORE running ANYTHING else except above functions # Check for dependencies BEFORE running ANYTHING else except above functions
# Not all distro's have these depends installed by default # Not all distro's have these depends installed by default
@ -356,8 +383,6 @@ main()
# first init function must be set first for colors etc. Remember, no debugger # first init function must be set first for colors etc. Remember, no debugger
# stuff works on this function unless you set the debugging flag manually. # stuff works on this function unless you set the debugging flag manually.
# Debugging flag -@ [number] will not work until get_parameters runs. # Debugging flag -@ [number] will not work until get_parameters runs.
# This function just initializes variables
initialize_script_data
### Only continue if depends ok ### Only continue if depends ok
SCRIPT_PATH=$( dirname $0 ) SCRIPT_PATH=$( dirname $0 )
@ -373,15 +398,29 @@ main()
fi fi
## this needs to run before the KONVI stuff is set below ## this needs to run before the KONVI stuff is set below
## Konversation 1.2 apparently does not like the $PPID test in get_start_client
## So far there is no known way to detect if qt4_konvi is the parent process
## this method will infer qt4_konvi as parent
get_start_client get_start_client
# note: this only works if it's run from inside konversation as a script builtin or something # note: this only works if it's run from inside konversation as a script builtin or something
# only do this if inxi has been started as a konversation script, otherwise bypass this # only do this if inxi has been started as a konversation script, otherwise bypass this
if [[ $KONVI -eq 1 ]];then # KONVI=3 ## for testing puroses
DCPORT="$1" ##
DCSERVER="$2" if [[ $KONVI -eq 1 || $KONVI -eq 3 ]];then
DCTARGET="$3"
shift 3 if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (ie 1.x < 1.2(qt3))
DCPORT="$1"
DCSERVER="$2"
DCTARGET="$3"
shift 3
elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
DCSERVER="$1" ##dbus testing
DCTARGET="$2" ##dbus testing
shift 2
fi
# The section below is on request of Argonel from the Konversation developer team: # The section below is on request of Argonel from the Konversation developer team:
# it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf # it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf
IFS=":" IFS=":"
@ -394,6 +433,7 @@ main()
done done
IFS="$ORIGINAL_IFS" IFS="$ORIGINAL_IFS"
fi fi
## leave this for debugging dcop stuff if we get that working ## leave this for debugging dcop stuff if we get that working
# print_screen_output "DCPORT: $DCPORT" # print_screen_output "DCPORT: $DCPORT"
# print_screen_output "DCSERVER: $DCSERVER" # print_screen_output "DCSERVER: $DCSERVER"
@ -509,6 +549,12 @@ initialize_script_data()
A_INTERFACES_DATA=( "Interfaces tool requires missing app: $DIR_IFCONFIG" ) A_INTERFACES_DATA=( "Interfaces tool requires missing app: $DIR_IFCONFIG" )
fi fi
if [[ -n $( which sensors ) ]];then
B_SENSORS='true'
else
A_SENSORS_DATA=( "Sensors tool requires missing app: lm-sensors" )
fi
if [[ -n $DISPLAY ]];then if [[ -n $DISPLAY ]];then
B_X_RUNNING='true' B_X_RUNNING='true'
fi fi
@ -895,10 +941,17 @@ print_screen_output()
fi fi
fi fi
if [[ $KONVI -eq 1 ]];then if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (<= 1.1 (qt3))
# konvi doesn't seem to like \n characters, it just prints them literally # konvi doesn't seem to like \n characters, it just prints them literally
print_data="$( tr '\n' ' ' <<< "$print_data" )" $print_data="$( tr '\n' ' ' <<< "$print_data" )"
dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data" dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data"
elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
qdbus org.kde.konversation /irc say "$DCSERVER" "$DCTARGET" "$print_data"
# elif [[ $IRC_CLIENT == 'X-Chat' ]]; then
# qdbus org.xchat.service print "$print_data\n"
else else
# the -n is needed to avoid double spacing of output in terminal # the -n is needed to avoid double spacing of output in terminal
echo -ne "$print_data\n" echo -ne "$print_data\n"
@ -958,7 +1011,7 @@ get_parameters()
# the short form only runs if no args output args are used # the short form only runs if no args output args are used
# no need to run through these if there are no args # no need to run through these if there are no args
if [[ -n $1 ]];then if [[ -n $1 ]];then
while getopts Ac:CdDfFGhHiIlNpPSuv:Vx%@:${update_flags} opt while getopts Ac:CdDfFGhHiIlNpPsSuv:Vx%@:${update_flags} opt
do do
case $opt in case $opt in
A) B_SHOW_AUDIO='true' A) B_SHOW_AUDIO='true'
@ -1019,6 +1072,9 @@ get_parameters()
P) B_SHOW_PARTITIONS='true' P) B_SHOW_PARTITIONS='true'
use_short='false' use_short='false'
;; ;;
s) B_SHOW_SENSORS='true'
use_short='false'
;;
S) B_SHOW_SYSTEM='true' S) B_SHOW_SYSTEM='true'
use_short='false' use_short='false'
;; ;;
@ -1153,6 +1209,7 @@ show_options()
print_screen_output "-p Show full partition information (-P plus all other detected partitions)." print_screen_output "-p Show full partition information (-P plus all other detected partitions)."
print_screen_output "-P Show Partition information (shows what -v 4 would show, but without extra data)." print_screen_output "-P Show Partition information (shows what -v 4 would show, but without extra data)."
print_screen_output " Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted partitions." print_screen_output " Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted partitions."
print_screen_output "-s Show sensors output (if sensors installed/configured): mobo/cpu temp, cpu fan speed"
print_screen_output "-S Show System information: host name, kernel, distro" print_screen_output "-S Show System information: host name, kernel, distro"
print_screen_output "-u Show partition UUIDs. Default: short partition -P. For full -p output, use: -pu (or -plu)." print_screen_output "-u Show partition UUIDs. Default: short partition -P. For full -p output, use: -pu (or -plu)."
print_screen_output "-v Script verbosity levels. Verbosity level number is required." print_screen_output "-v Script verbosity levels. Verbosity level number is required."
@ -1231,6 +1288,7 @@ get_start_client()
eval $LOGFS eval $LOGFS
local irc_client_path='' irc_client_path_lower='' non_native_konvi='' i='' local irc_client_path='' irc_client_path_lower='' non_native_konvi='' i=''
local b_non_native_app='false' pppid='' app_working_name='' local b_non_native_app='false' pppid='' app_working_name=''
local b_qt4_konvi='false'
if tty >/dev/null;then if tty >/dev/null;then
IRC_CLIENT='Shell' IRC_CLIENT='Shell'
@ -1304,11 +1362,11 @@ get_start_client()
}' )" }' )"
IRC_CLIENT="Irssi" IRC_CLIENT="Irssi"
;; ;;
konversation) konversation) ## konvi < 1.2 (qt4)
# this is necessary to avoid the dcop errors from starting inxi as a /cmd started script # this is necessary to avoid the dcop errors from starting inxi as a /cmd started script
if [[ $b_non_native_app == 'true' ]];then if [[ $b_non_native_app == 'true' ]];then ## true negative is confusing
KONVI=2 KONVI=2
else else # if native app
KONVI=1 KONVI=1
fi fi
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk ' IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
@ -1470,13 +1528,70 @@ get_start_client()
unset IRC_CLIENT_VERSION unset IRC_CLIENT_VERSION
fi fi
else else
IRC_CLIENT="PPID=\"$PPID\" - empty?" ## lets look to see if qt4_konvi is the parent. There is no direct way to tell, so lets infer it.
unset IRC_CLIENT_VERSION ## because $PPID does not work with qt4_konvi, the above case does not work
b_qt4_konvi=$( is_this_qt4_konvi )
if [[ $b_qt4_konvi == 'true' ]];then
KONVI=3
IRC_CLIENT='Konversation'
IRC_CLIENT_VERSION=" $( konversation -v | gawk '
/Konversation:/ {
for ( i=2; i<=NF; i++ ) {
if (i == NF) {
print $i
}
else {
printf $i" "
}
}
exit
}' )"
else
IRC_CLIENT="PPID=\"$PPID\" - empty?"
unset IRC_CLIENT_VERSION
fi
fi fi
log_function_data "IRC_CLIENT: $IRC_CLIENT :: IRC_CLIENT_VERSION: $IRC_CLIENT_VERSION :: PPID: $PPID" log_function_data "IRC_CLIENT: $IRC_CLIENT :: IRC_CLIENT_VERSION: $IRC_CLIENT_VERSION :: PPID: $PPID"
eval $LOGFE eval $LOGFE
} }
## try to infer the use of Konversation >= 1.2, which shows $PPID improperly
## no known method of finding Kovni >= 1.2 as parent process, so we look to see if it is running,
## and all other irc clients are not running.
is_this_qt4_konvi()
{
local konvi_qt4_client='' konvi_dbus_exist='' konvi_pid='' konvi_home_dir=''
local konvi='' konvi_qt4_ver='' b_is_qt4=''
konvi_dbus_exist=$( qdbus | grep "org.kde.konversation" )
if [[ -n $konvi_dbus_exist && -e /usr/share/kde4/apps/konversation ]]; then
konvi_pid=$( ps -A | grep -i 'konversation' )
konvi_pid=$( echo $konvi_pid | gawk '{ print $1 }' )
konvi_home_dir=$( readlink /proc/$konvi_pid/exe )
konvi=$( echo $konvi_home_dir | sed "s/\// /g" )
konvi=($konvi)
if [[ ${konvi[2]} == 'konversation' ]];then
konvi_qt4_ver=$( konversation -v | grep -i 'konversation' )
konvi_qt4_client=$( echo "$konvi_qt4_ver" | gawk '{ print $2 }' )
if [[ $konvi_qt4_client > 1.1 ]]; then
b_is_qt4='true'
fi
fi
else
konvi_qt4="qt3"
b_is_qt4='false'
fi
echo $b_is_qt4
## for testing this module
#qdbus org.kde.konversation /irc say $1 $2 "getpid_dir: $konvi_qt4 qt4_konvi: $konvi_qt4_ver verNum: $konvi_qt4_ver_num pid: $konvi_pid ppid: $PPID konvi_home_dir: ${konvi[2]}"
}
# This needs some cleanup and comments, not quite understanding what is happening, although generally output is known # This needs some cleanup and comments, not quite understanding what is happening, although generally output is known
# Parse the null separated commandline under /proc/<pid passed in $1>/cmdline # Parse the null separated commandline under /proc/<pid passed in $1>/cmdline
# args: $1 - $PPID # args: $1 - $PPID
@ -2894,6 +3009,47 @@ get_partition_data_advanced()
eval $LOGFE eval $LOGFE
} }
get_sensors_data()
{
eval $LOGFS
if [[ $B_SENSORS == 'true' ]];then
IFS=","
A_SENSORS_DATA=( $( sensors | gawk '
BEGIN {
IGNORECASE=1
moboTemp=""
cpuTemp=""
cpuFan=""
}
# dumping the extra + signs, nobody has negative temps
/M\/B Temp/ {
moboTemp=$3
}
/CPU Temp/ {
cpuTemp=$3
}
/CPU Fan/ {
cpuFan=$3
}
END {
if ( moboTemp != "" && cpuTemp != "" && cpuFan != "" ) {
print moboTemp "," cpuTemp "," cpuFan
}
else {
print "No sensors found. Have you configured your sensors yet?"
}
}
'
) )
IFS="$ORIGINAL_IFS"
fi
log_function_data "A_SENSORS_DATA: ${A_SENSORS_DATA[@]}"
# echo "A_SENSORS_DATA: ${A_SENSORS_DATA[@]}"
eval $LOGFE
}
## return uptime string ## return uptime string
get_uptime() get_uptime()
{ {
@ -3034,6 +3190,9 @@ print_it_out()
if [[ $VERBOSITY_LEVEL -ge 4 || $B_SHOW_PARTITIONS == 'true' ]];then if [[ $VERBOSITY_LEVEL -ge 4 || $B_SHOW_PARTITIONS == 'true' ]];then
print_partition_data print_partition_data
fi fi
if [[ $VERBOSITY_LEVEL -ge 5 || $B_SHOW_SENSORS == 'true' ]];then
print_sensors_data
fi
if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_INFO == 'true' ]];then if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_INFO == 'true' ]];then
print_info_data print_info_data
fi fi
@ -3740,6 +3899,43 @@ print_partition_data()
eval $LOGFE eval $LOGFE
} }
print_sensors_data()
{
eval $LOGFS
local mobo_temp='' cpu_temp='' cpu_fan='' sensors_data=''
get_sensors_data
if [[ ${#A_SENSORS_DATA[@]} -eq 1 ]];then
sensors_data=${A_SENSORS_DATA[0]}
else
if [[ -n ${A_SENSORS_DATA[0]} ]];then
mobo_temp=${A_SENSORS_DATA[0]}
else
mobo_temp='N/A'
fi
mobo_temp="${C1}mobo temp:${C2} $mobo_temp"
if [[ -n ${A_SENSORS_DATA[1]} ]];then
cpu_temp=${A_SENSORS_DATA[1]}
else
cpu_temp='N/A'
fi
cpu_temp="${C1}cpu temp:${C2} $cpu_temp"
if [[ -n ${A_SENSORS_DATA[2]} ]];then
cpu_fan=${A_SENSORS_DATA[2]}
else
cpu_fan='N/A'
fi
cpu_fan="${C1}cpu fan:${C2} $cpu_fan rpm"
sensors_data=${A_SENSORS_DATA[0]}
fi
sensors_data="$mobo_temp $cpu_temp $cpu_fan"
sensors_data=$( create_print_line "Sensors:" "$sensors_data" )
print_screen_output "$sensors_data"
eval $LOGFE
}
print_system_data() print_system_data()
{ {
eval $LOGFS eval $LOGFS