mirror of
https://github.com/smxi/inxi.git
synced 2025-01-19 08:57:57 +00:00
new option, show full flags (-f), created a few new functions to split the flag handling, for get and print. This removes
that junk from the old get cpu data and makes it cleaner.
This commit is contained in:
parent
f57394e296
commit
fbff2fbed9
238
inxi
238
inxi
|
@ -1,8 +1,8 @@
|
|||
#!/bin/bash
|
||||
########################################################################
|
||||
#### Script Name: inxi
|
||||
#### version: 0.3.21
|
||||
#### Date: November 4 2008
|
||||
#### version: 0.3.22
|
||||
#### Date: November 5 2008
|
||||
########################################################################
|
||||
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
||||
#### As time permits functionality improvements and recoding will occur.
|
||||
|
@ -47,9 +47,6 @@
|
|||
CMDL_MAX=''
|
||||
COLOR_SCHEME=''
|
||||
COLOR_SCHEME_SET=''
|
||||
CPU_MODEL=''
|
||||
CPU_CLOCK=''
|
||||
CPU_FLAGS=''
|
||||
IRC_CLIENT=''
|
||||
IRC_CLIENT_VERSION=''
|
||||
|
||||
|
@ -69,6 +66,8 @@ A_X_DATA=''
|
|||
# check to make sure initial steps run without error for debugging
|
||||
# inxi hasn't been 'booted' yet.
|
||||
B_ALL_UP='false'
|
||||
# triggers full display of cpu flags
|
||||
B_CPU_FLAGS_FULL='false'
|
||||
# Debug flood override: make 'true' to allow long debug output
|
||||
B_DEBUG_FLOOD='false'
|
||||
# show extra output data
|
||||
|
@ -168,7 +167,7 @@ DISTROS_PRIMARY="gentoo-release mandrake-release redhat-release slackware-versio
|
|||
# user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v
|
||||
# 00000000 01 01 6f 6e 65 20 74 77 6f 0a |..one two.|
|
||||
A_NORMAL_BANS=( corporation communications gmbh technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" $'\2'"\(rev ..\)" )
|
||||
A_CPU_BANS=( cpu deca 'dual core' 'tri core' 'quad core' ennea genuine hepta hexa multi octa penta processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" )
|
||||
A_CPU_BANS=( cpu deca 'dual core ' 'tri core ' 'quad core ' ennea genuine hepta hexa multi octa penta 'processor ' processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" )
|
||||
|
||||
### Source global config overrides
|
||||
if [ -s /etc/$SCRIPT_NAME.conf ];then
|
||||
|
@ -443,7 +442,7 @@ get_parameters()
|
|||
return 1
|
||||
fi
|
||||
|
||||
while getopts c:CdDhTUv:Vx opt
|
||||
while getopts c:CdDfhTUv:Vx opt
|
||||
do
|
||||
case $opt in
|
||||
c) if [ -n "$( egrep '^[0-9][0-9]?$' <<< $OPTARG )" ];then
|
||||
|
@ -464,6 +463,8 @@ get_parameters()
|
|||
D) DEBUG=1
|
||||
exec 2>&1
|
||||
;;
|
||||
f) B_CPU_FLAGS_FULL='true'
|
||||
;;
|
||||
T) B_TESTING_FLAG='true'
|
||||
;;
|
||||
v) if [[ -n $( egrep "^[0-9][0-9]?$" <<< $OPTARG ) && $OPTARG -le $VERBOSITY_LEVELS ]];then
|
||||
|
@ -501,6 +502,7 @@ show_options()
|
|||
print_screen_output "-c Available color schemes. Scheme number is required."
|
||||
print_screen_output " Supported schemes: 0-$color_scheme_count Example: $SCRIPT_NAME -c 11"
|
||||
print_screen_output "-d Default output verbosity level, same as: $SCRIPT_NAME -v 1"
|
||||
print_screen_output "-f Show all cpu flags used, not just the short list."
|
||||
print_screen_output "-U Autoupdate script. Note: if you installed as root, you"
|
||||
print_screen_output " must be root to update, otherwise user is fine."
|
||||
print_screen_output "-v Script verbosity levels. Verbosity level number is required."
|
||||
|
@ -747,13 +749,13 @@ get_audio_data()
|
|||
|
||||
IFS=$'\n'
|
||||
A_AUDIO_DATA=( $( echo "$lspci_data" | gawk -F': ' '
|
||||
{ IGNORECASE=1 }
|
||||
/multimedia audio controller|audio device/ { print $NF }' ) )
|
||||
{ IGNORECASE=1 }
|
||||
/multimedia audio controller|audio device/ {
|
||||
gsub(/'"$A_NORMAL_BANS"'/, "", $NF )
|
||||
print $NF
|
||||
}' ) )
|
||||
IFS="$ORIGINAL_IFS"
|
||||
for (( i=0; i < ${#A_AUDIO_DATA[@]}; i++ ))
|
||||
do
|
||||
A_AUDIO_DATA[i]=$( sanitize_characters A_NORMAL_BANS "${A_AUDIO_DATA[i]}" )
|
||||
done
|
||||
|
||||
# handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
|
||||
if [ "${#A_AUDIO_DATA[@]}" -eq 0 ];then
|
||||
A_AUDIO_DATA[0]='Failed to Detect Sound Card!'
|
||||
|
@ -808,6 +810,9 @@ get_cpu_data()
|
|||
|
||||
/^model name|^cpu\t+:/ {
|
||||
gsub(/,/," ",$NF)
|
||||
gsub(//,"",$NF)
|
||||
gsub(/'"$A_NORMAL_BANS"'/, "", $NF )
|
||||
gsub(/'"$A_CPU_BANS"'/, "", $NF )
|
||||
cpu[nr, "model"] = $NF
|
||||
}
|
||||
|
||||
|
@ -825,7 +830,7 @@ get_cpu_data()
|
|||
max = $NF
|
||||
}
|
||||
gsub(/MHZ/,"",$NF) ## clears out for cell cpu
|
||||
gsub(/.000000/,".00",$NF) ## clears out for cell cpu
|
||||
gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros
|
||||
cpu[nr, "speed"] = $NF
|
||||
}
|
||||
|
||||
|
@ -859,81 +864,6 @@ get_cpu_data()
|
|||
' /proc/cpuinfo))
|
||||
|
||||
IFS="$ORIGINAL_IFS"
|
||||
|
||||
for (( i=0; i < ${#A_CPU_DATA[@]} - 1; i++ ))
|
||||
do
|
||||
IFS=","
|
||||
a_cpu_working=(${A_CPU_DATA[i]})
|
||||
IFS="$ORIGINAL_IFS"
|
||||
unset A_CPU_DATA[i]
|
||||
a_cpu_working[0]=$( sanitize_characters A_NORMAL_BANS "${a_cpu_working[0]}" )
|
||||
a_cpu_working[0]=$( sanitize_characters A_CPU_BANS "${a_cpu_working[0]}" )
|
||||
# I use all these loops so I can easily extend the cpu array created in the awk script above with more fields per cpu.
|
||||
for (( j=0; j < ${#a_cpu_working[@]}; j++ ))
|
||||
do
|
||||
if [ "$j" -gt 0 ];then
|
||||
A_CPU_DATA[i]="${A_CPU_DATA[i]},${a_cpu_working[j]}"
|
||||
else
|
||||
A_CPU_DATA[i]="${a_cpu_working[j]}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
IFS=","
|
||||
a_cpu_working=(${A_CPU_DATA[0]})
|
||||
IFS="$ORIGINAL_IFS"
|
||||
# For the short line
|
||||
# CPU_MODEL="${CPU2}${CPU2+ }${a_cpu_working[0]}" # clocked at [${CPU[${#CPU[@]}-1]}]" # old CPU2
|
||||
CPU_MODEL="${a_cpu_working[0]}"
|
||||
# set count first, this avoids an syntax highlighting error with nested {{...}}
|
||||
cpu_array_nu=$(( ${#A_CPU_DATA[@]} - 1 ))
|
||||
CPU_CLOCK="${A_CPU_DATA[$cpu_array_nu]}" # old CPU3
|
||||
CPU_FLAGS="${a_cpu_working[3]}" # old CPU4
|
||||
# nx = AMD stack protection extensions
|
||||
# lm = Intel 64bit extensions
|
||||
# sse, sse2, pni = sse1,2,3 gfx extensions
|
||||
# svm = AMD pacifica virtualization extensions
|
||||
# vmx = Intel IVT (vanderpool) virtualization extensions
|
||||
CPU_FLAGS=$( echo "$CPU_FLAGS" | awk '
|
||||
BEGIN {
|
||||
RS=" "
|
||||
ssel["sse"] = 1
|
||||
ssel["sse2"] = 2
|
||||
ssel["pni"] = 3
|
||||
sses[1] = "sse"
|
||||
sses[2] = "sse2"
|
||||
sses[3] = "sse3"
|
||||
}
|
||||
/^(nx|lm|svm|vmx)$/ {
|
||||
if (s) {
|
||||
s = s " " $0
|
||||
}
|
||||
else {
|
||||
s = $0
|
||||
}
|
||||
}
|
||||
/^(sse2?|pni)$/ {
|
||||
if (ssel[$0] > sse) {
|
||||
sse = ssel[$0]
|
||||
}
|
||||
}
|
||||
END {
|
||||
if (sse) {
|
||||
if (s) {
|
||||
s = sses[sse] " " s
|
||||
}
|
||||
else {
|
||||
s = sses[sse]
|
||||
}
|
||||
}
|
||||
print s
|
||||
}
|
||||
' )
|
||||
|
||||
#grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
|
||||
if [ -z "$CPU_FLAGS" ];then
|
||||
CPU_FLAGS="-"
|
||||
fi
|
||||
}
|
||||
|
||||
## return distro name/id if found
|
||||
|
@ -1315,6 +1245,10 @@ get_uptime()
|
|||
echo $( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); print a }' )
|
||||
}
|
||||
|
||||
#### -------------------------------------------------------------------
|
||||
#### special data handling for specific options and conditions
|
||||
#### -------------------------------------------------------------------
|
||||
|
||||
## multiply the core count by the data to be calculated, bmips, cache
|
||||
# args: $1 - string to handle; $2 - cpu count
|
||||
calculate_multicore_data()
|
||||
|
@ -1336,6 +1270,59 @@ calculate_multicore_data()
|
|||
echo "$string_number$string_data"
|
||||
}
|
||||
|
||||
# args: $1 - string of cpu flags to process
|
||||
process_cpu_flags()
|
||||
{
|
||||
local cpu_flags="$1"
|
||||
|
||||
# nx = AMD stack protection extensions
|
||||
# lm = Intel 64bit extensions
|
||||
# sse, sse2, pni = sse1,2,3 gfx extensions
|
||||
# svm = AMD pacifica virtualization extensions
|
||||
# vmx = Intel IVT (vanderpool) virtualization extensions
|
||||
cpu_flags=$( echo "$cpu_flags" | awk '
|
||||
BEGIN {
|
||||
RS=" "
|
||||
ssel["sse"] = 1
|
||||
ssel["sse2"] = 2
|
||||
ssel["pni"] = 3
|
||||
sses[1] = "sse"
|
||||
sses[2] = "sse2"
|
||||
sses[3] = "sse3"
|
||||
}
|
||||
/^(nx|lm|svm|vmx)$/ {
|
||||
if (s) {
|
||||
s = s " " $0
|
||||
}
|
||||
else {
|
||||
s = $0
|
||||
}
|
||||
}
|
||||
/^(sse2?|pni)$/ {
|
||||
if (ssel[$0] > sse) {
|
||||
sse = ssel[$0]
|
||||
}
|
||||
}
|
||||
END {
|
||||
if (sse) {
|
||||
if (s) {
|
||||
s = sses[sse] " " s
|
||||
}
|
||||
else {
|
||||
s = sses[sse]
|
||||
}
|
||||
}
|
||||
print s
|
||||
}
|
||||
' )
|
||||
|
||||
#grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
|
||||
if [ -z "$cpu_flags" ];then
|
||||
cpu_flags="-"
|
||||
fi
|
||||
echo "$cpu_flags"
|
||||
}
|
||||
|
||||
#### -------------------------------------------------------------------
|
||||
#### print and processing of output data
|
||||
#### -------------------------------------------------------------------
|
||||
|
@ -1381,13 +1368,14 @@ print_audio_data()
|
|||
|
||||
print_cpu_data()
|
||||
{
|
||||
local cpu_data='' i='' a_cpu_working='' cpu_clock_speed='' cpu_multi_clock_data=''
|
||||
local bmip_data='' cpu_cache='' cpu_vendor=''
|
||||
local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data=''
|
||||
local bmip_data='' cpu_cache='' cpu_vendor='' cpu_flags=''
|
||||
|
||||
##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\""
|
||||
IFS=","
|
||||
a_cpu_working=(${A_CPU_DATA[0]})
|
||||
IFS="$ORIGINAL_IFS"
|
||||
# Array A_CPU_DATA always has one element: max clockfreq found.
|
||||
# that's why its count is one more than you'd think from cores/cpus alone
|
||||
# weird hack, probably should be changed
|
||||
|
||||
cpu_vendor=$( tr '[A-Z]' '[a-z]' <<< ${a_cpu_working[5]} )
|
||||
# Strange (and also some expected) behavior encountered.
|
||||
# If print_screen_output() uses $1 as the parameter to output to the screen,
|
||||
|
@ -1402,14 +1390,7 @@ print_cpu_data()
|
|||
if [[ -z ${a_cpu_working[2]} ]];then
|
||||
a_cpu_working[2]="unknown"
|
||||
fi
|
||||
## leave this here in case they release cpus that can run at different speeds per core
|
||||
# if [[ ${#A_CPU_DATA[@]} -gt 2 ]];then
|
||||
# cpu_core_count="${C1}(1)${C2} "
|
||||
# else
|
||||
# # Array CPU always has one element: max clockfreq found. Therefore -gt and not -ge
|
||||
# unset cpu_core_count
|
||||
# fi
|
||||
echo ${A_CPU_DATA[@]}
|
||||
|
||||
cpu_data=$( create_print_line "CPU:" "${C1}${cpu_core_count_string}${C2} ${a_cpu_working[0]}" )
|
||||
if [ "$VERBOSITY_LEVEL" -ge 3 ];then
|
||||
# update for multicore, bogomips x core count.
|
||||
|
@ -1428,7 +1409,12 @@ print_cpu_data()
|
|||
else
|
||||
cpu_cache="${a_cpu_working[2]}"
|
||||
fi
|
||||
cpu_data="$cpu_data${C2} ${C1}cache${C2} $cpu_cache ${C1}flags${C2} ($CPU_FLAGS)$bmip_data${CN}"
|
||||
# only print shortened list
|
||||
if [ "$B_CPU_FLAGS_FULL" != 'true' ];then
|
||||
cpu_flags=$( process_cpu_flags "${a_cpu_working[3]}" )
|
||||
cpu_flags=" ${C1}flags${C2} ($cpu_flags)"
|
||||
fi
|
||||
cpu_data="$cpu_data${C2} ${C1}cache${C2} $cpu_cache$cpu_flags$bmip_data${CN}"
|
||||
fi
|
||||
|
||||
if [ "$VERBOSITY_LEVEL" -ge 5 -a "${#A_CPU_DATA[@]}" -gt 2 ];then
|
||||
|
@ -1456,6 +1442,40 @@ print_cpu_data()
|
|||
print_screen_output "$cpu_multi_clock_data"
|
||||
fi
|
||||
fi
|
||||
if [ "$B_CPU_FLAGS_FULL" == 'true' ];then
|
||||
print_cpu_flags_full "${a_cpu_working[3]}"
|
||||
fi
|
||||
}
|
||||
# takes list of all flags, split them and prints x per line
|
||||
# args: $1 - cpu flag string
|
||||
print_cpu_flags_full()
|
||||
{
|
||||
local flag='' cpu_flags_full="$1" cpu_flags_1='' cpu_flags_2='' cpu_flags_3='' i=0
|
||||
local flag_count=$( wc -w <<< "$" ) flag_data=''
|
||||
|
||||
for flag in $cpu_flags_full
|
||||
do
|
||||
if [ "$i" -ge 36 ];then
|
||||
cpu_flags_3="$cpu_flags_3$flag "
|
||||
elif [ "$i" -ge 18 ];then
|
||||
cpu_flags_2="$cpu_flags_2$flag "
|
||||
elif [ "$i" -ge 0 ];then
|
||||
cpu_flags_1="$cpu_flags_1$flag "
|
||||
fi
|
||||
((i++))
|
||||
done
|
||||
if [ -n "$cpu_flags_1" ];then
|
||||
flag_data=$( create_print_line " " "${C1}CPU Flags${C2} $cpu_flags_1" )
|
||||
print_screen_output "$flag_data"
|
||||
fi
|
||||
if [ -n "$cpu_flags_2" ];then
|
||||
flag_data=$( create_print_line " " "$cpu_flags_2" )
|
||||
print_screen_output "$flag_data"
|
||||
fi
|
||||
if [ -n "$cpu_flags_3" ];then
|
||||
flag_data=$( create_print_line " " "$cpu_flags_3" )
|
||||
print_screen_output "$flag_data"
|
||||
fi
|
||||
}
|
||||
|
||||
print_gfx_data()
|
||||
|
@ -1593,6 +1613,10 @@ print_short_data()
|
|||
{
|
||||
local short_data='' i='' b_background_black='false'
|
||||
local memory=$( get_memory_data )
|
||||
local cpu_clock="${a_cpu_working[1]}" # old CPU3
|
||||
# this gets that weird min/max final array item
|
||||
local min_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 ))
|
||||
local min_max_clock=${A_CPU_DATA[$min_max_clock_nu]}
|
||||
|
||||
#set_color_scheme 12
|
||||
if [ "$B_RUNNING_IN_SHELL" == 'false' ];then
|
||||
|
@ -1616,7 +1640,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} ${CPU_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}]"
|
||||
|
@ -1676,7 +1700,13 @@ print_it_out()
|
|||
local hdd_model=${A_HDD_DATA[0]}
|
||||
local hdd_capacity=${A_HDD_DATA[1]}
|
||||
local hdd_used=${A_HDD_DATA[2]}
|
||||
# load A_CPU_DATA
|
||||
get_cpu_data
|
||||
|
||||
IFS=","
|
||||
local a_cpu_working=(${A_CPU_DATA[0]})
|
||||
IFS="$ORIGINAL_IFS"
|
||||
local cpu_model="${a_cpu_working[0]}"
|
||||
|
||||
case "$VERBOSITY_LEVEL" in
|
||||
0)
|
||||
|
|
Loading…
Reference in a new issue