inxi bumping: 1.4.15
[quassel.git] / data / scripts / inxi
1 #!/bin/bash
2 ########################################################################
3 ####  Script Name: inxi
4 ####  version: 1.4.15
5 ####  Date: September 16 2010
6 ########################################################################
7 ####  SPECIAL THANKS
8 ########################################################################
9 ####  Special thanks to all those in #lsc and #smxi for their tireless 
10 ####  dedication 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-10 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 ####  Package names in (...) are the Debian Squeeze package name. Check your 
46 ####  distro for proper package name by doing this: which <application> 
47 ####  then find what package owns that application file.
48 ####  DEPENDENCIES
49 ####  bash >=3.0 (bash); df, readlink, stty, tr, uname, wc (coreutils);
50 ####  gawk (gawk); grep (grep); hostname (hostname); lspci (pciutils);
51 ####  free, ps, uptime (procps); 
52 ####  Also the proc filesystem should be present and mounted
53 ####
54 ####    Apparently unpatched bash 3.0 has arrays broken; bug reports:
55 ####    http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-008
56 ####    http://lists.gnu.org/archive/html/bug-bash/2004-08/msg00144.html
57 ####  Bash 3.1 for proper array use
58 ####
59 ####    Arrays work in bash 2.05b, but "egrep -m" does not
60 ####
61 ####  RECOMMENDS (Needed to run certain features, listed by option)
62 ####  -A - for output of usb audio information: lsusb (usbutils)
63 ####  -Ax - for audio module version: modinfo (module-init-tools)
64 ####  -Dx - for hdd temp output (root only default): hddtemp (hddtemp)
65 ####       For user level hdd temp output: sudo (sudo)
66 ####       Note: requires user action for this feature to run as user (edit /etc/sudoers file)
67 ####  -G - full graphics output requires:  glxinfo (mesa-utils); xdpyinfo (X11-utils);
68 ####       xrandr (x11-xserver-utils)
69 ####  -i - IP information, local/wan - ifconfig (net-tools)
70 ####  -Ix - view current runlevel while not in X window system (or with -x): runlevel (sysvinit)
71 ####  -o - for unmounted file system information in unmounted drives (root only default): file (file)
72 ####       Note: requires user action for this feature to run as user (edit /etc/sudoers file)
73 ####       For user level unmounted file system type output: sudo (sudo)
74 ####  -s   For any sensors output, fan, temp, etc: sensors (lm-sensors)
75 ####       Note: requires setup of lm-sensors (sensors-detect and adding modules/modprobe/reboot,
76 ####       and ideally, pwmconfig) prior to full output being available. 
77 ########################################################################
78 ####  CONVENTIONS:
79 ####  Indentation: TABS
80 ####  Do not use `....` (back quotes), those are totally non-reabable, use $(....).
81 ####  Do not use one liner flow controls. 
82 ####  The ONLY time you should use ';' (semi-colon) is in this single case: if [[ condition ]];then.
83 ####  Never use compound 'if': ie, if [[ condition ]] && statement.
84 ####  Note: [[ -n $something ]] - double brackets does not require quotes for variables: ie, "$something".
85 ####  Always use quotes, double or single, for all string values.
86 ####
87 ####  All new code/methods must be in a function.
88 ####  For all boolean tests, use 'true' / 'false'.
89 ####  !! Do NOT use 0 or 1 unless it's a function return. 
90 ####  Avoid complicated tests in the if condition itself.
91 ####  To 'return' a value in a function, use 'echo <var>'.
92 ####
93 ####  For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
94 ####  This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
95 ####
96 ####  VARIABLE/FUNCTION NAMING:
97 ####  All functions should follow standard naming--verb adjective noun. 
98 ####    ie, get_cpu_data
99 ####  All variables MUST be initialized / declared explicitly.
100 ####  All variables should clearly explain what they are, except counters like i, j.
101 ####  Each word of variable must be separated by '_' (underscore) (camel form).
102 ####  Global variables are 'UPPER CASE', at top of script.
103 ####    ie, SOME_VARIABLE=''
104 ####  Local variables are 'lower case' and declared at the top of the function.
105 ####    ie, some_variable=''
106 ####  Locals that will be inherited by child functions have first char capitalized (so you know they are inherited).
107 ####    ie, Some_Variable 
108 ####
109 ####  Booleans should start with b_ (local) or B_ (global) and state clearly what is being tested.
110 ####  Arrays should start with a_ (local) or A_ (global).
111 ####
112 ####  SPECIAL NOTES:
113 ####  The color variable ${C2} must always be followed by a space unless you know what
114 ####  character is going to be next for certain. Otherwise irc color codes can be accidentally
115 ####  activated or altered.
116 ####
117 ####  For native script konversation support (check distro for correct konvi scripts path):
118 ####  ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi
119 ####  DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.
120 ####
121 ####  As with all 'rules' there are acceptions, these are noted where used.
122 ####
123 ###################################################################################
124 ####    KDE Konversation information.  Moving from dcop(qt3/KDE3) to dbus(qt4/KDE4)
125 ###################################################################################
126 ####    dcop and dbus   -- these talk back to Konversation from this script
127 ####    
128 ####    Scripting info  -- http://konversation.berlios.de/docs/scripting.html
129 ####                    -- http://www.kde.org.uk/apps/konversation/
130 ####
131 ####    dbus info       -- http://dbus.freedesktop.org/doc/dbus-tutorial.html
132 ####    view dbus info  -- https://fedorahosted.org/d-feet/
133 ####                    -- or run qdbus
134 ####    Konvi dbus/usage-- qdbus org.kde.konversation /irc say <server> <target-channel> <output>
135 ####
136 ####    Python usage    -- http://wiki.python.org/moin/DbusExamples  (just in case)
137 ####
138 ####    Because webpages come and go, the above information needs to be moved to inxi's wiki
139 ####    
140 ########################################################################
141 ####  Valuable Resources
142 ####  gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
143 ########################################################################
144 ####  TESTING FLAGS
145 ####  inxi supports advanced testing triggers to do various things, using -! <arg>
146 ####  -! 1  - triggers default B_TESTING_1='true' to trigger some test or other
147 ####  -! 2  - triggers default B_TESTING_2='true' to trigger some test or other
148 ####  -! 3  - triggers B_TESTING_1='true' and B_TESTING_2='true'
149 ####  -! 10 - triggers an update from the primary dev download server instead of svn
150 ####  -! 11 - triggers an update from svn branch one - if present, of course
151 ####  -! 12 - triggers an update from svn branch two - if present, of course
152 ####  -! 13 - triggers an update from svn branch three - if present, of course
153 ####  -! 14 - triggers an update from svn branch four - if present, of course
154 ####  -! <http://......> - Triggers an update from whatever server you list.
155 #### LOG FLAGS (logs to $HOME/.inxi/inxi.log with rotate 3 total)
156 ####  -@ 8  - Basic data logging of generated data / array values
157 ####  -@ 9  - Full logging of all data used, including cat of files and system data
158 ####  -@ 10 - Basic data logging plus color code logging
159 ########################################################################
160 #### VARIABLES
161 ########################################################################
162
163 ## NOTE: we can use hwinfo if it's available in all systems, or most, to get
164 ## a lot more data and verbosity levels going
165 # set to default LANG to avoid locales errors with , or .
166 LANG=C
167 ### Variable initializations: null values
168 CMDL_MAX=''
169 COLOR_SCHEME=''
170 COLOR_SCHEME_SET=''
171 # override in user config if desired, seems like less than .3 doesn't work as reliably
172 CPU_SLEEP='0.3' 
173 DEV_DISK_LABEL=''
174 DEV_DISK_UUID=''
175 IRC_CLIENT=''
176 IRC_CLIENT_VERSION=''
177 PS_COUNT=5
178 PS_THROTTLED=''
179 REPO_DATA=''
180 REPO_FILE_ID=''
181
182 ### primary data array holders  ## usage: 'A_<var>'
183 A_AUDIO_DATA=''
184 A_CMDL=''
185 A_CPU_CORE_DATA=''
186 A_CPU_DATA=''
187 A_CPU_TYPE_PCNT_CCNT=''
188 A_DEBUG_BUFFER=''
189 A_GFX_CARD_DATA=''
190 A_GLX_DATA=''
191 A_HDD_DATA=''
192 A_INTERFACES_DATA=''
193 A_NETWORK_DATA=''
194 A_PARTITION_DATA=''
195 A_PS_DATA=''
196 A_SENSORS_DATA=''
197 A_UNMOUNTED_PARTITION_DATA=''
198 A_X_DATA=''
199
200 ### Boolean true/false globals  ## usage: 'B_<var>'
201 # flag to allow distro maintainers to turn off update features. If false, turns off
202 # -U and -! testing/advanced update options, as well as removing the -U help menu item
203 B_ALLOW_UPDATE='true'
204 # triggers full display of cpu flags
205 B_CPU_FLAGS_FULL='false'
206 # test for dbus irc client
207 B_DBUS_CLIENT='false'
208 # kde dcop
209 B_DCOP='false'
210 # Debug flood override: make 'true' to allow long debug output
211 B_DEBUG_FLOOD='false'
212 # show extra output data
213 B_EXTRA_DATA='false'
214 # override certain errors due to currupted data
215 B_HANDLE_CORRUPT_DATA='false'
216 B_LABEL_SET='false'
217 B_LOG_COLORS='false'
218 B_LOG_FULL_DATA='false'
219 # kde qdbus
220 B_QDBUS='false'
221 B_ROOT='false'
222 # Running in a shell? Defaults to false, and is determined later.
223 B_RUNNING_IN_SHELL='false'
224 # this sets the debug buffer
225 B_SCRIPT_UP='false'
226 # Show sound card data
227 B_SHOW_AUDIO='false'
228 B_SHOW_CPU='false'
229 B_SHOW_DISK='false'
230 # Show full hard disk output
231 B_SHOW_FULL_HDD='false'
232 B_SHOW_GRAPHICS='false'
233 # Set this to 'false' to avoid printing the hostname
234 B_SHOW_HOST='true'
235 B_SHOW_INFO='false'
236 B_SHOW_IP='false'
237 B_SHOW_LABELS='false'
238 B_SHOW_NETWORK='false'
239 # either -v > 3 or -P will show partitions
240 B_SHOW_PARTITIONS='false'
241 B_SHOW_PARTITIONS_FULL='false'
242 B_SHOW_PS_CPU_DATA='false'
243 B_SHOW_PS_MEM_DATA='false'
244 B_SHOW_REPOS='false'
245 B_SHOW_SENSORS='false'
246 # triggers only short inxi output
247 B_SHOW_SHORT_OUTPUT='false'
248 B_SHOW_SYSTEM='false'
249 B_SHOW_UNMOUNTED_PARTITIONS='false'
250 B_SHOW_UUIDS='false'
251 # triggers various debugging and new option testing
252 B_TESTING_1='false'
253 B_TESTING_2='false'
254 # set to true here for debug logging from script start
255 B_USE_LOGGING='false'
256 B_UUID_SET='false'
257 # Test for X running
258 B_X_RUNNING='false'
259
260 ### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
261 B_ASOUND_DEVICE_FILE='false'
262 B_ASOUND_VERSION_FILE='false'
263 B_BASH_ARRAY='false'
264 B_CPUINFO_FILE='false'
265 B_LSB_FILE='false'
266 B_MEMINFO_FILE='false'
267 B_MODULES_FILE='false' #
268 B_MOUNTS_FILE='false'
269 B_PARTITIONS_FILE='false' #
270 B_PROC_DIR='false'
271 B_SCSI_FILE='false'
272
273 ### File's used when present
274 FILE_ASOUND_DEVICE='/proc/asound/cards'
275 FILE_ASOUND_VERSION='/proc/asound/version'
276 FILE_CPUINFO='/proc/cpuinfo'
277 FILE_LSB_RELEASE='/etc/lsb-release'
278 FILE_MEMINFO='/proc/meminfo'
279 FILE_MODULES='/proc/modules'
280 FILE_MOUNTS='/proc/mounts'
281 FILE_PARTITIONS='/proc/partitions'
282 FILE_SCSI='/proc/scsi/scsi'
283
284 ## app tested for and present, to avoid repeat tests
285 B_FILE_TESTED='false'
286 B_HDDTEMP_TESTED='false'
287 B_MODINFO_TESTED='false'
288 B_SUDO_TESTED='false'
289 FILE_PATH=''
290 HDDTEMP_PATH=''
291 MODINFO_PATH=''
292 SUDO_PATH=''
293
294 ### Variable initializations: constants
295 DCOPOBJ="default"
296 DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels)
297 # Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up'
298 DEBUG_BUFFER_INDEX=0
299 ## note: the debugger rerouting to /dev/null has been moved to the end of the get_parameters function
300 ## so -@[number] debug levels can be set if there is a failure, otherwise you can't even see the errors
301
302 # Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Set to any other valid scheme you like.
303 # Same as runtime parameter.
304 DEFAULT_SCHEME=2
305
306 # Default indentation level
307 INDENT=10
308
309 # logging eval variables, start and end function: Insert to LOGFS LOGFE when debug level >= 8
310 LOGFS_STRING='log_function_data fs $FUNCNAME "$( echo $@ )"'
311 LOGFE_STRING='log_function_data fe $FUNCNAME'
312 LOGFS=''
313 LOGFE=''
314 # uncomment for debugging from script start
315 # LOGFS=$LOGFS_STRING
316 # LOGFE=$LOGFE_STRING
317
318 # default to false, no konversation found, 1 is native konvi (qt3/KDE3) script mode, 2 is /cmd inxi start,
319 ##      3 is Konversation > 1.2 (qt4/KDE4) 
320 KONVI=0
321 # NO_CPU_COUNT=0        # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
322 # This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
323 PARAMETER_LIMIT=30
324 SCHEME=0 # set default scheme
325 # this is set in user prefs file, to override dynamic temp1/temp2 determination of sensors output in case
326 # cpu runs colder than mobo
327 SENSORS_CPU_NO=''
328 # SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
329 SHOW_IRC=2
330 # Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
331 VERBOSITY_LEVEL=0
332 # Supported number of verbosity levels, including 0
333 VERBOSITY_LEVELS=5
334
335 # Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
336 # type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
337 # therefore results in nothing.
338 shopt -u nullglob
339 ## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
340 # Backup the current Internal Field Separator
341 ORIGINAL_IFS="$IFS"
342
343 # These two determine separators in single line output, to force irc clients not to break off sections
344 SEP1='-'
345 SEP2='~'
346
347 ### Script names/paths - must be non root writable
348 SCRIPT_DATA_DIR="$HOME/.inxi"
349 LOG_FILE="$SCRIPT_DATA_DIR/inxi.log"
350 LOG_FILE_1="$SCRIPT_DATA_DIR/inxi.1.log"
351 LOG_FILE_2="$SCRIPT_DATA_DIR/inxi.2.log"
352 SCRIPT_NAME="inxi"
353 SCRIPT_PATH=""                  #filled-in in Main
354 SCRIPT_VERSION_NUMBER=""        #filled-in in Main
355 SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
356 SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
357 SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
358 SCRIPT_DOWNLOAD_BRANCH_3='http://inxi.googlecode.com/svn/branches/three/'
359 SCRIPT_DOWNLOAD_BRANCH_4='http://inxi.googlecode.com/svn/branches/four/'
360 SCRIPT_DOWNLOAD_DEV='http://smxi.org/test/'
361 KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data)
362
363 ### Script Localization
364 # Make sure every program speaks English.
365 LC_ALL="C"
366 export LC_ALL
367
368 ### Output Colors
369 # A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
370 unset EMPTY
371 #              DGREY    BLACK    RED      DRED     GREEN    DGREEN   YELLOW   DYELLOW
372 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"
373 IRC_COLORS="   \x0314   \x0301   \x0304   \x0305   \x0309   \x0303   \x0308   \x0307"
374 #                            BLUE     DBLUE    MAGENTA  DMAGENTA CYAN     DCYAN    WHITE    GREY     NORMAL
375 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"
376 IRC_COLORS=" $IRC_COLORS    \x0312   \x0302   \x0313   \x0306   \x0311   \x0310   \x0300   \x0315   \x03"
377
378 #ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
379 A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL )
380 # See above for notes on EMPTY
381 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 )
382 ## Actual color variables
383 C1=''
384 C2=''
385 CN=''
386
387 ### Distro Data
388 # In cases of derived distros where the version file of the base distro can also be found under /etc,
389 # the derived distro's version file should go first. (Such as with Sabayon / Gentoo)
390 DISTROS_DERIVED="antix-version kanotix-version knoppix-version mandrake-release pardus-release sabayon-release sidux-version turbolinux-release zenwalk-version"
391 # debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
392 DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
393 DISTROS_PRIMARY="gentoo-release redhat-release slackware-version SuSE-release"
394 DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
395 ## Distros with known problems
396 # DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
397 # Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
398
399 ### Bans Data
400 # Precede a banword with $'\2' to prevent it from being subject to automated escaping by the make_ban_lists routine
401 # $'\1' gets weird results :
402 # user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v
403 # 00000000  01 01 6f 6e 65 20 74 77  6f 0a                    |..one two.|
404 A_NORMAL_BANS=( corporation communications gmbh technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" "®" $'\2'"\(rev ..\)" )
405 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]" )
406 # after processing, the ban arrays will be put into these:
407 BAN_LIST_NORMAL=''
408 BAN_LIST_CPU=''
409
410 # WARNING: In the main part below (search for 'KONVI')
411 # there's a check for Konversation-specific config files.
412 # Any one of these can override the above if inxi is run
413 # from Konversation!
414
415 ########################################################################
416 #### MAIN: Where it all begins
417 ########################################################################
418 main()
419 {
420         eval $LOGFS
421         
422         # This function just initializes variables
423         initialize_script_data
424
425         # Check for dependencies BEFORE running ANYTHING else except above functions
426         # Not all distro's have these depends installed by default
427         check_script_depends
428         check_script_suggested_apps
429         
430         # note: this needs to go AFTER depends check because these use gawk
431         # Do this after sourcing of config overrides so user can customize banwords
432         # Contrary to my previous belief, "${ARR[@]}" passes a quoted list, not one string
433         BAN_LIST_NORMAL=$( make_ban_lists "${A_NORMAL_BANS[@]}" ) 
434         BAN_LIST_CPU=$( make_ban_lists "${A_CPU_BANS[@]}" )
435         ##echo "BAN_LIST_NORMAL='$BAN_LIST_NORMAL'"
436
437         # first init function must be set first for colors etc. Remember, no debugger
438         # stuff works on this function unless you set the debugging flag manually.
439         # Debugging flag -@ [number] will not work until get_parameters runs.
440         
441         ### Only continue if depends ok
442         SCRIPT_PATH=$( dirname $0 )
443         SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
444         
445         ### Source global config overrides
446         if [[ -s /etc/$SCRIPT_NAME.conf ]];then
447                 source /etc/$SCRIPT_NAME.conf
448         fi
449         # Source user config overrides, ~/.inxi/inxi.conf
450         if [[ -s $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf ]];then
451                 source $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf
452         fi
453
454         ## this needs to run before the KONVI stuff is set below
455         ## Konversation 1.2 apparently does not like the $PPID test in get_start_client
456         ## So far there is no known way to detect if qt4_konvi is the parent process
457         ## this method will infer qt4_konvi as parent
458         
459         get_start_client
460
461         # note: this only works if it's run from inside konversation as a script builtin or something
462         # only do this if inxi has been started as a konversation script, otherwise bypass this 
463 #       KONVI=3 ## for testing puroses
464         ## 
465         if [[ $KONVI -eq 1 || $KONVI -eq 3 ]];then
466                 
467                 if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (ie 1.x < 1.2(qt3))    
468                         DCPORT="$1"
469                         DCSERVER="$2"
470                         DCTARGET="$3"
471                         shift 3
472                 elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
473                         DCSERVER="$1" ##dbus testing
474                         DCTARGET="$2" ##dbus testing
475                         shift 2
476                 fi
477
478                 # The section below is on request of Argonel from the Konversation developer team:
479                 # it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf
480                 IFS=":"
481                 for kde_config in $( kde-config --path data )
482                 do
483                         if [[ -r ${kde_config}${KONVI_CFG} ]];then
484                                 source "${kde_config}${KONVI_CFG}"
485                                 break
486                         fi
487                 done
488                 IFS="$ORIGINAL_IFS"
489         fi
490
491         ## leave this for debugging dcop stuff if we get that working
492         #       print_screen_output "DCPORT: $DCPORT"
493         #       print_screen_output "DCSERVER: $DCSERVER"
494         #       print_screen_output "DCTARGET: $DCTARGET"
495
496         # "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
497         # must be here to allow debugger and other flags to be set.
498         get_parameters "$@"
499
500         # If no colorscheme was set in the parameter handling routine, then set the default scheme
501         if [[ $COLOR_SCHEME_SET != 'true' ]];then
502                 set_color_scheme "$DEFAULT_SCHEME"
503         fi
504
505         # all the pre-start stuff is in place now
506         B_SCRIPT_UP='true'
507         script_debugger "Debugger: $SCRIPT_NAME is up and running..."
508         
509         # then create the output
510         print_it_out
511
512         ## last steps
513         if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
514                 echo -n "\e[0m"
515         fi
516         eval $LOGFE
517         # weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
518         # from the last command is taken..
519         exit 0
520 }
521
522 #### -------------------------------------------------------------------
523 #### basic tests: set script data, booleans, PATH
524 #### -------------------------------------------------------------------
525
526 # Set PATH data so we can access all programs as user. Set BAN lists.
527 # initialize some boleans, these directories are used throughout the script
528 # some apps are used for extended functions any directory used, should be
529 # checked here first.
530 # No args taken.
531 initialize_script_data()
532 {
533         eval $LOGFS
534         local path='' sys_path='' added_path='' b_path_found=''
535         # Extra path variable to make execute failures less likely, merged below
536         local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
537
538         # Fallback paths put into $extra_paths; This might, among others, help on gentoo.
539         # Now, create a difference of $PATH and $extra_paths and add that to $PATH:
540         IFS=":"
541         for path in $extra_paths
542         do
543                 b_path_found='false'
544                 for sys_path in $PATH
545                 do
546                         if [[ $path == $sys_path ]];then
547                                 b_path_found='true'
548                         fi
549                 done
550                 if [[ $b_path_found == 'false' ]];then
551                         added_path="$added_path:$path"
552                 fi
553         done
554
555         IFS="$ORIGINAL_IFS"
556         PATH="${PATH}${added_path}"
557         ##echo "PATH='$PATH'"
558         ##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
559
560         # now set the script BOOLEANS for files required to run features
561         if [[ -d "/proc/" ]];then
562                 B_PROC_DIR='true'
563         else
564                 error_handler 6
565         fi
566
567         if [[ -e $FILE_CPUINFO ]]; then
568                 B_CPUINFO_FILE='true'
569         fi
570
571         if [[ -e $FILE_MEMINFO ]];then
572                 B_MEMINFO_FILE='true'
573         fi
574
575         if [[ -e $FILE_ASOUND_DEVICE ]];then
576                 B_ASOUND_DEVICE_FILE='true'
577         fi
578
579         if [[ -e $FILE_ASOUND_VERSION ]];then
580                 B_ASOUND_VERSION_FILE='true'
581         fi
582
583         if [[ -f $FILE_LSB_RELEASE ]];then
584                 B_LSB_FILE='true'
585         fi
586
587         if [[ -e $FILE_SCSI ]];then
588                 B_SCSI_FILE='true'
589         fi
590
591         if [[ -n $DISPLAY ]];then
592                 B_X_RUNNING='true'
593         fi
594
595         if [[ -e $FILE_MODULES ]];then
596                 B_MODULES_FILE='true'
597         fi
598
599         if [[ -e $FILE_MOUNTS ]];then
600                 B_MOUNTS_FILE='true'
601         fi
602
603         if [[ -e $FILE_PARTITIONS ]];then
604                 B_PARTITIONS_FILE='true'
605         fi
606         # gfx output will require this flag
607         if [[ $( whoami ) == 'root' ]];then
608                 B_ROOT='true'
609         fi
610         eval $LOGFE
611 }
612
613 # No args taken.
614 check_script_suggested_apps()
615 {
616         eval $LOGFS
617         local bash_array_test=( "one" "two" )
618
619         # check for array ability of bash, this is only good for the warning at this time
620         # the boolean could be used later
621         # bash version 2.05b is used in DSL
622         # bash version 3.0 is used in Puppy Linux; it has a known array bug <reference to be placed here>
623         # versions older than 3.1 don't handle arrays
624         # distro's using below 2.05b are unknown, released in 2002
625         if [[ ${bash_array_test[1]} -eq "two" ]];then
626                 B_BASH_ARRAY='true'
627         else
628                 script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output"
629         fi
630         # now setting qdbus/dcop for first run, some systems can have both by the way
631         if [[ -n $( type -p qdbus ) ]];then
632                 B_QDBUS='true'
633         fi
634         if [[ -n $( type -p dcop ) ]];then
635                 B_DCOP='true'
636         fi
637         eval $LOGFE
638 }
639
640 # Determine if any of the absolutely necessary tools are absent
641 # No args taken.
642 check_script_depends()
643 {
644         eval $LOGFS
645         local app_name='' app_path=''
646         # bc removed from deps for now
647         local depends="df free gawk grep hostname lspci ps readlink tr uname uptime wc"
648         local x_apps="xrandr xdpyinfo glxinfo"
649
650         if [[ $B_X_RUNNING == 'true' ]];then
651                 for app_name in $x_apps
652                 do
653                         app_path=$( type -p $app_name )
654                         if [[ -z $app_path ]];then
655                                 script_debugger "Resuming in non X mode: $app_name not found in path"
656                                 B_X_RUNNING='false'
657                                 break
658                         fi
659                 done
660         fi
661
662         app_name=''
663
664         for app_name in $depends
665         do
666                 app_path=$( type -p $app_name )
667                 if [[ -z $app_path ]];then
668                         error_handler 5 "$app_name"
669                 fi
670         done
671         eval $LOGFE
672 }
673
674 ## note: this is now running inside each gawk sequence directly to avoid exiting gawk
675 ## looping in bash through arrays, then re-entering gawk to clean up, then writing back to array
676 ## in bash. For now I'll leave this here because there's still some interesting stuff to get re methods
677 # Enforce boilerplate and buzzword filters
678 # args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
679 sanitize_characters()
680 {
681         eval $LOGFS
682         # Cannot use strong quotes to unquote a string with pipes in it!
683         # bash will interpret the |'s as usual and try to run a subshell!
684         # Using weak quotes instead, or use '"..."'
685         echo "$2" | gawk "
686         BEGIN {
687                 IGNORECASE=1
688         }
689         {
690                 gsub(/${!1}/,\"\")
691                 gsub(/ [ ]+/,\" \")    ## ([ ]+) with (space)
692                 gsub(/^ +| +$/,\"\")   ## (pipe char) with (nothing)
693                 print                  ## prints (returns) cleaned input
694         }"
695         eval $LOGFE
696 }
697
698 # Filter boilerplate & buzzwords.
699 # args: $1 - quoted: "$@" array of ban terms
700 make_ban_lists()
701 {
702         eval $LOGFS
703         local ban_list=''
704         # Iterate over $@
705         ## note: this is a weird, non-intuitive method, needs some documentation or rewriting
706         ## if you declare ban_string it stops working, have to read up on this
707         for ban_string
708         do
709                 # echo "term=\"$ban_string\"" # >&2
710                 if [[ ${ban_string:0:1} = $'\2' ]];then
711                         ban_list="${ban_list}${ban_list+|}${ban_string:1:${#ban_string}-1}"
712                 else
713                         # Automatically escapes [ ] ( ) . and +
714                         ban_list="${ban_list}${ban_list+|}$( echo "$ban_string" | gawk '{
715                                 gsub(/([\[\]+().])/,"\\\\&")
716                                 print
717                         }' )"
718                 fi
719         done
720
721         echo "$ban_list"
722         eval $LOGFS
723 }
724 # make_ban_lists "${A_CPU_BANS[@]}";exit
725
726 # Set the colorscheme
727 # args: $1 = <scheme number>|<"none">
728 set_color_scheme()
729 {
730         eval $LOGFS
731         local i='' script_colors='' color_codes=''
732
733         if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then
734                 set -- 1
735         fi
736         # Set a global variable to allow checking for chosen scheme later
737         SCHEME="$1"
738         if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
739                 color_codes=( $ANSI_COLORS )
740         else
741                 color_codes=( $IRC_COLORS )
742         fi
743         for (( i=0; i < ${#A_COLORS_AVAILABLE[@]}; i++ ))
744         do
745                 eval "${A_COLORS_AVAILABLE[i]}=\"${color_codes[i]}\""
746         done
747         IFS=","
748         script_colors=( ${A_COLOR_SCHEMES[$1]} )
749         IFS="$ORIGINAL_IFS"
750         # then assign the colors globally
751         C1="${!script_colors[0]}"
752         C2="${!script_colors[1]}"
753         CN="${!script_colors[2]}"
754         # ((COLOR_SCHEME++)) ## note: why is this? ##
755         eval $LOGFE
756 }
757
758 ########################################################################
759 #### UTILITY FUNCTIONS
760 ########################################################################
761
762 #### -------------------------------------------------------------------
763 #### error handler, debugger, script updater
764 #### -------------------------------------------------------------------
765
766 # Error handling
767 # args: $1 - error number; $2 - optional, extra information
768 error_handler()
769 {
770         eval $LOGFS
771         local error_message=''
772
773         # assemble the error message
774         case $1 in
775                 2)      error_message="large flood danger, debug buffer full!"
776                         ;;
777                 3)      error_message="unsupported color scheme number: $2"
778                         ;;
779                 4)      error_message="unsupported verbosity level: $2"
780                         ;;
781                 5)      error_message="dependency not met: $2 not found in path"
782                         ;;
783                 6)      error_message="/proc not found! Quitting..."
784                         ;;
785                 7)      error_message="One of the options you entered in your script parameters: $2\nis not supported.The option may require extra arguments to work.\nFor supported options (and their arguments), check the help menu: $SCRIPT_NAME -h"
786                         ;;
787                 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"
788                         ;;
789                 9)      error_message="unsupported debugging level: $2"
790                         ;;
791                 10)
792                         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/"
793                         ;;
794                 11)
795                         error_message="unsupported testing option argument: -! $2"
796                         ;;
797                 12)
798                         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."
799                         ;;
800                 13)
801                         error_message="The -t option requires the following extra arguments (no spaces between letters/numbers):\nc m cm [required], for example: -t cm8 OR -t cm OR -t c9\n(numbers: 1-20, > 5 throttled to 5 in irc clients) You entered: $2"
802                         ;;
803                 *)      error_message="error unknown: $@"
804                         set -- 99
805                         ;;
806         esac
807         # then print it and exit
808         print_screen_output "Error $1: $error_message"
809         eval $LOGFE
810         exit $1
811 }
812
813 # prior to script up set, pack the data into an array
814 # then we'll print it out later.
815 # args: $1 - $@ debugging string text
816 script_debugger()
817 {
818         eval $LOGFS
819         if [[ $B_SCRIPT_UP == 'true' ]];then
820                 # only return if debugger is off and no pre start up errors have occured
821                 if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
822                         return 0
823                 # print out the stored debugging information if errors occured
824                 elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
825                         for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
826                         do
827                                 print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
828                         done
829                         DEBUG_BUFFER_INDEX=0
830                 fi
831                 # or print out normal debugger messages if debugger is on
832                 if [[ $DEBUG -gt 0 ]];then
833                         print_screen_output "$1"
834                 fi
835         else
836                 if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
837                         error_handler 2
838                 # this case stores the data for later printout, will print out only
839                 # at B_SCRIPT_UP == 'true' if array index > 0
840                 else
841                         A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
842                         # increment count for next pre script up debugging error
843                         (( DEBUG_BUFFER_INDEX++ ))
844                 fi
845         fi
846         eval $LOGFE
847 }
848
849 # NOTE: no logging available until get_parameters is run, since that's what sets logging
850 # in order to trigger earlier logging manually set B_USE_LOGGING to true in top variables.
851 # $1 alone: logs data; $2 with or without $3 logs func start/end.
852 # $1 type (fs/fe/cat/raw) or logged data; [$2 is $FUNCNAME; [$3 - function args]]
853 log_function_data()
854 {
855         if [ "$B_USE_LOGGING" == 'true' ];then
856                 local logged_data='' spacer='   ' line='----------------------------------------'
857                 case $1 in
858                         fs)
859                                 logged_data="Function: $2 - Primary: Start"
860                                 if [ -n "$3" ];then
861                                         logged_data="$logged_data\n${spacer}Args: $3"
862                                 fi
863                                 spacer=''
864                                 ;;
865                         fe)
866                                 logged_data="Function: $2 - Primary: End"
867                                 spacer=''
868                                 ;;
869                         cat)
870                                 if [[ $B_LOG_FULL_DATA == 'true' ]];then
871                                         logged_data="\n$line\nFull file data: cat $2\n\n$( cat $2 )\n$line\n"
872                                         spacer=''
873                                 fi
874                                 ;;
875                         raw)
876                                 if [[ $B_LOG_FULL_DATA == 'true' ]];then
877                                         logged_data="\n$line\nRaw system data:\n\n$2\n$line\n"
878                                         spacer=''
879                                 fi
880                                 ;;
881                         *)
882                                 logged_data="$1"
883                                 ;;
884                 esac
885                 # Create any required line breaks and strip out escape color code, either ansi (case 1)or irc (case 2).
886                 # This pattern doesn't work for irc colors, if we need that someone can figure it out
887                 if [[ -n $logged_data ]];then
888                         if [[ $B_LOG_COLORS != 'true' ]];then
889                                 echo -e "${spacer}$logged_data" | sed -r 's/\x1b\[[0-9]{1,2}(;[0-9]{1,2}){0,2}m//g' >> $LOG_FILE
890                         else
891                                 echo -e "${spacer}$logged_data" >> $LOG_FILE
892                         fi
893                 fi
894         fi
895 }
896
897 # called in the initial -@ 10 script args setting so we can get logging as soon as possible
898 # will have max 3 files, inxi.log, inxi.1.log, inxi.2.log
899 create_rotate_logfiles()
900 {
901         if [[ ! -d $SCRIPT_DATA_DIR ]];then
902                 mkdir $SCRIPT_DATA_DIR
903         fi
904         # do the rotation if logfile exists
905         if [[ -f $LOG_FILE ]];then
906                 # copy if present second to third
907                 if [[ -f $LOG_FILE_1 ]];then
908                         mv -f $LOG_FILE_1 $LOG_FILE_2
909                 fi
910                 # then copy initial to second
911                 mv -f $LOG_FILE $LOG_FILE_1
912         fi
913         # now create the logfile
914         touch $LOG_FILE
915         # and echo the start data
916         echo "=========================================================" >> $LOG_FILE
917         echo "START $SCRIPT_NAME LOGGING:"                               >> $LOG_FILE
918         echo "Script started: $( date +%Y-%m-%d-%H:%M:%S )"              >> $LOG_FILE
919         echo "=========================================================" >> $LOG_FILE
920 }
921
922 # args: $1 - download url, not including file name; $2 - string to print out
923 # note that $1 must end in / to properly construct the url path
924 script_self_updater()
925 {
926         eval $LOGFS
927         local wget_error=0
928         print_screen_output "Starting $SCRIPT_NAME self updater."
929         print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER"
930         print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..."
931         # first test if path is good, need to make sure it's good because we're -O overwriting file
932         wget -q --spider $1$SCRIPT_NAME || wget_error=$?
933         # then do the actual download
934         if [[ $wget_error -eq 0 ]];then
935                 wget -q -O $SCRIPT_PATH/$SCRIPT_NAME $1$SCRIPT_NAME || wget_error=$?
936                 if [[ $wget_error -eq 0 ]];then
937                         SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
938                         print_screen_output "Successfully updated to $2 version: $SCRIPT_VERSION_NUMBER"
939                         print_screen_output "To run the new version, just start $SCRIPT_NAME again."
940                         exit 0
941                 fi
942         fi
943         # now run the error handlers on any wget failure
944         if [[ $wget_error -gt 0 ]];then
945                 if [[ $2 == 'svn server' ]];then
946                         error_handler 8 "$wget_error"
947                 elif [[ $2 == 'alt server' ]];then
948                         error_handler 10 "$1"
949                 else
950                         error_handler 12 "$1"
951                 fi
952         fi
953         eval $LOGFS
954 }
955
956 #### -------------------------------------------------------------------
957 #### print / output cleaners
958 #### -------------------------------------------------------------------
959
960 # inxi speaks through here. When run by Konversation script alias mode, uses DCOP
961 # for dcop to work, must use 'say' operator, AND colors must be evaluated by echo -e
962 # note: dcop does not seem able to handle \n so that's being stripped out and replaced with space.
963 print_screen_output()
964 {
965         eval $LOGFS
966         # the double quotes are needed to avoid losing whitespace in data when certain output types are used
967         local print_data="$( echo -e "$1" )"
968
969         # just using basic debugger stuff so you can tell which thing is printing out the data. This
970         # should help debug kde 4 konvi issues when that is released into sid, we'll see. Turning off
971         # the redundant debugger output which as far as I can tell does exactly nothing to help debugging.
972         if [[ $DEBUG -gt 5 ]];then
973                 if [[ $KONVI -eq 1 ]];then
974                         # konvi doesn't seem to like \n characters, it just prints them literally
975                         # print_data="$( tr '\n' ' ' <<< "$print_data" )"
976                         # dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "konvi='$KONVI' saying : '$print_data'"
977                         print_data="KP-$KONVI: $print_data"
978                 elif [[ $KONVI -eq 2 ]];then
979                         # echo "konvi='$KONVI' saying : '$print_data'"
980                         print_data="KP-$KONVI: $print_data"
981                 else
982                         # echo "printing out: '$print_data'"
983                         print_data="P: $print_data"
984                 fi
985         fi
986
987         if [[ $KONVI -eq 1 && $B_DCOP == 'true' ]]; then ## dcop Konversation (<= 1.1 (qt3))
988                 # konvi doesn't seem to like \n characters, it just prints them literally
989                 $print_data="$( tr '\n' ' ' <<< "$print_data" )"
990                 dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data"
991
992         elif [[ $KONVI -eq 3 && $B_QDBUS == 'true' ]]; then ## dbus Konversation (> 1.2 (qt4))
993                 qdbus org.kde.konversation /irc say "$DCSERVER" "$DCTARGET" "$print_data"
994
995 #       elif [[ $IRC_CLIENT == 'X-Chat' ]]; then
996 #               qdbus org.xchat.service print "$print_data\n"
997
998         else
999                 # the -n is needed to avoid double spacing of output in terminal
1000                 echo -ne "$print_data\n"
1001         fi
1002         eval $LOGFE
1003 }
1004
1005 ## this handles all verbose line construction with indentation/line starter
1006 ## args: $1 - null (, actually: " ") or line starter; $2 - line content
1007 create_print_line()
1008 {
1009         eval $LOGFS
1010         printf "${C1}%-${INDENT}s${C2} %s" "$1" "$2"
1011         eval $LOGFE
1012 }
1013
1014 # this removes newline and pipes.
1015 # args: $1 - string to clean
1016 remove_erroneous_chars()
1017 {
1018         eval $LOGFS
1019         ## RS is input record separator
1020         ## gsub is substitute;
1021         gawk '
1022         BEGIN {
1023                 RS=""
1024         }
1025         {
1026                 gsub(/\n$/,"")         ## (newline; end of string) with (nothing)
1027                 gsub(/\n/," ");        ## (newline) with (space)
1028                 gsub(/^ *| *$/, "")    ## (pipe char) with (nothing)
1029                 gsub(/  +/, " ")       ## ( +) with (space)
1030                 gsub(/ [ ]+/, " ")     ## ([ ]+) with (space)
1031                 gsub(/^ +| +$/, "")    ## (pipe char) with (nothing)
1032                 printf $0
1033         }' "$1"      ## prints (returns) cleaned input
1034         eval $LOGFE
1035 }
1036
1037 #### -------------------------------------------------------------------
1038 #### parameter handling, print usage functions.
1039 #### -------------------------------------------------------------------
1040
1041 # Get the parameters. Note: standard options should be lower case, advanced or testing, upper
1042 # args: $1 - full script startup args: $@
1043 get_parameters()
1044 {
1045         eval $LOGFS
1046         local opt='' wget_test='' update_flags='U!:'
1047         local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false
1048
1049         # If distro maintainers want to not allow updates, turn off that option for users
1050         if [[ $B_ALLOW_UPDATE == 'false' ]];then
1051                 update_flags=''
1052         fi
1053
1054         # the short form only runs if no args output args are used
1055         # no need to run through these if there are no args
1056         if [[ -n $1 ]];then
1057                 while getopts Ac:CdDfFGhHiIlNopPrsSt:uv:Vx%@:${update_flags} opt
1058                 do
1059                         case $opt in
1060                         A)      B_SHOW_AUDIO='true'
1061                                 use_short='false'
1062                                 ;;
1063                         c)      if [[ -n $( grep -E '^[0-9][0-9]?$' <<< $OPTARG ) ]];then
1064                                         COLOR_SCHEME_SET='true'
1065                                         ## note: not sure about this, you'd think user values should be overridden, but
1066                                         ## we'll leave this for now
1067                                         if [[ -z $COLOR_SCHEME ]];then
1068                                                 set_color_scheme "$OPTARG"
1069                                         fi
1070                                 else
1071                                         error_handler 3 "$OPTARG"
1072                                 fi
1073                                 ;;
1074                         C)      B_SHOW_CPU='true'
1075                                 use_short='false'
1076                                 ;;
1077                         d)      VERBOSITY_LEVEL=1
1078                                 use_short='false'
1079                                 ;;
1080                         D)      B_SHOW_DISK='true'
1081                                 use_short='false'
1082                                 ;;
1083                         f)      B_SHOW_CPU='true'
1084                                 B_CPU_FLAGS_FULL='true'
1085                                 use_short='false'
1086                                 ;;
1087                         F)      VERBOSITY_LEVEL=$VERBOSITY_LEVELS
1088                                 B_EXTRA_DATA='true'
1089                                 B_SHOW_DISK='true'
1090                                 B_SHOW_PARTITIONS='true'
1091                                 B_SHOW_AUDIO='true'
1092                                 use_short='false'
1093                                 ;;
1094                         G)      B_SHOW_GRAPHICS='true'
1095                                 use_short='false'
1096                                 ;;
1097                         i)      B_SHOW_IP='true'
1098                                 B_SHOW_NETWORK='true'
1099                                 use_short='false'
1100                                 ;;
1101                         I)      B_SHOW_INFO='true'
1102                                 use_short='false'
1103                                 ;;
1104                         l)      B_SHOW_LABELS='true'
1105                                 B_SHOW_PARTITIONS='true'
1106                                 use_short='false'
1107                                 ;;
1108                         N)      B_SHOW_NETWORK='true'
1109                                 use_short='false'
1110                                 ;;
1111                         o) B_SHOW_UNMOUNTED_PARTITIONS='true'
1112                                 use_short='false'
1113                                 ;;
1114                         p)      B_SHOW_PARTITIONS_FULL='true'
1115                                 B_SHOW_PARTITIONS='true'
1116                                 use_short='false'
1117                                 ;;
1118                         P)      B_SHOW_PARTITIONS='true'
1119                                 use_short='false'
1120                                 ;;
1121                         r)      B_SHOW_REPOS='true'
1122                                 use_short='false'
1123                                 ;;
1124                         
1125                         s)      B_SHOW_SENSORS='true'
1126                                 use_short='false'
1127                                 ;;
1128                         S)      B_SHOW_SYSTEM='true'
1129                                 use_short='false'
1130                                 ;;
1131                         t)      if [[ -n $( grep -E '^(c|m|cm|mc)([1-9]|1[0-9]|20)?$' <<< $OPTARG ) ]];then
1132                                         use_short='false'
1133                                         if [[ -n $( grep -E '[0-9]+' <<< $OPTARG ) ]];then
1134                                                 PS_COUNT=$( grep -Eo '[0-9]+' <<< $OPTARG )
1135                                         fi
1136                                         if [[ -n $( grep 'c' <<< $OPTARG ) ]];then
1137                                                 B_SHOW_PS_CPU_DATA='true'
1138                                         fi
1139                                         if [[ -n $( grep 'm' <<< $OPTARG ) ]];then
1140                                                 B_SHOW_PS_MEM_DATA='true'
1141                                         fi
1142                                 else
1143                                         error_handler 13 "$OPTARG"
1144                                 fi
1145                                 ;;
1146                         u)      B_SHOW_UUIDS='true'
1147                                 B_SHOW_PARTITIONS='true'
1148                                 use_short='false'
1149                                 ;;
1150                         v)      if [[ -n $( grep -E "^[0-9][0-9]?$" <<< $OPTARG ) && $OPTARG -le $VERBOSITY_LEVELS ]];then
1151                                         VERBOSITY_LEVEL="$OPTARG"
1152                                         if [[ $OPTARG -gt 0 ]];then
1153                                                 use_short='false'
1154                                         fi
1155                                 else
1156                                         error_handler 4 "$OPTARG"
1157                                 fi
1158                                 ;;
1159                         U)      script_self_updater "$SCRIPT_DOWNLOAD" 'svn server'
1160                                 ;;
1161                         V)      print_version_info
1162                                 exit 0
1163                                 ;;
1164                         x)      B_EXTRA_DATA='true'
1165                                 ;;
1166                         h)      show_options
1167                                 exit 0
1168                                 ;;
1169                         H)      show_options 'full'
1170                                 exit 0
1171                                 ;;
1172                         ## debuggers and testing tools
1173                         %)      B_HANDLE_CORRUPT_DATA='true'
1174                                 ;;
1175                         @)      if [[ -n $( grep -E "^([1-9]|10)$" <<< $OPTARG ) ]];then
1176                                         DEBUG=$OPTARG
1177                                         exec 2>&1
1178                                         # switch on logging only for -@ 8-10
1179                                         if [[ $OPTARG -ge 8 ]];then
1180                                                 if [[ $OPTARG -eq 10 ]];then
1181                                                         B_LOG_COLORS='true'
1182                                                 elif [[ $OPTARG -eq 9 ]];then           
1183                                                         B_LOG_FULL_DATA='true'
1184                                                 fi
1185                                                 B_USE_LOGGING='true'
1186                                                 # pack the logging data for evals function start/end
1187                                                 LOGFS=$LOGFS_STRING
1188                                                 LOGFE=$LOGFE_STRING
1189                                                 create_rotate_logfiles # create/rotate logfiles before we do anything else
1190                                         fi
1191                                 else
1192                                         error_handler 9 "$OPTARG"
1193                                 fi
1194                                 ;;
1195                         !)      # test for various supported methods
1196                                 case $OPTARG in
1197                                         1)      B_TESTING_1='true'
1198                                                 ;;
1199                                         2)      B_TESTING_2='true'
1200                                                 ;;
1201                                         3)      B_TESTING_1='true'
1202                                                 B_TESTING_2='true'
1203                                                 ;;
1204                                         10)
1205                                                 script_self_updater "$SCRIPT_DOWNLOAD_DEV" 'dev server'
1206                                                 ;;
1207                                         11)
1208                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_1" 'svn: branch one server'
1209                                                 ;;
1210                                         12)
1211                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_2" 'svn: branch two server'
1212                                                 ;;
1213                                         13)
1214                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_3" 'svn: branch three server'
1215                                                 ;;
1216                                         14)
1217                                                 script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_4" 'svn: branch four server'
1218                                                 ;;
1219                                         http*)
1220                                                 script_self_updater "$OPTARG" 'alt server'
1221                                                 ;;
1222                                         *)      error_handler 11 "$OPTARG"
1223                                                 ;;
1224                                 esac
1225                                 ;;
1226                         *)      error_handler 7 "$1"
1227                                 ;;
1228                         esac
1229                 done
1230         fi
1231         ## this must occur here so you can use the debugging flag to show errors
1232         ## Reroute all error messages to the bitbucket (if not debugging)
1233         if [[ $DEBUG -eq 0 ]];then
1234                 exec 2>/dev/null
1235         fi
1236         #((DEBUG)) && exec 2>&1 # This is for debugging konversation
1237
1238         # after all the args have been processed, if no long output args used, run short output
1239         if [[ $use_short == 'true' ]];then
1240                 B_SHOW_SHORT_OUTPUT='true'
1241         fi
1242         eval $LOGFE
1243 }
1244
1245 ## print out help menu, not including Testing or Debugger stuff because it's not needed
1246 show_options()
1247 {
1248         local color_scheme_count=${#A_COLOR_SCHEMES[@]}
1249
1250         print_screen_output "$SCRIPT_NAME supports the following options. You can combine them, or list them"
1251         print_screen_output "one by one: Examples: $SCRIPT_NAME -v4 -c6 OR $SCRIPT_NAME -dDc 6"
1252         print_screen_output ""
1253         print_screen_output "If you start $SCRIPT_NAME with no arguments, it will show the short form."
1254         print_screen_output "The following options if used without -d or -v will show just that complete line:"
1255         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."
1256         print_screen_output "If you use them with a -v level (or -d), it will show the full output for that line "
1257         print_screen_output "along with the output for the chosen verbosity level."
1258         print_screen_output "- - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
1259         print_screen_output "Output Control Options:"
1260         print_screen_output "-A  Show Audio/sound card information."
1261         print_screen_output "-c  Available color schemes. Scheme number is required."
1262         print_screen_output "    Supported schemes: 0-$color_scheme_count Example: $SCRIPT_NAME -c 11"
1263         print_screen_output "-C  Show full CPU output, including per CPU clockspeed."
1264         print_screen_output "-d  Default output verbosity level, same as: $SCRIPT_NAME -v 1"
1265         print_screen_output "-D  Show full hard Disk info, not only model, ie: /dev/sda ST380817AS 80.0GB."
1266         print_screen_output "-f  Show all cpu flags used, not just the short list. Not shown with -F to avoid spamming."
1267         print_screen_output "-F  Show Full output for $SCRIPT_NAME. Does not show extra verbose options like -f -u -l -o -p or -t"
1268         print_screen_output "-G  Show Graphic card information (card, x type, resolution, glx renderer, version)."
1269         print_screen_output "-i  Show Wan IP address, and shows local interfaces (requires ifconfig network tool)."
1270         print_screen_output "    Not shown with -F for user security reasons, you shouldn't paste your local/wan IP."
1271         print_screen_output "-I  Show Information: processes, uptime, memory, irc client, inxi version."
1272         print_screen_output "-l  Show partition labels. Default: short partition -P. For full -p output, use: -pl (or -plu)."
1273         print_screen_output "-N  Show Network card information."
1274         print_screen_output "-o  Show unmounted partition information (includes UUID and LABEL if available)."
1275         print_screen_output "    Shows file system type if you have file installed, if you are root OR if you have"
1276         print_screen_output "    added to /etc/sudoers (sudo v. 1.7 or newer): <username> ALL = NOPASSWD: /usr/bin/file (sample)"
1277         print_screen_output "-p  Show full partition information (-P plus all other detected partitions)."
1278         print_screen_output "-P  Show Partition information (shows what -v 4 would show, but without extra data)."
1279         print_screen_output "    Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted partitions."
1280         print_screen_output "-r  Show distro repository data. Currently supported repo types: APT; PACMAN; PISI; YUM."
1281         print_screen_output "-s  Show sensors output (if sensors installed/configured): mobo/cpu/gpu temp; detected fan speeds."
1282         print_screen_output "    Gpu temp only for Fglrx/Nvidia drivers. Nvidia shows screen number for > 1 screens."
1283         print_screen_output "-S  Show System information: host name, kernel, distro"
1284         print_screen_output "-t  Show processes. Requires extra options: c (cpu) m (memory) cm (cpu+memory). If followed by numbers 1-20,"
1285         print_screen_output "    shows that number of processes for each type (default: $PS_COUNT; if in irc, max: 5): -t cm10"
1286         print_screen_output "    Make sure to have no space between letters and numbers (-t cm10 -right, -t cm 10 -wrong)."
1287         print_screen_output "-u  Show partition UUIDs. Default: short partition -P. For full -p output, use: -pu (or -plu)."
1288         print_screen_output "-v  Script verbosity levels. Verbosity level number is required."
1289         print_screen_output "    Supported levels: 0-${VERBOSITY_LEVELS} Example: $SCRIPT_NAME -v 4"
1290         print_screen_output "    0 - short output, same as: $SCRIPT_NAME"
1291         print_screen_output "    1 - basic verbose, same as: $SCRIPT_NAME -d"
1292         print_screen_output "    2 - Also show networking card data"
1293         print_screen_output "    3 - Also show hard disk names as detected."
1294         print_screen_output "    4 - Also show partition size/filled data for (if present):/, /home, /var/, /boot"
1295         print_screen_output "    5 - For multicore systems, also shows: per core clock speeds; audio card; full disk data."
1296         print_screen_output "-x  Show extra data: bogomips on Cpu; driver version (if available) for Network/Audio;"
1297         print_screen_output "    for network, audio cards, shows PCI Bus ID number also;"
1298         print_screen_output "    direct rendering status for Graphics (in X). Only works with verbose or line output;"
1299         print_screen_output "    shows (for single gpu, nvidia driver) screen number gpu is running on."
1300         print_screen_output "    Shows hdd temp with disk data if you have hddtemp installed, if you are root OR if you have"
1301         print_screen_output "    added to /etc/sudoers (sudo v. 1.7 or newer): <username> ALL = NOPASSWD: /usr/sbin/hddtemp (sample)"
1302         print_screen_output "    For -t, adds memory use output to cpu (-tx c), and cpu use to memory (-tx m)."
1303         print_screen_output ""
1304         print_screen_output "Additional Options:"
1305         print_screen_output "-h - this help menu."
1306         if [[ $B_ALLOW_UPDATE == 'true' ]];then
1307                 print_screen_output "-U  Auto-update script. Note: if you installed as root, you"
1308                 print_screen_output "    must be root to update, otherwise user is fine."
1309         fi
1310         print_screen_output "-V  $SCRIPT_NAME version information. Prints information then exits."
1311         print_screen_output "-%  Overrides defective or corrupted data."
1312         print_screen_output "-@  Triggers debugger output. Requires debugging level 1-10 (8-10 - logging)."
1313         print_screen_output "    8 - basic logging; 9 - full file/sys info logging; 10 - color logging."
1314         if [[ $1 == 'full' ]];then
1315                 print_screen_output ""
1316                 print_screen_output "Developer and Testing Options (Advanced):"
1317                 print_screen_output "-! 1 - Sets testing flag B_TESTING_1='true' to trigger testing condition 1."
1318                 print_screen_output "-! 2 - Sets testing flag B_TESTING_2='true' to trigger testing condition 2."
1319                 print_screen_output "-! 3 - Sets flags B_TESTING_1='true' and B_TESTING_2='true'."
1320                 print_screen_output "-! 10 - Triggers an update from the primary dev download server instead of svn."
1321                 print_screen_output "-! 11 - Triggers an update from svn branch one - if present, of course."
1322                 print_screen_output "-! 12 - Triggers an update from svn branch two - if present, of course."
1323                 print_screen_output "-! 13 - Triggers an update from svn branch three - if present, of course."
1324                 print_screen_output "-! 14 - Triggers an update from svn branch four - if present, of course."
1325                 print_screen_output "-! <http://......> - Triggers an update from whatever server you list."
1326                 print_screen_output ""
1327         fi
1328         print_screen_output ""
1329 }
1330
1331 ## print out version information for -V/--version
1332 print_version_info()
1333 {
1334         local last_modified=$( grep -im 1 'date:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3,$4,$5}' )
1335
1336         print_screen_output "$SCRIPT_NAME - the universal, portable, system info script for irc."
1337         print_screen_output "Version: $SCRIPT_VERSION_NUMBER"
1338         print_screen_output "Script Last Modified: $last_modified"
1339         print_screen_output "Script Location: $SCRIPT_PATH"
1340         print_screen_output ""
1341         print_screen_output "Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,"
1342         print_screen_output "Gaim/Pidgin, Weechat, KVIrc and Kopete."
1343         print_screen_output ""
1344         print_screen_output "This script is a fork of Infobash 3.02, which is:"
1345         print_screen_output "Copyright (C) 2005-2007  Michiel de Boer a.k.a. locsmif"
1346         print_screen_output "Subsequent changes and modifications (after Infobash 3.02) are:"
1347         print_screen_output "Copyright (C) 2008-10 Scott Rogers, Harald Hope, aka trash80 & h2"
1348         print_screen_output ""
1349         print_screen_output "This program is free software; you can redistribute it and/or modify"
1350         print_screen_output "it under the terms of the GNU General Public License as published by"
1351         print_screen_output "the Free Software Foundation; either version 3 of the License, or"
1352         print_screen_output "(at your option) any later version."
1353 }
1354
1355 ########################################################################
1356 #### MAIN FUNCTIONS
1357 ########################################################################
1358
1359 #### -------------------------------------------------------------------
1360 #### initial startup stuff
1361 #### -------------------------------------------------------------------
1362
1363 # Determine where inxi was run from, set IRC_CLIENT and IRC_CLIENT_VERSION
1364 get_start_client()
1365 {
1366         eval $LOGFS
1367         local irc_client_path='' irc_client_path_lower='' non_native_konvi='' i=''
1368         local b_non_native_app='false' pppid='' app_working_name=''
1369         local b_qt4_konvi='false'
1370
1371         if tty >/dev/null;then
1372                 IRC_CLIENT='Shell'
1373                 unset IRC_CLIENT_VERSION
1374                 B_RUNNING_IN_SHELL='true'
1375         elif [[ -n $PPID && -f /proc/$PPID/exe ]];then
1376                 irc_client_path=$( readlink /proc/$PPID/exe )
1377                 irc_client_path_lower=$( tr '[:upper:]' '[:lower:]' <<< $irc_client_path )
1378                 app_working_name=$( basename $irc_client_path_lower )
1379                 # handles the xchat/sh/bash/dash cases, and the konversation/perl cases, where clients
1380                 # report themselves as perl or unknown shell. IE:  when konversation starts inxi
1381                 # from inside itself, as a script, the parent is konversation/xchat, not perl/bash etc
1382                 # note: perl can report as: perl5.10.0, so it needs wildcard handling
1383                 case $app_working_name in
1384                         bash|dash|sh|perl*)     # We want to know who wrapped it into the shell or perl.
1385                                 pppid="$( ps -p $PPID -o ppid --no-headers | sed 's/ //g' )"
1386                                 if [[ -n $pppid && -f /proc/$pppid/exe ]];then
1387                                         irc_client_path="$( readlink /proc/$pppid/exe )"
1388                                         irc_client_path_lower="$( tr '[:upper:]' '[:lower:]' <<< $irc_client_path )"
1389                                         app_working_name=$( basename $irc_client_path_lower )
1390                                         b_non_native_app='true'
1391                                 fi
1392                                 ;;
1393                 esac
1394                 # replacing loose detection with tight detection, bugs will be handled with app names
1395                 # as they appear.
1396                 case $app_working_name in
1397                         # check for shell first
1398                         bash|dash|sh)
1399                                 unset IRC_CLIENT_VERSION
1400                                 IRC_CLIENT="Shell wrapper"
1401                                 ;;
1402                         # now start on irc clients, alphabetically
1403                         bitchx)
1404                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
1405                                 /Version/ {
1406                                         a=tolower($2)
1407                                         gsub(/[()]|bitchx-/,"",a)
1408                                         print a
1409                                         exit
1410                                 }
1411                                 $2 == "version" {
1412                                         a=tolower($3)
1413                                         sub(/bitchx-/,"",a)
1414                                         print a
1415                                         exit
1416                                 }' )"
1417                                 IRC_CLIENT="BitchX"
1418                                 ;;
1419                         finch)
1420                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1421                                         print $2
1422                                 }' )"
1423                                 IRC_CLIENT="Finch"
1424                                 ;;
1425                         gaim)
1426                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1427                                         print $2
1428                                 }' )"
1429                                 IRC_CLIENT="Gaim"
1430                                 ;;
1431                         ircii)
1432                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1433                                         print $3
1434                                 }' )"
1435                                 IRC_CLIENT="ircII"
1436                                 ;;
1437                         irssi-text|irssi)
1438                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1439                                         print $2
1440                                 }' )"
1441                                 IRC_CLIENT="Irssi"
1442                                 ;;
1443                         konversation) ## konvi < 1.2 (qt4)
1444                                 # this is necessary to avoid the dcop errors from starting inxi as a /cmd started script
1445                                 if [[ $b_non_native_app == 'true' ]];then  ## true negative is confusing
1446                                         KONVI=2
1447                                 else # if native app
1448                                         KONVI=1
1449                                 fi
1450                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
1451                                 /Konversation:/ {
1452                                         for ( i=2; i<=NF; i++ ) {
1453                                                 if (i == NF) {
1454                                                         print $i
1455                                                 }
1456                                                 else {
1457                                                         printf $i" "
1458                                                 }
1459                                         }
1460                                         exit
1461                                 }' )"
1462
1463                                 T=($IRC_CLIENT_VERSION)
1464                                 if [[ ${T[0]} == *+* ]];then
1465                                         # < Sho_> locsmif: The version numbers of SVN versions look like this:
1466                                         #         "<version number of last release>+ #<build number", i.e. "1.0+ #3177" ...
1467                                         #         for releases we remove the + and build number, i.e. "1.0" or soon "1.0.1"
1468                                         IRC_CLIENT_VERSION=" CVS $IRC_CLIENT_VERSION"
1469                                         T2="${T[0]/+/}"
1470                                 else
1471                                         IRC_CLIENT_VERSION=" ${T[0]}"
1472                                         T2="${T[0]}"
1473                                 fi
1474                                 # Remove any dots except the first, and make sure there are no trailing zeroes,
1475                                 T2=$( echo "$T2" | gawk '{
1476                                         sub(/\./, " ")
1477                                         gsub(/\./, "")
1478                                         sub(/ /, ".")
1479                                         printf("%g\n", $0)
1480                                 }' )
1481                                 # Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc
1482                                 # becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller
1483                                 # than 1 and change the DCOP parameter/object accordingly.
1484                                 if [[ ${T2} -lt 1 ]];then
1485                                         DCOPOBJ="Konversation"
1486                                 fi
1487                                 IRC_CLIENT="Konversation"
1488                                 ;;
1489                         kopete)
1490                                 IRC_CLIENT_VERSION=" $( kopete -v | gawk '
1491                                 /Kopete:/ {
1492                                         print $2
1493                                         exit
1494                                 }' )"
1495                                 IRC_CLIENT="Kopete"
1496                                 ;;
1497                         kvirc)
1498                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>&1 | gawk '{
1499                                         for ( i=2; i<=NF; i++) {
1500                                                 if ( i == NF ) {
1501                                                         print $i
1502                                                 }
1503                                                 else {
1504                                                         printf $i" "
1505                                                 }
1506                                         }
1507                                         exit
1508                                  }' )"
1509                                 IRC_CLIENT="KVIrc"
1510                                 ;;
1511                         pidgin)
1512                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1513                                         print $2
1514                                 }' )"
1515                                 IRC_CLIENT="Pidgin"
1516                                 ;;
1517                         quassel*)
1518                                 # sample: quassel -v
1519                                 # Qt: 4.5.0
1520                                 # KDE: 4.2.65 (KDE 4.2.65 (KDE 4.3 >= 20090226))
1521                                 # Quassel IRC: v0.4.0 [+60] (git-22effe5)
1522                                 # note: early < 0.4.1 quassels do not have -v
1523                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>/dev/null | gawk -F ': ' '
1524                                 BEGIN {
1525                                         IGNORECASE=1
1526                                         clientVersion=""
1527                                 }
1528                                 /Quassel IRC/ {
1529                                         clientVersion = $2
1530                                 }
1531                                 END {
1532                                         # this handles pre 0.4.1 cases with no -v
1533                                         if ( clientVersion == "" ) {
1534                                                 clientVersion = "(pre v0.4.1)"
1535                                         }
1536                                         print clientVersion
1537                                 }' )"
1538                                 # now handle primary, client, and core. quasselcore doesn't actually
1539                                 # handle scripts with exec, but it's here just to be complete
1540                                 case $app_working_name in
1541                                         quassel)
1542                                                 IRC_CLIENT="Quassel [M]"
1543                                                 ;;
1544                                         quasselclient)
1545                                                 IRC_CLIENT="Quassel"
1546                                                 ;;
1547                                         quasselcore)
1548                                                 IRC_CLIENT="Quassel (core)"
1549                                                 ;;
1550                                 esac
1551                                 ;;
1552                         weechat-curses)
1553                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v ) "
1554                                 IRC_CLIENT="Weechat"
1555                                 ;;
1556                         xchat-gnome)
1557                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1558                                         print $2
1559                                 }' )"
1560                                 IRC_CLIENT="X-Chat-Gnome"
1561                                 ;;
1562                         xchat)
1563                                 IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
1564                                         print $2
1565                                 }' )"
1566                                 IRC_CLIENT="X-Chat"
1567                                 ;;
1568                         # then do some perl type searches, do this last since it's a wildcard search
1569                         perl*|ksirc|dsirc)
1570                                 unset IRC_CLIENT_VERSION
1571                                 # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
1572                                 get_cmdline $PPID
1573                                 for (( i=0; i <= $CMDL_MAX; i++ ))
1574                                 do
1575                                         case ${A_CMDL[i]} in
1576                                                 *dsirc*)
1577                                                 IRC_CLIENT="KSirc"
1578                                                 # Dynamic runpath detection is too complex with KSirc, because KSirc is started from
1579                                                 # kdeinit. /proc/<pid of the grandparent of this process>/exe is a link to /usr/bin/kdeinit
1580                                                 # with one parameter which contains parameters separated by spaces(??), first param being KSirc.
1581                                                 # Then, KSirc runs dsirc as the perl irc script and wraps around it. When /exec is executed,
1582                                                 # dsirc is the program that runs inxi, therefore that is the parent process that we see.
1583                                                 # You can imagine how hosed I am if I try to make inxi find out dynamically with which path
1584                                                 # KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
1585                                                 # (KSirc sucks anyway ;)
1586                                                 IRC_CLIENT_VERSION=" $( ksirc -v | gawk '
1587                                                 /KSirc:/ {
1588                                                         print $2
1589                                                         exit
1590                                                 }' )"
1591                                                 break
1592                                                 ;;
1593                                         esac
1594                                 done
1595                                 if [[ -z $IRC_CLIENT_VERSION ]];then
1596                                         IRC_CLIENT="Unknown Perl client"
1597                                 fi
1598                                 ;;
1599                         # then unset, set unknown data
1600                         *)      
1601                                 IRC_CLIENT="Unknown : ${irc_client_path##*/}"
1602                                 unset IRC_CLIENT_VERSION
1603                                 ;;
1604                 esac
1605                 if [[ $SHOW_IRC -lt 2 ]];then
1606                         unset IRC_CLIENT_VERSION
1607                 fi
1608         else
1609                 ## lets look to see if qt4_konvi is the parent.  There is no direct way to tell, so lets infer it.
1610                 ## because $PPID does not work with qt4_konvi, the above case does not work
1611                 b_qt4_konvi=$( is_this_qt4_konvi )
1612                 if [[ $b_qt4_konvi == 'true' ]];then
1613                         KONVI=3
1614                         IRC_CLIENT='Konversation'
1615                         IRC_CLIENT_VERSION=" $( konversation -v | gawk '
1616                                 /Konversation:/ {
1617                                         for ( i=2; i<=NF; i++ ) {
1618                                                 if (i == NF) {
1619                                                         print $i
1620                                                 }
1621                                                 else {
1622                                                         printf $i" "
1623                                                 }
1624                                         }
1625                                         exit
1626                                 }' )"
1627                 else
1628                         IRC_CLIENT="PPID=\"$PPID\" - empty?"
1629                         unset IRC_CLIENT_VERSION
1630                 fi
1631         fi
1632         log_function_data "IRC_CLIENT: $IRC_CLIENT :: IRC_CLIENT_VERSION: $IRC_CLIENT_VERSION :: PPID: $PPID"
1633         eval $LOGFE
1634 }
1635
1636 ## try to infer the use of Konversation >= 1.2, which shows $PPID improperly
1637 ## no known method of finding Kovni >= 1.2 as parent process, so we look to see if it is running,
1638 ## and all other irc clients are not running.  
1639 is_this_qt4_konvi()
1640 {
1641         local konvi_qt4_client='' konvi_dbus_exist='' konvi_pid='' konvi_home_dir='' 
1642         local konvi='' konvi_qt4_ver='' b_is_qt4=''
1643         
1644         # fringe cases can throw error, always if untested app, use 2>/dev/null after testing if present
1645         if [[ $B_QDBUS == 'true' ]];then
1646                 konvi_dbus_exist=$( qdbus 2>/dev/null | grep "org.kde.konversation" )
1647         fi
1648          
1649         if [[ -n $konvi_dbus_exist && -e /usr/share/kde4/apps/konversation ]]; then
1650                 konvi_pid=$( ps -A | grep -i 'konversation' )
1651                 konvi_pid=$( echo $konvi_pid | gawk '{ print $1 }' ) 
1652                 konvi_home_dir=$( readlink /proc/$konvi_pid/exe )
1653                 konvi=$( echo $konvi_home_dir | sed "s/\// /g" )
1654                 konvi=($konvi)
1655
1656                 if [[ ${konvi[2]} == 'konversation' ]];then     
1657                         konvi_qt4_ver=$( konversation -v | grep -i 'konversation' )
1658                         konvi_qt4_client=$( echo "$konvi_qt4_ver" | gawk '{ print $2 }' )
1659
1660                         if [[ $konvi_qt4_client > 1.1 ]]; then
1661                                 b_is_qt4='true'
1662                         fi
1663                 fi
1664         else
1665                 konvi_qt4="qt3"
1666                 b_is_qt4='false'
1667         fi
1668
1669         echo $b_is_qt4
1670         ## for testing this module
1671         #qdbus org.kde.konversation /irc say $1 $2 "getpid_dir: $konvi_qt4  qt4_konvi: $konvi_qt4_ver   verNum: $konvi_qt4_ver_num  pid: $konvi_pid ppid: $PPID  konvi_home_dir: ${konvi[2]}"
1672 }
1673
1674 # This needs some cleanup and comments, not quite understanding what is happening, although generally output is known
1675 # Parse the null separated commandline under /proc/<pid passed in $1>/cmdline
1676 # args: $1 - $PPID
1677 get_cmdline()
1678 {
1679         eval $LOGFS
1680         local i=0 ppid=$1
1681
1682         if [[ ! -e /proc/$ppid/cmdline ]];then
1683                 echo 0
1684                 return
1685         fi
1686         ##print_screen_output "Marker"
1687         ##print_screen_output "\$ppid='$ppid' -=- $(< /proc/$ppid/cmdline)"
1688         unset A_CMDL
1689         ## note: need to figure this one out, and ideally clean it up and make it readable
1690         while read -d $'\0' L && [[ $i -lt 32 ]]
1691         do
1692                 A_CMDL[i++]="$L" ## note: make sure this is valid - What does L mean? ##
1693         done < /proc/$ppid/cmdline
1694         ##print_screen_output "\$i='$i'"
1695         if [[ $i -eq 0 ]];then
1696                 A_CMDL[0]=$(< /proc/$ppid/cmdline)
1697                 if [[ -n ${A_CMDL[0]} ]];then
1698                         i=1
1699                 fi
1700         fi
1701         CMDL_MAX=$i
1702         log_function_data "CMDL_MAX: $CMDL_MAX"
1703         eval $LOGFE
1704 }
1705
1706 #### -------------------------------------------------------------------
1707 #### get data types
1708 #### -------------------------------------------------------------------
1709 ## create array of sound cards installed on system, and if found, use asound data as well
1710 get_audio_data()
1711 {
1712         eval $LOGFS
1713         local i='' alsa_data='' alsa_driver='' device_count='' lsusb_path=''
1714         local usb_proc_file='' array_count='' usb_id='' usb_data=''
1715
1716         IFS=$'\n'
1717         # this first step handles the drivers for cases where the second step fails to find one
1718         device_count=$( echo "$Lspci_Data" | egrep -ic '(multimedia audio controller|audio device)' )
1719         if [[ $device_count -eq 1 ]] && [[ $B_ASOUND_DEVICE_FILE == 'true' ]];then
1720                 alsa_driver=$( gawk -F ']: ' '
1721                 BEGIN {
1722                         IGNORECASE=1
1723                 }
1724                 # filtering out modems and usb devices like webcams, this might get a
1725                 # usb audio card as well, this will take some trial and error
1726                 $0 !~ /modem/ || $0 !~ /usb/ {
1727                         driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
1728                         gsub(/^ +| +$/,"",driver)
1729                         if ( driver != "" ){
1730                                 print driver
1731                         }
1732                 }'  $FILE_ASOUND_DEVICE )
1733                 log_function_data 'cat' "$FILE_ASOUND_DEVICE"
1734         fi
1735
1736         # this is to safeguard against line breaks from results > 1, which if inserted into following
1737         # array will create a false array entry. This is a hack, not a permanent solution.
1738         alsa_driver=$( echo $alsa_driver )
1739         # now we'll build the main audio data, card name, driver, and port. If no driver is found,
1740         # and if the first method above is not null, and one card is found, it will use that instead.
1741         A_AUDIO_DATA=( $( echo "$Lspci_Data" | gawk -F ': ' -v alsaDriver="$alsa_driver" '
1742         BEGIN {
1743                 IGNORECASE=1
1744         }
1745         /multimedia audio controller|audio device/ {
1746                 audioCard=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
1747                 # The doublequotes are necessary because of the pipes in the variable.
1748                 gsub(/'"$BAN_LIST_NORMAL"'/, "", audioCard)
1749                 gsub(/,/, " ", audioCard)
1750                 gsub(/^ +| +$/, "", audioCard)
1751                 gsub(/ [ \t]+/, " ", audioCard)
1752                 aPciBusId[audioCard] = gensub(/(^[0-9a-f:\.]+) [^:]+: .+$/,"\\1","g",$0)
1753                 cards[audioCard]++
1754
1755                 # loop until you get to the end of the data block
1756                 while (getline && !/^$/) {
1757                         gsub( /,/, "", $0 )
1758                         if (/driver in use/) {
1759                                 drivers[audioCard] = drivers[audioCard] gensub( /(.*): (.*)/ ,"\\2", "g" ,$0 ) ""
1760                         }
1761                         else if (/kernel modules:/) {
1762                                 modules[audioCard] = modules[audioCard] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) ""
1763                         }
1764                         else if (/I\/O/) {
1765                                 portsTemp = gensub(/\t*I\/O ports at (.*) \[.*\]/,"\\1","g",$0)
1766                                 ports[audioCard] = ports[audioCard] portsTemp " "
1767                         }
1768                 }
1769         }
1770
1771         END {
1772                 j=0
1773                 for (i in cards) {
1774                         useDrivers=""
1775                         useModules=""
1776                         usePorts=""
1777                         usePciBusId=""
1778                          
1779                         if (cards[i]>1) {
1780                                 a[j]=cards[i]"x "i
1781                                 if (drivers[i] != "") {
1782                                         useDrivers=drivers[i]
1783                                 }
1784                         }
1785                         else {
1786                                 a[j]=i
1787                                 # little trick here to try to catch the driver if there is
1788                                 # only one card and it was null, from the first test of asound/cards
1789                                 if (drivers[i] != "") {
1790                                         useDrivers=drivers[i]
1791                                 }
1792                                 else if ( alsaDriver != "" ) {
1793                                         useDrivers=alsaDriver
1794                                 }
1795                         }
1796                         if (ports[i] != "") {
1797                                 usePorts = ports[i]
1798                         }
1799                         if (modules[i] != "" ) {
1800                                 useModules = modules[i]
1801                         }
1802                         if ( aPciBusId[i] != "" ) {
1803                                 usePciBusId = aPciBusId[i]
1804                         }
1805                         # create array primary item for master array
1806                         sub( / $/, "", usePorts ) # clean off trailing whitespace
1807                         print a[j] "," useDrivers "," usePorts "," useModules "," usePciBusId
1808                         j++
1809                 }
1810         }') )
1811
1812         # in case of failure of first check do this instead
1813         if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]] && [[ $B_ASOUND_DEVICE_FILE == 'true' ]];then
1814                 A_AUDIO_DATA=( $( gawk -F ']: ' '
1815                 BEGIN {
1816                         IGNORECASE=1
1817                 }
1818                 $1 !~ /modem/ && $2 !~ /modem/ {
1819                         card=gensub( /^(.+)( - )(.+)$/, "\\3", 1, $2 )
1820                         driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
1821                         if ( card != "" ){
1822                                 print card","driver
1823                         }
1824                 }'  $FILE_ASOUND_DEVICE ) )
1825         fi
1826
1827         # alsa usb detection by damentz
1828         # for every sound card symlink in /proc/asound - display information about it
1829         lsusb_path=$( type -p lsusb )
1830         for usb_proc_file in /proc/asound/*
1831         do
1832                 # if lsusb exists, the file is a symlink, and contains an important usb exclusive file: continue
1833                 if [[ -n $lsusb_path && -L $usb_proc_file && -e $usb_proc_file/usbid  ]]; then
1834                         # send error messages of lsusb to /dev/null as it will display a bunch if not a super user
1835                         # also, find the contents of usbid in lsusb and print everything after the 7th word on the
1836                         # corresponding line. Finally, strip out commas as they will change the driver :)
1837                         usb_id=$( cat $usb_proc_file/usbid )
1838                         usb_data=$( $lsusb_path -v 2>/dev/null | grep "$usb_id" )
1839                         log_function_data 'raw' "usb_data:\n$usb_data"
1840                         usb_data=$( gawk '{
1841                                 gsub( /,/, " ", $0 )
1842                                 for( i=7; i <= NF; i++ ) {
1843                                         printf( $i " " )
1844                                 }
1845                         }' <<< "$usb_data" )
1846                         # this method is interesting, it shouldn't work but it does
1847                         #A_AUDIO_DATA=( "${A_AUDIO_DATA[@]}" "$usb_data,snd-usb-audio,," )
1848                         # but until we learn why the above worked, I'm using this one, which is safer
1849                         if [[ -n $usb_data ]];then
1850                                 array_count=${#A_AUDIO_DATA[@]}
1851                                 A_AUDIO_DATA[$array_count]="$usb_data,snd-usb-audio,,"
1852                         fi
1853                 fi
1854         done
1855         IFS="$ORIGINAL_IFS"
1856
1857         # handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
1858         if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]];then
1859                 A_AUDIO_DATA[0]='Failed to Detect Sound Card!'
1860         fi
1861         log_function_data "A_AUDIO_DATA: ${A_AUDIO_DATA[@]}"
1862         eval $LOGFE
1863 }
1864
1865 get_audio_alsa_data()
1866 {
1867         eval $LOGFS
1868         local alsa_data=''
1869
1870         # now we'll get the alsa data if the file exists
1871         if [[ $B_ASOUND_VERSION_FILE == 'true' ]];then
1872                 alsa_data=$( gawk '
1873                         BEGIN {
1874                                 IGNORECASE=1
1875                         }
1876                         # some alsa strings have the build date in (...)
1877                         # remove trailing . and remove possible second line if compiled by user
1878                         $0 !~ /compile/ {
1879                                 gsub( "Driver | [(].*[)]|\.$","",$0 )
1880                                 gsub(/,/, " ", $0)
1881                                 gsub(/^ +| +$/, "", $0)
1882                                 gsub(/ [ \t]+/, " ", $0)
1883                                 if ( $0 != "" ){
1884                                         print $0
1885                                 }
1886                 }' $FILE_ASOUND_VERSION )
1887                 log_function_data 'cat' "$FILE_ASOUND_VERSION"
1888         fi
1889         echo "$alsa_data"
1890         log_function_data "alsa_data: $alsa_data"
1891         eval $LOGFE
1892 }
1893
1894 ## create A_CPU_CORE_DATA, currently with two values: integer core count; core string text
1895 ## return value cpu core count string, this helps resolve the multi redundant lines of old style output
1896 get_cpu_core_count()
1897 {
1898         eval $LOGFS
1899         if [[ $B_CPUINFO_FILE == 'true' ]]; then
1900                 # load the A_CPU_TYPE_PCNT_CCNT core data array
1901                 get_cpu_ht_multicore_smp_data
1902                 ## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10)
1903                 # count the number of processors given
1904                 local cpu_physical_count=${A_CPU_TYPE_PCNT_CCNT[1]}
1905                 local cpu_core_count=${A_CPU_TYPE_PCNT_CCNT[2]}
1906                 local cpu_type=${A_CPU_TYPE_PCNT_CCNT[0]}
1907
1908                 # match the numberic value to an alpha value
1909                 case $cpu_core_count in
1910                         1) cpu_alpha_count='Single';;
1911                         2) cpu_alpha_count='Dual';;
1912                         3) cpu_alpha_count='Triple';;
1913                         4) cpu_alpha_count='Quad';;
1914                         5) cpu_alpha_count='Penta';;
1915                         6) cpu_alpha_count='Hexa';;
1916                         7) cpu_alpha_count='Hepta';;
1917                         8) cpu_alpha_count='Octa';;
1918                         9) cpu_alpha_count='Ennea';;
1919                         10) cpu_alpha_count='Deca';;
1920                         *) cpu_alpha_count='Multi';;
1921                 esac
1922                 # create array, core count integer; core count string
1923                 # A_CPU_CORE_DATA=( "$cpu_core_count" "$cpu_alpha_count Core$cpu_type" )
1924                 A_CPU_CORE_DATA=( "$cpu_physical_count" "$cpu_alpha_count" "$cpu_type" "$cpu_core_count" )
1925         fi
1926         log_function_data "A_CPU_CORE_DATA: ${A_CPU_CORE_DATA[@]}"
1927         eval $LOGFE
1928 }
1929
1930 ## main cpu data collector
1931 get_cpu_data()
1932 {
1933         eval $LOGFS
1934         local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits=''
1935
1936         if [[ $B_CPUINFO_FILE == 'true' ]];then
1937                 # stop script for a bit to let cpu slow down before parsing cpu /proc file
1938                 sleep $CPU_SLEEP
1939                 IFS=$'\n'
1940                 A_CPU_DATA=( $( gawk -F': ' '
1941                 BEGIN {
1942                         IGNORECASE=1
1943                 }
1944                 # TAKE STRONGER NOTE: \t+ does NOT always work, MUST be [ \t]+
1945                 # TAKE NOTE: \t+ will work for $FILE_CPUINFO, but SOME ARBITRARY FILE used for TESTING might contain SPACES!
1946                 # Therefore PATCH to use [ \t]+ when TESTING!
1947                 /^processor[ \t]+:/ {
1948                         nr = $NF
1949                 }
1950
1951                 /^model name|^cpu\t+:/ {
1952                         gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
1953                         gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
1954                         gsub(/,/, " ", $NF)
1955                         gsub(/^ +| +$/, "", $NF)
1956                         gsub(/ [ \t]+/, " ", $NF)
1957                         cpu[nr, "model"] = $NF
1958                 }
1959
1960                 /^cpu MHz|^clock\t+:/ {
1961                         if (!min) {
1962                                 min = $NF
1963                         }
1964                         else {
1965                                 if ($NF < min) {
1966                                         min = $NF
1967                                 }
1968                         }
1969
1970                         if ($NF > max) {
1971                                 max = $NF
1972                         }
1973                         gsub(/MHZ/,"",$NF) ## clears out for cell cpu
1974                         gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros
1975                         cpu[nr, "speed"] = $NF
1976                 }
1977
1978                 /^cache size/ {
1979                         cpu[nr, "cache"] = $NF
1980                 }
1981
1982                 /^flags/ {
1983                         cpu[nr, "flags"] = $NF
1984                 }
1985
1986                 /^bogomips/ {
1987                         cpu[nr, "bogomips"] = $NF
1988                 }
1989
1990                 /vendor_id/ {
1991                         gsub(/genuine|authentic/,"",$NF)
1992                         cpu[nr, "vendor"] = tolower( $NF )
1993                 }
1994
1995                 END {
1996                         #if (!nr) { print ",,,"; exit } # <- should this be necessary or should bash handle that
1997                         for ( i = 0; i <= nr; i++ ) {
1998                                 print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] ","  cpu[nr, "vendor"]
1999                         }
2000                         if (!min) {
2001                                 print "not found"
2002                                 exit
2003                         }
2004                         if (min != max) {
2005                                 printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz")
2006                         }
2007                         else {
2008                                 printf("%s %s\n", max, "Mhz")
2009                         }
2010                 }' $FILE_CPUINFO ) )
2011                 log_function_data 'cat' "$FILE_CPUINFO"
2012         fi
2013
2014         IFS="$ORIGINAL_IFS"
2015         log_function_data "A_CPU_DATA: ${A_CPU_DATA[@]}"
2016         eval $LOGFE
2017 #       echo getMainCpu: ${[@]}
2018 }
2019
2020 ## this is for counting processors and finding HT types
2021 get_cpu_ht_multicore_smp_data()
2022 {
2023         eval $LOGFS
2024         # in /proc/cpuinfo
2025         
2026
2027         if [[ $B_CPUINFO_FILE == 'true' ]]; then
2028                 A_CPU_TYPE_PCNT_CCNT=( $(
2029                 gawk '
2030                 BEGIN {
2031                         FS=": "
2032                         IGNORECASE = 1
2033                         num_of_cores = 0
2034                         num_of_processors = 0
2035                         num_of_cpus = 0
2036                         core_id[0]
2037                         processor_id[0]
2038                         cpu_id[0]
2039                         type = "-"
2040                         iter = 0
2041                 }
2042                 # array of logical processors, both HT and physical
2043                 /^processor/ {
2044                         processor_id[iter] = $NF
2045                 }
2046                 # array of physical cpus ids
2047                 /^physical/ {
2048                         cpu_id[iter] = $NF
2049                 }
2050                 # array of core ids
2051                 /^core id/ {
2052                         core_id[iter] = $NF
2053                         iter++
2054                 }
2055                 END {
2056                         ##      Look thru the array and filter same numbers.
2057                         ##      only unique numbers required
2058                         ##      this is to get an accurate count
2059                         ##      we are only concerned with array length
2060                         
2061                         i = 0
2062                         ## count unique processors ##
2063                         for ( i in processor_id ) {
2064                                 procHolder[processor_id[i]] = 1
2065                         }
2066                         for ( i in procHolder ) {                               
2067                                 num_of_processors++
2068                         }
2069                         
2070                         i = 0
2071                         ## count unique physical cpus ##
2072                         for ( i in cpu_id ) {
2073                                 cpuHolder[cpu_id[i]] = 1
2074                         }
2075                         for ( i in cpuHolder ) {                                
2076                                 num_of_cpus++
2077                         }
2078                         
2079                         i = 0           
2080                         ## count unique cores ##
2081                         for ( i in core_id ) {
2082                                 coreHolder[core_id[i]] = 1
2083                         }
2084                         for ( i in coreHolder ) {                               
2085                                 num_of_cores++
2086                         }
2087                         
2088                         ####################################################################
2089                         #                               algorithm
2090                         # if > 1 processor && processor id (physical id) == core id then Hyperthreaded (HT)
2091                         # if > 1 processor && processor id (physical id) != core id then Multi-Core Processors (MCP)
2092                         # if > 1 processor && processor ids (physical id) > 1 then Multiple Processors (SMP)
2093                         # if = 1 processor then single core/processor Uni-Processor (UP)
2094                         if ( num_of_processors > 1 )
2095                         {
2096                                 # non-multicore HT
2097                                 if ( num_of_processors == (num_of_cores * 2))
2098                                 {
2099                                         type = type "HT-"
2100                                 }
2101                                 # non-HT multi-core or HT multi-core
2102                                 if (( num_of_processors == num_of_cores) ||
2103                                         ( num_of_cpus < num_of_cores))
2104                                 {
2105                                         type = type "MCP-"
2106                                 }
2107                                 # >1 cpu sockets active
2108                                 if ( num_of_cpus > 1 )
2109                                 {
2110                                         type = type "SMP-"
2111                                 }
2112                         } else {
2113                                 type = type "UP-"
2114                         }                       
2115                         
2116                         print type " " num_of_cpus " " num_of_cores
2117                 }
2118                 ' $FILE_CPUINFO 
2119                 ) )
2120         fi
2121         log_function_data "A_CPU_TYPE_PCNT_CCNT: ${A_CPU_TYPE_PCNT_CCNT[@]}"
2122         eval $LOGFE
2123 }
2124
2125 # for more on distro id, please reference this python thread: http://bugs.python.org/issue1322
2126 ## return distro name/id if found
2127 get_distro_data()
2128 {
2129         eval $LOGFS
2130         local i='' j='' distro='' distro_file='' a_distro_glob=''
2131
2132         # get the wild carded array of release/version /etc files if present
2133         shopt -s nullglob
2134         cd /etc
2135         a_distro_glob=(*[-_]{release,version})
2136         cd "$OLDPWD"
2137         shopt -u nullglob
2138
2139         if [[ ${#a_distro_glob[@]} -eq 1 ]];then
2140                 distro_file="${a_distro_glob}"
2141         # use the file if it's in the known good lists
2142         elif [[ ${#a_distro_glob[@]} -gt 1 ]];then
2143                 for i in $DISTROS_DERIVED $DISTROS_PRIMARY
2144                 do
2145                         # Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
2146                         # This is a known bug, search for the word "strange" inside comments
2147                         # echo "i='$i' a_distro_glob[@]='${a_distro_glob[@]}'"
2148                         if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then
2149                                 # Now lets see if the distro file is in the known-good working-lsb-list
2150                                 # if so, use lsb-release, if not, then just use the found file
2151                                 # this is for only those distro's with self named release/version files
2152                                 # because Mint does not use such, it must be done as below
2153                                 ## this if statement requires the spaces and * as it is, else it won't work
2154                                 ##
2155                                 if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_FILE == 'true' ]];then
2156                                         distro_file='lsb-release'
2157                                 else
2158                                         distro_file="${i}"
2159                                 fi
2160                                 break
2161                         fi
2162                 done
2163         fi
2164         log_function_data "distro_file: $distro_file"
2165         # first test for the legacy antiX distro id file
2166         if [[ -e /etc/antiX ]];then
2167                 distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )"
2168         # this handles case where only one release/version file was found, and it's lsb-release. This would
2169         # never apply for ubuntu or debian, which will filter down to the following conditions. In general
2170         # if there's a specific distro release file available, that's to be preferred, but this is a good backup.
2171         elif [[ -n $distro_file && -f $FILE_LSB_RELEASE && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then
2172                 distro=$( get_distro_lsb_data )
2173         elif [[ $distro_file == 'lsb-release' ]];then
2174                 distro=$( get_distro_lsb_data )
2175         # then if the distro id file was found and it's not in the exluded primary distro file list, read it
2176         elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
2177                 distro=$( remove_erroneous_chars "/etc/$distro_file" )
2178         # otherwise try  the default debian/ubuntu /etc/issue file
2179         elif [[ -f /etc/issue ]];then
2180                 # lsb gives more manageable and accurate output than issue, but mint should use issue for now
2181                 # some bashism, boolean must be in parenthesis to work correctly, ie [[ $(boolean) ]] not [[ $boolean ]]
2182                 if [[ $B_LSB_FILE == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then
2183                         distro=$( get_distro_lsb_data )
2184                 else
2185                         distro=$( gawk '
2186                         BEGIN {
2187                                 RS=""
2188                         }
2189                         {
2190                                 gsub(/\\[a-z]/, "")
2191                                 gsub(/,/, " ")
2192                                 gsub(/^ +| +$/, "")
2193                                 gsub(/ [ \t]+/, " ")
2194                                 print
2195                         }' /etc/issue )
2196                 fi
2197         fi
2198
2199         if [[ ${#distro} -gt 80 ]] &&  [[ $B_HANDLE_CORRUPT_DATA != 'true' ]];then
2200                 distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}"
2201         fi
2202         ## note: would like to actually understand the method even if it's not used
2203         # : ${distro:=Unknown distro o_O}
2204         ## test for /etc/lsb-release as a backup in case of failure, in cases where > one version/release file
2205         ## were found but the above resulted in null distro value
2206         if [[ -z $distro ]] && [[ $B_LSB_FILE == 'true' ]];then
2207                 distro=$( get_distro_lsb_data )
2208         fi
2209         ## finally, if all else has failed, give up
2210         if [[ -z $distro ]];then
2211                 distro='Unknown distro o_O'
2212         fi
2213
2214         # this handles an arch bug where /etc/arch-release is empty and /etc/issue is corrupted
2215         if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
2216                 distro='Arch Linux'
2217         fi
2218
2219         echo "$distro"
2220         log_function_data "distro: $distro"
2221         eval $LOGFE
2222 }
2223
2224 # args: $1 - optional, app, uses the app test, not being used now
2225 get_distro_lsb_data()
2226 {
2227         eval $LOGFS
2228         local distro=''
2229
2230         if [[ $B_LSB_FILE == 'true' ]] && [[ $1 != 'app' ]];then
2231                 distro=$( gawk -F '=' '
2232                 BEGIN {
2233                         IGNORECASE=1
2234                 }
2235                 # note: adding the spacing directly to variable to make sure distro output is null if not found
2236                 /^DISTRIB_ID/ {
2237                         gsub(/^ +| +$/, "", $NF)
2238                         # this is needed because grep for "arch" is too loose to be safe
2239                         if ( $NF == "arch" ) {
2240                                 distroId = "Arch Linux"
2241                         }
2242                         else if ( $NF != "n/a" ) {
2243                                 distroId = $NF " "
2244                         }
2245                 }
2246                 /^DISTRIB_RELEASE/ {
2247                         gsub(/^ +| +$/, "", $NF)
2248                         if ( $NF != "n/a" ) {
2249                                 distroRelease = $NF " "
2250                         }
2251                 }
2252                 /^DISTRIB_CODENAME/ {
2253                         gsub(/^ +| +$/, "", $NF)
2254                         if ( $NF != "n/a" ) {
2255                                 distroCodename = $NF " "
2256                         }
2257                 }
2258                 END {
2259                         print distroId distroRelease distroCodename
2260                 }' $FILE_LSB_RELEASE )
2261                 log_function_data 'cat' "$FILE_LSB_RELEASE"
2262         fi
2263         # this is HORRIBLY slow, but I don't know why, it runs fast in shell
2264 #       if [[  -n $( type -p lsb_release ) && $1 == 'app' ]];then
2265 #               distro=$( echo "$( lsb_release -irc )" | gawk '
2266 #               { IGNORECASE=1 }
2267 #               /^Distributor ID/ {
2268 #                       gsub(/^ +| +$/, "", $NF)
2269 #                       distroId = $NF
2270 #               }
2271 #               /^Release/ {
2272 #                       gsub(/^ +| +$/, "", $NF)
2273 #                       distroRelease = $NF
2274 #               }
2275 #               /^Codename/ {
2276 #                       gsub(/^ +| +$/, "", $NF)
2277 #                       distroCodename = $NF
2278 #               }
2279 #               END {
2280 #                       print distroId " " distroRelease " (" distroCodename ")"
2281 #               }' )
2282 #       fi
2283
2284         echo $distro
2285         log_function_data "distro: $distro"
2286         eval $LOGFE
2287 }
2288
2289 get_gpu_temp_data()
2290 {
2291         local gpu_temp='' gpu_fan='' screens='' screen_nu='' gpu_temp_looper=''
2292
2293         # we'll try for nvidia/ati, then add if more are shown
2294         if [[ -n $( type -p nvidia-settings ) ]];then
2295                 # first get the number of screens
2296                 screens=$( nvidia-settings -q screens | gawk '
2297                 /:[0-9]\.[0-9]/ {
2298                         screens=screens gensub(/(.*)(:[0-9]\.[0-9])(.*)/, "\\2", "1", $0) " "
2299                 }
2300                 END {
2301                         print screens
2302                 }
2303                 ' )
2304                 # now we'll get the gpu temp for each screen discovered. The print out function
2305                 # will handle removing screen data for single gpu systems
2306                 for screen_nu in $screens
2307                 do
2308                         gpu_temp_looper=$( nvidia-settings -c $screen_nu -q GPUCoreTemp | gawk -F ': ' '
2309                         BEGIN {
2310                                 IGNORECASE=1
2311                                 gpuTemp=""
2312                                 gpuTempWorking=""
2313                         }
2314                         /Attribute (.*)[0-9]+\.$/ {
2315                                 gsub(/\./, "", $2)
2316                                 if ( $2 ~ /^[0-9]+$/ ) {
2317                                         gpuTemp=gpuTemp $2 "C "
2318                                 }
2319                         }
2320                         END {
2321                                 print gpuTemp
2322                         }'
2323                         )
2324                         screen_nu=$( cut -d ':' -f 2 <<< $screen_nu )
2325                         gpu_temp="$gpu_temp$screen_nu:$gpu_temp_looper "
2326                 done
2327         elif [[ -n $( type -p aticonfig ) ]];then
2328 #               gpu_temp=$( aticonfig --adapter=0 --od-gettemperature | gawk -F ': ' '
2329                 gpu_temp=$( aticonfig --adapter=all --od-gettemperature | gawk -F ': ' '
2330                 BEGIN {
2331                         IGNORECASE=1
2332                         gpuTemp=""
2333                         gpuTempWorking=""
2334                 }
2335                 /Sensor (.*)[0-9\.]+ / {
2336                         gpuTempWorking=gensub(/(.*) ([0-9\.]+) (.*)/, "\\2", "1", $2)
2337                         if ( gpuTempWorking ~ /^[0-9\.]+$/ ) {
2338                                 gpuTemp=gpuTemp gpuTempWorking "C "
2339                         }
2340                 }
2341                 END {
2342                         print gpuTemp
2343                 }'
2344                 )
2345         fi
2346         
2347         if [[ -n $gpu_temp ]];then
2348                 echo $gpu_temp
2349         fi
2350 }
2351
2352 ## create array of gfx cards installed on system
2353 get_graphics_card_data()
2354 {
2355         eval $LOGFS
2356         local i=''
2357
2358         IFS=$'\n'
2359         A_GFX_CARD_DATA=( $( echo "$Lspci_Data" | gawk -F': ' '
2360         BEGIN {
2361                 IGNORECASE=1
2362         }
2363         /vga compatible controller/ {
2364                 gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
2365                 gsub(/,/, " ", $NF)
2366                 gsub(/^ +| +$/, "", $NF)
2367                 gsub(/ [ \t]+/, " ", $NF)
2368                 print $NF
2369         }' ) )
2370         IFS="$ORIGINAL_IFS"
2371 #       for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
2372 #       do
2373 #               A_GFX_CARD_DATA[i]=$( sanitize_characters BAN_LIST_NORMAL "${A_GFX_CARD_DATA[i]}" )
2374 #       done
2375         # handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
2376         if [[ ${#A_GFX_CARD_DATA[@]} -eq 0 ]];then
2377                 A_GFX_CARD_DATA[0]='Failed to Detect Video Card!'
2378         fi
2379
2380         # GFXMEM is UNUSED at the moment, because it shows AGP aperture size, which is not necessarily equal to GFX memory..
2381         # 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]"
2382         log_function_data "A_GFX_CARD_DATA: ${A_GFX_CARD_DATA[@]}"
2383         eval $LOGFE
2384 }
2385
2386 ## create array of glx data
2387 get_graphics_glx_data()
2388 {
2389         eval $LOGFS
2390         if [[ $B_X_RUNNING == 'true' && $B_ROOT != 'true' ]];then
2391                 IFS=$'\n'
2392                 A_GLX_DATA=( $( glxinfo | gawk -F ': ' '
2393                 # note: function declarations go before BEGIN? It appears so, confirm.
2394                 # the real question here though is why this function is even here, seems
2395                 # just to be a complicated way to pack/print a variable, but maybe the
2396                 # original idea was to handle > 1 cases of detections I guess
2397                 function join( arr, sep ) {
2398                         s=""
2399                         i=flag=0
2400                         for ( i in arr ) {
2401                                 if ( flag++ ) {
2402                                         s = s sep
2403                                 }
2404                                 s = s i
2405                         }
2406                         return s
2407                 }
2408
2409                 BEGIN {
2410                         IGNORECASE=1
2411                 }
2412                 /opengl renderer/ {
2413                         if ( $2 ~ /mesa/ ) {
2414                                 # Allow all mesas
2415 #                               if ( $2 ~ / r[3-9][0-9][0-9] / ) {
2416                                         gsub(/'"$BAN_LIST_NORMAL"'/, "", $2)
2417                                         a[$2]
2418                                         # this counter failed in one case, a bug, and is not needed now
2419 #                                       f++
2420 #                               }
2421                                 next
2422                         }
2423                         $2 && a[$2]
2424                 }
2425                 # dropping all conditions from this test to just show full mesa information
2426                 # there is a user case where not f and mesa apply, atom mobo
2427                 # /opengl version/ && ( f || $2 !~ /mesa/ ) {
2428                 /opengl version/ {
2429                         $2 && b[$2]
2430                 }
2431                 /direct rendering/ {
2432                         $2 && c[$2]
2433                 }
2434                 END {
2435                         printf( "%s\n%s\n%s\n", join( a, ", " ), join( b, ", " ), join( c, ", " ) )
2436                 }' ) )
2437                 IFS="$ORIGINAL_IFS"
2438
2439                 # GLXR=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl renderer/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
2440                 #    GLXV=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl version/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
2441         fi
2442         log_function_data "A_GLX_DATA: ${A_GLX_DATA[@]}"
2443         eval $LOGFE
2444 }
2445
2446 ## return screen resolution / tty resolution
2447 get_graphics_res_data()
2448 {
2449         eval $LOGFS
2450         local screen_resolution='' 
2451
2452         if [[ $B_X_RUNNING == 'true' && $B_ROOT != 'true' ]];then
2453                 # Added the two ?'s , because the resolution is now reported without spaces around the 'x', as in
2454                 # 1400x1050 instead of 1400 x 1050. Change as of X.org version 1.3.0
2455                 screen_resolution=$( xrandr | gawk '
2456                 /\*/ {
2457                         res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0)
2458                 }
2459                 END {
2460                         for (n in res) {
2461                                 if (res[n] ~ /^[[:digit:]]+x[[:digit:]]+/) {
2462                                         line = line ? line ", " res[n] : res[n]
2463                                 }
2464                         }
2465                         if (line) {
2466                                 print(line)
2467                         }
2468                 }' )
2469                 if [[ -z $screen_resolution ]];then
2470                         screen_resolution=$( xdpyinfo | gawk '
2471                         /dimensions/ {
2472                                 print $2
2473                         }' )
2474                 fi
2475         else
2476                 screen_resolution=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{
2477                         print $2"x"$1
2478                 }' )
2479         fi
2480         echo "$screen_resolution"
2481         log_function_data "screen_resolution: $screen_resolution"
2482         eval $LOGFE
2483 }
2484
2485 ## for possible future data, not currently used
2486 get_graphics_agp_data()
2487 {
2488         eval $LOGFS
2489         local agp_module=''
2490
2491         if [[ $B_MODULES_FILE == 'true' ]];then
2492                 ## not used currently
2493                 agp_module=$( gawk '
2494                 /agp/ && !/agpgart/ && $3 > 0 {
2495                         print(gensub(/(.*)_agp.*/,"\\1","g",$1))
2496                 }' $FILE_MODULES )
2497                 log_function_data 'cat' "$FILE_MODULES"
2498         fi
2499         log_function_data "agp_module: $agp_module"
2500         eval $LOGFE
2501 }
2502
2503 ## create array of x vendor/version data
2504 get_graphics_x_data()
2505 {
2506         eval $LOGFS
2507         local x_vendor='' x_version=''
2508
2509         if [[ $B_X_RUNNING == 'true' && $B_ROOT != 'true' ]];then
2510                 # X vendor and version detection.
2511                 x_vendor=$( xdpyinfo | gawk -F': +' '
2512                 BEGIN {
2513                         IGNORECASE=1
2514                 }
2515                 /vendor string/ {
2516                         gsub(/the|inc|foundation|project|corporation/, "", $2)
2517                         gsub(/,/, " ", $2)
2518                         gsub(/^ +| +$/, "", $2)
2519                         gsub(/ [ \t]+/, " ", $2)
2520                         print $2
2521                 }' )
2522
2523                 # new method added since radeon and X.org and the disappearance of <X server name> version : ...etc
2524                 # Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2
2525                 # A failover mechanism is in place. (if $x_version is empty, the release number is parsed instead)
2526                 x_version=$( xdpyinfo | gawk '
2527                 /version:/ {
2528                         print $NF
2529                 }' )
2530                 # this gives better output than the failure last case, which would only show:
2531                 # for example: X.org: 1.9 instead of: X.org: 1.9.0
2532                 if [[ -z $x_version ]];then
2533                         x_version=$( get_x_version )
2534                 fi
2535                 if [[ -z $x_version ]];then
2536                         x_version=$( xdpyinfo | gawk -F': +' '
2537                         BEGIN {
2538                                 IGNORECASE=1
2539                         }
2540                         /vendor release number/ {
2541                                 gsub(/0+$/, "", $2)
2542                                 gsub(/0+/, ".", $2)
2543                                 print $2
2544                         }' )
2545                 fi
2546                 
2547                 # some distros, like fedora, report themselves as the xorg vendor, so quick check
2548                 # here to make sure the vendor string includes Xorg in string
2549                 if [[ -z $( grep -E '(X|xorg|x\.org)' <<< $x_vendor ) ]];then
2550                         x_vendor="$x_vendor X.org"
2551                 fi
2552                 
2553                 A_X_DATA[0]="$x_vendor"
2554                 A_X_DATA[1]="$x_version"
2555         else
2556                 x_version=$( get_x_version )
2557                 if [[ -n $x_version ]];then
2558                         x_vendor='X.org'
2559                         A_X_DATA[0]="$x_vendor"
2560                         A_X_DATA[1]="$x_version"
2561                 fi
2562         fi
2563         log_function_data "A_X_DATA: ${A_X_DATA[@]}"
2564         eval $LOGFE
2565 }
2566 # if other tests fail, try this one, this works for root, out of X also
2567 get_x_version()
2568 {
2569         eval $LOGFS
2570         local x_exists=$( type -p X )
2571         local x_version=''
2572         
2573         if [[ -n $x_exists ]];then
2574                 # note: MUST be this syntax: X -version 2>&1
2575                 # otherwise X -version overrides everything and this comes out null.
2576                 # two knowns id strings: X.Org X Server 1.7.5 AND Window System Version 1.7.5
2577                 #X -version 2>&1 | gawk '/^X Window System Version/ { print $5 }'
2578                 x_version=$( X -version 2>&1 | gawk '
2579                 BEGIN {
2580                         IGNORECASE=1
2581                 }
2582                 /x.org x server|X Window System Version/ {
2583                         print $NF
2584                 }' )
2585         fi
2586         echo $x_version
2587         log_function_data " x_version: $x_version"
2588         eval $LOGFE
2589 }
2590
2591 # this gets just the raw data, total space/percent used and disk/name/per disk capacity
2592 get_hdd_data_basic()
2593 {
2594         eval $LOGFS
2595         local hdd_used=''
2596         local hdd_data="$( df --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 )"
2597         log_function_data 'raw' "hdd_data:\n$hdd_data"
2598         
2599         hdd_used=$( echo "$hdd_data" | gawk '
2600         # also handles odd dm-1 type, from lvm
2601         /^\/dev\/(mapper\/|[hs]d[a-z][0-9]+|dm[-]?[0-9]+)/ {
2602                 # this handles the case where the first item is too long
2603                 # and makes df wrap output to next line, so here we advance
2604                 # it to the next line for that single case
2605                 if ( NF < 5 && $0 !~ /.*\%/ ) {
2606                         getline
2607                 }
2608                 # if the first item caused a wrap, use one less than standard
2609                 # testing for the field with % in it, ie: 34%, then go down from there
2610                 # this also protects against cases where the mount point has a space in the
2611                 # file name, thus breaking going down from $NF directly.
2612                 if ( $4 ~ /.*\%/ ) {
2613                         used += $2
2614                 }
2615                 # otherwise use standard
2616                 else if ( $5 ~ /.*\%/ ) {
2617                         used += $3
2618                 }
2619                 # and if this is not detected, give up, we need user data to debug
2620                 else {
2621                         next
2622                 }
2623         }
2624         END {
2625                 print used
2626         }' )
2627
2628         if [[ -z $hdd_used ]];then
2629                 hdd_used='na'
2630         fi
2631         log_function_data "hdd_used: $hdd_used"
2632         # create the initial array strings:
2633         # disk-dev, capacity, name, usb or not
2634         # final item is the total of the disk
2635         IFS=$'\n'
2636
2637         if [[ $B_PARTITIONS_FILE == 'true' ]];then
2638                 A_HDD_DATA=( $(
2639                 gawk -v hddused="$hdd_used" '
2640                 /[hs]d[a-z]$/ {
2641                         driveSize = $(NF - 1)*1024/1000**3
2642                         gsub(/,/, " ", driveSize)
2643                         gsub(/^ +| +$/, "", driveSize)
2644                         printf( $NF",%.1fGB,,\n", driveSize )
2645                 }
2646                 # See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
2647                 # $1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0  {
2648                 #       size += $3
2649                 # }
2650                 # special case from this data: 8     0  156290904 sda
2651                 $1 ~ /^(3|22|33|8)$/ && $NF ~ /[hs]d[a-z]$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) {
2652                         size += $3
2653                 }
2654
2655                 END {
2656                         size = size*1024/1000**3                   # calculate size in GB size
2657                         workingUsed = hddused*1024/1000**3         # calculate workingUsed in GB used
2658                         # this handles a special case with livecds where no hdd_used is detected
2659                         if ( size > 0 && hddused == "na" ) {
2660                                 size = sprintf( "%.1f", size )
2661                                 print size "GB,-"
2662                         }
2663                         else if ( size > 0 && workingUsed > 0 ) {
2664                                 diskUsed = workingUsed*100/size  # calculate used percentage
2665                                 diskUsed = sprintf( "%.1f", diskUsed )
2666                                 size = sprintf( "%.1f", size )
2667                                 print size "GB," diskUsed "% used"
2668                         }
2669                         else {
2670                                 print "NA,-" # print an empty array, this will be further handled in the print out function
2671                         }
2672                 }' $FILE_PARTITIONS ) )
2673                 log_function_data 'cat' "$FILE_PARTITIONS"
2674         fi
2675         IFS="$ORIGINAL_IFS"
2676         log_function_data "A_HDD_DATA: ${A_HDD_DATA[@]}"
2677         eval $LOGFE
2678 }
2679
2680 ## fills out the A_HDD_DATA array with disk names
2681 get_hard_drive_data_advanced()
2682 {
2683         eval $LOGFS
2684         local a_temp_working='' a_temp_scsi='' temp_holder='' temp_name='' i='' j=''
2685         local sd_ls_by_id='' ls_disk_by_id='' usb_exists=''
2686
2687         ## check for all ide type drives, non libata, only do it if hdx is in array
2688         ## this is now being updated for new /sys type paths, this may handle that ok too
2689         if [[ -n $( egrep 'hd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
2690                 # remember, we're using the last array item to store the total size of disks
2691                 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
2692                 do
2693                         IFS=","
2694                         a_temp_working=( ${A_HDD_DATA[i]} )
2695                         IFS="$ORIGINAL_IFS"
2696                         if [[ -n $( egrep '^hd[a-z]' <<< ${a_temp_working[0]} ) ]];then
2697                                 if [[ -e /proc/ide/${a_temp_working[0]}/model ]];then
2698                                         a_temp_working[2]="$( remove_erroneous_chars /proc/ide/${a_temp_working[0]}/model )"
2699                                 else
2700                                         a_temp_working[2]="Name n/a"
2701                                 fi
2702                                 # these loops are to easily extend the cpu array created in the gawk script above with more fields per cpu.
2703                                 for (( j=0; j < ${#a_temp_working[@]}; j++ ))
2704                                 do
2705                                         if [[ $j -gt 0 ]];then
2706                                                 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2707                                         else
2708                                                 A_HDD_DATA[i]="${a_temp_working[$j]}"
2709                                         fi
2710                                 done
2711                         fi
2712                 done
2713         fi
2714
2715         ## then handle libata names
2716         # first get the ata device names, put them into an array
2717         IFS=$'\n'
2718         if [[ $B_SCSI_FILE == 'true' ]]; then
2719                 a_temp_scsi=( $( gawk  '
2720                 BEGIN {
2721                         IGNORECASE=1
2722                 }
2723                 /host/ {
2724                         getline a[$0]
2725                         getline b[$0]
2726                 }
2727                 END {
2728                         for (i in a) {
2729                                 if (b[i] ~ / *type: *direct-access.*/) {
2730                                         #c=gensub(/^ *vendor: (.+) +model: (.+) +rev: (.+)$/,"\\1 \\2 \\3","g",a[i])
2731                                         #c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i] )
2732                                         # the vendor: string is useless, and is a bug, ATA is not a vendor for example
2733                                         c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/, "\\2", "g", a[i] )
2734                                         gsub(/,/, " ", c)
2735                                         gsub(/^ +| +$/, "", c)
2736                                         gsub(/ [ \t]+/, " ", c)
2737                                         #print a[i]
2738                                         # we actually want this data, so leaving this off for now
2739 #                                       if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) {
2740 #                                               continue
2741 #                                       }
2742                                         print c
2743                                 }
2744                         }
2745                 }' $FILE_SCSI ) )
2746                 log_function_data 'cat' "$FILE_SCSI"
2747         fi
2748         IFS="$ORIGINAL_IFS"
2749
2750         ## then we'll loop through that array looking for matches.
2751         if [[ -n $( egrep 'sd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
2752                 # first pack the main ls variable so we don't have to keep using ls /dev...
2753                 ls_disk_by_id="$( ls -l /dev/disk/by-id )"
2754                 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
2755                 do
2756                         if [[ -n $( egrep '^sd[a-z]' <<< ${A_HDD_DATA[$i]} ) ]];then
2757                                 IFS=","
2758                                 a_temp_working=( ${A_HDD_DATA[$i]} )
2759                                 IFS="$ORIGINAL_IFS"
2760                                 # /sys/block/[sda,hda]/device/model
2761                                 # this is handles the new /sys data types first
2762                                 if [[ -e /sys/block/${a_temp_working[0]}/device/model ]];then
2763                                         temp_name="$( remove_erroneous_chars /sys/block/${a_temp_working[0]}/device/model )"
2764                                         temp_name=$( tr ' ' '_' <<< $temp_name | cut -d '-' -f 1 )
2765                                 elif [[ ${#a_temp_scsi[@]} -gt 0 ]];then
2766                                         for (( j=0; j < ${#a_temp_scsi[@]}; j++ ))
2767                                         do
2768                                                 ## ok, ok, it's incomprehensible, search /dev/disk/by-id for a line that contains the
2769                                                 # discovered disk name AND ends with the correct identifier, sdx
2770                                                 # get rid of whitespace for some drive names and ids, and extra data after - in name
2771                                                 temp_name=$( tr ' ' '_' <<< ${a_temp_scsi[$j]} | cut -d '-' -f 1 )
2772                                                 sd_ls_by_id=$( egrep -m1 ".*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" )
2773
2774                                                 if [[ -n $sd_ls_by_id ]];then
2775                                                         temp_name=${a_temp_scsi[$j]}
2776                                                         break
2777                                                 else
2778                                                         # test to see if we can get a better name output when null
2779                                                         if [[ -n $temp_name ]];then
2780                                                                 temp_name=$temp_name
2781                                                         fi
2782                                                 fi
2783                                         done
2784                                 fi
2785                                 
2786                                 if [[ -z $temp_name ]];then
2787                                         temp_name="Name n/a"
2788                                 else 
2789                                         usb_exists=$( egrep -m1 "usb-.*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" )
2790                                         if [[ -n $usb_exists ]];then
2791                                                 a_temp_working[3]='USB'
2792                                         fi
2793                                 fi
2794                                 a_temp_working[2]=$temp_name
2795                                 # these loops are to easily extend the cpu array created in the gawk script above with more fields per cpu.
2796                                 for (( j=0; j < ${#a_temp_working[@]}; j++ ))
2797                                 do
2798                                         if [[ $j -gt 0 ]];then
2799                                                 A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
2800                                         else
2801                                                 A_HDD_DATA[i]="${a_temp_working[$j]}"
2802                                         fi
2803                                 done
2804                         fi
2805                 done
2806                 unset ls_disk_by_id # and then let's dump the data we don't need
2807         fi
2808         log_function_data "A_HDD_DATA: ${A_HDD_DATA[@]}"
2809         eval $LOGFE
2810 }
2811
2812 # a few notes, normally hddtemp requires root, but you can set user rights in /etc/sudoers.
2813 # args: $1 - /dev/<disk> to be tested for
2814 get_hdd_temp_data()
2815 {
2816         eval $LOGFS
2817         local hdd_temp='' sudo_command='' 
2818
2819         if [[ $B_HDDTEMP_TESTED != 'true' ]];then
2820                 B_HDDTEMP_TESTED='true'
2821                 HDDTEMP_PATH=$( type -p hddtemp )
2822         fi
2823         if [[ $B_SUDO_TESTED != 'true' ]];then
2824                 B_SUDO_TESTED='true'
2825                 SUDO_PATH=$( type -p sudo )
2826         fi
2827         
2828         if [[ -n $HDDTEMP_PATH && -n $1 ]];then
2829                 # only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
2830                 # which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
2831                 # important: -n makes it non interactive, no prompt for password
2832                 if [[ $B_ROOT != 'true' && -n $SUDO_PATH ]];then
2833                         sudo_command='sudo -n '
2834                 fi
2835                 # this will fail if regular user and no sudo present, but that's fine, it will just return null
2836                 hdd_temp=$( eval $sudo_command $HDDTEMP_PATH -nq -u C $1 )
2837                 if [[ -n $hdd_temp && -n $( grep -E '^([0-9]+)$' <<< $hdd_temp ) ]];then
2838                         echo $hdd_temp
2839                 fi
2840         fi
2841         eval $LOGFE
2842 }
2843
2844 get_lspci_data()
2845 {
2846         eval $LOGFS
2847         local lspci_data="$( lspci -v | gawk '{
2848                 gsub(/\(prog-if[^)]*\)/,"")
2849                 print
2850         }' )"
2851         
2852         echo "$lspci_data"
2853         log_function_data 'raw' "lspci_data:\n$lspci_data"
2854         eval $LOGFE
2855 }
2856
2857 ## return memory used/installed
2858 get_memory_data()
2859 {
2860         eval $LOGFS
2861         local memory=''
2862         if [[ $B_MEMINFO_FILE == 'true' ]];then
2863                 memory=$( gawk '
2864                 /^MemTotal:/ {
2865                         tot = $2
2866                 }
2867                 /^(MemFree|Buffers|Cached):/ {
2868                         notused+=$2
2869                 }
2870                 END {
2871                         used = tot-notused
2872                         printf("%.1f/%.1fMB\n", used/1024, tot/1024)
2873                 }' $FILE_MEMINFO )
2874                 log_function_data 'cat' "$FILE_MEMINFO"
2875         fi
2876         echo "$memory"
2877         log_function_data "memory: $memory"
2878         eval $LOGFE
2879 }
2880
2881 # process and return module version data
2882 get_module_version_number()
2883 {
2884         eval $LOGFS
2885         local module_version=''
2886         
2887         if [[ $B_MODINFO_TESTED != 'true' ]];then
2888                 B_MODINFO_TESTED='true'
2889                 MODINFO_PATH=$( type -p modinfo )
2890         fi
2891
2892         if [[ -n $MODINFO_PATH ]];then
2893                 module_version=$( $MODINFO_PATH $1 2>/dev/null | gawk '
2894                 BEGIN {
2895                         IGNORECASE=1
2896                 }
2897                 /^version/ {
2898                         gsub(/,/, " ", $2)
2899                         gsub(/^ +| +$/, "", $2)
2900                         gsub(/ [ \t]+/, " ", $2)
2901                         print $2
2902                 }
2903                 ' )
2904         fi
2905
2906         echo "$module_version"
2907         log_function_data "module_version: $module_version"
2908         eval $LOGFE
2909 }
2910
2911 ## create array of network cards
2912 get_networking_data()
2913 {
2914         eval $LOGFS
2915         
2916         IFS=$'\n'
2917         A_NETWORK_DATA=( $( echo "$Lspci_Data" | gawk '
2918         BEGIN {
2919                 IGNORECASE=1
2920                 counter=0 # required to handle cases of > 1 instance of the same chipset
2921         }
2922         /^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
2923                 nic=gensub(/^[0-9a-f:\.]+ [^:]+: (.+)$/,"\\1","g",$0)
2924                 gsub(/realtek semiconductor/, "Realtek", nic)
2925                 gsub(/davicom semiconductor/, "Davicom", nic)
2926                 # The doublequotes are necessary because of the pipes in the variable.
2927                 gsub(/'"$BAN_LIST_NORMAL"'/, "", nic)
2928                 gsub(/,/, " ", nic)
2929                 gsub(/^ +| +$/, "", nic)
2930                 gsub(/ [ \t]+/, " ", nic)
2931                 # construct a unique string ending for each chipset detected, this allows for
2932                 # multiple instances of the same exact chipsets, ie, dual gigabit 
2933                 nic = nic "~~" counter++
2934                 aPciBusId[nic] = gensub(/(^[0-9a-f:\.]+) [^:]+: .+$/,"\\1","g",$0)
2935                 # I do not understand why incrementing a string index makes sense? 
2936                 eth[nic]++ 
2937                 while ( getline && !/^$/ ) {
2938                         gsub(/,/, "", $0)
2939                         if ( /I\/O/ ) {
2940                                 ports[nic] = ports[nic] $4 " "
2941                         }
2942                         if ( /driver in use/ ) {
2943                                 drivers[nic] = drivers[nic] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) ""
2944                         }
2945                         else if ( /kernel modules/ ) {
2946                                 modules[nic] = modules[nic] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) ""
2947                         }
2948                 }
2949         }
2950
2951         END {
2952                 j=0
2953                 for (i in eth) {
2954                         useDrivers=""
2955                         usePorts=""
2956                         useModules=""
2957                         usePciBusId=""
2958                         if ( eth[i] > 1 ) {
2959                                 a[j] = eth[i] "x " i
2960                         }
2961                         else {
2962                                 a[j] = i
2963                         }       
2964                         ## note: this loses the plural ports case, is it needed anyway?
2965                         if ( ports[i] != "" ) {
2966                                 usePorts = ports[i]
2967                         }
2968                         if ( drivers[i] != "" ) {
2969                                 useDrivers = drivers[i]
2970                         }
2971                         if ( modules[i] != "" ) {
2972                                 useModules = modules[i]
2973                         }
2974                         if ( aPciBusId[i] != "" ) {
2975                                 usePciBusId = aPciBusId[i]
2976                         }
2977                         # create array primary item for master array
2978                         # and strip out the counter again, this handled dual cards with same chipset
2979                         sub( /~~[0-9]+$/, "", a[j] )
2980                         sub( / $/, "", usePorts ) # clean off trailing whitespace
2981                         print a[j] "," useDrivers "," usePorts "," useModules, "," usePciBusId
2982                         j++
2983                 }
2984         }') )
2985         IFS="$ORIGINAL_IFS"
2986         log_function_data "A_NETWORK_DATA: ${A_NETWORK_DATA[@]}"
2987         eval $LOGFE
2988 }
2989
2990 get_networking_wan_ip_data()
2991 {
2992         eval $LOGFS
2993         local ip=''
2994
2995         # get ip using wget redirect to stdout. This is a clean, text only IP output url.
2996         ip=$( wget -q -O - http://smxi.org/opt/ip.php | gawk -F 'is: ' '{
2997                 #gsub("\n","",$2")
2998                 print $2
2999         }' )
3000
3001         if [[ -z $ip ]];then
3002                 ip='None Detected!'
3003         fi
3004         echo "$ip"
3005         log_function_data "ip: $ip"
3006         eval $LOGFE
3007 }
3008
3009 get_networking_local_ip_data()
3010 {
3011         eval $LOGFS
3012         
3013         local ifconfig_path=$( type -p ifconfig )
3014         
3015         # lack of ifconfig will throw an error only upon it's usage
3016         if [[ -n $ifconfig_path ]];then
3017                 IFS=$'\n'
3018                 A_INTERFACES_DATA=( $( $ifconfig_path | gawk '
3019                 BEGIN {
3020                         IGNORECASE=1
3021                 }
3022                 $0 !~ /^lo/ {
3023                         # not clear on why inet is coming through, but this gets rid of it
3024                         # as first line item.
3025                         interface = $1
3026                         gsub(/,/, " ", interface)
3027                         gsub(/^ +| +$/, "", interface)
3028                         gsub(/ [ \t]+/, " ", interface)
3029
3030                         aInterfaces[interface]++
3031                         while (getline && !/^$/) {
3032                                 if (/inet addr:/) {
3033                                         ipAddresses[interface] = gensub( /addr:([0-9\.]+)/, "\\1", "g", $2 )
3034                                 }
3035                         }
3036                 }
3037
3038                 END {
3039                         j=0
3040                         for (i in aInterfaces) {
3041                                 useInterfaceIp = ""
3042                                 a[j] = i
3043                                 if (ipAddresses[i] != "") {
3044                                         useInterfaceIp = ipAddresses[i]
3045                                 }
3046                                 # create array primary item for master array
3047                                 # tested needed to avoid bad data from above, if null it is garbage
3048                                 # this is the easiest way to handle junk I found, improve if you want
3049                                 if ( useInterfaceIp != "" ) {
3050                                         print a[j] "," useInterfaceIp
3051                                 }
3052                                 j++
3053                         }
3054                 }') )
3055                 IFS="$ORIGINAL_IFS"
3056         else
3057                 A_INTERFACES_DATA=( "Interfaces tool requires missing app: ifconfig" )
3058         fi
3059         log_function_data "A_INTERFACES_DATA: ${A_INTERFACES_DATA[@]}"
3060         eval $LOGFE
3061 }
3062
3063 get_partition_data()
3064 {
3065         eval $LOGFS
3066         
3067         local a_partition_working='' dev_item=''
3068         #local excluded_file_types='--exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660'
3069         # df doesn't seem to work in script with variables like at the command line
3070         local main_partition_data="$( df -h -T --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 )"
3071         local swap_data="$( swapon -s )"
3072         # set dev disk label/uuid data globals
3073         get_partition_uuid_label_data 'label'
3074         get_partition_uuid_label_data 'uuid'
3075         
3076         log_function_data 'raw' "main_partition_data:\n$main_partition_data\n\nswap_data:\n$swap_data"
3077         
3078         IFS=$'\n'
3079         # sample line: /dev/sda2     ext3     15G  8.9G  4.9G  65% /home
3080         # $NF = partition name; $(NF - 4) = partition size; $(NF - 3) = used, in gB; $(NF - 1) = percent used
3081         ## note: by subtracting from the last field number NF, we avoid a subtle issue with LVM df output, where if
3082         ## the first field is too long, it will occupy its own line, this way we are getting only the needed data
3083         A_PARTITION_DATA=( $( echo "$main_partition_data" | gawk '
3084         BEGIN {
3085                 IGNORECASE=1
3086         }
3087         # this has to be nulled for every iteration so it does not retain value from last iteration
3088         devBase=""
3089         # this is required because below we are subtracting from NF, so it has to be > 5
3090         # the real issue is long file system names that force the wrap of df output: //fileserver/main
3091         # but we still need to handle more dynamically long space containing file names, but later.
3092         ( NF < 6 ) && ( $0 !~ /[0-9]+\%/ ) {
3093                 # set the dev location here for cases of wrapped output
3094                 if ( NF == 1 ){
3095                         devBase=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
3096                 }
3097                 getline
3098         }
3099         # next set devBase if it didn not get set above here
3100         ( $1 ~ /^\/dev\// ) && ( devBase == "" ) {
3101                 devBase=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
3102         }
3103         # this handles yet another fredforfaen special case where a mounted drive
3104         # has the search string in its name
3105         $NF ~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$/ {
3106                 print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main," $(NF - 5) "," devBase 
3107         }
3108         # skip all these, including the first, header line. Use the --exclude-type
3109         # to handle new filesystems types we do not want listed here
3110         $NF !~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$|^filesystem/ {
3111                 # this is to avoid file systems with spaces in their names, that will make
3112                 # the test show the wrong data in each of the fields, if no x%, then do not use
3113                 # using 3 cases, first default, standard, 2nd, 3rd, handles one and two spaces in name
3114                 if ( $(NF - 1) ~ /[0-9]+\%/ ) {
3115                         print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",secondary," $(NF - 5) "," devBase 
3116                 }
3117                 # these two cases construct the space containing name
3118                 else if ( $(NF - 2) ~ /[0-9]+\%/ ) {
3119                         print $(NF - 1) " " $NF "," $(NF - 5) "," $(NF - 4) "," $(NF - 2) ",secondary," $(NF - 6) "," devBase
3120                 }
3121                 else if ( $(NF - 3) ~ /[0-9]+\%/ ) {
3122                         print $(NF - 2) " " $(NF - 1) " " $NF "," $(NF - 6) "," $(NF - 5) "," $(NF - 3) ",secondary," $(NF - 7) "," devBase 
3123                 }
3124         }
3125         ' )
3126         
3127         # now add the swap partition data, don't want to show swap files, just partitions,
3128         # though this can include /dev/ramzswap0. Note: you can also use /proc/swaps for this
3129         # data, it's the same exact output as swapon -s
3130         $( echo "$swap_data" | gawk '
3131         BEGIN {
3132                 swapCounter = 1
3133         }
3134         /^\/dev/ {
3135                 size = sprintf( "%.2f", $3*1024/1000**3 )
3136                 devBase = gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
3137                 used = sprintf( "%.2f", $4*1024/1000**3 )
3138                 percentUsed = sprintf( "%.0f", ( $4/$3 )*100 )
3139                 print "swap-" swapCounter "," size "GB," used "GB," percentUsed "\%,main," "swap," devBase
3140                 swapCounter = ++swapCounter
3141         }' ) )
3142         IFS="$ORIGINAL_IFS"
3143         
3144         # now we'll handle some fringe cases where irregular df -hT output shows /dev/disk/.. instead of 
3145         # /dev/h|sdxy type data for column 1, . A_PARTITION_DATA[6]
3146         for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
3147         do
3148                 IFS=","
3149                 a_partition_working=( ${A_PARTITION_DATA[i]} )
3150                 IFS="$ORIGINAL_IFS"
3151                 dev_item='' # reset each loop
3152                 # note: for swap this will already be set
3153                 if [[ -n $( grep -E '(by-uuid|by-label)' <<< ${a_partition_working[6]} ) ]];then
3154                         if [[ -n $DEV_DISK_UUID ]];then
3155                                 dev_item=$( echo "$DEV_DISK_UUID" | gawk '
3156                                         /'$( basename ${a_partition_working[6]} )'/ {
3157                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
3158                                                 print item
3159                                         }' )
3160                         fi
3161                         # if we didn't find anything for uuid try label
3162                         if [[ -z $dev_item && -n $DEV_DISK_LABEL ]];then
3163                                 dev_item=$( echo "$DEV_DISK_LABEL" | gawk '
3164                                         /'$( basename ${a_partition_working[6]} )'/ {
3165                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
3166                                                 print item
3167                                         }' )
3168                         fi
3169                         if [[ -n $dev_item ]];then
3170                                 # assemble everything we could get for dev/h/dx, label, and uuid
3171                                 IFS=","
3172                                 A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","${a_partition_working[5]}","$dev_item
3173                                 IFS="$ORIGINAL_IFS"
3174                         fi
3175                 fi
3176         done
3177
3178         if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
3179                 get_partition_data_advanced
3180         fi
3181         log_function_data "A_PARTITION_DATA: ${A_PARTITION_DATA[@]}"
3182         eval $LOGFE
3183 }
3184
3185 # first get the locations of the mount points for label/uuid detection
3186 get_partition_data_advanced()
3187 {
3188         eval $LOGFS
3189         local a_partition_working='' dev_partition_data=''
3190         local dev_item='' dev_label='' dev_uuid=''
3191         local mount_point=''
3192         # set dev disk label/uuid data globals
3193         get_partition_uuid_label_data 'label'
3194         get_partition_uuid_label_data 'uuid'
3195
3196         if [[ $B_MOUNTS_FILE == 'true' ]];then
3197                 for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
3198                 do
3199                         IFS=","
3200                         a_partition_working=( ${A_PARTITION_DATA[i]} )
3201                         IFS="$ORIGINAL_IFS"
3202                         
3203                         # note: for swap this will already be set
3204                         if [[ -z ${a_partition_working[6]} ]];then
3205                                 mount_point=$( sed 's|/|\\/|g'  <<< ${a_partition_working[0]} )
3206                                 #echo mount_point $mount_point
3207                                 dev_partition_data=$( gawk '
3208                                 BEGIN {
3209                                         IGNORECASE = 1
3210                                         partition = ""
3211                                         partTemp = ""
3212                                 }
3213                                 # trying to handle space in name
3214 #                               gsub( /\\040/, " ", $0 )
3215                                 /[ \t]'$mount_point'[ \t]/ && $1 != "rootfs" {
3216                                         # initialize the variables
3217                                         label = ""
3218                                         uuid = ""
3219
3220                                         # slice out the /dev
3221                                         partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
3222                                         # label and uuid can occur for root, set partition to null now
3223                                         if ( partition ~ /by-label/ ) {
3224                                                 label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, $1 )
3225                                                 partition = ""
3226                                         }
3227                                         if ( partition ~ /by-uuid/ ) {
3228                                                 uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, $1 )
3229                                                 partition = ""
3230                                         }
3231
3232                                         # handle /dev/root for / id
3233                                         if ( partition == "root" ) {
3234                                                 # if this works, great, otherwise, just set this to null values
3235                                                 partTemp="'$( readlink /dev/root 2>/dev/null )'"
3236                                                 if ( partTemp != "" ) {
3237                                                         if ( partTemp ~ /[hs]d[a-z][0-9]/ ) {
3238                                                                 partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, partTemp )
3239                                                         }
3240                                                         else if ( partTemp ~ /by-uuid/ ) {
3241                                                                 uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, partTemp )
3242                                                                 partition="" # set null to let real location get discovered
3243                                                         }
3244                                                         else if ( partTemp ~ /by-label/ ) {
3245                                                                 label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, partTemp )
3246                                                                 partition="" # set null to let real location get discovered
3247                                                         }
3248                                                 }
3249                                                 else {
3250                                                         partition = ""
3251                                                         label = ""
3252                                                         uuid = ""
3253                                                 }
3254                                         }
3255                                         print partition "," label "," uuid
3256                                 }'      $FILE_MOUNTS )
3257
3258                                 # assemble everything we could get for dev/h/dx, label, and uuid
3259                                 IFS=","
3260                                 A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","${a_partition_working[5]}","$dev_partition_data
3261                                 IFS="$ORIGINAL_IFS"
3262                         fi
3263                         ## now we're ready to proceed filling in the data
3264                         IFS=","
3265                         a_partition_working=( ${A_PARTITION_DATA[i]} )
3266                         IFS="$ORIGINAL_IFS"
3267
3268                         dev_item=${a_partition_working[6]}
3269                         dev_label=${a_partition_working[7]}
3270                         dev_uuid=${a_partition_working[8]}
3271                         
3272                         # then if dev data/uuid is incomplete, try to get missing piece
3273                         # it's more likely we'll get a uuid than a label. But this should get the
3274                         # dev item set no matter what, so then we can get the rest of any missing data
3275                         # first we'll get the dev_item if it's missing
3276                         if [[ -n $DEV_DISK_UUID ]] && [[ -z $dev_item && -n $dev_uuid ]];then
3277                                 dev_item=$( echo "$DEV_DISK_UUID" | gawk '
3278                                         /'$dev_uuid'/ {
3279                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
3280                                                 print item
3281                                         }' )
3282                         elif [[ -n $DEV_DISK_LABEL ]] && [[ -z $dev_item && -n $dev_label ]];then
3283                                 dev_item=$( echo "$DEV_DISK_LABEL" | gawk '
3284                                         # first we need to change space x20 in by-label back to a real space
3285                                         #gsub( /x20/, " ", $0 )
3286                                         # then we can see if the string is there
3287                                         /'$dev_label'/ {
3288                                                 item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
3289                                                 print item
3290                                         }' )
3291                         fi
3292                         if [[ -n $DEV_DISK_UUID ]] && [[ -n $dev_item && -z $dev_uuid ]];then
3293                                 dev_uuid=$( echo "$DEV_DISK_UUID" | gawk '
3294                                 /'$dev_item'$/ {
3295                                         print $(NF - 2)
3296                                 }' )
3297                         fi
3298                         if [[ -n $DEV_DISK_LABEL ]] && [[ -n $dev_item && -z $dev_label ]];then
3299                                 dev_label=$( echo "$DEV_DISK_LABEL" | gawk '
3300                                 /'$dev_item'/ {
3301                                         print $(NF - 2)
3302                                 }' )
3303                         fi
3304
3305                         # assemble everything we could get for dev/h/dx, label, and uuid
3306                         IFS=","
3307                         A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","${a_partition_working[5]}","$dev_item","$dev_label","$dev_uuid
3308                         IFS="$ORIGINAL_IFS"
3309                 done
3310                 log_function_data 'cat' "$FILE_MOUNTS"
3311         fi
3312         log_function_data "A_PARTITION_DATA: ${A_PARTITION_DATA[@]}"
3313         eval $LOGFE
3314 }
3315
3316         
3317 # args: $1 - uuid/label
3318 get_partition_uuid_label_data()
3319 {
3320         eval $LOGFS
3321         
3322         # only run these tests once per directory to avoid excessive queries to fs
3323         case $1 in
3324                 label)
3325                         if [[ $B_LABEL_SET != 'true' ]];then
3326                                 if [[ -d /dev/disk/by-label ]];then
3327                                         DEV_DISK_LABEL="$( ls -l /dev/disk/by-label )"
3328                                 fi
3329                                 B_LABEL_SET='true'
3330                         fi
3331                         ;;
3332                 uuid)
3333                         if [[ $B_UUID_SET != 'true' ]];then
3334                                 if [[ -d /dev/disk/by-uuid ]];then
3335                                         DEV_DISK_UUID="$( ls -l /dev/disk/by-uuid )"
3336                                 fi
3337                                 B_UUID_SET='true'
3338                         fi
3339                         ;;
3340         esac
3341         log_function_data 'raw' "DEV_DISK_LABEL:\n$DEV_DISK_LABEL\n\nDEV_DISK_UUID:\n$DEV_DISK_UUID"
3342         # debugging section, uncomment to insert user data
3343 #       DEV_DISK_LABEL='
3344 #
3345 # '
3346 # DEV_DISK_UUID='
3347 #
3348 # '
3349         eval $LOGFE
3350 }
3351
3352 # args: $1 - type cpu/mem 
3353 get_ps_data()
3354 {
3355         eval $LOGFS
3356         local array_length='' reorder_temp='' i=0 head_tail='' sort_type=''
3357         
3358         # bummer, have to make it more complex here because of reverse sort
3359         # orders in output, pesky lack of support of +rss in old systems
3360         case $1 in
3361                 mem)
3362                         head_tail='head'
3363                         sort_type='-rss'
3364                         ;;
3365                 cpu)
3366                         head_tail='tail'
3367                         sort_type='%cpu'
3368                         ;;
3369         esac
3370         
3371         # throttle potential irc abuse
3372         if [[ $B_RUNNING_IN_SHELL != 'true' && $PS_COUNT -gt 5 ]];then
3373                 PS_THROTTLED=$PS_COUNT
3374                 PS_COUNT=5
3375         fi
3376
3377         IFS=$'\n'
3378         # note that inxi can use a lot of cpu, and can actually show up here as the script runs
3379         A_PS_DATA=( $( ps aux --sort $sort_type | grep -Ev "($SCRIPT_NAME|%CPU|[[:space:]]ps[[:space:]])" | $head_tail -n $PS_COUNT | gawk '
3380         BEGIN {
3381                 IGNORECASE=1
3382                 appName=""
3383                 appPath=""
3384                 appStarterName=""
3385                 appStarterPath=""
3386                 cpu=""
3387                 mem=""
3388                 pid=""
3389                 user=""
3390                 rss=""
3391         }
3392         {
3393                 cpu=$3
3394                 mem=$4
3395                 pid=$2
3396                 user=$1
3397                 rss=sprintf( "%.2f", $6/1024 )
3398                 # have to get rid of [,],(,) eg: [lockd] which break the printout function compare in bash
3399                 gsub(/\[|\]|\(|\)/,"~", $0 )
3400                 if ( $12 ~ /^\// ){
3401                         appStarterPath=$11
3402                         appPath=$12
3403                 }
3404                 else {
3405                         appStarterPath=$11
3406                         appPath=$11
3407                 }
3408                 appStarterName=gensub( /(\/.*\/)(.*)/, "\\2", "1", appStarterPath )
3409                 appName=gensub( /(\/.*\/)(.*)/, "\\2", "1", appPath )
3410                 print appName "," appPath "," appStarterName "," appStarterPath "," cpu "," mem "," pid "," rss "," user
3411         }
3412         ' ) )
3413         # make the array ordered highest to lowest so output looks the way we expect it to
3414         # this isn't necessary for -rss, and we can't make %cpu ordered the other way, so
3415         # need to reverse it here. -rss is used because on older systems +rss is not supported
3416         if [[ $1 == 'cpu' ]];then
3417                 array_length=${#A_PS_DATA[@]}; 
3418                 while (( $i < $array_length/2 ))
3419                 do 
3420                         reorder_temp=${A_PS_DATA[i]}f
3421                         A_PS_DATA[i]=${A_PS_DATA[$array_length-$i-1]}
3422                         A_PS_DATA[$array_length-$i-1]=$reorder_temp
3423                         (( i++ ))
3424                 done 
3425         fi
3426
3427         IFS="$ORIGINAL_IFS"
3428         
3429 #       echo ${A_PS_DATA[@]}
3430         eval $LOGFE
3431 }
3432
3433 # Repos will be added as we get distro package manager data to create the repo data. 
3434 # This method will output the file name also, which is useful to create output that's 
3435 # neat and readable.
3436 get_repo_data()
3437 {
3438         eval $LOGFS
3439         local repo_file='' repo_data_working='' repo_data_working2='' repo_line=''
3440         local apt_file='/etc/apt/sources.list' yum_repo_dir='/etc/yum.repos.d/' yum_conf='/etc/yum.conf'
3441         local pacman_conf='/etc/pacman.conf' pacman_repo_dir='/etc/pacman.d/' pisi_dir='/etc/pisi/'
3442         
3443         # apt - debian, buntus
3444         if [[ -f $apt_file || -d $apt_file.d ]];then
3445                 REPO_DATA="$( grep -Esv '(^[[:space:]]*$|^[[:space:]]*#)' $apt_file $apt_file.d/*.list )"
3446                 REPO_FILE_ID='apt sources'
3447         # yum - fedora, redhat, centos, etc
3448         elif [[ -d $yum_repo_dir || -f $yum_conf ]];then
3449                 # older redhats put their yum data in /etc/yum.conf
3450                 for repo_file in $( ls $yum_repo_dir*.repo $yum_conf 2>/dev/null )
3451                 do
3452                         repo_data_working="$( gawk -v repoFile=$repo_file '
3453                         # construct the string for the print function to work with, file name: data
3454                         function print_line( fileName, repoId, repoUrl ){
3455                                 print fileName ":" repoId repoUrl
3456                         }
3457                         BEGIN {
3458                                 FS="\n"
3459                                 IGNORECASE=1
3460                                 enabledStatus=""
3461                                 repoTitle=""
3462                                 urlData=""
3463                         }
3464                         # this is a hack, assuming that each item has these fields listed, we collect the 3
3465                         # items one by one, then when the url/enabled fields are set, we print it out and
3466                         # reset the data. Not elegant but it works. Note that if enabled was not present
3467                         # we assume it is enabled then, and print the line, reset the variables. This will
3468                         # miss the last item, so it is printed if found in END
3469                         /^\[.+\]/ {
3470                                 if ( urlData != "" && repoTitle != "" ){
3471                                         print_line( repoFile, repoTitle, urlData )
3472                                         enabledStatus=""
3473                                         urlData=""
3474                                         repoTitle=""
3475                                 }
3476                                 gsub( /\[|\]/, "", $1 ) # strip out the brackets
3477                                 repoTitle = $1 " ~ "
3478                         }
3479                         /^(mirrorlist|baseurl)/ {
3480                                 sub( /(mirrorlist|baseurl)=/, "", $1 ) # strip out the field starter
3481                                 urlData = $1
3482                         }
3483                         /^enabled=/ {
3484                                 enabledStatus = $1
3485                         }
3486                         # print out the line if all 3 values are found, otherwise if a new
3487                         # repoTitle is hit above, it will print out the line there instead
3488                         { 
3489                                 if ( urlData != "" && enabledStatus != "" && repoTitle != "" ){
3490                                         if ( enabledStatus !~ /enabled=0/ ){
3491                                                 print_line( repoFile, repoTitle, urlData )
3492                                         }
3493                                         enabledStatus=""
3494                                         urlData=""
3495                                         repoTitle=""
3496                                 }
3497                         }
3498                         END {
3499                                 # print the last one if there is data for it
3500                                 if ( urlData != ""  && repoTitle != "" ){
3501                                         print_line( repoFile, repoTitle, urlData )
3502                                 }
3503                         }
3504                         ' $repo_file )"
3505                         
3506                         # then load the global for each file as it gets filled
3507                         if [[ -n $repo_data_working ]];then
3508                                 if [[ -z $REPO_DATA ]];then
3509                                         REPO_DATA="$repo_data_working"
3510                                 else
3511                                         REPO_DATA="$REPO_DATA
3512 $repo_data_working"
3513                                 fi
3514                                 repo_data_working=''
3515                         fi
3516                 done
3517                 REPO_FILE_ID='yum repos'
3518         # pisi - pardus
3519         elif [[ -d $pisi_dir && -n $( type -p pisi ) ]];then
3520                 REPO_DATA="$( pisi list-repo )"
3521                 # now we need to create the structure: repo info: repo path
3522                 # we do that by looping through the lines of the output and then
3523                 # putting it back into the <data>:<url> format print repos expects to see
3524                 while read repo_line
3525                 do
3526                         repo_line=$( gawk '
3527                         {
3528                                 # need to dump leading/trailing spaces and clear out color codes for irc output
3529                                 sub(/^[[:space:]]+|[[:space:]]+$/,"",$0)
3530 #                               gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/,"",$0) # leaving this pattern in case need it
3531                                 gsub(/\e\[([0-9];)?[0-9]+m/,"",$0)
3532                                 print $0
3533                         }' <<< $repo_line )
3534                         if [[ -n $( grep '://' <<< $repo_line ) ]];then
3535                                 repo_data_working="$repo_data_working:$repo_line\n"
3536                         else
3537                                 repo_data_working="$repo_data_working$repo_line"
3538                         fi
3539                 done <<< "$REPO_DATA"
3540                 # echo and execute the line breaks inserted
3541                 REPO_DATA="$( echo -e $repo_data_working )"
3542                 REPO_FILE_ID='pisi repo'
3543         # pacman - archlinux
3544         elif [[ -f $pacman_conf ]];then
3545                 # get list of mirror include files, trim white space off ends
3546                 repo_data_working="$( gawk '
3547                 BEGIN {
3548                         FS="="
3549                         IGNORECASE=1
3550                 }
3551                 /^[[:space:]]*Include/ {
3552                         sub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
3553                         print $2
3554                 }
3555                 ' $pacman_conf )"
3556                 # sort into unique paths only, to be used to search for server = data
3557                 repo_data_working=$( sort -bu <<< "$repo_data_working" | uniq ) 
3558                 repo_data_working="$repo_data_working $pacman_conf"
3559                 for repo_file in $repo_data_working 
3560                 do
3561                         if [[ -f $repo_file ]];then
3562                                 # inserting a new line after each found / processed match
3563                                 repo_data_working2="$repo_data_working2$( gawk -v repoFile=$repo_file '
3564                                 BEGIN {
3565                                         FS="="
3566                                         IGNORECASE=1
3567                                 }
3568                                 /^[[:space:]]*Server/ {
3569                                         sub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
3570                                         print repoFile ":" $2 "\\n"
3571                                 }
3572                                 ' $repo_file )"
3573                         else
3574                                 echo "Error: file listed in $pacman_conf does not exist - $repo_file"
3575                         fi
3576                 done
3577                 # execute line breaks
3578                 REPO_DATA="$( echo -e $repo_data_working2 )"
3579                 REPO_FILE_ID='arch repo servers'
3580         fi
3581         eval $LOGFE
3582 }
3583
3584 get_runlevel_data()
3585 {
3586         eval $LOGFS
3587         local runlvl=''
3588         local runlevel_path=$( type -p runlevel )
3589         if [[ -n $runlevel_path ]];then
3590                 runlvl="$( $runlevel_path | gawk '{ print $2 }' )"
3591         fi
3592         echo $runlvl
3593         eval $LOGFE
3594 }
3595
3596 get_sensors_data()
3597 {
3598         eval $LOGFS
3599         
3600         local sensors_path=$( type -p sensors )
3601                 
3602         IFS=$'\n'
3603         if [[ -n $sensors_path ]];then
3604                 # note: non-configured sensors gives error message, which we need to redirect to stdout
3605                 # also, -F ':' no space, since some cases have the data starting right after,like - :1287
3606                 A_SENSORS_DATA=( $( 
3607                 $sensors_path | gawk -F ':' -v userCpuNo="$SENSORS_CPU_NO" '
3608                 BEGIN {
3609                         IGNORECASE=1
3610                         core0Temp="" # only if all else fails...
3611                         cpuTemp=""
3612                         cpuTempReal=""
3613                         fanWorking=""
3614                         indexCountaFanMain=0
3615                         indexCountaFanDefault=0
3616                         i=""
3617                         j=""
3618                         moboTemp=""
3619                         moboTempReal=""
3620                         psuTemp=""
3621                         separator=""
3622                         sysFanString=""
3623                         temp1=""
3624                         temp2=""
3625                         tempFanType="" # set to 1 or 2
3626                         tempUnit=""
3627                         tempWorking=""
3628                         tempWorkingUnit=""
3629                 }
3630                 # dumping the extra + signs after testing for them,  nobody has negative temps.
3631                 # also, note gawk treats Â° as a space, so we have to get the C/F data
3632                 # there are some guesses here, but with more sensors samples it will get closer.
3633                 # note: using arrays starting at 1 for all fan arrays to make it easier overall
3634                 # more validation because gensub if fails to get match returns full string, so
3635                 # we have to be sure we are working with the actual real string before assiging
3636                 # data to real variables and arrays. Extracting C/F degree unit as well to use
3637                 # when constructing temp items for array. 
3638                 # note that because of charset issues, no tempUnit="°" tempWorkingUnit degree sign 
3639                 # used, but it is required in testing regex to avoid error.
3640                 /^(M\/B|MB|SIO|SYS)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
3641                         moboTemp=gensub( /[ \t]+\+([0-9\.]*)(.*)/, "\\1", 1, $2 )
3642                         tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
3643                         if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
3644                                 tempUnit=tempWorkingUnit
3645                         }
3646                 }
3647                 /^CPU(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
3648                         cpuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
3649                         tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
3650                         if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
3651                                 tempUnit=tempWorkingUnit
3652                         }
3653                 }
3654                 /^(P\/S|Power)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
3655                         psuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
3656                         tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
3657                         if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
3658                                 tempUnit=tempWorkingUnit
3659                         }
3660                 }
3661                 $1 ~ /^temp1$/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
3662                         tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
3663                         if ( temp1 == "" || tempWorking > 0 ) {
3664                                 temp1=tempWorking
3665                         }
3666                         tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
3667                         if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
3668                                 tempUnit=tempWorkingUnit
3669                         }
3670                 }
3671                 $1 ~ /^temp2$/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
3672                         tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
3673                         if ( temp2 == "" || tempWorking > 0 ) {
3674                                 temp2=tempWorking
3675                         }
3676                         tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
3677                         if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
3678                                 tempUnit=tempWorkingUnit
3679                         }
3680                 }
3681                 
3682                 # final fallback if all else fails, funtoo user showed sensors putting
3683                 # temp on wrapped second line, not handled
3684                 /^(core0|core 0)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
3685                         tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
3686                         if ( core0Temp == "" || tempWorking > 0 ) {
3687                                 core0Temp=tempWorking
3688                         }
3689                         tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
3690                         if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
3691                                 tempUnit=tempWorkingUnit
3692                         }
3693                 }
3694                 
3695                 # note: can be cpu fan:, cpu fan speed:, etc. Some cases have no space before
3696                 # $2 starts (like so :1234 RPM), so skip that space test in regex
3697                 /^CPU(.*)[ \t]*([0-9]+)[ \t]RPM/ {
3698                         aFanMain[1]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
3699                 }
3700                 /^(M\/B|MB|SYS)(.*)[ \t]*([0-9]+)[ \t]RPM/ {
3701                         aFanMain[2]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
3702                 }
3703                 /(Power|P\/S|POWER)(.*)[ \t]*([0-9]+)[ \t]RPM/ {
3704                         aFanMain[3]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
3705                 }
3706                 # note that the counters are dynamically set for fan numbers here
3707                 # otherwise you could overwrite eg aux fan2 with case fan2 in theory
3708                 # note: cpu/mobo/ps are 1/2/3
3709                 # NOTE: test: ! i in array does NOT work, this appears to be an awk/gawk bug
3710                 /^(AUX(1)? |CASE(1)? |CHASSIS(1)? )(.*)[ \t]*([0-9]+)[ \t]RPM/ {
3711                         for ( i = 4; i < 7; i++ ){
3712                                 if ( i in aFanMain ){
3713                                         ##
3714                                 }
3715                                 else {
3716                                         aFanMain[i]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
3717                                         break
3718                                 }
3719                         }
3720                 }
3721                 /^(AUX([2-9]) |CASE([2-9]) |CHASSIS([2-9]) )(.*)[ \t]*([0-9]+)[ \t]RPM/ {
3722                         for ( i = 5; i < 30; i++ ){
3723                                 if ( i in aFanMain ) {
3724                                         ##
3725                                 }
3726                                 else {
3727                                         sysFanNu = i
3728                                         aFanMain[i]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
3729                                         break
3730                                 }
3731                         }
3732                 }
3733                 # in rare cases syntax is like: fan1: xxx RPM
3734                 /^(FAN(1)?[ \t:])(.*)[ \t]*([0-9]+)[ \t]RPM/ {
3735                         aFanDefault[1]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
3736                 }
3737                 /^FAN([2-9]|1[0-9])(.*)[ \t]*([0-9]+)[ \t]RPM/ {
3738                         fanWorking=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
3739                         sysFanNu=gensub( /fan([0-9]+)/, "\\1", 1, $1 )
3740                         if ( sysFanNu ~ /^([0-9]+)$/ ) {
3741                                 # add to array if array index does not exist OR if number is > existing number
3742                                 if ( sysFanNu in aFanDefault ) {
3743                                         if ( fanWorking >= aFanDefault[sysFanNu] ) {
3744                                                 aFanDefault[sysFanNu]=fanWorking
3745                                         }
3746                                 }
3747                                 else {
3748                                         aFanDefault[sysFanNu]=fanWorking
3749                                 }
3750                         }
3751                 }
3752                 
3753                 END {
3754                         # first we need to handle the case where we have to determine which temp/fan to use for cpu and mobo:
3755                         # note, for rare cases of weird cool cpus, user can override in their prefs and force the assignment
3756                         if ( temp1 != "" && temp2 != "" ){
3757                                 if ( userCpuNo != "" && userCpuNo ~ /(1|2)/ ) {
3758                                         tempFanType=userCpuNo
3759                                 }
3760                                 else {
3761                                         # first some fringe cases with cooler cpu than mobo: assume which is cpu temp based on fan speed
3762                                         # but only if other fan speed is 0
3763                                         if ( temp1 >= temp2 && 1 in aFanDefault && 2 in aFanDefault && aFanDefault[1] == 0 && aFanDefault[2] > 0 ) {
3764                                                 tempFanType=2
3765                                         }
3766                                         else if ( temp2 >= temp1 && 1 in aFanDefault && 2 in aFanDefault && aFanDefault[2] == 0 && aFanDefault[1] > 0 ) {
3767                                                 tempFanType=1
3768                                         }
3769                                         # then handle the standard case if these fringe cases are false
3770                                         else if ( temp1 >= temp2 ) {
3771                                                 tempFanType=1
3772                                         }
3773                                         else {
3774                                                 tempFanType=2
3775                                         }
3776                                 }
3777                         }
3778                         # need a case for no temps at all reported, like with old intels
3779                         else if ( temp2 == "" && cpuTemp == "" ){
3780                                 if ( temp1 == "" && moboTemp == "" ){
3781                                         tempFanType=1
3782                                 }
3783                                 else if ( temp1 != "" && moboTemp == "" ){
3784                                         tempFanType=1
3785                                 }
3786                                 else if ( temp1 != "" && moboTemp != "" ){
3787                                         tempFanType=1
3788                                 }
3789                         }
3790                         
3791                         # then get the real cpu temp, best guess is hottest is real
3792                         if ( cpuTemp != "" ){
3793                                 cpuTempReal=cpuTemp
3794                         }
3795                         else if ( tempFanType != "" ){
3796                                 if ( tempFanType == 1 ){
3797                                         cpuTempReal=temp1
3798                                 }
3799                                 else {
3800                                         cpuTempReal=temp2
3801                                 }
3802                         }
3803                         else {
3804                                 cpuTempReal=temp1
3805                         }
3806                         # if all else fails, use core0 temp if it is present and cpu is null
3807                         if ( cpuTempReal == "" && core0Temp != "" ) {
3808                                 cpuTempReal=core0Temp
3809                         }
3810
3811                         # then the real mobo temp
3812                         if ( moboTemp != "" ){
3813                                 moboTempReal=moboTemp
3814                         }
3815                         else if ( tempFanType != "" ){
3816                                 if ( tempFanType == 1 ) {
3817                                         moboTempReal=temp2
3818                                 }
3819                                 else {
3820                                         moboTempReal=temp1
3821                                 }
3822                         }
3823                         else {
3824                                 moboTempReal=temp2
3825                         }
3826                         # then set the cpu fan speed
3827                         if ( aFanMain[1] == "" ) {
3828                                 # note, you cannot test for aFanDefault[1] or [2] != "" 
3829                                 # because that creates an array item in gawk just by the test itself
3830                                 if ( tempFanType == 1 && 1 in aFanDefault ) {
3831                                         aFanMain[1]=aFanDefault[1]
3832                                         aFanDefault[1]=""
3833                                 }
3834                                 else if ( tempFanType == 2 && 2 in aFanDefault ) {
3835                                         aFanMain[1]=aFanDefault[2]
3836                                         aFanDefault[2]=""
3837                                 }
3838                         }
3839
3840                         # then we need to get the actual numeric max array count for both fan arrays
3841                         for (i = 0; i <= 29; i++) {
3842                                 if ( i in aFanMain && i > indexCountaFanMain ) {
3843                                         indexCountaFanMain=i
3844                                 }
3845                         }
3846                         for (i = 0; i <= 14; i++) {
3847                                 if ( i in aFanDefault && i > indexCountaFanDefault ) {
3848                                         indexCountaFanDefault=i
3849                                 }
3850                         }
3851                         
3852                         # clear out any duplicates. Primary fan real trumps fan working always if same speed
3853                         for (i = 1; i <= indexCountaFanMain; i++) {
3854                                 if ( i in aFanMain && aFanMain[i] != "" && aFanMain[i] != 0 ) {
3855                                         for (j = 1; j <= indexCountaFanDefault; j++) {
3856                                                 if ( j in aFanDefault && aFanMain[i] == aFanDefault[j] ) {
3857                                                         aFanDefault[j] = ""
3858                                                 }
3859                                         }
3860                                 }
3861                         }
3862
3863                         # now see if you can find the fast little mobo fan, > 5000 rpm and put it as mobo
3864                         # note that gawk is returning true for some test cases when aFanDefault[j] < 5000
3865                         # which has to be a gawk bug, unless there is something really weird with arrays
3866                         # note: 500 > aFanDefault[j] < 1000 is the exact trigger, and if you manually 
3867                         # assign that value below, the > 5000 test works again, and a print of the value
3868                         # shows the proper value, so the corruption might be internal in awk. 
3869                         # Note: gensub is the culprit I think, assigning type string for range 501-1000 but 
3870                         # type integer for all others, this triggers true for >
3871                         for (j = 1; j <= indexCountaFanDefault; j++) {
3872                                 if ( j in aFanDefault && int( aFanDefault[j] ) > 5000 && aFanMain[2] == "" ) {
3873                                         aFanMain[2] = aFanDefault[j]
3874                                         aFanDefault[j] = ""
3875                                         # then add one if required for output
3876                                         if ( indexCountaFanMain < 2 ) {
3877                                                 indexCountaFanMain = 2
3878                                         }
3879                                 }
3880                         }
3881
3882                         # then construct the sys_fan string for echo, note that iteration 1
3883                         # makes: fanDefaultString separator null, ie, no space or ,
3884                         for (j = 1; j <= indexCountaFanDefault; j++) {
3885                                 fanDefaultString = fanDefaultString separator aFanDefault[j]
3886                                 separator=","
3887                         }
3888                         separator="" # reset to null for next loop
3889                         # then construct the sys_fan string for echo
3890                         for (j = 1; j <= indexCountaFanMain; j++) {
3891                                 fanMainString = fanMainString separator aFanMain[j]
3892                                 separator=","
3893                         }
3894                         
3895                         # and then build the temps:
3896                         if ( moboTempReal != "" ) {
3897                                 moboTempReal = moboTempReal tempUnit
3898                         }
3899                         if ( cpuTempReal != "" ) {
3900                                 cpuTempReal = cpuTempReal tempUnit
3901                         }
3902                         
3903                         # if they are ALL null, print error message. psFan is not used in output currently
3904                         if ( cpuTempReal == "" && moboTempReal == "" && aFanMain[1] == "" && aFanMain[2] == "" && aFanMain[3] == "" && fanDefaultString == "" ) {
3905                                 print "No active sensors found. Have you configured your sensors yet?"
3906                         }
3907                         else {
3908                                 # then build array arrays: 
3909                                 print cpuTempReal "," moboTempReal "," psuTemp
3910                                 # this is for output, a null print line does NOT create a new array index in bash
3911                                 if ( fanMainString == "" ) {
3912                                         fanMainString=","
3913                                 }
3914                                 print fanMainString
3915                                 print fanDefaultString
3916                         }
3917                 }
3918                 '
3919                 ) )
3920         # the error case needs to go here because we are setting special array delimiter ','
3921         else
3922                 A_SENSORS_DATA=( "You do not have the sensors app installed." )
3923         fi
3924         
3925         IFS="$ORIGINAL_IFS"
3926         log_function_data "A_SENSORS_DATA: ${A_SENSORS_DATA[@]}"
3927 #       echo "A_SENSORS_DATA: ${A_SENSORS_DATA[@]}"
3928         eval $LOGFE
3929 }
3930
3931 get_unmounted_partition_data()
3932 {
3933         eval $LOGFS
3934         local a_unmounted_working='' mounted_partitions='' separator='' unmounted_fs=''
3935         local dev_working='' uuid_working='' label_working=''
3936         
3937         if [[ $B_PARTITIONS_FILE == 'true' ]];then
3938                 # set dev disk label/uuid data globals
3939                 get_partition_uuid_label_data 'label'
3940                 get_partition_uuid_label_data 'uuid'
3941                 
3942                 # create list for slicing out the mounted partitions
3943                 for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
3944                 do
3945                         IFS=","
3946                         a_unmounted_working=( ${A_PARTITION_DATA[i]} )
3947                         IFS="$ORIGINAL_IFS"
3948                         if [[ -n ${a_unmounted_working[6]} ]];then
3949                                 mounted_partitions="$mounted_partitions$separator${a_unmounted_working[6]}"
3950                                 separator='|'
3951                         fi
3952                 done
3953         
3954                 A_UNMOUNTED_PARTITION_DATA=( $( grep -Ev '('$mounted_partitions')' $FILE_PARTITIONS | gawk '
3955                 BEGIN {
3956                         IGNORECASE=1
3957                 }
3958                 # note that size 1 means it is a logical extended partition container
3959                 # lvm might have dm-1 type syntax
3960                 # need to exclude loop type file systems, squashfs for example
3961                 /[a-z][0-9]+$|dm-[0-9]+$/ && $3 != 1 && $NF !~ /loop/ {
3962                         size = sprintf( "%.2f", $3*1024/1000**3 )
3963                         print $4 "," size "G"
3964                 }' ) )
3965
3966                 for (( i=0; i < ${#A_UNMOUNTED_PARTITION_DATA[@]}; i++ ))
3967                 do
3968                         IFS=","
3969                         a_unmounted_working=( ${A_UNMOUNTED_PARTITION_DATA[i]} )
3970                         IFS="$ORIGINAL_IFS"
3971                         
3972                         label_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$DEV_DISK_LABEL"  | gawk '{
3973                                 print $(NF - 2)
3974                         }' )
3975                         uuid_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$DEV_DISK_UUID"  | gawk '{
3976                                 print $(NF - 2)
3977                         }' )
3978                         unmounted_fs=$( get_unmounted_partition_filesystem "/dev/${a_unmounted_working[0]}" )
3979                         
3980                         IFS=","
3981                         A_UNMOUNTED_PARTITION_DATA[i]=${a_unmounted_working[0]}","${a_unmounted_working[1]}","$label_working","$uuid_working","$unmounted_fs
3982                         IFS="$ORIGINAL_IFS"
3983                 done
3984         fi
3985 #       echo "${A_PARTITION_DATA[@]}"
3986 #       echo "${A_UNMOUNTED_PARTITION_DATA[@]}"
3987         eval $LOGFE
3988 }
3989
3990 # a few notes, normally file -s requires root, but you can set user rights in /etc/sudoers.
3991 # list of file systems: http://en.wikipedia.org/wiki/List_of_file_systems
3992 # args: $1 - /dev/<disk><part> to be tested for
3993 get_unmounted_partition_filesystem()
3994 {
3995         eval $LOGFS
3996         local partition_filesystem='' sudo_command=''
3997         
3998         if [[ $B_FILE_TESTED != 'true' ]];then
3999                 B_FILE_TESTED='true'
4000                 FILE_PATH=$( type -p file )
4001         fi
4002         
4003         if [[ $B_SUDO_TESTED != 'true' ]];then
4004                 B_SUDO_TESTED='true'
4005                 SUDO_PATH=$( type -p sudo )
4006         fi
4007         
4008         if [[ -n $FILE_PATH && -n $1 ]];then
4009                 # only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
4010                 # which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
4011                 # important: -n makes it non interactive, no prompt for password
4012                 if [[ $B_ROOT != 'true' && -n $SUDO_PATH ]];then
4013                         sudo_command='sudo -n '
4014                 fi
4015                 # this will fail if regular user and no sudo present, but that's fine, it will just return null
4016                 # note the hack that simply slices out the first line if > 1 items found in string
4017                 partition_filesystem=$( eval $sudo_command $FILE_PATH -s $1 | grep -Eio '(ext2|ext3|ext4|ext5|ext[[:space:]]|ntfs|fat32|fat16|fat[[:space:]]\(.*\)|vfat|fatx|tfat|swap|btrfs|ffs[[:space:]]|hfs\+|hfs[[:space:]]plus|hfs[[:space:]]extended[[:space:]]version[[:space:]][1-9]|hfsj|hfs[[:space:]]|jfs[[:space:]]|nss[[:space:]]|reiserfs|reiser4|ufs2|ufs[[:space:]]|xfs[[:space:]]|zfs[[:space:]])' | grep -Em 1 '.*' )
4018                 if [[ -n $partition_filesystem ]];then
4019                         echo $partition_filesystem
4020                 fi
4021         fi
4022         eval $LOGFE
4023 }
4024
4025 ## return uptime string
4026 get_uptime()
4027 {
4028         eval $LOGFS
4029         ## note: removing gsub(/ /,"",a); to get get space back in there, goes right before print a
4030         local uptime_value="$( uptime | gawk '{
4031                 a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0)
4032                 print a
4033         }' )"
4034         echo "$uptime_value"
4035         log_function_data "uptime_value: $uptime_value"
4036         eval $LOGFE
4037 }
4038
4039 #### -------------------------------------------------------------------
4040 #### special data handling for specific options and conditions
4041 #### -------------------------------------------------------------------
4042
4043 ## multiply the core count by the data to be calculated, bmips, cache
4044 # args: $1 - string to handle; $2 - cpu count
4045 calculate_multicore_data()
4046 {
4047         eval $LOGFS
4048         local string_number=$1 string_data=''
4049
4050         if [[ -n $( egrep -i '( mb| kb)' <<< $1 ) ]];then
4051                 string_data=" $( gawk '{print $2}' <<< $1 )" # add a space for output
4052                 string_number=$( gawk '{print $1}' <<< $1 )
4053         fi
4054         # handle weird error cases where it's not a number
4055         if [[ -n $( egrep '^[0-9\.,]+$' <<< $string_number ) ]];then
4056                 string_number=$( echo $string_number $2 | gawk '{
4057                         total = $1*$2
4058                         print total
4059                 }' )
4060         elif [[ $string_number == '' ]];then
4061                 string_number='Not Available'
4062         else
4063                 # I believe that the above returns 'unknown' by default so no need for extra text
4064                 string_number="$string_number "
4065         fi
4066         echo "$string_number$string_data"
4067         log_function_data "string_numberstring_data: $string_number$string_data"
4068         eval $LOGFE
4069 }
4070
4071 # prints out shortened list of flags, the main ones of interest
4072 # args: $1 - string of cpu flags to process
4073 process_cpu_flags()
4074 {
4075         eval $LOGFS
4076         # must have a space after last item in list for RS=" "
4077         local cpu_flags_working="$1 "
4078         
4079         # nx = AMD stack protection extensions
4080         # lm = Intel 64bit extensions
4081         # sse, sse2, pni = sse1,2,3,4,5 gfx extensions
4082         # svm = AMD pacifica virtualization extensions
4083         # vmx = Intel IVT (vanderpool) virtualization extensions
4084         cpu_flags=$( 
4085         echo "$cpu_flags_working" | gawk '
4086         BEGIN {
4087                 RS=" "
4088                 count = 0
4089                 i = 1 # start at one because of for increment issue
4090                 flag_string = ""
4091         }
4092         /^(lm|nx|pni|svm|vmx|(sss|ss)e([2-9])?([a-z])?(_[0-9])?)$/ {
4093                 if ( $0 == "pni" ){
4094                         a_flags[i] = "sse3"
4095                 }
4096                 else {
4097                         a_flags[i] = $0
4098                 }
4099                 i++
4100         }
4101         END {
4102                 count = asort( a_flags )
4103                 # note: why does gawk increment before the loop and not after? weird.
4104                 for ( i=0; i <= count; i++ ){
4105                         if ( flag_string == "" ) {
4106                                 flag_string = a_flags[i] 
4107                         }
4108                         else {
4109                                 flag_string = flag_string " " a_flags[i]
4110                         }
4111                 }
4112                 print flag_string
4113         }' 
4114         )
4115
4116         #grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
4117         if [[ -z $cpu_flags ]];then
4118                 cpu_flags="-"
4119         fi
4120         echo "$cpu_flags"
4121         log_function_data "cpu_flags: $cpu_flags"
4122         eval $LOGFE
4123 }
4124
4125 #### -------------------------------------------------------------------
4126 #### print and processing of output data
4127 #### -------------------------------------------------------------------
4128
4129 #### MASTER PRINT FUNCTION - triggers all line item print functions
4130 ## main function to print out, master for all sub print functions.
4131 print_it_out()
4132 {
4133         eval $LOGFS
4134         # note that print_it_out passes local variable values on to its children,
4135         # and in some cases, their children, with Lspci_Data
4136         local Lspci_Data='' # only for verbose
4137
4138         if [[ $B_SHOW_SHORT_OUTPUT == 'true' ]];then
4139                 print_short_data
4140         else
4141                 Lspci_Data="$( get_lspci_data )"
4142                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_SYSTEM == 'true' ]];then
4143                         print_system_data
4144                 fi
4145                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_CPU == 'true' ]];then
4146                         print_cpu_data
4147                 fi
4148                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_GRAPHICS == 'true' ]];then
4149                         print_gfx_data
4150                 fi
4151                 if [[ $VERBOSITY_LEVEL -ge 5 || $B_SHOW_AUDIO == 'true' ]];then
4152                         print_audio_data
4153                 fi
4154                 if [[ $VERBOSITY_LEVEL -ge 2 || $B_SHOW_NETWORK == 'true' ]];then
4155                         print_networking_data
4156                 fi
4157                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_DISK == 'true' ]];then
4158                         print_hard_disk_data
4159                 fi
4160                 if [[ $VERBOSITY_LEVEL -ge 4 || $B_SHOW_PARTITIONS == 'true' ]];then
4161                         print_partition_data
4162                 fi
4163                 if [[ $B_SHOW_UNMOUNTED_PARTITIONS == 'true' ]];then
4164                         print_unmounted_partition_data
4165                 fi
4166                 if [[ $VERBOSITY_LEVEL -ge 5 || $B_SHOW_SENSORS == 'true' ]];then
4167                         print_sensors_data
4168                 fi
4169                 if [[ $B_SHOW_REPOS == 'true' ]];then
4170                         print_repo_data
4171                 fi
4172                 if [[ $B_SHOW_PS_CPU_DATA == 'true' || $B_SHOW_PS_MEM_DATA == 'true' ]];then
4173                         print_ps_data
4174                 fi
4175                 if [[ $VERBOSITY_LEVEL -ge 1 || $B_SHOW_INFO == 'true' ]];then
4176                         print_info_data
4177                 fi
4178         fi
4179         eval $LOGFE
4180 }
4181
4182 #### SHORT OUTPUT PRINT FUNCTION, ie, verbosity 0
4183 # all the get data stuff is loaded here to keep execution time down for single line print commands
4184 # these will also be loaded in each relevant print function for long output
4185 print_short_data()
4186 {
4187         eval $LOGFS
4188         local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
4189         local processes="$(( $( ps aux | wc -l ) - 1 ))"
4190         local short_data='' i='' b_background_black='false'
4191         local memory=$( get_memory_data )
4192         local up_time="$( get_uptime )"
4193
4194         # set A_CPU_CORE_DATA
4195         get_cpu_core_count
4196         local cpc_plural='' cpu_count_print='' model_plural=''
4197         local cpu_physical_count=${A_CPU_CORE_DATA[0]}
4198         local cpu_core_count=${A_CPU_CORE_DATA[3]}
4199         local cpu_core_alpha=${A_CPU_CORE_DATA[1]}
4200         local cpu_type=${A_CPU_CORE_DATA[2]}
4201
4202         if [[ $cpu_physical_count -gt 1 ]];then
4203                 cpc_plural='(s)'
4204                 model_plural='s'
4205                 cpu_count_print="$cpu_physical_count "
4206         fi
4207
4208         local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
4209 #       local cpu_core_count=${A_CPU_CORE_DATA[0]}
4210
4211         # load A_HDD_DATA
4212         get_hdd_data_basic
4213         ## note: if hdd_model is declared prior to use, whatever string you want inserted will
4214         ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
4215         local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
4216         IFS=","
4217         local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
4218         IFS="$ORIGINAL_IFS"
4219         local hdd_capacity=${a_hdd_basic_working[0]}
4220         local hdd_used=${a_hdd_basic_working[1]}
4221
4222         # load A_CPU_DATA
4223         get_cpu_data
4224
4225         IFS=","
4226         local a_cpu_working=(${A_CPU_DATA[0]})
4227         IFS="$ORIGINAL_IFS"
4228         local cpu_model="${a_cpu_working[0]}"
4229         ## assemble data for output
4230         local cpu_clock="${a_cpu_working[1]}" # old CPU3
4231         # this gets that weird min/max final array item
4232         local min_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 ))
4233         local min_max_clock=${A_CPU_DATA[$min_max_clock_nu]}
4234
4235         #set_color_scheme 12
4236         if [[ $B_RUNNING_IN_SHELL == 'false' ]];then
4237                 for i in $C1 $C2 $CN
4238                 do
4239                         case "$i" in
4240                                 "$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN")
4241                                         b_background_black='true'
4242                                         ;;
4243                         esac
4244                 done
4245                 if [[ $b_background_black == 'true' ]];then
4246                         for i in C1 C2 CN
4247                         do
4248                                 ## these need to be in quotes, don't know why
4249                                 if [[ ${!i} == $NORMAL ]];then
4250                                         declare $i="${!i}15,1"
4251                                 else
4252                                         declare $i="${!i},1"
4253                                 fi
4254                         done
4255                         #C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
4256                 fi
4257         fi
4258         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}]"
4259
4260         if [[ $SHOW_IRC -gt 0 ]];then
4261                 short_data="${short_data} ${C1}Client${CN}[${C2}${SEP1}${IRC_CLIENT}${IRC_CLIENT_VERSION}${SEP1}${CN}]"
4262         fi
4263         short_data="${short_data} ${C1}$SCRIPT_NAME${C2}${CN}[${C2}${SEP1}$SCRIPT_VERSION_NUMBER${SEP1}${CN}]"
4264         if [[ $SCHEME -gt 0 ]];then
4265                 short_data="${short_data} $NORMAL"
4266         fi
4267         print_screen_output "$short_data"
4268         eval $LOGFE
4269 }
4270
4271 #### LINE ITEM PRINT FUNCTIONS
4272
4273 # print sound card data
4274 print_audio_data()
4275 {
4276         eval $LOGFS
4277         local i='' card_one='Card-1' audio_data='' a_audio_data='' port_data='' pci_bus_id=''
4278         local a_audio_working='' alsa_driver='' alsa_data='' port_plural='' module_version=''
4279         # set A_AUDIO_DATA and get alsa data
4280         get_audio_data
4281         alsa_data=$( get_audio_alsa_data )
4282         IFS=","
4283         a_audio_working=(${A_AUDIO_DATA[0]})
4284         IFS="$ORIGINAL_IFS"
4285
4286         if [[ -n ${A_AUDIO_DATA[@]} ]];then
4287                 # slightly complicated because 2nd array item could be the alsa data
4288                 if [[ ${#A_AUDIO_DATA[@]} -le 1 ]];then
4289                         card_one='Card'
4290                 fi
4291
4292 #               if [[ -n ${a_audio_working[2]} ]];then
4293 #                       port_data=" ${C1}at port${C2} ${a_audio_working[2]}"
4294 #               fi
4295                 # this should only trigger if the $FILE_ASOUND_DEVICE data is used, not lspci -nn
4296                 if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
4297                         # note that for some reason, the module name is not the same as the module
4298                         # loaded to kernel name for audio drivers, and you'll need to change the -
4299                         module_version=$( print_module_version "${a_audio_working[3]}" 'audio' )
4300                 elif [[ -n ${a_audio_working[1]} && $B_EXTRA_DATA == 'true' ]];then
4301                         module_version=$( print_module_version "${a_audio_working[1]}" 'audio' )
4302                 fi
4303                 if [[ -n ${a_audio_working[1]} ]];then
4304                         alsa_driver=" ${C1}driver${C2} ${a_audio_working[1]}$module_version"
4305                 fi
4306                 if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
4307                         if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
4308                                 port_plural='s'
4309                         fi
4310                         port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
4311                 fi
4312                 if [[ -n ${a_audio_working[4]} && $B_EXTRA_DATA == 'true' ]];then
4313                         pci_bus_id=" ${C1}BusID:${C2} ${a_audio_working[4]}"
4314                 fi
4315                 audio_data="${C1}$card_one${C2} ${a_audio_working[0]}$alsa_driver$port_data$pci_bus_id"
4316                 audio_data=$( create_print_line "Audio:" "$audio_data" )
4317                 print_screen_output "$audio_data"
4318                 i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
4319                 while [[ -n ${A_AUDIO_DATA[++i]} ]]
4320                 do
4321                         IFS=","
4322                         a_audio_working=( ${A_AUDIO_DATA[i]} )
4323                         IFS="$ORIGINAL_IFS"
4324                         port_data=''
4325                         alsa_driver=''
4326                         port_plural=''
4327                         module_version=''
4328                         pci_bus_id=''
4329                         if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
4330                                 module_version=$( print_module_version "${a_audio_working[3]}" 'audio' )
4331                         elif [[ -n ${a_audio_working[1]} && $B_EXTRA_DATA == 'true' ]];then
4332                                 module_version=$( print_module_version "${a_audio_working[1]}" 'audio' )
4333                         fi
4334                         # we're testing for the presence of the 2nd array item here, which is the driver name
4335                         if [[ -n ${a_audio_working[1]} ]];then
4336                                 alsa_driver="${C1}driver${C2} ${a_audio_working[1]}"
4337                         fi
4338                         if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
4339                                 if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
4340                                         port_plural='s'
4341                                 fi
4342                                 port_data=" ${C1}at port$port_plural${C2} ${a_audio_working[2]}"
4343                         fi
4344                         if [[ -n ${a_audio_working[4]} && $B_EXTRA_DATA == 'true' ]];then
4345                                 pci_bus_id=" ${C1}BusID:${C2} ${a_audio_working[4]}"
4346                         fi
4347                         if [[ -n ${a_audio_working[0]} ]];then
4348                                 audio_data="${C1}Card-$(( $i + 1 ))${C2} ${a_audio_working[0]}$alsa_driver$port_data$pci_bus_id"
4349                         fi
4350                         if [[ -n $audio_data ]];then
4351                                 audio_data=$( create_print_line " " "$audio_data" )
4352                                 print_screen_output "$audio_data"
4353                         fi
4354                 done
4355                 # alsa driver data only prints out if sound card data is found
4356                 if [[ -n $alsa_data ]];then
4357                         audio_data="${C1}Sound:${C2} $alsa_data"
4358                         audio_data=$( create_print_line " " "$audio_data" )
4359                         print_screen_output "$audio_data"
4360                 fi
4361         fi
4362         eval $LOGFE
4363 }
4364
4365 print_cpu_data()
4366 {
4367         eval $LOGFS
4368         local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data=''
4369         local bmip_data='' cpu_cache='' cpu_vendor='' cpu_flags=''
4370
4371         ##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\""
4372         # Array A_CPU_DATA always has one extra element: max clockfreq found.
4373         # that's why its count is one more than you'd think from cores/cpus alone
4374         # load A_CPU_DATA
4375         get_cpu_data
4376
4377         IFS=","
4378         local a_cpu_working=(${A_CPU_DATA[0]})
4379         IFS="$ORIGINAL_IFS"
4380         local cpu_model="${a_cpu_working[0]}"
4381         ## assemble data for output
4382         local cpu_clock="${a_cpu_working[1]}"
4383
4384         cpu_vendor=${a_cpu_working[5]}
4385
4386         # set A_CPU_CORE_DATA
4387         get_cpu_core_count
4388         local cpc_plural='' cpu_count_print='' model_plural=''
4389         local cpu_physical_count=${A_CPU_CORE_DATA[0]}
4390         local cpu_core_count=${A_CPU_CORE_DATA[3]}
4391         local cpu_core_alpha=${A_CPU_CORE_DATA[1]}
4392         local cpu_type=${A_CPU_CORE_DATA[2]}
4393
4394         if [[ $cpu_physical_count -gt 1 ]];then
4395                 cpc_plural='(s)'
4396                 cpu_count_print="$cpu_physical_count "
4397                 model_plural='s'
4398         fi
4399
4400         local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
4401         # Strange (and also some expected) behavior encountered. If print_screen_output() uses $1
4402         # as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
4403         # will output only <text1> and first element of ARR. That "@" splits in elements and "*" _doesn't_,
4404         # is to be expected. However, that text2 is consecutively truncated is somewhat strange, so take note.
4405         # This has been confirmed by #bash on freenode.
4406         # The above mentioned only emerges when using the debugging markers below
4407         ## print_screen_output "a_cpu_working=\"***${a_cpu_working[@]} $hostName+++++++\"----------"
4408
4409         if [[ -z ${a_cpu_working[2]} ]];then
4410                 a_cpu_working[2]="unknown"
4411         fi
4412
4413         cpu_data=$( create_print_line "CPU$cpc_plural:" "${C1}${cpu_data_string}${C2} ${a_cpu_working[0]}$model_plural (${cpu_type})" )
4414         if [[ $VERBOSITY_LEVEL -ge 3 || $B_SHOW_CPU == 'true' ]];then
4415                 # update for multicore, bogomips x core count.
4416                 if [[ $B_EXTRA_DATA == 'true' ]];then
4417 #                       if [[ $cpu_vendor != 'intel' ]];then
4418                                 bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$(( $cpu_core_count * $cpu_physical_count ))" )
4419 #                       else
4420 #                               bmip_data="${a_cpu_working[4]}"
4421 #                       fi
4422                         bmip_data=" ${C1}bmips${C2} $bmip_data"
4423                 fi
4424                 ## note: this handles how intel reports L2, total instead of per core like AMD does
4425                 # note that we need to multiply by number of actual cpus here to get true cache size
4426                 if [[ $cpu_vendor != 'intel' ]];then
4427                         cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$(( $cpu_core_count * $cpu_physical_count ))"  )
4428                 else
4429                         cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$cpu_physical_count"  )
4430                 fi
4431                 # only print shortened list
4432                 if [[ $B_CPU_FLAGS_FULL != 'true' ]];then
4433                         cpu_flags=$( process_cpu_flags "${a_cpu_working[3]}" )
4434                         cpu_flags=" ${C1}flags${C2} ($cpu_flags)"
4435                 fi
4436                 cpu_data="$cpu_data${C2} ${C1}cache${C2} $cpu_cache$cpu_flags$bmip_data${CN}"
4437         fi
4438         # we don't this printing out extra line unless > 1 cpu core
4439         if [[ ${#A_CPU_DATA[@]} -gt 2 ]] && [[ $B_SHOW_CPU == 'true' || $VERBOSITY_LEVEL -ge 5 ]];then
4440                 cpu_clock_speed='' # null < verbosity level 5
4441         else
4442                 cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}"
4443         fi
4444
4445         cpu_data="$cpu_data $cpu_clock_speed"
4446         print_screen_output "$cpu_data"
4447
4448         # we don't this printing out extra line unless > 1 cpu core
4449         if [[ ${#A_CPU_DATA[@]} -gt 2 ]] && [[ $B_SHOW_CPU == 'true' || $VERBOSITY_LEVEL -ge 5 ]];then
4450                 for (( i=0; i < ${#A_CPU_DATA[@]}-1; i++ ))
4451                 do
4452                         IFS=","
4453                         a_cpu_working=(${A_CPU_DATA[i]})
4454                         IFS="$ORIGINAL_IFS"
4455                         # note: the first iteration will create a first space, for color code separation below
4456                         cpu_multi_clock_data="$cpu_multi_clock_data ${C1}($(( i + 1 )))${C2} ${a_cpu_working[1]} MHz${CN}"
4457                         if [[ $i -gt 10 ]];then
4458                                 break
4459                         fi
4460                 done
4461                 if [[ -n $cpu_multi_clock_data ]];then
4462                         cpu_multi_clock_data=$( create_print_line " " "${C1}Clock Speeds:${C2}$cpu_multi_clock_data" )
4463                         print_screen_output "$cpu_multi_clock_data"
4464                 fi
4465         fi
4466         if [[ $B_CPU_FLAGS_FULL == 'true' ]];then
4467                 print_cpu_flags_full "${a_cpu_working[3]}"
4468         fi
4469         eval $LOGFE
4470 }
4471
4472 # takes list of all flags, split them and prints x per line
4473 # args: $1 - cpu flag string
4474 print_cpu_flags_full()
4475 {
4476         eval $LOGFS
4477         local cpu_flags_full="$1" a_cpu_flags='' line_starter=''
4478         local i=0 counter=0 max_length=18 max_length_add=18 flag='' flag_data=''
4479
4480         # build the flag line array
4481         for flag in $cpu_flags_full
4482         do
4483                 a_cpu_flags[$counter]="${a_cpu_flags[$counter]}$flag "
4484                 if [[ $i -ge $max_length ]];then
4485                         (( counter++ ))
4486                         max_length=$(( $max_length + $max_length_add ))
4487                 fi
4488                 ((i++))
4489         done
4490         # then print it out
4491         for (( i=0; i < ${#a_cpu_flags[@]};i++ ))
4492         do
4493                 if [[ $i -eq 0 ]];then
4494                         line_starter="${C1}CPU Flags${C2} "
4495                 else
4496                         line_starter=''
4497                 fi
4498                 flag_data=$( create_print_line " " "$line_starter${a_cpu_flags[$i]}" )
4499                 print_screen_output "$flag_data"
4500         done
4501         eval $LOGFE
4502 }
4503
4504 print_gfx_data()
4505 {
4506         eval $LOGFS
4507         local gfx_data='' i='' card_one='Card' root_alert='' root_x_string=''
4508         local screen_resolution="$( get_graphics_res_data )"
4509         local b_is_mesa='false' display_full_string=''
4510         # set A_GFX_CARD_DATA
4511         get_graphics_card_data
4512         # set A_X_DATA
4513         get_graphics_x_data
4514         local x_vendor=${A_X_DATA[0]}
4515         local x_version=${A_X_DATA[1]}
4516         # set A_GLX_DATA
4517         get_graphics_glx_data
4518         local glx_renderer="${A_GLX_DATA[0]}"
4519         local glx_version="${A_GLX_DATA[1]}"
4520         # this can contain a long No case debugging message, so it's being sliced off
4521         # note: using grep -ioE '(No|Yes)' <<< ${A_GLX_DATA[2]} did not work in Arch, no idea why
4522         local glx_direct_render=$( gawk '{
4523                 print $1
4524         }'  <<< "${A_GLX_DATA[2]}" )
4525         # some basic error handling:
4526         if [[ -z $screen_resolution ]];then
4527                 screen_resolution='N/A'
4528         fi
4529
4530         if [[ $B_X_RUNNING == 'true' && $B_ROOT != 'true' ]];then
4531                 if [[ -z $x_vendor || -z $x_version ]];then
4532                         x_vendor='X-Vendor: N/A'
4533                 fi
4534                 display_full_string="${C1}$x_vendor${C2} $x_version ${C1}Res:${C2} ${screen_resolution} "
4535         else
4536                 root_x_string=''
4537                 if [[ $B_ROOT == 'true' ]];then
4538                         root_x_string='for root '
4539                 fi
4540                 if [[ $B_X_RUNNING != 'true' ]];then
4541                         root_x_string="${root_x_string}out of X"
4542                 fi
4543                 if [[ -n $x_vendor && -n $x_version ]];then
4544                         display_full_string="${C1}$x_vendor${C2} $x_version ${C1}Res:${C2} ${screen_resolution} ${C1}Gfx Data:${C2} N/A $root_x_string"
4545                 elif [[ $B_X_RUNNING == 'true' && $B_ROOT == 'true' ]];then
4546                         root_alert="${C1}Gfx Data:${C2} N/A for root user"
4547                         display_full_string="${C1}tty res:${C2} ${screen_resolution} $root_alert"
4548                 fi
4549         fi
4550
4551         if [[ ${#A_GFX_CARD_DATA[@]} -gt 1 ]];then
4552                 i=1
4553                 while [[ -n ${A_GFX_CARD_DATA[i]} && $i -le 3 ]]
4554                 do
4555                         gfx_data=" ${C1}Card-$(($i+1))${C2} ${A_GFX_CARD_DATA[i]}"
4556                         ((i++))
4557                 done
4558                 card_one='Card-1'
4559         fi
4560         gfx_data=$( create_print_line "Graphics:" "${C1}$card_one${C2} ${A_GFX_CARD_DATA[0]}${gfx_data} $display_full_string" )
4561         print_screen_output "$gfx_data"
4562
4563 #       if [[ -z $glx_renderer || -z $glx_version ]];then
4564 #               b_is_mesa='true'
4565 #       fi
4566
4567         ## note: if glx render or version have no content, then mesa is true
4568         # if [[ $B_X_RUNNING == 'true' ]] && [[ $b_is_mesa != 'true' ]];then
4569         if [[ $B_X_RUNNING == 'true' && $B_ROOT != 'true' ]];then
4570                 if [[ -z $glx_renderer ]];then
4571                         glx_renderer='N/A'
4572                 fi
4573                 if [[ -z $glx_version ]];then
4574                         glx_version='N/A'
4575                 fi
4576                 if [[ -z $glx_direct_render ]];then
4577                         glx_direct_render='N/A'
4578                 fi
4579                 gfx_data=$( create_print_line " " "${C1}GLX Renderer${C2} ${glx_renderer} ${C1}GLX Version${C2} ${glx_version}${CN}" )
4580                 if [[ $B_HANDLE_CORRUPT_DATA == 'true' || $B_EXTRA_DATA == 'true' ]];then
4581                         gfx_data="$gfx_data ${C1}Direct Rendering${C2} ${glx_direct_render}${CN}"
4582                 fi
4583                 print_screen_output "$gfx_data"
4584         fi
4585         eval $LOGFE
4586 }
4587
4588 print_hard_disk_data()
4589 {
4590         eval $LOGFS
4591         local hdd_data='' hdd_data_2='' a_hdd_working='' hdd_temp_data='' hdd_string=''
4592         local dev_data='' size_data='' hdd_model='' usb_data='' hdd_name='' divisor=5
4593
4594         # load A_HDD_DATA
4595         get_hdd_data_basic
4596         ## note: if hdd_model is declared prior to use, whatever string you want inserted will
4597         ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
4598         local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
4599         IFS=","
4600         local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
4601         IFS="$ORIGINAL_IFS"
4602         local hdd_capacity=${a_hdd_basic_working[0]}
4603         local hdd_used=${a_hdd_basic_working[1]}
4604
4605         if [[ $VERBOSITY_LEVEL -ge 3 || $B_SHOW_DISK == 'true' ]];then
4606         ## note: the output part of this should be in the print hdd data function, not here
4607                 get_hard_drive_data_advanced
4608                 for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
4609                 do
4610                         # this adds the (x) numbering in front of each disk found, and creates the full disk string
4611                         IFS=","
4612                         a_hdd_working=( ${A_HDD_DATA[i]} )
4613                         IFS="$ORIGINAL_IFS"
4614                         if [[ $B_SHOW_DISK == 'true' || $VERBOSITY_LEVEL -ge 5 ]];then
4615                                 if [[ -n ${a_hdd_working[3]} ]];then
4616                                         usb_data="${a_hdd_working[3]} "
4617                                 else
4618                                         usb_data=''
4619                                 fi
4620                                 dev_data="/dev/${a_hdd_working[0]} "
4621                                 size_data=" ${a_hdd_working[1]}"
4622                                 if [[ $B_EXTRA_DATA == 'true' && -n $dev_data ]];then
4623                                         hdd_temp_data=$( get_hdd_temp_data "$dev_data" )
4624                                         # error handling is done in get data function
4625                                         if [[ -n $hdd_temp_data ]];then
4626                                                 hdd_temp_data=" ${hdd_temp_data}C"
4627                                         else
4628                                                 hdd_temp_data=''
4629                                         fi
4630                                 fi
4631                                 divisor=2 # for modulus line print out, either 2 items for full, or default for short
4632                         fi
4633                         hdd_name="${a_hdd_working[2]}"
4634                         hdd_string="$usb_data$dev_data$hdd_name$size_data$hdd_temp_data"
4635                         hdd_model="${hdd_model}${C1}$(($i+1)):${C2} $hdd_string "
4636                         # printing line one, then new lines according to $divisor setting, and after, if leftovers, print that line.
4637                         case $i in 
4638                                 0)
4639                                         hdd_data=$( create_print_line "Disks:" "${C1}HDD${C2} ${C1}Total Size:${C2} ${hdd_capacity} (${hdd_used}) ${hdd_model}" )
4640                                         print_screen_output "$hdd_data"
4641                                         hdd_model=''
4642                                         ;;
4643                                 *)
4644                                         # using modulus here, if divisible by $divisor, print line, otherwise skip
4645                                         if [[ $(( $i % $divisor )) -eq 0 ]];then
4646                                                 hdd_data=$( create_print_line " " "${hdd_model}${CN}" )
4647                                                 print_screen_output "$hdd_data"
4648                                                 hdd_model=''
4649                                         fi
4650                                         ;;
4651                         esac
4652                 done
4653                 # then print any leftover items
4654                 if [[ -n $hdd_model ]];then
4655                         hdd_data=$( create_print_line " " "${hdd_model}${CN}" )
4656                         print_screen_output "$hdd_data"
4657                 fi
4658         else
4659                 hdd_data=$( create_print_line "Disks:" "${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used})${CN}" )
4660                 print_screen_output "$hdd_data"
4661         fi
4662
4663         eval $LOGFE
4664 }
4665
4666 print_info_data()
4667 {
4668         eval $LOGFS
4669
4670         local info_data=''
4671         local runlvl=''
4672         local memory="$( get_memory_data )"
4673         local processes="$(( $( ps aux | wc -l ) - 1 ))"
4674         local up_time="$( get_uptime )"
4675
4676         # Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch!
4677         # long_last=$( echo -ne "${C1}Processes${C2} ${processes}${CN} | ${C1}Uptime${C2} ${up_time}${CN} | ${C1}Memory${C2} ${MEM}${CN}" )
4678         info_data=$( create_print_line "Info:" "${C1}Processes${C2} ${processes} ${C1}Uptime${C2} ${up_time} ${C1}Memory${C2} ${memory}${CN}" )
4679
4680         # this only triggers if no X data is present or if extra data switch is on
4681         if [[ $B_X_RUNNING != 'true' || $B_EXTRA_DATA == 'true' ]];then
4682                 runlvl="$( get_runlevel_data )"
4683                 if [[ -n $runlvl ]];then
4684                         info_data="${info_data} ${C1}Runlevel${C2} ${runlvl}${CN}"
4685                 fi
4686         fi
4687
4688         if [[ $SHOW_IRC -gt 0 ]];then
4689                 info_data="${info_data} ${C1}Client${C2} ${IRC_CLIENT}${IRC_CLIENT_VERSION}${CN}"
4690         fi
4691         info_data="${info_data} ${C1}$SCRIPT_NAME${C2} $SCRIPT_VERSION_NUMBER${CN}"
4692
4693         if [[ $SCHEME -gt 0 ]];then
4694                 info_data="${info_data} ${NORMAL}"
4695         fi
4696         print_screen_output "$info_data"
4697         eval $LOGFE
4698 }
4699
4700 # args: $1 - module name (could be > 1, so loop it ); $2 - audio (optional)
4701 print_module_version()
4702 {
4703         eval $LOGFS
4704         local module_versions='' module='' version='' prefix='' modules=$1
4705         
4706         # note that sound driver data tends to have upper case, but modules are lower
4707         if [[ $2 == 'audio' ]];then
4708                 if [[ -z $( grep -E '^snd' <<< $modules ) ]];then
4709                         prefix='snd_' # sound modules start with snd_
4710                 fi
4711                 modules=$( tr '[A-Z]' '[a-z]' <<< $modules )
4712                 modules=$( tr '-' '_' <<< $modules )
4713                 # special intel processing, generally no version info though
4714                 if [[ $modules == 'hda intel' ]];then
4715                         modules='hda_intel'
4716                 elif [[ $modules == 'intel ich' ]];then
4717                         modules='intel8x0'
4718                 fi
4719         fi
4720
4721         for module in $modules
4722         do
4723                 version=$( get_module_version_number "$prefix$module" )
4724                 if [[ -n $version ]];then
4725                         module_versions="$module_versions $version"
4726                 fi
4727         done
4728
4729         if [[ -n $module_versions ]];then
4730                 echo " ${C1}v:${C2}$module_versions"
4731         fi
4732         eval $LOGFE
4733 }
4734
4735 print_networking_data()
4736 {
4737         eval $LOGFS
4738         local i='' card_one='Card-1' network_data='' a_network_working='' port_data='' driver_data=''
4739         local card_string='' port_plural='' module_version='' pci_bus_id=''
4740         # set A_NETWORK_DATA
4741         get_networking_data
4742
4743         IFS=","
4744         a_network_working=(${A_NETWORK_DATA[0]})
4745         IFS="$ORIGINAL_IFS"
4746
4747         # will never be null because null is handled in get_network_data, but in case we change
4748         # that leaving this test in place.
4749         if [[ -n ${A_NETWORK_DATA[@]} ]];then
4750                 if [[ ${#A_NETWORK_DATA[@]} -le 1 ]];then
4751                         card_one='Card'
4752                 fi
4753                 if [[ -n ${a_network_working[1]} && $B_EXTRA_DATA == 'true' ]];then
4754                         module_version=$( print_module_version "${a_network_working[1]}" )
4755                 fi
4756                 if [[ -n ${a_network_working[1]} ]];then
4757                         driver_data=" ${C1}driver${C2} ${a_network_working[1]}$module_version"
4758                 fi
4759                 if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then
4760                         if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then
4761                                 port_plural='s'
4762                         fi
4763                         port_data=" ${C1}at port$port_plural${C2} ${a_network_working[2]}"
4764                 fi
4765                 if [[ -n ${a_network_working[4]} && $B_EXTRA_DATA == 'true' ]];then
4766                         pci_bus_id=" ${C1}BusID:${C2} ${a_network_working[4]}"
4767                 fi
4768                 
4769                 card_string=''
4770                 network_data="${C1}$card_one${C2} ${a_network_working[0]}$driver_data$port_data$pci_bus_id"
4771                 network_data=$( create_print_line "Network:" "$network_data" )
4772                 print_screen_output "$network_data"
4773                 i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
4774                 while [[ -n ${A_NETWORK_DATA[++i]} ]]
4775                 do
4776                         IFS=","
4777                         a_network_working=( ${A_NETWORK_DATA[i]} )
4778                         IFS="$ORIGINAL_IFS"
4779                         port_data=''
4780                         driver_data=''
4781                         port_plural=''
4782                         module_version=''
4783                         pci_bus_id=''
4784                         if [[ -n ${a_network_working[1]} && $B_EXTRA_DATA == 'true' ]];then
4785                                 module_version=$( print_module_version "${a_network_working[1]}" )
4786                         fi
4787                         if [[ -n ${a_network_working[1]} ]];then
4788                                 driver_data=" ${C1}driver${C2} ${a_network_working[1]}$module_version"
4789                         fi
4790                         if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then
4791                                 if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then
4792                                         port_plural='s'
4793                                 fi
4794                                 port_data=" ${C1}at port$port_plural${C2} ${a_network_working[2]}"
4795                         fi
4796                         if [[ -n ${a_network_working[4]} && $B_EXTRA_DATA == 'true' ]];then
4797                                 pci_bus_id=" ${C1}BusID:${C2} ${a_network_working[4]}"
4798                         fi
4799                         network_data="${C1}Card-$(( $i + 1 ))${C2} ${a_network_working[0]}$driver_data$port_data$pci_bus_id"
4800                         network_data=$( create_print_line " " "$network_data" )
4801                         print_screen_output "$network_data"
4802                 done
4803         fi
4804         if [[ $B_SHOW_IP == 'true' ]];then
4805                 print_networking_ip_data
4806         fi
4807         eval $LOGFE
4808 }
4809
4810 print_networking_ip_data()
4811 {
4812         eval $LOGFS
4813         local ip=$( get_networking_wan_ip_data )
4814         local ip_data='' a_interfaces_working='' interfaces='' interfaces_2='' i=''
4815
4816         # set A_INTERFACES_DATA
4817         get_networking_local_ip_data
4818         # first print output for wan ip line. Null is handled in the get function
4819         ip_data=$( create_print_line " " "${C1}Wan IP:${C2} $ip" )
4820
4821         # then create the list of local interface/ip
4822         interfaces=" ${C1}Interface:${C2}"
4823         i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
4824         while [[ -n ${A_INTERFACES_DATA[i]} ]]
4825         do
4826                 IFS=","
4827                 a_interfaces_working=(${A_INTERFACES_DATA[i]})
4828                 IFS="$ORIGINAL_IFS"
4829                 if [[ $i -lt 3 ]];then
4830                         if [[ -n ${a_interfaces_working[0]} ]];then
4831                                 interfaces="$interfaces ${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]}"
4832                         fi
4833                 else
4834                         if [[ -n ${a_interfaces_working[0]} ]];then
4835                                 # space on end here for lining up with line starter
4836                                 interfaces_2="$interfaces_2${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]} "
4837                         fi
4838                 fi
4839                 ((i++))
4840         done
4841         print_screen_output "$ip_data$interfaces"
4842         # then wrap it if needed
4843         if [[ -n $interfaces_2 ]];then
4844                 interfaces_2=$( create_print_line " " "$interfaces_2" )
4845                 print_screen_output "$interfaces_2"
4846         fi
4847         eval $LOGFE
4848 }
4849
4850 print_partition_data()
4851 {
4852         eval $LOGFS
4853         local a_partition_working='' partition_used='' partition_data=''
4854         local counter=0 line_max=160  i=0 a_partition_data='' line_starter=''
4855         local partitionIdClean='' part_dev='' full_dev='' part_label='' full_label=''
4856         local part_uuid='' full_uuid='' dev_remote='' full_fs=''
4857
4858         # this handles the different, shorter, irc colors strings embedded in variable data
4859         if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
4860                 line_max=130
4861         fi
4862         # and no color string data at all
4863         if [[ $SCHEME -eq 0 ]];then
4864                 line_max=75
4865         fi
4866         if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
4867                 line_max=20
4868         fi
4869
4870         # set A_PARTITION_DATA
4871         get_partition_data
4872
4873         for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
4874         do
4875                 IFS=","
4876                 a_partition_working=(${A_PARTITION_DATA[i]})
4877                 IFS="$ORIGINAL_IFS"
4878                 full_label=''
4879                 full_uuid=''
4880
4881                 if [[ $B_SHOW_PARTITIONS_FULL == 'true' ]] || [[ ${a_partition_working[4]} == 'main' ]];then
4882                         if [[ -n ${a_partition_working[2]} ]];then
4883                                 partition_used=" ${C1}used:${C2} ${a_partition_working[2]} (${a_partition_working[3]})"
4884                         else
4885                                 partition_used='' # reset partition used to null
4886                         fi
4887                         if [[ -n ${a_partition_working[5]} ]];then
4888                                 full_fs="${a_partition_working[5]}"
4889                         else
4890                                 full_fs='N/A' # reset partition used to null
4891                         fi
4892                         full_fs=" ${C1}fs:${C2} $full_fs"
4893
4894                         # don't show user names in output
4895                         if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
4896                                 if [[ -n ${a_partition_working[6]} ]];then
4897                                         if [[ -z $( grep -E '(^//|:/)' <<< ${a_partition_working[6]} ) ]];then
4898                                                 part_dev="/dev/${a_partition_working[6]}"
4899                                                 dev_remote='dev'
4900                                         else
4901                                                 part_dev="${a_partition_working[6]}"
4902                                                 dev_remote='remote'
4903                                         fi
4904                                 else
4905                                         dev_remote='dev'
4906                                         part_dev='N/A'
4907                                 fi
4908                                 full_dev=" ${C1}$dev_remote:${C2} $part_dev"
4909                                 if [[ $B_SHOW_LABELS == 'true' && $dev_remote != 'remote' ]];then
4910                                         if [[ -n ${a_partition_working[7]} ]];then
4911                                                 part_label="${a_partition_working[7]}"
4912                                         else
4913                                                 part_label='N/A'
4914                                         fi
4915                                         full_label=" ${C1}label:${C2} $part_label"
4916                                 fi
4917                                 if [[ $B_SHOW_UUIDS == 'true' && $dev_remote != 'remote' ]];then
4918                                         if [[ -n ${a_partition_working[8]} ]];then
4919                                                 part_uuid="${a_partition_working[8]}"
4920                                         else
4921                                                 part_uuid='N/A'
4922                                         fi
4923                                         full_uuid=" ${C1}uuid:${C2} $part_uuid"
4924                                 fi
4925                         fi
4926                         partitionIdClean=$( sed -r 's|/home/(.*)/(.*)|/home/##/\2|' <<< ${a_partition_working[0]} )
4927                         # because these lines can vary widely, using dynamic length handling here
4928                         a_partition_data[$counter]="${a_partition_data[$counter]}${C1}ID:${C2}$partitionIdClean ${C1}size:${C2} ${a_partition_working[1]}$partition_used$full_fs$full_dev$full_label$full_uuid "
4929
4930                         if [[ $( wc -c <<< ${a_partition_data[$counter]} ) -gt $line_max ]];then
4931                                 ((counter++))
4932                         fi
4933                 fi
4934         done
4935         # print out all lines, line starter on first line
4936         for (( i=0; i < ${#a_partition_data[@]};i++ ))
4937         do
4938                 if [[ $i -eq 0 ]];then
4939                         line_starter='Partition:'
4940                 else
4941                         line_starter=' '
4942                 fi
4943                 partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}" )
4944                 print_screen_output "$partition_data"
4945         done
4946         
4947         eval $LOGFE
4948 }
4949
4950 print_ps_data()
4951 {
4952         eval $LOGFS
4953         
4954         local b_print_first='true' 
4955
4956         if [[ $B_SHOW_PS_CPU_DATA == 'true' ]];then
4957                 get_ps_data 'cpu'
4958                 print_ps_item 'cpu' "$b_print_first"
4959                 b_print_first='false' 
4960         fi
4961         if [[ $B_SHOW_PS_MEM_DATA == 'true' ]];then
4962                 get_ps_data 'mem'
4963                 print_ps_item 'mem' "$b_print_first"
4964         fi
4965         
4966         eval $LOGFE
4967 }
4968
4969 # args: $1 - cpu/mem; $2 true/false
4970 print_ps_item()
4971 {
4972         eval $LOGFS
4973         local a_ps_data='' ps_data='' line_starter='' line_start_data='' full_line=''
4974         local app_name='' app_pid='' app_cpu='' app_mem='' throttled='' app_daemon=''
4975         local b_print_first=$2 line_counter=0 i=0 count_nu='' extra_data=''
4976         
4977         if [[ -n $PS_THROTTLED ]];then
4978                 throttled=" ${C1} - throttled from${C2} $PS_THROTTLED"
4979         fi
4980         case $1 in
4981                 cpu)
4982                         line_start_data="${C1}CPU - % used - top ${C2} $PS_COUNT ${C1}active$throttled "
4983                         ;;
4984                 mem)
4985                         line_start_data="${C1}Memory - MB / % used - top ${C2} $PS_COUNT ${C1}active$throttled"
4986                         ;;
4987         esac
4988         
4989         if [[ $b_print_first == 'true' ]];then
4990                 line_starter='Processes:'
4991         else
4992                 line_starter=' '
4993         fi
4994         
4995         # appName, appPath, appStarterName, appStarterPath, cpu, mem, pid, vsz, user
4996         ps_data=$( create_print_line "$line_starter" "$line_start_data" )
4997         print_screen_output "$ps_data"
4998
4999         for (( i=0; i < ${#A_PS_DATA[@]}; i++ ))
5000         do
5001                 IFS=","
5002                 a_ps_data=(${A_PS_DATA[i]})
5003                 IFS="$ORIGINAL_IFS"
5004                 
5005                 # handle the converted app names, with ~..~ means it didn't have a path
5006                 if [[ -n $( grep -E '^~.*~$' <<<  ${a_ps_data[0]} ) ]];then
5007                         app_daemon='daemon:'
5008                 else
5009                         app_daemon='command:'
5010                 fi
5011
5012                 app_name=" ${C1}$app_daemon${C2} ${a_ps_data[0]}"
5013                 if [[ ${a_ps_data[0]} != ${a_ps_data[2]} ]];then
5014                         app_name="$app_name ${C1}(started by:${C2} ${a_ps_data[2]}${C1})${C2}"
5015                 fi
5016                 app_pid=" ${C1}pid:${C2} ${a_ps_data[6]}"
5017                 #  ${C1}user:${C2} ${a_ps_data[8]}
5018                 case $1 in
5019                         cpu)
5020                                 app_cpu=" ${C1}cpu:${C2} ${a_ps_data[4]}%"
5021                                 if [[ $B_EXTRA_DATA == 'true' ]];then
5022                                         extra_data=" ${C1}mem:${C2} ${a_ps_data[7]}MB (${a_ps_data[5]}%)${C2}"
5023                                 fi
5024                                 ;;
5025                         mem)
5026                                 app_mem=" ${C1}mem:${C2} ${a_ps_data[7]}MB (${a_ps_data[5]}%)${C2}"
5027                                 if [[ $B_EXTRA_DATA == 'true' ]];then
5028                                         extra_data=" ${C1}cpu:${C2} ${a_ps_data[4]}%"
5029                                 fi
5030                                 ;;
5031                 esac
5032                 (( line_counter++ ))
5033                 count_nu="${C1}$line_counter -${C2}"
5034                 full_line="$count_nu$app_cpu$app_mem$app_name$app_pid$extra_data"
5035                 ps_data=$( create_print_line " " "$full_line" )
5036                 print_screen_output "$ps_data"
5037         done
5038         
5039         eval $LOGFE
5040 }
5041
5042
5043 # currently only apt using distros support this feature, but over time we can add others
5044 print_repo_data()
5045 {
5046         eval $LOGFS
5047         local repo_count=0 repo_line='' file_name='' file_content='' file_name_holder=''
5048         local repo_full='' b_print_next_line='false' 
5049         
5050         get_repo_data
5051         
5052         if [[ -n $REPO_DATA ]];then
5053                 # loop through the variable's lines one by one, update counter each iteration
5054                 while read repo_line
5055                 do
5056                         (( repo_count++ ))
5057                         file_name=$( cut -d ':' -f 1 <<< $repo_line )
5058                         file_content=$( cut -d ':' -f 2-6 <<< $repo_line )
5059                         # this will dump unwanted white space line starters. Some irc channels
5060                         # use bots that show page title for urls, so need to break the url by adding 
5061                         # a white space.
5062                         if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
5063                                 file_content=$( echo $file_content | sed 's|://|: //|' )
5064                         else
5065                                 file_content=$( echo $file_content )
5066                         fi
5067                         # check file name, if different, update the holder for print out
5068                         if [[ $file_name != $file_name_holder ]];then
5069                                 if [[ $REPO_FILE_ID != 'pisi repo' ]];then
5070                                         repo_full="${C1}Active $REPO_FILE_ID in file:${C2} $file_name"
5071                                 else
5072                                         repo_full="${C1}$REPO_FILE_ID:${C2} $file_name"
5073                                 fi
5074                                 file_name_holder=$file_name
5075                                 b_print_next_line='true'
5076                         else
5077                                 repo_full=$file_content
5078                         fi
5079                         # first line print Repos: 
5080                         if [[ $repo_count -eq 1 ]];then
5081                                 repo_full=$( create_print_line "Repos:" "$repo_full" )
5082                         else
5083                                 repo_full=$( create_print_line " " "$repo_full" )
5084                         fi
5085                         print_screen_output "$repo_full"
5086                         # this prints the content of the file as well as the file name
5087                         if [[ $b_print_next_line == 'true' ]];then
5088                                 repo_full=$( create_print_line " " "$file_content" )
5089                                 print_screen_output "$repo_full"
5090                                 b_print_next_line='false'
5091                         fi
5092                 done <<< "$REPO_DATA"
5093         else
5094                 repo_full=$( create_print_line "Repos:" "${C1}Error:${C2} $SCRIPT_NAME does not support this feature for your distro yet." )
5095                 print_screen_output "$repo_full"
5096         fi
5097         eval $LOGFE
5098 }
5099
5100 print_sensors_data()
5101 {
5102         eval $LOGFS
5103         local mobo_temp='' cpu_temp='' psu_temp='' cpu_fan='' mobo_fan='' ps_fan='' sys_fans='' sys_fans2='' 
5104         local temp_data='' fan_data='' fan_data2='' b_is_error='false' fan_count=0 gpu_temp=''
5105         local a_sensors_working=''
5106         get_sensors_data
5107         
5108         IFS=","
5109         a_sensors_working=( ${A_SENSORS_DATA[0]} )
5110         IFS="$ORIGINAL_IFS"
5111         # initial error cases, for missing app or unconfigured sensors. Note that array 0
5112         # always has at least 3 items, cpu/mobo/psu temp in it. If it's a single item, then
5113         # it's an error message, not the real data arrays.
5114         if [[ ${#a_sensors_working[@]} -eq 1 ]];then
5115                 cpu_temp="${C1}Error:${C2} ${A_SENSORS_DATA[0]}"
5116                 b_is_error='true'
5117         else
5118                 for (( i=0; i < ${#A_SENSORS_DATA[@]}; i++ ))
5119                 do
5120                         IFS=","
5121                         a_sensors_working=( ${A_SENSORS_DATA[i]} )
5122                         IFS="$ORIGINAL_IFS"
5123                         case $i in
5124                                 # first the temp data
5125                                 0)
5126                                         if [[ -n ${a_sensors_working[0]} ]];then
5127                                                 cpu_temp=${a_sensors_working[0]}
5128                                         else
5129                                                 cpu_temp='N/A'
5130                                         fi
5131                                         cpu_temp="${C1}System Temperatures: cpu:${C2} $cpu_temp "
5132
5133                                         if [[ -n ${a_sensors_working[1]} ]];then
5134                                                 mobo_temp=${a_sensors_working[1]}
5135                                         else
5136                                                 mobo_temp='N/A'
5137                                         fi
5138                                         mobo_temp="${C1}mobo:${C2} $mobo_temp "
5139
5140                                         if [[ -n ${a_sensors_working[2]} ]];then
5141                                                 psu_temp="${C1}psu:${C2} ${a_sensors_working[2]} "
5142                                         fi
5143                                         gpu_temp=$( get_gpu_temp_data )
5144                                         # dump the unneeded screen data for single gpu systems 
5145                                         if [[ $( wc -w <<< $gpu_temp ) -eq 1 && $B_EXTRA_DATA != 'true' ]];then
5146                                                 gpu_temp=$( cut -d ':' -f 2 <<< $gpu_temp )
5147                                         fi
5148                                         if [[ -n $gpu_temp ]];then
5149                                                 gpu_temp="${C1}gpu:${C2} ${gpu_temp} "
5150                                         fi
5151                                         ;;
5152                                 # then the fan data from main fan array
5153                                 1)
5154                                         for (( j=0; j < ${#a_sensors_working[@]}; j++ ))
5155                                         do
5156                                                 case $j in
5157                                                         0)
5158                                                                 # we need to make sure it's either cpu fan OR cpu fan and sys fan 1
5159                                                                 if [[ -n ${a_sensors_working[0]} ]];then
5160                                                                         cpu_fan="${a_sensors_working[0]}"
5161                                                                 elif [[ -z ${a_sensors_working[0]} && -n ${a_sensors_working[1]} ]];then
5162                                                                         cpu_fan="${a_sensors_working[1]}"
5163                                                                 else
5164                                                                         cpu_fan='N/A'
5165                                                                 fi
5166                                                                 cpu_fan="${C1}Fan Speeds (in rpm): cpu:${C2} $cpu_fan "
5167                                                                 (( fan_count++ ))
5168                                                                 ;;
5169                                                         1)
5170                                                                 if [[ -n ${a_sensors_working[1]} ]];then
5171                                                                         mobo_fan="${C1}mobo:${C2} ${a_sensors_working[1]} "
5172                                                                         (( fan_count++ ))
5173                                                                 fi
5174                                                                 ;;
5175                                                         2)
5176                                                                 if [[ -n ${a_sensors_working[2]} ]];then
5177                                                                         ps_fan="${C1}psu:${C2} ${a_sensors_working[2]} "
5178                                                                         (( fan_count++ ))
5179                                                                 fi
5180                                                                 ;;
5181                                                         [3-9]|[1-9][0-9])
5182                                                                 if [[ -n ${a_sensors_working[$j]} ]];then
5183                                                                         fan_number=$(( $j - 2 )) # sys fans start on array key 5
5184                                                                         # wrap after fan 6 total
5185                                                                         if [[ $fan_count -lt 7 ]];then
5186                                                                                 sys_fans="$sys_fans${C1}sys-$fan_number:${C2} ${a_sensors_working[$j]} "
5187                                                                         else
5188                                                                                 sys_fans2="$sys_fans2${C1}sys-$fan_number:${C2} ${a_sensors_working[$j]} "
5189                                                                         fi
5190                                                                         (( fan_count++ ))
5191                                                                 fi
5192                                                                 ;;
5193                                                 esac
5194                                         done
5195                                         ;;
5196                                 2)
5197                                         for (( j=0; j < ${#a_sensors_working[@]}; j++ ))
5198                                         do
5199                                                 case $j in
5200                                                         [0-9]|[1-9][0-9])
5201                                                                 if [[ -n ${a_sensors_working[$j]} ]];then
5202                                                                         fan_number=$(( $j + 1 )) # sys fans start on array key 5
5203                                                                         # wrap after fan 6 total
5204                                                                         if [[ $fan_count -lt 7 ]];then
5205                                                                                 sys_fans="$sys_fans${C1}fan-$fan_number:${C2} ${a_sensors_working[$j]} "
5206                                                                         else
5207                                                                                 sys_fans2="$sys_fans2${C1}fan-$fan_number:${C2} ${a_sensors_working[$j]} "
5208                                                                         fi
5209                                                                         (( fan_count++ ))
5210                                                                 fi
5211                                                                 ;;
5212                                                 esac
5213                                         done
5214                                         ;;
5215                         esac
5216                 done
5217         fi
5218         # turning off all output for case where no sensors detected or no sensors output 
5219         # unless -s used explicitly. So for -F type output won't show unless valid or -! 1 used
5220         if [[ $b_is_error != 'true' || $B_SHOW_SENSORS == 'true' || $B_TESTING_1 == 'true' ]];then
5221                 temp_data="$cpu_temp$mobo_temp$psu_temp$gpu_temp"
5222                 temp_data=$( create_print_line "Sensors:" "$temp_data" )
5223                 print_screen_output "$temp_data"
5224                 # don't print second or subsequent lines if error data
5225                 fan_data="$cpu_fan$mobo_fan$ps_fan$sys_fans"
5226                 if [[ $b_is_error != 'true' && -n $fan_data ]];then
5227                         fan_data=$( create_print_line " " "$fan_data" )
5228                         print_screen_output "$fan_data"
5229                         # and then second wrapped fan line if needed
5230                         if [[ -n $sys_fans2 ]];then
5231                                 fan_data2=$( create_print_line " " "$sys_fans2" )
5232                                 print_screen_output "$fan_data2"
5233                         fi
5234                 fi
5235         fi
5236         eval $LOGFE
5237 }
5238
5239 print_system_data()
5240 {
5241         eval $LOGFS
5242         local system_data='' bits=''
5243         local host_name=$( hostname )
5244         local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' )
5245         local distro="$( get_distro_data )"
5246                 # check for 64 bit first
5247         if [[ -n $( uname -m | grep -o 'x86_64' ) ]];then
5248                 bits="(64 bit)"
5249         else
5250                 bits="(32 bit)"
5251         fi
5252
5253         if [[ $B_SHOW_HOST == 'true' ]];then
5254                 system_data=$( create_print_line "System:" "${C1}Host${C2} $host_name ${C1}Kernel${C2}" )
5255         else
5256                 system_data=$( create_print_line "System:" "${C1}Kernel${C2}" )
5257         fi
5258         system_data="$system_data $current_kernel $bits ${C1}Distro${C2} $distro"
5259         print_screen_output "$system_data"
5260         eval $LOGFE
5261 }
5262
5263 print_unmounted_partition_data()
5264 {
5265         eval $LOGFS
5266         local a_unmounted_data='' line_starter='' unmounted_data='' full_fs=''
5267         local full_dev='' full_size='' full_label='' full_uuid='' full_string=''
5268         
5269         if [[ -z ${A_PARTITION_DATA} ]];then
5270                 get_partition_data
5271         fi
5272         get_unmounted_partition_data
5273         
5274         if [[ ${#A_UNMOUNTED_PARTITION_DATA[@]} -ge 1 ]];then
5275                 for (( i=0; i < ${#A_UNMOUNTED_PARTITION_DATA[@]}; i++ ))
5276                 do
5277                         IFS=","
5278                         a_unmounted_data=(${A_UNMOUNTED_PARTITION_DATA[i]})
5279                         IFS="$ORIGINAL_IFS"
5280                         if [[ -z ${a_unmounted_data[0]} ]];then
5281                                 full_dev='N/A'
5282                         else
5283                                 full_dev="/dev/${a_unmounted_data[0]}"
5284                         fi
5285                         full_dev="${C1}ID:${C2} $full_dev"
5286                         if [[ -z ${a_unmounted_data[1]} ]];then
5287                                 full_size='N/A'
5288                         else
5289                                 full_size=${a_unmounted_data[1]}
5290                         fi
5291                         full_size="${C1}size:${C2} $full_size"
5292                         if [[ -z ${a_unmounted_data[2]} ]];then
5293                                 full_label='N/A'
5294                         else
5295                                 full_label=${a_unmounted_data[2]}
5296                         fi
5297                         full_label="${C1}label:${C2} $full_label"
5298                         if [[ -z ${a_unmounted_data[3]} ]];then
5299                                 full_uuid='N/A'
5300                         else
5301                                 full_uuid=${a_unmounted_data[3]}
5302                         fi
5303                         full_uuid="${C1}uuid:${C2} $full_uuid"
5304                         if [[ -z ${a_unmounted_data[4]} ]];then
5305                                 full_fs=''
5306                         else
5307                                 full_fs="${C1}fs:${C2} ${a_unmounted_data[4]}"
5308                         fi
5309                         full_string="$full_dev $full_size $full_label $full_uuid $full_fs"
5310                         if [[ $i -eq 0 ]];then
5311                                 line_starter='Unmounted:'
5312                         else
5313                                 line_starter=' '
5314                         fi
5315                         unmounted_data=$( create_print_line "$line_starter" "$full_string" )
5316                         print_screen_output "$unmounted_data"
5317                 done
5318         else
5319                 unmounted_data=$( create_print_line "Unmounted:" "No unmounted partitions detected." )
5320                 print_screen_output "$unmounted_data"
5321         fi
5322         
5323         eval $LOGFE
5324 }
5325
5326 ########################################################################
5327 #### SCRIPT EXECUTION
5328 ########################################################################
5329
5330 main $@ ## From the End comes the Beginning
5331
5332 ## note: this EOF is needed for smxi handling, this is what triggers the full download ok
5333 ###**EOF**###