045563bf57f1abb1bb43b6a59865d15274975d7b
[quassel.git] / data / scripts / inxi
1 #!/bin/bash
2 ########################################################################
3 ####  Script Name: inxi
4 ####  version: 1.0.7-b1-t1
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 "    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                 # note: function declarations go before BEGIN? It appears so, confirm.
1895                 function join(arr, sep) {
1896                         s=""
1897                         i=flag=0
1898                         for ( i in arr ) {
1899                                 if ( flag++ ) {
1900                                         s = s sep
1901                                 }
1902                                 s = s i
1903                         }
1904                         return s
1905                 }
1906
1907                 BEGIN {
1908                         IGNORECASE=1
1909                 }
1910                 /opengl renderer/ {
1911                         if ( $2 ~ /mesa/ ) {
1912                                 # Allow r300 et al, but not the rest
1913                                 if ( $2 ~ / r[3-9][0-9][0-9] / ) {
1914                                         a[$2]
1915                                         f++
1916                                 }
1917                                 next
1918                         }
1919                         $2 && a[$2]
1920                 }
1921                 /opengl version/ && ( f || $2 !~ /mesa/ ) {
1922                         $2 && b[$2]
1923                 }
1924                 /direct rendering/ {
1925                         $2 && c[$2]
1926                 }
1927
1928                 END {
1929                         printf("%s\n%s\n%s\n", join(a,", "), join(b,", "), join(c,", "))
1930                 }' ) )
1931                 IFS="$ORIGINAL_IFS"
1932
1933                 # GLXR=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl renderer/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
1934                 #    GLXV=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl version/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
1935         fi
1936 }
1937
1938 ## return screen resolution / tty resolution
1939 get_graphics_res_data()
1940 {
1941         local screen_resolution=''
1942
1943         if [[ $B_X_RUNNING == 'true' ]];then
1944                 # Added the two ?'s , because the resolution is now reported without spaces around the 'x', as in
1945                 # 1400x1050 instead of 1400 x 1050. Change as of X.org version 1.3.0
1946                 screen_resolution=$( xrandr | gawk '
1947                 /\*/ {
1948                         res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0)
1949                 }
1950                 END {
1951                         for (n in res) {
1952                                 if (res[n] ~ /^[[:digit:]]+x[[:digit:]]+/) {
1953                                         line = line ? line ", " res[n] : res[n]
1954                                 }
1955                         }
1956                         if (line) {
1957                                 print(line)
1958                         }
1959                 }' )
1960                 if [[ -z $screen_resolution ]];then
1961                         screen_resolution=$( xdpyinfo | gawk '
1962                         /dimensions/ {
1963                                 print $2
1964                         }' )
1965                 fi
1966         else
1967                 screen_resolution=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{ print $2"x"$1 }' )
1968         fi
1969         echo "$screen_resolution"
1970 }
1971
1972 ## for possible future data, not currently used
1973 get_graphics_agp_data()
1974 {
1975         local agp_module=''
1976
1977         if [[ B_MODULES_DIR == 'true' ]];then
1978                 ## not used currently
1979                 agp_module=$( gawk '
1980                 /agp/ && !/agpgart/ && $3 > 0 {
1981                         print(gensub(/(.*)_agp.*/,"\\1","g",$1))
1982                 }' $DIR_MODULES )
1983         fi
1984 }
1985
1986 ## create array of x vendor/version data
1987 get_graphics_x_data()
1988 {
1989         local x_vendor='' x_version=''
1990
1991         if [[ $B_X_RUNNING == 'true' ]];then
1992                 # X vendor and version detection.
1993                 x_vendor=$( xdpyinfo | gawk -F': +' '
1994                 BEGIN {
1995                         IGNORECASE=1
1996                 }
1997                 /vendor string/ {
1998                         gsub(/the|inc|foundation|project|corporation/, "", $2)
1999                         gsub(/,/, " ", $2)
2000                         gsub(/^ +| +$/, "", $2)
2001                         gsub(/ [ \t]+/, " ", $2)
2002                         print $2
2003                 }' )
2004
2005                 # new method added since radeon and X.org and the disappearance of <X server name> version : ...etc
2006                 # Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2
2007                 # A failover mechanism is in place. (if $x_version is empty, the release number is parsed instead)
2008                 x_version=$( xdpyinfo | gawk '/version:/ { print $NF }' )
2009                 if [[ -z $x_version ]];then
2010                         x_version=$(xdpyinfo | gawk -F': +' '
2011                         BEGIN {
2012                                 IGNORECASE=1
2013                         }
2014                         /vendor release number/ {
2015                                 gsub(/0+$/, "", $2)
2016                                 gsub(/0+/, ".", $2)
2017                                 print $2
2018                         }' )
2019                 fi
2020                 A_X_DATA[0]="$x_vendor"
2021                 A_X_DATA[1]="$x_version"
2022
2023                 #X -version 2>&1 | gawk '/^X Window System Version/ { print $5 }'
2024                 #This method could be used in the future to detect X when X is not running,
2025                 #however currently inxi ignores X checks when X is not found.
2026         fi
2027 }
2028
2029 # this gets just the raw data, total space/percent used and disk/name/per disk capacity
2030 get_hdd_data_basic()
2031 {
2032         local hdd_used=''
2033
2034         hdd_used=$( df --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk '
2035         # also handles odd dm-1 type, from lvm
2036         /^\/dev\/(mapper\/|[hs]d[a-z][0-9]+|dm[-]?[0-9]+)/ {
2037                 # this handles the case where the first item is too long
2038                 # and makes df wrap output to next line, so here we advance
2039                 # it to the next line for that single case
2040                 if ( NF < 5 && $0 !~ /.*\%/ ) {
2041                         getline
2042                 }
2043                 # if the first item caused a wrap, use one less than standard
2044                 # testing for the field with % in it, ie: 34%, then go down from there
2045                 # this also protects against cases where the mount point has a space in the
2046                 # file name, thus breaking going down from $NF directly.
2047                 if ( $4 ~ /.*\%/ ) {
2048                         used += $2
2049                 }
2050                 # otherwise use standard
2051                 else if ( $5 ~ /.*\%/ ) {
2052                         used += $3
2053                 }
2054                 # and if this is not detected, give up, we need user data to debug
2055                 else {
2056                         next
2057                 }
2058         }
2059         END {
2060                 print used
2061         }' )
2062
2063         if [[ -z $hdd_used ]];then
2064                 hdd_used='na'
2065         fi
2066
2067         # create the initial array strings:
2068         # disk-dev, capacity, name, usb or not
2069         # final item is the total of the disk
2070         IFS=$'\n'
2071
2072         if [[ $B_PARTITIONS_DIR == 'true' ]];then
2073                 A_HDD_DATA=( $(
2074                 gawk -v hddused="$hdd_used" '
2075                 /[hs]d[a-z]$/ {
2076                         driveSize = $(NF - 1)*1024/1000**3
2077                         gsub(/,/, " ", driveSize)
2078                         gsub(/^ +| +$/, "", driveSize)
2079                         printf( $NF",%.1fGB,,\n", driveSize )
2080                 }
2081                 # See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
2082                 # $1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0  {
2083                 #       size += $3
2084                 # }
2085                 # special case from this data: 8     0  156290904 sda
2086                 $1 ~ /^(3|22|33|8)$/ && $NF ~ /[hs]d[a-z]$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) {
2087                         size += $3
2088                 }
2089
2090                 END {
2091                         size = size*1024/1000**3                   # calculate size in GB size
2092                         workingUsed = hddused*1024/1000**3         # calculate workingUsed in GB used
2093                         # this handles a special case with livecds where no hdd_used is detected
2094                         if ( size > 0 && hddused == "na" ) {
2095                                 size = sprintf( "%.1f", size )
2096                                 print size "GB,-"
2097                         }
2098                         else if ( size > 0 && workingUsed > 0 ) {
2099                                 diskUsed = workingUsed*100/size  # calculate used percentage
2100                                 diskUsed = sprintf( "%.1f", diskUsed )
2101                                 size = sprintf( "%.1f", size )
2102                                 print size "GB," diskUsed "% used"
2103                         }
2104                         else {
2105                                 print "NA,-" # print an empty array, this will be further handled in the print out function
2106                         }
2107                 }' $DIR_PARTITIONS
2108                 ) )
2109         fi
2110         IFS="$ORIGINAL_IFS"
2111 }
2112
2113 ## fills out the A_HDD_DATA array with disk names
2114 get_hard_drive_data_advanced()
2115 {
2116         local a_temp_working='' a_temp_scsi='' temp_holder='' temp_name='' i='' j=''
2117         local sd_ls_by_id='' ls_disk_by_id=''
2118
2119         ## check for all ide type drives, non libata, only do it if hdx is in array
2120         if [[ -n $( egrep 'hd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
2121                 # remember, we're using the last array item to store the total size of disks
2122                 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
2123                 do
2124                         IFS=","
2125                         a_temp_working=( ${A_HDD_DATA[i]} )
2126                         IFS="$ORIGINAL_IFS"
2127                         if [[ -n $( egrep '^hd[a-z]' <<< ${a_temp_working[0]} ) ]];then
2128                                 if [[ -e /proc/ide/${a_temp_working[0]}/model ]];then
2129                                         a_temp_working[2]="$( remove_erroneous_chars /proc/ide/${a_temp_working[0]}/model )"
2130                                 else
2131                                         a_temp_working[2]="Name n/a"
2132                                 fi
2133                                 # these loops are to easily extend the cpu array created in the awk script above with more fields per cpu.
2134                                 for (( j=0; j < ${#a_temp_working[@]}; j++ ))
2135                                 do
2136                                         if [[ $j -gt 0 ]];then
2137                                                 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2138                                         else
2139                                                 A_HDD_DATA[i]="${a_temp_working[$j]}"
2140                                         fi
2141                                 done
2142                         fi
2143                 done
2144         fi
2145
2146         ## then handle libata names
2147         # first get the ata device names, put them into an array
2148         IFS=$'\n'
2149         if [[ $B_SCSI_DIR == 'true' ]]; then
2150                 a_temp_scsi=( $( gawk  '
2151                 BEGIN {
2152                         IGNORECASE=1
2153                 }
2154                 /host/ {
2155                         getline a[$0]
2156                         getline b[$0]
2157                 }
2158                 END {
2159                         for (i in a) {
2160                                 if (b[i] ~ / *type: *direct-access.*/) {
2161                                         #c=gensub(/^ *vendor: (.+) +model: (.+) +rev: (.+)$/,"\\1 \\2 \\3","g",a[i])
2162                                         #c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i] )
2163                                         # the vendor: string is useless, and is a bug, ATA is not a vendor for example
2164                                         c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/, "\\2", "g", a[i] )
2165                                         gsub(/,/, " ", c)
2166                                         gsub(/^ +| +$/, "", c)
2167                                         gsub(/ [ \t]+/, " ", c)
2168                                         #print a[i]
2169                                         # we actually want this data, so leaving this off for now
2170 #                                       if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) {
2171 #                                               continue
2172 #                                       }
2173                                         print c
2174                                 }
2175                         }
2176                 }' $DIR_SCSI ) )
2177         fi
2178         IFS="$ORIGINAL_IFS"
2179
2180         ## then we'll loop through that array looking for matches.
2181         if [[ -n $( egrep 'sd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
2182                 # first pack the main ls variable so we don't have to keep using ls /dev...
2183                 ls_disk_by_id="$( ls -l /dev/disk/by-id )"
2184                 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
2185                 do
2186                         if [[ -n $( egrep '^sd[a-z]' <<< ${A_HDD_DATA[$i]} ) ]];then
2187                                 IFS=","
2188                                 a_temp_working=( ${A_HDD_DATA[$i]} )
2189                                 IFS="$ORIGINAL_IFS"
2190                                 if [[ ${#a_temp_scsi[@]} -gt 0 ]];then
2191                                         for (( j=0; j < ${#a_temp_scsi[@]}; j++ ))
2192                                         do
2193                                                 ## ok, ok, it's incomprehensible, search /dev/disk/by-id for a line that contains the
2194                                                 # discovered disk name AND ends with the correct identifier, sdx
2195                                                 # get rid of whitespace for some drive names and ids, and extra data after - in name
2196                                                 temp_name=$( tr ' ' '_' <<< ${a_temp_scsi[$j]} | cut -d '-' -f 1 )
2197                                                 sd_ls_by_id=$( egrep -m1 ".*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" )
2198
2199                                                 if [[ -n $sd_ls_by_id ]];then
2200                                                         a_temp_working[2]=${a_temp_scsi[$j]}
2201                                                         if [[ -n $( grep 'usb-' <<< $sd_ls_by_id ) ]];then
2202                                                                 a_temp_working[3]='USB'
2203                                                         fi
2204                                                         break
2205                                                 else
2206                                                         a_temp_working[2]="Name n/a"
2207                                                 fi
2208                                         done
2209                                 else
2210                                         a_temp_working[2]="Name n/a"
2211                                 fi
2212
2213                                 # these loops are to easily extend the cpu array created in the awk script above with more fields per cpu.
2214                                 for (( j=0; j < ${#a_temp_working[@]}; j++ ))
2215                                 do
2216                                         if [[ $j -gt 0 ]];then
2217                                                 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2218                                         else
2219                                                 A_HDD_DATA[i]="${a_temp_working[$j]}"
2220                                         fi
2221                                 done
2222                         fi
2223                 done
2224                 unset ls_disk_by_id # and then let's dump the data we don't need
2225         fi
2226 }
2227
2228 get_lspci_data()
2229 {
2230         echo "$( lspci -v | gawk '{
2231                 gsub(/\(prog-if[^)]*\)/,"")
2232                 print
2233         }' )"
2234 }
2235
2236 ## return memory used/installed
2237 get_memory_data()
2238 {
2239         local memory=''
2240
2241         memory=$( gawk '
2242         /^MemTotal:/ {
2243                 tot = $2
2244         }
2245         /^(MemFree|Buffers|Cached):/ {
2246                 notused+=$2
2247         }
2248         END {
2249                 used = tot-notused
2250                 printf("%.1f/%.1fMB\n", used/1024, tot/1024)
2251         }' $DIR_MEMINFO )
2252
2253         echo "$memory"
2254 }
2255
2256 # process and return module version data
2257 get_module_version_number()
2258 {
2259         local module_version=''
2260
2261         if [[ -n $( which modinfo ) ]];then
2262                 module_version=$( modinfo $1 | gawk '
2263                 BEGIN {
2264                         IGNORECASE=1
2265                 }
2266                 /^version/ {
2267                         gsub(/,/, " ", $2)
2268                         gsub(/^ +| +$/, "", $2)
2269                         gsub(/ [ \t]+/, " ", $2)
2270                         print $2
2271                 }
2272                 ' )
2273         fi
2274
2275         echo "$module_version"
2276 }
2277
2278 ## create array of network cards
2279 get_networking_data()
2280 {
2281         IFS=$'\n'
2282         A_NETWORK_DATA=( $( echo "$Lspci_Data" | gawk '
2283         BEGIN {
2284                 IGNORECASE=1
2285         }
2286         /^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
2287                 nic=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
2288                 gsub(/realtek semiconductor/, "Realtek", nic)
2289                 gsub(/davicom semiconductor/, "Davicom", nic)
2290                 # The doublequotes are necessary because of the pipes in the variable.
2291                 gsub(/'"$BAN_LIST_NORMAL"'/, "", nic)
2292                 gsub(/,/, " ", nic)
2293                 gsub(/^ +| +$/, "", nic)
2294                 gsub(/ [ \t]+/, " ", nic)
2295
2296                 eth[nic]++
2297                 while (getline && !/^$/) {
2298                         if (/I\/O/) {
2299                                 ports[nic] = ports[nic] $4 " "
2300                         }
2301                         if (/driver in use/) {
2302                                 drivers[nic] = drivers[nic] gensub(/(.*): (.*)/,"\\2","g",$0) ""
2303                         }
2304                         else if (/kernel modules/) {
2305                                 modules[nic] = modules[nic] gensub(/(.*): (.*)/,"\\2","g",$0) ""
2306                         }
2307                 }
2308         }
2309
2310         END {
2311                 j=0
2312                 for (i in eth) {
2313                         useDrivers=""
2314                         usePorts=""
2315                         useModules=""
2316                         if (eth[i]>1) {
2317                                 a[j]=eth[i]"x "i
2318                                 ## note: this loses the plural ports case, is it needed anyway?
2319                                 if (ports[i] != "") {
2320                                         usePorts=ports[i]
2321                                 }
2322                                 if (drivers[i] != "") {
2323                                         useDrivers=drivers[i]
2324                                 }
2325                                 if (modules[i] != "" ) {
2326                                         useModules = modules[i]
2327                                 }
2328                         }
2329                         else {
2330                                 a[j]=i
2331                                 if (ports[i] != "") {
2332                                         usePorts=ports[i]
2333                                 }
2334                                 if (drivers[i] != "") {
2335                                         useDrivers=drivers[i]
2336                                 }
2337                                 if (modules[i] != "" ) {
2338                                         useModules = modules[i]
2339                                 }
2340                         }
2341                         # create array primary item for master array
2342                         print a[j] "," useDrivers "," usePorts "," useModules
2343                         j++
2344                 }
2345         }') )
2346         IFS="$ORIGINAL_IFS"
2347 }
2348
2349 get_networking_wan_ip_data()
2350 {
2351         local ip=''
2352
2353         # get ip using wget redirect to stdout. This is a clean, text only IP output url.
2354         ip=$( wget -q -O - http://smxi.org/opt/ip.php | awk -F 'is: ' '{
2355                 #gsub("\n","",$2")
2356                 print $2
2357         }' )
2358
2359         if [[ -z $ip ]];then
2360                 ip='None Detected!'
2361         fi
2362         echo "$ip"
2363 }
2364
2365 get_networking_local_ip_data()
2366 {
2367         if [[ $B_IFCONFIG == 'true' ]];then
2368                 IFS=$'\n'
2369                 A_INTERFACES_DATA=( $( $DIR_IFCONFIG | gawk '
2370                 BEGIN {
2371                         IGNORECASE=1
2372                 }
2373                 $0 !~ /^lo/ {
2374                         # not clear on why inet is coming through, but this gets rid of it
2375                         # as first line item.
2376                         interface = $1
2377                         gsub(/,/, " ", interface)
2378                         gsub(/^ +| +$/, "", interface)
2379                         gsub(/ [ \t]+/, " ", interface)
2380
2381                         aInterfaces[interface]++
2382                         while (getline && !/^$/) {
2383                                 if (/inet addr:/) {
2384                                         ipAddresses[interface] = gensub( /addr:([0-9\.]+)/, "\\1", "g", $2 )
2385                                 }
2386                         }
2387                 }
2388
2389                 END {
2390                         j=0
2391                         for (i in aInterfaces) {
2392                                 useInterfaceIp = ""
2393                                 a[j] = i
2394                                 if (ipAddresses[i] != "") {
2395                                         useInterfaceIp = ipAddresses[i]
2396                                 }
2397                                 # create array primary item for master array
2398                                 # tested needed to avoid bad data from above, if null it is garbage
2399                                 # this is the easiest way to handle junk I found, improve if you want
2400                                 if ( useInterfaceIp != "" ) {
2401                                         print a[j] "," useInterfaceIp
2402                                 }
2403                                 j++
2404                         }
2405                 }') )
2406                 IFS="$ORIGINAL_IFS"
2407         fi
2408 }
2409
2410 get_partition_data()
2411 {
2412         #local excluded_file_types='--exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660'
2413         # df doesn't seem to work in script with variables like at the command line
2414
2415         IFS=$'\n'
2416         # sample line: /dev/sda2     ext3     15G  8.9G  4.9G  65% /home
2417         # $NF = partition name; $(NF - 4) = partition size; $(NF - 3) = used, in gB; $(NF - 1) = percent used
2418         ## note: by subtracting from the last field number NF, we avoid a subtle issue with LVM df output, where if
2419         ## the first field is too long, it will occupy its own line, this way we are getting only the needed data
2420         A_PARTITION_DATA=( $( df -h -T --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk '
2421         BEGIN {
2422                 IGNORECASE=1
2423         }
2424         # this has to be nulled for every iteration so it does not retain value from last iteration
2425         devBase=""
2426         # this is required because below we are subtracting from NF, so it has to be > 4
2427         # the real issue is long file system names that force the wrap of df output: //fileserver/main
2428         # but we still need to handle more dynamically long space containing file names, but later.
2429         ( NF < 5 ) && ( $0 !~ /[0-9]+\%/ ) {
2430                 # set the dev location here for cases of wrapped output
2431                 if ( NF == 1 ){
2432                         devBase=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
2433                 }
2434                 getline
2435         }
2436         # this handles yet another fredforfaen special case where a mounted drive
2437         # has the search string in its name
2438         $NF ~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$/ {
2439                 print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main," devBase
2440         }
2441         # skip all these, including the first, header line. Use the --exclude-type
2442         # to handle new filesystems types we do not want listed here
2443         $NF !~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$|^filesystem/ {
2444                 # this is to avoid file systems with spaces in their names, that will make
2445                 # the test show the wrong data in each of the fields, if no x%, then do not use
2446                 # using 3 cases, first default, standard, 2nd, 3rd, handles one and two spaces in name
2447                 if ( $(NF - 1) ~ /[0-9]+\%/ ) {
2448                         print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",secondary," devBase
2449                 }
2450                 # these two cases construct the space containing name
2451                 else if ( $(NF - 2) ~ /[0-9]+\%/ ) {
2452                         print $(NF - 1) " " $NF "," $(NF - 5) "," $(NF - 4) "," $(NF - 2) ",secondary," devBase
2453                 }
2454                 else if ( $(NF - 3) ~ /[0-9]+\%/ ) {
2455                         print $(NF - 2) " " $(NF - 1) " " $NF "," $(NF - 6) "," $(NF - 5) "," $(NF - 3) ",secondary," devBase
2456                 }
2457         }
2458         ' )
2459         # now add the swap partition data, don't want to show swap files, just partitions,
2460         # though this can include /dev/ramzswap0. Note: you can also use /proc/swaps for this
2461         # data, it's the same exact output as swapon -s
2462         $( swapon -s | gawk '
2463         BEGIN {
2464                 swapCounter = 1
2465         }
2466         /^\/dev/ {
2467                 size = sprintf( "%.2f", $3*1024/1000**3 )
2468                 devBase = gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
2469                 used = sprintf( "%.2f", $4*1024/1000**3 )
2470                 percentUsed = sprintf( "%.0f", ( $4/$3 )*100 )
2471                 print "swap-" swapCounter "," size "GB," used "GB," percentUsed "\%,main," devBase
2472                 swapCounter = ++swapCounter
2473         }' ) )
2474         IFS="$ORIGINAL_IFS"
2475
2476         if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
2477                 get_partition_data_advanced
2478         fi
2479 }
2480
2481 # first get the locations of the mount points for label/uuid detection
2482 get_partition_data_advanced()
2483 {
2484         local a_partition_working='' dev_partition_data=''
2485         local dev_disk_label='' dev_disk_uuid='' dev_item='' dev_label='' dev_uuid=''
2486         local mount_point=''
2487
2488         if [[ -d /dev/disk/by-label ]];then
2489                 dev_disk_label="$( ls -l /dev/disk/by-label )"
2490         fi
2491         if [[ -d /dev/disk/by-uuid ]];then
2492                 dev_disk_uuid="$( ls -l /dev/disk/by-uuid )"
2493         fi
2494
2495         if [[ $B_MOUNTS_DIR == 'true' ]];then
2496                 for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
2497                 do
2498                         IFS=","
2499                         a_partition_working=( ${A_PARTITION_DATA[i]} )
2500                         IFS="$ORIGINAL_IFS"
2501                         # note: for swap this will already be set
2502                         if [[ -z ${a_partition_working[5]} ]];then
2503                                 mount_point=$( sed 's|/|\\/|g'  <<< ${a_partition_working[0]} )
2504                                 #echo mount_point $mount_point
2505                                 dev_partition_data=$( gawk '
2506                                 BEGIN {
2507                                         IGNORECASE = 1
2508                                         partition = ""
2509                                         partTemp = ""
2510                                 }
2511                                 # trying to handle space in name
2512 #                               gsub( /\\040/, " ", $0 )
2513                                 /[ \t]'$mount_point'[ \t]/ && $1 != "rootfs" {
2514                                         # initialize the variables
2515                                         label = ""
2516                                         uuid = ""
2517
2518                                         # slice out the /dev
2519                                         partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
2520                                         # label and uuid can occur for root, set partition to null now
2521                                         if ( partition ~ /by-label/ ) {
2522                                                 label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, $1 )
2523                                                 partition = ""
2524                                         }
2525                                         if ( partition ~ /by-uuid/ ) {
2526                                                 uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, $1 )
2527                                                 partition = ""
2528                                         }
2529
2530                                         # handle /dev/root for / id
2531                                         if ( partition == "root" ) {
2532                                                 # if this works, great, otherwise, just set this to null values
2533                                                 partTemp="'$( readlink /dev/root 2>/dev/null )'"
2534                                                 if ( partTemp != "" ) {
2535                                                         if ( partTemp ~ /[hs]d[a-z][0-9]/ ) {
2536                                                                 partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, partTemp )
2537                                                         }
2538                                                         else if ( partTemp ~ /by-uuid/ ) {
2539                                                                 uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, partTemp )
2540                                                                 partition="" # set null to let real location get discovered
2541                                                         }
2542                                                         else if ( partTemp ~ /by-label/ ) {
2543                                                                 label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, partTemp )
2544                                                                 partition="" # set null to let real location get discovered
2545                                                         }
2546                                                 }
2547                                                 else {
2548                                                         partition = ""
2549                                                         label = ""
2550                                                         uuid = ""
2551                                                 }
2552                                         }
2553                                         print partition "," label "," uuid
2554                                 }'      $DIR_MOUNTS )
2555
2556 #                               echo dev_partition_data: $dev_partition_data
2557                                 # assemble everything we could get for dev/h/dx, label, and uuid
2558                                 IFS=","
2559                                 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
2560                                 IFS="$ORIGINAL_IFS"
2561                         fi
2562                         ## now we're ready to proceed filling in the data
2563                         IFS=","
2564                         a_partition_working=( ${A_PARTITION_DATA[i]} )
2565                         IFS="$ORIGINAL_IFS"
2566
2567                         dev_item=${a_partition_working[5]}
2568                         dev_label=${a_partition_working[6]}
2569                         dev_uuid=${a_partition_working[7]}
2570
2571                         # then if dev data/uuid is incomplete, try to get missing piece
2572                         # it's more likely we'll get a uuid than a label. But this should get the
2573                         # dev item set no matter what, so then we can get the rest of any missing data
2574                         # first we'll get the dev_item if it's missing
2575                         if [[ -n $dev_disk_uuid ]] && [[ -z $dev_item && -n $dev_uuid ]];then
2576                                 dev_item=$( echo "$dev_disk_uuid" | gawk '
2577                                         /'$dev_uuid'/ {
2578                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
2579                                                 print item
2580                                         }' )
2581                         elif [[ -n $dev_disk_label ]] && [[ -z $dev_item && -n $dev_label ]];then
2582                                 dev_item=$( echo "$dev_disk_label" | gawk '
2583                                         # first we need to change space x20 in by-label back to a real space
2584                                         #gsub( /x20/, " ", $0 )
2585                                         # then we can see if the string is there
2586                                         /'$dev_label'/ {
2587                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
2588                                                 print item
2589                                         }' )
2590                         fi
2591                         if [[ -n $dev_disk_uuid ]] && [[ -n $dev_item && -z $dev_uuid ]];then
2592                                 dev_uuid=$( echo "$dev_disk_uuid" | gawk '
2593                                 /'$dev_item'$/ {
2594                                         print $(NF - 2)
2595                                 }' )
2596                         fi
2597                         if [[ -n $dev_disk_label ]] && [[ -n $dev_item && -z $dev_label ]];then
2598                                 dev_label=$( echo "$dev_disk_label" | gawk '
2599                                 /'$dev_item'/ {
2600                                         print $(NF - 2)
2601                                 }' )
2602
2603                         fi
2604                         # assemble everything we could get for dev/h/dx, label, and uuid
2605                         IFS=","
2606                         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
2607                         IFS="$ORIGINAL_IFS"
2608                 done
2609         fi
2610 }
2611
2612 ## return uptime string
2613 get_uptime()
2614 {
2615         ## note: removing gsub(/ /,"",a); to get get space back in there, goes right before print a
2616         echo $( uptime | gawk '{
2617                 a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0)
2618                 print a
2619         }' )
2620 }
2621
2622 #### -------------------------------------------------------------------
2623 #### special data handling for specific options and conditions
2624 #### -------------------------------------------------------------------
2625
2626 ## multiply the core count by the data to be calculated, bmips, cache
2627 # args: $1 - string to handle; $2 - cpu count
2628 calculate_multicore_data()
2629 {
2630         local string_number=$1 string_data=''
2631
2632         if [[ -n $( egrep -i '( mb| kb)' <<< $1 ) ]];then
2633                 string_data=" $( gawk '{print $2}' <<< $1 )" # add a space for output
2634                 string_number=$( gawk '{print $1}' <<< $1 )
2635         fi
2636         # handle weird error cases where it's not a number
2637         if [[ -n $( egrep '^[0-9\.,]+$' <<< $string_number ) ]];then
2638                 string_number=$( echo $string_number $2 | gawk '{
2639                         total = $1*$2
2640                         print total
2641                 }' )
2642         elif [[ $string_number == '' ]];then
2643                 string_number='Not Available'
2644         else
2645                 # I believe that the above returns 'unknown' by default so no need for extra text
2646                 string_number="$string_number "
2647         fi
2648         echo "$string_number$string_data"
2649 }
2650
2651 # prints out shortened list of flags, the main ones of interest
2652 # args: $1 - string of cpu flags to process
2653 process_cpu_flags()
2654 {
2655         local cpu_flags="$1"
2656
2657         # nx = AMD stack protection extensions
2658         # lm = Intel 64bit extensions
2659         # sse, sse2, pni = sse1,2,3 gfx extensions
2660         # svm = AMD pacifica virtualization extensions
2661         # vmx = Intel IVT (vanderpool) virtualization extensions
2662         cpu_flags=$( echo "$cpu_flags" | gawk '
2663         BEGIN {
2664                 RS=" "
2665                 ssel["sse"] = 1
2666                 ssel["sse2"] = 2
2667                 ssel["pni"] = 3
2668                 sses[1] = "sse"
2669                 sses[2] = "sse2"
2670                 sses[3] = "sse3"
2671         }
2672         /^(nx|lm|svm|vmx)$/ {
2673                         if (s) {
2674                                 s = s " " $0
2675                         }
2676                         else {
2677                                 s = $0
2678                         }
2679         }
2680         /^(sse2?|pni)$/ {
2681                 if (ssel[$0] > sse) {
2682                         sse = ssel[$0]
2683                 }
2684         }
2685         END {
2686                 if (sse) {
2687                         if (s) {
2688                                 s = sses[sse] " " s
2689                         }
2690                         else {
2691                                 s = sses[sse]
2692                         }
2693                 }
2694                 print s
2695         }' )
2696
2697         #grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
2698         if [[ -z $cpu_flags ]];then
2699                 cpu_flags="-"
2700         fi
2701         echo "$cpu_flags"
2702 }
2703
2704 #### -------------------------------------------------------------------
2705 #### print and processing of output data
2706 #### -------------------------------------------------------------------
2707
2708 #### MASTER PRINT FUNCTION - triggers all line item print functions
2709 ## main function to print out, master for all sub print functions.
2710 print_it_out()
2711 {
2712         # note that print_it_out passes local variable values on to its children,
2713         # and in some cases, their children, with Lspci_Data
2714         local Lspci_Data='' # only for verbose
2715
2716         if [[ $B_SHOW_SHORT_OUTPUT == 'true' ]];then
2717                 print_short_data
2718         else
2719                 Lspci_Data="$( get_lspci_data )"
2720                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_SYSTEM == 'true' ]];then
2721                         print_system_data
2722                 fi
2723                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_CPU == 'true' ]];then
2724                         print_cpu_data
2725                 fi
2726                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_GRAPHICS == 'true' ]];then
2727                         print_gfx_data
2728                 fi
2729                 if [[ $VERBOSITY_LEVEL -ge 5 || $B_SHOW_AUDIO == 'true' ]];then
2730                         print_audio_data
2731                 fi
2732                 if [[ $VERBOSITY_LEVEL -ge 2 || $B_SHOW_NETWORK == 'true' ]];then
2733                         print_networking_data
2734                 fi
2735                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_DISK == 'true' ]];then
2736                         print_hard_disk_data
2737                 fi
2738                 if [[ $VERBOSITY_LEVEL -ge 4 || $B_SHOW_PARTITIONS == 'true' ]];then
2739                         print_partition_data
2740                 fi
2741                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_INFO == 'true' ]];then
2742                         print_info_data
2743                 fi
2744         fi
2745 }
2746
2747 #### SHORT OUTPUT PRINT FUNCTION, ie, verbosity 0
2748 # all the get data stuff is loaded here to keep execution time down for single line print commands
2749 # these will also be loaded in each relevant print function for long output
2750 print_short_data()
2751 {
2752         local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
2753         local processes="$(( $( ps aux | wc -l ) - 1 ))"
2754         local short_data='' i='' b_background_black='false'
2755         local memory=$( get_memory_data )
2756         local up_time="$( get_uptime )"
2757
2758         # set A_CPU_CORE_DATA
2759         get_cpu_core_count
2760         local cpc_plural='' cpu_count_print='' model_plural=''
2761         local cpu_physical_count=${A_CPU_CORE_DATA[0]}
2762         local cpu_core_count=${A_CPU_CORE_DATA[3]}
2763         local cpu_core_alpha=${A_CPU_CORE_DATA[1]}
2764         local cpu_type=${A_CPU_CORE_DATA[2]}
2765
2766         if [[ $cpu_physical_count -gt 1 ]];then
2767                 cpc_plural='(s)'
2768                 model_plural='s'
2769                 cpu_count_print="$cpu_physical_count "
2770         fi
2771
2772         local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
2773 #       local cpu_core_count=${A_CPU_CORE_DATA[0]}
2774
2775         # load A_HDD_DATA
2776         get_hdd_data_basic
2777         ## note: if hdd_model is declared prior to use, whatever string you want inserted will
2778         ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
2779         local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
2780         IFS=","
2781         local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
2782         IFS="$ORIGINAL_IFS"
2783         local hdd_capacity=${a_hdd_basic_working[0]}
2784         local hdd_used=${a_hdd_basic_working[1]}
2785
2786         # load A_CPU_DATA
2787         get_cpu_data
2788
2789         IFS=","
2790         local a_cpu_working=(${A_CPU_DATA[0]})
2791         IFS="$ORIGINAL_IFS"
2792         local cpu_model="${a_cpu_working[0]}"
2793         ## assemble data for output
2794         local cpu_clock="${a_cpu_working[1]}" # old CPU3
2795         # this gets that weird min/max final array item
2796         local min_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 ))
2797         local min_max_clock=${A_CPU_DATA[$min_max_clock_nu]}
2798
2799         #set_color_scheme 12
2800         if [[ $B_RUNNING_IN_SHELL == 'false' ]];then
2801                 for i in $C1 $C2 $CN
2802                 do
2803                         case "$i" in
2804                                 "$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN")
2805                                         b_background_black='true'
2806                                         ;;
2807                         esac
2808                 done
2809                 if [[ $b_background_black == 'true' ]];then
2810                         for i in C1 C2 CN
2811                         do
2812                                 ## these need to be in quotes, don't know why
2813                                 if [[ ${!i} == $NORMAL ]];then
2814                                         declare $i="${!i}15,1"
2815                                 else
2816                                         declare $i="${!i},1"
2817                                 fi
2818                         done
2819                         #C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
2820                 fi
2821         fi
2822         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}]"
2823
2824         if [[ $SHOW_IRC -gt 0 ]];then
2825                 short_data="${short_data} ${C1}Client${CN}[${C2}${SEP1}${IRC_CLIENT}${IRC_CLIENT_VERSION}${SEP1}${CN}]"
2826         fi
2827         short_data="${short_data} ${C1}$SCRIPT_NAME${C2}${CN}[${C2}${SEP1}$SCRIPT_VERSION_NUMBER${SEP1}${CN}]"
2828         if [[ $SCHEME -gt 0 ]];then
2829                 short_data="${short_data} $NORMAL"
2830         fi
2831         print_screen_output "$short_data"
2832 }
2833
2834 #### LINE ITEM PRINT FUNCTIONS
2835
2836 # print sound card data
2837 print_audio_data()
2838 {
2839         local i='' card_one='Card-1 ' audio_data='' a_audio_data='' port_data=''
2840         local a_audio_working='' alsa_driver='' alsa_data='' port_plural='' module_version=''
2841         # set A_AUDIO_DATA and get alsa data
2842         get_audio_data
2843         alsa_data=$( get_audio_alsa_data )
2844         IFS=","
2845         a_audio_working=(${A_AUDIO_DATA[0]})
2846         IFS="$ORIGINAL_IFS"
2847
2848         if [[ -n ${A_AUDIO_DATA[@]} ]];then
2849                 # slightly complicated because 2nd array item could be the alsa data
2850                 if [[ ${#A_AUDIO_DATA[@]} -le 1 ]];then
2851                         card_one='Card '
2852                 fi
2853
2854 #               if [[ -n ${a_audio_working[2]} ]];then
2855 #                       port_data=" ${C1}at port${C2} ${a_audio_working[2]}"
2856 #               fi
2857                 # this should only trigger if the $DIR_ASOUND_DEVICE data is used, not lspci -nn
2858                 if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
2859                         module_version=$( print_module_version "${a_audio_working[3]}" )
2860                 fi
2861                 if [[ -n ${a_audio_working[1]} ]];then
2862                         alsa_driver=" ${C1}driver${C2} ${a_audio_working[1]}$module_version"
2863                 fi
2864                 if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
2865                         if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
2866                                 port_plural='s'
2867                         fi
2868                         port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
2869                 fi
2870                 audio_data="${C1}$card_one${C2}${a_audio_working[0]}$alsa_driver$port_data"
2871                 audio_data=$( create_print_line "Audio:" "$audio_data" )
2872                 print_screen_output "$audio_data"
2873                 i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
2874                 while [[ -n ${A_AUDIO_DATA[++i]} ]]
2875                 do
2876                         IFS=","
2877                         a_audio_working=( ${A_AUDIO_DATA[i]} )
2878                         IFS="$ORIGINAL_IFS"
2879                         port_data=''
2880                         alsa_driver=''
2881                         port_plural=''
2882                         module_version=''
2883                         if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
2884                                 module_version=$( print_module_version "${a_audio_working[3]}" )
2885                         fi
2886                         # we're testing for the presence of the 2nd array item here, which is the driver name
2887                         if [[ -n ${a_audio_working[1]} ]];then
2888                                 alsa_driver="${C1}driver${C2} ${a_audio_working[1]}"
2889                         fi
2890                         if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
2891                                 if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
2892                                         port_plural='s'
2893                                 fi
2894                                 port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
2895                         fi
2896                         if [[ -n ${a_audio_working[0]} ]];then
2897                                 audio_data="${C1}Card-$(( $i + 1 )) ${C2}${a_audio_working[0]}$alsa_driver$port_data"
2898                         fi
2899                         if [[ -n $audio_data ]];then
2900                                 audio_data=$( create_print_line " " "$audio_data" )
2901                                 print_screen_output "$audio_data"
2902                         fi
2903                 done
2904                 # alsa driver data only prints out if sound card data is found
2905                 if [[ -n $alsa_data ]];then
2906                         audio_data="${C1}Sound: ${C2}$alsa_data"
2907                         audio_data=$( create_print_line " " "$audio_data" )
2908                         print_screen_output "$audio_data"
2909                 fi
2910         fi
2911 }
2912
2913 print_cpu_data()
2914 {
2915         local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data=''
2916         local bmip_data='' cpu_cache='' cpu_vendor='' cpu_flags=''
2917
2918         ##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\""
2919         # Array A_CPU_DATA always has one extra element: max clockfreq found.
2920         # that's why its count is one more than you'd think from cores/cpus alone
2921         # load A_CPU_DATA
2922         get_cpu_data
2923
2924         IFS=","
2925         local a_cpu_working=(${A_CPU_DATA[0]})
2926         IFS="$ORIGINAL_IFS"
2927         local cpu_model="${a_cpu_working[0]}"
2928         ## assemble data for output
2929         local cpu_clock="${a_cpu_working[1]}"
2930
2931         cpu_vendor=${a_cpu_working[5]}
2932
2933         # set A_CPU_CORE_DATA
2934         get_cpu_core_count
2935         local cpc_plural='' cpu_count_print='' model_plural=''
2936         local cpu_physical_count=${A_CPU_CORE_DATA[0]}
2937         local cpu_core_count=${A_CPU_CORE_DATA[3]}
2938         local cpu_core_alpha=${A_CPU_CORE_DATA[1]}
2939         local cpu_type=${A_CPU_CORE_DATA[2]}
2940
2941         if [[ $cpu_physical_count -gt 1 ]];then
2942                 cpc_plural='(s)'
2943                 cpu_count_print="$cpu_physical_count "
2944                 model_plural='s'
2945         fi
2946
2947         local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
2948         # Strange (and also some expected) behavior encountered. If print_screen_output() uses $1
2949         # as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
2950         # will output only <text1> and first element of ARR. That "@" splits in elements and "*" _doesn't_,
2951         # is to be expected. However, that text2 is consecutively truncated is somewhat strange, so take note.
2952         # This has been confirmed by #bash on freenode.
2953         # The above mentioned only emerges when using the debugging markers below
2954         ## print_screen_output "a_cpu_working=\"***${a_cpu_working[@]} $hostName+++++++\"----------"
2955
2956         if [[ -z ${a_cpu_working[2]} ]];then
2957                 a_cpu_working[2]="unknown"
2958         fi
2959
2960         cpu_data=$( create_print_line "CPU$cpc_plural:" "${C1}${cpu_data_string}${C2} ${a_cpu_working[0]}$model_plural (${cpu_type})" )
2961         if [[ $VERBOSITY_LEVEL -ge 3 || $B_SHOW_CPU == 'true' ]];then
2962                 # update for multicore, bogomips x core count.
2963                 if [[ $B_EXTRA_DATA == 'true' ]];then
2964 #                       if [[ $cpu_vendor != 'intel' ]];then
2965                                 bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$(( $cpu_core_count * $cpu_physical_count ))" )
2966 #                       else
2967 #                               bmip_data="${a_cpu_working[4]}"
2968 #                       fi
2969                         bmip_data=" ${C1}bmips${C2} $bmip_data"
2970                 fi
2971                 ## note: this handles how intel reports L2, total instead of per core like AMD does
2972                 # note that we need to multiply by number of actual cpus here to get true cache size
2973                 if [[ $cpu_vendor != 'intel' ]];then
2974                         cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$(( $cpu_core_count * $cpu_physical_count ))"  )
2975                 else
2976                         cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$cpu_physical_count"  )
2977                 fi
2978                 # only print shortened list
2979                 if [[ $B_CPU_FLAGS_FULL != 'true' ]];then
2980                         cpu_flags=$( process_cpu_flags "${a_cpu_working[3]}" )
2981                         cpu_flags=" ${C1}flags${C2} ($cpu_flags)"
2982                 fi
2983                 cpu_data="$cpu_data${C2} ${C1}cache${C2} $cpu_cache$cpu_flags$bmip_data${CN}"
2984         fi
2985         # we don't this printing out extra line unless > 1 cpu core
2986         if [[ ${#A_CPU_DATA[@]} -gt 2 ]] && [[ $B_SHOW_CPU == 'true' || $VERBOSITY_LEVEL -ge 5 ]];then
2987                 cpu_clock_speed='' # null < verbosity level 5
2988         else
2989                 cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}"
2990         fi
2991
2992         cpu_data="$cpu_data $cpu_clock_speed"
2993         print_screen_output "$cpu_data"
2994
2995         # we don't this printing out extra line unless > 1 cpu core
2996         if [[ ${#A_CPU_DATA[@]} -gt 2 ]] && [[ $B_SHOW_CPU == 'true' || $VERBOSITY_LEVEL -ge 5 ]];then
2997                 for (( i=0; i < ${#A_CPU_DATA[@]}-1; i++ ))
2998                 do
2999                         IFS=","
3000                         a_cpu_working=(${A_CPU_DATA[i]})
3001                         IFS="$ORIGINAL_IFS"
3002                         cpu_multi_clock_data="$cpu_multi_clock_data ${C1}($(( i + 1 )))${C2} ${a_cpu_working[1]} MHz${CN}"
3003                         if [[ $i -gt 10 ]];then
3004                                 break
3005                         fi
3006                 done
3007                 if [[ -n $cpu_multi_clock_data ]];then
3008                         cpu_multi_clock_data=$( create_print_line " " "${C1}Clock Speeds:${C2}$cpu_multi_clock_data" )
3009                         print_screen_output "$cpu_multi_clock_data"
3010                 fi
3011         fi
3012         if [[ $B_CPU_FLAGS_FULL == 'true' ]];then
3013                 print_cpu_flags_full "${a_cpu_working[3]}"
3014         fi
3015 }
3016
3017 # takes list of all flags, split them and prints x per line
3018 # args: $1 - cpu flag string
3019 print_cpu_flags_full()
3020 {
3021         local cpu_flags_full="$1" a_cpu_flags='' line_starter=''
3022         local i=0 counter=0 max_length=18 max_length_add=18 flag='' flag_data=''
3023
3024         # build the flag line array
3025         for flag in $cpu_flags_full
3026         do
3027                 a_cpu_flags[$counter]="${a_cpu_flags[$counter]}$flag "
3028                 if [[ $i -ge $max_length ]];then
3029                         (( counter++ ))
3030                         max_length=$(( $max_length + $max_length_add ))
3031                 fi
3032                 ((i++))
3033         done
3034         # then print it out
3035         for (( i=0; i < ${#a_cpu_flags[@]};i++ ))
3036         do
3037                 if [[ $i -eq 0 ]];then
3038                         line_starter="${C1}CPU Flags${C2} "
3039                 else
3040                         line_starter=''
3041                 fi
3042                 flag_data=$( create_print_line " " "$line_starter${a_cpu_flags[$i]}" )
3043                 print_screen_output "$flag_data"
3044         done
3045 }
3046
3047 print_gfx_data()
3048 {
3049         local gfx_data='' i='' card_one='Card '
3050         local screen_resolution="$( get_graphics_res_data )"
3051         local b_is_mesa='false'
3052
3053         # set A_GFX_CARD_DATA
3054         get_graphics_card_data
3055         # set A_X_DATA
3056         get_graphics_x_data
3057         local x_vendor=${A_X_DATA[0]}
3058         local x_version=${A_X_DATA[1]}
3059         # set A_GLX_DATA
3060         get_graphics_glx_data
3061         local glx_renderer="${A_GLX_DATA[0]}"
3062         local glx_version="${A_GLX_DATA[1]}"
3063         local glx_direct_render="${A_GLX_DATA[2]}"
3064
3065         if [[ ${#A_GFX_CARD_DATA[@]} -gt 1 ]];then
3066                 i=1
3067                 while [[ -n ${A_GFX_CARD_DATA[i]} && $i -le 3 ]]
3068                 do
3069                         gfx_data=" ${C1}Card-$(($i+1))${C2} ${A_GFX_CARD_DATA[i]}"
3070                         ((i++))
3071                 done
3072                 card_one='Card-1 '
3073         fi
3074         gfx_data=$( create_print_line "Graphics:" "${C1}$card_one${C2}${A_GFX_CARD_DATA[0]}${gfx_data}" )
3075
3076         if [[ $B_X_RUNNING == 'true' ]];then
3077                 gfx_data="${gfx_data} ${C1}$x_vendor${C2} $x_version ${C1}Res${C2} ${screen_resolution}"
3078         else
3079                 gfx_data="${gfx_data} ${C1} tty resolution ${CN}(${C2} ${screen_resolution} ${CN})"
3080         fi
3081         print_screen_output "$gfx_data"
3082
3083         if [[ -z $glx_renderer || -z $glx_version ]];then
3084                 b_is_mesa='true'
3085         fi
3086
3087         ## note: if glx render or version have no content, then mesa is true
3088         if [[ $B_X_RUNNING == 'true' ]] && [[ $b_is_mesa != 'true' ]];then
3089                 gfx_data=$( create_print_line " " "${C1}GLX Renderer${C2} ${glx_renderer} ${C1}GLX Version${C2} ${glx_version}${CN}" )
3090                 if [[ $B_HANDLE_CORRUPT_DATA == 'true' ]];then
3091                         gfx_data="${gfx_data} ${C1}Direct rendering${C2} ${glx_direct_render}${CN}"
3092                 fi
3093                 print_screen_output "$gfx_data"
3094         fi
3095 }
3096
3097 print_hard_disk_data()
3098 {
3099         local hdd_data='' hdd_data_2='' a_hdd_working=''
3100         local dev_data='' size_data='' hdd_model='' hdd_model_2='' hdd_model_3='' usb_data=''
3101
3102         # load A_HDD_DATA
3103         get_hdd_data_basic
3104         ## note: if hdd_model is declared prior to use, whatever string you want inserted will
3105         ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
3106         local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
3107         IFS=","
3108         local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
3109         IFS="$ORIGINAL_IFS"
3110         local hdd_capacity=${a_hdd_basic_working[0]}
3111         local hdd_used=${a_hdd_basic_working[1]}
3112
3113         if [[ $VERBOSITY_LEVEL -ge 3 ]] || [[ $B_SHOW_DISK == 'true' ]];then
3114         ## note: the output part of this should be in the print hdd data function, not here
3115                 get_hard_drive_data_advanced
3116                 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
3117                 do
3118                         # this adds the (x) numbering in front of each disk found, and creates the full disk string
3119                         IFS=","
3120                         a_hdd_working=( ${A_HDD_DATA[i]} )
3121                         IFS="$ORIGINAL_IFS"
3122                         if [[ $B_SHOW_DISK == 'true' ]];then
3123                                 if [[ -n ${a_hdd_working[3]} ]];then
3124                                         usb_data="${a_hdd_working[3]} "
3125                                 else
3126                                         usb_data=''
3127                                 fi
3128                                 dev_data="/dev/${a_hdd_working[0]} "
3129                                 size_data=" ${a_hdd_working[1]}"
3130                         fi
3131                         # wrap to avoid long lines
3132
3133                         if [[ $i -gt 1 && $B_SHOW_DISK == 'true' ]] || [[ $i -gt 3 ]];then
3134                                 hdd_model_2="${hdd_model_2}${hdd_model_2+${C1}$(($i+1)):${C2}} $usb_data$dev_data${a_hdd_working[2]}$size_data "
3135                         else
3136                                 hdd_model="${hdd_model}${hdd_model+ ${C1}$(($i+1)):${C2}} $usb_data$dev_data${a_hdd_working[2]}$size_data"
3137                         fi
3138                 done
3139                 if [[ -z $hdd_model ]];then
3140                         hdd_model=' None Detected'
3141                 fi
3142                 if [[ -n $hdd_model_2 ]];then
3143                         hdd_data=$( create_print_line "Disks:" "${C1}HDD${C2} ${C1}Total Size:${C2} ${hdd_capacity} (${hdd_used})${hdd_model}" )
3144                         hdd_data_2=$( create_print_line " " "${hdd_model_2}${CN}" )
3145                 else
3146                         hdd_data=$( create_print_line "Disks:" "${C1}HDD${C2} ${C1}Total Size:${C2} ${hdd_capacity} (${hdd_used})${hdd_model}${CN}" )
3147                 fi
3148         else
3149                 hdd_data=$( create_print_line "Disks:" "${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used})${CN}" )
3150         fi
3151         print_screen_output "$hdd_data"
3152         if [[ -n $hdd_model_2 ]];then
3153                 print_screen_output "$hdd_data_2"
3154         fi
3155 }
3156
3157 print_info_data()
3158 {
3159         local suggested_app="runlevel"
3160         local info_data=''
3161         local runlvl=''
3162         local memory="$( get_memory_data )"
3163         local processes="$(( $( ps aux | wc -l ) - 1 ))"
3164         local up_time="$( get_uptime )"
3165
3166         # Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch!
3167         # long_last=$( echo -ne "${C1}Processes${C2} ${processes}${CN} | ${C1}Uptime${C2} ${up_time}${CN} | ${C1}Memory${C2} ${MEM}${CN}" )
3168         info_data=$( create_print_line "Info:" "${C1}Processes${C2} ${processes} ${C1}Uptime${C2} ${up_time} ${C1}Memory${C2} ${memory}${CN}" )
3169
3170         # this only triggers if no X data is present
3171         if [[ $B_X_RUNNING != 'true' ]];then
3172                 if [[ -e $suggested_app ]];then
3173                         runlvl="$( runlevel | gawk '{ print $2 }' )"
3174                         info_data="${info_data} ${C1}Runlevel${C2} ${runlvl}${CN}"
3175                 fi
3176         fi
3177
3178         if [[ $SHOW_IRC -gt 0 ]];then
3179                 info_data="${info_data} ${C1}Client${C2} ${IRC_CLIENT}${IRC_CLIENT_VERSION}${CN}"
3180         fi
3181         info_data="${info_data} ${C1}$SCRIPT_NAME${C2} $SCRIPT_VERSION_NUMBER${CN}"
3182
3183         if [[ $SCHEME -gt 0 ]];then
3184                 info_data="${info_data} ${NORMAL}"
3185         fi
3186         print_screen_output "$info_data"
3187 }
3188
3189 # args: $1 - module name (could be > 1, so loop it )
3190 print_module_version()
3191 {
3192         local module_versions='' module='' version=''
3193
3194         for module in $1
3195         do
3196                 version=$( get_module_version_number $module )
3197                 if [[ -n $version ]];then
3198                         module_versions="$module_versions $version"
3199                 fi
3200         done
3201
3202         if [[ -n $module_versions ]];then
3203                 echo " ${C1}v:${C2}$module_versions"
3204         fi
3205 }
3206
3207 print_networking_data()
3208 {
3209         local i='' card_one='Card-1' network_data='' a_network_working='' port_data='' driver_data=''
3210         local card_string='' port_plural='' module_version=''
3211         # set A_NETWORK_DATA
3212         get_networking_data
3213
3214         IFS=","
3215         a_network_working=(${A_NETWORK_DATA[0]})
3216         IFS="$ORIGINAL_IFS"
3217
3218         # will never be null because null is handled in get_network_data, but in case we change
3219         # that leaving this test in place.
3220         if [[ -n ${A_NETWORK_DATA[@]} ]];then
3221                 if [[ ${#A_NETWORK_DATA[@]} -le 1 ]];then
3222                         card_one='Card'
3223                 fi
3224                 if [[ -n ${a_network_working[3]} && $B_EXTRA_DATA == 'true' ]];then
3225                         module_version=$( print_module_version "${a_network_working[3]}" )
3226                 fi
3227                 if [[ -n ${a_network_working[1]} ]];then
3228                         driver_data=" ${C1}driver${C2} ${a_network_working[1]}$module_version"
3229                 fi
3230                 if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then
3231                         if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then
3232                                 port_plural='s'
3233                         fi
3234                         port_data=" ${C1}at port$port_plural${C2} ${a_network_working[2]}"
3235                 fi
3236                 card_string=''
3237                 network_data="${C1}$card_one${C2} ${a_network_working[0]}$driver_data$port_data"
3238                 network_data=$( create_print_line "Network:" "$network_data" )
3239                 print_screen_output "$network_data"
3240                 i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
3241                 while [[ -n ${A_NETWORK_DATA[++i]} ]]
3242                 do
3243                         IFS=","
3244                         a_network_working=( ${A_NETWORK_DATA[i]} )
3245                         IFS="$ORIGINAL_IFS"
3246                         port_data=''
3247                         driver_data=''
3248                         port_plural=''
3249                         module_version=''
3250                         if [[ -n ${a_network_working[3]} && $B_EXTRA_DATA == 'true' ]];then
3251                                 module_version=$( print_module_version "${a_network_working[3]}" )
3252                         fi
3253                         if [[ -n ${a_network_working[1]} ]];then
3254                                 driver_data=" ${C1}driver${C2} ${a_network_working[1]}$module_version"
3255                         fi
3256                         if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then
3257                                 if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then
3258                                         port_plural='s'
3259                                 fi
3260                                 port_data=" ${C1}at port$port_plural${C2} ${a_network_working[2]}"
3261                         fi
3262                         network_data="${C1}Card-$(( $i + 1 )) ${C2}${a_network_working[0]}$driver_data$port_data"
3263                         network_data=$( create_print_line " " "$network_data" )
3264                         print_screen_output "$network_data"
3265                 done
3266         fi
3267         if [[ $B_SHOW_IP == 'true' ]];then
3268                 print_networking_ip_data
3269         fi
3270 }
3271
3272 print_networking_ip_data()
3273 {
3274         local ip=$( get_networking_wan_ip_data )
3275         local ip_data='' a_interfaces_working='' interfaces='' interfaces_2='' i=''
3276
3277         # set A_INTERFACES_DATA
3278         get_networking_local_ip_data
3279         # first print output for wan ip line. Null is handled in the get function
3280         ip_data=$( create_print_line " " "${C1}Wan IP:${C2} $ip" )
3281
3282         # then create the list of local interface/ip
3283         interfaces=" ${C1}Interface:${C2}"
3284         i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
3285         while [[ -n ${A_INTERFACES_DATA[i]} ]]
3286         do
3287                 IFS=","
3288                 a_interfaces_working=(${A_INTERFACES_DATA[i]})
3289                 IFS="$ORIGINAL_IFS"
3290                 if [[ $i -lt 3 ]];then
3291                         if [[ -n ${a_interfaces_working[0]} ]];then
3292                                 interfaces="$interfaces ${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]}"
3293                         fi
3294                 else
3295                         if [[ -n ${a_interfaces_working[0]} ]];then
3296                                 # space on end here for lining up with line starter
3297                                 interfaces_2="$interfaces_2${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]} "
3298                         fi
3299                 fi
3300                 ((i++))
3301         done
3302         print_screen_output "$ip_data$interfaces"
3303         # then wrap it if needed
3304         if [[ -n $interfaces_2 ]];then
3305                 interfaces_2=$( create_print_line " " "$interfaces_2" )
3306                 print_screen_output "$interfaces_2"
3307         fi
3308 }
3309
3310 print_partition_data()
3311 {
3312         local a_partition_working='' partition_used='' partition_data=''
3313         local counter=0 line_max=160  i=0 a_partition_data='' line_starter=''
3314         local partitionIdClean='' part_dev='' full_dev='' part_label='' full_label=''
3315         local part_uuid='' full_uuid='' dev_remote=''
3316
3317         # this handles the different, shorter, irc colors strings embedded in variable data
3318         if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
3319                 line_max=130
3320         fi
3321         # and no color string data at all
3322         if [[ $SCHEME -eq 0 ]];then
3323                 line_max=75
3324         fi
3325         if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
3326                 line_max=20
3327         fi
3328
3329         # set A_PARTITION_DATA
3330         get_partition_data
3331
3332         for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
3333         do
3334                 IFS=","
3335                 a_partition_working=(${A_PARTITION_DATA[i]})
3336                 IFS="$ORIGINAL_IFS"
3337                 full_label=''
3338                 full_uuid=''
3339                 if [[ $B_SHOW_PARTITIONS_FULL == 'true' ]] || [[ ${a_partition_working[4]} == 'main' ]];then
3340                         if [[ -n ${a_partition_working[2]} ]];then
3341                                 partition_used=" ${C1}used:${C2} ${a_partition_working[2]} (${a_partition_working[3]})"
3342                         else
3343                                 partition_used='' # reset partition used to null
3344                         fi
3345
3346                         # don't show user names in output
3347                         if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
3348                                 if [[ -n ${a_partition_working[5]} ]];then
3349                                         if [[ -z $( grep -E '(^//|:/)' <<< ${a_partition_working[5]} ) ]];then
3350                                                 part_dev="/dev/${a_partition_working[5]}"
3351                                                 dev_remote='dev'
3352                                         else
3353                                                 part_dev="${a_partition_working[5]}"
3354                                                 dev_remote='remote'
3355                                         fi
3356                                 else
3357                                         dev_remote='dev'
3358                                         part_dev='N/A'
3359                                 fi
3360                                 full_dev=" ${C1}$dev_remote:${C2} $part_dev"
3361                                 if [[ $B_SHOW_LABELS == 'true' && $dev_remote != 'remote' ]];then
3362                                         if [[ -n ${a_partition_working[6]} ]];then
3363                                                 part_label="${a_partition_working[6]}"
3364                                         else
3365                                                 part_label='N/A'
3366                                         fi
3367                                         full_label=" ${C1}label:${C2} $part_label"
3368                                 fi
3369                                 if [[ $B_SHOW_UUIDS == 'true' && $dev_remote != 'remote' ]];then
3370                                         if [[ -n ${a_partition_working[7]} ]];then
3371                                                 part_uuid="${a_partition_working[7]}"
3372                                         else
3373                                                 part_uuid='N/A'
3374                                         fi
3375                                         full_uuid=" ${C1}uuid:${C2} $part_uuid"
3376                                 fi
3377                         fi
3378                         partitionIdClean=$( sed -r 's|/home/(.*)/(.*)|/home/##/\2|' <<< ${a_partition_working[0]} )
3379                         # because these lines can vary widely, using dynamic length handling here
3380                         a_partition_data[$counter]="${a_partition_data[$counter]}${C1}ID:${C2}$partitionIdClean ${C1}size:${C2} ${a_partition_working[1]}$partition_used$full_dev$full_label$full_uuid "
3381
3382                         if [[ $( wc -c <<< ${a_partition_data[$counter]} ) -gt $line_max ]];then
3383                                 ((counter++))
3384                         fi
3385                 fi
3386         done
3387         # print out all lines, line starter on first line
3388         for (( i=0; i < ${#a_partition_data[@]};i++ ))
3389         do
3390                 if [[ $i -eq 0 ]];then
3391                         line_starter='Partition:'
3392                 else
3393                         line_starter=' '
3394                 fi
3395                 partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}" )
3396                 print_screen_output "$partition_data"
3397         done
3398 }
3399
3400 print_system_data()
3401 {
3402         local system_data='' bits=''
3403         local host_name=$( hostname )
3404         local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
3405         local distro="$( get_distro_data )"
3406                 # check for 64 bit first
3407         if [[ -n $( uname -m | grep -o 'x86_64' ) ]];then
3408                 bits="(64 bit)"
3409         else
3410                 bits="(32 bit)"
3411         fi
3412
3413         if [[ $B_SHOW_HOST == 'true' ]];then
3414                 system_data=$( create_print_line "System:" "${C1}Host${C2} $host_name ${C1}Kernel${C2}" )
3415         else
3416                 system_data=$( create_print_line "System:" "${C1}Kernel${C2}" )
3417         fi
3418         system_data="$system_data $current_kernel $bits ${C1}Distro${C2} $distro"
3419         print_screen_output "$system_data"
3420 }
3421
3422 ########################################################################
3423 #### SCRIPT EXECUTION
3424 ########################################################################
3425
3426 main $@ ## From the End comes the Beginning
3427
3428 ## note: this EOF is needed for smxi handling, this is what triggers the full download ok
3429 ###**EOF**###