mirror of
https://github.com/smxi/inxi.git
synced 2024-11-17 00:31:19 +00:00
Made all gawk use the same structure syntax, a hanging {, for END, BEGIN, if, else, for
This will help avoid future difficulties in reading the code. also converted all gawk one liners to normally expanded logic, one statement or case per line
This commit is contained in:
parent
b1503df5ae
commit
e8a2c34658
166
inxi
166
inxi
|
@ -1,8 +1,8 @@
|
|||
#!/bin/bash
|
||||
########################################################################
|
||||
#### Script Name: inxi
|
||||
#### version: 0.9.6-b1-t1
|
||||
#### Date: 23 January 2009
|
||||
#### version: 0.9.7-b1-t1
|
||||
#### Date: 26 January 2009
|
||||
########################################################################
|
||||
#### SPECIAL THANKS
|
||||
########################################################################
|
||||
|
@ -68,6 +68,9 @@
|
|||
#### For all boolean tests, use 'true' / 'false'. Do NOT use 0 or 1 unless
|
||||
#### it's a function return. Avoid complicated tests in the if condition itself.
|
||||
####
|
||||
#### For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
|
||||
#### This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
|
||||
####
|
||||
#### VARIABLE/FUNCTION NAMING:
|
||||
#### All variables should explain what they are, except counters like i, j
|
||||
#### All variables MUST be initialized / declared explicitly
|
||||
|
@ -180,8 +183,8 @@ B_MODULES_DIR='false' #
|
|||
B_PARTITIONS_DIR='false' #
|
||||
|
||||
### Directory's used when present
|
||||
# DIR_CPUINFO='/proc/cpuinfo'
|
||||
DIR_CPUINFO="$HOME/bin/scripts/inxi/svn/modules/data/xeon_2x_2"
|
||||
DIR_CPUINFO='/proc/cpuinfo'
|
||||
# DIR_CPUINFO="$HOME/bin/scripts/inxi/svn/modules/data/xeon_2x_2"
|
||||
DIR_MEMINFO='/proc/meminfo'
|
||||
DIR_ASOUND_DEVICE='/proc/asound/cards'
|
||||
DIR_ASOUND_VERSION='/proc/asound/version'
|
||||
|
@ -517,7 +520,10 @@ sanitize_characters()
|
|||
# bash will interpret the |'s as usual and try to run a subshell!
|
||||
# Using weak quotes instead, or use '"..."'
|
||||
echo "$2" | gawk "
|
||||
BEGIN { IGNORECASE=1 } {
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
{
|
||||
gsub(/${!1}/,\"\")
|
||||
gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
|
||||
gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
|
||||
|
@ -744,7 +750,10 @@ remove_erroneous_chars()
|
|||
## RS is input record separator
|
||||
## gsub is substitute;
|
||||
gawk '
|
||||
BEGIN { RS="" } {
|
||||
BEGIN {
|
||||
RS=""
|
||||
}
|
||||
{
|
||||
gsub(/\n$/,"") ## (newline; end of string) with (nothing)
|
||||
gsub(/\n/," "); ## (newline) with (space)
|
||||
gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
|
||||
|
@ -1239,7 +1248,9 @@ get_audio_data()
|
|||
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 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
# filtering out modems and usb devices like webcams, this might get a
|
||||
# usb audio card as well, this will take some trial and error
|
||||
$0 !~ /modem/ || $0 !~ /usb/ {
|
||||
|
@ -1257,7 +1268,9 @@ get_audio_data()
|
|||
# now we'll build the main audio data, card name, driver, and port. If no driver is found,
|
||||
# and if the first method above is not null, and one card is found, it will use that instead.
|
||||
A_AUDIO_DATA=( $( echo "$lspci_data" | gawk -F ': ' -v alsaDriver="$alsa_driver" '
|
||||
BEGIN { IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
/multimedia audio controller|audio device/ {
|
||||
audioCard=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
|
||||
# The doublequotes are necessary because of the pipes in the variable.
|
||||
|
@ -1327,7 +1340,9 @@ get_audio_data()
|
|||
# in case of failure of first check do this instead
|
||||
if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]] && [[ $B_ASOUND_CARDS == 'true' ]];then
|
||||
A_AUDIO_DATA=( $( gawk -F ']: ' '
|
||||
{ IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
$1 !~ /modem/ && $2 !~ /modem/ {
|
||||
card=gensub( /^(.+)( - )(.+)$/, "\\3", 1, $2 )
|
||||
driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
|
||||
|
@ -1351,7 +1366,9 @@ get_audio_alsa_data()
|
|||
# now we'll get the alsa data if the file exists
|
||||
if [[ $B_ASOUND_VERSION == 'true' ]];then
|
||||
alsa_data=$( gawk '
|
||||
{ IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
# some alsa strings have the build date in (...)
|
||||
# remove trailing . and remove possible second line if compiled by user
|
||||
$0 !~ /compile/ {
|
||||
|
@ -1378,7 +1395,6 @@ get_cpu_core_count()
|
|||
# count the number of processors given
|
||||
local cpu_core_count=${A_CPU_TYPE_PCNT_CCNT[2]}
|
||||
local cpu_type=''
|
||||
echo A_CPU_TYPE_PCNT_CCNT ${A_CPU_TYPE_PCNT_CCNT[2]}
|
||||
|
||||
if [[ ${A_CPU_TYPE_PCNT_CCNT[0]} == "HT" || ${A_CPU_TYPE_PCNT_CCNT[0]} == "SMP" ]]; then
|
||||
# note the use of the space, this avoids a double space if this is null in the output
|
||||
|
@ -1412,11 +1428,15 @@ get_cpu_data()
|
|||
if [[ $B_CPUINFO == 'true' ]];then
|
||||
IFS=$'\n'
|
||||
A_CPU_DATA=( $( gawk -F': ' '
|
||||
{ IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
# TAKE STRONGER NOTE: \t+ does NOT always work, MUST be [ \t]+
|
||||
# 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 }
|
||||
/^processor[ \t]+:/ {
|
||||
nr = $NF
|
||||
}
|
||||
|
||||
/^model name|^cpu\t+:/ {
|
||||
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
|
||||
|
@ -1445,11 +1465,17 @@ get_cpu_data()
|
|||
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)
|
||||
|
@ -1488,7 +1514,7 @@ get_cpu_ht_multicore_smp_data()
|
|||
# if = 1 processor then single core/processor Uni-Processor (UP)
|
||||
|
||||
if [[ $B_CPUINFO == 'true' ]]; then
|
||||
# A_CPU_TYPE_PCNT_CCNT=( $(
|
||||
A_CPU_TYPE_PCNT_CCNT=( $(
|
||||
gawk '
|
||||
BEGIN {
|
||||
FS=": "
|
||||
|
@ -1520,15 +1546,12 @@ get_cpu_ht_multicore_smp_data()
|
|||
}
|
||||
END {
|
||||
# look for the largest id number, and assign it
|
||||
for ( j = 0; j < num_of_processors; j++ )
|
||||
{
|
||||
if ( physical_id[j] > cpu_temp )
|
||||
{
|
||||
for ( j = 0; j < num_of_processors; j++ ) {
|
||||
if ( physical_id[j] > cpu_temp ) {
|
||||
cpu_temp = physical_id[j]
|
||||
# print "physical_id: " physical_id[j]
|
||||
}
|
||||
if ( core_id[j] > core_temp )
|
||||
{
|
||||
if ( core_id[j] > core_temp ) {
|
||||
core_temp = core_id[j]
|
||||
# print "core_temp: " core_id[j]
|
||||
}
|
||||
|
@ -1540,35 +1563,27 @@ get_cpu_ht_multicore_smp_data()
|
|||
# print "physical_cpu_count: " physical_cpu_count
|
||||
|
||||
# looking at logical processor counts over 1, which means either HT, SMP or MCP
|
||||
if ( num_of_processors > 1 )
|
||||
{
|
||||
if ( physical_cpu_count == 1 )
|
||||
{
|
||||
if ( physical_cpu_count == core_count )
|
||||
{
|
||||
if ( num_of_processors > 1 ) {
|
||||
if ( physical_cpu_count == 1 ) {
|
||||
if ( physical_cpu_count == core_count ) {
|
||||
type = "HT" # this is more than likely a P4 w/HT or an Atom 270
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( core_count == num_of_cores && core_count == num_of_processors)
|
||||
{
|
||||
else {
|
||||
if ( core_count == num_of_cores && core_count == num_of_processors) {
|
||||
type = "MCP"
|
||||
cores = core_count
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
type = "HT" # this is i7 or Atom 330
|
||||
cores = core_count
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
type = "SMP"
|
||||
processors = physical_cpu_count
|
||||
|
||||
if ( num_of_cores > 1 )
|
||||
{
|
||||
if ( num_of_cores > 1 ) {
|
||||
type = "SMPMC" # processors could be both MCP and SMP
|
||||
cores = core_count
|
||||
}
|
||||
|
@ -1577,7 +1592,7 @@ get_cpu_ht_multicore_smp_data()
|
|||
print type " " processors " " cores
|
||||
}
|
||||
' $DIR_CPUINFO
|
||||
# ) )
|
||||
) )
|
||||
fi
|
||||
# echo A_CPU_TYPE_PCNT_CCNT:1 ${A_CPU_TYPE_PCNT_CCNT[@]}
|
||||
}
|
||||
|
@ -1640,7 +1655,10 @@ get_distro_data()
|
|||
distro=$( get_distro_lsb_data )
|
||||
else
|
||||
distro=$( gawk '
|
||||
BEGIN { RS="" } {
|
||||
BEGIN {
|
||||
RS=""
|
||||
}
|
||||
{
|
||||
gsub(/\\[a-z]/, "")
|
||||
gsub(/,/, " ")
|
||||
gsub(/^ +| +$/, "")
|
||||
|
@ -1680,8 +1698,9 @@ get_distro_lsb_data()
|
|||
|
||||
if [[ $B_LSB_DIR == 'true' ]] && [[ $1 != 'app' ]];then
|
||||
distro=$( gawk -F '=' '
|
||||
|
||||
{ IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
# note: adding the spacing directly to variable to make sure distro output is null if not found
|
||||
/^DISTRIB_ID/ {
|
||||
gsub(/^ +| +$/, "", $NF)
|
||||
|
@ -1740,7 +1759,9 @@ get_graphics_card_data()
|
|||
|
||||
IFS=$'\n'
|
||||
A_GFX_CARD_DATA=( $( echo "$lspci_data" | gawk -F': ' '
|
||||
{ IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
/vga compatible controller/ {
|
||||
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
|
||||
gsub(/,/, " ", $NF)
|
||||
|
@ -1792,8 +1813,12 @@ get_graphics_glx_data()
|
|||
}
|
||||
$2 && a[$2]
|
||||
}
|
||||
/opengl version/ && (f || $2 !~ /mesa/) { $2 && b[$2] }
|
||||
/direct rendering/ { $2 && c[$2] }
|
||||
/opengl version/ && (f || $2 !~ /mesa/) {
|
||||
$2 && b[$2]
|
||||
}
|
||||
/direct rendering/ {
|
||||
$2 && c[$2]
|
||||
}
|
||||
|
||||
END {
|
||||
printf("%s\n%s\n%s\n", join(a,", "), join(b,", "), join(c,", "))
|
||||
|
@ -1817,14 +1842,19 @@ get_graphics_res_data()
|
|||
/\*/ { res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0) }
|
||||
END {
|
||||
for (n in res) {
|
||||
if (res[n] ~ /^[[:digit:]]+x[[:digit:]]+/)
|
||||
if (res[n] ~ /^[[:digit:]]+x[[:digit:]]+/) {
|
||||
line = line ? line ", " res[n] : res[n]
|
||||
}
|
||||
if (line)
|
||||
}
|
||||
if (line) {
|
||||
print(line)
|
||||
}
|
||||
}' )
|
||||
if [[ -z $screen_resolution ]];then
|
||||
screen_resolution=$( xdpyinfo | gawk '/dimensions/ { print $2 }' )
|
||||
screen_resolution=$( xdpyinfo | gawk '
|
||||
/dimensions/ {
|
||||
print $2
|
||||
}' )
|
||||
fi
|
||||
else
|
||||
screen_resolution=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{ print $2"x"$1 }' )
|
||||
|
@ -1839,7 +1869,10 @@ get_graphics_agp_data()
|
|||
|
||||
if [[ B_MODULES_DIR == 'true' ]];then
|
||||
## not used currently
|
||||
agp_module=$( gawk '/agp/ && !/agpgart/ && $3 > 0 { print(gensub(/(.*)_agp.*/,"\\1","g",$1)) }' $DIR_MODULES )
|
||||
agp_module=$( gawk '
|
||||
/agp/ && !/agpgart/ && $3 > 0 {
|
||||
print(gensub(/(.*)_agp.*/,"\\1","g",$1))
|
||||
}' $DIR_MODULES )
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -1998,7 +2031,9 @@ get_hard_drive_data_advanced()
|
|||
IFS=$'\n'
|
||||
if [[ $B_SCSI_DIR == 'true' ]]; then
|
||||
a_temp_scsi=( $( gawk '
|
||||
BEGIN { IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
/host/ {
|
||||
getline a[$0]
|
||||
getline b[$0]
|
||||
|
@ -2087,8 +2122,12 @@ get_memory_data()
|
|||
local memory=''
|
||||
|
||||
memory=$( gawk '
|
||||
/^MemTotal:/ { tot = $2 }
|
||||
/^(MemFree|Buffers|Cached):/ { notused+=$2 }
|
||||
/^MemTotal:/ {
|
||||
tot = $2
|
||||
}
|
||||
/^(MemFree|Buffers|Cached):/ {
|
||||
notused+=$2
|
||||
}
|
||||
END {
|
||||
used = tot-notused
|
||||
printf("%.1f/%.1fMB\n", used/1024, tot/1024)
|
||||
|
@ -2104,7 +2143,9 @@ get_module_version_number()
|
|||
|
||||
if [[ -n $( which modinfo ) ]];then
|
||||
module_version=$( modinfo $1 | gawk '
|
||||
BEGIN { IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
/^version/ {
|
||||
gsub(/,/, " ", $2)
|
||||
gsub(/^ +| +$/, "", $2)
|
||||
|
@ -2122,7 +2163,9 @@ get_networking_data()
|
|||
{
|
||||
IFS=$'\n'
|
||||
A_NETWORK_DATA=( $( echo "$lspci_data" | gawk '
|
||||
BEGIN { IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
/^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
|
||||
nic=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
|
||||
gsub(/realtek semiconductor/, "Realtek", nic)
|
||||
|
@ -2207,7 +2250,9 @@ get_networking_local_ip_data()
|
|||
if [[ $B_IFCONFIG == 'true' ]];then
|
||||
IFS=$'\n'
|
||||
A_INTERFACES_DATA=( $( $DIR_IFCONFIG | gawk '
|
||||
BEGIN { IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
$0 !~ /^lo/ {
|
||||
# not clear on why inet is coming through, but this gets rid of it
|
||||
# as first line item.
|
||||
|
@ -2256,7 +2301,9 @@ get_partition_data()
|
|||
## 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 '
|
||||
BEGIN { IGNORECASE=1 }
|
||||
BEGIN {
|
||||
IGNORECASE=1
|
||||
}
|
||||
/\/$|\/boot$|\/var$|\/home$|\/tmp$|\/usr$/ && ! /aufs/ {
|
||||
print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main"
|
||||
}
|
||||
|
@ -2308,7 +2355,10 @@ calculate_multicore_data()
|
|||
fi
|
||||
# handle weird error cases where it's not a number
|
||||
if [[ -n $( egrep '^[0-9\.,]+$' <<< $string_number ) ]];then
|
||||
string_number=$( echo $string_number $2 | gawk '{total = $1*$2; print total}' )
|
||||
string_number=$( echo $string_number $2 | gawk '{
|
||||
total = $1*$2
|
||||
print total
|
||||
}' )
|
||||
elif [[ $string_number == '' ]];then
|
||||
string_number='Not Available'
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue