Add mpris script to retreive now-playing information from compatible players via...
[quassel.git] / data / scripts / inxi
1 #!/bin/bash
2 ########################################################################
3 ####  Script Name: inxi
4 ####  version: 1.0.8
5 ####  Date: 13 March 2009
6 ########################################################################
7 ####  SPECIAL THANKS
8 ########################################################################
9 ####  Special thanks to all those in lsc for their tireless dedication
10 ####  with helping test inxi modules
11 ########################################################################
12 ####  ABOUT INXI
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.
16 ####
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
25 ####
26 ####  Current script home page: http://techpatterns.com/forums/about1131.html
27 ####  Script svn: http://code.google.com/p/inxi
28 ####
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.
33 ####
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.
38 ####
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/>.
41 ####
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 ########################################################################
45 ####  DEPENDENCIES
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
50 ####
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
54 ####
55 ####    Arrays work in bash 2.05b, but "egrep -m" does not
56 ####
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 ########################################################################
62 ####  CONVENTIONS:
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
69 ####
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.
73 ####
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
76 ####
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.
84 ####
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
88 ####
89 ####  SPECIAL NOTES:
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.
93 ####
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 ########################################################################
101 ####  TESTING FLAGS
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 ########################################################################
113 #### VARIABLES
114 ########################################################################
115
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
118
119 ### Variable initializations: null values
120 CMDL_MAX=''
121 COLOR_SCHEME=''
122 COLOR_SCHEME_SET=''
123 IRC_CLIENT=''
124 IRC_CLIENT_VERSION=''
125
126 ### primary data array holders
127 A_AUDIO_DATA=''
128 A_CMDL=''
129 A_CPU_CORE_DATA=''
130 A_CPU_DATA=''
131 A_CPU_TYPE_PCNT_CCNT=''
132 A_DEBUG_BUFFER=''
133 A_GFX_CARD_DATA=''
134 A_GLX_DATA=''
135 A_HDD_DATA=''
136 A_INTERFACES_DATA=''
137 A_NETWORK_DATA=''
138 A_PARTITION_DATA=''
139 A_X_DATA=''
140
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
150 B_EXTRA_DATA='false'
151 B_SHOW_DISK='false'
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
157 B_SCRIPT_UP='false'
158 # Show sound card data
159 B_SHOW_AUDIO='false'
160 B_SHOW_CPU='false'
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
165 B_SHOW_HOST='true'
166 B_SHOW_INFO='false'
167 B_SHOW_IP='false'
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'
176 B_SHOW_UUIDS='false'
177 # triggers various debugging and new option testing
178 B_TESTING_1='false'
179 B_TESTING_2='false'
180 # Test for X running
181 B_X_RUNNING='false'
182
183 ### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
184 B_PROC='false'
185 B_CPUINFO='false'
186 B_MEMINFO='false'
187 B_ASOUND_CARDS='false'
188 B_ASOUND_VERSION='false'
189 B_BASH_ARRAY='false'
190 B_IFCONFIG='false'
191 B_LSB_DIR='false'
192 B_SCSI_DIR='false'
193 B_MODULES_DIR='false' #
194 B_MOUNTS_DIR='false'
195 B_PARTITIONS_DIR='false' #
196
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'
208
209 ### Variable initializations: constants
210 DCOPOBJ="default"
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'
213 DEBUG_BUFFER_INDEX=0
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
216
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.
219 DEFAULT_SCHEME=2
220 # Default indentation level
221 INDENT=10
222 # default to false, no konversation found, 1 is /cmd inxi start, 2 is native konvi script mode
223 KONVI=0
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.
226 PARAMETER_LIMIT=30
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.
229 SHOW_IRC=2
230 # Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
231 VERBOSITY_LEVEL=0
232 # Supported number of verbosity levels, including 0
233 VERBOSITY_LEVELS=5
234
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.
238 shopt -u nullglob
239 ## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
240 # Backup the current Internal Field Separator
241 ORIGINAL_IFS="$IFS"
242 # These two determine separators in single line output, to force irc clients not to break off sections
243 SEP1='-'
244 SEP2='~'
245
246 ### Script names/paths
247 SCRIPT_NAME="inxi"
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)
257
258 ### Script Localization
259 # Make sure every program speaks English.
260 LC_ALL="C"
261 export LC_ALL
262
263 ### Output Colors
264 # A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
265 unset EMPTY
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
277 C1=''
278 C2=''
279 CN=''
280
281 ### Distro Data
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
292
293 ### Bans Data
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:
301 BAN_LIST_NORMAL=''
302 BAN_LIST_CPU=''
303
304 ### Source global config overrides
305 if [[ -s /etc/$SCRIPT_NAME.conf ]];then
306         source /etc/$SCRIPT_NAME.conf
307 fi
308 # Source user config overrides
309 if [[ -s $HOME/.$SCRIPT_NAME ]];then
310         source $HOME/.$SCRIPT_NAME
311 fi
312
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
316 # from Konversation!
317
318 ########################################################################
319 #### MAIN: Where it all begins
320 ########################################################################
321 main()
322 {
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
327
328         ## this needs to run before the KONVI stuff is set below
329         get_start_client
330
331         # Check for dependencies before running anything else except above functions
332         check_script_depends
333         check_script_suggested_apps
334
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
338                 DCPORT="$1"
339                 DCSERVER="$2"
340                 DCTARGET="$3"
341                 shift 3
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
344                 IFS=":"
345                 for kde_config in $( kde-config --path data )
346                 do
347                         if [[ -r ${kde_config}${KONVI_CFG} ]];then
348                                 source "${kde_config}${KONVI_CFG}"
349                                 break
350                         fi
351                 done
352                 IFS="$ORIGINAL_IFS"
353         fi
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"
358
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.
361         get_parameters "$@"
362
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"
366         fi
367
368         # all the pre-start stuff is in place now
369         B_SCRIPT_UP='true'
370         script_debugger "Debugger: $SCRIPT_NAME is up and running..."
371
372         # then create the output
373         print_it_out
374
375         ## last steps
376         if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
377                 echo -n "\e[0m"
378         fi
379
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..
382         exit 0
383 }
384
385 #### -------------------------------------------------------------------
386 #### basic tests: set script data, booleans, PATH
387 #### -------------------------------------------------------------------
388
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()
394 {
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"
398
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:
401         IFS=":"
402         for path in $extra_paths
403         do
404                 b_path_found='false'
405                 for sys_path in $PATH
406                 do
407                         if [[ $path == $sys_path ]];then
408                                 b_path_found='true'
409                         fi
410                 done
411                 if [[ $b_path_found == 'false' ]];then
412                         added_path="$added_path:$path"
413                 fi
414         done
415         IFS="$ORIGINAL_IFS"
416         PATH="${PATH}${added_path}"
417         ##echo "PATH='$PATH'"
418         ##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
419
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'"
424
425         # now set the script BOOLEANS for files required to run features
426         if [[ -d "/proc/" ]];then
427                 B_PROC='true'
428         else
429                 error_handler 6
430         fi
431
432         if [[ -e $DIR_CPUINFO ]]; then
433                 B_CPUINFO='true'
434         fi
435
436         if [[ -e $DIR_MEMINFO ]];then
437                 B_MEMINFO='true'
438         fi
439
440         if [[ -e $DIR_ASOUND_DEVICE ]];then
441                 B_ASOUND_CARDS='true'
442         fi
443
444         if [[ -e $DIR_ASOUND_VERSION ]];then
445                 B_ASOUND_VERSION='true'
446         fi
447
448         if [[ -f $DIR_LSB_RELEASE ]];then
449                 B_LSB_DIR='true'
450         fi
451
452         if [[ -e $DIR_SCSI ]];then
453                 B_SCSI_DIR='true'
454         fi
455
456         # lack of ifconfig will throw an error only upon it's usage
457         if [[ -x ifconfig ]]; then
458                 B_IFCONFIG='true'
459                 DIR_IFCONFIG='ifconfig' # change from full path to use $PATH
460         elif [[ -x $DIR_IFCONFIG ]];then
461                 B_IFCONFIG='true'
462         else
463                 A_INTERFACES_DATA=( "Interfaces tool requires missing app: $DIR_IFCONFIG" )
464         fi
465
466         if [[ -n $DISPLAY ]];then
467                 B_X_RUNNING='true'
468         fi
469
470         if [[ -e $DIR_MODULES ]];then
471                 B_MODULES_DIR='true'
472         fi
473
474         if [[ -e $DIR_MOUNTS ]];then
475                 B_MOUNTS_DIR='true'
476         fi
477
478         if [[ -e $DIR_PARTITIONS ]];then
479                 B_PARTITIONS_DIR='true'
480         fi
481 }
482
483 check_script_suggested_apps()
484 {
485         local bash_array_test=( "one" "two" )
486
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
494                 B_BASH_ARRAY='true'
495         else
496                 script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output"
497         fi
498 }
499
500 # Determine if any of the absolutely necessary tools are absent
501 check_script_depends()
502 {
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"
506
507         if [[ $B_X_RUNNING == 'true' ]];then
508                 for app_name in xrandr xdpyinfo glxinfo
509                 do
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"
513                                 B_X_RUNNING='false'
514                                 break
515                         fi
516                 done
517         fi
518
519         app_name=''
520
521         for app_name in $depends
522         do
523                 app_data=$( type -p $app_name )
524                 if [[ -z $app_data ]];then
525                         error_handler 5 "$app_name"
526                 fi
527         done
528 }
529
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()
536 {
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 '"..."'
540         echo "$2" | gawk "
541         BEGIN {
542                 IGNORECASE=1
543         }
544         {
545                 gsub(/${!1}/,\"\")
546                 gsub(/ [ ]+/,\" \")    ## ([ ]+) with (space)
547                 gsub(/^ +| +$/,\"\")   ## (pipe char) with (nothing)
548                 print                  ## prints (returns) cleaned input
549         }"
550 }
551
552 # Filter boilerplate & buzzwords.
553 # args: $1 - quoted: "$@" array of ban terms
554 make_ban_lists()
555 {
556         local ban_list=''
557         # Iterate over $@
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
560         for ban_string
561         do
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}"
565                 else
566                         # Automatically escapes [ ] ( ) . and +
567                         ban_list="${ban_list}${ban_list+|}$( echo "$ban_string" | gawk '{
568                                 gsub(/([\[\]+().])/,"\\\\&")
569                                 print
570                         }' )"
571                 fi
572         done
573
574         echo "$ban_list"
575 }
576 # make_ban_lists "${A_CPU_BANS[@]}";exit
577
578 # Set the colorscheme
579 # args: $1 = <scheme number>|<"none">
580 set_color_scheme()
581 {
582         local i='' script_colors='' color_codes=''
583
584         if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then
585                 set -- 1
586         fi
587         # Set a global variable to allow checking for chosen scheme later
588         SCHEME="$1"
589         if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
590                 color_codes=( $ANSI_COLORS )
591         else
592                 color_codes=( $IRC_COLORS )
593         fi
594         for (( i=0; i < ${#A_COLORS_AVAILABLE[@]}; i++ ))
595         do
596                 eval "${A_COLORS_AVAILABLE[i]}=\"${color_codes[i]}\""
597         done
598         IFS=","
599         script_colors=( ${A_COLOR_SCHEMES[$1]} )
600         IFS="$ORIGINAL_IFS"
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? ##
606 }
607
608 ########################################################################
609 #### UTILITY FUNCTIONS
610 ########################################################################
611
612 #### -------------------------------------------------------------------
613 #### error handler, debugger, script updater
614 #### -------------------------------------------------------------------
615
616 # Error handling
617 # args: $1 - error number; $2 - optional, extra information
618 error_handler()
619 {
620         local error_message=''
621
622         # assemble the error message
623         case $1 in
624                 2)      error_message="large flood danger, debug buffer full!"
625                         ;;
626                 3)      error_message="unsupported color scheme number: $2"
627                         ;;
628                 4)      error_message="unsupported verbosity level: $2"
629                         ;;
630                 5)      error_message="dependency not met: $2 not found in path"
631                         ;;
632                 6)      error_message="/proc not found! Quitting..."
633                         ;;
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"
635                         ;;
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"
637                         ;;
638                 9)      error_message="unsupported debugging level: $2"
639                         ;;
640                 10)
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/"
642                         ;;
643                 11)
644                         error_message="unsupported testing option argument: -! $2"
645                         ;;
646                 12)
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."
648                         ;;
649                 *)      error_message="error unknown: $@"
650                         set -- 99
651                         ;;
652         esac
653         # then print it and exit
654         print_screen_output "Error $1: $error_message"
655         exit $1
656 }
657
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
661 script_debugger()
662 {
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
666                         return 0
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++ ))
670                         do
671                                 print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
672                         done
673                         DEBUG_BUFFER_INDEX=0
674                 fi
675                 # or print out normal debugger messages if debugger is on
676                 if [[ $DEBUG -gt 0 ]];then
677                         print_screen_output "$1"
678                 fi
679         else
680                 if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
681                         error_handler 2
682                 # this case stores the data for later printout, will print out only
683                 # at B_SCRIPT_UP == 'true' if array index > 0
684                 else
685                         A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
686                         # increment count for next pre script up debugging error
687                         (( DEBUG_BUFFER_INDEX++ ))
688                 fi
689         fi
690 }
691
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()
695 {
696         local wget_error=0
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."
709                         exit 0
710                 fi
711         fi
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"
718                 else
719                         error_handler 12 "$1"
720                 fi
721         fi
722 }
723
724 #### -------------------------------------------------------------------
725 #### print / output cleaners
726 #### -------------------------------------------------------------------
727
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()
732 {
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" )"
735
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'"
743                 else
744                         echo "printing out: '$print_data'"
745                 fi
746         fi
747
748         if [[ $KONVI -eq 1 ]];then
749                 print_data="$( tr '\n' ' ' <<< "$print_data" )"
750                 dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data"
751         else
752                 # the -n is needed to avoid double spacing of output in terminal
753                 echo -ne "$print_data\n"
754         fi
755 }
756
757 ## this handles all verbose line construction with indentation/line starter
758 ## args: $1 - null (, actually: " ") or line starter; $2 - line content
759 create_print_line()
760 {
761         printf "${C1}%-${INDENT}s${C2} %s" "$1" "$2"
762 }
763
764 # this removes newline and pipes.
765 # args: $1 - string to clean
766 remove_erroneous_chars()
767 {
768         ## RS is input record separator
769         ## gsub is substitute;
770         gawk '
771         BEGIN {
772                 RS=""
773         }
774         {
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)
781                 printf $0
782         }' "$1"      ## prints (returns) cleaned input
783 }
784
785 #### -------------------------------------------------------------------
786 #### parameter handling, print usage functions.
787 #### -------------------------------------------------------------------
788
789 # Get the parameters. Note: standard options should be lower case, advanced or testing, upper
790 # args: $1 - full script startup args: $@
791 get_parameters()
792 {
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
795
796         if [[ $B_ALLOW_UPDATE == 'false' ]];then
797                 update_flags=''
798         fi
799
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
802         if [[ -n $1 ]];then
803                 while getopts Ac:CdDfFGhHiIlNpPSuv:Vx%@:${update_flags} opt
804                 do
805                         case $opt in
806                         A)      B_SHOW_AUDIO='true'
807                                 use_short='false'
808                                 ;;
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"
815                                         fi
816                                 else
817                                         error_handler 3 "$OPTARG"
818                                 fi
819                                 ;;
820                         C)      B_SHOW_CPU='true'
821                                 use_short='false'
822                                 ;;
823                         d)      VERBOSITY_LEVEL=1
824                                 use_short='false'
825                                 ;;
826                         D)      B_SHOW_DISK='true'
827                                 use_short='false'
828                                 ;;
829                         f)      B_SHOW_CPU='true'
830                                 B_CPU_FLAGS_FULL='true'
831                                 use_short='false'
832                                 ;;
833                         F)      VERBOSITY_LEVEL=$VERBOSITY_LEVELS
834                                 B_EXTRA_DATA='true'
835                                 B_SHOW_DISK='true'
836                                 B_SHOW_PARTITIONS='true'
837                                 B_SHOW_AUDIO='true'
838                                 use_short='false'
839                                 ;;
840                         G)      B_SHOW_GRAPHICS='true'
841                                 use_short='false'
842                                 ;;
843                         i)      B_SHOW_IP='true'
844                                 B_SHOW_NETWORK='true'
845                                 use_short='false'
846                                 ;;
847                         I)      B_SHOW_INFO='true'
848                                 use_short='false'
849                                 ;;
850                         l)      B_SHOW_LABELS='true'
851                                 B_SHOW_PARTITIONS='true'
852                                 use_short='false'
853                                 ;;
854                         N)      B_SHOW_NETWORK='true'
855                                 use_short='false'
856                                 ;;
857                         p)      B_SHOW_PARTITIONS_FULL='true'
858                                 B_SHOW_PARTITIONS='true'
859                                 use_short='false'
860                                 ;;
861                         P)      B_SHOW_PARTITIONS='true'
862                                 use_short='false'
863                                 ;;
864                         S)      B_SHOW_SYSTEM='true'
865                                 use_short='false'
866                                 ;;
867                         u)      B_SHOW_UUIDS='true'
868                                 B_SHOW_PARTITIONS='true'
869                                 use_short='false'
870                                 ;;
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
874                                                 use_short='false'
875                                         fi
876                                 else
877                                         error_handler 4 "$OPTARG"
878                                 fi
879                                 ;;
880                         U)      script_self_updater "$SCRIPT_DOWNLOAD" 'svn server'
881                                 ;;
882                         V)      print_version_info
883                                 exit 0
884                                 ;;
885                         x)      B_EXTRA_DATA='true'
886                                 ;;
887                         h)      show_options
888                                 exit 0
889                                 ;;
890                         H)      show_options 'full'
891                                 exit 0
892                                 ;;
893                         ## debuggers and testing tools
894                         %)      B_HANDLE_CORRUPT_DATA='true'
895                                 ;;
896                         @)      if [[ -n $( egrep "^([1-9]|10)$" <<< $OPTARG ) ]];then
897                                         DEBUG=$OPTARG
898                                         exec 2>&1
899                                 else
900                                         error_handler 9 "$OPTARG"
901                                 fi
902                                 ;;
903                         !)      # test for various supported methods
904                                 case $OPTARG in
905                                         1)      B_TESTING_1='true'
906                                                 ;;
907                                         2)      B_TESTING_2='true'
908                                                 ;;
909                                         3)      B_TESTING_1='true'
910                                                 B_TESTING_2='true'
911                                                 ;;
912                                         10)
913                                                 script_self_updater "$SCRIPT_DOWNLOAD_DEV" 'dev server'
914                                                 ;;
915                                         11)
916                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_1" 'svn: branch one server'
917                                                 ;;
918                                         12)
919                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_2" 'svn: branch two server'
920                                                 ;;
921                                         13)
922                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_3" 'svn: branch three server'
923                                                 ;;
924                                         14)
925                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_4" 'svn: branch four server'
926                                                 ;;
927                                         http*)
928                                                 script_self_updater "$OPTARG" 'alt server'
929                                                 ;;
930                                         *)      error_handler 11 "$OPTARG"
931                                                 ;;
932                                 esac
933                                 ;;
934                         *)      error_handler 7 "$1"
935                                 ;;
936                         esac
937                 done
938         fi
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
942                 exec 2>/dev/null
943         fi
944         #((DEBUG)) && exec 2>&1 # This is for debugging konversation
945
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'
949         fi
950 }
951
952 ## print out help menu, not including Testing or Debugger stuff because it's not needed
953 show_options()
954 {
955         local color_scheme_count=${#A_COLOR_SCHEMES[@]}
956
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."
1003         fi
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 ""
1020         fi
1021         print_screen_output ""
1022 }
1023
1024 ## print out version information for -V/--version
1025 print_version_info()
1026 {
1027         local last_modified=$( grep -im 1 'date:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3,$4,$5}' )
1028
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."
1046 }
1047
1048 ########################################################################
1049 #### MAIN FUNCTIONS
1050 ########################################################################
1051
1052 #### -------------------------------------------------------------------
1053 #### initial startup stuff
1054 #### -------------------------------------------------------------------
1055
1056 # Determine where inxi was run from, set IRC_CLIENT and IRC_CLIENT_VERSION
1057 get_start_client()
1058 {
1059         local irc_client_path='' irc_client_path_lower='' non_native_konvi='' i=''
1060         local b_non_native_app='false' pppid='' app_working_name=''
1061
1062         if tty >/dev/null;then
1063                 IRC_CLIENT='Shell'
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'
1082                                 fi
1083                                 ;;
1084                 esac
1085                 # replacing loose detection with tight detection, bugs will be handled with app names
1086                 # as they appear.
1087                 case $app_working_name in
1088                         irssi-text|irssi)
1089                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1090                                         print $2
1091                                 }' )"
1092                                 IRC_CLIENT="Irssi"
1093                                 ;;
1094                         konversation)
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
1097                                         KONVI=2
1098                                 else
1099                                         KONVI=1
1100                                 fi
1101                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
1102                                 /Konversation:/ {
1103                                         for ( i=2; i<=NF; i++ ) {
1104                                                 if (i == NF) {
1105                                                         print $i
1106                                                 }
1107                                                 else {
1108                                                         printf $i" "
1109                                                 }
1110                                         }
1111                                         exit
1112                                 }' )"
1113
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"
1120                                         T2="${T[0]/+/}"
1121                                 else
1122                                         IRC_CLIENT_VERSION=" ${T[0]}"
1123                                         T2="${T[0]}"
1124                                 fi
1125                                 # Remove any dots except the first, and make sure there are no trailing zeroes,
1126                                 T2=$( echo "$T2" | gawk '{
1127                                         sub(/\./, " ")
1128                                         gsub(/\./, "")
1129                                         sub(/ /, ".")
1130                                         printf("%g\n", $0)
1131                                 }' )
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"
1137                                 fi
1138                                 IRC_CLIENT="Konversation"
1139                                 ;;
1140                         xchat-gnome)
1141                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1142                                         print $2
1143                                 }' )"
1144                                 IRC_CLIENT="X-Chat-Gnome"
1145                                 ;;
1146                         xchat)
1147                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1148                                         print $2
1149                                 }' )"
1150                                 IRC_CLIENT="X-Chat"
1151                                 ;;
1152                         bitchx)
1153                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
1154                                 /Version/ {
1155                                         a=tolower($2)
1156                                         gsub(/[()]|bitchx-/,"",a)
1157                                         print a
1158                                         exit
1159                                 }
1160                                 $2 == "version" {
1161                                         a=tolower($3)
1162                                         sub(/bitchx-/,"",a)
1163                                         print a
1164                                         exit
1165                                 }' )"
1166                                 IRC_CLIENT="BitchX"
1167                                 ;;
1168                         ircii)
1169                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1170                                         print $3
1171                                 }' )"
1172                                 IRC_CLIENT="ircII"
1173                                 ;;
1174                         gaim)
1175                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1176                                         print $2
1177                                 }' )"
1178                                 IRC_CLIENT="Gaim"
1179                                 ;;
1180                         pidgin)
1181                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1182                                         print $2
1183                                 }' )"
1184                                 IRC_CLIENT="Pidgin"
1185                                 ;;
1186                         quassel*)
1187                                 # sample: quassel -v
1188                                 # Qt: 4.5.0
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 ': ' '
1193                                 BEGIN {
1194                                         IGNORECASE=1
1195                                         clientVersion=""
1196                                 }
1197                                 /Quassel IRC/ {
1198                                         clientVersion = $2
1199                                 }
1200                                 END {
1201                                         # this handles pre 0.4.1 cases with no -v
1202                                         if ( clientVersion == "" ) {
1203                                                 clientVersion = "(pre v0.4.1)"
1204                                         }
1205                                         print clientVersion
1206                                 }' )"
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
1210                                         quassel)
1211                                                 IRC_CLIENT="Quassel [M]"
1212                                                 ;;
1213                                         quasselclient)
1214                                                 IRC_CLIENT="Quassel"
1215                                                 ;;
1216                                         quasselcore)
1217                                                 IRC_CLIENT="Quassel (core)"
1218                                                 ;;
1219                                 esac
1220                                 ;;
1221                         weechat-curses)
1222                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v ) "
1223                                 IRC_CLIENT="Weechat"
1224                                 ;;
1225                         kvirc)
1226                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>&1 | gawk '{
1227                                         for ( i=2; i<=NF; i++) {
1228                                                 if ( i == NF ) {
1229                                                         print $i
1230                                                 }
1231                                                 else {
1232                                                         printf $i" "
1233                                                 }
1234                                         }
1235                                         exit
1236                                  }' )"
1237                                 IRC_CLIENT="KVIrc"
1238                                 ;;
1239                         kopete)
1240                                 IRC_CLIENT_VERSION=" $( kopete -v | gawk '
1241                                 /Kopete:/ {
1242                                         print $2
1243                                         exit
1244                                 }' )"
1245                                 IRC_CLIENT="Kopete"
1246                                 ;;
1247                         perl*|ksirc|dsirc)
1248                                 unset IRC_CLIENT_VERSION
1249                                 # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
1250                                 get_cmdline $PPID
1251                                 for (( i=0; i <= $CMDL_MAX; i++ ))
1252                                 do
1253                                         case ${A_CMDL[i]} in
1254                                                 *dsirc*)
1255                                                 IRC_CLIENT="KSirc"
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 '
1265                                                 /KSirc:/ {
1266                                                         print $2
1267                                                         exit
1268                                                 }' )"
1269                                                 break
1270                                                 ;;
1271                                         esac
1272                                 done
1273                                 if [[ -z $IRC_CLIENT_VERSION ]];then
1274                                         IRC_CLIENT="Unknown Perl client"
1275                                 fi
1276                                 ;;
1277                         bash|dash|sh)
1278                                 unset IRC_CLIENT_VERSION
1279                                 IRC_CLIENT="Shell wrapper"
1280                                 ;;
1281                         *)
1282                                 IRC_CLIENT="Unknown : ${irc_client_path##*/}"
1283                                 unset IRC_CLIENT_VERSION
1284                                 ;;
1285                 esac
1286                 if [[ $SHOW_IRC -lt 2 ]];then
1287                         unset IRC_CLIENT_VERSION
1288                 fi
1289         else
1290                 IRC_CLIENT="PPID=\"$PPID\" - empty?"
1291                 unset IRC_CLIENT_VERSION
1292         fi
1293 }
1294
1295 # Parse the null separated commandline under /proc/<pid passed in $1>/cmdline
1296 # args: $1 - $PPID
1297 get_cmdline()
1298 {
1299         local i=0 ppid=$1
1300
1301         if [[ ! -e /proc/$ppid/cmdline ]];then
1302                 echo 0
1303                 return
1304         fi
1305         ##print_screen_output "Marker"
1306         ##print_screen_output "\$ppid='$ppid' -=- $(< /proc/$ppid/cmdline)"
1307         unset A_CMDL
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 ]]
1310         do
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
1317                         i=1
1318                 fi
1319         fi
1320         CMDL_MAX=$i
1321 }
1322
1323 #### -------------------------------------------------------------------
1324 #### get data types
1325 #### -------------------------------------------------------------------
1326 ## create array of sound cards installed on system, and if found, use asound data as well
1327 get_audio_data()
1328 {
1329         local i='' alsa_data='' alsa_driver='' device_count=''
1330         local usb_proc_file='' array_count='' usb_id='' usb_data=''
1331
1332         IFS=$'\n'
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 ']: ' '
1337                 BEGIN {
1338                         IGNORECASE=1
1339                 }
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 != "" ){
1346                                 print driver
1347                         }
1348                 }'  $DIR_ASOUND_DEVICE )
1349         fi
1350
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" '
1357         BEGIN {
1358                 IGNORECASE=1
1359         }
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)
1367
1368                 cards[audioCard]++
1369
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) ""
1374                         }
1375                         else if (/kernel modules:/) {
1376                                 modules[audioCard] = modules[audioCard] gensub(/(.*): (.*)/,"\\2","g",$0) ""
1377                         }
1378                         else if (/I\/O/) {
1379                                 portsTemp = gensub(/\t*I\/O ports at (.*) \[.*\]/,"\\1","g",$0)
1380                                 ports[audioCard] = ports[audioCard] portsTemp " "
1381                         }
1382                 }
1383         }
1384
1385         END {
1386                 j=0
1387                 for (i in cards) {
1388                         useDrivers=""
1389                         useModules=""
1390                         usePorts=""
1391                         if (cards[i]>1) {
1392                                 a[j]=cards[i]"x "i
1393                                 if (drivers[i] != "") {
1394                                         useDrivers=drivers[i]
1395                                 }
1396                                 if (ports[i] != "") {
1397                                         usePorts = ports[i]
1398                                 }
1399                                 if (modules[i] != "" ) {
1400                                         useModules = modules[i]
1401                                 }
1402                         }
1403                         else {
1404                                 a[j]=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]
1409                                 }
1410                                 else if ( alsaDriver != "" ) {
1411                                         useDrivers=alsaDriver
1412                                 }
1413                                 if (ports[i] != "") {
1414                                         usePorts=ports[i]
1415                                 }
1416                                 if (modules[i] != "" ) {
1417                                         useModules = modules[i]
1418                                 }
1419                         }
1420                         # create array primary item for master array
1421                         print a[j] "," useDrivers "," usePorts "," useModules
1422                         j++
1423                 }
1424         }') )
1425
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 ']: ' '
1429                 BEGIN {
1430                         IGNORECASE=1
1431                 }
1432                 $1 !~ /modem/ && $2 !~ /modem/ {
1433                         card=gensub( /^(.+)( - )(.+)$/, "\\3", 1, $2 )
1434                         driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
1435                         if ( card != "" ){
1436                                 print card","driver
1437                         }
1438                 }'  $DIR_ASOUND_DEVICE ) )
1439         fi
1440
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/*
1444         do
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" )
1452                         usb_data=$( gawk '{
1453                                 gsub( /,/, " ", $0 )
1454                                 for( i=7; i <= NF; i++ ) {
1455                                         printf( $i " " )
1456                                 }
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,,"
1464                         fi
1465                 fi
1466         done
1467         IFS="$ORIGINAL_IFS"
1468
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!'
1472         fi
1473 }
1474
1475 get_audio_alsa_data()
1476 {
1477         local alsa_data=''
1478
1479         # now we'll get the alsa data if the file exists
1480         if [[ $B_ASOUND_VERSION == 'true' ]];then
1481                 alsa_data=$( gawk '
1482                         BEGIN {
1483                                 IGNORECASE=1
1484                         }
1485                         # some alsa strings have the build date in (...)
1486                         # remove trailing . and remove possible second line if compiled by user
1487                         $0 !~ /compile/ {
1488                                 gsub( "Driver | [(].*[)]|\.$","",$0 )
1489                                 gsub(/,/, " ", $0)
1490                                 gsub(/^ +| +$/, "", $0)
1491                                 gsub(/ [ \t]+/, " ", $0)
1492                                 if ( $0 != "" ){
1493                                         print $0
1494                                 }
1495                 }' $DIR_ASOUND_VERSION )
1496         fi
1497         echo "$alsa_data"
1498 }
1499
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()
1503 {
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]}
1512
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';;
1526                 esac
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" )
1530         fi
1531 }
1532
1533 ## main cpu data collector
1534 get_cpu_data()
1535 {
1536         local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits=''
1537
1538         if [[ $B_CPUINFO == 'true' ]];then
1539                 IFS=$'\n'
1540                 A_CPU_DATA=( $( gawk -F': ' '
1541                 BEGIN {
1542                         IGNORECASE=1
1543                 }
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]+:/ {
1548                         nr = $NF
1549                 }
1550
1551                 /^model name|^cpu\t+:/ {
1552                         gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
1553                         gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
1554                         gsub(/,/, " ", $NF)
1555                         gsub(/^ +| +$/, "", $NF)
1556                         gsub(/ [ \t]+/, " ", $NF)
1557                         cpu[nr, "model"] = $NF
1558                 }
1559
1560                 /^cpu MHz|^clock\t+:/ {
1561                         if (!min) {
1562                                 min = $NF
1563                         }
1564                         else {
1565                                 if ($NF < min) {
1566                                         min = $NF
1567                                 }
1568                         }
1569
1570                         if ($NF > max) {
1571                                 max = $NF
1572                         }
1573                         gsub(/MHZ/,"",$NF) ## clears out for cell cpu
1574                         gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros
1575                         cpu[nr, "speed"] = $NF
1576                 }
1577
1578                 /^cache size/ {
1579                         cpu[nr, "cache"] = $NF
1580                 }
1581
1582                 /^flags/ {
1583                         cpu[nr, "flags"] = $NF
1584                 }
1585
1586                 /^bogomips/ {
1587                         cpu[nr, "bogomips"] = $NF
1588                 }
1589
1590                 /vendor_id/ {
1591                         gsub(/genuine|authentic/,"",$NF)
1592                         cpu[nr, "vendor"] = tolower( $NF )
1593                 }
1594
1595                 END {
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"]
1599                         }
1600                         if (!min) {
1601                                 print "not found"
1602                                 exit
1603                         }
1604                         if (min != max) {
1605                                 printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz")
1606                         }
1607                         else {
1608                                 printf("%s %s\n", max, "Mhz")
1609                         }
1610                 }' $DIR_CPUINFO ) )
1611         fi
1612
1613         IFS="$ORIGINAL_IFS"
1614 #       echo getMainCpu: ${[@]}
1615 }
1616
1617 ## this is for counting processors and finding HT types
1618 get_cpu_ht_multicore_smp_data()
1619 {
1620         # in /proc/cpuinfo
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)
1625
1626         if [[ $B_CPUINFO == 'true' ]]; then
1627                 A_CPU_TYPE_PCNT_CCNT=( $(
1628                 gawk '
1629                 BEGIN {
1630                         FS=": "
1631                         IGNORECASE = 1
1632                         core_count = 0
1633                         i = 0
1634                         index_temp = ""
1635                         num_of_cores = 0
1636                         physical_cpu_count = 0
1637                         processor_logical_count = 0
1638                         processors = 1
1639                         type = "UP"
1640                 }
1641                 # counts logical processors, both HT and physical
1642                 /^processor/ {
1643                         processor_logical_count = $NF + 1
1644                 }
1645                 # counts physical cores (not used currently)
1646                 /^cpu cores/ {
1647                         num_of_cores = $NF
1648                 }
1649                 # array of physical cpus ids
1650                 /^physical/ {
1651                         a_physical_id[i] = $NF
1652                 }
1653                 # array of core ids
1654                 /^core id/ {
1655                         a_core_id[i] = $NF
1656                         i++
1657                 }
1658                 END {
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]
1663                                 }
1664                         }
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]
1671                         }
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
1675                         }
1676
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
1682                                 }
1683                                 else if ( processor_logical_count > core_count ) {
1684                                         type = "HT"  # this is more than likely a P4 w/HT or an Atom 270
1685                                 }
1686                                 else {
1687                                         type = "SMP"
1688                                 }
1689                         }
1690                         # make sure to handle up cpus too
1691                         else {
1692                                 core_count = 1
1693                                 physical_cpu_count = 1
1694                         }
1695                         print type " " physical_cpu_count " " core_count
1696                 }
1697                 ' $DIR_CPUINFO
1698                 ) )
1699         fi
1700 }
1701
1702 # for more on distro id, please reference this python thread: http://bugs.python.org/issue1322
1703 ## return distro name/id if found
1704 get_distro_data()
1705 {
1706         local i='' j='' distro='' distro_file='' a_distro_glob=''
1707
1708         # get the wild carded array of release/version /etc files if present
1709         shopt -s nullglob
1710         cd /etc
1711         a_distro_glob=(*[-_]{release,version})
1712         cd "$OLDPWD"
1713         shopt -u nullglob
1714
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
1720                 do
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
1730                                 ##
1731                                 if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_DIR == 'true' ]];then
1732                                         distro_file='lsb-release'
1733                                 else
1734                                         distro_file="${i}"
1735                                 fi
1736                                 break
1737                         fi
1738                 done
1739         fi
1740
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 )
1758                 else
1759                         distro=$( gawk '
1760                         BEGIN {
1761                                 RS=""
1762                         }
1763                         {
1764                                 gsub(/\\[a-z]/, "")
1765                                 gsub(/,/, " ")
1766                                 gsub(/^ +| +$/, "")
1767                                 gsub(/ [ \t]+/, " ")
1768                                 print
1769                         }' /etc/issue )
1770                 fi
1771         fi
1772
1773         if [[ ${#distro} -gt 80 ]] &&  [[ $B_HANDLE_CORRUPT_DATA != 'true' ]];then
1774                 distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}"
1775         fi
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 )
1782         fi
1783         ## finally, if all else has failed, give up
1784         if [[ -z $distro ]];then
1785                 distro='Unknown distro o_O'
1786         fi
1787
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
1790                 distro='Arch Linux'
1791         fi
1792
1793         echo "$distro"
1794 }
1795
1796 # args: $1 - optional, app, uses the app test, not being used now
1797 get_distro_lsb_data()
1798 {
1799         local distro=''
1800
1801         if [[ $B_LSB_DIR == 'true' ]] && [[ $1 != 'app' ]];then
1802                 distro=$( gawk -F '=' '
1803                 BEGIN {
1804                         IGNORECASE=1
1805                 }
1806                 # note: adding the spacing directly to variable to make sure distro output is null if not found
1807                 /^DISTRIB_ID/ {
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"
1812                         }
1813                         else if ( $NF != "n/a" ) {
1814                                 distroId = $NF " "
1815                         }
1816                 }
1817                 /^DISTRIB_RELEASE/ {
1818                         gsub(/^ +| +$/, "", $NF)
1819                         if ( $NF != "n/a" ) {
1820                                 distroRelease = $NF " "
1821                         }
1822                 }
1823                 /^DISTRIB_CODENAME/ {
1824                         gsub(/^ +| +$/, "", $NF)
1825                         if ( $NF != "n/a" ) {
1826                                 distroCodename = $NF " "
1827                         }
1828                 }
1829                 END {
1830                         print distroId distroRelease distroCodename
1831                 }' $DIR_LSB_RELEASE )
1832         fi
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 '
1836 #               { IGNORECASE=1 }
1837 #               /^Distributor ID/ {
1838 #                       gsub(/^ +| +$/, "", $NF)
1839 #                       distroId = $NF
1840 #               }
1841 #               /^Release/ {
1842 #                       gsub(/^ +| +$/, "", $NF)
1843 #                       distroRelease = $NF
1844 #               }
1845 #               /^Codename/ {
1846 #                       gsub(/^ +| +$/, "", $NF)
1847 #                       distroCodename = $NF
1848 #               }
1849 #               END {
1850 #                       print distroId " " distroRelease " (" distroCodename ")"
1851 #               }' )
1852 #       fi
1853
1854         echo $distro
1855 }
1856
1857 ## create array of gfx cards installed on system
1858 get_graphics_card_data()
1859 {
1860         local i=''
1861
1862         IFS=$'\n'
1863         A_GFX_CARD_DATA=( $( echo "$Lspci_Data" | gawk -F': ' '
1864         BEGIN {
1865                 IGNORECASE=1
1866         }
1867         /vga compatible controller/ {
1868                 gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
1869                 gsub(/,/, " ", $NF)
1870                 gsub(/^ +| +$/, "", $NF)
1871                 gsub(/ [ \t]+/, " ", $NF)
1872                 print $NF
1873         }' ) )
1874         IFS="$ORIGINAL_IFS"
1875 #       for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
1876 #       do
1877 #               A_GFX_CARD_DATA[i]=$( sanitize_characters BAN_LIST_NORMAL "${A_GFX_CARD_DATA[i]}" )
1878 #       done
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!'
1882         fi
1883
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]"
1886 }
1887
1888 ## create array of glx data
1889 get_graphics_glx_data()
1890 {
1891         if [[ $B_X_RUNNING == 'true' ]];then
1892                 IFS=$'\n'
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 ) {
1905                         s=""
1906                         i=flag=0
1907                         for ( i in arr ) {
1908                                 if ( flag++ ) {
1909                                         s = s sep
1910                                 }
1911                                 s = s i
1912                         }
1913                         return s
1914                 }
1915
1916                 BEGIN {
1917                         IGNORECASE=1
1918                 }
1919                 /opengl renderer/ {
1920                         if ( $2 ~ /mesa/ ) {
1921                                 # Allow all mesas
1922 #                               if ( $2 ~ / r[3-9][0-9][0-9] / ) {
1923                                         gsub(/'"$BAN_LIST_NORMAL"'/, "", $2)
1924                                         a[$2]
1925                                         # this counter failed in one case, a bug, and is not needed now
1926 #                                       f++
1927 #                               }
1928                                 next
1929                         }
1930                         $2 && a[$2]
1931                 }
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/ ) {
1935                 /opengl version/ {
1936                         $2 && b[$2]
1937                 }
1938                 /direct rendering/ {
1939                         $2 && c[$2]
1940                 }
1941                 END {
1942                         printf( "%s\n%s\n%s\n", join( a, ", " ), join( b, ", " ), join( c, ", " ) )
1943                 }' ) )
1944                 IFS="$ORIGINAL_IFS"
1945
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)}}')
1948         fi
1949 }
1950
1951 ## return screen resolution / tty resolution
1952 get_graphics_res_data()
1953 {
1954         local screen_resolution=''
1955
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 '
1960                 /\*/ {
1961                         res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0)
1962                 }
1963                 END {
1964                         for (n in res) {
1965                                 if (res[n] ~ /^[[:digit:]]+x[[:digit:]]+/) {
1966                                         line = line ? line ", " res[n] : res[n]
1967                                 }
1968                         }
1969                         if (line) {
1970                                 print(line)
1971                         }
1972                 }' )
1973                 if [[ -z $screen_resolution ]];then
1974                         screen_resolution=$( xdpyinfo | gawk '
1975                         /dimensions/ {
1976                                 print $2
1977                         }' )
1978                 fi
1979         else
1980                 screen_resolution=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{ print $2"x"$1 }' )
1981         fi
1982         echo "$screen_resolution"
1983 }
1984
1985 ## for possible future data, not currently used
1986 get_graphics_agp_data()
1987 {
1988         local agp_module=''
1989
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))
1995                 }' $DIR_MODULES )
1996         fi
1997 }
1998
1999 ## create array of x vendor/version data
2000 get_graphics_x_data()
2001 {
2002         local x_vendor='' x_version=''
2003
2004         if [[ $B_X_RUNNING == 'true' ]];then
2005                 # X vendor and version detection.
2006                 x_vendor=$( xdpyinfo | gawk -F': +' '
2007                 BEGIN {
2008                         IGNORECASE=1
2009                 }
2010                 /vendor string/ {
2011                         gsub(/the|inc|foundation|project|corporation/, "", $2)
2012                         gsub(/,/, " ", $2)
2013                         gsub(/^ +| +$/, "", $2)
2014                         gsub(/ [ \t]+/, " ", $2)
2015                         print $2
2016                 }' )
2017
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': +' '
2024                         BEGIN {
2025                                 IGNORECASE=1
2026                         }
2027                         /vendor release number/ {
2028                                 gsub(/0+$/, "", $2)
2029                                 gsub(/0+/, ".", $2)
2030                                 print $2
2031                         }' )
2032                 fi
2033                 A_X_DATA[0]="$x_vendor"
2034                 A_X_DATA[1]="$x_version"
2035
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.
2039         fi
2040 }
2041
2042 # this gets just the raw data, total space/percent used and disk/name/per disk capacity
2043 get_hdd_data_basic()
2044 {
2045         local hdd_used=''
2046
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 !~ /.*\%/ ) {
2054                         getline
2055                 }
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 ~ /.*\%/ ) {
2061                         used += $2
2062                 }
2063                 # otherwise use standard
2064                 else if ( $5 ~ /.*\%/ ) {
2065                         used += $3
2066                 }
2067                 # and if this is not detected, give up, we need user data to debug
2068                 else {
2069                         next
2070                 }
2071         }
2072         END {
2073                 print used
2074         }' )
2075
2076         if [[ -z $hdd_used ]];then
2077                 hdd_used='na'
2078         fi
2079
2080         # create the initial array strings:
2081         # disk-dev, capacity, name, usb or not
2082         # final item is the total of the disk
2083         IFS=$'\n'
2084
2085         if [[ $B_PARTITIONS_DIR == 'true' ]];then
2086                 A_HDD_DATA=( $(
2087                 gawk -v hddused="$hdd_used" '
2088                 /[hs]d[a-z]$/ {
2089                         driveSize = $(NF - 1)*1024/1000**3
2090                         gsub(/,/, " ", driveSize)
2091                         gsub(/^ +| +$/, "", driveSize)
2092                         printf( $NF",%.1fGB,,\n", driveSize )
2093                 }
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  {
2096                 #       size += $3
2097                 # }
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 ) {
2100                         size += $3
2101                 }
2102
2103                 END {
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 )
2109                                 print size "GB,-"
2110                         }
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"
2116                         }
2117                         else {
2118                                 print "NA,-" # print an empty array, this will be further handled in the print out function
2119                         }
2120                 }' $DIR_PARTITIONS
2121                 ) )
2122         fi
2123         IFS="$ORIGINAL_IFS"
2124 }
2125
2126 ## fills out the A_HDD_DATA array with disk names
2127 get_hard_drive_data_advanced()
2128 {
2129         local a_temp_working='' a_temp_scsi='' temp_holder='' temp_name='' i='' j=''
2130         local sd_ls_by_id='' ls_disk_by_id=''
2131
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++ ))
2136                 do
2137                         IFS=","
2138                         a_temp_working=( ${A_HDD_DATA[i]} )
2139                         IFS="$ORIGINAL_IFS"
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 )"
2143                                 else
2144                                         a_temp_working[2]="Name n/a"
2145                                 fi
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++ ))
2148                                 do
2149                                         if [[ $j -gt 0 ]];then
2150                                                 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2151                                         else
2152                                                 A_HDD_DATA[i]="${a_temp_working[$j]}"
2153                                         fi
2154                                 done
2155                         fi
2156                 done
2157         fi
2158
2159         ## then handle libata names
2160         # first get the ata device names, put them into an array
2161         IFS=$'\n'
2162         if [[ $B_SCSI_DIR == 'true' ]]; then
2163                 a_temp_scsi=( $( gawk  '
2164                 BEGIN {
2165                         IGNORECASE=1
2166                 }
2167                 /host/ {
2168                         getline a[$0]
2169                         getline b[$0]
2170                 }
2171                 END {
2172                         for (i in a) {
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] )
2178                                         gsub(/,/, " ", c)
2179                                         gsub(/^ +| +$/, "", c)
2180                                         gsub(/ [ \t]+/, " ", c)
2181                                         #print a[i]
2182                                         # we actually want this data, so leaving this off for now
2183 #                                       if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) {
2184 #                                               continue
2185 #                                       }
2186                                         print c
2187                                 }
2188                         }
2189                 }' $DIR_SCSI ) )
2190         fi
2191         IFS="$ORIGINAL_IFS"
2192
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++ ))
2198                 do
2199                         if [[ -n $( egrep '^sd[a-z]' <<< ${A_HDD_DATA[$i]} ) ]];then
2200                                 IFS=","
2201                                 a_temp_working=( ${A_HDD_DATA[$i]} )
2202                                 IFS="$ORIGINAL_IFS"
2203                                 if [[ ${#a_temp_scsi[@]} -gt 0 ]];then
2204                                         for (( j=0; j < ${#a_temp_scsi[@]}; j++ ))
2205                                         do
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" )
2211
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'
2216                                                         fi
2217                                                         break
2218                                                 else
2219                                                         a_temp_working[2]="Name n/a"
2220                                                 fi
2221                                         done
2222                                 else
2223                                         a_temp_working[2]="Name n/a"
2224                                 fi
2225
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++ ))
2228                                 do
2229                                         if [[ $j -gt 0 ]];then
2230                                                 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2231                                         else
2232                                                 A_HDD_DATA[i]="${a_temp_working[$j]}"
2233                                         fi
2234                                 done
2235                         fi
2236                 done
2237                 unset ls_disk_by_id # and then let's dump the data we don't need
2238         fi
2239 }
2240
2241 get_lspci_data()
2242 {
2243         echo "$( lspci -v | gawk '{
2244                 gsub(/\(prog-if[^)]*\)/,"")
2245                 print
2246         }' )"
2247 }
2248
2249 ## return memory used/installed
2250 get_memory_data()
2251 {
2252         local memory=''
2253
2254         memory=$( gawk '
2255         /^MemTotal:/ {
2256                 tot = $2
2257         }
2258         /^(MemFree|Buffers|Cached):/ {
2259                 notused+=$2
2260         }
2261         END {
2262                 used = tot-notused
2263                 printf("%.1f/%.1fMB\n", used/1024, tot/1024)
2264         }' $DIR_MEMINFO )
2265
2266         echo "$memory"
2267 }
2268
2269 # process and return module version data
2270 get_module_version_number()
2271 {
2272         local module_version=''
2273
2274         if [[ -n $( which modinfo ) ]];then
2275                 module_version=$( modinfo $1 | gawk '
2276                 BEGIN {
2277                         IGNORECASE=1
2278                 }
2279                 /^version/ {
2280                         gsub(/,/, " ", $2)
2281                         gsub(/^ +| +$/, "", $2)
2282                         gsub(/ [ \t]+/, " ", $2)
2283                         print $2
2284                 }
2285                 ' )
2286         fi
2287
2288         echo "$module_version"
2289 }
2290
2291 ## create array of network cards
2292 get_networking_data()
2293 {
2294         IFS=$'\n'
2295         A_NETWORK_DATA=( $( echo "$Lspci_Data" | gawk '
2296         BEGIN {
2297                 IGNORECASE=1
2298         }
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)
2305                 gsub(/,/, " ", nic)
2306                 gsub(/^ +| +$/, "", nic)
2307                 gsub(/ [ \t]+/, " ", nic)
2308
2309                 eth[nic]++
2310                 while (getline && !/^$/) {
2311                         if (/I\/O/) {
2312                                 ports[nic] = ports[nic] $4 " "
2313                         }
2314                         if (/driver in use/) {
2315                                 drivers[nic] = drivers[nic] gensub(/(.*): (.*)/,"\\2","g",$0) ""
2316                         }
2317                         else if (/kernel modules/) {
2318                                 modules[nic] = modules[nic] gensub(/(.*): (.*)/,"\\2","g",$0) ""
2319                         }
2320                 }
2321         }
2322
2323         END {
2324                 j=0
2325                 for (i in eth) {
2326                         useDrivers=""
2327                         usePorts=""
2328                         useModules=""
2329                         if (eth[i]>1) {
2330                                 a[j]=eth[i]"x "i
2331                                 ## note: this loses the plural ports case, is it needed anyway?
2332                                 if (ports[i] != "") {
2333                                         usePorts=ports[i]
2334                                 }
2335                                 if (drivers[i] != "") {
2336                                         useDrivers=drivers[i]
2337                                 }
2338                                 if (modules[i] != "" ) {
2339                                         useModules = modules[i]
2340                                 }
2341                         }
2342                         else {
2343                                 a[j]=i
2344                                 if (ports[i] != "") {
2345                                         usePorts=ports[i]
2346                                 }
2347                                 if (drivers[i] != "") {
2348                                         useDrivers=drivers[i]
2349                                 }
2350                                 if (modules[i] != "" ) {
2351                                         useModules = modules[i]
2352                                 }
2353                         }
2354                         # create array primary item for master array
2355                         print a[j] "," useDrivers "," usePorts "," useModules
2356                         j++
2357                 }
2358         }') )
2359         IFS="$ORIGINAL_IFS"
2360 }
2361
2362 get_networking_wan_ip_data()
2363 {
2364         local ip=''
2365
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: ' '{
2368                 #gsub("\n","",$2")
2369                 print $2
2370         }' )
2371
2372         if [[ -z $ip ]];then
2373                 ip='None Detected!'
2374         fi
2375         echo "$ip"
2376 }
2377
2378 get_networking_local_ip_data()
2379 {
2380         if [[ $B_IFCONFIG == 'true' ]];then
2381                 IFS=$'\n'
2382                 A_INTERFACES_DATA=( $( $DIR_IFCONFIG | gawk '
2383                 BEGIN {
2384                         IGNORECASE=1
2385                 }
2386                 $0 !~ /^lo/ {
2387                         # not clear on why inet is coming through, but this gets rid of it
2388                         # as first line item.
2389                         interface = $1
2390                         gsub(/,/, " ", interface)
2391                         gsub(/^ +| +$/, "", interface)
2392                         gsub(/ [ \t]+/, " ", interface)
2393
2394                         aInterfaces[interface]++
2395                         while (getline && !/^$/) {
2396                                 if (/inet addr:/) {
2397                                         ipAddresses[interface] = gensub( /addr:([0-9\.]+)/, "\\1", "g", $2 )
2398                                 }
2399                         }
2400                 }
2401
2402                 END {
2403                         j=0
2404                         for (i in aInterfaces) {
2405                                 useInterfaceIp = ""
2406                                 a[j] = i
2407                                 if (ipAddresses[i] != "") {
2408                                         useInterfaceIp = ipAddresses[i]
2409                                 }
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
2415                                 }
2416                                 j++
2417                         }
2418                 }') )
2419                 IFS="$ORIGINAL_IFS"
2420         fi
2421 }
2422
2423 get_partition_data()
2424 {
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
2427
2428         IFS=$'\n'
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 '
2434         BEGIN {
2435                 IGNORECASE=1
2436         }
2437         # this has to be nulled for every iteration so it does not retain value from last iteration
2438         devBase=""
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
2444                 if ( NF == 1 ){
2445                         devBase=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
2446                 }
2447                 getline
2448         }
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
2453         }
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
2462                 }
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
2466                 }
2467                 else if ( $(NF - 3) ~ /[0-9]+\%/ ) {
2468                         print $(NF - 2) " " $(NF - 1) " " $NF "," $(NF - 6) "," $(NF - 5) "," $(NF - 3) ",secondary," devBase
2469                 }
2470         }
2471         ' )
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 '
2476         BEGIN {
2477                 swapCounter = 1
2478         }
2479         /^\/dev/ {
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
2486         }' ) )
2487         IFS="$ORIGINAL_IFS"
2488
2489         if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
2490                 get_partition_data_advanced
2491         fi
2492 }
2493
2494 # first get the locations of the mount points for label/uuid detection
2495 get_partition_data_advanced()
2496 {
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=''
2500
2501         if [[ -d /dev/disk/by-label ]];then
2502                 dev_disk_label="$( ls -l /dev/disk/by-label )"
2503         fi
2504         if [[ -d /dev/disk/by-uuid ]];then
2505                 dev_disk_uuid="$( ls -l /dev/disk/by-uuid )"
2506         fi
2507
2508         if [[ $B_MOUNTS_DIR == 'true' ]];then
2509                 for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
2510                 do
2511                         IFS=","
2512                         a_partition_working=( ${A_PARTITION_DATA[i]} )
2513                         IFS="$ORIGINAL_IFS"
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 '
2519                                 BEGIN {
2520                                         IGNORECASE = 1
2521                                         partition = ""
2522                                         partTemp = ""
2523                                 }
2524                                 # trying to handle space in name
2525 #                               gsub( /\\040/, " ", $0 )
2526                                 /[ \t]'$mount_point'[ \t]/ && $1 != "rootfs" {
2527                                         # initialize the variables
2528                                         label = ""
2529                                         uuid = ""
2530
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 )
2536                                                 partition = ""
2537                                         }
2538                                         if ( partition ~ /by-uuid/ ) {
2539                                                 uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, $1 )
2540                                                 partition = ""
2541                                         }
2542
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 )
2550                                                         }
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
2554                                                         }
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
2558                                                         }
2559                                                 }
2560                                                 else {
2561                                                         partition = ""
2562                                                         label = ""
2563                                                         uuid = ""
2564                                                 }
2565                                         }
2566                                         print partition "," label "," uuid
2567                                 }'      $DIR_MOUNTS )
2568
2569 #                               echo dev_partition_data: $dev_partition_data
2570                                 # assemble everything we could get for dev/h/dx, label, and uuid
2571                                 IFS=","
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
2573                                 IFS="$ORIGINAL_IFS"
2574                         fi
2575                         ## now we're ready to proceed filling in the data
2576                         IFS=","
2577                         a_partition_working=( ${A_PARTITION_DATA[i]} )
2578                         IFS="$ORIGINAL_IFS"
2579
2580                         dev_item=${a_partition_working[5]}
2581                         dev_label=${a_partition_working[6]}
2582                         dev_uuid=${a_partition_working[7]}
2583
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 '
2590                                         /'$dev_uuid'/ {
2591                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
2592                                                 print item
2593                                         }' )
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
2599                                         /'$dev_label'/ {
2600                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
2601                                                 print item
2602                                         }' )
2603                         fi
2604                         if [[ -n $dev_disk_uuid ]] && [[ -n $dev_item && -z $dev_uuid ]];then
2605                                 dev_uuid=$( echo "$dev_disk_uuid" | gawk '
2606                                 /'$dev_item'$/ {
2607                                         print $(NF - 2)
2608                                 }' )
2609                         fi
2610                         if [[ -n $dev_disk_label ]] && [[ -n $dev_item && -z $dev_label ]];then
2611                                 dev_label=$( echo "$dev_disk_label" | gawk '
2612                                 /'$dev_item'/ {
2613                                         print $(NF - 2)
2614                                 }' )
2615
2616                         fi
2617                         # assemble everything we could get for dev/h/dx, label, and uuid
2618                         IFS=","
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
2620                         IFS="$ORIGINAL_IFS"
2621                 done
2622         fi
2623 }
2624
2625 ## return uptime string
2626 get_uptime()
2627 {
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)
2631                 print a
2632         }' )
2633 }
2634
2635 #### -------------------------------------------------------------------
2636 #### special data handling for specific options and conditions
2637 #### -------------------------------------------------------------------
2638
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()
2642 {
2643         local string_number=$1 string_data=''
2644
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 )
2648         fi
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 '{
2652                         total = $1*$2
2653                         print total
2654                 }' )
2655         elif [[ $string_number == '' ]];then
2656                 string_number='Not Available'
2657         else
2658                 # I believe that the above returns 'unknown' by default so no need for extra text
2659                 string_number="$string_number "
2660         fi
2661         echo "$string_number$string_data"
2662 }
2663
2664 # prints out shortened list of flags, the main ones of interest
2665 # args: $1 - string of cpu flags to process
2666 process_cpu_flags()
2667 {
2668         local cpu_flags="$1"
2669
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 '
2676         BEGIN {
2677                 RS=" "
2678                 ssel["sse"] = 1
2679                 ssel["sse2"] = 2
2680                 ssel["pni"] = 3
2681                 sses[1] = "sse"
2682                 sses[2] = "sse2"
2683                 sses[3] = "sse3"
2684         }
2685         /^(nx|lm|svm|vmx)$/ {
2686                         if (s) {
2687                                 s = s " " $0
2688                         }
2689                         else {
2690                                 s = $0
2691                         }
2692         }
2693         /^(sse2?|pni)$/ {
2694                 if (ssel[$0] > sse) {
2695                         sse = ssel[$0]
2696                 }
2697         }
2698         END {
2699                 if (sse) {
2700                         if (s) {
2701                                 s = sses[sse] " " s
2702                         }
2703                         else {
2704                                 s = sses[sse]
2705                         }
2706                 }
2707                 print s
2708         }' )
2709
2710         #grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
2711         if [[ -z $cpu_flags ]];then
2712                 cpu_flags="-"
2713         fi
2714         echo "$cpu_flags"
2715 }
2716
2717 #### -------------------------------------------------------------------
2718 #### print and processing of output data
2719 #### -------------------------------------------------------------------
2720
2721 #### MASTER PRINT FUNCTION - triggers all line item print functions
2722 ## main function to print out, master for all sub print functions.
2723 print_it_out()
2724 {
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
2728
2729         if [[ $B_SHOW_SHORT_OUTPUT == 'true' ]];then
2730                 print_short_data
2731         else
2732                 Lspci_Data="$( get_lspci_data )"
2733                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_SYSTEM == 'true' ]];then
2734                         print_system_data
2735                 fi
2736                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_CPU == 'true' ]];then
2737                         print_cpu_data
2738                 fi
2739                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_GRAPHICS == 'true' ]];then
2740                         print_gfx_data
2741                 fi
2742                 if [[ $VERBOSITY_LEVEL -ge 5 || $B_SHOW_AUDIO == 'true' ]];then
2743                         print_audio_data
2744                 fi
2745                 if [[ $VERBOSITY_LEVEL -ge 2 || $B_SHOW_NETWORK == 'true' ]];then
2746                         print_networking_data
2747                 fi
2748                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_DISK == 'true' ]];then
2749                         print_hard_disk_data
2750                 fi
2751                 if [[ $VERBOSITY_LEVEL -ge 4 || $B_SHOW_PARTITIONS == 'true' ]];then
2752                         print_partition_data
2753                 fi
2754                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_INFO == 'true' ]];then
2755                         print_info_data
2756                 fi
2757         fi
2758 }
2759
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
2763 print_short_data()
2764 {
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 )"
2770
2771         # set A_CPU_CORE_DATA
2772         get_cpu_core_count
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]}
2778
2779         if [[ $cpu_physical_count -gt 1 ]];then
2780                 cpc_plural='(s)'
2781                 model_plural='s'
2782                 cpu_count_print="$cpu_physical_count "
2783         fi
2784
2785         local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
2786 #       local cpu_core_count=${A_CPU_CORE_DATA[0]}
2787
2788         # load A_HDD_DATA
2789         get_hdd_data_basic
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 ))
2793         IFS=","
2794         local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
2795         IFS="$ORIGINAL_IFS"
2796         local hdd_capacity=${a_hdd_basic_working[0]}
2797         local hdd_used=${a_hdd_basic_working[1]}
2798
2799         # load A_CPU_DATA
2800         get_cpu_data
2801
2802         IFS=","
2803         local a_cpu_working=(${A_CPU_DATA[0]})
2804         IFS="$ORIGINAL_IFS"
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]}
2811
2812         #set_color_scheme 12
2813         if [[ $B_RUNNING_IN_SHELL == 'false' ]];then
2814                 for i in $C1 $C2 $CN
2815                 do
2816                         case "$i" in
2817                                 "$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN")
2818                                         b_background_black='true'
2819                                         ;;
2820                         esac
2821                 done
2822                 if [[ $b_background_black == 'true' ]];then
2823                         for i in C1 C2 CN
2824                         do
2825                                 ## these need to be in quotes, don't know why
2826                                 if [[ ${!i} == $NORMAL ]];then
2827                                         declare $i="${!i}15,1"
2828                                 else
2829                                         declare $i="${!i},1"
2830                                 fi
2831                         done
2832                         #C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
2833                 fi
2834         fi
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}]"
2836
2837         if [[ $SHOW_IRC -gt 0 ]];then
2838                 short_data="${short_data} ${C1}Client${CN}[${C2}${SEP1}${IRC_CLIENT}${IRC_CLIENT_VERSION}${SEP1}${CN}]"
2839         fi
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"
2843         fi
2844         print_screen_output "$short_data"
2845 }
2846
2847 #### LINE ITEM PRINT FUNCTIONS
2848
2849 # print sound card data
2850 print_audio_data()
2851 {
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
2855         get_audio_data
2856         alsa_data=$( get_audio_alsa_data )
2857         IFS=","
2858         a_audio_working=(${A_AUDIO_DATA[0]})
2859         IFS="$ORIGINAL_IFS"
2860
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
2864                         card_one='Card '
2865                 fi
2866
2867 #               if [[ -n ${a_audio_working[2]} ]];then
2868 #                       port_data=" ${C1}at port${C2} ${a_audio_working[2]}"
2869 #               fi
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]}" )
2873                 fi
2874                 if [[ -n ${a_audio_working[1]} ]];then
2875                         alsa_driver=" ${C1}driver${C2} ${a_audio_working[1]}$module_version"
2876                 fi
2877                 if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
2878                         if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
2879                                 port_plural='s'
2880                         fi
2881                         port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
2882                 fi
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]} ]]
2888                 do
2889                         IFS=","
2890                         a_audio_working=( ${A_AUDIO_DATA[i]} )
2891                         IFS="$ORIGINAL_IFS"
2892                         port_data=''
2893                         alsa_driver=''
2894                         port_plural=''
2895                         module_version=''
2896                         if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
2897                                 module_version=$( print_module_version "${a_audio_working[3]}" )
2898                         fi
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]}"
2902                         fi
2903                         if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
2904                                 if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
2905                                         port_plural='s'
2906                                 fi
2907                                 port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
2908                         fi
2909                         if [[ -n ${a_audio_working[0]} ]];then
2910                                 audio_data="${C1}Card-$(( $i + 1 )) ${C2}${a_audio_working[0]}$alsa_driver$port_data"
2911                         fi
2912                         if [[ -n $audio_data ]];then
2913                                 audio_data=$( create_print_line " " "$audio_data" )
2914                                 print_screen_output "$audio_data"
2915                         fi
2916                 done
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"
2922                 fi
2923         fi
2924 }
2925
2926 print_cpu_data()
2927 {
2928         local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data=''
2929         local bmip_data='' cpu_cache='' cpu_vendor='' cpu_flags=''
2930
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
2934         # load A_CPU_DATA
2935         get_cpu_data
2936
2937         IFS=","
2938         local a_cpu_working=(${A_CPU_DATA[0]})
2939         IFS="$ORIGINAL_IFS"
2940         local cpu_model="${a_cpu_working[0]}"
2941         ## assemble data for output
2942         local cpu_clock="${a_cpu_working[1]}"
2943
2944         cpu_vendor=${a_cpu_working[5]}
2945
2946         # set A_CPU_CORE_DATA
2947         get_cpu_core_count
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]}
2953
2954         if [[ $cpu_physical_count