mirror of
https://github.com/smxi/inxi.git
synced 2024-11-17 00:31:19 +00:00
updated trunk inxi
This commit is contained in:
parent
b59210e006
commit
462fff6b5d
118
inxi
118
inxi
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Script Name: inxi
|
#### Script Name: inxi
|
||||||
#### version: 1.0.11
|
#### version: 1.0.12
|
||||||
#### Date: 20 March 2009
|
#### Date: 20 March 2009
|
||||||
########################################################################
|
########################################################################
|
||||||
#### SPECIAL THANKS
|
#### SPECIAL THANKS
|
||||||
|
@ -61,30 +61,37 @@
|
||||||
########################################################################
|
########################################################################
|
||||||
#### CONVENTIONS:
|
#### CONVENTIONS:
|
||||||
#### Indentation: TABS
|
#### Indentation: TABS
|
||||||
#### Do not use `....`, those are totally non-reabable, use $(....)
|
#### Do not use `....` (back quotes), those are totally non-reabable, use $(....).
|
||||||
#### Do not use one liner flow controls. The ONLY time you should use ; is in
|
#### Do not use one liner flow controls.
|
||||||
#### this single case: if [[ condition ]];then (ie, never: [[ condition ]] && statement)
|
#### The ONLY time you should use ';' (semi-colon) is in this single case: if [[ condition ]];then.
|
||||||
#### Note: [[ -n $something ]] - double brackets do not require quotes: "$something" for variables
|
#### Never use compound 'if': ie, if [[ condition ]] && statement.
|
||||||
#### Always use quotes, double or single, for all string values
|
#### Note: [[ -n $something ]] - double brackets does not require quotes for variables: ie, "$something".
|
||||||
|
#### Always use quotes, double or single, for all string values.
|
||||||
####
|
####
|
||||||
#### All new code/methods must be in a function.
|
#### All new code/methods must be in a function.
|
||||||
#### For all boolean tests, use 'true' / 'false'. Do NOT use 0 or 1 unless
|
#### For all boolean tests, use 'true' / 'false'.
|
||||||
#### it's a function return. Avoid complicated tests in the if condition itself.
|
#### !! Do NOT use 0 or 1 unless it's a function return.
|
||||||
|
#### Avoid complicated tests in the if condition itself.
|
||||||
|
#### To 'return' a value in a function, use 'echo <var>'.
|
||||||
####
|
####
|
||||||
#### For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
|
#### 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
|
#### This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
|
||||||
####
|
####
|
||||||
#### VARIABLE/FUNCTION NAMING:
|
#### VARIABLE/FUNCTION NAMING:
|
||||||
#### All variables should explain what they are, except counters like i, j
|
#### All functions should follow standard naming--verb adjective noun.
|
||||||
#### All variables MUST be initialized / declared explicitly
|
#### ie, get_cpu_data
|
||||||
####, globals UPPER CASE, at top of script, SOME_VARIABLE='' (words separated by _ ).
|
#### All variables MUST be initialized / declared explicitly.
|
||||||
#### Locals always with: local some_variable= (lower case, words separated by _ )
|
#### All variables should clearly explain what they are, except counters like i, j.
|
||||||
#### Locals that will be inherited by child functions: Some_Variable (so you know they are inherited)
|
#### Each word of variable must be separated by '_' (underscore) (camel form).
|
||||||
#### and at the top of the function.
|
#### Global variables are 'UPPER CASE', at top of script.
|
||||||
|
#### ie, SOME_VARIABLE=''
|
||||||
|
#### Local variables are 'lower case' and declared at the top of the function.
|
||||||
|
#### ie, some_variable=''
|
||||||
|
#### Locals that will be inherited by child functions have first char capitalized (so you know they are inherited).
|
||||||
|
#### ie, Some_Variable
|
||||||
####
|
####
|
||||||
#### Booleans should start with b_ or B_ and state clearly what is being tested
|
#### Booleans should start with b_ (local) or B_ (global) and state clearly what is being tested.
|
||||||
#### Arrays should start with a_ or A_
|
#### Arrays should start with a_ (local) or A_ (global).
|
||||||
#### All functions should follow standard naming, ie, verb adjective noun, get_cpu_data
|
|
||||||
####
|
####
|
||||||
#### SPECIAL NOTES:
|
#### SPECIAL NOTES:
|
||||||
#### The color variable ${C2} must always be followed by a space unless you know what
|
#### The color variable ${C2} must always be followed by a space unless you know what
|
||||||
|
@ -94,9 +101,12 @@
|
||||||
#### For native script konversation support (check distro for correct konvi scripts path):
|
#### For native script konversation support (check distro for correct konvi scripts path):
|
||||||
#### ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi
|
#### ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi
|
||||||
#### DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.
|
#### DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.
|
||||||
|
####
|
||||||
|
#### As with all 'rules' there are acceptions, these are noted where used.
|
||||||
|
####
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Valuable Resources
|
#### Valuable Resources
|
||||||
#### awk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
|
#### gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
|
||||||
########################################################################
|
########################################################################
|
||||||
#### TESTING FLAGS
|
#### TESTING FLAGS
|
||||||
#### inxi supports advanced testing triggers to do various things, using -! <arg>
|
#### inxi supports advanced testing triggers to do various things, using -! <arg>
|
||||||
|
@ -123,7 +133,7 @@ COLOR_SCHEME_SET=''
|
||||||
IRC_CLIENT=''
|
IRC_CLIENT=''
|
||||||
IRC_CLIENT_VERSION=''
|
IRC_CLIENT_VERSION=''
|
||||||
|
|
||||||
### primary data array holders
|
### primary data array holders ## usage: 'A_<var>'
|
||||||
A_AUDIO_DATA=''
|
A_AUDIO_DATA=''
|
||||||
A_CMDL=''
|
A_CMDL=''
|
||||||
A_CPU_CORE_DATA=''
|
A_CPU_CORE_DATA=''
|
||||||
|
@ -138,7 +148,7 @@ A_NETWORK_DATA=''
|
||||||
A_PARTITION_DATA=''
|
A_PARTITION_DATA=''
|
||||||
A_X_DATA=''
|
A_X_DATA=''
|
||||||
|
|
||||||
### Boolean true/false globals
|
### Boolean true/false globals ## usage: 'B_<var>'
|
||||||
# flag to allow distro maintainers to turn off update features. If false, turns off
|
# flag to allow distro maintainers to turn off update features. If false, turns off
|
||||||
# -U and -! testing/advanced update options, as well as removing the -U help menu item
|
# -U and -! testing/advanced update options, as well as removing the -U help menu item
|
||||||
B_ALLOW_UPDATE='true'
|
B_ALLOW_UPDATE='true'
|
||||||
|
@ -235,19 +245,20 @@ VERBOSITY_LEVELS=5
|
||||||
|
|
||||||
# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
|
# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
|
||||||
# type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
|
# type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
|
||||||
# therefore results in nothing. Tricky as fuck.
|
# therefore results in nothing.
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
|
## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
|
||||||
# Backup the current Internal Field Separator
|
# Backup the current Internal Field Separator
|
||||||
ORIGINAL_IFS="$IFS"
|
ORIGINAL_IFS="$IFS"
|
||||||
|
|
||||||
# These two determine separators in single line output, to force irc clients not to break off sections
|
# These two determine separators in single line output, to force irc clients not to break off sections
|
||||||
SEP1='-'
|
SEP1='-'
|
||||||
SEP2='~'
|
SEP2='~'
|
||||||
|
|
||||||
### Script names/paths
|
### Script names/paths
|
||||||
SCRIPT_NAME="inxi"
|
SCRIPT_NAME="inxi"
|
||||||
SCRIPT_PATH=$( dirname $0 )
|
SCRIPT_PATH="" #filled-in in Main
|
||||||
SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
|
SCRIPT_VERSION_NUMBER="" #filled-in in Main
|
||||||
SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
|
SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
|
||||||
SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
|
SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
|
||||||
SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
|
SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
|
||||||
|
@ -302,15 +313,6 @@ A_CPU_BANS=( @ cpu deca 'dual core' dual-core 'tri core' tri-core 'quad core' qu
|
||||||
BAN_LIST_NORMAL=''
|
BAN_LIST_NORMAL=''
|
||||||
BAN_LIST_CPU=''
|
BAN_LIST_CPU=''
|
||||||
|
|
||||||
### Source global config overrides
|
|
||||||
if [[ -s /etc/$SCRIPT_NAME.conf ]];then
|
|
||||||
source /etc/$SCRIPT_NAME.conf
|
|
||||||
fi
|
|
||||||
# Source user config overrides
|
|
||||||
if [[ -s $HOME/.$SCRIPT_NAME ]];then
|
|
||||||
source $HOME/.$SCRIPT_NAME
|
|
||||||
fi
|
|
||||||
|
|
||||||
# WARNING: In the main part below (search for 'KONVI')
|
# WARNING: In the main part below (search for 'KONVI')
|
||||||
# there's a check for Konversation-specific config files.
|
# there's a check for Konversation-specific config files.
|
||||||
# Any one of these can override the above if inxi is run
|
# Any one of these can override the above if inxi is run
|
||||||
|
@ -322,17 +324,32 @@ fi
|
||||||
main()
|
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
|
# stuff works on this function unless you set the debugging flag manually.
|
||||||
# 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
|
initialize_script_data
|
||||||
|
|
||||||
|
# Check for dependencies BEFORE running ANYTHING else except above functions
|
||||||
|
# Not all distro's have these depends installed by default
|
||||||
|
check_script_depends
|
||||||
|
check_script_suggested_apps
|
||||||
|
|
||||||
|
### Only continue if depends ok
|
||||||
|
SCRIPT_PATH=$( dirname $0 )
|
||||||
|
SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
|
||||||
|
|
||||||
|
### Source global config overrides
|
||||||
|
if [[ -s /etc/$SCRIPT_NAME.conf ]];then
|
||||||
|
source /etc/$SCRIPT_NAME.conf
|
||||||
|
fi
|
||||||
|
# Source user config overrides
|
||||||
|
if [[ -s $HOME/.$SCRIPT_NAME ]];then
|
||||||
|
source $HOME/.$SCRIPT_NAME
|
||||||
|
fi
|
||||||
|
|
||||||
## this needs to run before the KONVI stuff is set below
|
## this needs to run before the KONVI stuff is set below
|
||||||
get_start_client
|
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
|
# 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
|
if [[ $KONVI -eq 1 ]];then
|
||||||
|
@ -391,6 +408,7 @@ main()
|
||||||
# initialize some boleans, these directories are used throughout the script
|
# initialize some boleans, these directories are used throughout the script
|
||||||
# some apps are used for extended functions any directory used, should be
|
# some apps are used for extended functions any directory used, should be
|
||||||
# checked here first.
|
# checked here first.
|
||||||
|
# No args taken.
|
||||||
initialize_script_data()
|
initialize_script_data()
|
||||||
{
|
{
|
||||||
local path='' sys_path='' added_path='' b_path_found=''
|
local path='' sys_path='' added_path='' b_path_found=''
|
||||||
|
@ -413,6 +431,7 @@ initialize_script_data()
|
||||||
added_path="$added_path:$path"
|
added_path="$added_path:$path"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
IFS="$ORIGINAL_IFS"
|
IFS="$ORIGINAL_IFS"
|
||||||
PATH="${PATH}${added_path}"
|
PATH="${PATH}${added_path}"
|
||||||
##echo "PATH='$PATH'"
|
##echo "PATH='$PATH'"
|
||||||
|
@ -485,6 +504,7 @@ initialize_script_data()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# No args taken.
|
||||||
check_script_suggested_apps()
|
check_script_suggested_apps()
|
||||||
{
|
{
|
||||||
local bash_array_test=( "one" "two" )
|
local bash_array_test=( "one" "two" )
|
||||||
|
@ -492,7 +512,7 @@ check_script_suggested_apps()
|
||||||
# check for array ability of bash, this is only good for the warning at this time
|
# check for array ability of bash, this is only good for the warning at this time
|
||||||
# the boolean could be used later
|
# the boolean could be used later
|
||||||
# bash version 2.05b is used in DSL
|
# bash version 2.05b is used in DSL
|
||||||
# bash version 3.0 is used in Puppy Linux
|
# bash version 3.0 is used in Puppy Linux; it has a known array bug <reference to be placed here>
|
||||||
# versions older than 3.1 don't handle arrays
|
# versions older than 3.1 don't handle arrays
|
||||||
# distro's using below 2.05b are unknown, released in 2002
|
# distro's using below 2.05b are unknown, released in 2002
|
||||||
if [[ ${bash_array_test[1]} -eq "two" ]];then
|
if [[ ${bash_array_test[1]} -eq "two" ]];then
|
||||||
|
@ -503,14 +523,16 @@ check_script_suggested_apps()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine if any of the absolutely necessary tools are absent
|
# Determine if any of the absolutely necessary tools are absent
|
||||||
|
# No args taken.
|
||||||
check_script_depends()
|
check_script_depends()
|
||||||
{
|
{
|
||||||
local app_name='' app_data=''
|
local app_name='' app_data=''
|
||||||
# bc removed from deps for now
|
# bc removed from deps for now
|
||||||
local depends="df free gawk grep hostname lspci ps readlink tr uname uptime wc"
|
local depends="df free gawk grep hostname lspci ps readlink tr uname uptime wc"
|
||||||
|
local x_apps="xrandr xdpyinfo glxinfo"
|
||||||
|
|
||||||
if [[ $B_X_RUNNING == 'true' ]];then
|
if [[ $B_X_RUNNING == 'true' ]];then
|
||||||
for app_name in xrandr xdpyinfo glxinfo
|
for app_name in $x_apps
|
||||||
do
|
do
|
||||||
app_data=$( type -p $app_name )
|
app_data=$( type -p $app_name )
|
||||||
if [[ -z $app_data ]];then
|
if [[ -z $app_data ]];then
|
||||||
|
@ -805,6 +827,7 @@ get_parameters()
|
||||||
local opt='' wget_test='' update_flags='U!:'
|
local opt='' wget_test='' update_flags='U!:'
|
||||||
local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false
|
local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false
|
||||||
|
|
||||||
|
# <comment here. what is this for?>
|
||||||
if [[ $B_ALLOW_UPDATE == 'false' ]];then
|
if [[ $B_ALLOW_UPDATE == 'false' ]];then
|
||||||
update_flags=''
|
update_flags=''
|
||||||
fi
|
fi
|
||||||
|
@ -1303,6 +1326,7 @@ get_start_client()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
get_cmdline()
|
get_cmdline()
|
||||||
|
@ -1629,7 +1653,8 @@ get_cpu_data()
|
||||||
get_cpu_ht_multicore_smp_data()
|
get_cpu_ht_multicore_smp_data()
|
||||||
{
|
{
|
||||||
# in /proc/cpuinfo
|
# in /proc/cpuinfo
|
||||||
# if > 1 processor && processor id == core id then Hyperthreaded (HT)
|
# algorithm
|
||||||
|
# if > 1 processor && processor id (physical id) == core id then Hyperthreaded (HT)
|
||||||
# if > 1 processor && different processor ids then Multiple Processors (SMP)
|
# if > 1 processor && different processor ids then Multiple Processors (SMP)
|
||||||
# if > 1 processor && processor id != core id then Multi-Core Processors (MCP)
|
# if > 1 processor && processor id != core id then Multi-Core Processors (MCP)
|
||||||
# if = 1 processor then single core/processor Uni-Processor (UP)
|
# if = 1 processor then single core/processor Uni-Processor (UP)
|
||||||
|
@ -1755,8 +1780,13 @@ get_distro_data()
|
||||||
# this handles case where only one release/version file was found, and it's lsb-release. This would
|
# this handles case where only one release/version file was found, and it's lsb-release. This would
|
||||||
# never apply for ubuntu or debian, which will filter down to the following conditions. In general
|
# never apply for ubuntu or debian, which will filter down to the following conditions. In general
|
||||||
# if there's a specific distro release file available, that's to be preferred, but this is a good backup.
|
# if there's a specific distro release file available, that's to be preferred, but this is a good backup.
|
||||||
|
<<<<<<< .mine
|
||||||
|
elif [[ -n $distro_file && -f /etc/lsb_release && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then
|
||||||
|
distro=$( get_distro_lsb_data )
|
||||||
|
=======
|
||||||
elif [[ $distro_file == 'lsb-release' ]];then
|
elif [[ $distro_file == 'lsb-release' ]];then
|
||||||
distro=$( get_distro_lsb_data )
|
distro=$( get_distro_lsb_data )
|
||||||
|
>>>>>>> .r394
|
||||||
# then if the distro id file was found and it's not in the exluded primary distro file list, read it
|
# then if the distro id file was found and it's not in the exluded primary distro file list, read it
|
||||||
elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
|
elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
|
||||||
distro=$( remove_erroneous_chars "/etc/$distro_file" )
|
distro=$( remove_erroneous_chars "/etc/$distro_file" )
|
||||||
|
@ -2152,7 +2182,7 @@ get_hard_drive_data_advanced()
|
||||||
else
|
else
|
||||||
a_temp_working[2]="Name n/a"
|
a_temp_working[2]="Name n/a"
|
||||||
fi
|
fi
|
||||||
# these loops are to easily extend the cpu array created in the awk script above with more fields per cpu.
|
# these loops are to easily extend the cpu array created in the gawk script above with more fields per cpu.
|
||||||
for (( j=0; j < ${#a_temp_working[@]}; j++ ))
|
for (( j=0; j < ${#a_temp_working[@]}; j++ ))
|
||||||
do
|
do
|
||||||
if [[ $j -gt 0 ]];then
|
if [[ $j -gt 0 ]];then
|
||||||
|
@ -2232,7 +2262,7 @@ get_hard_drive_data_advanced()
|
||||||
a_temp_working[2]="Name n/a"
|
a_temp_working[2]="Name n/a"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# these loops are to easily extend the cpu array created in the awk script above with more fields per cpu.
|
# these loops are to easily extend the cpu array created in the gawk script above with more fields per cpu.
|
||||||
for (( j=0; j < ${#a_temp_working[@]}; j++ ))
|
for (( j=0; j < ${#a_temp_working[@]}; j++ ))
|
||||||
do
|
do
|
||||||
if [[ $j -gt 0 ]];then
|
if [[ $j -gt 0 ]];then
|
||||||
|
@ -2373,7 +2403,7 @@ get_networking_wan_ip_data()
|
||||||
local ip=''
|
local ip=''
|
||||||
|
|
||||||
# get ip using wget redirect to stdout. This is a clean, text only IP output url.
|
# get ip using wget redirect to stdout. This is a clean, text only IP output url.
|
||||||
ip=$( wget -q -O - http://smxi.org/opt/ip.php | awk -F 'is: ' '{
|
ip=$( wget -q -O - http://smxi.org/opt/ip.php | gawk -F 'is: ' '{
|
||||||
#gsub("\n","",$2")
|
#gsub("\n","",$2")
|
||||||
print $2
|
print $2
|
||||||
}' )
|
}' )
|
||||||
|
|
Loading…
Reference in a new issue