updated trunk inxi

This commit is contained in:
inxi-svn 2009-05-28 20:26:29 +00:00
parent b59210e006
commit 462fff6b5d

128
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 1.0.11
#### version: 1.0.12
#### Date: 20 March 2009
########################################################################
#### SPECIAL THANKS
@ -61,30 +61,37 @@
########################################################################
#### CONVENTIONS:
#### Indentation: TABS
#### Do not use `....`, those are totally non-reabable, use $(....)
#### Do not use one liner flow controls. The ONLY time you should use ; is in
#### this single case: if [[ condition ]];then (ie, never: [[ condition ]] && statement)
#### Note: [[ -n $something ]] - double brackets do not require quotes: "$something" for variables
#### Always use quotes, double or single, for all string values
#### Do not use `....` (back quotes), those are totally non-reabable, use $(....).
#### Do not use one liner flow controls.
#### The ONLY time you should use ';' (semi-colon) is in this single case: if [[ condition ]];then.
#### Never use compound 'if': ie, if [[ condition ]] && statement.
#### 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.
#### 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 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.
#### To 'return' a value in a function, use 'echo <var>'.
####
#### 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
####, globals UPPER CASE, at top of script, SOME_VARIABLE='' (words separated by _ ).
#### Locals always with: local some_variable= (lower case, words separated by _ )
#### Locals that will be inherited by child functions: Some_Variable (so you know they are inherited)
#### and at the top of the function.
#### All functions should follow standard naming--verb adjective noun.
#### ie, get_cpu_data
#### All variables MUST be initialized / declared explicitly.
#### All variables should clearly explain what they are, except counters like i, j.
#### Each word of variable must be separated by '_' (underscore) (camel form).
#### 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
#### Arrays should start with a_ or A_
#### All functions should follow standard naming, ie, verb adjective noun, get_cpu_data
#### Booleans should start with b_ (local) or B_ (global) and state clearly what is being tested.
#### Arrays should start with a_ (local) or A_ (global).
####
#### SPECIAL NOTES:
#### The color variable ${C2} must always be followed by a space unless you know what
@ -94,15 +101,18 @@
#### For native script konversation support (check distro for correct konvi scripts path):
#### 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.
####
#### As with all 'rules' there are acceptions, these are noted where used.
####
########################################################################
#### 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
#### inxi supports advanced testing triggers to do various things, using -! <arg>
#### -! 1 - triggers default B_TESTING_1='true' to trigger some test or other
#### -! 2 - triggers default B_TESTING_2='true' to trigger some test or other
#### -! 3 - triggers B_TESTING_1='true' and B_TESTING_2='true'
#### -! 1 - triggers default B_TESTING_1='true' to trigger some test or other
#### -! 2 - triggers default B_TESTING_2='true' to trigger some test or other
#### -! 3 - triggers B_TESTING_1='true' and B_TESTING_2='true'
#### -! 10 - triggers an update from the primary dev download server instead of svn
#### -! 11 - triggers an update from svn branch one - if present, of course
#### -! 12 - triggers an update from svn branch two - if present, of course
@ -123,7 +133,7 @@ COLOR_SCHEME_SET=''
IRC_CLIENT=''
IRC_CLIENT_VERSION=''
### primary data array holders
### primary data array holders ## usage: 'A_<var>'
A_AUDIO_DATA=''
A_CMDL=''
A_CPU_CORE_DATA=''
@ -138,7 +148,7 @@ A_NETWORK_DATA=''
A_PARTITION_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
# -U and -! testing/advanced update options, as well as removing the -U help menu item
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"
# 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
## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
# Backup the current Internal Field Separator
ORIGINAL_IFS="$IFS"
# These two determine separators in single line output, to force irc clients not to break off sections
SEP1='-'
SEP2='~'
### Script names/paths
SCRIPT_NAME="inxi"
SCRIPT_PATH=$( dirname $0 )
SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
SCRIPT_PATH="" #filled-in in Main
SCRIPT_VERSION_NUMBER="" #filled-in in Main
SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
@ -264,10 +275,10 @@ export LC_ALL
### Output Colors
# A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
unset EMPTY
# DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW
# DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW
ANSI_COLORS="       "
IRC_COLORS=" \x0314 \x0301 \x0304 \x0305 \x0309 \x0303 \x0308 \x0307"
# BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL
# BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL
ANSI_COLORS="$ANSI_COLORS         "
IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300 \x0315 \x03"
#ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
@ -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_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')
# there's a check for Konversation-specific config files.
# Any one of these can override the above if inxi is run
@ -322,17 +324,32 @@ fi
main()
{
# first init function must be set first for colors etc. Remember, no debugger
# stuff works on this function unless you set the debugging flag
# manually. Debugging flag -@ [number] will not work until get_parameters runs.
# stuff works on this function unless you set the debugging flag manually.
# Debugging flag -@ [number] will not work until get_parameters runs.
# This function just initializes variables
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
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
@ -391,6 +408,7 @@ main()
# initialize some boleans, these directories are used throughout the script
# some apps are used for extended functions any directory used, should be
# checked here first.
# No args taken.
initialize_script_data()
{
local path='' sys_path='' added_path='' b_path_found=''
@ -413,6 +431,7 @@ initialize_script_data()
added_path="$added_path:$path"
fi
done
IFS="$ORIGINAL_IFS"
PATH="${PATH}${added_path}"
##echo "PATH='$PATH'"
@ -485,6 +504,7 @@ initialize_script_data()
fi
}
# No args taken.
check_script_suggested_apps()
{
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
# the boolean could be used later
# 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
# distro's using below 2.05b are unknown, released in 2002
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
# No args taken.
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"
local x_apps="xrandr xdpyinfo glxinfo"
if [[ $B_X_RUNNING == 'true' ]];then
for app_name in xrandr xdpyinfo glxinfo
for app_name in $x_apps
do
app_data=$( type -p $app_name )
if [[ -z $app_data ]];then
@ -805,6 +827,7 @@ get_parameters()
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
# <comment here. what is this for?>
if [[ $B_ALLOW_UPDATE == 'false' ]];then
update_flags=''
fi
@ -1303,6 +1326,7 @@ get_start_client()
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
# args: $1 - $PPID
get_cmdline()
@ -1629,7 +1653,8 @@ get_cpu_data()
get_cpu_ht_multicore_smp_data()
{
# 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 && processor id != core id then Multi-Core Processors (MCP)
# 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
# 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.
<<<<<<< .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
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
elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
distro=$( remove_erroneous_chars "/etc/$distro_file" )
@ -2152,7 +2182,7 @@ get_hard_drive_data_advanced()
else
a_temp_working[2]="Name n/a"
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++ ))
do
if [[ $j -gt 0 ]];then
@ -2232,7 +2262,7 @@ get_hard_drive_data_advanced()
a_temp_working[2]="Name n/a"
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++ ))
do
if [[ $j -gt 0 ]];then
@ -2373,7 +2403,7 @@ get_networking_wan_ip_data()
local ip=''
# 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")
print $2
}' )