refactored and ordered get data functions

This commit is contained in:
inxi-svn 2008-10-30 05:04:11 +00:00
parent 4a4ee6a650
commit a9e0462c43

296
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 0.1.41 #### version: 0.1.42
#### Date: October 29 2008 #### Date: October 29 2008
######################################################################## ########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif #### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -37,7 +37,7 @@
## Variable initializations: null values ## Variable initializations: null values
COLOR_SCHEME_SET='' COLOR_SCHEME_SET=''
CSCHEME='' COLOR_SCHEME=''
DISTRO='' DISTRO=''
DISTRO_FILE='' DISTRO_FILE=''
A_DISTRO_GLOB='' A_DISTRO_GLOB=''
@ -350,7 +350,7 @@ set_color_scheme()
C1="${!script_colors[0]}" C1="${!script_colors[0]}"
C2="${!script_colors[1]}" C2="${!script_colors[1]}"
CN="${!script_colors[2]}" CN="${!script_colors[2]}"
# ((CSCHEME++)) ## note: why is this? ## # ((COLOR_SCHEME++)) ## note: why is this? ##
} }
# Parse the null separated commandline under /proc/<pid passed in $1>/cmdline # Parse the null separated commandline under /proc/<pid passed in $1>/cmdline
@ -427,7 +427,7 @@ get_parameters()
# these will need to be converted to standard type options # these will need to be converted to standard type options
echo "$1" | grep -q '^[0-9][0-9]\?$' || error_handler 3 "$1" echo "$1" | grep -q '^[0-9][0-9]\?$' || error_handler 3 "$1"
COLOR_SCHEME_SET='true' COLOR_SCHEME_SET='true'
if [ -z "$CSCHEME" ] if [ -z "$COLOR_SCHEME" ]
then then
set_color_scheme "$1" set_color_scheme "$1"
fi fi
@ -673,53 +673,6 @@ set_calculated_variables()
#### get data types #### get data types
#### ------------------------------------------------------------------- #### -------------------------------------------------------------------
get_distro_data()
{
local i=''
unset DISTRO
shopt -s nullglob
cd /etc
A_DISTRO_GLOB=(*[-_]{release,version})
cd "$OLDPWD"
shopt -u nullglob
if (( ${#A_DISTRO_GLOB[@]} == 1 ))
then
DISTRO_FILE="${A_DISTRO_GLOB}"
elif (( ${#A_DISTRO_GLOB[@]} > 1 ))
then
for i in $DISTROS_DERIVED $DISTROS_PRIMARY
do
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
# This is a known bug, search for the word "strange" inside comments
# echo "i='$i' A_DISTRO_GLOB[@]='${A_DISTRO_GLOB[@]}'"
if [[ " ${A_DISTRO_GLOB[@]} " == *" $i "* ]]
then
DISTRO_FILE="${i}"
break
fi
done
fi
if [ -n "$DISTRO_FILE" -a -s /etc/$DISTRO_FILE -a " $DISTROS_BLIST " != *" $DISTRO_FILE "* ]
then
DISTRO=$( remove_erroneous_chars "/etc/$DISTRO_FILE" )
else
# Debian pure should fall through here
DISTRO_FILE="issue"
DISTRO=$( gawk 'BEGIN { RS="" } { gsub(/\\[a-z]/,"");
gsub(/ [ ]+/," ");
gsub(/^ +| +$/,"");
print }' "/etc/${DISTRO_FILE}" )
fi
if (( ${#DISTRO} > 80 && ! CRAP ))
then
DISTRO="${RED}/etc/${DISTRO_FILE} corrupted, use --crap to override${NORMAL}"
fi
## note: figure out a more readable way to achieve whatever is intended here ##
: ${DISTRO:=Unknown distro o_O}
}
get_cpu_data() get_cpu_data()
{ {
local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu=''
@ -861,113 +814,51 @@ get_cpu_data()
fi fi
} }
get_hard_drive_data() get_distro_data()
{ {
local disk='' i='' local i=''
for disk in /proc/ide/ide*/hd* unset DISTRO
do shopt -s nullglob
if [[ -e $disk/media && $( remove_erroneous_chars $disk/media ) = disk ]] cd /etc
then A_DISTRO_GLOB=(*[-_]{release,version})
# BUGFIX: Ran into a debian sarge kernel that did not have the "capacity" file in the hd* directories cd "$OLDPWD"
if [[ ! -e $disk/capacity ]] shopt -u nullglob
if (( ${#A_DISTRO_GLOB[@]} == 1 ))
then
DISTRO_FILE="${A_DISTRO_GLOB}"
elif (( ${#A_DISTRO_GLOB[@]} > 1 ))
then
for i in $DISTROS_DERIVED $DISTROS_PRIMARY
do
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
# This is a known bug, search for the word "strange" inside comments
# echo "i='$i' A_DISTRO_GLOB[@]='${A_DISTRO_GLOB[@]}'"
if [[ " ${A_DISTRO_GLOB[@]} " == *" $i "* ]]
then then
CAP=0 DISTRO_FILE="${i}"
break break
fi fi
(( CAP+=$( remove_erroneous_chars $disk/capacity ) ))
HDDMOD="${HDDMOD}${HDDMOD+,}$( remove_erroneous_chars $disk/model )"
fi
done
if [[ -e /proc/scsi/scsi ]]
then
# Silly sata detection, will also pick up usb sticks, and it is all I will put into infobash. if you want more, infoperl is on
# the way :)
IFS=$'\n'
THDD=($(gawk '
BEGIN { IGNORECASE=1 }
/host/ {
getline a[$0]
getline b[$0]
}
END {
for (i in a) {
if (b[i] ~ / *type: *direct-access.*/) {
#c=gensub(/^ *vendor: (.+) +model: (.+) +rev: (.+)$/,"\\1 \\2 \\3","g",a[i])
c=gensub(/^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i])
gsub(/ [ ]+/, " ", c); gsub(/^ +| +$/, "", c)
#print a[i]
if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) continue
print c
}
}
}
' /proc/scsi/scsi))
IFS="$OIFS"
for (( i=0; i < ${#THDD[@]}; i++ ))
do
HDDMOD="${HDDMOD}${HDDMOD+,}${THDD[i]}"
done done
fi fi
if [ -n "$DISTRO_FILE" -a -s /etc/$DISTRO_FILE -a " $DISTROS_BLIST " != *" $DISTRO_FILE "* ]
##print_screen_output "$HDDMOD" ; exit
if ((CAP))
then then
HDDCAP1="$((CAP/2))" DISTRO=$( remove_erroneous_chars "/etc/$DISTRO_FILE" )
fi
# See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
HDDCAP2=$( gawk '$1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3} END {printf("%d\n",size)}' /proc/partitions )
##print_screen_output "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit
HDD=0
for i in ${!HDDCAP*}
do
if [[ ${!i} -gt $HDD ]]
then
HDD="${!i}"
fi
done
if [ "$HDD" -gt 0 ]
then
HDDUSG=$( df | gawk '
p {
if (/^\/dev\/(mapper\/|[hs]d[a-z][0-9]+)/) {
if (NF == 1) {
getline
if (NF == 5) { c += $2 }
else next
}
else if (NF == 6) { c += $3 }
}
}
/^Filesystem/ { p++ }
END { print c }
' )
HDDUSG="$((HDDUSG*100/HDD))%used"
HDD="$(($HDD*1024/1000**3))GB"
else else
unset HDDUSG # Debian pure should fall through here
HDD="unknown.." DISTRO_FILE="issue"
DISTRO=$( gawk 'BEGIN { RS="" } { gsub(/\\[a-z]/,"");
gsub(/ [ ]+/," ");
gsub(/^ +| +$/,"");
print }' "/etc/${DISTRO_FILE}" )
fi fi
} if (( ${#DISTRO} > 80 && ! CRAP ))
then
get_memory_data() DISTRO="${RED}/etc/${DISTRO_FILE} corrupted, use --crap to override${NORMAL}"
{ fi
MEM=$( gawk ' ## note: figure out a more readable way to achieve whatever is intended here ##
/^MemTotal:/ { tot = $2 } : ${DISTRO:=Unknown distro o_O}
/^(MemFree|Buffers|Cached):/ { notused+=$2 }
END {
used = tot-notused
printf("%.1f/%.1fMB\n", used/1024, tot/1024)
}' /proc/meminfo )
}
get_processes_uptime()
{
PROC="$(( $( ps aux | wc -l ) - 1 ))"
UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' )
} }
get_graphics_data() get_graphics_data()
@ -1087,6 +978,109 @@ get_graphics_data()
fi fi
} }
get_hard_drive_data()
{
local disk='' i=''
for disk in /proc/ide/ide*/hd*
do
if [[ -e $disk/media && $( remove_erroneous_chars $disk/media ) = disk ]]
then
# BUGFIX: Ran into a debian sarge kernel that did not have the "capacity" file in the hd* directories
if [[ ! -e $disk/capacity ]]
then
CAP=0
break
fi
(( CAP+=$( remove_erroneous_chars $disk/capacity ) ))
HDDMOD="${HDDMOD}${HDDMOD+,}$( remove_erroneous_chars $disk/model )"
fi
done
if [[ -e /proc/scsi/scsi ]]
then
# Silly sata detection, will also pick up usb sticks, and it is all I will put into infobash. if you want more, infoperl is on
# the way :)
IFS=$'\n'
THDD=($(gawk '
BEGIN { IGNORECASE=1 }
/host/ {
getline a[$0]
getline b[$0]
}
END {
for (i in a) {
if (b[i] ~ / *type: *direct-access.*/) {
#c=gensub(/^ *vendor: (.+) +model: (.+) +rev: (.+)$/,"\\1 \\2 \\3","g",a[i])
c=gensub(/^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i])
gsub(/ [ ]+/, " ", c); gsub(/^ +| +$/, "", c)
#print a[i]
if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) continue
print c
}
}
}
' /proc/scsi/scsi))
IFS="$OIFS"
for (( i=0; i < ${#THDD[@]}; i++ ))
do
HDDMOD="${HDDMOD}${HDDMOD+,}${THDD[i]}"
done
fi
##print_screen_output "$HDDMOD" ; exit
if ((CAP))
then
HDDCAP1="$((CAP/2))"
fi
# See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
HDDCAP2=$( gawk '$1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3} END {printf("%d\n",size)}' /proc/partitions )
##print_screen_output "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit
HDD=0
for i in ${!HDDCAP*}
do
if [[ ${!i} -gt $HDD ]]
then
HDD="${!i}"
fi
done
if [ "$HDD" -gt 0 ]
then
HDDUSG=$( df | gawk '
p {
if (/^\/dev\/(mapper\/|[hs]d[a-z][0-9]+)/) {
if (NF == 1) {
getline
if (NF == 5) { c += $2 }
else next
}
else if (NF == 6) { c += $3 }
}
}
/^Filesystem/ { p++ }
END { print c }
' )
HDDUSG="$((HDDUSG*100/HDD))%used"
HDD="$(($HDD*1024/1000**3))GB"
else
unset HDDUSG
HDD="unknown.."
fi
}
get_memory_data()
{
MEM=$( gawk '
/^MemTotal:/ { tot = $2 }
/^(MemFree|Buffers|Cached):/ { notused+=$2 }
END {
used = tot-notused
printf("%.1f/%.1fMB\n", used/1024, tot/1024)
}' /proc/meminfo )
}
get_networking_data() get_networking_data()
{ {
IFS=$'\n' IFS=$'\n'
@ -1128,6 +1122,12 @@ get_networking_data()
IFS="$OIFS" IFS="$OIFS"
} }
get_processes_uptime()
{
PROC="$(( $( ps aux | wc -l ) - 1 ))"
UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' )
}
#### ------------------------------------------------------------------- #### -------------------------------------------------------------------
#### print and processing of output data #### print and processing of output data
#### ------------------------------------------------------------------- #### -------------------------------------------------------------------