2 ########################################################################
5 #### Date: 13 March 2009
6 ########################################################################
8 ########################################################################
9 #### Special thanks to all those in lsc for their tireless dedication
10 #### with helping test inxi modules
11 ########################################################################
13 ########################################################################
14 #### inxi is a fork of infobash 3.02, the original bash sys info script by locsmif
15 #### As time permits functionality improvements and recoding will occur.
17 #### inxi, the universal, portable, system info script for irc.
18 #### Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,
19 #### Gaim/Pidgin, Weechat, KVIrc and Kopete.
20 #### Original infobash author and copyright holder:
21 #### Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif
22 #### inxi version: Copyright (C) 2008-9 Scott Rogers & Harald Hope
23 #### Further fixes (listed as known): Horst Tritremmel <hjt at sidux.com>
24 #### Steven Barrett (aka: damentz) - usb audio patch; swap percent used patch
26 #### Current script home page: http://techpatterns.com/forums/about1131.html
27 #### Script svn: http://code.google.com/p/inxi
29 #### This program is free software; you can redistribute it and/or modify
30 #### it under the terms of the GNU General Public License as published by
31 #### the Free Software Foundation; either version 3 of the License, or
32 #### (at your option) any later version.
34 #### This program is distributed in the hope that it will be useful,
35 #### but WITHOUT ANY WARRANTY; without even the implied warranty of
36 #### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 #### GNU General Public License for more details.
39 #### You should have received a copy of the GNU General Public License
40 #### along with this program. If not, see <http://www.gnu.org/licenses/>.
42 #### If you don't understand what Free Software is, please read (or reread)
43 #### this page: http://www.gnu.org/philosophy/free-sw.html
44 ########################################################################
46 #### bash >=3.0(bash), df;readlink;stty;tr;uname;wc(coreutils),
47 #### gawk(gawk), grep(grep), hostname(hostname), lspci(pciutils),
48 #### ps;uptime(procps), glxinfo;xdpyinfo;xrandr(xbase-clients)
49 #### Also the proc filesystem should be present and mounted
51 #### Apparently unpatched bash 3.0 has arrays broken; bug reports:
52 #### http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-008
53 #### http://lists.gnu.org/archive/html/bug-bash/2004-08/msg00144.html
55 #### Arrays work in bash 2.05b, but "egrep -m" does not
57 #### RECOMMENDS (Needed to run certain features)
58 #### For local interfaces/IP test: ifconfig (in net-tools for Debian systems)
59 #### runlevel(sysvinit): to view current runlevel while not in X window system
60 #### Bash 3.1 for proper array use
61 ########################################################################
63 #### Indentation: TABS
64 #### Do not use `....`, those are totally non-reabable, use $(....)
65 #### Do not use one liner flow controls. The ONLY time you should use ; is in
66 #### this single case: if [[ condition ]];then (ie, never: [[ condition ]] && statement)
67 #### Note: [[ -n $something ]] - double brackets do not require quotes: "$something" for variables
68 #### Always use quotes, double or single, for all string values
70 #### All new code/methods must be in a function.
71 #### For all boolean tests, use 'true' / 'false'. Do NOT use 0 or 1 unless
72 #### it's a function return. Avoid complicated tests in the if condition itself.
74 #### For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
75 #### This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
77 #### VARIABLE/FUNCTION NAMING:
78 #### All variables should explain what they are, except counters like i, j
79 #### All variables MUST be initialized / declared explicitly
80 ####, globals UPPER CASE, at top of script, SOME_VARIABLE='' (words separated by _ ).
81 #### Locals always with: local some_variable= (lower case, words separated by _ )
82 #### Locals that will be inherited by child functions: Some_Variable (so you know they are inherited)
83 #### and at the top of the function.
85 #### Booleans should start with b_ or B_ and state clearly what is being tested
86 #### Arrays should start with a_ or A_
87 #### All functions should follow standard naming, ie, verb adjective noun, get_cpu_data
90 #### The color variable ${C2} must always be followed by a space unless you know what
91 #### character is going to be next for certain. Otherwise irc color codes can be accidentally
92 #### activated or altered.
94 #### For native script konversation support (check distro for correct konvi scripts path):
95 #### ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi
96 #### DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.
97 ########################################################################
98 #### Valuable Resources
99 #### awk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
100 ########################################################################
102 #### inxi supports advanced testing triggers to do various things, using -! <arg>
103 #### -! 1 - triggers default B_TESTING_1='true' to trigger some test or other
104 #### -! 2 - triggers default B_TESTING_2='true' to trigger some test or other
105 #### -! 3 - triggers B_TESTING_1='true' and B_TESTING_2='true'
106 #### -! 10 - triggers an update from the primary dev download server instead of svn
107 #### -! 11 - triggers an update from svn branch one - if present, of course
108 #### -! 12 - triggers an update from svn branch two - if present, of course
109 #### -! 13 - triggers an update from svn branch three - if present, of course
110 #### -! 14 - triggers an update from svn branch four - if present, of course
111 #### -! <http://......> - Triggers an update from whatever server you list.
112 ########################################################################
114 ########################################################################
116 ## NOTE: we can use hwinfo if it's available in all systems, or most, to get
117 ## a lot more data and verbosity levels going
119 ### Variable initializations: null values
124 IRC_CLIENT_VERSION=''
126 ### primary data array holders
131 A_CPU_TYPE_PCNT_CCNT=''
141 ### Boolean true/false globals
142 # flag to allow distro maintainers to turn off update features. If false, turns off
143 # -U and -! testing/advanced update options, as well as removing the -U help menu item
144 B_ALLOW_UPDATE='true'
145 # triggers full display of cpu flags
146 B_CPU_FLAGS_FULL='false'
147 # Debug flood override: make 'true' to allow long debug output
148 B_DEBUG_FLOOD='false'
149 # show extra output data
152 # override certain errors due to currupted data
153 B_HANDLE_CORRUPT_DATA='false'
154 # Running in a shell? Defaults to false, and is determined later.
155 B_RUNNING_IN_SHELL='false'
156 # this sets the debug buffer
158 # Show sound card data
161 # Show full hard disk output
162 B_SHOW_FULL_HDD='false'
163 B_SHOW_GRAPHICS='false'
164 # Set this to 'false' to avoid printing the hostname
168 B_SHOW_LABELS='false'
169 B_SHOW_NETWORK='false'
170 # either -v > 3 or -P will show partitions
171 B_SHOW_PARTITIONS='false'
172 B_SHOW_PARTITIONS_FULL='false'
173 # triggers only short inxi output
174 B_SHOW_SHORT_OUTPUT='false'
175 B_SHOW_SYSTEM='false'
177 # triggers various debugging and new option testing
183 ### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
187 B_ASOUND_CARDS='false'
188 B_ASOUND_VERSION='false'
193 B_MODULES_DIR='false' #
195 B_PARTITIONS_DIR='false' #
197 ### Directory's used when present
198 DIR_CPUINFO='/proc/cpuinfo'
199 DIR_MEMINFO='/proc/meminfo'
200 DIR_ASOUND_DEVICE='/proc/asound/cards'
201 DIR_ASOUND_VERSION='/proc/asound/version'
202 DIR_LSB_RELEASE='/etc/lsb-release'
203 DIR_SCSI='/proc/scsi/scsi'
204 DIR_MODULES='/proc/modules' #
205 DIR_MOUNTS='/proc/mounts'
206 DIR_PARTITIONS='/proc/partitions' #
207 DIR_IFCONFIG='/sbin/ifconfig'
209 ### Variable initializations: constants
211 DEBUG=0 # Set debug levels from 1-10
212 # Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up'
214 ## note: the debugger rerouting to /dev/null has been moved to the end of the get_parameters function
215 ## so -@[number] debug levels can be set if there is a failure, otherwise you can't even see the errors
217 # Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Set to any other valid scheme you like.
218 # Same as runtime parameter.
220 # Default indentation level
222 # default to false, no konversation found, 1 is /cmd inxi start, 2 is native konvi script mode
224 # NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
225 # This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
227 SCHEME=0 # set default scheme
228 # SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
230 # Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
232 # Supported number of verbosity levels, including 0
235 # Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
236 # type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
237 # therefore results in nothing. Tricky as fuck.
239 ## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
240 # Backup the current Internal Field Separator
242 # These two determine separators in single line output, to force irc clients not to break off sections
246 ### Script names/paths
248 SCRIPT_PATH=$( dirname $0 )
249 SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
250 SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
251 SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
252 SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
253 SCRIPT_DOWNLOAD_BRANCH_3='http://inxi.googlecode.com/svn/branches/three/'
254 SCRIPT_DOWNLOAD_BRANCH_4='http://inxi.googlecode.com/svn/branches/four/'
255 SCRIPT_DOWNLOAD_DEV='http://smxi.org/test/'
256 KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data)
258 ### Script Localization
259 # Make sure every program speaks English.
264 # A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
266 # DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW
267 ANSI_COLORS="
\e[1;30m
\e[0;30m
\e[1;31m
\e[0;31m
\e[1;32m
\e[0;32m
\e[1;33m
\e[0;33m"
268 IRC_COLORS=" \x0314 \x0301 \x0304 \x0305 \x0309 \x0303 \x0308 \x0307"
269 # BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL
270 ANSI_COLORS="$ANSI_COLORS
\e[1;34m
\e[0;34m
\e[1;35m
\e[0;35m
\e[1;36m
\e[0;36m
\e[1;37m
\e[0;37m
\e[0;37m"
271 IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300 \x0315 \x03"
272 #ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
273 A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL )
274 # See above for notes on EMPTY
275 A_COLOR_SCHEMES=( EMPTY,EMPTY,EMPTY NORMAL,NORMAL,NORMAL BLUE,NORMAL,NORMAL GREEN,YELLOW,NORMAL DYELLOW,NORMAL,NORMAL CYAN,BLUE,NORMAL RED,NORMAL,NORMAL GREEN,NORMAL,NORMAL YELLOW,NORMAL,NORMAL GREEN,DGREEN,NORMAL BLUE,RED,NORMAL BLUE,NORMAL,RED YELLOW,WHITE,GREEN BLUE,NORMAL,GREEN DCYAN,NORMAL,DMAGENTA )
276 ## Actual color variables
282 # In cases of derived distros where the version file of the base distro can also be found under /etc,
283 # the derived distro's version file should go first. (Such as with Sabayon / Gentoo)
284 DISTROS_DERIVED="antix-version kanotix-version knoppix-version mandrake-release pardus-release sabayon-release sidux-version turbolinux-release zenwalk-version"
285 # debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
286 DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
287 DISTROS_PRIMARY="gentoo-release redhat-release slackware-version SuSE-release"
288 DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
289 ## Distros with known problems
290 # DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
291 # Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
294 # Precede a banword with $'\2' to prevent it from being subject to automated escaping by the make_ban_lists routine
295 # $'\1' gets weird results :
296 # user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v
297 # 00000000 01 01 6f 6e 65 20 74 77 6f 0a |..one two.|
298 A_NORMAL_BANS=( corporation communications gmbh technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" "®" $'\2'"\(rev ..\)" )
299 A_CPU_BANS=( @ cpu deca 'dual core' dual-core 'tri core' tri-core 'quad core' quad-core ennea genuine hepta hexa multi octa penta 'processor' processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" )
300 # after processing, the ban arrays will be put into these:
304 ### Source global config overrides
305 if [[ -s /etc/$SCRIPT_NAME.conf ]];then
306 source /etc/$SCRIPT_NAME.conf
308 # Source user config overrides
309 if [[ -s $HOME/.$SCRIPT_NAME ]];then
310 source $HOME/.$SCRIPT_NAME
313 # WARNING: In the main part below (search for 'KONVI')
314 # there's a check for Konversation-specific config files.
315 # Any one of these can override the above if inxi is run
318 ########################################################################
319 #### MAIN: Where it all begins
320 ########################################################################
323 # first init function must be set first for colors etc. Remember, no debugger
324 # stuff works on this function unless you set the debugging flag
325 # manually. Debugging flag -@ [number] will not work until get_parameters runs.
326 initialize_script_data
328 ## this needs to run before the KONVI stuff is set below
331 # Check for dependencies before running anything else except above functions
333 check_script_suggested_apps
335 # note: this only works if it's run from inside konversation as a script builtin or something
336 # only do this if inxi has been started as a konversation script, otherwise bypass this
337 if [[ $KONVI -eq 1 ]];then
342 # The section below is on request of Argonel from the Konversation developer team:
343 # it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf
345 for kde_config in $( kde-config --path data )
347 if [[ -r ${kde_config}${KONVI_CFG} ]];then
348 source "${kde_config}${KONVI_CFG}"
354 ## leave this for debugging dcop stuff if we get that working
355 # print_screen_output "DCPORT: $DCPORT"
356 # print_screen_output "DCSERVER: $DCSERVER"
357 # print_screen_output "DCTARGET: $DCTARGET"
359 # "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
360 # must be here to allow debugger and other flags to be set.
363 # If no colorscheme was set in the parameter handling routine, then set the default scheme
364 if [[ $COLOR_SCHEME_SET != 'true' ]];then
365 set_color_scheme "$DEFAULT_SCHEME"
368 # all the pre-start stuff is in place now
370 script_debugger "Debugger: $SCRIPT_NAME is up and running..."
372 # then create the output
376 if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
380 # weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
381 # from the last command is taken..
385 #### -------------------------------------------------------------------
386 #### basic tests: set script data, booleans, PATH
387 #### -------------------------------------------------------------------
389 # Set PATH data so we can access all programs as user. Set BAN lists.
390 # initialize some boleans, these directories are used throughout the script
391 # some apps are used for extended functions any directory used, should be
392 # checked here first.
393 initialize_script_data()
395 local path='' sys_path='' added_path='' b_path_found=''
396 # Extra path variable to make execute failures less likely, merged below
397 local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
399 # Fallback paths put into $extra_paths; This might, among others, help on gentoo.
400 # Now, create a difference of $PATH and $extra_paths and add that to $PATH:
402 for path in $extra_paths
405 for sys_path in $PATH
407 if [[ $path == $sys_path ]];then
411 if [[ $b_path_found == 'false' ]];then
412 added_path="$added_path:$path"
416 PATH="${PATH}${added_path}"
417 ##echo "PATH='$PATH'"
418 ##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
420 # Do this after sourcing of config overrides so user can customize banwords
421 BAN_LIST_NORMAL=$( make_ban_lists "${A_NORMAL_BANS[@]}" ) # Contrary to my previous belief, "${ARR[@]}" passes a quoted list, not one string
422 BAN_LIST_CPU=$( make_ban_lists "${A_CPU_BANS[@]}" )
423 ##echo "BAN_LIST_NORMAL='$BAN_LIST_NORMAL'"
425 # now set the script BOOLEANS for files required to run features
426 if [[ -d "/proc/" ]];then
432 if [[ -e $DIR_CPUINFO ]]; then
436 if [[ -e $DIR_MEMINFO ]];then
440 if [[ -e $DIR_ASOUND_DEVICE ]];then
441 B_ASOUND_CARDS='true'
444 if [[ -e $DIR_ASOUND_VERSION ]];then
445 B_ASOUND_VERSION='true'
448 if [[ -f $DIR_LSB_RELEASE ]];then
452 if [[ -e $DIR_SCSI ]];then
456 # lack of ifconfig will throw an error only upon it's usage
457 if [[ -x ifconfig ]]; then
459 DIR_IFCONFIG='ifconfig' # change from full path to use $PATH
460 elif [[ -x $DIR_IFCONFIG ]];then
463 A_INTERFACES_DATA=( "Interfaces tool requires missing app: $DIR_IFCONFIG" )
466 if [[ -n $DISPLAY ]];then
470 if [[ -e $DIR_MODULES ]];then
474 if [[ -e $DIR_MOUNTS ]];then
478 if [[ -e $DIR_PARTITIONS ]];then
479 B_PARTITIONS_DIR='true'
483 check_script_suggested_apps()
485 local bash_array_test=( "one" "two" )
487 # check for array ability of bash, this is only good for the warning at this time
488 # the boolean could be used later
489 # bash version 2.05b is used in DSL
490 # bash version 3.0 is used in Puppy Linux
491 # versions older than 3.1 don't handle arrays
492 # distro's using below 2.05b are unknown, released in 2002
493 if [[ ${bash_array_test[1]} -eq "two" ]];then
496 script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output"
500 # Determine if any of the absolutely necessary tools are absent
501 check_script_depends()
503 local app_name='' app_data=''
504 # bc removed from deps for now
505 local depends="df free gawk grep hostname lspci ps readlink tr uname uptime wc"
507 if [[ $B_X_RUNNING == 'true' ]];then
508 for app_name in xrandr xdpyinfo glxinfo
510 app_data=$( type -p $app_name )
511 if [[ -z $app_data ]];then
512 script_debugger "Resuming in non X mode: $app_name not found in path"
521 for app_name in $depends
523 app_data=$( type -p $app_name )
524 if [[ -z $app_data ]];then
525 error_handler 5 "$app_name"
530 ## note: this is now running inside each gawk sequence directly to avoid exiting gawk
531 ## looping in bash through arrays, then re-entering gawk to clean up, then writing back to array
532 ## in bash. For now I'll leave this here because there's still some interesting stuff to get re methods
533 # Enforce boilerplate and buzzword filters
534 # args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
535 sanitize_characters()
537 # Cannot use strong quotes to unquote a string with pipes in it!
538 # bash will interpret the |'s as usual and try to run a subshell!
539 # Using weak quotes instead, or use '"..."'
546 gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
547 gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
548 print ## prints (returns) cleaned input
552 # Filter boilerplate & buzzwords.
553 # args: $1 - quoted: "$@" array of ban terms
558 ## note: this is a weird, non-intuitive method, needs some documentation or rewriting
559 ## if you declare ban_string it stops working, have to read up on this
562 # echo "term=\"$ban_string\"" # >&2
563 if [[ ${ban_string:0:1} = $'\2' ]];then
564 ban_list="${ban_list}${ban_list+|}${ban_string:1:${#ban_string}-1}"
566 # Automatically escapes [ ] ( ) . and +
567 ban_list="${ban_list}${ban_list+|}$( echo "$ban_string" | gawk '{
568 gsub(/([\[\]+().])/,"\\\\&")
576 # make_ban_lists "${A_CPU_BANS[@]}";exit
578 # Set the colorscheme
579 # args: $1 = <scheme number>|<"none">
582 local i='' script_colors='' color_codes=''
584 if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then
587 # Set a global variable to allow checking for chosen scheme later
589 if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
590 color_codes=( $ANSI_COLORS )
592 color_codes=( $IRC_COLORS )
594 for (( i=0; i < ${#A_COLORS_AVAILABLE[@]}; i++ ))
596 eval "${A_COLORS_AVAILABLE[i]}=\"${color_codes[i]}\""
599 script_colors=( ${A_COLOR_SCHEMES[$1]} )
601 # then assign the colors globally
602 C1="${!script_colors[0]}"
603 C2="${!script_colors[1]}"
604 CN="${!script_colors[2]}"
605 # ((COLOR_SCHEME++)) ## note: why is this? ##
608 ########################################################################
609 #### UTILITY FUNCTIONS
610 ########################################################################
612 #### -------------------------------------------------------------------
613 #### error handler, debugger, script updater
614 #### -------------------------------------------------------------------
617 # args: $1 - error number; $2 - optional, extra information
620 local error_message=''
622 # assemble the error message
624 2) error_message="large flood danger, debug buffer full!"
626 3) error_message="unsupported color scheme number: $2"
628 4) error_message="unsupported verbosity level: $2"
630 5) error_message="dependency not met: $2 not found in path"
632 6) error_message="/proc not found! Quitting..."
634 7) error_message="One of the options you entered in your script parameters: $2\nIs not supported. For supported options, check the help menu: $SCRIPT_NAME -h"
636 8) error_message="the self-updater failed, wget exited with error: $2.\nYou probably need to be root.\nHint, to make for easy updates without being root, do: chown <user name> $SCRIPT_PATH/$SCRIPT_NAME"
638 9) error_message="unsupported debugging level: $2"
641 error_message="the alt download url you provided: $2\nappears to be wrong, download aborted. Please note, the url\nneeds to end in /, without $SCRIPT_NAME, like: http://yoursite.com/downloads/"
644 error_message="unsupported testing option argument: -! $2"
647 error_message="the svn branch download url: $2\nappears to be empty currently. Make sure there is an actual svn branch version\nactive before you try this again. Check http://code.google.com/p/inxi\nto verify the branch status."
649 *) error_message="error unknown: $@"
653 # then print it and exit
654 print_screen_output "Error $1: $error_message"
658 # prior to script up set, pack the data into an array
659 # then we'll print it out later.
660 # args: $1 - $@ debugging string text
663 if [[ $B_SCRIPT_UP == 'true' ]];then
664 # only return if debugger is off and no pre start up errors have occured
665 if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
667 # print out the stored debugging information if errors occured
668 elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
669 for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
671 print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
675 # or print out normal debugger messages if debugger is on
676 if [[ $DEBUG -gt 0 ]];then
677 print_screen_output "$1"
680 if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
682 # this case stores the data for later printout, will print out only
683 # at B_SCRIPT_UP == 'true' if array index > 0
685 A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
686 # increment count for next pre script up debugging error
687 (( DEBUG_BUFFER_INDEX++ ))
692 # args: $1 - download url, not including file name; $2 - string to print out
693 # note that $1 must end in / to properly construct the url path
694 script_self_updater()
697 print_screen_output "Starting $SCRIPT_NAME self updater."
698 print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER"
699 print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..."
700 # first test if path is good, need to make sure it's good because we're -O overwriting file
701 wget -q --spider $1$SCRIPT_NAME || wget_error=$?
702 # then do the actual download
703 if [[ $wget_error -eq 0 ]];then
704 wget -q -O $SCRIPT_PATH/$SCRIPT_NAME $1$SCRIPT_NAME || wget_error=$?
705 if [[ $wget_error -eq 0 ]];then
706 SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
707 print_screen_output "Successfully updated to $2 version: $SCRIPT_VERSION_NUMBER"
708 print_screen_output "To run the new version, just start $SCRIPT_NAME again."
712 # now run the error handlers on any wget failure
713 if [[ $wget_error -gt 0 ]];then
714 if [[ $2 == 'svn server' ]];then
715 error_handler 8 "$wget_error"
716 elif [[ $2 == 'alt server' ]];then
717 error_handler 10 "$1"
719 error_handler 12 "$1"
724 #### -------------------------------------------------------------------
725 #### print / output cleaners
726 #### -------------------------------------------------------------------
728 # inxi speaks through here. When run by Konversation script alias mode, uses DCOP
729 # for dcop to work, must use 'say' operator, AND colors must be evaluated by echo -e
730 # note: dcop does not seem able to handle \n so that's being stripped out and replaced with space.
731 print_screen_output()
733 # the double quotes are needed to avoid losing whitespace in data when certain output types are used
734 local print_data="$( echo -e "$1" )"
736 if [[ $DEBUG -gt 5 ]];then
737 if [[ $KONVI -eq 1 ]];then
738 # konvi doesn't seem to like \n characters, it just prints them literally
739 print_data="$( tr '\n' ' ' <<< "$print_data" )"
740 dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "konvi='$KONVI' saying : '$print_data'"
741 elif [[ $KONVI -eq 2 ]];then
742 echo "konvi='$KONVI' saying : '$print_data'"
744 echo "printing out: '$print_data'"
748 if [[ $KONVI -eq 1 ]];then
749 print_data="$( tr '\n' ' ' <<< "$print_data" )"
750 dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data"
752 # the -n is needed to avoid double spacing of output in terminal
753 echo -ne "$print_data\n"
757 ## this handles all verbose line construction with indentation/line starter
758 ## args: $1 - null (, actually: " ") or line starter; $2 - line content
761 printf "${C1}%-${INDENT}s${C2} %s" "$1" "$2"
764 # this removes newline and pipes.
765 # args: $1 - string to clean
766 remove_erroneous_chars()
768 ## RS is input record separator
769 ## gsub is substitute;
775 gsub(/\n$/,"") ## (newline; end of string) with (nothing)
776 gsub(/\n/," "); ## (newline) with (space)
777 gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
778 gsub(/ +/, " ") ## ( +) with (space)
779 gsub(/ [ ]+/, " ") ## ([ ]+) with (space)
780 gsub(/^ +| +$/, "") ## (pipe char) with (nothing)
782 }' "$1" ## prints (returns) cleaned input
785 #### -------------------------------------------------------------------
786 #### parameter handling, print usage functions.
787 #### -------------------------------------------------------------------
789 # Get the parameters. Note: standard options should be lower case, advanced or testing, upper
790 # args: $1 - full script startup args: $@
793 local opt='' wget_test='' update_flags='U!:'
794 local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false
796 if [[ $B_ALLOW_UPDATE == 'false' ]];then
800 # the short form only runs if no args output args are used
801 # no need to run through these if there are no args
803 while getopts Ac:CdDfFGhHiIlNpPSuv:Vx%@:${update_flags} opt
806 A) B_SHOW_AUDIO='true'
809 c) if [[ -n $( egrep '^[0-9][0-9]?$' <<< $OPTARG ) ]];then
810 COLOR_SCHEME_SET='true'
811 ## note: not sure about this, you'd think user values should be overridden, but
812 ## we'll leave this for now
813 if [[ -z $COLOR_SCHEME ]];then
814 set_color_scheme "$OPTARG"
817 error_handler 3 "$OPTARG"
826 D) B_SHOW_DISK='true'
830 B_CPU_FLAGS_FULL='true'
833 F) VERBOSITY_LEVEL=$VERBOSITY_LEVELS
836 B_SHOW_PARTITIONS='true'
840 G) B_SHOW_GRAPHICS='true'
844 B_SHOW_NETWORK='true'
847 I) B_SHOW_INFO='true'
850 l) B_SHOW_LABELS='true'
851 B_SHOW_PARTITIONS='true'
854 N) B_SHOW_NETWORK='true'
857 p) B_SHOW_PARTITIONS_FULL='true'
858 B_SHOW_PARTITIONS='true'
861 P) B_SHOW_PARTITIONS='true'
864 S) B_SHOW_SYSTEM='true'
867 u) B_SHOW_UUIDS='true'
868 B_SHOW_PARTITIONS='true'
871 v) if [[ -n $( egrep "^[0-9][0-9]?$" <<< $OPTARG ) && $OPTARG -le $VERBOSITY_LEVELS ]];then
872 VERBOSITY_LEVEL="$OPTARG"
873 if [[ $OPTARG -gt 0 ]];then
877 error_handler 4 "$OPTARG"
880 U) script_self_updater "$SCRIPT_DOWNLOAD" 'svn server'
882 V) print_version_info
885 x) B_EXTRA_DATA='true'
890 H) show_options 'full'
893 ## debuggers and testing tools
894 %) B_HANDLE_CORRUPT_DATA='true'
896 @) if [[ -n $( egrep "^([1-9]|10)$" <<< $OPTARG ) ]];then
900 error_handler 9 "$OPTARG"
903 !) # test for various supported methods
905 1) B_TESTING_1='true'
907 2) B_TESTING_2='true'
909 3) B_TESTING_1='true'
913 script_self_updater "$SCRIPT_DOWNLOAD_DEV" 'dev server'
916 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_1" 'svn: branch one server'
919 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_2" 'svn: branch two server'
922 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_3" 'svn: branch three server'
925 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_4" 'svn: branch four server'
928 script_self_updater "$OPTARG" 'alt server'
930 *) error_handler 11 "$OPTARG"
934 *) error_handler 7 "$1"
939 ## this must occur here so you can use the debugging flag to show errors
940 ## Reroute all error messages to the bitbucket (if not debugging)
941 if [[ $DEBUG -eq 0 ]];then
944 #((DEBUG)) && exec 2>&1 # This is for debugging konversation
946 # after all the args have been processed, if no long output args used, run short output
947 if [[ $use_short == 'true' ]];then
948 B_SHOW_SHORT_OUTPUT='true'
952 ## print out help menu, not including Testing or Debugger stuff because it's not needed
955 local color_scheme_count=${#A_COLOR_SCHEMES[@]}
957 print_screen_output "$SCRIPT_NAME supports the following options. You can combine them, or list them"
958 print_screen_output "one by one: Examples: $SCRIPT_NAME -v4 -c6 OR $SCRIPT_NAME -dDc 6"
959 print_screen_output ""
960 print_screen_output "If you start $SCRIPT_NAME with no arguments, it will show the short form."
961 print_screen_output "The following options if used without -d or -v will show just that complete line:"
962 print_screen_output "A,C,D,G,I,N,P,S - you can use these together to show just the lines you want to see."
963 print_screen_output "If you use them with a -v level (or -d), it will show the full output for that line "
964 print_screen_output "along with the output for the chosen verbosity level."
965 print_screen_output "- - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
966 print_screen_output "Output Control Options:"
967 print_screen_output "-A Show audio/sound card information."
968 print_screen_output "-c Available color schemes. Scheme number is required."
969 print_screen_output " Supported schemes: 0-$color_scheme_count Example: $SCRIPT_NAME -c 11"
970 print_screen_output "-C Show full CPU output, including per CPU clockspeed."
971 print_screen_output "-d Default output verbosity level, same as: $SCRIPT_NAME -v 1"
972 print_screen_output "-D Show full hard disk info, not only model, ie: /dev/sda ST380817AS 80.0GB."
973 print_screen_output "-f Show all cpu flags used, not just the short list. Not shown with -F to avoid spamming."
974 print_screen_output "-F Show Full, all possible, output for $SCRIPT_NAME."
975 print_screen_output "-G Show graphic card information (+ glx driver and version for non free video drivers)."
976 print_screen_output "-i Show Wan IP address, and shows local interfaces (requires ifconfig network tool)."
977 print_screen_output " Not shown with -F for user security reasons, you shouldn't paste your local/wan IP."
978 print_screen_output "-I Show information: processes, uptime, memory, irc client, inxi version."
979 print_screen_output "-l Show partition labels. Default: short partition -P. For full -p output, use: -pl (or -plu)."
980 print_screen_output "-N Show network card information."
981 print_screen_output "-p Show full partition information (-P plus all other detected partitions)."
982 print_screen_output " If any of your partitions have spaces in their names, they will not show with -p"
983 print_screen_output "-P Show partition information (shows what -v4 would show, but without extra data)."
984 print_screen_output " Shows, if detected: / /boot /home /tmp /usr /var. Use -p for All partitions."
985 print_screen_output "-S Show system information: host name, kernel, distro"
986 print_screen_output "-u Show partition UUIDs. Default: short partition -P. For full -p output, use: -pu (or -plu)."
987 print_screen_output "-v Script verbosity levels. Verbosity level number is required."
988 print_screen_output " Supported levels: 0-${VERBOSITY_LEVELS} Example: $SCRIPT_NAME -v 4"
989 print_screen_output " 0 - short output, same as: $SCRIPT_NAME"
990 print_screen_output " 1 - basic verbose, same as: $SCRIPT_NAME -d"
991 print_screen_output " 2 - Also show networking card data"
992 print_screen_output " 3 - Also show hard disk names as detected."
993 print_screen_output " 4 - Also show partition size/filled data for (if present):/, /home, /var/, /boot"
994 print_screen_output " 5 - For multicore systems, also show per core clock speeds; shows audio card."
995 print_screen_output "-x Show extra data: bogomips on cpu; driver version (if available) for network/audio;"
996 print_screen_output " direct rendering status for Graphics. Only works with verbose or line output."
997 print_screen_output ""
998 print_screen_output "Additional Options:"
999 print_screen_output "-h - this help menu."
1000 if [[ $B_ALLOW_UPDATE == 'true' ]];then
1001 print_screen_output "-U Auto-update script. Note: if you installed as root, you"
1002 print_screen_output " must be root to update, otherwise user is fine."
1004 print_screen_output "-V $SCRIPT_NAME version information. Prints information then exits."
1005 print_screen_output "-% Overrides defective or corrupted data."
1006 print_screen_output "-@ Triggers debugger output. Requires debugging level 1-10."
1007 if [[ $1 == 'full' ]];then
1008 print_screen_output ""
1009 print_screen_output "Developer and Testing Options (Advanced):"
1010 print_screen_output "-! 1 - Sets testing flag B_TESTING_1='true' to trigger testing condition 1."
1011 print_screen_output "-! 2 - Sets testing flag B_TESTING_2='true' to trigger testing condition 2."
1012 print_screen_output "-! 3 - Sets flags B_TESTING_1='true' and B_TESTING_2='true'."
1013 print_screen_output "-! 10 - Triggers an update from the primary dev download server instead of svn."
1014 print_screen_output "-! 11 - Triggers an update from svn branch one - if present, of course."
1015 print_screen_output "-! 12 - Triggers an update from svn branch two - if present, of course."
1016 print_screen_output "-! 13 - Triggers an update from svn branch three - if present, of course."
1017 print_screen_output "-! 14 - Triggers an update from svn branch four - if present, of course."
1018 print_screen_output "-! <http://......> - Triggers an update from whatever server you list."
1019 print_screen_output ""
1021 print_screen_output ""
1024 ## print out version information for -V/--version
1025 print_version_info()
1027 local last_modified=$( grep -im 1 'date:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3,$4,$5}' )
1029 print_screen_output "$SCRIPT_NAME - the universal, portable, system info script for irc."
1030 print_screen_output "Version: $SCRIPT_VERSION_NUMBER"
1031 print_screen_output "Script Last Modified: $last_modified"
1032 print_screen_output "Script Location: $SCRIPT_PATH"
1033 print_screen_output ""
1034 print_screen_output "Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,"
1035 print_screen_output "Gaim/Pidgin, Weechat, KVIrc and Kopete."
1036 print_screen_output ""
1037 print_screen_output "This script is a fork of Infobash 3.02, which is:"
1038 print_screen_output "Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif"
1039 print_screen_output "Subsequent changes and modifications (after Infobash 3.02) are:"
1040 print_screen_output "Copyright (C) 2008-9 Scott Rogers, Harald Hope, aka trash80 & h2"
1041 print_screen_output ""
1042 print_screen_output "This program is free software; you can redistribute it and/or modify"
1043 print_screen_output "it under the terms of the GNU General Public License as published by"
1044 print_screen_output "the Free Software Foundation; either version 3 of the License, or"
1045 print_screen_output "(at your option) any later version."
1048 ########################################################################
1050 ########################################################################
1052 #### -------------------------------------------------------------------
1053 #### initial startup stuff
1054 #### -------------------------------------------------------------------
1056 # Determine where inxi was run from, set IRC_CLIENT and IRC_CLIENT_VERSION
1059 local irc_client_path='' irc_client_path_lower='' non_native_konvi='' i=''
1060 local b_non_native_app='false' pppid='' app_working_name=''
1062 if tty >/dev/null;then
1064 unset IRC_CLIENT_VERSION
1065 B_RUNNING_IN_SHELL='true'
1066 elif [[ -n $PPID && -f /proc/$PPID/exe ]];then
1067 irc_client_path=$( readlink /proc/$PPID/exe )
1068 irc_client_path_lower=$( tr '[:upper:]' '[:lower:]' <<< $irc_client_path )
1069 app_working_name=$( basename $irc_client_path_lower )
1070 # handles the xchat/sh/bash/dash cases, and the konversation/perl cases, where clients
1071 # report themselves as perl or unknown shell. IE: when konversation starts inxi
1072 # from inside itself, as a script, the parent is konversation/xchat, not perl/bash etc
1073 # note: perl can report as: perl5.10.0, so it needs wildcard handling
1074 case $app_working_name in
1075 bash|dash|sh|perl*) # We want to know who wrapped it into the shell or perl.
1076 pppid="$( ps -p $PPID -o ppid --no-headers | sed 's/ //g' )"
1077 if [[ -n $pppid && -f /proc/$pppid/exe ]];then
1078 irc_client_path="$( readlink /proc/$pppid/exe )"
1079 irc_client_path_lower="$( tr '[:upper:]' '[:lower:]' <<< $irc_client_path )"
1080 app_working_name=$( basename $irc_client_path_lower )
1081 b_non_native_app='true'
1085 # replacing loose detection with tight detection, bugs will be handled with app names
1087 case $app_working_name in
1089 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1095 # this is necessary to avoid the dcop errors from starting inxi as a /cmd started script
1096 if [[ $b_non_native_app == 'true' ]];then
1101 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
1103 for ( i=2; i<=NF; i++ ) {
1114 T=($IRC_CLIENT_VERSION)
1115 if [[ ${T[0]} == *+* ]];then
1116 # < Sho_> locsmif: The version numbers of SVN versions look like this:
1117 # "<version number of last release>+ #<build number", i.e. "1.0+ #3177" ...
1118 # for releases we remove the + and build number, i.e. "1.0" or soon "1.0.1"
1119 IRC_CLIENT_VERSION=" CVS $IRC_CLIENT_VERSION"
1122 IRC_CLIENT_VERSION=" ${T[0]}"
1125 # Remove any dots except the first, and make sure there are no trailing zeroes,
1126 T2=$( echo "$T2" | gawk '{
1132 # Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc
1133 # becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller
1134 # than 1 and change the DCOP parameter/object accordingly.
1135 if [[ ${T2} -lt 1 ]];then
1136 DCOPOBJ="Konversation"
1138 IRC_CLIENT="Konversation"
1141 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1144 IRC_CLIENT="X-Chat-Gnome"
1147 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1153 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
1156 gsub(/[()]|bitchx-/,"",a)
1169 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1175 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1181 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1187 # sample: quassel -v
1189 # KDE: 4.2.65 (KDE 4.2.65 (KDE 4.3 >= 20090226))
1190 # Quassel IRC: v0.4.0 [+60] (git-22effe5)
1191 # note: early < 0.4.1 quassels do not have -v
1192 IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>/dev/null | gawk -F ': ' '
1201 # this handles pre 0.4.1 cases with no -v
1202 if ( clientVersion == "" ) {
1203 clientVersion = "(pre v0.4.1)"
1207 # now handle primary, client, and core. quasselcore doesn't actually
1208 # handle scripts with exec, but it's here just to be complete
1209 case $app_working_name in
1211 IRC_CLIENT="Quassel [M]"
1214 IRC_CLIENT="Quassel"
1217 IRC_CLIENT="Quassel (core)"
1222 IRC_CLIENT_VERSION=" $( $irc_client_path -v ) "
1223 IRC_CLIENT="Weechat"
1226 IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>&1 | gawk '{
1227 for ( i=2; i<=NF; i++) {
1240 IRC_CLIENT_VERSION=" $( kopete -v | gawk '
1248 unset IRC_CLIENT_VERSION
1249 # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
1251 for (( i=0; i <= $CMDL_MAX; i++ ))
1253 case ${A_CMDL[i]} in
1256 # Dynamic runpath detection is too complex with KSirc, because KSirc is started from
1257 # kdeinit. /proc/<pid of the grandparent of this process>/exe is a link to /usr/bin/kdeinit
1258 # with one parameter which contains parameters separated by spaces(??), first param being KSirc.
1259 # Then, KSirc runs dsirc as the perl irc script and wraps around it. When /exec is executed,
1260 # dsirc is the program that runs inxi, therefore that is the parent process that we see.
1261 # You can imagine how hosed I am if I try to make inxi find out dynamically with which path
1262 # KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
1263 # (KSirc sucks anyway ;)
1264 IRC_CLIENT_VERSION=" $( ksirc -v | gawk '
1273 if [[ -z $IRC_CLIENT_VERSION ]];then
1274 IRC_CLIENT="Unknown Perl client"
1278 unset IRC_CLIENT_VERSION
1279 IRC_CLIENT="Shell wrapper"
1282 IRC_CLIENT="Unknown : ${irc_client_path##*/}"
1283 unset IRC_CLIENT_VERSION
1286 if [[ $SHOW_IRC -lt 2 ]];then
1287 unset IRC_CLIENT_VERSION
1290 IRC_CLIENT="PPID=\"$PPID\" - empty?"
1291 unset IRC_CLIENT_VERSION
1295 # Parse the null separated commandline under /proc/<pid passed in $1>/cmdline
1301 if [[ ! -e /proc/$ppid/cmdline ]];then
1305 ##print_screen_output "Marker"
1306 ##print_screen_output "\$ppid='$ppid' -=- $(< /proc/$ppid/cmdline)"
1308 ## note: need to figure this one out, and ideally clean it up and make it readable
1309 while read -d $'\0' L && [[ $i -lt 32 ]]
1311 A_CMDL[i++]="$L" ## note: make sure this is valid - What does L mean? ##
1312 done < /proc/$ppid/cmdline
1313 ##print_screen_output "\$i='$i'"
1314 if [[ $i -eq 0 ]];then
1315 A_CMDL[0]=$(< /proc/$ppid/cmdline)
1316 if [[ -n ${A_CMDL[0]} ]];then
1323 #### -------------------------------------------------------------------
1325 #### -------------------------------------------------------------------
1326 ## create array of sound cards installed on system, and if found, use asound data as well
1329 local i='' alsa_data='' alsa_driver='' device_count=''
1330 local usb_proc_file='' array_count='' usb_id='' usb_data=''
1333 # this first step handles the drivers for cases where the second step fails to find one
1334 device_count=$( echo "$Lspci_Data" | egrep -ic '(multimedia audio controller|audio device)' )
1335 if [[ $device_count -eq 1 ]] && [[ $B_ASOUND_CARDS == 'true' ]];then
1336 alsa_driver=$( gawk -F ']: ' '
1340 # filtering out modems and usb devices like webcams, this might get a
1341 # usb audio card as well, this will take some trial and error
1342 $0 !~ /modem/ || $0 !~ /usb/ {
1343 driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
1344 gsub(/^ +| +$/,"",driver)
1345 if ( driver != "" ){
1348 }' $DIR_ASOUND_DEVICE )
1351 # this is to safeguard against line breaks from results > 1, which if inserted into following
1352 # array will create a false array entry. This is a hack, not a permanent solution.
1353 alsa_driver=$( echo $alsa_driver )
1354 # now we'll build the main audio data, card name, driver, and port. If no driver is found,
1355 # and if the first method above is not null, and one card is found, it will use that instead.
1356 A_AUDIO_DATA=( $( echo "$Lspci_Data" | gawk -F ': ' -v alsaDriver="$alsa_driver" '
1360 /multimedia audio controller|audio device/ {
1361 audioCard=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
1362 # The doublequotes are necessary because of the pipes in the variable.
1363 gsub(/'"$BAN_LIST_NORMAL"'/, "", audioCard)
1364 gsub(/,/, " ", audioCard)
1365 gsub(/^ +| +$/, "", audioCard)
1366 gsub(/ [ \t]+/, " ", audioCard)
1370 # loop until you get to the end of the data block
1371 while (getline && !/^$/) {
1372 if (/driver in use/) {
1373 drivers[audioCard] = drivers[audioCard] gensub(/(.*): (.*)/,"\\2","g",$0) ""
1375 else if (/kernel modules:/) {
1376 modules[audioCard] = modules[audioCard] gensub(/(.*): (.*)/,"\\2","g",$0) ""
1379 portsTemp = gensub(/\t*I\/O ports at (.*) \[.*\]/,"\\1","g",$0)
1380 ports[audioCard] = ports[audioCard] portsTemp " "
1393 if (drivers[i] != "") {
1394 useDrivers=drivers[i]
1396 if (ports[i] != "") {
1399 if (modules[i] != "" ) {
1400 useModules = modules[i]
1405 # little trick here to try to catch the driver if there is
1406 # only one card and it was null, from the first test of asound/cards
1407 if (drivers[i] != "") {
1408 useDrivers=drivers[i]
1410 else if ( alsaDriver != "" ) {
1411 useDrivers=alsaDriver
1413 if (ports[i] != "") {
1416 if (modules[i] != "" ) {
1417 useModules = modules[i]
1420 # create array primary item for master array
1421 print a[j] "," useDrivers "," usePorts "," useModules
1426 # in case of failure of first check do this instead
1427 if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]] && [[ $B_ASOUND_CARDS == 'true' ]];then
1428 A_AUDIO_DATA=( $( gawk -F ']: ' '
1432 $1 !~ /modem/ && $2 !~ /modem/ {
1433 card=gensub( /^(.+)( - )(.+)$/, "\\3", 1, $2 )
1434 driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
1438 }' $DIR_ASOUND_DEVICE ) )
1441 # alsa usb detection by damentz
1442 # for every sound card symlink in /proc/asound - display information about it
1443 for usb_proc_file in /proc/asound/*
1445 # if lsusb exists, the file is a symlink, and contains an important usb exclusive file: continue
1446 if [[ -n $( which lsusb ) && -L $usb_proc_file && -e $usb_proc_file/usbid ]]; then
1447 # send error messages of lsusb to /dev/null as it will display a bunch if not a super user
1448 # also, find the contents of usbid in lsusb and print everything after the 7th word on the
1449 # corresponding line. Finally, strip out commas as they will change the driver :)
1450 usb_id=$( cat $usb_proc_file/usbid )
1451 usb_data=$( lsusb -v 2>/dev/null | grep "$usb_id" )
1453 gsub( /,/, " ", $0 )
1454 for( i=7; i <= NF; i++ ) {
1457 }' <<< "$usb_data" )
1458 # this method is interesting, it shouldn't work but it does
1459 #A_AUDIO_DATA=( "${A_AUDIO_DATA[@]}" "$usb_data,snd-usb-audio,," )
1460 # but until we learn why the above worked, I'm using this one, which is safer
1461 if [[ -n $usb_data ]];then
1462 array_count=${#A_AUDIO_DATA[@]}
1463 A_AUDIO_DATA[$array_count]="$usb_data,snd-usb-audio,,"
1469 # handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
1470 if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]];then
1471 A_AUDIO_DATA[0]='Failed to Detect Sound Card!'
1475 get_audio_alsa_data()
1479 # now we'll get the alsa data if the file exists
1480 if [[ $B_ASOUND_VERSION == 'true' ]];then
1485 # some alsa strings have the build date in (...)
1486 # remove trailing . and remove possible second line if compiled by user
1488 gsub( "Driver | [(].*[)]|\.$","",$0 )
1490 gsub(/^ +| +$/, "", $0)
1491 gsub(/ [ \t]+/, " ", $0)
1495 }' $DIR_ASOUND_VERSION )
1500 ## create A_CPU_CORE_DATA, currently with two values: integer core count; core string text
1501 ## return value cpu core count string, this helps resolve the multi redundant lines of old style output
1502 get_cpu_core_count()
1504 if [[ $B_CPUINFO == 'true' ]]; then
1505 # load the A_CPU_TYPE_PCNT_CCNT core data array
1506 get_cpu_ht_multicore_smp_data
1507 ## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10)
1508 # count the number of processors given
1509 local cpu_physical_count=${A_CPU_TYPE_PCNT_CCNT[1]}
1510 local cpu_core_count=${A_CPU_TYPE_PCNT_CCNT[2]}
1511 local cpu_type=${A_CPU_TYPE_PCNT_CCNT[0]}
1513 # match the numberic value to an alpha value
1514 case $cpu_core_count in
1515 1) cpu_alpha_count='Single';;
1516 2) cpu_alpha_count='Dual';;
1517 3) cpu_alpha_count='Triple';;
1518 4) cpu_alpha_count='Quad';;
1519 5) cpu_alpha_count='Penta';;
1520 6) cpu_alpha_count='Hexa';;
1521 7) cpu_alpha_count='Hepta';;
1522 8) cpu_alpha_count='Octa';;
1523 9) cpu_alpha_count='Ennea';;
1524 10) cpu_alpha_count='Deca';;
1525 *) cpu_alpha_count='Multi';;
1527 # create array, core count integer; core count string
1528 # A_CPU_CORE_DATA=( "$cpu_core_count" "$cpu_alpha_count Core$cpu_type" )
1529 A_CPU_CORE_DATA=( "$cpu_physical_count" "$cpu_alpha_count" "$cpu_type" "$cpu_core_count" )
1533 ## main cpu data collector
1536 local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits=''
1538 if [[ $B_CPUINFO == 'true' ]];then
1540 A_CPU_DATA=( $( gawk -F': ' '
1544 # TAKE STRONGER NOTE: \t+ does NOT always work, MUST be [ \t]+
1545 # TAKE NOTE: \t+ will work for $DIR_CPUINFO, but SOME ARBITRARY FILE used for TESTING might contain SPACES!
1546 # Therefore PATCH to use [ \t]+ when TESTING!
1547 /^processor[ \t]+:/ {
1551 /^model name|^cpu\t+:/ {
1552 gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
1553 gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
1555 gsub(/^ +| +$/, "", $NF)
1556 gsub(/ [ \t]+/, " ", $NF)
1557 cpu[nr, "model"] = $NF
1560 /^cpu MHz|^clock\t+:/ {
1573 gsub(/MHZ/,"",$NF) ## clears out for cell cpu
1574 gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros
1575 cpu[nr, "speed"] = $NF
1579 cpu[nr, "cache"] = $NF
1583 cpu[nr, "flags"] = $NF
1587 cpu[nr, "bogomips"] = $NF
1591 gsub(/genuine|authentic/,"",$NF)
1592 cpu[nr, "vendor"] = tolower( $NF )
1596 #if (!nr) { print ",,,"; exit } # <- should this be necessary or should bash handle that
1597 for ( i = 0; i <= nr; i++ ) {
1598 print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] "," cpu[nr, "vendor"]
1605 printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz")
1608 printf("%s %s\n", max, "Mhz")
1614 # echo getMainCpu: ${[@]}
1617 ## this is for counting processors and finding HT types
1618 get_cpu_ht_multicore_smp_data()
1621 # if > 1 processor && processor id == core id then Hyperthreaded (HT)
1622 # if > 1 processor && different processor ids then Multiple Processors (SMP)
1623 # if > 1 processor && processor id != core id then Multi-Core Processors (MCP)
1624 # if = 1 processor then single core/processor Uni-Processor (UP)
1626 if [[ $B_CPUINFO == 'true' ]]; then
1627 A_CPU_TYPE_PCNT_CCNT=( $(
1636 physical_cpu_count = 0
1637 processor_logical_count = 0
1641 # counts logical processors, both HT and physical
1643 processor_logical_count = $NF + 1
1645 # counts physical cores (not used currently)
1649 # array of physical cpus ids
1651 a_physical_id[i] = $NF
1659 # look for the largest id number, and assign it
1660 for ( j = 0; j < processor_logical_count; j++ ) {
1661 if ( a_core_id[j] > core_count ) {
1662 core_count = a_core_id[j]
1665 core_count = core_count + 1
1666 # trick, set the index equal to value, if the same, it will overwrite
1667 # this lets us create the actual array of true cpu physical ids
1668 for ( j in a_physical_id ) {
1669 index_temp = a_physical_id[j]
1670 a_cpu_physical_working[index_temp] = a_physical_id[j]
1672 # note that length() is a gawk >= 3.1.5 only method, better to do it manually
1673 for ( j in a_cpu_physical_working ) {
1674 ++physical_cpu_count
1677 # looking at logical processor counts over 1, which means either HT, SMP or MCP
1678 # http://en.wikipedia.org/wiki/Symmetric_multiprocessing
1679 if ( processor_logical_count > 1 ) {
1680 if ( processor_logical_count > core_count && physical_cpu_count > 1 ) {
1681 type = "SMP-HT" # could be Xeon/P4 HT dual cpu
1683 else if ( processor_logical_count > core_count ) {
1684 type = "HT" # this is more than likely a P4 w/HT or an Atom 270
1690 # make sure to handle up cpus too
1693 physical_cpu_count = 1
1695 print type " " physical_cpu_count " " core_count
1702 # for more on distro id, please reference this python thread: http://bugs.python.org/issue1322
1703 ## return distro name/id if found
1706 local i='' j='' distro='' distro_file='' a_distro_glob=''
1708 # get the wild carded array of release/version /etc files if present
1711 a_distro_glob=(*[-_]{release,version})
1715 if [[ ${#a_distro_glob[@]} -eq 1 ]];then
1716 distro_file="${a_distro_glob}"
1717 # use the file if it's in the known good lists
1718 elif [[ ${#a_distro_glob[@]} -gt 1 ]];then
1719 for i in $DISTROS_DERIVED $DISTROS_PRIMARY
1721 # Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
1722 # This is a known bug, search for the word "strange" inside comments
1723 # echo "i='$i' a_distro_glob[@]='${a_distro_glob[@]}'"
1724 if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then
1725 # Now lets see if the distro file is in the known-good working-lsb-list
1726 # if so, use lsb-release, if not, then just use the found file
1727 # this is for only those distro's with self named release/version files
1728 # because Mint does not use such, it must be done as below
1729 ## this if statement requires the spaces and * as it is, else it won't work
1731 if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_DIR == 'true' ]];then
1732 distro_file='lsb-release'
1741 # first test for the legacy antiX distro id file
1742 if [[ -e /etc/antiX ]];then
1743 distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )"
1744 # this handles case where only one release/version file was found, and it's lsb-release. This would
1745 # never apply for ubuntu or debian, which will filter down to the following conditions. In general
1746 # if there's a specific distro release file available, that's to be preferred, but this is a good backup.
1747 elif [[ $distro_file == 'lsb-release' ]];then
1748 distro=$( get_distro_lsb_data )
1749 # then if the distro id file was found and it's not in the exluded primary distro file list, read it
1750 elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
1751 distro=$( remove_erroneous_chars "/etc/$distro_file" )
1752 # otherwise try the default debian/ubuntu /etc/issue file
1753 elif [[ -f /etc/issue ]];then
1754 # lsb gives more manageable and accurate output than issue, but mint should use issue for now
1755 # some bashism, boolean must be in parenthesis to work correctly, ie [[ $(boolean) ]] not [[ $boolean ]]
1756 if [[ $B_LSB_DIR == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then
1757 distro=$( get_distro_lsb_data )
1767 gsub(/ [ \t]+/, " ")
1773 if [[ ${#distro} -gt 80 ]] && [[ $B_HANDLE_CORRUPT_DATA != 'true' ]];then
1774 distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}"
1776 ## note: would like to actually understand the method even if it's not used
1777 # : ${distro:=Unknown distro o_O}
1778 ## test for /etc/lsb-release as a backup in case of failure, in cases where > one version/release file
1779 ## were found but the above resulted in null distro value
1780 if [[ -z $distro ]] && [[ $B_LSB_DIR == 'true' ]];then
1781 distro=$( get_distro_lsb_data )
1783 ## finally, if all else has failed, give up
1784 if [[ -z $distro ]];then
1785 distro='Unknown distro o_O'
1788 # this handles an arch bug where /etc/arch-release is empty and /etc/issue is corrupted
1789 if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
1796 # args: $1 - optional, app, uses the app test, not being used now
1797 get_distro_lsb_data()
1801 if [[ $B_LSB_DIR == 'true' ]] && [[ $1 != 'app' ]];then
1802 distro=$( gawk -F '=' '
1806 # note: adding the spacing directly to variable to make sure distro output is null if not found
1808 gsub(/^ +| +$/, "", $NF)
1809 # this is needed because grep for "arch" is too loose to be safe
1810 if ( $NF == "arch" ) {
1811 distroId = "Arch Linux"
1813 else if ( $NF != "n/a" ) {
1817 /^DISTRIB_RELEASE/ {
1818 gsub(/^ +| +$/, "", $NF)
1819 if ( $NF != "n/a" ) {
1820 distroRelease = $NF " "
1823 /^DISTRIB_CODENAME/ {
1824 gsub(/^ +| +$/, "", $NF)
1825 if ( $NF != "n/a" ) {
1826 distroCodename = $NF " "
1830 print distroId distroRelease distroCodename
1831 }' $DIR_LSB_RELEASE )
1833 # this is HORRIBLY slow, but I don't know why, it runs fast in shell
1834 # if [[ -n $( which lsb_release ) && $1 == 'app' ]];then
1835 # distro=$( echo "$( lsb_release -irc )" | gawk '
1837 # /^Distributor ID/ {
1838 # gsub(/^ +| +$/, "", $NF)
1842 # gsub(/^ +| +$/, "", $NF)
1843 # distroRelease = $NF
1846 # gsub(/^ +| +$/, "", $NF)
1847 # distroCodename = $NF
1850 # print distroId " " distroRelease " (" distroCodename ")"
1857 ## create array of gfx cards installed on system
1858 get_graphics_card_data()
1863 A_GFX_CARD_DATA=( $( echo "$Lspci_Data" | gawk -F': ' '
1867 /vga compatible controller/ {
1868 gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
1870 gsub(/^ +| +$/, "", $NF)
1871 gsub(/ [ \t]+/, " ", $NF)
1875 # for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
1877 # A_GFX_CARD_DATA[i]=$( sanitize_characters BAN_LIST_NORMAL "${A_GFX_CARD_DATA[i]}" )
1879 # handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
1880 if [[ ${#A_GFX_CARD_DATA[@]} -eq 0 ]];then
1881 A_GFX_CARD_DATA[0]='Failed to Detect Video Card!'
1884 # GFXMEM is UNUSED at the moment, because it shows AGP aperture size, which is not necessarily equal to GFX memory..
1885 # GFXMEM="size=[$(echo "$Lspci_Data" | gawk '/VGA/{while (!/^$/) {getline;if (/size=[0-9][0-9]*M/) {size2=gensub(/.*\[size=([0-9]+)M\].*/,"\\1","g",$0);if (size<size2){size=size2}}}}END{print size2}')M]"
1888 ## create array of glx data
1889 get_graphics_glx_data()
1891 if [[ $B_X_RUNNING == 'true' ]];then
1893 # A_GLX_DATA=( $( glxinfo | gawk -F ': ' '
1894 # A_GLX_DATA=( $( cat ../../modules/data/glxinfo-atom-1r | gawk -F ': ' '
1895 # A_GLX_DATA=( $( cat ../../modules/data/glxinfo-intel-sput | gawk -F ': ' '
1896 # there are arch bugs that make glxinfo generate bad output errors
1897 # A_GLX_DATA=( $( glxinfo | gawk -F ': ' '
1898 # A_GLX_DATA=( $( cat ../../modules/data/glxinfo-bad-rendering | gawk -F ': ' '
1899 A_GLX_DATA=( $( glxinfo | gawk -F ': ' '
1900 # note: function declarations go before BEGIN? It appears so, confirm.
1901 # the real question here though is why this function is even here, seems
1902 # just to be a complicated way to pack/print a variable, but maybe the
1903 # original idea was to handle > 1 cases of detections I guess
1904 function join( arr, sep ) {
1920 if ( $2 ~ /mesa/ ) {
1922 # if ( $2 ~ / r[3-9][0-9][0-9] / ) {
1923 gsub(/'"$BAN_LIST_NORMAL"'/, "", $2)
1925 # this counter failed in one case, a bug, and is not needed now
1932 # dropping all conditions from this test to just show full mesa information
1933 # there is a user case where not f and mesa apply, atom mobo
1934 # /opengl version/ && ( f || $2 !~ /mesa/ ) {
1938 /direct rendering/ {
1942 printf( "%s\n%s\n%s\n", join( a, ", " ), join( b, ", " ), join( c, ", " ) )
1946 # GLXR=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl renderer/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
1947 # GLXV=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl version/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
1951 ## return screen resolution / tty resolution
1952 get_graphics_res_data()
1954 local screen_resolution=''
1956 if [[ $B_X_RUNNING == 'true' ]];then
1957 # Added the two ?'s , because the resolution is now reported without spaces around the 'x', as in
1958 # 1400x1050 instead of 1400 x 1050. Change as of X.org version 1.3.0
1959 screen_resolution=$( xrandr | gawk '
1961 res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0)
1965 if (res[n] ~ /^[[:digit:]]+x[[:digit:]]+/) {
1966 line = line ? line ", " res[n] : res[n]
1973 if [[ -z $screen_resolution ]];then
1974 screen_resolution=$( xdpyinfo | gawk '
1980 screen_resolution=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{ print $2"x"$1 }' )
1982 echo "$screen_resolution"
1985 ## for possible future data, not currently used
1986 get_graphics_agp_data()
1990 if [[ B_MODULES_DIR == 'true' ]];then
1991 ## not used currently
1992 agp_module=$( gawk '
1993 /agp/ && !/agpgart/ && $3 > 0 {
1994 print(gensub(/(.*)_agp.*/,"\\1","g",$1))
1999 ## create array of x vendor/version data
2000 get_graphics_x_data()
2002 local x_vendor='' x_version=''
2004 if [[ $B_X_RUNNING == 'true' ]];then
2005 # X vendor and version detection.
2006 x_vendor=$( xdpyinfo | gawk -F': +' '
2011 gsub(/the|inc|foundation|project|corporation/, "", $2)
2013 gsub(/^ +| +$/, "", $2)
2014 gsub(/ [ \t]+/, " ", $2)
2018 # new method added since radeon and X.org and the disappearance of <X server name> version : ...etc
2019 # Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2
2020 # A failover mechanism is in place. (if $x_version is empty, the release number is parsed instead)
2021 x_version=$( xdpyinfo | gawk '/version:/ { print $NF }' )
2022 if [[ -z $x_version ]];then
2023 x_version=$(xdpyinfo | gawk -F': +' '
2027 /vendor release number/ {
2033 A_X_DATA[0]="$x_vendor"
2034 A_X_DATA[1]="$x_version"
2036 #X -version 2>&1 | gawk '/^X Window System Version/ { print $5 }'
2037 #This method could be used in the future to detect X when X is not running,
2038 #however currently inxi ignores X checks when X is not found.
2042 # this gets just the raw data, total space/percent used and disk/name/per disk capacity
2043 get_hdd_data_basic()
2047 hdd_used=$( df --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk '
2048 # also handles odd dm-1 type, from lvm
2049 /^\/dev\/(mapper\/|[hs]d[a-z][0-9]+|dm[-]?[0-9]+)/ {
2050 # this handles the case where the first item is too long
2051 # and makes df wrap output to next line, so here we advance
2052 # it to the next line for that single case
2053 if ( NF < 5 && $0 !~ /.*\%/ ) {
2056 # if the first item caused a wrap, use one less than standard
2057 # testing for the field with % in it, ie: 34%, then go down from there
2058 # this also protects against cases where the mount point has a space in the
2059 # file name, thus breaking going down from $NF directly.
2060 if ( $4 ~ /.*\%/ ) {
2063 # otherwise use standard
2064 else if ( $5 ~ /.*\%/ ) {
2067 # and if this is not detected, give up, we need user data to debug
2076 if [[ -z $hdd_used ]];then
2080 # create the initial array strings:
2081 # disk-dev, capacity, name, usb or not
2082 # final item is the total of the disk
2085 if [[ $B_PARTITIONS_DIR == 'true' ]];then
2087 gawk -v hddused="$hdd_used" '
2089 driveSize = $(NF - 1)*1024/1000**3
2090 gsub(/,/, " ", driveSize)
2091 gsub(/^ +| +$/, "", driveSize)
2092 printf( $NF",%.1fGB,,\n", driveSize )
2094 # See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
2095 # $1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {
2098 # special case from this data: 8 0 156290904 sda
2099 $1 ~ /^(3|22|33|8)$/ && $NF ~ /[hs]d[a-z]$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) {
2104 size = size*1024/1000**3 # calculate size in GB size
2105 workingUsed = hddused*1024/1000**3 # calculate workingUsed in GB used
2106 # this handles a special case with livecds where no hdd_used is detected
2107 if ( size > 0 && hddused == "na" ) {
2108 size = sprintf( "%.1f", size )
2111 else if ( size > 0 && workingUsed > 0 ) {
2112 diskUsed = workingUsed*100/size # calculate used percentage
2113 diskUsed = sprintf( "%.1f", diskUsed )
2114 size = sprintf( "%.1f", size )
2115 print size "GB," diskUsed "% used"
2118 print "NA,-" # print an empty array, this will be further handled in the print out function
2126 ## fills out the A_HDD_DATA array with disk names
2127 get_hard_drive_data_advanced()
2129 local a_temp_working='' a_temp_scsi='' temp_holder='' temp_name='' i='' j=''
2130 local sd_ls_by_id='' ls_disk_by_id=''
2132 ## check for all ide type drives, non libata, only do it if hdx is in array
2133 if [[ -n $( egrep 'hd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
2134 # remember, we're using the last array item to store the total size of disks
2135 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
2138 a_temp_working=( ${A_HDD_DATA[i]} )
2140 if [[ -n $( egrep '^hd[a-z]' <<< ${a_temp_working[0]} ) ]];then
2141 if [[ -e /proc/ide/${a_temp_working[0]}/model ]];then
2142 a_temp_working[2]="$( remove_erroneous_chars /proc/ide/${a_temp_working[0]}/model )"
2144 a_temp_working[2]="Name n/a"
2146 # these loops are to easily extend the cpu array created in the awk script above with more fields per cpu.
2147 for (( j=0; j < ${#a_temp_working[@]}; j++ ))
2149 if [[ $j -gt 0 ]];then
2150 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2152 A_HDD_DATA[i]="${a_temp_working[$j]}"
2159 ## then handle libata names
2160 # first get the ata device names, put them into an array
2162 if [[ $B_SCSI_DIR == 'true' ]]; then
2163 a_temp_scsi=( $( gawk '
2173 if (b[i] ~ / *type: *direct-access.*/) {
2174 #c=gensub(/^ *vendor: (.+) +model: (.+) +rev: (.+)$/,"\\1 \\2 \\3","g",a[i])
2175 #c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i] )
2176 # the vendor: string is useless, and is a bug, ATA is not a vendor for example
2177 c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/, "\\2", "g", a[i] )
2179 gsub(/^ +| +$/, "", c)
2180 gsub(/ [ \t]+/, " ", c)
2182 # we actually want this data, so leaving this off for now
2183 # if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) {
2193 ## then we'll loop through that array looking for matches.
2194 if [[ -n $( egrep 'sd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
2195 # first pack the main ls variable so we don't have to keep using ls /dev...
2196 ls_disk_by_id="$( ls -l /dev/disk/by-id )"
2197 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
2199 if [[ -n $( egrep '^sd[a-z]' <<< ${A_HDD_DATA[$i]} ) ]];then
2201 a_temp_working=( ${A_HDD_DATA[$i]} )
2203 if [[ ${#a_temp_scsi[@]} -gt 0 ]];then
2204 for (( j=0; j < ${#a_temp_scsi[@]}; j++ ))
2206 ## ok, ok, it's incomprehensible, search /dev/disk/by-id for a line that contains the
2207 # discovered disk name AND ends with the correct identifier, sdx
2208 # get rid of whitespace for some drive names and ids, and extra data after - in name
2209 temp_name=$( tr ' ' '_' <<< ${a_temp_scsi[$j]} | cut -d '-' -f 1 )
2210 sd_ls_by_id=$( egrep -m1 ".*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" )
2212 if [[ -n $sd_ls_by_id ]];then
2213 a_temp_working[2]=${a_temp_scsi[$j]}
2214 if [[ -n $( grep 'usb-' <<< $sd_ls_by_id ) ]];then
2215 a_temp_working[3]='USB'
2219 a_temp_working[2]="Name n/a"
2223 a_temp_working[2]="Name n/a"
2226 # these loops are to easily extend the cpu array created in the awk script above with more fields per cpu.
2227 for (( j=0; j < ${#a_temp_working[@]}; j++ ))
2229 if [[ $j -gt 0 ]];then
2230 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2232 A_HDD_DATA[i]="${a_temp_working[$j]}"
2237 unset ls_disk_by_id # and then let's dump the data we don't need
2243 echo "$( lspci -v | gawk '{
2244 gsub(/\(prog-if[^)]*\)/,"")
2249 ## return memory used/installed
2258 /^(MemFree|Buffers|Cached):/ {
2263 printf("%.1f/%.1fMB\n", used/1024, tot/1024)
2269 # process and return module version data
2270 get_module_version_number()
2272 local module_version=''
2274 if [[ -n $( which modinfo ) ]];then
2275 module_version=$( modinfo $1 | gawk '
2281 gsub(/^ +| +$/, "", $2)
2282 gsub(/ [ \t]+/, " ", $2)
2288 echo "$module_version"
2291 ## create array of network cards
2292 get_networking_data()
2295 A_NETWORK_DATA=( $( echo "$Lspci_Data" | gawk '
2299 /^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
2300 nic=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
2301 gsub(/realtek semiconductor/, "Realtek", nic)
2302 gsub(/davicom semiconductor/, "Davicom", nic)
2303 # The doublequotes are necessary because of the pipes in the variable.
2304 gsub(/'"$BAN_LIST_NORMAL"'/, "", nic)
2306 gsub(/^ +| +$/, "", nic)
2307 gsub(/ [ \t]+/, " ", nic)
2310 while (getline && !/^$/) {
2312 ports[nic] = ports[nic] $4 " "
2314 if (/driver in use/) {
2315 drivers[nic] = drivers[nic] gensub(/(.*): (.*)/,"\\2","g",$0) ""
2317 else if (/kernel modules/) {
2318 modules[nic] = modules[nic] gensub(/(.*): (.*)/,"\\2","g",$0) ""
2331 ## note: this loses the plural ports case, is it needed anyway?
2332 if (ports[i] != "") {
2335 if (drivers[i] != "") {
2336 useDrivers=drivers[i]
2338 if (modules[i] != "" ) {
2339 useModules = modules[i]
2344 if (ports[i] != "") {
2347 if (drivers[i] != "") {
2348 useDrivers=drivers[i]
2350 if (modules[i] != "" ) {
2351 useModules = modules[i]
2354 # create array primary item for master array
2355 print a[j] "," useDrivers "," usePorts "," useModules
2362 get_networking_wan_ip_data()
2366 # get ip using wget redirect to stdout. This is a clean, text only IP output url.
2367 ip=$( wget -q -O - http://smxi.org/opt/ip.php | awk -F 'is: ' '{
2372 if [[ -z $ip ]];then
2378 get_networking_local_ip_data()
2380 if [[ $B_IFCONFIG == 'true' ]];then
2382 A_INTERFACES_DATA=( $( $DIR_IFCONFIG | gawk '
2387 # not clear on why inet is coming through, but this gets rid of it
2388 # as first line item.
2390 gsub(/,/, " ", interface)
2391 gsub(/^ +| +$/, "", interface)
2392 gsub(/ [ \t]+/, " ", interface)
2394 aInterfaces[interface]++
2395 while (getline && !/^$/) {
2397 ipAddresses[interface] = gensub( /addr:([0-9\.]+)/, "\\1", "g", $2 )
2404 for (i in aInterfaces) {
2407 if (ipAddresses[i] != "") {
2408 useInterfaceIp = ipAddresses[i]
2410 # create array primary item for master array
2411 # tested needed to avoid bad data from above, if null it is garbage
2412 # this is the easiest way to handle junk I found, improve if you want
2413 if ( useInterfaceIp != "" ) {
2414 print a[j] "," useInterfaceIp
2423 get_partition_data()
2425 #local excluded_file_types='--exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660'
2426 # df doesn't seem to work in script with variables like at the command line
2429 # sample line: /dev/sda2 ext3 15G 8.9G 4.9G 65% /home
2430 # $NF = partition name; $(NF - 4) = partition size; $(NF - 3) = used, in gB; $(NF - 1) = percent used
2431 ## note: by subtracting from the last field number NF, we avoid a subtle issue with LVM df output, where if
2432 ## the first field is too long, it will occupy its own line, this way we are getting only the needed data
2433 A_PARTITION_DATA=( $( df -h -T --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk '
2437 # this has to be nulled for every iteration so it does not retain value from last iteration
2439 # this is required because below we are subtracting from NF, so it has to be > 4
2440 # the real issue is long file system names that force the wrap of df output: //fileserver/main
2441 # but we still need to handle more dynamically long space containing file names, but later.
2442 ( NF < 5 ) && ( $0 !~ /[0-9]+\%/ ) {
2443 # set the dev location here for cases of wrapped output
2445 devBase=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
2449 # this handles yet another fredforfaen special case where a mounted drive
2450 # has the search string in its name
2451 $NF ~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$/ {
2452 print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main," devBase
2454 # skip all these, including the first, header line. Use the --exclude-type
2455 # to handle new filesystems types we do not want listed here
2456 $NF !~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$|^filesystem/ {
2457 # this is to avoid file systems with spaces in their names, that will make
2458 # the test show the wrong data in each of the fields, if no x%, then do not use
2459 # using 3 cases, first default, standard, 2nd, 3rd, handles one and two spaces in name
2460 if ( $(NF - 1) ~ /[0-9]+\%/ ) {
2461 print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",secondary," devBase
2463 # these two cases construct the space containing name
2464 else if ( $(NF - 2) ~ /[0-9]+\%/ ) {
2465 print $(NF - 1) " " $NF "," $(NF - 5) "," $(NF - 4) "," $(NF - 2) ",secondary," devBase
2467 else if ( $(NF - 3) ~ /[0-9]+\%/ ) {
2468 print $(NF - 2) " " $(NF - 1) " " $NF "," $(NF - 6) "," $(NF - 5) "," $(NF - 3) ",secondary," devBase
2472 # now add the swap partition data, don't want to show swap files, just partitions,
2473 # though this can include /dev/ramzswap0. Note: you can also use /proc/swaps for this
2474 # data, it's the same exact output as swapon -s
2475 $( swapon -s | gawk '
2480 size = sprintf( "%.2f", $3*1024/1000**3 )
2481 devBase = gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
2482 used = sprintf( "%.2f", $4*1024/1000**3 )
2483 percentUsed = sprintf( "%.0f", ( $4/$3 )*100 )
2484 print "swap-" swapCounter "," size "GB," used "GB," percentUsed "\%,main," devBase
2485 swapCounter = ++swapCounter
2489 if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
2490 get_partition_data_advanced
2494 # first get the locations of the mount points for label/uuid detection
2495 get_partition_data_advanced()
2497 local a_partition_working='' dev_partition_data=''
2498 local dev_disk_label='' dev_disk_uuid='' dev_item='' dev_label='' dev_uuid=''
2499 local mount_point=''
2501 if [[ -d /dev/disk/by-label ]];then
2502 dev_disk_label="$( ls -l /dev/disk/by-label )"
2504 if [[ -d /dev/disk/by-uuid ]];then
2505 dev_disk_uuid="$( ls -l /dev/disk/by-uuid )"
2508 if [[ $B_MOUNTS_DIR == 'true' ]];then
2509 for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
2512 a_partition_working=( ${A_PARTITION_DATA[i]} )
2514 # note: for swap this will already be set
2515 if [[ -z ${a_partition_working[5]} ]];then
2516 mount_point=$( sed 's|/|\\/|g' <<< ${a_partition_working[0]} )
2517 #echo mount_point $mount_point
2518 dev_partition_data=$( gawk '
2524 # trying to handle space in name
2525 # gsub( /\\040/, " ", $0 )
2526 /[ \t]'$mount_point'[ \t]/ && $1 != "rootfs" {
2527 # initialize the variables
2531 # slice out the /dev
2532 partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
2533 # label and uuid can occur for root, set partition to null now
2534 if ( partition ~ /by-label/ ) {
2535 label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, $1 )
2538 if ( partition ~ /by-uuid/ ) {
2539 uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, $1 )
2543 # handle /dev/root for / id
2544 if ( partition == "root" ) {
2545 # if this works, great, otherwise, just set this to null values
2546 partTemp="'$( readlink /dev/root 2>/dev/null )'"
2547 if ( partTemp != "" ) {
2548 if ( partTemp ~ /[hs]d[a-z][0-9]/ ) {
2549 partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, partTemp )
2551 else if ( partTemp ~ /by-uuid/ ) {
2552 uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, partTemp )
2553 partition="" # set null to let real location get discovered
2555 else if ( partTemp ~ /by-label/ ) {
2556 label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, partTemp )
2557 partition="" # set null to let real location get discovered
2566 print partition "," label "," uuid
2569 # echo dev_partition_data: $dev_partition_data
2570 # assemble everything we could get for dev/h/dx, label, and uuid
2572 A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","$dev_partition_data
2575 ## now we're ready to proceed filling in the data
2577 a_partition_working=( ${A_PARTITION_DATA[i]} )
2580 dev_item=${a_partition_working[5]}
2581 dev_label=${a_partition_working[6]}
2582 dev_uuid=${a_partition_working[7]}
2584 # then if dev data/uuid is incomplete, try to get missing piece
2585 # it's more likely we'll get a uuid than a label. But this should get the
2586 # dev item set no matter what, so then we can get the rest of any missing data
2587 # first we'll get the dev_item if it's missing
2588 if [[ -n $dev_disk_uuid ]] && [[ -z $dev_item && -n $dev_uuid ]];then
2589 dev_item=$( echo "$dev_disk_uuid" | gawk '
2591 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
2594 elif [[ -n $dev_disk_label ]] && [[ -z $dev_item && -n $dev_label ]];then
2595 dev_item=$( echo "$dev_disk_label" | gawk '
2596 # first we need to change space x20 in by-label back to a real space
2597 #gsub( /x20/, " ", $0 )
2598 # then we can see if the string is there
2600 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
2604 if [[ -n $dev_disk_uuid ]] && [[ -n $dev_item && -z $dev_uuid ]];then
2605 dev_uuid=$( echo "$dev_disk_uuid" | gawk '
2610 if [[ -n $dev_disk_label ]] && [[ -n $dev_item && -z $dev_label ]];then
2611 dev_label=$( echo "$dev_disk_label" | gawk '
2617 # assemble everything we could get for dev/h/dx, label, and uuid
2619 A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","$dev_item","$dev_label","$dev_uuid
2625 ## return uptime string
2628 ## note: removing gsub(/ /,"",a); to get get space back in there, goes right before print a
2629 echo $( uptime | gawk '{
2630 a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0)
2635 #### -------------------------------------------------------------------
2636 #### special data handling for specific options and conditions
2637 #### -------------------------------------------------------------------
2639 ## multiply the core count by the data to be calculated, bmips, cache
2640 # args: $1 - string to handle; $2 - cpu count
2641 calculate_multicore_data()
2643 local string_number=$1 string_data=''
2645 if [[ -n $( egrep -i '( mb| kb)' <<< $1 ) ]];then
2646 string_data=" $( gawk '{print $2}' <<< $1 )" # add a space for output
2647 string_number=$( gawk '{print $1}' <<< $1 )
2649 # handle weird error cases where it's not a number
2650 if [[ -n $( egrep '^[0-9\.,]+$' <<< $string_number ) ]];then
2651 string_number=$( echo $string_number $2 | gawk '{
2655 elif [[ $string_number == '' ]];then
2656 string_number='Not Available'
2658 # I believe that the above returns 'unknown' by default so no need for extra text
2659 string_number="$string_number "
2661 echo "$string_number$string_data"
2664 # prints out shortened list of flags, the main ones of interest
2665 # args: $1 - string of cpu flags to process
2668 local cpu_flags="$1"
2670 # nx = AMD stack protection extensions
2671 # lm = Intel 64bit extensions
2672 # sse, sse2, pni = sse1,2,3 gfx extensions
2673 # svm = AMD pacifica virtualization extensions
2674 # vmx = Intel IVT (vanderpool) virtualization extensions
2675 cpu_flags=$( echo "$cpu_flags" | gawk '
2685 /^(nx|lm|svm|vmx)$/ {
2694 if (ssel[$0] > sse) {
2710 #grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
2711 if [[ -z $cpu_flags ]];then
2717 #### -------------------------------------------------------------------
2718 #### print and processing of output data
2719 #### -------------------------------------------------------------------
2721 #### MASTER PRINT FUNCTION - triggers all line item print functions
2722 ## main function to print out, master for all sub print functions.
2725 # note that print_it_out passes local variable values on to its children,
2726 # and in some cases, their children, with Lspci_Data
2727 local Lspci_Data='' # only for verbose
2729 if [[ $B_SHOW_SHORT_OUTPUT == 'true' ]];then
2732 Lspci_Data="$( get_lspci_data )"
2733 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_SYSTEM == 'true' ]];then
2736 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_CPU == 'true' ]];then
2739 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_GRAPHICS == 'true' ]];then
2742 if [[ $VERBOSITY_LEVEL -ge 5 || $B_SHOW_AUDIO == 'true' ]];then
2745 if [[ $VERBOSITY_LEVEL -ge 2 || $B_SHOW_NETWORK == 'true' ]];then
2746 print_networking_data
2748 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_DISK == 'true' ]];then
2749 print_hard_disk_data
2751 if [[ $VERBOSITY_LEVEL -ge 4 || $B_SHOW_PARTITIONS == 'true' ]];then
2752 print_partition_data
2754 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_INFO == 'true' ]];then
2760 #### SHORT OUTPUT PRINT FUNCTION, ie, verbosity 0
2761 # all the get data stuff is loaded here to keep execution time down for single line print commands
2762 # these will also be loaded in each relevant print function for long output
2765 local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
2766 local processes="$(( $( ps aux | wc -l ) - 1 ))"
2767 local short_data='' i='' b_background_black='false'
2768 local memory=$( get_memory_data )
2769 local up_time="$( get_uptime )"
2771 # set A_CPU_CORE_DATA
2773 local cpc_plural='' cpu_count_print='' model_plural=''
2774 local cpu_physical_count=${A_CPU_CORE_DATA[0]}
2775 local cpu_core_count=${A_CPU_CORE_DATA[3]}
2776 local cpu_core_alpha=${A_CPU_CORE_DATA[1]}
2777 local cpu_type=${A_CPU_CORE_DATA[2]}
2779 if [[ $cpu_physical_count -gt 1 ]];then
2782 cpu_count_print="$cpu_physical_count "
2785 local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
2786 # local cpu_core_count=${A_CPU_CORE_DATA[0]}
2790 ## note: if hdd_model is declared prior to use, whatever string you want inserted will
2791 ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
2792 local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
2794 local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
2796 local hdd_capacity=${a_hdd_basic_working[0]}
2797 local hdd_used=${a_hdd_basic_working[1]}
2803 local a_cpu_working=(${A_CPU_DATA[0]})
2805 local cpu_model="${a_cpu_working[0]}"
2806 ## assemble data for output
2807 local cpu_clock="${a_cpu_working[1]}" # old CPU3
2808 # this gets that weird min/max final array item
2809 local min_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 ))
2810 local min_max_clock=${A_CPU_DATA[$min_max_clock_nu]}
2812 #set_color_scheme 12
2813 if [[ $B_RUNNING_IN_SHELL == 'false' ]];then
2814 for i in $C1 $C2 $CN
2817 "$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN")
2818 b_background_black='true'
2822 if [[ $b_background_black == 'true' ]];then
2825 ## these need to be in quotes, don't know why
2826 if [[ ${!i} == $NORMAL ]];then
2827 declare $i="${!i}15,1"
2829 declare $i="${!i},1"
2832 #C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
2835 short_data="${C1}CPU$cpc_plural${CN}[${C2}${SEP1}${cpu_data_string} ${cpu_model}$model_plural (${cpu_type}) clocked at ${min_max_clock}${SEP1}${CN}] ${C1}Kernel${CN}[${C2}${SEP1}${current_kernel}${SEP1}${CN}] ${C1}Up${CN}[${C2}${SEP1}${up_time}${SEP1}${CN}] ${C1}Mem${CN}[${C2}${SEP1}${memory}${SEP1}${CN}] ${C1}HDD${CN}[${C2}${SEP1}${hdd_capacity}($hdd_used)${SEP1}${CN}] ${C1}Procs${CN}[${C2}${SEP1}${processes}${SEP1}${CN}]"
2837 if [[ $SHOW_IRC -gt 0 ]];then
2838 short_data="${short_data} ${C1}Client${CN}[${C2}${SEP1}${IRC_CLIENT}${IRC_CLIENT_VERSION}${SEP1}${CN}]"
2840 short_data="${short_data} ${C1}$SCRIPT_NAME${C2}${CN}[${C2}${SEP1}$SCRIPT_VERSION_NUMBER${SEP1}${CN}]"
2841 if [[ $SCHEME -gt 0 ]];then
2842 short_data="${short_data} $NORMAL"
2844 print_screen_output "$short_data"
2847 #### LINE ITEM PRINT FUNCTIONS
2849 # print sound card data
2852 local i='' card_one='Card-1 ' audio_data='' a_audio_data='' port_data=''
2853 local a_audio_working='' alsa_driver='' alsa_data='' port_plural='' module_version=''
2854 # set A_AUDIO_DATA and get alsa data
2856 alsa_data=$( get_audio_alsa_data )
2858 a_audio_working=(${A_AUDIO_DATA[0]})
2861 if [[ -n ${A_AUDIO_DATA[@]} ]];then
2862 # slightly complicated because 2nd array item could be the alsa data
2863 if [[ ${#A_AUDIO_DATA[@]} -le 1 ]];then
2867 # if [[ -n ${a_audio_working[2]} ]];then
2868 # port_data=" ${C1}at port${C2} ${a_audio_working[2]}"
2870 # this should only trigger if the $DIR_ASOUND_DEVICE data is used, not lspci -nn
2871 if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
2872 module_version=$( print_module_version "${a_audio_working[3]}" )
2874 if [[ -n ${a_audio_working[1]} ]];then
2875 alsa_driver=" ${C1}driver${C2} ${a_audio_working[1]}$module_version"
2877 if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
2878 if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
2881 port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
2883 audio_data="${C1}$card_one${C2}${a_audio_working[0]}$alsa_driver$port_data"
2884 audio_data=$( create_print_line "Audio:" "$audio_data" )
2885 print_screen_output "$audio_data"
2886 i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
2887 while [[ -n ${A_AUDIO_DATA[++i]} ]]
2890 a_audio_working=( ${A_AUDIO_DATA[i]} )
2896 if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
2897 module_version=$( print_module_version "${a_audio_working[3]}" )
2899 # we're testing for the presence of the 2nd array item here, which is the driver name
2900 if [[ -n ${a_audio_working[1]} ]];then
2901 alsa_driver="${C1}driver${C2} ${a_audio_working[1]}"
2903 if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
2904 if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
2907 port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
2909 if [[ -n ${a_audio_working[0]} ]];then
2910 audio_data="${C1}Card-$(( $i + 1 )) ${C2}${a_audio_working[0]}$alsa_driver$port_data"
2912 if [[ -n $audio_data ]];then
2913 audio_data=$( create_print_line " " "$audio_data" )
2914 print_screen_output "$audio_data"
2917 # alsa driver data only prints out if sound card data is found
2918 if [[ -n $alsa_data ]];then
2919 audio_data="${C1}Sound: ${C2}$alsa_data"
2920 audio_data=$( create_print_line " " "$audio_data" )
2921 print_screen_output "$audio_data"
2928 local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data=''
2929 local bmip_data='' cpu_cache='' cpu_vendor='' cpu_flags=''
2931 ##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\""
2932 # Array A_CPU_DATA always has one extra element: max clockfreq found.
2933 # that's why its count is one more than you'd think from cores/cpus alone
2938 local a_cpu_working=(${A_CPU_DATA[0]})
2940 local cpu_model="${a_cpu_working[0]}"
2941 ## assemble data for output
2942 local cpu_clock="${a_cpu_working[1]}"
2944 cpu_vendor=${a_cpu_working[5]}
2946 # set A_CPU_CORE_DATA
2948 local cpc_plural='' cpu_count_print='' model_plural=''
2949 local cpu_physical_count=${A_CPU_CORE_DATA[0]}
2950 local cpu_core_count=${A_CPU_CORE_DATA[3]}
2951 local cpu_core_alpha=${A_CPU_CORE_DATA[1]}
2952 local cpu_type=${A_CPU_CORE_DATA[2]}
2954 if [[ $cpu_physical_count -gt 1 ]];then
2956 cpu_count_print="$cpu_physical_count "
2960 local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
2961 # Strange (and also some expected) behavior encountered. If print_screen_output() uses $1
2962 # as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
2963 # will output only <text1> and first element of ARR. That "@" splits in elements and "*" _doesn't_,
2964 # is to be expected. However, that text2 is consecutively truncated is somewhat strange, so take note.
2965 # This has been confirmed by #bash on freenode.
2966 # The above mentioned only emerges when using the debugging markers below
2967 ## print_screen_output "a_cpu_working=\"***${a_cpu_working[@]} $hostName+++++++\"----------"
2969 if [[ -z ${a_cpu_working[2]} ]];then
2970 a_cpu_working[2]="unknown"
2973 cpu_data=$( create_print_line "CPU$cpc_plural:" "${C1}${cpu_data_string}${C2} ${a_cpu_working[0]}$model_plural (${cpu_type})" )
2974 if [[ $VERBOSITY_LEVEL -ge 3 || $B_SHOW_CPU == 'true' ]];then
2975 # update for multicore, bogomips x core count.
2976 if [[ $B_EXTRA_DATA == 'true' ]];then
2977 # if [[ $cpu_vendor != 'intel' ]];then
2978 bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$(( $cpu_core_count * $cpu_physical_count ))" )
2980 # bmip_data="${a_cpu_working[4]}"
2982 bmip_data=" ${C1}bmips${C2} $bmip_data"
2984 ## note: this handles how intel reports L2, total instead of per core like AMD does
2985 # note that we need to multiply by number of actual cpus here to get true cache size
2986 if [[ $cpu_vendor != 'intel' ]];then
2987 cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$(( $cpu_core_count * $cpu_physical_count ))" )
2989 cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$cpu_physical_count" )
2991 # only print shortened list
2992 if [[ $B_CPU_FLAGS_FULL != 'true' ]];then
2993 cpu_flags=$( process_cpu_flags "${a_cpu_working[3]}" )
2994 cpu_flags=" ${C1}flags${C2} ($cpu_flags)"
2996 cpu_data="$cpu_data${C2} ${C1}cache${C2} $cpu_cache$cpu_flags$bmip_data${CN}"
2998 # we don't this printing out extra line unless > 1 cpu core
2999 if [[ ${#A_CPU_DATA[@]} -gt 2 ]] && [[ $B_SHOW_CPU == 'true' || $VERBOSITY_LEVEL -ge 5 ]];then
3000 cpu_clock_speed='' # null < verbosity level 5
3002 cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}"
3005 cpu_data="$cpu_data $cpu_clock_speed"
3006 print_screen_output "$cpu_data"
3008 # we don't this printing out extra line unless > 1 cpu core
3009 if [[ ${#A_CPU_DATA[@]} -gt 2 ]] && [[ $B_SHOW_CPU == 'true' || $VERBOSITY_LEVEL -ge 5 ]];then
3010 for (( i=0; i < ${#A_CPU_DATA[@]}-1; i++ ))
3013 a_cpu_working=(${A_CPU_DATA[i]})
3015 cpu_multi_clock_data="$cpu_multi_clock_data ${C1}($(( i + 1 )))${C2} ${a_cpu_working[1]} MHz${CN}"
3016 if [[ $i -gt 10 ]];then
3020 if [[ -n $cpu_multi_clock_data ]];then
3021 cpu_multi_clock_data=$( create_print_line " " "${C1}Clock Speeds:${C2}$cpu_multi_clock_data" )
3022 print_screen_output "$cpu_multi_clock_data"
3025 if [[ $B_CPU_FLAGS_FULL == 'true' ]];then
3026 print_cpu_flags_full "${a_cpu_working[3]}"
3030 # takes list of all flags, split them and prints x per line
3031 # args: $1 - cpu flag string
3032 print_cpu_flags_full()
3034 local cpu_flags_full="$1" a_cpu_flags='' line_starter=''
3035 local i=0 counter=0 max_length=18 max_length_add=18 flag='' flag_data=''
3037 # build the flag line array
3038 for flag in $cpu_flags_full
3040 a_cpu_flags[$counter]="${a_cpu_flags[$counter]}$flag "
3041 if [[ $i -ge $max_length ]];then
3043 max_length=$(( $max_length + $max_length_add ))
3048 for (( i=0; i < ${#a_cpu_flags[@]};i++ ))
3050 if [[ $i -eq 0 ]];then
3051 line_starter="${C1}CPU Flags${C2} "
3055 flag_data=$( create_print_line " " "$line_starter${a_cpu_flags[$i]}" )
3056 print_screen_output "$flag_data"
3062 local gfx_data='' i='' card_one='Card '
3063 local screen_resolution="$( get_graphics_res_data )"
3064 local b_is_mesa='false'
3066 # set A_GFX_CARD_DATA
3067 get_graphics_card_data
3070 local x_vendor=${A_X_DATA[0]}
3071 local x_version=${A_X_DATA[1]}
3073 get_graphics_glx_data
3074 local glx_renderer="${A_GLX_DATA[0]}"
3075 local glx_version="${A_GLX_DATA[1]}"
3076 # this can contain a long No case debugging message, so it's being sliced off
3077 # note: using grep -ioE '(No|Yes)' <<< ${A_GLX_DATA[2]} did not work in Arch, no idea why
3078 local glx_direct_render=$( gawk '{
3080 }' <<< "${A_GLX_DATA[2]}" )
3082 if [[ ${#A_GFX_CARD_DATA[@]} -gt 1 ]];then
3084 while [[ -n ${A_GFX_CARD_DATA[i]} && $i -le 3 ]]
3086 gfx_data=" ${C1}Card-$(($i+1))${C2} ${A_GFX_CARD_DATA[i]}"
3091 gfx_data=$( create_print_line "Graphics:" "${C1}$card_one${C2}${A_GFX_CARD_DATA[0]}${gfx_data}" )
3093 if [[ $B_X_RUNNING == 'true' ]];then
3094 gfx_data="${gfx_data} ${C1}$x_vendor${C2} $x_version ${C1}Res${C2} ${screen_resolution}"
3096 gfx_data="${gfx_data} ${C1} tty resolution ${CN}(${C2} ${screen_resolution} ${CN})"
3098 print_screen_output "$gfx_data"
3100 # if [[ -z $glx_renderer || -z $glx_version ]];then
3104 ## note: if glx render or version have no content, then mesa is true
3105 # if [[ $B_X_RUNNING == 'true' ]] && [[ $b_is_mesa != 'true' ]];then
3106 if [[ $B_X_RUNNING == 'true' ]];then
3107 gfx_data=$( create_print_line " " "${C1}GLX Renderer${C2} ${glx_renderer} ${C1}GLX Version${C2} ${glx_version}${CN}" )
3108 if [[ $B_HANDLE_CORRUPT_DATA == 'true' || $B_EXTRA_DATA == 'true' ]];then
3109 gfx_data="$gfx_data ${C1}Direct Rendering${C2} ${glx_direct_render}${CN}"
3111 print_screen_output "$gfx_data"
3115 print_hard_disk_data()
3117 local hdd_data='' hdd_data_2='' a_hdd_working=''
3118 local dev_data='' size_data='' hdd_model='' hdd_model_2='' hdd_model_3='' usb_data=''
3122 ## note: if hdd_model is declared prior to use, whatever string you want inserted will
3123 ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
3124 local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
3126 local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
3128 local hdd_capacity=${a_hdd_basic_working[0]}
3129 local hdd_used=${a_hdd_basic_working[1]}
3131 if [[ $VERBOSITY_LEVEL -ge 3 ]] || [[ $B_SHOW_DISK == 'true' ]];then
3132 ## note: the output part of this should be in the print hdd data function, not here
3133 get_hard_drive_data_advanced
3134 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
3136 # this adds the (x) numbering in front of each disk found, and creates the full disk string
3138 a_hdd_working=( ${A_HDD_DATA[i]} )
3140 if [[ $B_SHOW_DISK == 'true' ]];then
3141 if [[ -n ${a_hdd_working[3]} ]];then
3142 usb_data="${a_hdd_working[3]} "
3146 dev_data="/dev/${a_hdd_working[0]} "
3147 size_data=" ${a_hdd_working[1]}"
3149 # wrap to avoid long lines
3151 if [[ $i -gt 1 && $B_SHOW_DISK == 'true' ]] || [[ $i -gt 3 ]];then
3152 hdd_model_2="${hdd_model_2}${hdd_model_2+${C1}$(($i+1)):${C2}} $usb_data$dev_data${a_hdd_working[2]}$size_data "
3154 hdd_model="${hdd_model}${hdd_model+ ${C1}$(($i+1)):${C2}} $usb_data$dev_data${a_hdd_working[2]}$size_data"
3157 if [[ -z $hdd_model ]];then
3158 hdd_model=' None Detected'
3160 if [[ -n $hdd_model_2 ]];then
3161 hdd_data=$( create_print_line "Disks:" "${C1}HDD${C2} ${C1}Total Size:${C2} ${hdd_capacity} (${hdd_used})${hdd_model}" )
3162 hdd_data_2=$( create_print_line " " "${hdd_model_2}${CN}" )
3164 hdd_data=$( create_print_line "Disks:" "${C1}HDD${C2} ${C1}Total Size:${C2} ${hdd_capacity} (${hdd_used})${hdd_model}${CN}" )
3167 hdd_data=$( create_print_line "Disks:" "${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used})${CN}" )
3169 print_screen_output "$hdd_data"
3170 if [[ -n $hdd_model_2 ]];then
3171 print_screen_output "$hdd_data_2"
3177 local suggested_app="runlevel"
3180 local memory="$( get_memory_data )"
3181 local processes="$(( $( ps aux | wc -l ) - 1 ))"
3182 local up_time="$( get_uptime )"
3184 # Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch!
3185 # long_last=$( echo -ne "${C1}Processes${C2} ${processes}${CN} | ${C1}Uptime${C2} ${up_time}${CN} | ${C1}Memory${C2} ${MEM}${CN}" )
3186 info_data=$( create_print_line "Info:" "${C1}Processes${C2} ${processes} ${C1}Uptime${C2} ${up_time} ${C1}Memory${C2} ${memory}${CN}" )
3188 # this only triggers if no X data is present
3189 if [[ $B_X_RUNNING != 'true' ]];then
3190 if [[ -e $suggested_app ]];then
3191 runlvl="$( runlevel | gawk '{ print $2 }' )"
3192 info_data="${info_data} ${C1}Runlevel${C2} ${runlvl}${CN}"
3196 if [[ $SHOW_IRC -gt 0 ]];then
3197 info_data="${info_data} ${C1}Client${C2} ${IRC_CLIENT}${IRC_CLIENT_VERSION}${CN}"
3199 info_data="${info_data} ${C1}$SCRIPT_NAME${C2} $SCRIPT_VERSION_NUMBER${CN}"
3201 if [[ $SCHEME -gt 0 ]];then
3202 info_data="${info_data} ${NORMAL}"
3204 print_screen_output "$info_data"
3207 # args: $1 - module name (could be > 1, so loop it )
3208 print_module_version()
3210 local module_versions='' module='' version=''
3214 version=$( get_module_version_number $module )
3215 if [[ -n $version ]];then
3216 module_versions="$module_versions $version"
3220 if [[ -n $module_versions ]];then
3221 echo " ${C1}v:${C2}$module_versions"
3225 print_networking_data()
3227 local i='' card_one='Card-1' network_data='' a_network_working='' port_data='' driver_data=''
3228 local card_string='' port_plural='' module_version=''
3229 # set A_NETWORK_DATA
3233 a_network_working=(${A_NETWORK_DATA[0]})
3236 # will never be null because null is handled in get_network_data, but in case we change
3237 # that leaving this test in place.
3238 if [[ -n ${A_NETWORK_DATA[@]} ]];then
3239 if [[ ${#A_NETWORK_DATA[@]} -le 1 ]];then
3242 if [[ -n ${a_network_working[3]} && $B_EXTRA_DATA == 'true' ]];then
3243 module_version=$( print_module_version "${a_network_working[3]}" )
3245 if [[ -n ${a_network_working[1]} ]];then
3246 driver_data=" ${C1}driver${C2} ${a_network_working[1]}$module_version"
3248 if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then
3249 if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then
3252 port_data=" ${C1}at port$port_plural${C2} ${a_network_working[2]}"
3255 network_data="${C1}$card_one${C2} ${a_network_working[0]}$driver_data$port_data"
3256 network_data=$( create_print_line "Network:" "$network_data" )
3257 print_screen_output "$network_data"
3258 i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
3259 while [[ -n ${A_NETWORK_DATA[++i]} ]]
3262 a_network_working=( ${A_NETWORK_DATA[i]} )
3268 if [[ -n ${a_network_working[3]} && $B_EXTRA_DATA == 'true' ]];then
3269 module_version=$( print_module_version "${a_network_working[3]}" )
3271 if [[ -n ${a_network_working[1]} ]];then
3272 driver_data=" ${C1}driver${C2} ${a_network_working[1]}$module_version"
3274 if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then
3275 if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then
3278 port_data=" ${C1}at port$port_plural${C2} ${a_network_working[2]}"
3280 network_data="${C1}Card-$(( $i + 1 )) ${C2}${a_network_working[0]}$driver_data$port_data"
3281 network_data=$( create_print_line " " "$network_data" )
3282 print_screen_output "$network_data"
3285 if [[ $B_SHOW_IP == 'true' ]];then
3286 print_networking_ip_data
3290 print_networking_ip_data()
3292 local ip=$( get_networking_wan_ip_data )
3293 local ip_data='' a_interfaces_working='' interfaces='' interfaces_2='' i=''
3295 # set A_INTERFACES_DATA
3296 get_networking_local_ip_data
3297 # first print output for wan ip line. Null is handled in the get function
3298 ip_data=$( create_print_line " " "${C1}Wan IP:${C2} $ip" )
3300 # then create the list of local interface/ip
3301 interfaces=" ${C1}Interface:${C2}"
3302 i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
3303 while [[ -n ${A_INTERFACES_DATA[i]} ]]
3306 a_interfaces_working=(${A_INTERFACES_DATA[i]})
3308 if [[ $i -lt 3 ]];then
3309 if [[ -n ${a_interfaces_working[0]} ]];then
3310 interfaces="$interfaces ${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]}"
3313 if [[ -n ${a_interfaces_working[0]} ]];then
3314 # space on end here for lining up with line starter
3315 interfaces_2="$interfaces_2${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]} "
3320 print_screen_output "$ip_data$interfaces"
3321 # then wrap it if needed
3322 if [[ -n $interfaces_2 ]];then
3323 interfaces_2=$( create_print_line " " "$interfaces_2" )
3324 print_screen_output "$interfaces_2"
3328 print_partition_data()
3330 local a_partition_working='' partition_used='' partition_data=''
3331 local counter=0 line_max=160 i=0 a_partition_data='' line_starter=''
3332 local partitionIdClean='' part_dev='' full_dev='' part_label='' full_label=''
3333 local part_uuid='' full_uuid='' dev_remote=''
3335 # this handles the different, shorter, irc colors strings embedded in variable data
3336 if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
3339 # and no color string data at all
3340 if [[ $SCHEME -eq 0 ]];then
3343 if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
3347 # set A_PARTITION_DATA
3350 for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
3353 a_partition_working=(${A_PARTITION_DATA[i]})
3357 if [[ $B_SHOW_PARTITIONS_FULL == 'true' ]] || [[ ${a_partition_working[4]} == 'main' ]];then
3358 if [[ -n ${a_partition_working[2]} ]];then
3359 partition_used=" ${C1}used:${C2} ${a_partition_working[2]} (${a_partition_working[3]})"
3361 partition_used='' # reset partition used to null
3364 # don't show user names in output
3365 if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
3366 if [[ -n ${a_partition_working[5]} ]];then
3367 if [[ -z $( grep -E '(^//|:/)' <<< ${a_partition_working[5]} ) ]];then
3368 part_dev="/dev/${a_partition_working[5]}"
3371 part_dev="${a_partition_working[5]}"
3378 full_dev=" ${C1}$dev_remote:${C2} $part_dev"
3379 if [[ $B_SHOW_LABELS == 'true' && $dev_remote != 'remote' ]];then
3380 if [[ -n ${a_partition_working[6]} ]];then
3381 part_label="${a_partition_working[6]}"
3385 full_label=" ${C1}label:${C2} $part_label"
3387 if [[ $B_SHOW_UUIDS == 'true' && $dev_remote != 'remote' ]];then
3388 if [[ -n ${a_partition_working[7]} ]];then
3389 part_uuid="${a_partition_working[7]}"
3393 full_uuid=" ${C1}uuid:${C2} $part_uuid"
3396 partitionIdClean=$( sed -r 's|/home/(.*)/(.*)|/home/##/\2|' <<< ${a_partition_working[0]} )
3397 # because these lines can vary widely, using dynamic length handling here
3398 a_partition_data[$counter]="${a_partition_data[$counter]}${C1}ID:${C2}$partitionIdClean ${C1}size:${C2} ${a_partition_working[1]}$partition_used$full_dev$full_label$full_uuid "
3400 if [[ $( wc -c <<< ${a_partition_data[$counter]} ) -gt $line_max ]];then
3405 # print out all lines, line starter on first line
3406 for (( i=0; i < ${#a_partition_data[@]};i++ ))
3408 if [[ $i -eq 0 ]];then
3409 line_starter='Partition:'
3413 partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}" )
3414 print_screen_output "$partition_data"
3420 local system_data='' bits=''
3421 local host_name=$( hostname )
3422 local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
3423 local distro="$( get_distro_data )"
3424 # check for 64 bit first
3425 if [[ -n $( uname -m | grep -o 'x86_64' ) ]];then
3431 if [[ $B_SHOW_HOST == 'true' ]];then
3432 system_data=$( create_print_line "System:" "${C1}Host${C2} $host_name ${C1}Kernel${C2}" )
3434 system_data=$( create_print_line "System:" "${C1}Kernel${C2}" )
3436 system_data="$system_data $current_kernel $bits ${C1}Distro${C2} $distro"
3437 print_screen_output "$system_data"
3440 ########################################################################
3441 #### SCRIPT EXECUTION
3442 ########################################################################
3444 main $@ ## From the End comes the Beginning
3446 ## note: this EOF is needed for smxi handling, this is what triggers the full download ok