Testing seems to have gone ok, still working on damentz patch. The code seems quiet good. H2, awesome job on it :) Any thoughts about inxi 1.0 ?

This commit is contained in:
trash80.v2.0 2008-12-24 09:59:03 +00:00
parent cfa634c6bc
commit 9179e6a477

613
inxi
View file

@ -1,8 +1,8 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 0.8.13
#### Date: December 16 2008
#### version: 0.9
#### Date: December 24 2008
########################################################################
#### inxi is a fork of infobash 3.02, the original bash sys info script by locsmif
#### As time permits functionality improvements and recoding will occur.
@ -12,7 +12,7 @@
#### Gaim/Pidgin, Weechat, KVIrc and Kopete.
#### Original infobash author and copyright holder:
#### Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif
#### inxi version: Copyright (C) 2008 Warren Scott Rogers & Harald Hope
#### inxi version: Copyright (C) 2008 Scott Rogers & Harald Hope
#### Further fixes (listed as known): Horst Tritremmel <hjt at sidux.com>
####
#### Current script home page: http://techpatterns.com/forums/about1131.html
@ -35,14 +35,15 @@
#### this page: http://www.gnu.org/philosophy/free-sw.html
########################################################################
#### DEPENDENCIES
#### bash >=2.05b(bash), df;readlink;stty;tr;uname;wc(coreutils),
#### bash >=3.0(bash), df;readlink;stty;tr;uname;wc(coreutils),
#### gawk(gawk), grep(grep), hostname(hostname), lspci(pciutils),
#### ps;uptime(procps), glxinfo;xdpyinfo;xrandr(xbase-clients)
#### Also the proc filesystem should be present and mounted
####
#### RECOMMENDS (Needed to run certain features)
#### For local interfaces/IP test: ifconfig (in net-tools for Debian systems)
#### runlevel(sysvinit: to view current runlevel while not in X window system
#### runlevel(sysvinit): to view current runlevel while not in X window system
#### Bash 3.1 for proper array use
########################################################################
#### CONVENTIONS:
#### Indentation: TABS
@ -150,9 +151,29 @@ B_TESTING_1='false'
B_TESTING_2='false'
# Test for X running
B_X_RUNNING='false'
if [[ -n $DISPLAY ]];then
B_X_RUNNING='true'
fi
### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
B_PROC='false'
B_CPUINFO='false'
B_MEMINFO='false'
B_ASOUND_CARDS='false'
B_ASOUND_VERSION='false'
B_BASH_ARRAY='false'
B_IFCONFIG='false'
B_LSB_DIR='false'
B_SCSI_DIR='false'
B_MODULES_DIR='false' #
B_PARTITIONS_DIR='false' #
### Directory's used when present
DIR_CPUINFO='/proc/cpuinfo'
DIR_MEMINFO='/proc/meminfo'
DIR_ASOUND_DEVICE='/proc/asound/cards'
DIR_ASOUND_VERSION='/proc/asound/version'
DIR_LSB_RELEASE='/etc/lsb-release'
DIR_SCSI='/proc/scsi/scsi'
DIR_MODULES='/proc/modules' #
DIR_PARTITIONS='/proc/partitions' #
### Variable initializations: constants
DCOPOBJ="default"
@ -232,6 +253,9 @@ DISTROS_DERIVED="antix-version kanotix-version knoppix-version mandrake-release
DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
DISTROS_PRIMARY="gentoo-release redhat-release slackware-version SuSE-release"
DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
## Distros with known problems
# DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
# Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
### Bans Data
# Precede a banword with $'\2' to prevent it from being subject to automated escaping by the make_ban_lists routine
@ -258,6 +282,180 @@ fi
# Any one of these can override the above if inxi is run
# from Konversation!
########################################################################
#### MAIN: Where it all begins
########################################################################
main()
{
init
# first two functions must be set first for colors etc. Remember, no debugger
# stuff works on these first two functions unless you set the debugging flag
# manually. Debugging flag -@ [number] will not work until get_parameters runs.
set_calculated_variables
## this needs to run before the KONVI stuff is set below
get_start_client
# Check for dependencies before running anything else except above functions
check_script_depends
check_script_suggested_apps
# 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
if [[ $KONVI -eq 1 ]];then
DCPORT="$1"
DCSERVER="$2"
DCTARGET="$3"
shift 3
# 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
IFS=":"
for kde_config in $( kde-config --path data )
do
if [[ -r ${kde_config}${KONVI_CFG} ]];then
source "${kde_config}${KONVI_CFG}"
break
fi
done
IFS="$ORIGINAL_IFS"
fi
## leave this for debugging dcop stuff if we get that working
# print_screen_output "DCPORT: $DCPORT"
# print_screen_output "DCSERVER: $DCSERVER"
# print_screen_output "DCTARGET: $DCTARGET"
# "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
# must be here to allow debugger and other flags to be set.
get_parameters "$@"
# If no colorscheme was set in the parameter handling routine, then set the default scheme
if [[ $COLOR_SCHEME_SET != 'true' ]];then
set_color_scheme "$DEFAULT_SCHEME"
fi
# all the pre-start stuff is in place now
B_SCRIPT_UP='true'
script_debugger "Debugger: $SCRIPT_NAME is up and running..."
# then create the output
print_it_out
## last steps
if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
echo -n ""
fi
# weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
# from the last command is taken..
exit 0
}
#### -------------------------------------------------------------------
#### basic tests: init some boleans
#### -------------------------------------------------------------------
# initialize some boleans, these directories are used throughout the script
# some apps are used for extended functions
init()
{
if [[ -d "/proc/" ]];then
B_PROC='true'
else
error_handler 6
fi
if [[ -e "$DIR_CPUINFO" ]]; then
B_CPUINFO='true'
fi
if [[ -e "$DIR_MEMINFO" ]];then
B_MEMINFO='true'
fi
if [[ -e "$DIR_ASOUND_DEVICE" ]];then
B_ASOUND_CARDS='true'
fi
if [[ -e "$DIR_ASOUND_VERSION" ]];then
B_ASOUND_VERSION='true'
fi
if [[ -f "$DIR_LSB_RELEASE" ]];then
B_LSB_DIR='true'
fi
if [[ -e "$DIR_SCSI" ]];then
B_SCSI_DIR='true'
fi
# lack of ifconfig will throw an error only upon it's usage
if [[ -x ifconfig ]];then
B_IFCONFIG='true'
fi
if [[ -n $DISPLAY ]];then
B_X_RUNNING='true'
fi
if [[ -e $DIR_MODULES ]];then
B_MODULES_DIR='true'
fi
if [[ -e $DIR_PARTITIONS ]];then
B_PARTITIONS_DIR='true'
fi
}
check_script_suggested_apps()
{
local bash_array_test=( "one" "two" )
# check for array ability of bash, this is only good for the warning at this time
# the boolean could be used later
# bash version 2.05b is used in DSL
# bash version 3.0 is used in Puppy Linux
# versions older than 3.1 don't handle arrays
# distro's using below 2.05b are unknown, released in 2002
if [[ ${bash_array_test[1]} == "two" ]];then
B_BASH_ARRAY='true'
else
script_debugger "Suggestion: Bash v3.1 for optimal inxi output"
fi
}
# Determine if any of the absolutely necessary tools are absent
check_script_depends()
{
local app_name='' app_data=''
# bc removed from deps for now
local depends="df free gawk grep hostname lspci ps readlink tr uname uptime wc"
if [[ $B_X_RUNNING == 'true' ]];then
for app_name in xrandr xdpyinfo glxinfo
do
app_data=$( type -p $app_name )
if [[ -z $app_data ]];then
script_debugger "Resuming in non X mode: $app_name not found in path"
B_X_RUNNING='false'
break
fi
done
fi
app_name=''
for app_name in $depends
do
app_data=$( type -p $app_name )
if [[ -z $app_data ]];then
error_handler 5 "$app_name"
fi
done
}
########################################################################
#### UTILITY FUNCTIONS
########################################################################
@ -314,31 +512,31 @@ error_handler()
script_debugger()
{
if [[ $B_SCRIPT_UP == 'true' ]];then
# only return if debugger is off and no pre start up errors have occured
if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
return 0
# print out the stored debugging information if errors occured
elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
do
print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
done
DEBUG_BUFFER_INDEX=0
fi
# or print out normal debugger messages if debugger is on
if [[ $DEBUG -gt 0 ]];then
print_screen_output "$1"
fi
# only return if debugger is off and no pre start up errors have occured
if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
return 0
# print out the stored debugging information if errors occured
elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
do
print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
done
DEBUG_BUFFER_INDEX=0
fi
# or print out normal debugger messages if debugger is on
if [[ $DEBUG -gt 0 ]];then
print_screen_output "$1"
fi
else
if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
error_handler 2
# this case stores the data for later printout, will print out only
# at B_SCRIPT_UP == 'true' if array index > 0
else
A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
# increment count for next pre script up debugging error
(( DEBUG_BUFFER_INDEX++ ))
fi
if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
error_handler 2
# this case stores the data for later printout, will print out only
# at B_SCRIPT_UP == 'true' if array index > 0
else
A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
# increment count for next pre script up debugging error
(( DEBUG_BUFFER_INDEX++ ))
fi
fi
}
@ -419,43 +617,6 @@ sanitize_characters()
}"
}
#### -------------------------------------------------------------------
#### basic tests
#### -------------------------------------------------------------------
# Determine if any of the absolutely necessary tools are absent
check_script_depends()
{
local app_name='' app_data=''
# bc removed from deps for now
local depends="df free gawk grep hostname lspci ps readlink tr uname uptime wc"
if [[ ! -d /proc/ ]];then
error_handler 6
fi
if [[ $B_X_RUNNING == 'true' ]];then
for app_name in xrandr xdpyinfo glxinfo
do
app_data=$( type -p $app_name )
if [[ -z $app_data ]];then
script_debugger "Resuming in non X mode: $app_name not found in path"
B_X_RUNNING='false'
break
fi
done
fi
app_name=''
for app_name in $depends
do
app_data=$( type -p $app_name )
if [[ -z $app_data ]];then
error_handler 5 "$app_name"
fi
done
}
# Filter boilerplate & buzzwords.
# args: $1 - quoted: "$@" array of ban terms
make_ban_lists()
@ -734,8 +895,8 @@ show_options()
print_screen_output "-h - this help menu."
if [[ $B_ALLOW_UPDATE == 'true' ]];then
print_screen_output "-U Auto-update script. Note: if you installed as root, you"
print_screen_output " must be root to update, otherwise user is fine."
fi
print_screen_output " must be root to update, otherwise user is fine."
print_screen_output "-V $SCRIPT_NAME version information. Prints information then exits."
print_screen_output "-% Overrides defective or corrupted data."
print_screen_output "-@ Triggers debugger output. Requires debugging level 1-10."
@ -1056,8 +1217,8 @@ get_audio_data()
IFS=$'\n'
# this first step handles the drivers for cases where the second step fails to find one
device_count=$( egrep -ic '(multimedia audio controller|audio device)' <<< "$lspci_data" )
if [[ $device_count -eq 1 && -f /proc/asound/cards ]];then
device_count=$( echo "$lspci_data" | egrep -ic '(multimedia audio controller|audio device)' )
if [[ $device_count -eq 1 ]] && [[ $B_ASOUND_CARDS == 'true' ]];then
alsa_driver=$( gawk -F ']: ' '
{ IGNORECASE=1 }
# filtering out modems and usb devices like webcams, this might get a
@ -1068,8 +1229,9 @@ get_audio_data()
if ( driver != "" ){
print driver
}
}' /proc/asound/cards )
}' $DIR_ASOUND_DEVICE )
fi
# this is to safeguard against line breaks from results > 1, which if inserted into following
# array will create a false array entry. This is a hack, not a permanent solution.
alsa_driver=$( echo $alsa_driver )
@ -1144,7 +1306,7 @@ get_audio_data()
}') )
# in case of failure of first check do this instead
if [[ ${#A_AUDIO_DATA[@]} -eq 0 && -f /proc/asound/cards ]];then
if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]] && [[ $B_ASOUND_CARDS == 'true' ]];then
A_AUDIO_DATA=( $( gawk -F ']: ' '
{ IGNORECASE=1 }
$1 !~ /modem/ && $2 !~ /modem/ {
@ -1153,7 +1315,7 @@ get_audio_data()
if ( card != "" ){
print card","driver
}
}' /proc/asound/cards ) )
}' $DIR_ASOUND_DEVICE ) )
fi
IFS="$ORIGINAL_IFS"
@ -1168,7 +1330,7 @@ get_audio_alsa_data()
local alsa_data=''
# now we'll get the alsa data if the file exists
if [[ -e /proc/asound/version ]];then
if [[ $B_ASOUND_VERSION == 'true' ]];then
alsa_data=$( gawk '
{ IGNORECASE=1 }
# some alsa strings have the build date in (...)
@ -1181,7 +1343,7 @@ get_audio_alsa_data()
if ( $0 != "" ){
print $0
}
}' /proc/asound/version )
}' $DIR_ASOUND_VERSION )
fi
echo "$alsa_data"
}
@ -1190,17 +1352,19 @@ get_audio_alsa_data()
## return value cpu core count string, this helps resolve the multi redundant lines of old style output
get_cpu_core_count()
{
## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10)
# count the number of processors given
local cpu_core_count=$(grep -ic "cpu cores" /proc/cpuinfo| cut -d':' -f2)
if [[ $B_CPUINFO == 'true' ]]; then
## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10)
# count the number of processors given
local cpu_core_count=$(grep -ic "cpu cores" $DIR_CPUINFO| cut -d':' -f2)
if [[ $cpu_core_count -eq 0 ]];then
cpu_core_count=$(grep -ic "^processor" /proc/cpuinfo| cut -d':' -f2)
fi
local cpu_alpha_count=''
if [[ $cpu_core_count -eq 0 ]];then
cpu_core_count=$(grep -ic "^processor" $DIR_CPUINFO| cut -d':' -f2)
fi
local cpu_alpha_count=''
if [[ $cpu_core_count -lt 2 ]]; then
cpu_core_count=1
if [[ $cpu_core_count -lt 2 ]]; then
cpu_core_count=1
fi
fi
# match the numberic value to an alpha value
@ -1226,67 +1390,69 @@ get_cpu_data()
{
local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits=''
IFS=$'\n'
A_CPU_DATA=($(gawk -F': ' '
{ IGNORECASE=1 }
# TAKE NOTE: \t+ will work for /proc/cpuinfo, but SOME ARBITRARY FILE used for TESTING might contain SPACES!
# Therefore PATCH to use [ \t]+ when TESTING!
/^processor\t+:/ { nr = $NF }
if [[ $B_CPUINFO == 'true' ]];then
IFS=$'\n'
A_CPU_DATA=($(gawk -F': ' '
{ IGNORECASE=1 }
# TAKE NOTE: \t+ will work for $DIR_CPUINFO, but SOME ARBITRARY FILE used for TESTING might contain SPACES!
# Therefore PATCH to use [ \t]+ when TESTING!
/^processor\t+:/ { nr = $NF }
/^model name|^cpu\t+:/ {
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
gsub(/,/, " ", $NF)
gsub(/^ +| +$/, "", $NF)
gsub(/ [ \t]+/, " ", $NF)
cpu[nr, "model"] = $NF
}
/^cpu MHz|^clock\t+:/ {
if (!min) {
min = $NF
/^model name|^cpu\t+:/ {
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
gsub(/,/, " ", $NF)
gsub(/^ +| +$/, "", $NF)
gsub(/ [ \t]+/, " ", $NF)
cpu[nr, "model"] = $NF
}
else {
if ($NF < min) {
/^cpu MHz|^clock\t+:/ {
if (!min) {
min = $NF
}
else {
if ($NF < min) {
min = $NF
}
}
if ($NF > max) {
max = $NF
}
gsub(/MHZ/,"",$NF) ## clears out for cell cpu
gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros
cpu[nr, "speed"] = $NF
}
if ($NF > max) {
max = $NF
}
gsub(/MHZ/,"",$NF) ## clears out for cell cpu
gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros
cpu[nr, "speed"] = $NF
}
/^cache size/ { cpu[nr, "cache"] = $NF }
/^cache size/ { cpu[nr, "cache"] = $NF }
/^flags/ { cpu[nr, "flags"] = $NF }
/^flags/ { cpu[nr, "flags"] = $NF }
/^bogomips/ { cpu[nr, "bogomips"] = $NF }
/^bogomips/ { cpu[nr, "bogomips"] = $NF }
/vendor_id/ {
gsub(/genuine|authentic/,"",$NF)
cpu[nr, "vendor"] = tolower( $NF )
}
/vendor_id/ {
gsub(/genuine|authentic/,"",$NF)
cpu[nr, "vendor"] = tolower( $NF )
}
END {
#if (!nr) { print ",,,"; exit } # <- should this be necessary or should bash handle that
for ( i = 0; i <= nr; i++ ) {
print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] "," cpu[nr, "vendor"]
}
if (!min) {
print "not found"
exit
}
if (min != max) {
printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz")
}
else {
printf("%s %s\n", max, "Mhz")
}
}' /proc/cpuinfo))
END {
#if (!nr) { print ",,,"; exit } # <- should this be necessary or should bash handle that
for ( i = 0; i <= nr; i++ ) {
print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] "," cpu[nr, "vendor"]
}
if (!min) {
print "not found"
exit
}
if (min != max) {
printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz")
}
else {
printf("%s %s\n", max, "Mhz")
}
}' $DIR_CPUINFO))
fi
IFS="$ORIGINAL_IFS"
}
@ -1318,7 +1484,9 @@ get_distro_data()
# if so, use lsb-release, if not, then just use the found file
# this is for only those distro's with self named release/version files
# because Mint does not use such, it must be done as below
if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* && -f /etc/lsb-release ]];then
## this if statement requires the spaces and * as it is, else it won't work
##
if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_DIR == 'true' ]];then
distro_file='lsb-release'
else
distro_file="${i}"
@ -1342,7 +1510,8 @@ get_distro_data()
# otherwise try the default debian/ubuntu /etc/issue file
elif [[ -f /etc/issue ]];then
# lsb gives more manageable and accurate output than issue, but mint should use issue for now
if [[ -f /etc/lsb-release && -z $( grep -i 'mint' /etc/issue ) ]];then
# some bashism, boolean must be in parenthesis to work correctly, ie [[ $(boolean) ]] not [[ $boolean ]]
if [[ $B_LSB_DIR == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then
distro=$( get_distro_lsb_data )
else
distro=$( gawk '
@ -1356,14 +1525,14 @@ get_distro_data()
fi
fi
if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then
if [[ ${#distro} -gt 80 ]] && [[ $B_HANDLE_CORRUPT_DATA != 'true' ]];then
distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}"
fi
## note: would like to actually understand the method even if it's not used
# : ${distro:=Unknown distro o_O}
## test for /etc/lsb-release as a backup in case of failure, in cases where > one version/release file
## were found but the above resulted in null distro value
if [[ -z $distro && -f /etc/lsb-release ]];then
if [[ -z $distro ]] && [[ $B_LSB_DIR == 'true' ]];then
distro=$( get_distro_lsb_data )
fi
## finally, if all else has failed, give up
@ -1384,7 +1553,7 @@ get_distro_lsb_data()
{
local distro=''
if [[ -f /etc/lsb-release && $1 != 'app' ]];then
if [[ $B_LSB_DIR == 'true' ]] && [[ $1 != 'app' ]];then
distro=$( gawk -F '=' '
{ IGNORECASE=1 }
@ -1413,7 +1582,7 @@ get_distro_lsb_data()
}
END {
print distroId distroRelease distroCodename
}' /etc/lsb-release )
}' $DIR_LSB_RELEASE )
fi
# this is HORRIBLY slow, but I don't know why, it runs fast in shell
# if [[ -n $( which lsb_release ) && $1 == 'app' ]];then
@ -1542,9 +1711,11 @@ get_graphics_res_data()
get_graphics_agp_data()
{
local agp_module=''
## not used currently
agp_module=$( gawk '/agp/ && !/agpgart/ && $3 > 0 { print(gensub(/(.*)_agp.*/,"\\1","g",$1)) }' /proc/modules )
if [[ B_MODULES_DIR == 'true' ]];then
## not used currently
agp_module=$( gawk '/agp/ && !/agpgart/ && $3 > 0 { print(gensub(/(.*)_agp.*/,"\\1","g",$1)) }' $DIR_MODULES )
fi
}
## create array of x vendor/version data
@ -1621,35 +1792,38 @@ get_hdd_data_basic()
# disk-dev, capacity, name, usb or not
# final item is the total of the disk
IFS=$'\n'
A_HDD_DATA=( $( gawk -v hddused="$hdd_used" '
/[hs]d[a-z]$/ {
driveSize = $(NF - 1)*1024/1000**3
gsub(/,/, " ", driveSize)
gsub(/^ +| +$/, "", driveSize)
printf( $NF",%.1fGB,,\n", driveSize )
}
# See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
# $1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3}
# special case from this data: 8 0 156290904 sda
$1 ~ /^(3|22|33|8)$/ && $NF ~ /[hs]d[a-z]$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) {size+=$3}
END {
size = size*1024/1000**3 # calculate size in GB size
workingUsed = hddused*1024/1000**3 # calculate workingUsed in GB used
# this handles a special case with livecds where no hdd_used is detected
if ( size > 0 && hddused == "na" ) {
size = sprintf( "%.1f", size )
print size "GB,-"
if [[ B_PARTITIONS_DIR == 'true' ]];then
A_HDD_DATA=( $( gawk -v hddused="$hdd_used" '
/[hs]d[a-z]$/ {
driveSize = $(NF - 1)*1024/1000**3
gsub(/,/, " ", driveSize)
gsub(/^ +| +$/, "", driveSize)
printf( $NF",%.1fGB,,\n", driveSize )
}
else if ( size > 0 && workingUsed > 0 ) {
diskUsed = workingUsed*100/size # calculate used percentage
diskUsed = sprintf( "%.1f", diskUsed )
size = sprintf( "%.1f", size )
print size "GB," diskUsed "% used"
}
else {
print "NA,-" # print an empty array, this will be further handled in the print out function
}
}' /proc/partitions ) )
# See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
# $1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3}
# special case from this data: 8 0 156290904 sda
$1 ~ /^(3|22|33|8)$/ && $NF ~ /[hs]d[a-z]$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) {size+=$3}
END {
size = size*1024/1000**3 # calculate size in GB size
workingUsed = hddused*1024/1000**3 # calculate workingUsed in GB used
# this handles a special case with livecds where no hdd_used is detected
if ( size > 0 && hddused == "na" ) {
size = sprintf( "%.1f", size )
print size "GB,-"
}
else if ( size > 0 && workingUsed > 0 ) {
diskUsed = workingUsed*100/size # calculate used percentage
diskUsed = sprintf( "%.1f", diskUsed )
size = sprintf( "%.1f", size )
print size "GB," diskUsed "% used"
}
else {
print "NA,-" # print an empty array, this will be further handled in the print out function
}
}' $DIR_PARTITIONS ) )
fi
IFS="$ORIGINAL_IFS"
}
@ -1689,7 +1863,7 @@ get_hard_drive_data_advanced()
## then handle libata names
# first get the ata device names, put them into an array
IFS=$'\n'
if [[ -e /proc/scsi/scsi ]]; then
if [[ $B_SCSI_DIR == 'true' ]]; then
a_temp_scsi=( $( gawk '
BEGIN { IGNORECASE=1 }
/host/ {
@ -1714,7 +1888,7 @@ get_hard_drive_data_advanced()
print c
}
}
}' /proc/scsi/scsi) )
}' $DIR_SCSI ) )
fi
IFS="$ORIGINAL_IFS"
@ -1785,7 +1959,7 @@ get_memory_data()
END {
used = tot-notused
printf("%.1f/%.1fMB\n", used/1024, tot/1024)
}' /proc/meminfo )
}' $DIR_MEMINFO )
echo "$memory"
}
@ -1897,7 +2071,7 @@ get_networking_wan_ip_data()
get_networking_local_ip_data()
{
if [[ -n $( which ifconfig ) ]];then
if [[ $B_IFCONFIG == 'true' ]];then
IFS=$'\n'
A_INTERFACES_DATA=( $( ifconfig | gawk '
BEGIN { IGNORECASE=1 }
@ -1942,12 +2116,15 @@ get_networking_local_ip_data()
get_partition_data()
{
#local excluded_file_types='--exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660'
# df doesn't seem to work in script with variables like at the command line
IFS=$'\n'
# sample line: /dev/sda2 ext3 15G 8.9G 4.9G 65% /home
# $NF = partition name; $(NF - 4) = partition size; $(NF - 3) = used, in gB; $(NF - 1) = percent used
## note: by subtracting from the last field number NF, we avoid a subtle issue with LVM df output, where if
## the first field is too long, it will occupy its own line, this way we are getting only the needed data
A_PARTITION_DATA=( $( df -h -T --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk '
A_PARTITION_DATA=( $( df -h -T --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk '
BEGIN { IGNORECASE=1 }
/\/$|\/boot$|\/var$|\/home$|\/tmp$|\/usr$/ && ! /aufs/ {
print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main"
@ -2111,7 +2288,7 @@ print_it_out()
# these will also be loaded in each relevant print function for long output
print_short_data()
{
local current_kernel=$( uname -a | gawk '{print $1,$3,$(NF-1)}' )
local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
local processes="$(( $( ps aux | wc -l ) - 1 ))"
local short_data='' i='' b_background_black='false'
local memory=$( get_memory_data )
@ -2169,7 +2346,7 @@ print_short_data()
#C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
fi
fi
short_data="${C1}CPU${CN}[${C2}${cpu_core_count_string} ${cpu_model} ${C1}clocked at${C2} ${min_max_clock}${CN}] ${C1}Kernel${CN}[${C2}${current_kernel}${CN}] ${C1}Up${CN}[${C2}${FL2}${FL1}${up_time}${FL1}${CN}] ${C1}Mem${CN}[${C2}${FL2}${FL1}${memory}${FL1}${CN}] ${C1}HDD${CN}[${C2}${FL2}${FL1}${hdd_capacity}($hdd_used)${FL1}${CN}] ${C1}Procs${CN}[${C2}${FL2}${FL1}${processes}${FL1}${CN}]"
short_data="${C1}CPU${CN}[${C2}${cpu_core_count_string} ${cpu_model} ${C1}clocked at${C2} ${min_max_clock}${CN}] ${C1}Kernel${CN}[${C2} ${current_kernel}${CN}] ${C1}Up${CN}[${C2}${FL2}${FL1}${up_time}${FL1}${CN}] ${C1}Mem${CN}[${C2}${FL2}${FL1}${memory}${FL1}${CN}] ${C1}HDD${CN}[${C2}${FL2}${FL1}${hdd_capacity}($hdd_used)${FL1}${CN}] ${C1}Procs${CN}[${C2}${FL2}${FL1}${processes}${FL1}${CN}]"
if [[ $SHOW_IRC -gt 0 ]];then
short_data="${short_data} ${C1}Client${CN}[${C2}${IRC_CLIENT}${IRC_CLIENT_VERSION}${CN}]"
@ -2204,7 +2381,7 @@ print_audio_data()
# if [[ -n ${a_audio_working[2]} ]];then
# port_data=" ${C1}at port${C2} ${a_audio_working[2]}"
# fi
# this should only trigger if the /proc/asound/cards data is used, not lspci -nn
# this should only trigger if the $DIR_ASOUND_DEVICE data is used, not lspci -nn
if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
module_version=$( print_module_version "${a_audio_working[3]}" )
fi
@ -2423,7 +2600,7 @@ print_gfx_data()
fi
## note: if glx render or version have no content, then mesa is true
if [[ $B_X_RUNNING == 'true' && $b_is_mesa != 'true' ]];then
if [[ $B_X_RUNNING == 'true' ]] && [[ $b_is_mesa != 'true' ]];then
gfx_data=$( create_print_line " " "${C1}GLX Renderer${C2} ${glx_renderer} ${C1}GLX Version${C2} ${glx_version}${CN}" )
if [[ $B_HANDLE_CORRUPT_DATA == 'true' ]];then
gfx_data="${gfx_data} ${C1}Direct rendering${C2} ${glx_direct_render}${CN}"
@ -2448,7 +2625,7 @@ print_hard_disk_data()
local hdd_capacity=${a_hdd_basic_working[0]}
local hdd_used=${a_hdd_basic_working[1]}
if [[ $VERBOSITY_LEVEL -ge 3 || $B_SHOW_DISK == 'true' ]];then
if [[ $VERBOSITY_LEVEL -ge 3 ]] || [[ $B_SHOW_DISK == 'true' ]];then
## note: the output part of this should be in the print hdd data function, not here
get_hard_drive_data_advanced
for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
@ -2507,7 +2684,7 @@ print_info_data()
# this only triggers if no X data is present
if [[ $B_X_RUNNING != 'true' ]];then
if [[ -a $suggested_app ]];then
if [[ -e $suggested_app ]];then
runlvl="$( runlevel | gawk '{ print $2 }' )"
info_data="${info_data} ${C1}Runlevel${C2} ${runlvl}${CN}"
fi
@ -2703,7 +2880,7 @@ print_system_data()
{
local system_data='' bits=''
local host_name=$( hostname )
local current_kernel=$( uname -a | gawk '{print $1,$3,$(NF-1)}' )
local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
local distro="$( get_distro_data )"
# check for 64 bit first
if [ -n "$( uname -m | grep -o 'x86_64' )" ];then
@ -2713,75 +2890,19 @@ print_system_data()
fi
if [[ $B_SHOW_HOST == 'true' ]];then
system_data=$( create_print_line "System:" "${C1}Host${C2} $host_name ${C1}running${C2}" )
system_data=$( create_print_line "System:" "${C1}Host${C2} $host_name ${C1}Kernel${C2}" )
else
system_data=$( create_print_line "System:" "${C1}running${C2} ${CN}" )
system_data=$( create_print_line "System:" "${C1}Kernel${C2} ${CN}" )
fi
system_data="$system_data ${C2}$current_kernel $bits ${C1}Distro${C2} $distro"
system_data="$system_data ${C2} $current_kernel $bits ${C1}Distro${C2} $distro"
print_screen_output "$system_data"
}
########################################################################
#### SCRIPT EXECUTION
########################################################################
# first two functions must be set first for colors etc. Remember, no debugger
# stuff works on these first two functions unless you set the debugging flag
# manually. Debugging flag -@ [number] will not work until get_parameters runs.
set_calculated_variables
## this needs to run before the KONVI stuff is set below
get_start_client
main $@ ## From the End comes the Beginning
# Check for dependencies before running anything else except above functions
check_script_depends
# 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
if [[ $KONVI -eq 1 ]];then
DCPORT="$1"
DCSERVER="$2"
DCTARGET="$3"
shift 3
# 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
IFS=":"
for kde_config in $( kde-config --path data )
do
if [[ -r ${kde_config}${KONVI_CFG} ]];then
source "${kde_config}${KONVI_CFG}"
break
fi
done
IFS="$ORIGINAL_IFS"
fi
## leave this for debugging dcop stuff if we get that working
# print_screen_output "DCPORT: $DCPORT"
# print_screen_output "DCSERVER: $DCSERVER"
# print_screen_output "DCTARGET: $DCTARGET"
# "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
# must be here to allow debugger and other flags to be set.
get_parameters "$@"
# If no colorscheme was set in the parameter handling routine, then set the default scheme
if [[ $COLOR_SCHEME_SET != 'true' ]];then
set_color_scheme "$DEFAULT_SCHEME"
fi
# all the pre-start stuff is in place now
B_SCRIPT_UP='true'
script_debugger "Debugger: $SCRIPT_NAME is up and running..."
# then create the output
print_it_out
## last steps
if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
echo -n ""
fi
# weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
# from the last command is taken..
exit 0
## note: this EOF is needed for smxi handling, this is what triggers the full download ok
###**EOF**###