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