Update inxi to version 2.3.0
[quassel.git] / data / scripts / inxi
1 #!/usr/bin/env bash
2 ########################################################################
3 ####  Script Name: inxi
4 ####  Version: 2.3.0
5 ####  Date: 2016-04-18
6 ####  Patch Number: 00
7 ########################################################################
8 ####  SPECIAL THANKS
9 ########################################################################
10 ####  Special thanks to all those in #lsc and #smxi for their tireless 
11 ####  dedication helping test inxi modules.
12 ########################################################################
13 ####  ABOUT INXI
14 ########################################################################
15 ####  inxi is a fork of infobash 3.02, the original bash sys info tool by locsmif
16 ####  As time permits functionality improvements and recoding will occur.
17 ####
18 ####  inxi, the universal, portable, system information tool for irc.
19 ####  Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,
20 ####  Gaim/Pidgin, Weechat, KVIrc and Kopete.
21 ####  Original infobash author and copyright holder:
22 ####  Copyright (C) 2005-2007  Michiel de Boer a.k.a. locsmif
23 ####  inxi version: Copyright (C) 2008-2016 Scott Rogers & Harald Hope
24 ####  Further fixes (listed as known): Horst Tritremmel <hjt at sidux.com>
25 ####  Steven Barrett (aka: damentz) - usb audio patch; swap percent used patch
26 ####  Jarett.Stevens - dmidecde -M patch for older systems with the /sys 
27 ####
28 ####  Current script home page/wiki/git: https://github.com/smxi/inxi 
29 ####  Documentation/wiki pages will move to http://smxi.org soon.
30 ####  Script forums: http://techpatterns.com/forums/forum-33.html
31 ####  IRC support: irc.oftc.net channel #smxi
32 ####  Version control:
33 ####   * https://github.com/smxi/inxi
34 ####   * git: git pull https://github.com/smxi/inxi master
35 ####   * svn checkout url: https://github.com/smxi/inxi
36 ####
37 ####  This program is free software; you can redistribute it and/or modify
38 ####  it under the terms of the GNU General Public License as published by
39 ####  the Free Software Foundation; either version 3 of the License, or
40 ####  (at your option) any later version.
41 ####
42 ####  This program is distributed in the hope that it will be useful,
43 ####  but WITHOUT ANY WARRANTY; without even the implied warranty of
44 ####  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45 ####  GNU General Public License for more details.
46 ####
47 ####  You should have received a copy of the GNU General Public License
48 ####  along with this program.  If not, see <http://www.gnu.org/licenses/>.
49 ####
50 ####  If you don't understand what Free Software is, please read (or reread)
51 ####  this page: http://www.gnu.org/philosophy/free-sw.html
52 ########################################################################
53
54 ####
55 #### PACKAGE NAME NOTES
56 ####  * Package names in (...) are the Debian Squeeze package name. Check your 
57 ####    distro for proper package name by doing this: which <application> 
58 ####    then find what package owns that application file. Or run --recommends
59 ####    which shows package names for Debian/Ubuntu, Arch, and Fedora/Redhat/Suse
60 ####
61 ####  DEPENDENCIES
62 ####  * bash >=3.0 (bash); df, readlink, stty, tr, uname, wc (coreutils);
63 ####    gawk (gawk); grep (grep); lspci (pciutils);
64 ####    ps, find (findutils)
65 ####  * Also the proc filesystem should be present and mounted for Linux
66 ####  * Some features, like -M and -d will not work, or will work incompletely,
67 ####    if /sys is missing
68 ####
69 ####    Apparently unpatched bash 3.0 has arrays broken; bug reports:
70 ####    http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-008
71 ####    http://lists.gnu.org/archive/html/bug-bash/2004-08/msg00144.html
72 ####  Bash 3.1 for proper array use
73 ####
74 ####    Arrays work in bash 2.05b, but "grep -Em" does not
75 ####
76 ####  RECOMMENDS (Needed to run certain features, listed by option)
77 ####  -A - for output of usb audio information: lsusb (usbutils)
78 ####  -Ax -Nx - for audio/network module version: modinfo (module-init-tools)
79 ####  -Dx - for hdd temp output (root only default): hddtemp (hddtemp)
80 ####       For user level hdd temp output: sudo (sudo)
81 ####       Note: requires user action for this feature to run as user (edit /etc/sudoers file)
82 ####  -G - full graphics output requires:  glxinfo (mesa-utils); xdpyinfo (X11-utils);
83 ####       xrandr (x11-xserver-utils)
84 ####  -i - IP information, local/wan - ip (iproute) legacy, not used if ip present: ifconfig (net-tools)
85 ####  -I - uptime (procps, check Debian if changed)
86 ####  -Ix - view current runlevel while not in X window system (or with -x): runlevel (sysvinit)
87 ####  -m - all systems, dmidecode, unless someone can find a better way.
88 ####  -M - for older systems whose kernel does not have /sys data for machine, dmidecode (dmidecode)
89 ####  -o - for unmounted file system information in unmounted drives (root only default): file (file)
90 ####       Note: requires user action for this feature to run as user (edit /etc/sudoers file)
91 ####       For user level unmounted file system type output: sudo (sudo)
92 ####  -s   For any sensors output, fan, temp, etc: sensors (lm-sensors)
93 ####       Note: requires setup of lm-sensors (sensors-detect and adding modules/modprobe/reboot,
94 ####       and ideally, pwmconfig) prior to full output being available. 
95 ####  -S   For desktop environment, user must be in X and have xprop installed (in X11-utils)
96 ########################################################################
97 ####  BSD Adjustments
98 ####  * sed -i '' form supported by using SED_I="-i ''".
99 ####  * Note: New BSD sed supports using -r instead of -E for compatibility with gnu sed
100 ####    However, older, like FreeBSD 7.x, does not have -r so using SED_RX='-E' for this.
101 ####  * Gnu grep options can be used if the function component is only run in linux
102 ####    These are the options that bsd grep does not support that inxi uses: -m <number> -o 
103 ####    so make sure if you use those to have them in gnu/linux only sections.
104 ####    It appears that freebsd uses gnu grep but openbsd uses bsd grep, however.
105 ####  * BSD ps does not support --without-headers option, and also does not support --sort <option>
106 ####    Tests show that -m fails to sort memory as expected, but -r does sort cpu percentage.
107 ####  * BSD_TYPE is set with values null, debian-bsd (debian gnu/kfreebsd), bsd (all other bsds)
108 ####  * Subshell and array closing ) must not be on their own line unless you use an explicit \ 
109 ####    to indicate that logic continues to next line where closing ) or )) are located.
110 ########################################################################
111 ####  CONVENTIONS:
112 ####  * Character Encoding: UTF-8 - this file contains special characters that must be opened and saved as UTF8
113 ####  * Indentation: TABS
114 ####  * Do not use `....` (back quotes), those are totally non-reabable, use $(....).
115 ####  * Do not use one liner flow controls. 
116 ####    The ONLY time you should use ';' (semi-colon) is in this single case: if [[ condition ]];then.
117 ####    Never use compound 'if': ie, if [[ condition ]] && statement.
118 ####  * Note: [[ -n $something ]] - double brackets does not require quotes for variables: ie, "$something".
119 ####  * Always use quotes, double or single, for all string values.
120 ####  * All new code/methods must be in a function.
121
122 ####  * For all boolean tests, use 'true' / 'false'.
123 ####    !! Do NOT use 0 or 1 unless it's a function return. 
124 ####  * Avoid complicated tests in the if condition itself.
125 ####  * To 'return' a value in a function, use 'echo <var>'.
126 ####  * For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
127 ####    This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
128 ####  * Using ${VAR} is about 30% slower than $VAR because bash has to check the stuff for actions
129 ####  SUBSHELLS ARE EXPENSIVE! - run these two if you do not believe me.
130 ####  time for (( i=0; i<1000; i++ )) do ff='/usr/local/bin/foo.pid';ff=${ff##*/};ff=${ff%.*};done;echo $ff
131 ####  time for (( i=0; i<1000; i++ )) do ff='/usr/local/bin/foo.pid';ff=$( basename $ff | cut -d '.' -f 1 );done;echo $ff
132 ####
133 ####  VARIABLE/FUNCTION NAMING:
134 ####  * All functions should follow standard naming--verb adjective noun. 
135 ####      ie, get_cpu_data
136 ####  * All variables MUST be initialized / declared explicitly, either top of file, for Globals, or using local
137 ####  * All variables should clearly explain what they are, except counters like i, j.
138 ####  * Each word of Bash variable must be separated by '_' (underscore) (camel form), like: cpu_data
139 ####  * Each word of Gawk variable must be like this (first word lower, following start with upper): cpuData
140 ####  * Global variables are 'UPPER CASE', at top of this file.
141 ####      ie, SOME_VARIABLE=''
142 ####  * Local variables are 'lower case' and declared at the top of the function using local, always.
143 ####      ie: local some_variable=''
144 ####  * Locals that will be inherited by child functions have first char capitalized (so you know they are inherited).
145 ####      ie, Some_Variable 
146 ####  * Booleans should start with b_ (local) or B_ (global) and state clearly what is being tested.
147 ####  * Arrays should start with a_ (local) or A_ (global).
148 ####
149 ####  SPECIAL NOTES:
150 ####  * The color variable ${C2} must always be followed by a space unless you know what
151 ####    character is going to be next for certain. Otherwise irc color codes can be accidentally
152 ####    activated or altered.
153 ####  * For native script konversation support (check distro for correct konvi scripts path):
154 ####    ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi
155 ####    DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.
156 ####  * print_screen_output " " # requires space, not null, to avoid error in for example in irssi
157 ####  * For logging of array data, array must be placed into the a_temp, otherwise only the first key logs
158 ####  * In gawk search patterns, . is a wildcard EXCEPT in [0-9.] type containers, then it's a literal
159 ####    So outside of bracketed items, it must be escaped, \. but inside, no need. Outside of gawk it should 
160 ####    be escaped in search patterns if you are using it as a literal.
161 ####  
162 ####  PACKAGE MANAGER DATA (note, while inxi tries to avoid using package managers to get data, sometimes 
163 ####  it's the only way to get some data):
164 ####  * dpkg options: http://www.cyberciti.biz/howto/question/linux/dpkg-cheat-sheet.php
165 ####  * pacman options: https://wiki.archlinux.org/index.php/Pacman_Rosetta
166 ####
167 ####  As with all 'rules' there are acceptions, these are noted where used.
168 ###################################################################################
169 ####    KDE Konversation information.  Moving from dcop(qt3/KDE3) to dbus(qt4/KDE4)
170 ###################################################################################
171 ####  * dcop and dbus   -- these talk back to Konversation from this program
172 ####  * Scripting info  -- http://konversation.berlios.de/docs/scripting.html
173 ####    -- http://www.kde.org.uk/apps/konversation/
174 ####  * dbus info       -- http://dbus.freedesktop.org/doc/dbus-tutorial.html
175 ####    view dbus info  -- https://fedorahosted.org/d-feet/
176 ####    -- or run qdbus
177 ####  * Konvi dbus/usage-- qdbus org.kde.konversation /irc say <server> <target-channel> <output>
178 ####  * Python usage    -- http://wiki.python.org/moin/DbusExamples  (just in case)
179 ####
180 ####    Because webpages come and go, the above information needs to be moved to inxi's wiki
181 ########################################################################
182 ####  Valuable Resources
183 ####  CPU flags: http://unix.stackexchange.com/questions/43539/what-do-the-flags-in-proc-cpuinfo-mean
184 ####  Advanced Bash: http://wiki.bash-hackers.org/syntax/pe
185 ####  gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
186 ####  raid mdstat: http://www-01.ibm.com/support/docview.wss?uid=isg3T1011259
187 ####               http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array
188 ####               https://raid.wiki.kernel.org/index.php/Mdstat
189 ########################################################################
190 ####  TESTING FLAGS
191 ####  inxi supports advanced testing triggers to do various things, using -! <arg>
192 ####  -! 1  - triggers default B_TESTING_1='true' to trigger some test or other
193 ####  -! 2  - triggers default B_TESTING_2='true' to trigger some test or other
194 ####  -! 3  - triggers B_TESTING_1='true' and B_TESTING_2='true'
195 ####  -! 10 - triggers an update from the primary dev download server instead of svn
196 ####  -! 11 - triggers an update from svn branch one - if present, of course
197 ####  -! 12 - triggers an update from svn branch two - if present, of course
198 ####  -! 13 - triggers an update from svn branch three - if present, of course
199 ####  -! 14 - triggers an update from svn branch four - if present, of course
200 ####  -! <http://......> - Triggers an update from whatever server you list.
201 ####  LOG FLAGS (logs to $HOME/.inxi/inxi.log with rotate 3 total)
202 ####  -@ 8  - Basic data logging of generated data / array values
203 ####  -@ 9  - Full logging of all data used, including cat of files and system data
204 ####  -@ 10 - Basic data logging plus color code logging
205 ########################################################################
206 #### VARIABLES
207 ########################################################################
208
209 ## NOTE: we can use hwinfo if it's available in all systems, or most, to get
210 ## a lot more data and verbosity levels going
211
212 ### DISTRO MAINTAINER FLAGS ###
213 # flag to allow distro maintainers to turn off update features. If false, turns off
214 # -U and -! testing/advanced update options, as well as removing the -U help menu item
215 # NOTE: Usually you want to create these in /etc/inxi.conf to avoid having to update each time
216 B_ALLOW_UPDATE='true'
217 B_ALLOW_WEATHER='true'
218
219 ### USER CONFIGS: SET IN inxi.conf file see wiki for directions ###
220 # http://code.google.com/p/inxi/wiki/script_configuration_files
221 # override in user config if desired, seems like less than .3 doesn't work as reliably
222 CPU_SLEEP='0.3' 
223 FILTER_STRING='<filter>'
224
225 # for features like help/version will fit to terminal / console screen width. Console
226 # widths will be dynamically set in main() based on cols in term/console
227 COLS_MAX_CONSOLE='115'
228 COLS_MAX_IRC='105'
229 # note, this is console out of x/display server, will also be set dynamically
230 # not used currently, but maybe in future
231 COLS_MAX_NO_DISPLAY='140'
232 PS_COUNT=5
233 # change to less, or more if you have very slow connection
234 DL_TIMEOUT=8
235 ### END USER CONFIGS ###
236
237 ### LOCALIZATION - DO NOT CHANGE! ###
238 # set to default LANG to avoid locales errors with , or .
239 LANG=C
240 # Make sure every program speaks English.
241 LC_ALL="C"
242 export LC_ALL
243
244 ### ARRAYS ###
245 ## Prep
246 # Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
247 # type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
248 # therefore results in nothing.
249 shopt -u nullglob
250 ## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
251 # Backup the current Internal Field Separator
252 ORIGINAL_IFS="$IFS"
253
254 ## Initialize
255 A_ALSA_DATA=''
256 A_AUDIO_DATA=''
257 A_BATTERY_DATA=''
258 A_CMDL=''
259 A_CPU_CORE_DATA=''
260 A_CPU_DATA=''
261 A_CPU_TYPE_PCNT_CCNT=''
262 A_DEBUG_BUFFER=''
263 A_GCC_VERSIONS=''
264 A_GLX_DATA=''
265 A_GRAPHICS_CARD_DATA=''
266 A_GRAPHIC_DRIVERS=''
267 A_HDD_DATA=''
268 A_INIT_DATA=''
269 A_INTERFACES_DATA=''
270 A_MACHINE_DATA=''
271 A_MEMORY_DATA=''
272 A_NETWORK_DATA=''
273 A_OPTICAL_DRIVE_DATA=''
274 A_PARTITION_DATA=''
275 A_PCICONF_DATA=''
276 A_PS_DATA=''
277 A_RAID_DATA=''
278 A_SENSORS_DATA=''
279 A_UNMOUNTED_PARTITION_DATA=''
280 A_WEATHER_DATA=''
281 A_DISPLAY_SERVER_DATA=''
282
283 ### BOOLEANS ###
284 ## standard boolean flags ##
285 B_BSD_DISK_SET='false'
286 B_BSD_RAID='false'
287 B_COLOR_SCHEME_SET='false'
288 B_CONSOLE_IRC='false'
289 # triggers full display of cpu flags
290 B_CPU_FLAGS_FULL='false'
291 # test for dbus irc client
292 B_DBUS_CLIENT='false'
293 # kde dcop
294 B_DCOP='false'
295 # Debug flood override: make 'true' to allow long debug output
296 B_DEBUG_FLOOD='false'
297 # for special -i debugging cases
298 B_DEBUG_I='false'
299 B_DMIDECODE_SET='false'
300 # show extra output data
301 B_EXTRA_DATA='false'
302 # triggered by -xx
303 B_EXTRA_EXTRA_DATA='false'
304 B_FORCE_DMIDECODE='false'
305 B_ID_SET='false'
306 # override certain errors due to currupted data
307 B_HANDLE_CORRUPT_DATA='false'
308 B_LABEL_SET='false'
309 B_LSPCI='false'
310 B_LOG_COLORS='false'
311 B_LOG_FULL_DATA='false'
312 B_MAPPER_SET='false'
313 B_OUTPUT_FILTER='false'
314 B_OVERRIDE_FILTER='false'
315 B_PCICONF='false'
316 B_PCICONF_SET='false'
317 # kde qdbus
318 B_QDBUS='false'
319 B_PORTABLE='false'
320 B_RAID_SET='false'
321 B_ROOT='false'
322 B_RUN_COLOR_SELECTOR='false'
323 B_RUNNING_IN_DISPLAY='false' # in x type display server
324 if tty >/dev/null;then
325         B_IRC='false'
326 else
327         B_IRC='true'
328 fi
329 # this sets the debug buffer
330 B_SCRIPT_UP='false'
331 B_SHOW_ADVANCED_NETWORK='false'
332 # Show sound card data
333 B_SHOW_AUDIO='false'
334 B_SHOW_BASIC_RAID='false'
335 B_SHOW_BASIC_CPU='false'
336 B_SHOW_BASIC_DISK='false'
337 B_SHOW_BASIC_OPTICAL='false'
338 B_SHOW_BATTERY='false'
339 B_SHOW_BATTERY_FORCED='false'
340 B_SHOW_CPU='false'
341 B_SHOW_DISPLAY_DATA='false'
342 B_SHOW_DISK_TOTAL='false'
343 B_SHOW_DISK='false'
344 # Show full hard disk output
345 B_SHOW_FULL_HDD='false'
346 B_SHOW_FULL_OPTICAL='false'
347 B_SHOW_GRAPHICS='false'
348 # Set this to 'false' to avoid printing the hostname, can be set false now
349 B_SHOW_HOST='true'
350 B_SHOW_INFO='false'
351 B_SHOW_IP='false'
352 B_SHOW_LABELS='false'
353 B_SHOW_MACHINE='false'
354 B_SHOW_MEMORY='false'
355 B_SHOW_NETWORK='false'
356 # either -v > 3 or -P will show partitions
357 B_SHOW_PARTITIONS='false'
358 B_SHOW_PARTITIONS_FULL='false'
359 B_SHOW_PS_CPU_DATA='false'
360 B_SHOW_PS_MEM_DATA='false'
361 B_SHOW_RAID='false'
362 # because many systems have no mdstat file, -b/-F should not show error if no raid file found
363 B_SHOW_RAID_R='false' 
364 B_SHOW_REPOS='false'
365 B_SHOW_SENSORS='false'
366 # triggers only short inxi output
367 B_SHOW_SHORT_OUTPUT='false'
368 B_SHOW_SYSTEM='false'
369 B_SHOW_UNMOUNTED_PARTITIONS='false'
370 B_SHOW_UUIDS='false'
371 B_SHOW_WEATHER='false'
372 B_SYSCTL='false'
373 # triggers various debugging and new option testing
374 B_TESTING_1='false'
375 B_TESTING_2='false'
376 B_UPLOAD_DEBUG_DATA='false'
377 B_USB_NETWORKING='false'
378 # set to true here for debug logging from script start
379 B_USE_LOGGING='false'
380 B_UUID_SET='false'
381 B_XORG_LOG='false'
382
383 ## Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
384 B_ASOUND_DEVICE_FILE='false'
385 B_ASOUND_VERSION_FILE='false'
386 B_BASH_ARRAY='false'
387 B_CPUINFO_FILE='false'
388 B_DMESG_BOOT_FILE='false' # bsd only
389 B_LSB_FILE='false'
390 B_MDSTAT_FILE='false'
391 B_MEMINFO_FILE='false'
392 B_MODULES_FILE='false' #
393 B_MOUNTS_FILE='false'
394 B_OS_RELEASE_FILE='false' # new default distro id file? will this one work where lsb-release didn't?
395 B_PARTITIONS_FILE='false' #
396 B_PROC_DIR='false'
397 B_SCSI_FILE='false'
398
399 ## app tested for and present, to avoid repeat tests
400 B_FILE_TESTED='false'
401 B_HDDTEMP_TESTED='false'
402 B_MODINFO_TESTED='false'
403 B_SUDO_TESTED='false'
404
405 ### CONSTANTS/INITIALIZE - SOME MAY BE RESET LATER ###
406 DCOPOBJ="default"
407 DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels)
408 # Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up'
409 DEBUG_BUFFER_INDEX=0
410 ## note: the debugger rerouting to /dev/null has been moved to the end of the get_parameters function
411 ## so -@[number] debug levels can be set if there is a failure, otherwise you can't even see the errors
412 SED_I='-i' # for gnu sed, will be set to -i '' for bsd sed
413 SED_RX='-r' # for gnu sed, will be set to -E for bsd sed for backward compatibility
414
415 # default to false, no konversation found, 1 is native konvi (qt3/KDE3) script mode, 2 is /cmd inxi start,
416 ##      3 is Konversation > 1.2 (qt4/KDE4) 
417 KONVI=0
418 # NO_CPU_COUNT=0        # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
419 # This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
420 PARAMETER_LIMIT=30
421 SCHEME=0 # set default scheme - do not change this, it's set dynamically
422 # this is set in user prefs file, to override dynamic temp1/temp2 determination of sensors output in case
423 # cpu runs colder than mobo
424 SENSORS_CPU_NO=''
425 # SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
426 SHOW_IRC=2
427 # Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
428 VERBOSITY_LEVEL=0
429 # Supported number of verbosity levels, including 0
430 VERBOSITY_LEVELS=7
431
432 ### LOGGING ###
433 ## logging eval variables, start and end function: Insert to LOGFS LOGFE when debug level >= 8
434 LOGFS_STRING='log_function_data fs $FUNCNAME "$( echo $@ )"'
435 LOGFE_STRING='log_function_data fe $FUNCNAME'
436 LOGFS=''
437 LOGFE=''
438 # uncomment for debugging from script start
439 # LOGFS=$LOGFS_STRING
440 # LOGFE=$LOGFE_STRING
441
442 ### FILE NAMES/PATHS/URLS - must be non root writable ###
443 # File's used when present
444 FILE_ASOUND_DEVICE='/proc/asound/cards'
445 FILE_ASOUND_MODULES='/proc/asound/modules' # not used but maybe for -A?
446 FILE_ASOUND_VERSION='/proc/asound/version'
447 FILE_CPUINFO='/proc/cpuinfo'
448 FILE_DMESG_BOOT='/var/run/dmesg.boot'
449 FILE_LSB_RELEASE='/etc/lsb-release'
450 FILE_MDSTAT='/proc/mdstat'
451 FILE_MEMINFO='/proc/meminfo'
452 FILE_MODULES='/proc/modules'
453 FILE_MOUNTS='/proc/mounts'
454 FILE_OS_RELEASE='/etc/os-release'
455 FILE_PARTITIONS='/proc/partitions'
456 FILE_SCSI='/proc/scsi/scsi'
457 FILE_XORG_LOG='/var/log/Xorg.0.log' # if not found, search and replace with actual location
458
459 FILE_PATH=''
460 HDDTEMP_PATH=''
461 MODINFO_PATH=''
462 SUDO_PATH=''
463
464 SCRIPT_DATA_DIR="$HOME/.inxi"
465 ALTERNATE_FTP='' # for data uploads
466 ALTERNATE_WEATHER_LOCATION='' # weather alternate location
467 LOG_FILE="$SCRIPT_DATA_DIR/inxi.log"
468 LOG_FILE_1="$SCRIPT_DATA_DIR/inxi.1.log"
469 LOG_FILE_2="$SCRIPT_DATA_DIR/inxi.2.log"
470 MAN_FILE_DOWNLOAD='https://github.com/smxi/inxi/raw/master/inxi.1.gz'
471 MAN_FILE_LOCATION='/usr/share/man/man1'
472 SCRIPT_NAME='inxi'
473 SCRIPT_PATCH_NUMBER=''
474 SCRIPT_PATH='' #filled-in in Main
475 SCRIPT_VERSION_NUMBER=""        #filled-in in Main
476 SCRIPT_DOWNLOAD='https://github.com/smxi/inxi/raw/master/'
477 SCRIPT_DOWNLOAD_BRANCH_1='https://github.com/smxi/inxi/raw/one/'
478 SCRIPT_DOWNLOAD_BRANCH_2='https://github.com/smxi/inxi/raw/two/'
479 SCRIPT_DOWNLOAD_BRANCH_3='https://github.com/smxi/inxi/raw/three/'
480 SCRIPT_DOWNLOAD_BRANCH_4='https://github.com/smxi/inxi/raw/four/'
481 SCRIPT_DOWNLOAD_BRANCH_BSD='https://github.com/smxi/inxi/raw/bsd/'
482 SCRIPT_DOWNLOAD_BRANCH_GNUBSD='https://github.com/smxi/inxi/raw/gnubsd/'
483 SCRIPT_DOWNLOAD_DEV='http://smxi.org/test/'
484 # note, you can use any ip url here as long as it's the only line on the output page.
485 # Also the ip address must be the last thing on that line. If you abuse this ip tool 
486 # you will be banned from further access. Most > 24x daily automated queries to it are abuse.
487 WAN_IP_URL='http://smxi.org/opt/ip.php'
488 KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data)
489
490 ### INITIALIZE VARIABLES NULL ###
491 BSD_TYPE=''
492 BSD_VERSION=
493 CMDL_MAX=''
494
495 DEV_DISK_ID=''
496 DEV_DISK_LABEL=''
497 DEV_DISK_MAPPER=''
498 DEV_DISK_UUID=''
499 DMIDECODE_DATA=''
500 DNSTOOL=''
501 DOWNLOADER='wget'
502 IRC_CLIENT=''
503 IRC_CLIENT_VERSION=''
504 PS_THROTTLED=''
505 REPO_DATA=''
506
507 ### LAYOUT ###
508 # These two determine separators in single line output, to force irc clients not to break off sections
509 SEP1='~'
510 SEP2=' '
511 # these will assign a separator to non irc states. Important! Using ':' can trigger stupid emoticon
512 # behaviors in output on IRC, so do not use those.
513 SEP3_IRC=''
514 SEP3_CONSOLE=':'
515 SEP3='' # do not set, will be set dynamically
516 LINE1='---------------------------------------------------------------------------'
517 LINE2='- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
518
519 # Default indentation level. NOTE: actual indent is 1 greater to allow for spacing
520 INDENT=10
521
522 ### COLUMN WIDTHS ###
523 COLS_INNER='' ## for width minus INDENT
524 COLS_MAX=''
525
526 # these will be set dynamically in main()
527 TERM_COLUMNS=80
528 TERM_LINES=100
529
530 # Only for legacy user config files se we can test and convert the var name
531 LINE_MAX_CONSOLE=''
532 LINE_MAX_IRC=''
533
534 ### COLORS ###
535 # Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Use following variables in config 
536 # files to change defaults for each type, or global
537 # Same as runtime parameter.
538 DEFAULT_COLOR_SCHEME=2
539 ## color variables - set dynamically
540 COLOR_SCHEME=''
541 C1=''
542 C2=''
543 CN=''
544 ## Always leave these blank, these are only going to be set in inxi.conf files, that makes testing
545 ## for user changes easier after sourcing the files
546 ESC='\x1b'
547 GLOBAL_COLOR_SCHEME=''
548 IRC_COLOR_SCHEME=''
549 IRC_CONS_COLOR_SCHEME=''
550 IRC_X_TERM_COLOR_SCHEME=''
551 CONSOLE_COLOR_SCHEME=''
552 VIRT_TERM_COLOR_SCHEME=''
553
554 ## Output colors
555 # A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
556 unset EMPTY
557 #             DGREY   BLACK   RED     DRED    GREEN   DGREEN  YELLOW  DYELLOW
558 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"
559 IRC_COLORS="  \x0314  \x0301  \x0304  \x0305  \x0309  \x0303  \x0308  \x0307"
560 #                          BLUE    DBLUE   MAGENTA DMAGENTA CYAN   DCYAN   WHITE   GREY    NORMAL
561 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"
562 IRC_COLORS=" $IRC_COLORS    \x0312 \x0302  \x0313  \x0306  \x0311  \x0310  \x0300  \x0315  \x03"
563
564 #ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
565 A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL )
566
567 # See above for notes on EMPTY
568 ## note: group 1: 0, 1 are null/normal
569 ## Following: group 2: generic, light/dark or dark/light; group 3: dark on light; group 4 light on dark; 
570 # this is the count of the first two groups, starting at zero
571 SAFE_COLOR_COUNT=12
572 A_COLOR_SCHEMES=( 
573 EMPTY,EMPTY,EMPTY 
574 NORMAL,NORMAL,NORMAL 
575
576 BLUE,NORMAL,NORMAL
577 BLUE,RED,NORMAL 
578 CYAN,BLUE,NORMAL 
579 DCYAN,NORMAL,NORMAL
580 DCYAN,BLUE,NORMAL 
581 DGREEN,NORMAL,NORMAL 
582 DYELLOW,NORMAL,NORMAL 
583 GREEN,DGREEN,NORMAL 
584 GREEN,NORMAL,NORMAL 
585 MAGENTA,NORMAL,NORMAL
586 RED,NORMAL,NORMAL
587
588 BLACK,DGREY,NORMAL
589 DBLUE,DGREY,NORMAL 
590 DBLUE,DMAGENTA,NORMAL
591 DBLUE,DRED,NORMAL 
592 DBLUE,BLACK,NORMAL
593 DGREEN,DYELLOW,NORMAL 
594 DYELLOW,BLACK,NORMAL
595 DMAGENTA,BLACK,NORMAL
596 DCYAN,DBLUE,NORMAL
597
598 WHITE,GREY,NORMAL
599 GREY,WHITE,NORMAL
600 CYAN,GREY,NORMAL 
601 GREEN,WHITE,NORMAL 
602 GREEN,YELLOW,NORMAL 
603 YELLOW,WHITE,NORMAL 
604 MAGENTA,CYAN,NORMAL 
605 MAGENTA,YELLOW,NORMAL
606 RED,CYAN,NORMAL
607 RED,WHITE,NORMAL 
608 BLUE,WHITE,NORMAL
609
610 RED,BLUE,NORMAL 
611 RED,DBLUE,NORMAL
612 BLACK,BLUE,NORMAL
613 BLACK,DBLUE,NORMAL
614 NORMAL,BLUE,NORMAL
615 BLUE,MAGENTA,NORMAL
616 DBLUE,MAGENTA,NORMAL
617 BLACK,MAGENTA,NORMAL
618 MAGENTA,BLUE,NORMAL
619 MAGENTA,DBLUE,NORMAL
620 )
621
622 #echo ${#A_COLOR_SCHEMES[@]};exit
623
624 # WARNING: In the main part below (search for 'KONVI')
625 # there's a check for Konversation-specific config files.
626 # Any one of these can override the above if inxi is run
627 # from Konversation!
628
629 ## DISTRO DATA/ID ##
630 # In cases of derived distros where the version file of the base distro can also be found under /etc,
631 # the derived distro's version file should go first. (Such as with Sabayon / Gentoo)
632 DISTROS_DERIVED="antix-version aptosid-version kanotix-version knoppix-version mandrake-release pardus-release porteus-version sabayon-release siduction-version sidux-version slitaz-release solusos-release turbolinux-release zenwalk-version"
633 # debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
634 DISTROS_EXCLUDE_LIST="debian_version devuan_version ubuntu_version"
635 DISTROS_PRIMARY="arch-release gentoo-release redhat-release slackware-version SuSE-release"
636 DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
637 # this is being used both by core distros and derived distros now, eg, solusos 1 uses it for solusos id, while
638 # debian, solusos base, uses it as well, so we have to know which it is.
639 DISTROS_OS_RELEASE_GOOD="arch-release SuSE-release "
640 ## Distros with known problems
641 # DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
642 # Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
643
644 ## OUTPUT FILTERS/SEARCH ##
645 # Note that \<ltd\> bans only words, not parts of strings; in \<corp\> you can't use punctuation characters like . or ,
646 # we're saving about 10+% of the total script exec time by hand building the ban lists here, using hard quotes.
647
648 BAN_LIST_NORMAL='chipset|components|computing|computer|corporation|communications|electronics|electrical|electric|gmbh|group|incorporation|industrial|international|nee|revision|semiconductor|software|technologies|technology|ltd\.|\<ltd\>|inc\.|\<inc\>|intl\.|co\.|\<co\>|corp\.|\<corp\>|\(tm\)|\(r\)|®|\(rev ..\)'
649 BAN_LIST_CPU='@||cpu |cpu deca|dual core|dual-core|tri core|tri-core|quad core|quad-core|ennea|genuine|hepta|hexa|multi|octa|penta|processor|single|triple|[0-9\.]+ *[MmGg][Hh][Zz]'
650 # See github issue 75 for more details on value: *, triggers weird behaviors if present in value
651 # /sys/devices/virtual/dmi/id/product_name:['*']
652 # this is for bash arrays AND avoiding * in arrays: ( fred * greg ) expands to the contents of the directory
653 BAN_LIST_ARRAY=',|\*'
654
655 SENSORS_GPU_SEARCH='amdgpu|intel|radeon|nouveau'
656
657 ### USB networking search string data, because some brands can have other products than
658 ### wifi/nic cards, they need further identifiers, with wildcards.
659 ### putting the most common and likely first, then the less common, then some specifics
660 USB_NETWORK_SEARCH="Wi-Fi.*Adapter|Wireless.*Adapter|Ethernet.*Adapter|WLAN.*Adapter|Network.*Adapter|802\.11|Atheros|Atmel|D-Link.*Adapter|D-Link.*Wireless|Linksys|Netgea|Ralink|Realtek.*Network|Realtek.*Wireless|Realtek.*WLAN|Belkin.*Wireless|Belkin.*WLAN|Belkin.*Network"
661 USB_NETWORK_SEARCH="$USB_NETWORK_SEARCH|Actiontec.*Wireless|Actiontec.*Network|AirLink.*Wireless|Asus.*Network|Asus.*Wireless|Buffalo.*Wireless|Davicom|DWA-.*RangeBooster|DWA-.*Wireless|ENUWI-.*Wireless|LG.*Wi-Fi|Rosewill.*Wireless|RNX-.*Wireless|Samsung.*LinkStick|Samsung.*Wireless|Sony.*Wireless|TEW-.*Wireless|TP-Link.*Wireless|WG[0-9][0-9][0-9].*Wireless|WNA[0-9][0-9][0-9]|WNDA[0-9][0-9][0-9]|Zonet.*ZEW.*Wireless|54 Mbps" 
662 # then a few known hard to ID ones added 
663 # belkin=050d; d-link=07d1; netgear=0846; ralink=148f; realtek=0bda; 
664 USB_NETWORK_SEARCH="$USB_NETWORK_SEARCH|050d:935b|0bda:8189|0bda:8197"
665
666 ########################################################################
667 #### MAIN: Where it all begins
668 ########################################################################
669 main()
670 {
671         eval $LOGFS
672         
673         local color_scheme='' kde_config_app=''
674         # this will be used by all functions following
675         local Ps_aux_Data="$( ps aux )"
676
677         # This function just initializes variables
678         initialize_data
679         
680         # Source global config overrides, needs to be here because some things
681         # can be reset that were set in initialize, but check_required_apps needs
682         if [[ -s /etc/$SCRIPT_NAME.conf ]];then
683                 source /etc/$SCRIPT_NAME.conf
684         fi
685         # Source user config variables override /etc/inxi.conf variables
686         if [[ -s $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf ]];then
687                 source $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf
688         fi
689         set_display_width 'live' # can be reset with -y
690         
691         # echo SCHEME $SCHEME
692         # echo B_IRC $B_IRC
693         # echo sep3: $SEP3
694         # Check for dependencies BEFORE running ANYTHING else except above functions
695         # Not all distro's have these depends installed by default. Don't want to run
696         # this if the user is requesting to see this information in the first place
697         # Only continue if required apps tests ok
698         if [[ $1 != '--recommends' ]];then
699                 check_required_apps
700                 check_recommended_apps
701         fi
702
703         SCRIPT_VERSION_NUMBER=$( parse_version_data 'main' )
704         SCRIPT_PATCH_NUMBER=$( parse_version_data 'patch' )
705         
706         # previous source location, check for bugs
707
708         ## this needs to run before the KONVI stuff is set below
709         ## Konversation 1.2 apparently does not like the $PPID test in get_start_client
710         ## So far there is no known way to detect if qt4_konvi is the parent process
711         ## this method will infer qt4_konvi as parent
712         get_start_client
713
714         # note: this only works if it's run from inside konversation as a script builtin or something
715         # only do this if inxi has been started as a konversation script, otherwise bypass this 
716         #       KONVI=3 ## for testing puroses
717         if [[ $KONVI -eq 1 || $KONVI -eq 3 ]];then
718                 if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (ie 1.x < 1.2(qt3))    
719                         DCPORT="$1"
720                         DCSERVER="$2"
721                         DCTARGET="$3"
722                         shift 3
723                 elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
724                         DCSERVER="$1" ##dbus testing
725                         DCTARGET="$2" ##dbus testing
726                         shift 2
727                 fi
728                 # always have the current stable kde version tested first, 
729                 # then use fallbacks and future proofing
730                 if type -p kde4-config &>/dev/null;then
731                         kde_config_app='kde4-config'
732                 elif type -p kde5-config &>/dev/null;then
733                         kde_config_app='kde5-config'
734                 elif type -p kde-config &>/dev/null;then
735                         kde_config_app='kde-config'
736                 fi
737                 # The section below is on request of Argonel from the Konversation developer team:
738                 # it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf
739                 if [[ -n $kde_config_app ]];then
740                         IFS=":"
741                         for kde_config in $( $kde_config_app --path data )
742                         do
743                                 if [[ -r $kde_config$KONVI_CFG ]];then
744                                         source "$kde_config$KONVI_CFG"
745                                         break
746                                 fi
747                         done
748                         IFS="$ORIGINAL_IFS"
749                 fi
750         fi
751
752         ## leave this for debugging dcop stuff if we get that working
753         #       print_screen_output "DCPORT: $DCPORT"
754         #       print_screen_output "DCSERVER: $DCSERVER"
755         #       print_screen_output "DCTARGET: $DCTARGET"
756         
757         # first init function must be set first for colors etc. Remember, no debugger
758         # stuff works on this function unless you set the debugging flag manually.
759         # Debugging flag -@ [number] will not work until get_parameters runs.
760         
761         # "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
762         # must be here to allow debugger and other flags to be set.
763         get_parameters "$@"
764
765         # If no colorscheme was set in the parameter handling routine, then set the default scheme
766         if [[ $B_COLOR_SCHEME_SET != 'true' ]];then
767                 # This let's user pick their color scheme. For IRC, only shows the color schemes, no interactive
768                 # The override value only will be placed in user config files. /etc/inxi.conf can also override
769                 if [[ $B_RUN_COLOR_SELECTOR == 'true' ]];then 
770                         select_default_color_scheme
771                 else
772                         # set the default, then override as required
773                         color_scheme=$DEFAULT_COLOR_SCHEME
774                         if [[ -n $GLOBAL_COLOR_SCHEME ]];then
775                                 color_scheme=$GLOBAL_COLOR_SCHEME
776                         else
777                                 if [[ $B_IRC == 'false' ]];then
778                                         if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then
779                                                 color_scheme=$CONSOLE_COLOR_SCHEME
780                                         elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
781                                                 color_scheme=$VIRT_TERM_COLOR_SCHEME
782                                         fi
783                                 else
784                                         if [[ -n $IRC_X_TERM_COLOR_SCHEME && $B_CONSOLE_IRC == 'true' && -n $B_RUNNING_IN_DISPLAY ]];then
785                                                 color_scheme=$IRC_X_TERM_COLOR_SCHEME
786                                         elif [[ -n $IRC_CONS_COLOR_SCHEME && -z $DISPLAY ]];then
787                                                 color_scheme=$IRC_CONS_COLOR_SCHEME
788                                         elif [[ -n $IRC_COLOR_SCHEME ]];then
789                                                 color_scheme=$IRC_COLOR_SCHEME
790                                         fi
791                                 fi
792                         fi
793                         set_color_scheme $color_scheme
794                 fi
795         fi
796         if [[ $B_IRC == 'false' ]];then
797                 SEP3=$SEP3_CONSOLE
798         else
799                 # too hard to read if no colors, so force that for users on irc
800                 if [[ $SCHEME == 0 ]];then
801                         SEP3=$SEP3_CONSOLE
802                 else
803                         SEP3=$SEP3_IRC
804                 fi
805         fi
806         
807         # all the pre-start stuff is in place now
808         B_SCRIPT_UP='true'
809         script_debugger "Debugger: $SCRIPT_NAME is up and running..."
810         
811         # then create the output
812         print_it_out
813
814         eval $LOGFE
815         # weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
816         # from the last command is taken..
817         exit 0
818 }
819
820 #### -------------------------------------------------------------------
821 #### basic tests: set script data, booleans, PATH, version numbers
822 #### -------------------------------------------------------------------
823
824 # Set PATH data so we can access all programs as user. Set BAN lists.
825 # initialize some boleans, these directories are used throughout the script
826 # some apps are used for extended functions any directory used, should be
827 # checked here first.
828 # No args taken.
829 initialize_data()
830 {
831         eval $LOGFS
832         BSD_VERSION=$( uname -s 2>/dev/null | tr '[A-Z]' '[a-z]' )
833         # note: archbsd says they are a freebsd distro, so assuming it's the same as freebsd
834         if [[ -z ${BSD_VERSION/*bsd*/} || -z ${BSD_VERSION/*dragonfly*/} || -z ${BSD_VERSION/*darwin*/} ]];then
835                 if [[ -z ${BSD_VERSION/*openbsd*/} ]];then
836                         BSD_VERSION='openbsd'
837                 elif [[ -z ${BSD_VERSION/*darwin*/} ]];then
838                         BSD_VERSION='darwin'
839                 fi
840                 # GNU/kfreebsd will by definition have GNU tools like sed/grep
841                 if [[ -z ${BSD_VERSION/*kfreebsd*/} ]];then
842                         BSD_TYPE='debian-bsd' # debian gnu bsd
843                 else
844                         BSD_TYPE='bsd' # all other bsds
845                         SED_I="-i ''"
846                         SED_RX='-E'
847                         ESC=$(echo | tr '\n' '\033')
848                 fi
849         fi
850         # now set the script BOOLEANS for files required to run features
851         # note that freebsd has /proc but it's empty
852         if [[ -d "/proc/" && -z $BSD_TYPE ]];then
853                 B_PROC_DIR='true'
854         elif [[ -n $BSD_TYPE ]];then
855                 B_PROC_DIR='false'
856         else
857                 error_handler 6
858         fi
859         
860         initialize_paths
861         
862         if type -p dig &>/dev/null;then
863                 DNSTOOL='dig'
864         fi
865         
866         # set downloaders. 
867         if ! type -p wget &>/dev/null;then
868                 # first check for bsd stuff
869                 if type -p fetch &>/dev/null;then
870                         DOWNLOADER='fetch'
871                 elif type -p curl &>/dev/null;then
872                         DOWNLOADER='curl'
873                 elif [[ $BSD_VERSION == 'openbsd' && -n $( type -p ftp ) ]];then
874                         DOWNLOADER='ftp'
875                 else
876                         DOWNLOADER='no-downloader'
877                 fi
878         fi
879         
880         if [[ -n $BSD_TYPE ]];then
881                 if [[ -e $FILE_DMESG_BOOT ]];then
882                         B_DMESG_BOOT_FILE='true'
883                 fi
884         else
885                 # found a case of battery existing but having nothing in it on desktop mobo
886                 # not all laptops show the first. /proc/acpi/battery is deprecated.
887                 if [[ -n $( ls /proc/acpi/battery 2>/dev/null ) || -n $( ls /sys/class/power_supply/ 2>/dev/null )  ]];then
888                         B_PORTABLE='true'
889                 fi
890         fi
891         if [[ -e $FILE_CPUINFO ]]; then
892                 B_CPUINFO_FILE='true'
893         fi
894         if [[ -e $FILE_MEMINFO ]];then
895                 B_MEMINFO_FILE='true'
896         fi
897         if [[ -e $FILE_ASOUND_DEVICE ]];then
898                 B_ASOUND_DEVICE_FILE='true'
899         fi
900         if [[ -e $FILE_ASOUND_VERSION ]];then
901                 B_ASOUND_VERSION_FILE='true'
902         fi
903         if [[ -f $FILE_LSB_RELEASE ]];then
904                 B_LSB_FILE='true'
905         fi
906         if [[ -f $FILE_OS_RELEASE ]];then
907                 B_OS_RELEASE_FILE='true'
908         fi
909         if [[ -e $FILE_SCSI ]];then
910                 B_SCSI_FILE='true'
911         fi
912         if [[ -n $DISPLAY ]];then
913                 B_SHOW_DISPLAY_DATA='true'
914                 B_RUNNING_IN_DISPLAY='true'
915         fi
916         if [[ -e $FILE_MDSTAT ]];then
917                 B_MDSTAT_FILE='true'
918         fi
919         if [[ -e $FILE_MODULES ]];then
920                 B_MODULES_FILE='true'
921         fi
922         if [[ -e $FILE_MOUNTS ]];then
923                 B_MOUNTS_FILE='true'
924         fi
925         if [[ -e $FILE_PARTITIONS ]];then
926                 B_PARTITIONS_FILE='true'
927         fi
928         # default to the normal location, then search for it
929         if [[ -e $FILE_XORG_LOG ]];then
930                 B_XORG_LOG='true'
931         else
932                 # Detect location of the Xorg log file
933                 if type -p xset &>/dev/null; then
934                         FILE_XORG_LOG=$( xset q 2>/dev/null | grep -i 'Log file' | gawk '{print $3}')
935                         if [[ -e $FILE_XORG_LOG ]];then
936                                 B_XORG_LOG='true'
937                         fi
938                 fi
939         fi
940         # gfx output will require this flag
941         if [[ $( whoami ) == 'root' ]];then
942                 B_ROOT='true'
943         fi
944         eval $LOGFE
945 }
946
947 # args: $1 - default OR override default cols max integer count
948 set_display_width()
949 {
950         local cols_max_override=$1
951         
952         if [[ $cols_max_override == 'live' ]];then
953                 ## sometimes tput will trigger an error (mageia) if irc client
954                 if [[ $B_IRC == 'false' ]];then
955                         if type -p tput &>/dev/null;then
956                                 TERM_COLUMNS=$(tput cols)
957                                 TERM_LINES=$(tput lines)
958                         fi
959                         # double check, just in case it's missing functionality or whatever
960                         if [[ -z $TERM_COLUMNS || -n ${TERM_COLUMNS//[0-9]/} ]];then
961                                 TERM_COLUMNS=80
962                                 TERM_LINES=100
963                         fi
964                 fi
965                 # Convert to new variable names if set in config files, legacy test
966                 if [[ -n $LINE_MAX_CONSOLE ]];then
967                         COLS_MAX_CONSOLE=$LINE_MAX_CONSOLE
968                 fi
969                 if [[ -n $LINE_MAX_IRC ]];then
970                         COLS_MAX_IRC=$LINE_MAX_IRC
971                 fi
972                 # this lets you set different widths for in or out of display server
973         #       if [[ $B_RUNNING_IN_DISPLAY == 'false' && -n $COLS_MAX_NO_DISPLAY ]];then
974         #               COLS_MAX_CONSOLE=$COLS_MAX_NO_DISPLAY
975         #       fi
976                 # TERM_COLUMNS is set in top globals, using tput cols
977                 # echo tc: $TERM_COLUMNS cmc: $COLS_MAX_CONSOLE
978                 if [[ $TERM_COLUMNS -lt $COLS_MAX_CONSOLE ]];then
979                         COLS_MAX_CONSOLE=$TERM_COLUMNS
980                 fi
981                 # adjust, some terminals will wrap if output cols == term cols
982                 COLS_MAX_CONSOLE=$(( $COLS_MAX_CONSOLE - 2 ))
983                 # echo cmc: $COLS_MAX_CONSOLE
984                 # comes after source for user set stuff
985                 if [[ $B_IRC == 'false' ]];then
986                         COLS_MAX=$COLS_MAX_CONSOLE
987                 else
988                         COLS_MAX=$COLS_MAX_IRC
989                 fi
990         else
991                 COLS_MAX=$cols_max_override
992         fi
993         COLS_INNER=$(( $COLS_MAX - $INDENT - 1 ))
994         # echo cm: $COLS_MAX ci: $COLS_INNER
995 }
996
997 # arg: $1 - version number: main/patch/date
998 parse_version_data()
999 {
1000         local version_data=''
1001
1002         # note, using ####[[:space:]]+ to avoid having this function also trip the version datas
1003         case $1 in
1004                 date)
1005                         version_data=$( gawk -F ': ' '
1006                         /####[[:space:]]+Date:/ {
1007                                 print $NF
1008                         }' "$SCRIPT_PATH/$SCRIPT_NAME" )
1009                         ;;
1010                 main)
1011                         version_data=$( gawk '
1012                         /####[[:space:]]+Version:/ {
1013                                 print $3
1014                         }' "$SCRIPT_PATH/$SCRIPT_NAME" )
1015                         ;;
1016                 patch)
1017                         version_data=$( gawk '
1018                         /####[[:space:]]+Patch Number:/ {
1019                                 print $4
1020                         }' "$SCRIPT_PATH/$SCRIPT_NAME" )
1021                         ;;
1022         esac
1023         echo $version_data
1024 }
1025
1026 initialize_paths()
1027 {
1028         local path='' added_path='' b_path_found='' sys_path=''
1029         # Extra path variable to make execute failures less likely, merged below
1030         local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/local/bin"
1031         
1032         # this needs to be set here because various options call the parent initialize function directly.
1033         SCRIPT_PATH=$( dirname "$0" )
1034
1035         # Fallback paths put into $extra_paths; This might, among others, help on gentoo.
1036         # Now, create a difference of $PATH and $extra_paths and add that to $PATH:
1037         IFS=":"
1038         for path in $extra_paths
1039         do
1040                 b_path_found='false'
1041                 for sys_path in $PATH
1042                 do
1043                         if [[ $path == $sys_path ]];then
1044                                 b_path_found='true'
1045                         fi
1046                 done
1047                 if [[ $b_path_found == 'false' ]];then
1048                         added_path="$added_path:$path"
1049                 fi
1050         done
1051
1052         IFS="$ORIGINAL_IFS"
1053         PATH="$PATH$added_path"
1054         # echo "PATH='$PATH'"
1055         ##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
1056 }
1057 # No args taken.
1058 check_recommended_apps()
1059 {
1060         eval $LOGFS
1061         local bash_array_test=( "one" "two" )
1062
1063         # check for array ability of bash, this is only good for the warning at this time
1064         # the boolean could be used later
1065         # bash version 2.05b is used in DSL
1066         # bash version 3.0 is used in Puppy Linux; it has a known array bug <reference to be placed here>
1067         # versions older than 3.1 don't handle arrays
1068         # distro's using below 2.05b are unknown, released in 2002
1069         if [[ ${bash_array_test[1]} -eq "two" ]];then
1070                 B_BASH_ARRAY='true'
1071         else
1072                 script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output"
1073         fi
1074         # test for a few apps that bsds may not have after initial tests
1075         if type -p lspci &>/dev/null;then
1076                 B_LSPCI='true'
1077         fi
1078         if [[ -n $BSD_TYPE ]];then
1079                 if type -p sysctl &>/dev/null;then
1080                         B_SYSCTL='true'
1081                 fi
1082                 if type -p pciconf &>/dev/null;then
1083                         B_PCICONF='true'
1084                 fi
1085         fi
1086         # now setting qdbus/dcop for first run, some systems can have both by the way
1087         if type -p qdbus &>/dev/null;then
1088                 B_QDBUS='true'
1089         fi
1090         if type -p dcop &>/dev/null;then
1091                 B_DCOP='true'
1092         fi
1093         eval $LOGFE
1094 }
1095
1096 # Determine if any of the absolutely necessary tools are absent
1097 # No args taken.
1098 check_required_apps()
1099 {
1100         eval $LOGFS
1101         local app_name=''
1102         # bc removed from deps for now
1103         local depends="df gawk grep ps readlink tr uname wc"
1104         
1105         if [[ -z $BSD_TYPE  ]];then
1106                 depends="$depends lspci"
1107         elif [[ $BSD_TYPE == 'bsd' ]];then
1108                 depends="$depends sysctl"
1109                 # debian-bsd has lspci but you must be root to run it
1110         elif [[ $BSD_TYPE == 'debian-bsd' ]];then
1111                 depends="$depends sysctl lspci"
1112         fi
1113         # no need to add xprop because it will just give N/A if not there, but if we expand use of xprop,
1114         # should add that here as a test, then use the B_SHOW_DISPLAY_DATA flag to trigger the tests in de function
1115         local x_apps="xrandr xdpyinfo glxinfo" 
1116
1117         if [[ $B_RUNNING_IN_DISPLAY == 'true' ]];then
1118                 for app_name in $x_apps
1119                 do
1120                         if ! type -p $app_name &>/dev/null;then
1121                                 script_debugger "Resuming in non X mode: $app_name not found. For package install advice run: $SCRIPT_NAME --recommends"
1122                                 B_SHOW_DISPLAY_DATA='false'
1123                                 break
1124                         fi
1125                 done
1126         fi
1127
1128         app_name=''
1129
1130         for app_name in $depends
1131         do
1132                 if ! type -p $app_name &>/dev/null;then
1133                         error_handler 5 "$app_name"
1134                 fi
1135         done
1136         eval $LOGFE
1137 }
1138
1139 ## note: this is now running inside each gawk sequence directly to avoid exiting gawk
1140 ## looping in bash through arrays, then re-entering gawk to clean up, then writing back to array
1141 ## in bash. For now I'll leave this here because there's still some interesting stuff to get re methods
1142 # Enforce boilerplate and buzzword filters
1143 # args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
1144 sanitize_characters()
1145 {
1146         eval $LOGFS
1147         # Cannot use strong quotes to unquote a string with pipes in it!
1148         # bash will interpret the |'s as usual and try to run a subshell!
1149         # Using weak quotes instead, or use '"..."'
1150         echo "$2" | gawk "
1151         BEGIN {
1152                 IGNORECASE=1
1153         }
1154         {
1155                 gsub(/${!1}/,\"\")
1156                 gsub(/ [ ]+/,\" \")    ## ([ ]+) with (space)
1157                 gsub(/^ +| +$/,\"\")   ## (pipe char) with (nothing)
1158                 print                  ## prints (returns) cleaned input
1159         }"
1160         eval $LOGFE
1161 }
1162
1163 # Set the colorscheme
1164 # args: $1 = <scheme number>|<"none">
1165 set_color_scheme()
1166 {
1167         eval $LOGFS
1168         local i='' a_output_colors='' a_color_codes=''
1169
1170         if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then
1171                 set -- 1
1172         fi
1173         # Set a global variable to allow checking for chosen scheme later
1174         SCHEME="$1"
1175         if [[ $B_IRC == 'false' ]];then
1176                 a_color_codes=( $ANSI_COLORS )
1177         else
1178                 a_color_codes=( $IRC_COLORS )
1179         fi
1180         for (( i=0; i < ${#A_COLORS_AVAILABLE[@]}; i++ ))
1181         do
1182                 eval "${A_COLORS_AVAILABLE[i]}=\"${a_color_codes[i]}\""
1183         done
1184         IFS=","
1185         a_output_colors=( ${A_COLOR_SCHEMES[$1]} )
1186         IFS="$ORIGINAL_IFS"
1187         # then assign the colors globally
1188         C1="${!a_output_colors[0]}"
1189         C2="${!a_output_colors[1]}"
1190         CN="${!a_output_colors[2]}"
1191         # ((COLOR_SCHEME++)) ## note: why is this? ##
1192         # handle some explicit colors that are used for no color 0
1193         if [[ $SCHEME -eq 0 ]];then
1194                 NORMAL=''
1195                 RED=''
1196         fi
1197         eval $LOGFE
1198 }
1199
1200 select_default_color_scheme()
1201 {
1202         eval $LOGFS
1203         local spacer='  ' options='' user_selection='' config_variable=''
1204         local config_file="$HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf"
1205         local irc_clear="\e[0m" 
1206         local irc_gui='Unset' irc_console='Unset' irc_x_term='Unset'
1207         local console='Unset' virt_term='Unset' global='Unset' 
1208         
1209         if [[ -n $IRC_COLOR_SCHEME ]];then
1210                 irc_gui="Set: $IRC_COLOR_SCHEME"
1211         fi
1212         if [[ -n $IRC_CONS_COLOR_SCHEME ]];then
1213                 irc_console="Set: $IRC_CONS_COLOR_SCHEME"
1214         fi
1215         if [[ -n $IRC_X_TERM_COLOR_SCHEME ]];then
1216                 irc_x_term="Set: $IRC_X_TERM_COLOR_SCHEME"
1217         fi
1218         if [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
1219                 virt_term="Set: $VIRT_TERM_COLOR_SCHEME"
1220         fi
1221         if [[ -n $CONSOLE_COLOR_SCHEME ]];then
1222                 console="Set: $CONSOLE_COLOR_SCHEME"
1223         fi
1224         if [[ -n $GLOBAL_COLOR_SCHEME ]];then
1225                 global="Set: $GLOBAL_COLOR_SCHEME"
1226         fi
1227         
1228         # don't want these printing in irc since they show literally
1229         if [[ $B_IRC == 'true' ]];then
1230                 irc_clear=''
1231         fi
1232         # first make output neutral so it's just plain default for console client
1233         set_color_scheme "0"
1234         # print_lines_basic "0" "" ""
1235         if [[ $B_IRC == 'false' ]];then
1236                 print_lines_basic "0" "" "Welcome to $SCRIPT_NAME! Please select the default $COLOR_SELECTION color scheme."
1237                 # print_screen_output "You will see this message only one time per user account, unless you set preferences in: /etc/$SCRIPT_NAME.conf"
1238                 print_screen_output " "
1239         fi
1240         print_lines_basic "0" "" "Because there is no way to know your $COLOR_SELECTION foreground/background colors, you can set your color preferences from color scheme option list below. 0 is no colors, 1 neutral. After these, there are 4 sets: 1-dark or light backgrounds; 2-light backgrounds; 3-dark backgrounds; 4-miscellaneous."
1241         if [[ $B_IRC == 'false' ]];then
1242                 print_lines_basic "0" "" "Please note that this will set the $COLOR_SELECTION preferences only for user: $(whoami)"
1243         fi
1244         print_screen_output "$LINE1"
1245         for (( i=0; i < ${#A_COLOR_SCHEMES[@]}; i++ ))
1246         do
1247                 if [[ $i -gt 9 ]];then
1248                         spacer=' '
1249                 fi
1250                 # only offer the safe universal defaults
1251                 case $COLOR_SELECTION in
1252                         global|irc|irc-console|irc-virtual-terminal)
1253                                 if [[ $i -gt $SAFE_COLOR_COUNT ]];then
1254                                         break
1255                                 fi
1256                                 ;;
1257                 esac
1258                 set_color_scheme $i
1259                 print_screen_output "$irc_clear $i)$spacer${C1}Card:${C2} nVidia G86 [GeForce 8400 GS] ${C1}X.Org${C2} 1.7.7"
1260         done
1261         set_color_scheme 0
1262         
1263         if [[ $B_IRC == 'false' ]];then
1264                 echo -n "\e[0m"
1265                 
1266                 print_screen_output "$irc_clear $i)${spacer}Remove all color settings. Restore $SCRIPT_NAME default."
1267                 print_screen_output "$irc_clear $(($i+1)))${spacer}Continue, no changes or config file setting."
1268                 print_screen_output "$irc_clear $(($i+2)))${spacer}Exit, use another terminal, or set manually."
1269                 print_screen_output "$LINE1"
1270                 print_lines_basic "0" "" "Simply type the number for the color scheme that looks best to your eyes for your $COLOR_SELECTION settings and hit ENTER. NOTE: You can bring this option list up by starting $SCRIPT_NAME with option: -c plus one of these numbers:"
1271                 print_lines_basic "0" "" "94^(console,^no X^-^$console); 95^(terminal,^X^-^$virt_term); 96^(irc,^gui,^X^-^$irc_gui); 97^(irc,^X,^in^terminal^-^$irc_x_term); 98^(irc,^no^X^-^$irc_console); 99^(global^-^$global)"
1272                 print_lines_basic "0" "" ""
1273                 print_screen_output "Your selection(s) will be stored here: $config_file"
1274                 print_lines_basic "0" "" "Global overrides all individual color schemes. Individual schemes remove the global setting."
1275                 print_screen_output "$LINE1"
1276                 read user_selection
1277                 if [[ "$user_selection" =~ ^([0-9]+)$ && $user_selection -lt $i ]];then
1278                         case $COLOR_SELECTION in
1279                                 irc)
1280                                         config_variable='IRC_COLOR_SCHEME'
1281                                         ;;
1282                                 irc-console)
1283                                         config_variable='IRC_CONS_COLOR_SCHEME'
1284                                         ;;
1285                                 irc-virtual-terminal)
1286                                         config_variable='IRC_X_TERM_COLOR_SCHEME'
1287                                         ;;
1288                                 console)
1289                                         config_variable='CONSOLE_COLOR_SCHEME'
1290                                         ;;
1291                                 virtual-terminal)
1292                                         config_variable='VIRT_TERM_COLOR_SCHEME'
1293                                         ;;
1294                                 global)
1295                                         config_variable='GLOBAL_COLOR_SCHEME'
1296                                         ;;
1297                         esac
1298                         set_color_scheme $user_selection
1299                         # make file/directory first if missing
1300                         if [[ ! -f $config_file ]];then
1301                                 if [[ ! -d $HOME/.$SCRIPT_NAME ]];then
1302                                         mkdir $HOME/.$SCRIPT_NAME
1303                                 fi
1304                                 touch $config_file
1305                         fi
1306                         if [[ -z $( grep -s "$config_variable=" $config_file ) ]];then
1307                                 print_lines_basic "0" "" "Creating and updating config file for $COLOR_SELECTION color scheme now..."
1308                                 echo "$config_variable=$user_selection" >> $config_file
1309                         else
1310                                 print_screen_output "Updating config file for $COLOR_SELECTION color scheme now..."
1311                                 sed $SED_I "s/$config_variable=.*/$config_variable=$user_selection/" $config_file
1312                         fi
1313                         # file exists now so we can go on to cleanup
1314                         case $COLOR_SELECTION in
1315                                 irc|irc-console|irc-virtual-terminal|console|virtual-terminal)
1316                                         sed $SED_I '/GLOBAL_COLOR_SCHEME=/d' $config_file
1317                                         ;;
1318                                 global)
1319                                         sed $SED_I -e '/VIRT_TERM_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' -e '/IRC_COLOR_SCHEME=/d' \
1320                                         -e '/IRC_CONS_COLOR_SCHEME=/d' -e '/IRC_X_TERM_COLOR_SCHEME=/d' $config_file
1321                                         ;;
1322                         esac
1323                 elif [[ $user_selection == $i ]];then
1324                         print_screen_output "Removing all color settings from config file now..."
1325                         sed $SED_I -e '/VIRT_TERM_COLOR_SCHEME=/d' -e '/GLOBAL_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' \
1326                         -e '/IRC_COLOR_SCHEME=/d' -e '/IRC_CONS_COLOR_SCHEME=/d' -e '/IRC_X_TERM_COLOR_SCHEME=/d' $config_file
1327                         set_color_scheme $DEFAULT_COLOR_SCHEME
1328                 elif [[ $user_selection == $(( $i+1 )) ]];then
1329                         print_lines_basic "0" "" "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 95 to 99"
1330                         if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then
1331                                 set_color_scheme $CONSOLE_COLOR_SCHEME
1332                         elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
1333                                 set_color_scheme $VIRT_TERM_COLOR_SCHEME
1334                         else
1335                                 set_color_scheme $DEFAULT_COLOR_SCHEME
1336                         fi
1337                 elif [[ $user_selection == $(( $i+2 )) ]];then
1338                         set_color_scheme $DEFAULT_COLOR_SCHEME
1339                         print_screen_output "Ok, exiting $SCRIPT_NAME now. You can set the colors later."
1340                         exit 0
1341                 else
1342                         print_screen_output "Error - Invalid Selection. You entered this: $user_selection"
1343                         print_screen_output " "
1344                         select_default_color_scheme
1345                 fi
1346         else
1347                 print_screen_output "$LINE1"
1348                 print_lines_basic "0" "" "After finding the scheme number you like, simply run this again in a terminal to set the configuration data file for your irc client. You can set color schemes for the following: start inxi with -c plus:"
1349                 print_screen_output "94 (console, no X - $console); 95 (terminal, X - $virt_term); 96 (irc, gui, X - $irc_gui);"
1350                 print_screen_output "97 (irc, X, in terminal - $irc_x_term); 98 (irc, no X - $irc_console); 99 (global - $global)"
1351                 exit 0
1352         fi
1353
1354         eval $LOGFE
1355 }
1356
1357 ########################################################################
1358 #### UTILITY FUNCTIONS
1359 ########################################################################
1360
1361 #### -------------------------------------------------------------------
1362 #### error handler, debugger, script updater
1363 #### -------------------------------------------------------------------
1364
1365 # Error handling
1366 # args: $1 - error number; $2 - optional, extra information; $3 - optional extra info
1367 error_handler()
1368 {
1369         eval $LOGFS
1370         local error_message=''
1371
1372         # assemble the error message
1373         case $1 in
1374                 2)      error_message="large flood danger, debug buffer full!"
1375                         ;;
1376                 3)      error_message="unsupported color scheme number: $2"
1377                         ;;
1378                 4)      error_message="unsupported verbosity level: $2"
1379                         ;;
1380                 5)      error_message="dependency not met: $2 not found in path.\nFor distribution installation package names and missing apps information, run: $SCRIPT_NAME --recommends"
1381                         ;;
1382                 6)      error_message="/proc not found! Quitting..."
1383                         ;;
1384                 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"
1385                         ;;
1386                 8)      error_message="the self-updater failed, $DOWNLOADER 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"
1387                         ;;
1388                 9)      error_message="unsupported debugging level: $2"
1389                         ;;
1390                 10)
1391                         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/"
1392                         ;;
1393                 11)
1394                         error_message="unsupported testing option argument: -! $2"
1395                         ;;
1396                 12)
1397                         error_message="the git 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 https://github.com/smxi/inxi\nto verify the branch status."
1398                         ;;
1399                 13)
1400                         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"
1401                         ;;
1402                 14)
1403                         error_message="failed to write correctly downloaded $SCRIPT_NAME to location $SCRIPT_PATH.\nThis usually means you don't have permission to write to that location, maybe you need to be root?\nThe operation failed with error: $2"
1404                         ;;
1405                 15)
1406                         error_message="failed set execute permissions on $SCRIPT_NAME at location $SCRIPT_PATH.\nThis usually means you don't have permission to set permissions on files there, maybe you need to be root?\nThe operation failed with error: $2"
1407                         ;;
1408                 16)
1409                         error_message="$SCRIPT_NAME downloaded but the file data is corrupted. Purged data and using current version."
1410                         ;;
1411                 17)
1412                         error_message="All $SCRIPT_NAME self updater features have been disabled by the distribution\npackage maintainer. This includes the option you used: $2"
1413                         ;;
1414                 18)
1415                         error_message="The argument you provided for $2 does not have supported syntax.\nPlease use the following formatting:\n$3"
1416                         ;;
1417                 19)
1418                         error_message="The option $2 has been deprecated. Please use $3 instead.\nSee -h for instructions and syntax."
1419                         ;;
1420                 20)
1421                         error_message="The option you selected has been deprecated. $2\nSee the -h (help) menu for currently supported options."
1422                         ;;
1423                 21)
1424                         error_message="Width option requires an integer value of 80 or more.\nYou entered: $2"
1425                         ;;
1426                 *)      error_message="error unknown: $@"
1427                         set -- 99
1428                         ;;
1429         esac
1430         # then print it and exit
1431         print_screen_output "Error $1: $error_message"
1432         eval $LOGFE
1433         exit $1
1434 }
1435
1436 # prior to script up set, pack the data into an array
1437 # then we'll print it out later.
1438 # args: $1 - $@ debugging string text
1439 script_debugger()
1440 {
1441         eval $LOGFS
1442         if [[ $B_SCRIPT_UP == 'true' ]];then
1443                 # only return if debugger is off and no pre start up errors have occured
1444                 if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
1445                         return 0
1446                 # print out the stored debugging information if errors occured
1447                 elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
1448                         for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
1449                         do
1450                                 print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
1451                         done
1452                         DEBUG_BUFFER_INDEX=0
1453                 fi
1454                 # or print out normal debugger messages if debugger is on
1455                 if [[ $DEBUG -gt 0 ]];then
1456                         print_screen_output "$1"
1457                 fi
1458         else
1459                 if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
1460                         error_handler 2
1461                 # this case stores the data for later printout, will print out only
1462                 # at B_SCRIPT_UP == 'true' if array index > 0
1463                 else
1464                         A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
1465                         # increment count for next pre script up debugging error
1466                         (( DEBUG_BUFFER_INDEX++ ))
1467                 fi
1468         fi
1469         eval $LOGFE
1470 }
1471
1472 # NOTE: no logging available until get_parameters is run, since that's what sets logging
1473 # in order to trigger earlier logging manually set B_USE_LOGGING to true in top variables.
1474 # $1 alone: logs data; $2 with or without $3 logs func start/end.
1475 # $1 type (fs/fe/cat/raw) or logged data; [$2 is $FUNCNAME; [$3 - function args]]
1476 log_function_data()
1477 {
1478         if [ "$B_USE_LOGGING" == 'true' ];then
1479                 local logged_data='' spacer='   ' line='----------------------------------------'
1480                 case $1 in
1481                         fs)
1482                                 logged_data="Function: $2 - Primary: Start"
1483                                 if [ -n "$3" ];then
1484                                         logged_data="$logged_data\n${spacer}Args: $3"
1485                                 fi
1486                                 spacer=''
1487                                 ;;
1488                         fe)
1489                                 logged_data="Function: $2 - Primary: End"
1490                                 spacer=''
1491                                 ;;
1492                         cat)
1493                                 if [[ $B_LOG_FULL_DATA == 'true' ]];then
1494                                         for cat_file in $2
1495                                         do
1496                                                 logged_data="$logged_data\n$line\nFull file data: cat $cat_file\n\n$( cat $cat_file )\n$line\n"
1497                                         done
1498                                         spacer=''
1499                                 fi
1500                                 ;;
1501                         raw)
1502                                 if [[ $B_LOG_FULL_DATA == 'true' ]];then
1503                                         logged_data="\n$line\nRaw system data:\n\n$2\n$line\n"
1504                                         spacer=''
1505                                 fi
1506                                 ;;
1507                         *)
1508                                 logged_data="$1"
1509                                 ;;
1510                 esac
1511                 # Create any required line breaks and strip out escape color code, either ansi (case 1)or irc (case 2).
1512                 # This pattern doesn't work for irc colors, if we need that someone can figure it out
1513                 if [[ -n $logged_data ]];then
1514                         if [[ $B_LOG_COLORS != 'true' ]];then
1515                                 echo -e "${spacer}$logged_data" | sed $SED_RX 's/\x1b\[[0-9]{1,2}(;[0-9]{1,2}){0,2}m//g' >> $LOG_FILE
1516                         else
1517                                 echo -e "${spacer}$logged_data" >> $LOG_FILE
1518                         fi
1519                 fi
1520         fi
1521 }
1522
1523 # called in the initial -@ 10 script args setting so we can get logging as soon as possible
1524 # will have max 3 files, inxi.log, inxi.1.log, inxi.2.log
1525 create_rotate_logfiles()
1526 {
1527         if [[ ! -d $SCRIPT_DATA_DIR ]];then
1528                 mkdir $SCRIPT_DATA_DIR
1529         fi
1530         # do the rotation if logfile exists
1531         if [[ -f $LOG_FILE ]];then
1532                 # copy if present second to third
1533                 if [[ -f $LOG_FILE_1 ]];then
1534                         mv -f $LOG_FILE_1 $LOG_FILE_2
1535                 fi
1536                 # then copy initial to second
1537                 mv -f $LOG_FILE $LOG_FILE_1
1538         fi
1539         # now create the logfile
1540         touch $LOG_FILE
1541         # and echo the start data
1542         echo "=========================================================" >> $LOG_FILE
1543         echo "START $SCRIPT_NAME LOGGING:"                               >> $LOG_FILE
1544         echo "Script started: $( date +%Y-%m-%d-%H:%M:%S )"              >> $LOG_FILE
1545         echo "=========================================================" >> $LOG_FILE
1546 }
1547
1548 # args: $1 - download url, not including file name; $2 - string to print out
1549 # $3 - update type option
1550 # note that $1 must end in / to properly construct the url path
1551 script_self_updater()
1552 {
1553         eval $LOGFS
1554         local downloader_error=0 file_contents='' downloader_man_error=0 
1555         local man_file_path="$MAN_FILE_LOCATION/inxi.1.gz"
1556         
1557         if [[ $B_IRC == 'true' ]];then
1558                 print_screen_output "Sorry, you can't run the $SCRIPT_NAME self updater option (-$3) in an IRC client."
1559                 exit 1
1560         fi
1561
1562         print_screen_output "Starting $SCRIPT_NAME self updater."
1563         print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER"
1564         print_screen_output "Current version patch number: $SCRIPT_PATCH_NUMBER"
1565         print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..."
1566         case $DOWNLOADER in
1567                 curl)
1568                         file_contents="$( curl -s $1$SCRIPT_NAME )" || downloader_error=$?
1569                         ;;
1570                 fetch)
1571                         file_contents="$( fetch -q -o - $1$SCRIPT_NAME )" || downloader_error=$?
1572                         ;;
1573                 ftp)
1574                         file_contents="$( ftp -o - $1$SCRIPT_NAME 2>/dev/null )" || downloader_error=$?
1575                         ;;
1576                 wget)
1577                         file_contents="$( wget -q -O - $1$SCRIPT_NAME )" || downloader_error=$?
1578                         ;;
1579                 no-downloader)
1580                         downloader_error=1
1581                         ;;
1582         esac
1583
1584         # then do the actual download
1585         if [[  $downloader_error -eq 0 ]];then
1586                 # make sure the whole file got downloaded and is in the variable
1587                 if [[ -n $( grep '###\*\*EOF\*\*###' <<< "$file_contents" ) ]];then
1588                         echo "$file_contents" > $SCRIPT_PATH/$SCRIPT_NAME || error_handler 14 "$?"
1589                         chmod +x $SCRIPT_PATH/$SCRIPT_NAME || error_handler 15 "$?"
1590                         SCRIPT_VERSION_NUMBER=$( parse_version_data 'main' )
1591                         SCRIPT_PATCH_NUMBER=$( parse_version_data 'patch' )
1592                         print_screen_output "Successfully updated to $2 version: $SCRIPT_VERSION_NUMBER"
1593                         print_screen_output "New $2 version patch number: $SCRIPT_PATCH_NUMBER"
1594                         print_screen_output "To run the new version, just start $SCRIPT_NAME again."
1595                         print_screen_output "----------------------------------------"
1596                         print_screen_output "Starting download of man page file now."
1597                         if [[ ! -d $MAN_FILE_LOCATION ]];then
1598                                 print_screen_output "The required man directory was not detected on your system, unable to continue: $MAN_FILE_LOCATION"
1599                         else
1600                                 if [[ $B_ROOT == 'true' ]];then
1601                                         print_screen_output "Checking Man page download URL..."
1602                                         if [[ -f /usr/share/man/man8/inxi.8.gz ]];then
1603                                                 print_screen_output "Updating man page location to man1."
1604                                                 mv -f /usr/share/man/man8/inxi.8.gz /usr/share/man/man1/inxi.1.gz 
1605                                                 if type -p mandb &>/dev/null;then
1606                                                         exec $( type -p mandb ) -q 
1607                                                 fi
1608                                         fi
1609                                         if [[ $DOWNLOADER == 'wget' ]];then
1610                                                 wget -q --spider $MAN_FILE_DOWNLOAD || downloader_man_error=$?
1611                                         fi
1612                                         if [[ $downloader_man_error -eq 0 ]];then
1613                                                 if [[ $DOWNLOADER == 'wget' ]];then
1614                                                         print_screen_output "Man file download URL verified: $MAN_FILE_DOWNLOAD"
1615                                                 fi
1616                                                 print_screen_output "Downloading Man page file now."
1617                                                 case $DOWNLOADER in
1618                                                         curl)
1619                                                                 curl -s -o $man_file_path $MAN_FILE_DOWNLOAD || downloader_man_error=$?
1620                                                                 ;;
1621                                                         fetch)
1622                                                                 fetch -q -o $man_file_path $MAN_FILE_DOWNLOAD || downloader_man_error=$?
1623                                                                 ;;
1624                                                         ftp)
1625                                                                 ftp -o $man_file_path $MAN_FILE_DOWNLOAD 2>/dev/null || downloader_man_error=$?
1626                                                                 ;;
1627                                                         wget)
1628                                                                 wget -q -O $man_file_path $MAN_FILE_DOWNLOAD || downloader_man_error=$?
1629                                                                 ;;
1630                                                         no-downloader)
1631                                                                 downloader_man_error=1
1632                                                                 ;;
1633                                                 esac
1634                                                 if [[ $downloader_man_error -gt 0 ]];then
1635                                                         print_screen_output "Oh no! Something went wrong downloading the Man gz file at: $MAN_FILE_DOWNLOAD"
1636                                                         print_screen_output "Check the error messages for what happened. Error: $downloader_man_error"
1637                                                 else
1638                                                         print_screen_output "Download/install of man page successful. Check to make sure it works: man inxi"
1639                                                 fi
1640                                         else
1641                                                 print_screen_output "Man file download URL failed, unable to continue: $MAN_FILE_DOWNLOAD"
1642                                         fi
1643                                 else
1644                                         print_screen_output "Updating / Installing the Man page requires root user, writing to: $MAN_FILE_LOCATION"
1645                                         print_screen_output "If you want the man page, you'll have to run $SCRIPT_NAME -$3 as root."
1646                                 fi
1647                         fi
1648                         exit 0
1649                 else
1650                         error_handler 16
1651                 fi
1652         # now run the error handlers on any wget failure
1653         else
1654                 if [[ $2 == 'svn server' ]];then
1655                         error_handler 8 "$downloader_error"
1656                 elif [[ $2 == 'alt server' ]];then
1657                         error_handler 10 "$1"
1658                 else
1659                         error_handler 12 "$1"
1660                 fi
1661         fi
1662         eval $LOGFS
1663 }
1664
1665 # args: $1 - debug data type: sys|xorg|disk
1666 debug_data_collector()
1667 {
1668         local xiin_app='' xiin_data_file='' xiin_download='' error='' b_run_xiin='false'
1669         local debug_data_dir='' bsd_string='' xorg_d_files='' xorg_file='' a_distro_ids=''
1670         local completed_gz_file='' xiin_file='xiin.py' ftp_upload='ftp.techpatterns.com/incoming'
1671         local xiin_url="https://github.com/smxi/inxi/raw/xiin/$xiin_file"
1672         local Line='-------------------------' root_string=''
1673         local start_directory=$( pwd )
1674         local host=$( tr '[A-Z]' '[a-z]' <<< "$HOSTNAME" )
1675         local downloader_error=0 debug_i=''
1676         
1677         if [[ $B_DEBUG_I == 'true' ]];then
1678                 debug_i='i'
1679         fi
1680         
1681         if [[ -n $host ]];then
1682                 host=${host// /-}
1683         else
1684                 host="-no-host"
1685         fi
1686         if [[ -n $BSD_TYPE ]];then
1687                 bsd_string="-$BSD_TYPE-$BSD_VERSION"
1688         fi
1689         if [[ $( whoami ) == 'root' ]];then
1690                 root_string='-root'
1691         fi
1692         
1693         debug_data_dir="inxi$bsd_string-$host-$(date +%Y%m%d-%H%M%S)-$1$root_string" 
1694         
1695         if [[ $B_IRC == 'false' ]];then
1696                 if [[ -n $ALTERNATE_FTP ]];then
1697                         ftp_upload=$ALTERNATE_FTP
1698                 fi
1699                 echo "Starting debugging data collection type: $1"
1700                 echo -n "Checking/creating required directories... "
1701                 if [[ ! -d $SCRIPT_DATA_DIR ]];then
1702                         mkdir $SCRIPT_DATA_DIR
1703                 fi
1704                 echo 'completed'
1705                 cd $SCRIPT_DATA_DIR
1706                 if [[ -d $SCRIPT_DATA_DIR/$debug_data_dir ]];then
1707                         echo 'Deleting previous xiin data directory...'
1708                         rm -rf $SCRIPT_DATA_DIR/$debug_data_dir
1709                 fi
1710                 mkdir $SCRIPT_DATA_DIR/$debug_data_dir
1711                 if [[ -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz ]];then
1712                         echo 'Deleting previous tar.gz file...'
1713                         rm -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz
1714                 fi
1715                 
1716                 echo 'Collecting system info: sensors, lsusb, lspci, lspci -v data, plus /proc data'
1717                 echo 'also checking for dmidecode data: note, you must be root to have dmidecode work.'
1718                 echo "Data going into: $SCRIPT_DATA_DIR/$debug_data_dir"
1719                 # bsd tools http://cb.vu/unixtoolbox.xhtml
1720                 # freebsd
1721                 if type -p pciconf &>/dev/null;then
1722                         pciconf -l -cv &> $debug_data_dir/bsd-pciconf-cvl.txt
1723                         pciconf -vl &> $debug_data_dir/bsd-pciconf-vl.txt
1724                         pciconf -l &> $debug_data_dir/bsd-pciconf-l.txt
1725                 else
1726                         touch $debug_data_dir/bsd-pciconf-absent
1727                 fi
1728                 # openbsd
1729                 if type -p pcidump &>/dev/null;then
1730                         pcidump &> $debug_data_dir/bsd-pcidump-openbsd.txt
1731                         pcidump -v &> $debug_data_dir/bsd-pcidump-v-openbsd.txt
1732                 else
1733                         touch $debug_data_dir/bsd-pcidump-openbsd-absent
1734                 fi
1735                 # netbsd
1736                 if type -p pcictl &>/dev/null;then
1737                         pcictl list &> $debug_data_dir/bsd-pcictl-list-netbsd.txt
1738                         pcictl list -n &> $debug_data_dir/bsd-pcictl-list-n-netbsd.txt
1739                 else
1740                         touch $debug_data_dir/bsd-pcictl-netbsd-absent
1741                 fi
1742                 if type -p sysctl &>/dev/null;then
1743                         sysctl -a &> $debug_data_dir/bsd-sysctl-a.txt
1744                 else
1745                         touch $debug_data_dir/bsd-sysctl-absent
1746                 fi
1747                 if type -p usbdevs &>/dev/null;then
1748                         usbdevs -v  &> $debug_data_dir/bsd-usbdevs-v.txt
1749                 else
1750                         touch $debug_data_dir/bsd-usbdevs-absent
1751                 fi
1752                 if type -p kldstat &>/dev/null;then
1753                         kldstat  &> $debug_data_dir/bsd-kldstat.txt
1754                 else
1755                         touch $debug_data_dir/bsd-kldstat-absent
1756                 fi
1757                 # diskinfo -v <disk>
1758                 # fdisk <disk>
1759                 dmidecode &> $debug_data_dir/dmidecode.txt
1760                 
1761                 get_repo_data "$SCRIPT_DATA_DIR/$debug_data_dir"
1762                 
1763                 if type -p shopt &>/dev/null;then
1764                         shopt -s nullglob
1765                         a_distro_ids=(/etc/*[-_]{release,version})
1766                         shopt -u nullglob
1767                         echo ${a_distro_ids[@]} &> $debug_data_dir/etc-distro-files.txt
1768                         for distro_file in ${a_distro_ids[@]} /etc/issue
1769                         do
1770                                 if [[ -f $distro_file ]];then
1771                                         cat $distro_file &> $debug_data_dir/distro-file${distro_file//\//-}
1772                                 fi
1773                         done
1774                 fi
1775                 dmesg &> $debug_data_dir/dmesg.txt
1776                 lscpu &> $debug_data_dir/lscpu.txt
1777                 lspci &> $debug_data_dir/lspci.txt
1778                 lspci -k &> $debug_data_dir/lspci-k.txt
1779                 lspci -knn &> $debug_data_dir/lspci-knn.txt
1780                 lspci -n &> $debug_data_dir/lspci-n.txt
1781                 lspci -nn &> $debug_data_dir/lspci-nn.txt
1782                 lspci -mm &> $debug_data_dir/lspci-mm.txt
1783                 lspci -mmnn &> $debug_data_dir/lspci-mmnn.txt
1784                 lspci -mmnnv &> $debug_data_dir/lspci-mmnnv.txt
1785                 lspci -v &> $debug_data_dir/lspci-v.txt
1786                 lsusb &> $debug_data_dir/lsusb.txt
1787                 if type -p hciconfig &>/dev/null;then
1788                         hciconfig -a &> $debug_data_dir/hciconfig-a.txt
1789                 else
1790                         touch $debug_data_dir/hciconfig-absent
1791                 fi
1792                 ls /sys &> $debug_data_dir/ls-sys.txt
1793                 ps aux &> $debug_data_dir/ps-aux.txt
1794                 ps -e &> $debug_data_dir/ps-e.txt
1795                 ps -p 1 &> $debug_data_dir/ps-p-1.txt
1796                 cat /proc/1/comm &> $debug_data_dir/proc-1-comm.txt
1797                 runlevel &> $debug_data_dir/runlevel.txt
1798                 if type -p rc-status &>/dev/null;then
1799                         rc-status -a &> $debug_data_dir/rc-status-a.txt
1800                         rc-status -l &> $debug_data_dir/rc-status-l.txt
1801                         rc-status -r &> $debug_data_dir/rc-status-r.txt
1802                 else
1803                         touch $debug_data_dir/rc-status-absent
1804                 fi
1805                 if type -p systemctl &>/dev/null;then
1806                         systemctl list-units &> $debug_data_dir/systemctl-list-units.txt
1807                         systemctl list-units --type=target &> $debug_data_dir/systemctl-list-units-target.txt
1808                 else
1809                         touch $debug_data_dir/systemctl-absent
1810                 fi
1811                 if type -p initctl &>/dev/null;then
1812                         initctl list &> $debug_data_dir/initctl-list.txt
1813                 else
1814                         touch $debug_data_dir/initctl-absent
1815                 fi
1816                 sensors &> $debug_data_dir/sensors.txt
1817                 if type -p strings &>/dev/null;then
1818                         touch $debug_data_dir/strings-present
1819                 else
1820                         touch $debug_data_dir/strings-absent
1821                 fi
1822                 local id_dir='/sys/class/power_supply/' 
1823                 local ids=$( ls $id_dir 2>/dev/null )
1824                 if [[ -n $ids ]];then
1825                         for batid in $ids 
1826                         do
1827                                 cat $id_dir$batid'/uevent' &> $debug_data_dir/sys-power-supply-$batid.txt
1828                         done
1829                 else
1830                         touch $debug_data_dir/sys-power-supply-none
1831                 fi
1832                 
1833                 # leaving this commented out to remind that some systems do not
1834                 # support strings --version, but will just simply hang at that command
1835                 # which you can duplicate by simply typing: strings then hitting enter, you will get hang.
1836                 # strings --version  &> $debug_data_dir/strings.txt
1837                 if type -p nvidia-smi &>/dev/null;then
1838                         nvidia-smi -q &> $debug_data_dir/nvidia-smi-q.txt
1839                         nvidia-smi -q -x &> $debug_data_dir/nvidia-smi-xq.txt
1840                 else
1841                         touch $debug_data_dir/nvidia-smi-absent
1842                 fi
1843                 head -n 1 /proc/asound/card*/codec* &> $debug_data_dir/proc-asound-card-codec.txt
1844                 if [[ -f /proc/version ]];then
1845                         cat /proc/version &> $debug_data_dir/proc-version.txt
1846                 else
1847                         touch $debug_data_dir/proc-version-absent
1848                 fi
1849                 echo $CC &> $debug_data_dir/cc-content.txt
1850                 ls /usr/bin/gcc* &> $debug_data_dir/gcc-sys-versions.txt
1851                 if type -p gcc &>/dev/null;then
1852                         gcc --version &> $debug_data_dir/gcc-version.txt
1853                 else
1854                         touch $debug_data_dir/gcc-absent
1855                 fi
1856                 if type -p clang &>/dev/null;then
1857                         clang --version &> $debug_data_dir/clang-version.txt
1858                 else
1859                         touch $debug_data_dir/clang-absent
1860                 fi
1861                 cat /etc/src.conf &> $debug_data_dir/bsd-etc-src-conf.txt
1862                 cat /etc/make.conf &> $debug_data_dir/bsd-etc-make-conf.txt
1863                 cat /etc/issue &> $debug_data_dir/etc-issue.txt
1864                 cat $FILE_LSB_RELEASE &> $debug_data_dir/lsb-release.txt
1865                 cat $FILE_OS_RELEASE &> $debug_data_dir/os-release.txt
1866                 cat $FILE_ASOUND_DEVICE &> $debug_data_dir/proc-asound-device.txt
1867                 cat $FILE_ASOUND_VERSION &> $debug_data_dir/proc-asound-version.txt
1868                 cat $FILE_CPUINFO &> $debug_data_dir/proc-cpu-info.txt
1869                 cat $FILE_MEMINFO &> $debug_data_dir/proc-meminfo.txt
1870                 cat $FILE_MODULES &> $debug_data_dir/proc-modules.txt
1871                 cat /proc/net/arp &> $debug_data_dir/proc-net-arp.txt 
1872                 # bsd data
1873                 cat /var/run/dmesg.boot &> $debug_data_dir/bsd-var-run-dmesg.boot.txt 
1874                 echo $COLS_INNER &> $debug_data_dir/cols-inner.txt
1875                 
1876                 check_recommends_user_output &> $debug_data_dir/check-recommends-user-output.txt
1877                 # first download and verify xiin
1878                 if [[ $B_UPLOAD_DEBUG_DATA == 'true' || $1 == 'disk' || $1 == 'sys' || $1 == 'all' ]];then
1879                         touch $SCRIPT_DATA_DIR/$debug_data_dir/xiin-error.txt
1880                         echo "Downloading required tree traverse tool $xiin_file..."
1881                         if [[ -f xiin && ! -f $xiin_file ]];then
1882                                 mv -f xiin $xiin_file
1883                         fi
1884                         # -Nc is creating really weird download anomolies, so using -O instead
1885                         case $DOWNLOADER in
1886                                 curl)
1887                                         xiin_download="$( curl -s $xiin_url )" || downloader_error=$?
1888                                         ;;
1889                                 fetch)
1890                                         xiin_download="$( fetch -q -o - $xiin_url )" || downloader_error=$?
1891                                         ;;
1892                                 ftp)
1893                                         xiin_download="$( ftp -o - $xiin_url 2>/dev/null )" || downloader_error=$?
1894                                         ;;
1895                                 wget)
1896                                         xiin_download="$( wget -q -O - $xiin_url )" || downloader_error=$?
1897                                         ;;
1898                                 no-downloader)
1899                                         downloader_error=1
1900                                         ;;
1901                         esac
1902                         # if nothing got downloaded kick out error, otherwise we'll use an older version
1903                         if [[ $downloader_error -gt 0 && ! -f $xiin_file ]];then
1904                                 echo -e "ERROR: Failed to download required file: $xiin_file\nMaybe the remote site is down or your networking is broken?"
1905                                 echo "Continuing with incomplete data collection."
1906                                 echo "$xiin_file download failed and no existing $xiin_file" >> $debug_data_dir/xiin-error.txt
1907                         elif [[ -n $( grep -s '# EOF' <<< "$xiin_download" ) || -f $xiin_file ]];then
1908                                 if [[ -n $( grep -s '# EOF' <<< "$xiin_download" ) ]];then
1909                                         echo "Updating $xiin_file from remote location"
1910                                         echo "$xiin_download" > $xiin_file
1911                                 else
1912                                         echo "Using local $xiin_file due to download failure"
1913                                 fi
1914                                 b_run_xiin='true'
1915                         else
1916                                 echo -e "ERROR: $xiin_file downloaded but the program file data is corrupted.\nContinuing with incomplete data collection."
1917                                 echo "$xiin_file downloaded but the program file data is corrupted." >> $debug_data_dir/xiin-error.txt
1918                         fi
1919                 fi
1920                 # note, only bash 4> supports ;;& for case, so using if/then here
1921                 if [[ $1 == 'disk' || $1 == 'sys' || $1 == 'all' ]];then
1922                         xiin_data_file=$SCRIPT_DATA_DIR/$debug_data_dir/xiin-sys.txt
1923                         echo 'Collecting networking data...'
1924                         ifconfig &> $debug_data_dir/ifconfig.txt
1925                         ip addr &> $debug_data_dir/ip-addr.txt
1926                         if [[ $b_run_xiin == 'true' && -z $BSD_TYPE ]];then
1927                                 echo $Line
1928                                 echo "Running $xiin_file tool now on /sys..."
1929                                 echo "Using Python version:" && python --version
1930                                 python --version &> $debug_data_dir/python-version.txt
1931                                 python ./$xiin_file -d /sys -f $xiin_data_file
1932                                 if [[ $? -ne 0 ]];then
1933                                         error=$?
1934                                         echo -e "ERROR: $xiin_file exited with error $error - removing data file.\nContinuing with incomplete data collection."
1935                                         echo "Continuing with incomplete data collection."
1936                                         rm -f $xiin_data_file
1937                                         echo "$xiin_file data generation failed with python error $error" >> $debug_data_dir/xiin-error.txt
1938                                 fi
1939                                 echo $Line
1940                         fi
1941                 fi
1942                 if [[ $1 == 'xorg' || $1 == 'all' ]];then
1943                         if [[ $B_RUNNING_IN_DISPLAY != 'true' ]];then
1944                                 echo 'Warning: only some of the data collection can occur if you are not in X'
1945                                 touch $debug_data_dir/warning-user-not-in-x
1946                         fi
1947                         if [[ $B_ROOT == 'true' ]];then
1948                                 echo 'Warning: only some of the data collection can occur if you are running as Root user'
1949                                 touch $debug_data_dir/warning-root-user
1950                         fi
1951                         echo 'Collecting Xorg log and xorg.conf files'
1952                         if [[ -e $FILE_XORG_LOG ]];then
1953                                 cat $FILE_XORG_LOG &> $debug_data_dir/xorg-log-file.txt
1954                         else
1955                                 touch $debug_data_dir/xorg-log-file-absent
1956                         fi
1957                         if [[ -e /etc/X11/xorg.conf ]];then
1958                                 cat /etc/X11/xorg.conf &> $debug_data_dir/xorg-conf.txt
1959                         else
1960                                 touch $debug_data_dir/xorg-conf-file-absent
1961                         fi
1962                         if [[ -n $( ls /etc/X11/xorg.conf.d/ 2>/dev/null ) ]];then
1963                                 ls /etc/X11/xorg.conf.d &> $debug_data_dir/ls-etc-x11-xorg-conf-d.txt
1964                                 xorg_d_files=$(ls /etc/X11/xorg.conf.d)
1965                                 for xorg_file in $xorg_d_files
1966                                 do
1967                                         cat /etc/X11/xorg.conf.d/$xorg_file &> $debug_data_dir/xorg-conf-d-$xorg_file.txt
1968                                 done
1969                         else
1970                                 touch $debug_data_dir/xorg-conf-d-files-absent
1971                         fi
1972                         echo 'Collecting X, xprop, glxinfo, xrandr, xdpyinfo data, wayland, weston...'
1973                         if type -p weston-info &>/dev/null; then
1974                                 weston-info &> $debug_data_dir/weston-info.txt
1975                         else
1976                                 touch $debug_data_dir/weston-info-absent
1977                         fi
1978                         if type -p weston &>/dev/null; then
1979                                 weston --version &> $debug_data_dir/weston-version.txt
1980                         else
1981                                 touch $debug_data_dir/weston-absent
1982                         fi
1983                         if type -p xprop &>/dev/null; then
1984                                 xprop -root &> $debug_data_dir/xprop_root.txt
1985                         else
1986                                 touch $debug_data_dir/xprop-absent
1987                         fi
1988                         if type -p xprop &>/dev/null; then
1989                                 glxinfo &> $debug_data_dir/glxinfo.txt
1990                         else
1991                                 touch $debug_data_dir/glxinfo-absent
1992                         fi
1993                         if type -p xdpyinfo &>/dev/null; then
1994                                 xdpyinfo &> $debug_data_dir/xdpyinfo.txt
1995                         else
1996                                 touch $debug_data_dir/xdpyinfo-absent
1997                         fi
1998                         if type -p xrandr &>/dev/null; then
1999                                 xrandr &> $debug_data_dir/xrandr.txt
2000                         else
2001                                 touch $debug_data_dir/xrandr-absent
2002                         fi
2003                         if type -p X &>/dev/null; then
2004                                 X -version &> $debug_data_dir/x-version.txt
2005                         else
2006                                 touch $debug_data_dir/x-absent
2007                         fi
2008                         if type -p Xorg &>/dev/null; then
2009                                 Xorg -version &> $debug_data_dir/xorg-version.txt
2010                         else
2011                                 touch $debug_data_dir/xorg-absent
2012                         fi
2013                         
2014                         echo $GNOME_DESKTOP_SESSION_ID &> $debug_data_dir/gnome-desktop-session-id.txt
2015                         # kde 3 id
2016                         echo $KDE_FULL_SESSION &> $debug_data_dir/kde3-full-session.txt
2017                         echo $KDE_SESSION_VERSION &> $debug_data_dir/kde-gte-4-session-version.txt
2018                         if type -p kf5-config &>/dev/null; then
2019                                 kf5-config --version &> $debug_data_dir/kde-kf5-config-version-data.txt
2020                         elif type -p kf6-config &>/dev/null; then
2021                                 kf6-config --version &> $debug_data_dir/kde-kf6-config-version-data.txt
2022                         elif type -p kf$KDE_SESSION_VERSION-config &>/dev/null; then
2023                                 kf$KDE_SESSION_VERSION-config --version &> $debug_data_dir/kde-kf$KDE_SESSION_VERSION-KSV-config-version-data.txt
2024                         else
2025                                 touch $debug_data_dir/kde-kf-config-absent
2026                         fi
2027                         if type -p plasmashell &>/dev/null; then
2028                                 plasmashell --version &> $debug_data_dir/kde-plasmashell-version-data.txt
2029                         else
2030                                 touch $debug_data_dir/kde-plasmashell-absent
2031                         fi
2032                         if type -p kwin_x11 &>/dev/null; then
2033                                 kwin_x11 --version &> $debug_data_dir/kde-kwin_x11-version-data.txt
2034                         else
2035                                 touch $debug_data_dir/kde-kwin_x11-absent
2036                         fi
2037                         if type -p kded4 &>/dev/null; then
2038                                 kded4 --version &> $debug_data_dir/kded4-version-data.txt
2039                         elif type -p kded5 &>/dev/null; then
2040                                 kded5 --version &> $debug_data_dir/kded5-version-data.txt
2041                         elif type -p kded &>/dev/null; then
2042                                 kded --version &> $debug_data_dir/kded-version-data.txt
2043                         else
2044                                 touch $debug_data_dir/kded-$KDE_SESSION_VERSION-absent
2045                         fi
2046                         # kde 5/plasma desktop 5, this is maybe an extra package and won't be used
2047                         if type -p about-distro &>/dev/null; then
2048                                 about-distro &> $debug_data_dir/kde-about-distro.txt
2049                         else
2050                                 touch $debug_data_dir/kde-about-distro-absent
2051                         fi
2052                         echo $XDG_CURRENT_DESKTOP &> $debug_data_dir/xdg-current-desktop.txt
2053                 fi
2054                 if [[ $1 == 'disk' || $1 == 'all' ]];then
2055                         echo 'Collecting dev, label, disk, uuid data, df...'
2056                         ls -l /dev &> $debug_data_dir/dev-data.txt
2057                         ls -l /dev/disk &> $debug_data_dir/dev-disk-data.txt
2058                         ls -l /dev/disk/by-id &> $debug_data_dir/dev-disk-id-data.txt
2059                         ls -l /dev/disk/by-label &> $debug_data_dir/dev-disk-label-data.txt
2060                         ls -l /dev/disk/by-uuid &> $debug_data_dir/dev-disk-uuid-data.txt
2061                         # http://comments.gmane.org/gmane.linux.file-systems.zfs.user/2032
2062                         ls -l /dev/disk/by-wwn &> $debug_data_dir/dev-disk-wwn-data.txt
2063                         ls -l /dev/disk/by-path &> $debug_data_dir/dev-disk-path-data.txt
2064                         ls -l /dev/mapper &> $debug_data_dir/dev-disk-mapper-data.txt
2065                         readlink /dev/root &> $debug_data_dir/dev-root.txt
2066                         df -h -T -P --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 --exclude-type=devfs --exclude-type=linprocfs --exclude-type=sysfs --exclude-type=fdescfs &> $debug_data_dir/df-h-T-P-excludes.txt
2067                         df -T -P --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 --exclude-type=devfs --exclude-type=linprocfs --exclude-type=sysfs --exclude-type=fdescfs &> $debug_data_dir/df-T-P-excludes.txt
2068                         df -T -P --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 --exclude-type=devfs --exclude-type=linprocfs --exclude-type=sysfs --exclude-type=fdescfs --total &> $debug_data_dir/df-T-P-excludes-total.txt
2069                         df -h -T &> $debug_data_dir/bsd-df-h-T-no-excludes.txt
2070                         df -h &> $debug_data_dir/bsd-df-h-no-excludes.txt
2071                         df -k -T &> $debug_data_dir/bsd-df-k-T-no-excludes.txt
2072                         df -k &> $debug_data_dir/bsd-df-k-no-excludes.txt
2073                         atacontrol list &> $debug_data_dir/bsd-atacontrol-list.txt
2074                         camcontrol devlist &> $debug_data_dir/bsd-camcontrol-devlist.txt
2075                         # bsd tool
2076                         mount &> $debug_data_dir/mount.txt
2077                         btrfs filesystem show  &> $debug_data_dir/btrfs-filesystem-show.txt
2078                         btrfs filesystem show --mounted  &> $debug_data_dir/btrfs-filesystem-show-mounted.txt
2079                         # btrfs filesystem show --all-devices  &> $debug_data_dir/btrfs-filesystem-show-all-devices.txt
2080                         gpart list &> $debug_data_dir/bsd-gpart-list.txt
2081                         gpart show &> $debug_data_dir/bsd-gpart-show.txt
2082                         gpart status &> $debug_data_dir/bsd-gpart-status.txt
2083                         swapctl -l -k &> $debug_data_dir/bsd-swapctl-l-k.txt
2084                         swapon -s &> $debug_data_dir/swapon-s.txt
2085                         sysctl -b kern.geom.conftxt &> $debug_data_dir/bsd-sysctl-b-kern.geom.conftxt.txt
2086                         sysctl -b kern.geom.confxml &> $debug_data_dir/bsd-sysctl-b-kern.geom.confxml.txt
2087                         zfs list &> $debug_data_dir/bsd-zfs-list.txt
2088                         zpool list &> $debug_data_dir/bsd-zpool-list.txt
2089                         zpool list -v &> $debug_data_dir/bsd-zpool-list-v.txt
2090                         df -P --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 &> $debug_data_dir/df-P-excludes.txt
2091                         df -P &> $debug_data_dir/bsd-df-P-no-excludes.txt
2092                         cat /proc/mdstat &> $debug_data_dir/proc-mdstat.txt
2093                         cat $FILE_PARTITIONS &> $debug_data_dir/proc-partitions.txt
2094                         cat $FILE_SCSI &> $debug_data_dir/proc-scsi.txt
2095                         cat $FILE_MOUNTS &> $debug_data_dir/proc-mounts.txt
2096                         cat /proc/sys/dev/cdrom/info &> $debug_data_dir/proc-cdrom-info.txt
2097                         ls /proc/ide/ &> $debug_data_dir/proc-ide.txt
2098                         cat /proc/ide/*/* &> $debug_data_dir/proc-ide-hdx-cat.txt
2099                         cat /etc/fstab &> $debug_data_dir/etc-fstab.txt
2100                         cat /etc/mtab &> $debug_data_dir/etc-mtab.txt
2101                 fi
2102                 echo 'Creating inxi output file now. This can take a few seconds...'
2103                 echo "Starting $SCRIPT_NAME from: $start_directory"
2104                 cd $start_directory
2105                 $SCRIPT_PATH/$SCRIPT_NAME -F${debug_i}Rfrploudmxxx -c 0 -@ 8 -y 120 > $SCRIPT_DATA_DIR/$debug_data_dir/inxi-F${debug_i}Rfrploudmxxxy120.txt
2106                 cp $LOG_FILE $SCRIPT_DATA_DIR/$debug_data_dir
2107                 if [[ -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz ]];then
2108                         echo "Found and removing previous tar.gz data file: $debug_data_dir.tar.gz"
2109                         rm -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz
2110                 fi
2111                 cd $SCRIPT_DATA_DIR
2112                 echo 'Creating tar.gz compressed file of this material now. Contents:'
2113                 echo $Line
2114                 tar -cvzf $debug_data_dir.tar.gz $debug_data_dir
2115                 echo $Line
2116                 echo 'Cleaning up leftovers...'
2117                 rm -rf $debug_data_dir
2118                 echo 'Testing gzip file integrity...'
2119                 gzip -t $debug_data_dir.tar.gz
2120                 if [[ $? -gt 0 ]];then
2121                         echo 'Data in gz is corrupted, removing gzip file, try running data collector again.'
2122                         rm -f $debug_data_dir.tar.gz
2123                         echo "Data in gz is corrupted, removed gzip file" >> $debug_data_dir/gzip-error.txt
2124                 else
2125                         echo 'All done, you can find your data gzipped directory here:'
2126                         completed_gz_file=$SCRIPT_DATA_DIR/$debug_data_dir.tar.gz
2127                         echo $completed_gz_file
2128                         if [[ $B_UPLOAD_DEBUG_DATA == 'true' ]];then
2129                                 echo $Line
2130                                 if [[ $b_run_xiin == 'true' ]];then
2131                                         echo "Running automatic upload of data to remote server $ftp_upload now..."
2132                                         python ./$xiin_file --version
2133                                         python ./$xiin_file -u $completed_gz_file $ftp_upload
2134                                         if [[ $? -gt 0 ]];then
2135                                                 echo $Line
2136                                                 echo "Error: looks like the ftp upload failed. Error number: $?"
2137                                                 echo "The ftp upload failed. Error number: $?" >> $debug_data_dir/xiin-error.txt
2138                                         fi
2139                                 else
2140                                         echo 'Unable to run the automoatic ftp upload because of an error with the xiin download.'
2141                                         echo "Unable to run the automoatic ftp upload because of an error with the xiin download" >> $debug_data_dir/xiin-error.txt
2142                                 fi
2143                         else
2144                                 echo 'You can upload this here using most file managers: ftp.techpatterns.com/incoming'
2145                                 echo 'then let a maintainer know it is uploaded.'
2146                         fi
2147                 fi
2148         else
2149                 echo 'This feature only available in console or shell client! Exiting now.'
2150         fi
2151         exit 0
2152 }
2153
2154 check_recommends_user_output()
2155 {
2156         local Line=$LINE1
2157         local gawk_version='N/A' sed_version='N/A' sudo_version='N/A' python_version='N/A'
2158         local downloaders_bsd=''
2159         
2160         if [[ $B_IRC == 'true' ]];then
2161                 print_screen_output "Sorry, you can't run this option in an IRC client."
2162                 exit 1
2163         fi
2164         if [[ -n $BSD_TYPE ]];then
2165                 downloaders_bsd='
2166                 fetch:BSD-only~BSD-only~BSD-only~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(BSDs)
2167                 ftp:ftp-OpenBSD-only~ftp-OpenBSD-only~ftp-OpenBSD-only~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(OpenBSD_only)'
2168         fi
2169         initialize_paths
2170         print_lines_basic "0" "" "$SCRIPT_NAME will now begin checking for the programs it needs to operate. First a check of the main languages and tools $SCRIPT_NAME uses. Python is only for debugging data collection."
2171         echo $Line
2172         echo "Bash version: $( bash --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU bash/ {print $4}' )"
2173         if type -p gawk &>/dev/null;then
2174                 gawk_version=$( gawk --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU Awk/ {print $3}' )
2175         fi
2176         if type -p sed &>/dev/null;then
2177                 sed_version=$( sed --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU sed version/ {print $4}' )
2178                 if [[ -z $sed_version ]];then
2179                         # note: bsd sed shows error with --version flag
2180                         sed_version=$( sed --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^sed: illegal option/ {print "BSD sed"}' )
2181                 fi
2182         fi
2183         if type -p sudo &>/dev/null;then
2184                 sudo_version=$( sudo -V 2>&1 | awk 'BEGIN {IGNORECASE=1} /^Sudo version/ {print $3}' )
2185         fi
2186         if type -p python &>/dev/null;then
2187                 python_version=$( python --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^Python/ {print $2}' )
2188         fi
2189         echo "Gawk version: $gawk_version"
2190         echo "Sed version: $sed_version"
2191         echo "Sudo version: $sudo_version"
2192         echo "Python version: $python_version"
2193         echo $Line
2194         
2195         echo "Test One: Required System Directories (Linux Only)."
2196         print_lines_basic "0" "" "If one of these system directories is missing, $SCRIPT_NAME cannot operate:"
2197         echo 
2198         check_recommends_items 'required-dirs'
2199         
2200         echo "Test Two: Required Core Applications."
2201         print_lines_basic "0" "" "If one of these applications is missing, $SCRIPT_NAME cannot operate:"
2202         echo 
2203         check_recommends_items 'required-apps'
2204         
2205         print_lines_basic "0" "" "Test Three: Script Recommends for Graphics Features."
2206         print_lines_basic "0" "" "NOTE: If you do not use X these do not matter (like a headless server). Otherwise, if one of these applications is missing, $SCRIPT_NAME will have incomplete output:"
2207         echo 
2208         check_recommends_items 'recommended-x-apps'
2209         
2210         echo 'Test Four: Script Recommends for Remaining Features.' 
2211         print_lines_basic "0" "" "If one of these applications is missing, $SCRIPT_NAME will have incomplete output:"
2212         echo 
2213         check_recommends_items 'recommended-apps'
2214         
2215         echo 'Test Five: Script Recommends for Remaining Features.' 
2216         print_lines_basic "0" "" "One of these downloaders needed for options -i/-w/-W (-U/-! [11-15], if supported):"
2217         echo 
2218         check_recommends_items 'downloaders'
2219         
2220         echo 'Test Six: System Directories for Various Information.'
2221         echo '(Unless otherwise noted, these are for GNU/Linux systems)' 
2222         print_lines_basic "0" "" "If one of these directories is missing, $SCRIPT_NAME may have incomplete output:"
2223         echo 
2224         check_recommends_items 'system-dirs'
2225         
2226         echo 'Test Seven: System Files for Various Information.'
2227         echo '(Unless otherwise noted, these are for GNU/Linux systems)' 
2228         print_lines_basic "0" "" "If one of these files is missing, $SCRIPT_NAME may have incomplete output:"
2229         echo 
2230         check_recommends_items 'system-files'
2231         
2232         echo 'All tests completed.' 
2233 }
2234 # args: $1 - check item
2235 check_recommends_items()
2236 {
2237         local item='' item_list='' item_string='' missing_items='' missing_string=''
2238         local package='' application='' feature='' type='' starter='' finisher=''
2239         local package_deb='' package_pacman='' package_rpm='' 
2240         local print_string='' separator='' width=56
2241         local required_dirs='/proc /sys'
2242         # package-owner: 1 - debian/ubuntu; 2 - arch; 3 - yum/rpm
2243         # pardus: pisi sf -q /usr/bin/package
2244         local required_apps='
2245         df:coreutils~coreutils~coreutils~:partition_data 
2246         gawk:gawk~gawk~gawk~:core_tool
2247         grep:grep~grep~grep~:string_search 
2248         lspci:pciutils~pciutils~pciutils~:hardware_data 
2249         ps:procps~procps~procps~:process_data 
2250         readlink:coreutils~coreutils~coreutils~: 
2251         sed:sed~sed~sed~:string_replace 
2252         tr:coreutils~coreutils~coreutils~:character_replace 
2253         uname:uname~coreutils~coreutils~:kernel_data 
2254         wc:coreutils~coreutils~coreutils~:word_character_count
2255         '
2256         local x_recommends='
2257         glxinfo:mesa-utils~mesa-demos~glx-utils_(openSUSE_12.3_and_later_Mesa-demo-x)~:-G_glx_info 
2258         xdpyinfo:X11-utils~xorg-xdpyinfo~xorg-x11-utils~:-G_multi_screen_resolution 
2259         xprop:X11-utils~xorg-xprop~x11-utils~:-S_desktop_data 
2260         xrandr:x11-xserver-utils~xrandr~x11-server-utils~:-G_single_screen_resolution
2261         '
2262         local recommended_apps='
2263         dig:dnsutils~dnsutils~bind-utils:-i_first_wlan_ip_default_test
2264         dmidecode:dmidecode~dmidecode~dmidecode~:-M_if_no_sys_machine_data;_-m_memory 
2265         file:file~file~file~:-o_unmounted_file_system
2266         hciconfig:bluez~bluez-utils~bluez-utils~:-n_-i_bluetooth_data
2267         hddtemp:hddtemp~hddtemp~hddtemp~:-Dx_show_hdd_temp 
2268         ifconfig:net-tools~net-tools~net-tools~:-i_ip_lan-deprecated
2269         ip:iproute~iproute2~iproute~:-i_ip_lan
2270         sensors:lm-sensors~lm_sensors~lm-sensors~:-s_sensors_output
2271         strings:binutils~~~:-I_sysvinit_version
2272         lsusb:usbutils~usbutils~usbutils~:-A_usb_audio;-N_usb_networking 
2273         modinfo:module-init-tools~module-init-tools~module-init-tools~:-Ax,-Nx_module_version 
2274         runlevel:sysvinit~sysvinit~systemd~:-I_runlevel
2275         sudo:sudo~sudo~sudo~:-Dx_hddtemp-user;-o_file-user
2276         uptime:procps~procps~procps~:-I_uptime_(check_which_package_owns_Debian)
2277         '
2278         
2279         local downloaders="
2280         wget:wget~wget~wget~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(if_supported)
2281         curl:curl~curl~curl~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(if_supported)
2282         $downloaders_bsd
2283         "
2284         local recommended_dirs='
2285         /sys/class/dmi/id:-M_system,_motherboard,_bios
2286         /dev:-l,-u,-o,-p,-P,-D_disk_partition_data
2287         /dev/disk/by-label:-l,-o,-p,-P_partition_labels
2288         /dev/disk/by-uuid:-u,-o,-p,-P_partition_uuid
2289         '
2290         local recommended_files="
2291         $FILE_ASOUND_DEVICE:-A_sound_card_data
2292         $FILE_ASOUND_VERSION:-A_ALSA_data
2293         $FILE_CPUINFO:-C_cpu_data
2294         $FILE_LSB_RELEASE:-S_distro_version_data_[deprecated]
2295         $FILE_MDSTAT:-R_mdraid_data
2296         $FILE_MEMINFO:-I_memory_data
2297         $FILE_OS_RELEASE:-S_distro_version_data
2298         $FILE_PARTITIONS:-p,-P_partitions_data
2299         $FILE_MODULES:-G_module_data
2300         $FILE_MOUNTS:-P,-p_partition_advanced_data
2301         $FILE_DMESG_BOOT:-D,-d_disk_data_[BSD_only]
2302         $FILE_SCSI:-D_Advanced_hard_disk_data_[used_rarely]
2303         $FILE_XORG_LOG:-G_graphics_driver_load_status
2304         "
2305         
2306         if [[ -n $COLS_INNER ]];then
2307                 if [[ $COLS_INNER -ge 90 ]];then
2308                         width=${#LINE1} # match width of $LINE1
2309                 elif [[ $COLS_INNER -ge 78 ]];then
2310                         width=$(( $COLS_INNER - 11 ))
2311                 fi
2312         fi
2313         
2314         case $1 in
2315                 downloaders)
2316                         item_list=$downloaders
2317                         item_string='Downloaders'
2318                         item_string=''
2319                         missing_string='downloaders, and their corresponding packages,'
2320                         type='applications'
2321                         ;;
2322                 required-dirs)
2323                         item_list=$required_dirs
2324                         item_string='Required file system'
2325                         item_string=''
2326                         missing_string='system directories'
2327                         type='directories'
2328                         ;;
2329                 required-apps)
2330                         item_list=$required_apps
2331                         item_string='Required application'
2332                         item_string=''
2333                         missing_string='applications, and their corresponding packages,'
2334                         type='applications'
2335                         ;;
2336                 recommended-x-apps)
2337                         item_list=$x_recommends
2338                         item_string='Recommended X application'
2339                         item_string=''
2340                         missing_string='applications, and their corresponding packages,'
2341                         type='applications'
2342                         ;;
2343                 recommended-apps)
2344                         item_list=$recommended_apps
2345                         item_string='Recommended application'
2346                         item_string=''
2347                         missing_string='applications, and their corresponding packages,'
2348                         type='applications'
2349                         ;;
2350                 system-dirs)
2351                         item_list=$recommended_dirs
2352                         item_string='System directory'
2353                         item_string=''
2354                         missing_string='system directories'
2355                         type='directories'
2356                         ;;
2357                 system-files)
2358                         item_list=$recommended_files
2359                         item_string='System file'
2360                         item_string=''
2361                         missing_string='system files'
2362                         type='files'
2363                         ;;
2364         esac
2365         # great trick from: http://ideatrash.net/2011/01/bash-string-padding-with-sed.html
2366         # left pad: sed -e :a -e 's/^.\{1,80\}$/& /;ta'
2367         # right pad: sed -e :a -e 's/^.\{1,80\}$/ &/;ta'
2368         # center pad: sed -e :a -e 's/^.\{1,80\}$/ & /;ta'
2369         
2370         for item in $item_list
2371         do
2372                 if [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 0 ]];then
2373                         application=$item
2374                         package=''
2375                         feature=''
2376                         location=''
2377                 elif [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 1 ]];then
2378                         application=$( cut -d ':' -f 1 <<< $item )
2379                         package=''
2380                         feature=$( cut -d ':' -f 2 <<< $item )
2381                         location=''
2382                 else
2383                         application=$( cut -d ':' -f 1 <<< $item )
2384                         package=$( cut -d ':' -f 2 <<< $item )
2385                         location=$( type -p $application )
2386                         if [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 2 ]];then
2387                                 feature=$( cut -d ':' -f 3 <<< $item )
2388                         else
2389                                 feature=''
2390                         fi
2391                 fi
2392                 if [[ -n $feature ]];then
2393                         print_string="$item_string$application (info: $( sed 's/_/ /g' <<< $feature ))"
2394                 else
2395                         print_string="$item_string$application"
2396                 fi
2397                 
2398                 starter="$( sed -e :a -e 's/^.\{1,'$width'\}$/&./;ta' <<< $print_string )"
2399                 if [[ -z $( grep '^/' <<< $application ) && -n $location ]] || [[ -d $application || -f $application ]];then
2400                         if [[ -n $location ]];then
2401                                 finisher=" $location"
2402                         else
2403                                 finisher=" Present"
2404                         fi
2405                 else
2406                         finisher=" Missing"
2407                         missing_items="$missing_items$separator$application:$package"
2408                         separator=' '
2409                 fi
2410                 
2411                 echo "$starter$finisher"
2412         done
2413         echo 
2414         if [[ -n $missing_items ]];then
2415                 echo "The following $type are missing from your system:"
2416                 for item in $missing_items
2417                 do
2418                         application=$( cut -d ':' -f 1 <<< $item )
2419                         if [[ $type == 'applications' ]];then
2420                                 echo
2421                                 package=$( cut -d ':' -f 2 <<< $item )
2422                                 package_deb=$( cut -d '~' -f 1 <<< $package )
2423                                 package_pacman=$( cut -d '~' -f 2 <<< $package )
2424                                 package_rpm=$( cut -d '~' -f 3 <<< $package )
2425                                 echo "Application: $application"
2426                                 print_lines_basic "0" "" "To add to your system, install the proper distribution package for your system:"
2427                                 print_lines_basic "0" "" "Debian/Ubuntu:^$package_deb^:: Arch Linux:^$package_pacman^:: Redhat/Fedora/Suse:^$package_rpm"
2428                         elif [[ $type == 'directories' ]];then
2429                                 echo "Directory: $application"
2430                         elif [[ $type == 'files' ]];then
2431                                 echo "File: $application"
2432                         fi
2433                 done
2434                 if [[ $item_string == 'System directory' ]];then
2435                         print_lines_basic "0" "" "These directories are created by the kernel, so don't worry if they are not present."
2436                 fi
2437         else
2438                 echo "All the $( cut -d ' ' -f 1 <<< $item_string | sed -e 's/Re/re/' -e 's/Sy/sy/' ) $type are present."
2439         fi
2440         echo $Line
2441 }
2442
2443 #### -------------------------------------------------------------------
2444 #### print / output cleaners
2445 #### -------------------------------------------------------------------
2446
2447 # inxi speaks through here. When run by Konversation script alias mode, uses DCOP
2448 # for dcop to work, must use 'say' operator, AND colors must be evaluated by echo -e
2449 # note: dcop does not seem able to handle \n so that's being stripped out and replaced with space.
2450 print_screen_output()
2451 {
2452         eval $LOGFS
2453         # the double quotes are needed to avoid losing whitespace in data when certain output types are used
2454         # trim off whitespace at end
2455         local print_data="$( echo -e "$1" )" 
2456
2457         # just using basic debugger stuff so you can tell which thing is printing out the data. This
2458         # should help debug kde 4 konvi issues when that is released into sid, we'll see. Turning off
2459         # the redundant debugger output which as far as I can tell does exactly nothing to help debugging.
2460         if [[ $DEBUG -gt 5 ]];then
2461                 if [[ $KONVI -eq 1 ]];then
2462                         # konvi doesn't seem to like \n characters, it just prints them literally
2463                         # print_data="$( tr '\n' ' ' <<< "$print_data" )"
2464                         # dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "konvi='$KONVI' saying : '$print_data'"
2465                         print_data="KP-$KONVI: $print_data"
2466                 elif [[ $KONVI -eq 2 ]];then
2467                         # echo "konvi='$KONVI' saying : '$print_data'"
2468                         print_data="KP-$KONVI: $print_data"
2469                 else
2470                         # echo "printing out: '$print_data'"
2471                         print_data="P: $print_data"
2472                 fi
2473         fi
2474         if [[ $KONVI -eq 1 && $B_DCOP == 'true' ]]; then ## dcop Konversation (<= 1.1 (qt3))
2475                 # konvi doesn't seem to like \n characters, it just prints them literally
2476                 $print_data="$( tr '\n' ' ' <<< "$print_data" )"
2477                 dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data"
2478         elif [[ $KONVI -eq 3 && $B_QDBUS == 'true' ]]; then ## dbus Konversation (> 1.2 (qt4))
2479                 qdbus org.kde.konversation /irc say "$DCSERVER" "$DCTARGET" "$print_data"
2480 #       elif [[ $IRC_CLIENT == 'X-Chat' ]]; then
2481 #               qdbus org.xchat.service print "$print_data\n"
2482         else
2483                 # the -n is needed to avoid double spacing of output in terminal
2484                 echo -ne "$print_data\n"
2485         fi
2486         eval $LOGFE
2487 }
2488
2489 ## this handles all verbose line construction with indentation/line starter
2490 ## args: $1 - null (, actually: " ") or line starter; $2 - line content
2491 create_print_line()
2492 {
2493         eval $LOGFS
2494         # convoluted, yes, but it works to trim spaces off end
2495         local line=${2%${2##*[![:space:]]}}
2496         printf "${C1}%-${INDENT}s${C2} %s" "$1" "$line${CN}"
2497         eval $LOGFE
2498 }
2499
2500 # this removes newline and pipes.
2501 # args: $1 - string to clean
2502 remove_erroneous_chars()
2503 {
2504         eval $LOGFS
2505         ## RS is input record separator
2506         ## gsub is substitute;
2507         gawk '
2508         BEGIN {
2509                 RS=""
2510         }
2511         {
2512                 gsub(/\n$/,"")         ## (newline; end of string) with (nothing)
2513                 gsub(/\n/," ");        ## (newline) with (space)
2514                 gsub(/^ *| *$/, "")    ## (pipe char) with (nothing)
2515                 gsub(/  +/, " ")       ## ( +) with (space)
2516                 gsub(/ [ ]+/, " ")     ## ([ ]+) with (space)
2517                 gsub(/^ +| +$/, "")    ## (pipe char) with (nothing)
2518                 printf $0
2519         }' "$1"      ## prints (returns) cleaned input
2520         eval $LOGFE
2521 }
2522
2523 #### -------------------------------------------------------------------
2524 #### parameter handling, print usage functions.
2525 #### -------------------------------------------------------------------
2526
2527 # Get the parameters. Note: standard options should be lower case, advanced or testing, upper
2528 # args: $1 - full script startup args: $@
2529 get_parameters()
2530 {
2531         eval $LOGFS
2532         local opt='' downloader_test='' debug_data_type='' weather_flag='wW:' 
2533         local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false
2534
2535         # if distro maintainers don't want the weather feature disable it
2536         if [[ $B_ALLOW_WEATHER == 'false' ]];then
2537                 weather_flag=''
2538         fi
2539         if [[ $1 == '--version' ]];then
2540                 print_version_info
2541                 exit 0
2542         elif [[ $1 == '--help' ]];then
2543                 show_options
2544                 exit 0
2545         elif [[ $1 == '--recommends' ]];then
2546                 check_recommends_user_output
2547                 exit 0
2548         # the short form only runs if no args output args are used
2549         # no need to run through these if there are no args
2550         # reserved for future use: -g for extra Graphics; -m for extra Machine; -d for extra Disk
2551         elif [[ -n $1 ]];then
2552                 while getopts AbBc:CdDfFGhHiIlmMnNopPrRsSt:uUv:V${weather_flag}xy:zZ%@:!: opt
2553                 do
2554                         case $opt in
2555                         A)      B_SHOW_AUDIO='true'
2556                                 use_short='false'
2557                                 ;;
2558                         b)      use_short='false'
2559                                 B_SHOW_BASIC_CPU='true'
2560                                 B_SHOW_BASIC_RAID='true'
2561                                 B_SHOW_DISK_TOTAL='true'
2562                                 B_SHOW_GRAPHICS='true'
2563                                 B_SHOW_INFO='true'
2564                                 B_SHOW_MACHINE='true'
2565                                 B_SHOW_BATTERY='true'
2566                                 B_SHOW_NETWORK='true'
2567                                 B_SHOW_SYSTEM='true'
2568                                 ;;
2569                         B)      B_SHOW_BATTERY_FORCED='true'
2570                                 B_SHOW_BATTERY='true'
2571                                 use_short='false'
2572                                 ;;
2573                         c)      if [[ $OPTARG =~ ^[0-9][0-9]?$ ]];then
2574                                         case $OPTARG in
2575                                                 99)
2576                                                         B_RUN_COLOR_SELECTOR='true'
2577                                                         COLOR_SELECTION='global'
2578                                                         ;;
2579                                                 98)
2580                                                         B_RUN_COLOR_SELECTOR='true'
2581                                                         COLOR_SELECTION='irc-console'
2582                                                         ;;
2583                                                 97)
2584                                                         B_RUN_COLOR_SELECTOR='true'
2585                                                         COLOR_SELECTION='irc-virtual-terminal'
2586                                                         ;;
2587                                                 96)
2588                                                         B_RUN_COLOR_SELECTOR='true'
2589                                                         COLOR_SELECTION='irc'
2590                                                         ;;
2591                                                 95)
2592                                                         B_RUN_COLOR_SELECTOR='true'
2593                                                         COLOR_SELECTION='virtual-terminal'
2594                                                         ;;
2595                                                 94)
2596                                                         B_RUN_COLOR_SELECTOR='true'
2597                                                         COLOR_SELECTION='console'
2598                                                         ;;
2599                                                 *)      
2600                                                         B_COLOR_SCHEME_SET='true'
2601                                                         ## note: not sure about this, you'd think user values should be overridden, but
2602                                                         ## we'll leave this for now
2603                                                         if [[ -z $COLOR_SCHEME ]];then
2604                                                                 set_color_scheme "$OPTARG"
2605                                                         fi
2606                                                         ;;
2607                                         esac
2608                                 else
2609                                         error_handler 3 "$OPTARG"
2610                                 fi
2611                                 ;;
2612                         C)      B_SHOW_CPU='true'
2613                                 use_short='false'
2614                                 ;;
2615                         d)      B_SHOW_DISK='true'
2616                                 B_SHOW_FULL_OPTICAL='true'
2617                                 use_short='false'
2618                                 # error_handler 20 "-d has been replaced by -b"
2619                                 ;;
2620                         D)      B_SHOW_DISK='true'
2621                                 use_short='false'
2622                                 ;;
2623                         f)      B_SHOW_CPU='true'
2624                                 B_CPU_FLAGS_FULL='true'
2625                                 use_short='false'
2626                                 ;;
2627                         F)      # B_EXTRA_DATA='true'
2628                                 B_SHOW_ADVANCED_NETWORK='true'
2629                                 B_SHOW_AUDIO='true'
2630                                 # B_SHOW_BASIC_OPTICAL='true'
2631                                 B_SHOW_CPU='true'
2632                                 B_SHOW_DISK='true'
2633                                 B_SHOW_GRAPHICS='true'
2634                                 B_SHOW_INFO='true'
2635                                 B_SHOW_MACHINE='true'
2636                                 B_SHOW_BATTERY='true'
2637                                 B_SHOW_NETWORK='true'
2638                                 B_SHOW_PARTITIONS='true'
2639                                 B_SHOW_RAID='true'
2640                                 B_SHOW_SENSORS='true'
2641                                 B_SHOW_SYSTEM='true'
2642                                 use_short='false'
2643                                 ;;
2644                         G)      B_SHOW_GRAPHICS='true'
2645                                 use_short='false'
2646                                 ;;
2647                         i)      B_SHOW_IP='true'
2648                                 B_SHOW_NETWORK='true'
2649                                 B_SHOW_ADVANCED_NETWORK='true'
2650                                 use_short='false'
2651                                 ;;
2652                         I)      B_SHOW_INFO='true'
2653                                 use_short='false'
2654                                 ;;
2655                         l)      B_SHOW_LABELS='true'
2656                                 B_SHOW_PARTITIONS='true'
2657                                 use_short='false'
2658                                 ;;
2659                         m)      B_SHOW_MEMORY='true'
2660                                 use_short='false'
2661                                 ;;
2662                         M)      B_SHOW_MACHINE='true'
2663                                 B_SHOW_BATTERY='true'
2664                                 use_short='false'
2665                                 ;;
2666                         n)      B_SHOW_ADVANCED_NETWORK='true'
2667                                 B_SHOW_NETWORK='true'
2668                                 use_short='false'
2669                                 ;;
2670                         N)      B_SHOW_NETWORK='true'
2671                                 use_short='false'
2672                                 ;;
2673                         o)      B_SHOW_UNMOUNTED_PARTITIONS='true'
2674                                 use_short='false'
2675                                 ;;
2676                         p)      B_SHOW_PARTITIONS_FULL='true'
2677                                 B_SHOW_PARTITIONS='true'
2678                                 use_short='false'
2679                                 ;;
2680                         P)      B_SHOW_PARTITIONS='true'
2681                                 use_short='false'
2682                                 ;;
2683                         r)      B_SHOW_REPOS='true'
2684                                 use_short='false'
2685                                 ;;
2686                         R)      B_SHOW_RAID='true'
2687                                 # it turns out only users with mdraid software installed will have raid,
2688                                 # so unless -R is explicitly called, blank -b/-F/-v6 and less output will not show
2689                                 # error if file is missing.
2690                                 B_SHOW_RAID_R='true'
2691                                 use_short='false'
2692                                 ;;
2693                         s)      B_SHOW_SENSORS='true'
2694                                 use_short='false'
2695                                 ;;
2696                         S)      B_SHOW_SYSTEM='true'
2697                                 use_short='false'
2698                                 ;;
2699                         t)      if [[ $OPTARG =~ ^(c|m|cm|mc)([1-9]|1[0-9]|20)?$ ]];then
2700                                         use_short='false'
2701                                         if [[ -n $( grep -E '[0-9]+' <<< $OPTARG ) ]];then
2702                                                 PS_COUNT=$( sed 's/[^0-9]//g' <<< $OPTARG )
2703                                         fi
2704                                         if [[ -n $( grep 'c' <<< $OPTARG ) ]];then
2705                                                 B_SHOW_PS_CPU_DATA='true'
2706                                         fi
2707                                         if [[ -n $( grep 'm' <<< $OPTARG ) ]];then
2708                                                 B_SHOW_PS_MEM_DATA='true'
2709                                         fi
2710                                 else
2711                                         error_handler 13 "$OPTARG"
2712                                 fi
2713                                 ;;
2714                         u)      B_SHOW_UUIDS='true'
2715                                 B_SHOW_PARTITIONS='true'
2716                                 use_short='false'
2717                                 ;;
2718                         v)      if [[ $OPTARG =~ ^[0-9][0-9]?$ && $OPTARG -le $VERBOSITY_LEVELS ]];then
2719                                         if [[ $OPTARG -ge 1 ]];then
2720                                                 use_short='false'
2721                                                 B_SHOW_BASIC_CPU='true'
2722                                                 B_SHOW_DISK_TOTAL='true'
2723                                                 B_SHOW_GRAPHICS='true'
2724                                                 B_SHOW_INFO='true'
2725                                                 B_SHOW_SYSTEM='true'
2726                                         fi
2727                                         if [[ $OPTARG -ge 2 ]];then
2728                                                 B_SHOW_BASIC_DISK='true'
2729                                                 B_SHOW_BASIC_RAID='true'
2730                                                 B_SHOW_BATTERY='true'
2731                                                 B_SHOW_MACHINE='true'
2732                                                 B_SHOW_NETWORK='true'
2733                                         fi
2734                                         if [[ $OPTARG -ge 3 ]];then
2735                                                 B_SHOW_ADVANCED_NETWORK='true'
2736                                                 B_SHOW_CPU='true'
2737                                                 B_EXTRA_DATA='true'
2738                                         fi
2739                                         if [[ $OPTARG -ge 4 ]];then
2740                                                 B_SHOW_DISK='true'
2741                                                 B_SHOW_PARTITIONS='true'
2742                                         fi
2743                                         if [[ $OPTARG -ge 5 ]];then
2744                                                 B_SHOW_AUDIO='true'
2745                                                 B_SHOW_BASIC_OPTICAL='true'
2746                                                 B_SHOW_MEMORY='true'
2747                                                 B_SHOW_SENSORS='true'
2748                                                 B_SHOW_LABELS='true'
2749                                                 B_SHOW_UUIDS='true'
2750                                                 B_SHOW_RAID='true'
2751                                         fi
2752                                         if [[ $OPTARG -ge 6 ]];then
2753                                                 B_SHOW_FULL_OPTICAL='true'
2754                                                 B_SHOW_PARTITIONS_FULL='true'
2755                                                 B_SHOW_UNMOUNTED_PARTITIONS='true'
2756                                                 B_EXTRA_EXTRA_DATA='true'
2757                                         fi
2758                                         if [[ $OPTARG -ge 7 ]];then
2759                                                 B_EXTRA_EXTRA_EXTRA_DATA='true'
2760                                                 B_SHOW_IP='true'
2761                                                 B_SHOW_RAID_R='true'
2762                                         fi
2763                                 else
2764                                         error_handler 4 "$OPTARG"
2765                                 fi
2766                                 ;;
2767                         U)      if [[ $B_ALLOW_UPDATE == 'true' ]];then
2768                                         script_self_updater "$SCRIPT_DOWNLOAD" 'svn server' "$opt"
2769                                 else
2770                                         error_handler 17 "-$opt"
2771                                 fi
2772                                 ;;
2773                         V)      print_version_info
2774                                 exit 0
2775                                 ;;
2776                         w)      B_SHOW_WEATHER=true
2777                                 use_short='false'
2778                                 ;;
2779                         W)      ALTERNATE_WEATHER_LOCATION=$( sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'  <<< $OPTARG )
2780                                 if [[ -n $( grep -Esi '([^,]+,.+|[0-9-]+)' <<< $ALTERNATE_WEATHER_LOCATION ) ]];then
2781                                         B_SHOW_WEATHER=true
2782                                         use_short='false'
2783                                 else
2784                                         error_handler 18 "-$opt: '$OPTARG'" "city,state OR latitude,longitude OR postal/zip code."
2785                                 fi
2786                                 ;;
2787                         # this will trigger either with x, xx, xxx or with Fx but not with xF
2788                         x)      if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
2789                                         B_EXTRA_EXTRA_EXTRA_DATA='true'
2790                                 elif [[ $B_EXTRA_DATA == 'true' ]];then
2791                                         B_EXTRA_EXTRA_DATA='true'
2792                                 else
2793                                         B_EXTRA_DATA='true'
2794                                 fi
2795                                 ;;
2796                         y)      if [[ -z ${OPTARG//[0-9]/} && $OPTARG -ge 80 ]];then
2797                                         set_display_width "$OPTARG"
2798                                 else
2799                                         error_handler 21 "$OPTARG"
2800                                 fi
2801                                 ;;
2802                         z)      B_OUTPUT_FILTER='true'
2803                                 ;;
2804                         Z)      B_OVERRIDE_FILTER='true'
2805                                 ;;
2806                         h)      show_options
2807                                 exit 0
2808                                 ;;
2809                         H)      show_options 'full'
2810                                 exit 0
2811                                 ;;
2812                         ## debuggers and testing tools
2813                         %)      B_HANDLE_CORRUPT_DATA='true'
2814                                 ;;
2815                         @)      if [[ -n $( grep -E "^([1-9]|1[0-5])$" <<< $OPTARG ) ]];then
2816                                         DEBUG=$OPTARG
2817                                         if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
2818                                                 B_UPLOAD_DEBUG_DATA='true'
2819                                         fi
2820                                         exec 2>&1
2821                                         # switch on logging only for -@ 8-10
2822                                         case $OPTARG in
2823                                                 8|9|10)
2824                                                         if [[ $OPTARG -eq 10 ]];then
2825                                                                 B_LOG_COLORS='true'
2826                                                         elif [[ $OPTARG -eq 9 ]];then           
2827                                                                 B_LOG_FULL_DATA='true'
2828                                                         fi
2829                                                         B_USE_LOGGING='true'
2830                                                         # pack the logging data for evals function start/end
2831                                                         LOGFS=$LOGFS_STRING
2832                                                         LOGFE=$LOGFE_STRING
2833                                                         create_rotate_logfiles # create/rotate logfiles before we do anything else
2834                                                         ;;
2835                                                 11|12|13|14|15)
2836                                                         case $OPTARG in
2837                                                                 11)
2838                                                                         debug_data_type='sys'
2839                                                                         ;;
2840                                                                 12)
2841                                                                         debug_data_type='xorg'
2842                                                                         ;;
2843                                                                 13)
2844                                                                         debug_data_type='disk'
2845                                                                         ;;
2846                                                                 14)
2847                                                                         debug_data_type='all'
2848                                                                         ;;
2849                                                                 15)
2850                                                                         debug_data_type='all'
2851                                                                         B_DEBUG_I='true'
2852                                                                         ;;
2853                                                         esac
2854                                                         initialize_data
2855                                                         debug_data_collector $debug_data_type
2856                                                         ;;
2857                                         esac
2858                                 else
2859                                         error_handler 9 "$OPTARG"
2860                                 fi
2861                                 ;;
2862                         !)      # test for various supported methods
2863                                 case $OPTARG in
2864                                         1)      B_TESTING_1='true'
2865                                                 ;;
2866                                         2)      B_TESTING_2='true'
2867                                                 ;;
2868                                         3)      B_TESTING_1='true'
2869                                                 B_TESTING_2='true'
2870                                                 ;;
2871                                         1[0-6]|http*)
2872                                                 if [[ $B_ALLOW_UPDATE == 'true' ]];then
2873                                                         case $OPTARG in
2874                                                                 10)
2875                                                                         script_self_updater "$SCRIPT_DOWNLOAD_DEV" 'dev server' "$opt $OPTARG"
2876                                                                         ;;
2877                                                                 11)
2878                                                                         script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_1" 'svn: branch one server' "$opt $OPTARG"
2879                                                                         ;;
2880                                                                 12)
2881                                                                         script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_2" 'svn: branch two server' "$opt $OPTARG"
2882                                                                         ;;
2883                                                                 13)
2884                                                                         script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_3" 'svn: branch three server' "$opt $OPTARG"
2885                                                                         ;;
2886                                                                 14)
2887                                                                         script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_4" 'svn: branch four server' "$opt $OPTARG"
2888                                                                         ;;
2889                                                                 15)
2890                                                                         script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_BSD" 'svn: branch bsd server' "$opt $OPTARG"
2891                                                                         ;;
2892                                                                 16)
2893                                                                         script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_GNUBSD" 'svn: branch gnubsd server' "$opt $OPTARG"
2894                                                                         ;;
2895                                                                 http*)
2896                                                                         script_self_updater "$OPTARG" 'alt server' "$opt <http...>"
2897                                                                         ;;
2898                                                         esac
2899                                                 else
2900                                                         error_handler 17 "-$opt $OPTARG"
2901                                                 fi
2902                                                 ;;
2903                                         30)
2904                                                 B_IRC='false'
2905                                                 ;;