BSDG33KCLUB

inxi

Feb 1st, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 380.40 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. ########################################################################
  3. #### Script Name: inxi
  4. #### Version: 1.9.17
  5. #### Date: 2013-12-02
  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-2013 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/svn: http://inxi.googlecode.com
  29. #### Script forums: http://techpatterns.com/forums/forum-33.html
  30. #### IRC support: irc.oftc.net channel #smxi
  31. ####
  32. #### This program is free software; you can redistribute it and/or modify
  33. #### it under the terms of the GNU General Public License as published by
  34. #### the Free Software Foundation; either version 3 of the License, or
  35. #### (at your option) any later version.
  36. ####
  37. #### This program is distributed in the hope that it will be useful,
  38. #### but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. #### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40. #### GNU General Public License for more details.
  41. ####
  42. #### You should have received a copy of the GNU General Public License
  43. #### along with this program. If not, see <http://www.gnu.org/licenses/>.
  44. ####
  45. #### If you don't understand what Free Software is, please read (or reread)
  46. #### this page: http://www.gnu.org/philosophy/free-sw.html
  47. ########################################################################
  48. #### * Package names in (...) are the Debian Squeeze package name. Check your
  49. #### distro for proper package name by doing this: which <application>
  50. #### then find what package owns that application file. Or run --recommends
  51. #### which shows package names for Debian/Ubuntu, Arch, and Fedora/Redhat/Suse
  52. ####
  53. #### DEPENDENCIES
  54. #### * bash >=3.0 (bash); df, readlink, stty, tr, uname, wc (coreutils);
  55. #### gawk (gawk); grep (grep); lspci (pciutils);
  56. #### ps, uptime (procps); find (findutils)
  57. #### * Also the proc filesystem should be present and mounted
  58. #### * Some features, like -M and -d will not work, or will work incompletely,
  59. #### if /sys is missing
  60. ####
  61. #### Apparently unpatched bash 3.0 has arrays broken; bug reports:
  62. #### http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-008
  63. #### http://lists.gnu.org/archive/html/bug-bash/2004-08/msg00144.html
  64. #### Bash 3.1 for proper array use
  65. ####
  66. #### Arrays work in bash 2.05b, but "grep -Em" does not
  67. ####
  68. #### RECOMMENDS (Needed to run certain features, listed by option)
  69. #### -A - for output of usb audio information: lsusb (usbutils)
  70. #### -Ax -Nx - for audio/network module version: modinfo (module-init-tools)
  71. #### -Dx - for hdd temp output (root only default): hddtemp (hddtemp)
  72. #### For user level hdd temp output: sudo (sudo)
  73. #### Note: requires user action for this feature to run as user (edit /etc/sudoers file)
  74. #### -G - full graphics output requires: glxinfo (mesa-utils); xdpyinfo (X11-utils);
  75. #### xrandr (x11-xserver-utils)
  76. #### -i - IP information, local/wan - ip (iproute) legacy, not used if ip present: ifconfig (net-tools)
  77. #### -Ix - view current runlevel while not in X window system (or with -x): runlevel (sysvinit)
  78. #### -M - for older systems whose kernel does not have /sys data for machine, dmidecode (dmidecode)
  79. #### -o - for unmounted file system information in unmounted drives (root only default): file (file)
  80. #### Note: requires user action for this feature to run as user (edit /etc/sudoers file)
  81. #### For user level unmounted file system type output: sudo (sudo)
  82. #### -s For any sensors output, fan, temp, etc: sensors (lm-sensors)
  83. #### Note: requires setup of lm-sensors (sensors-detect and adding modules/modprobe/reboot,
  84. #### and ideally, pwmconfig) prior to full output being available.
  85. #### -S For desktop environment, user must be in X and have xprop installed (in X11-utils)
  86. ########################################################################
  87. #### BSD Adjustments
  88. #### * sed -i '' form supported by using SED_I="-i ''".
  89. #### * Note: New BSD sed supports using -r instead of -E for compatibility with gnu sed
  90. #### However, older, like FreeBSD 7.x, does not have -r so using SED_RX='-E' for this.
  91. #### * Gnu grep options can be used if the function component is only run in linux
  92. #### These are the options that bsd grep does not support that inxi uses: -m <number> -o
  93. #### so make sure if you use those to have them in gnu/linux only sections.
  94. #### It appears that freebsd uses gnu grep but openbsd uses bsd grep, however.
  95. #### * BSD ps does not support --without-headers option, and also does not support --sort <option>
  96. #### Tests show that -m fails to sort memory as expected, but -r does sort cpu percentage.
  97. #### * BSD_TYPE is set with values null, debian-bsd (debian gnu/kfreebsd), bsd (all other bsds)
  98. #### * Subshell and array closing ) must not be on their own line unless you use an explicit \
  99. #### to indicate that logic continues to next line where closing ) or )) are located.
  100. ########################################################################
  101. #### CONVENTIONS:
  102. #### * Character Encoding: UTF-8 - this file contains special characters that must be opened and saved as UTF8
  103. #### * Indentation: TABS
  104. #### * Do not use `....` (back quotes), those are totally non-reabable, use $(....).
  105. #### * Do not use one liner flow controls.
  106. #### The ONLY time you should use ';' (semi-colon) is in this single case: if [[ condition ]];then.
  107. #### Never use compound 'if': ie, if [[ condition ]] && statement.
  108. #### * Note: [[ -n $something ]] - double brackets does not require quotes for variables: ie, "$something".
  109. #### * Always use quotes, double or single, for all string values.
  110. #### * All new code/methods must be in a function.
  111. #### * For all boolean tests, use 'true' / 'false'.
  112. #### !! Do NOT use 0 or 1 unless it's a function return.
  113. #### * Avoid complicated tests in the if condition itself.
  114. #### * To 'return' a value in a function, use 'echo <var>'.
  115. #### * For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
  116. #### This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
  117. ####
  118. #### VARIABLE/FUNCTION NAMING:
  119. #### * All functions should follow standard naming--verb adjective noun.
  120. #### ie, get_cpu_data
  121. #### * All variables MUST be initialized / declared explicitly, either top of file, for Globals, or using local
  122. #### * All variables should clearly explain what they are, except counters like i, j.
  123. #### * Each word of Bash variable must be separated by '_' (underscore) (camel form), like: cpu_data
  124. #### * Each word of Gawk variable must be like this (first word lower, following start with upper): cpuData
  125. #### * Global variables are 'UPPER CASE', at top of this file.
  126. #### ie, SOME_VARIABLE=''
  127. #### * Local variables are 'lower case' and declared at the top of the function using local, always.
  128. #### ie: local some_variable=''
  129. #### * Locals that will be inherited by child functions have first char capitalized (so you know they are inherited).
  130. #### ie, Some_Variable
  131. #### * Booleans should start with b_ (local) or B_ (global) and state clearly what is being tested.
  132. #### * Arrays should start with a_ (local) or A_ (global).
  133. ####
  134. #### SPECIAL NOTES:
  135. #### * The color variable ${C2} must always be followed by a space unless you know what
  136. #### character is going to be next for certain. Otherwise irc color codes can be accidentally
  137. #### activated or altered.
  138. #### * For native script konversation support (check distro for correct konvi scripts path):
  139. #### ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi
  140. #### DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.
  141. #### * print_screen_output " " # requires space, not null, to avoid error in for example in irssi
  142. #### * For logging of array data, array must be placed into the temp_array, otherwise only the first key logs
  143. #### * In gawk search patterns, . is a wildcard EXCEPT in [0-9.] type containers, then it's a literal
  144. #### So outside of bracketed items, it must be escaped, \. but inside, no need. Outside of gawk it should
  145. #### be escaped in search patterns if you are using it as a literal.
  146. ####
  147. #### As with all 'rules' there are acceptions, these are noted where used.
  148. ###################################################################################
  149. #### KDE Konversation information. Moving from dcop(qt3/KDE3) to dbus(qt4/KDE4)
  150. ###################################################################################
  151. #### * dcop and dbus -- these talk back to Konversation from this program
  152. #### * Scripting info -- http://konversation.berlios.de/docs/scripting.html
  153. #### -- http://www.kde.org.uk/apps/konversation/
  154. #### * dbus info -- http://dbus.freedesktop.org/doc/dbus-tutorial.html
  155. #### view dbus info -- https://fedorahosted.org/d-feet/
  156. #### -- or run qdbus
  157. #### * Konvi dbus/usage-- qdbus org.kde.konversation /irc say <server> <target-channel> <output>
  158. #### * Python usage -- http://wiki.python.org/moin/DbusExamples (just in case)
  159. ####
  160. #### Because webpages come and go, the above information needs to be moved to inxi's wiki
  161. ########################################################################
  162. #### Valuable Resources
  163. #### CPU flags: http://unix.stackexchange.com/questions/43539/what-do-the-flags-in-proc-cpuinfo-mean
  164. #### gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
  165. #### raid mdstat: http://www-01.ibm.com/support/docview.wss?uid=isg3T1011259
  166. #### http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array
  167. #### https://raid.wiki.kernel.org/index.php/Mdstat
  168. ########################################################################
  169. #### TESTING FLAGS
  170. #### inxi supports advanced testing triggers to do various things, using -! <arg>
  171. #### -! 1 - triggers default B_TESTING_1='true' to trigger some test or other
  172. #### -! 2 - triggers default B_TESTING_2='true' to trigger some test or other
  173. #### -! 3 - triggers B_TESTING_1='true' and B_TESTING_2='true'
  174. #### -! 10 - triggers an update from the primary dev download server instead of svn
  175. #### -! 11 - triggers an update from svn branch one - if present, of course
  176. #### -! 12 - triggers an update from svn branch two - if present, of course
  177. #### -! 13 - triggers an update from svn branch three - if present, of course
  178. #### -! 14 - triggers an update from svn branch four - if present, of course
  179. #### -! <http://......> - Triggers an update from whatever server you list.
  180. #### LOG FLAGS (logs to $HOME/.inxi/inxi.log with rotate 3 total)
  181. #### -@ 8 - Basic data logging of generated data / array values
  182. #### -@ 9 - Full logging of all data used, including cat of files and system data
  183. #### -@ 10 - Basic data logging plus color code logging
  184. ########################################################################
  185. #### VARIABLES
  186. ########################################################################
  187.  
  188. ## NOTE: we can use hwinfo if it's available in all systems, or most, to get
  189. ## a lot more data and verbosity levels going
  190. # set to default LANG to avoid locales errors with , or .
  191. LANG=C
  192. ### Variable initializations: null values
  193. BSD_TYPE=''
  194. BSD_VERSION=
  195. CMDL_MAX=''
  196. COLOR_SCHEME=''
  197. # override in user config if desired, seems like less than .3 doesn't work as reliably
  198. CPU_SLEEP='0.3'
  199. DEV_DISK_ID=''
  200. DEV_DISK_LABEL=''
  201. DEV_DISK_MAPPER=''
  202. DEV_DISK_UUID=''
  203. DMIDECODE_DATA=''
  204. FILTER_STRING='<filter>'
  205. IRC_CLIENT=''
  206. IRC_CLIENT_VERSION=''
  207. LINE_MAX=''
  208. LINE_MAX_CONSOLE='115'
  209. LINE_MAX_IRC='105'
  210. PS_COUNT=5
  211. PS_THROTTLED=''
  212. REPO_DATA=''
  213. SED_I='-i' # for gnu sed, will be set to -i '' for bsd sed
  214. SED_RX='-r' # for gnu sed, will be set to -E for bsd sed for backward compatibility
  215. # change to less, or more if you have very slow connection
  216. WGET_TIMEOUT=8
  217.  
  218. ### primary data array holders ## usage: 'A_<var>'
  219. A_ALSA_DATA=''
  220. A_AUDIO_DATA=''
  221. A_CMDL=''
  222. A_CPU_CORE_DATA=''
  223. A_CPU_DATA=''
  224. A_CPU_TYPE_PCNT_CCNT=''
  225. A_DEBUG_BUFFER=''
  226. A_GCC_VERSIONS=''
  227. A_GFX_CARD_DATA=''
  228. A_GLX_DATA=''
  229. A_GRAPHIC_DRIVERS=''
  230. A_HDD_DATA=''
  231. A_INTERFACES_DATA=''
  232. A_MACHINE_DATA=''
  233. A_NETWORK_DATA=''
  234. A_OPTICAL_DRIVE_DATA=''
  235. A_PARTITION_DATA=''
  236. A_PCICONF_DATA=''
  237. A_PS_DATA=''
  238. A_RAID_DATA=''
  239. A_SENSORS_DATA=''
  240. A_UNMOUNTED_PARTITION_DATA=''
  241. A_WEATHER_DATA=''
  242. A_X_DATA=''
  243.  
  244. ### Boolean true/false globals ## usage: 'B_<var>'
  245. ## Distro maintainer flags ##
  246. # flag to allow distro maintainers to turn off update features. If false, turns off
  247. # -U and -! testing/advanced update options, as well as removing the -U help menu item
  248. B_ALLOW_UPDATE='true'
  249. B_ALLOW_WEATHER='true'
  250. ## standard boolean flags ##
  251. B_BSD_RAID='false'
  252. B_COLOR_SCHEME_SET='false'
  253. B_CONSOLE_IRC='false'
  254. # triggers full display of cpu flags
  255. B_CPU_FLAGS_FULL='false'
  256. # test for dbus irc client
  257. B_DBUS_CLIENT='false'
  258. # kde dcop
  259. B_DCOP='false'
  260. # Debug flood override: make 'true' to allow long debug output
  261. B_DEBUG_FLOOD='false'
  262. B_DMIDECODE_SET='false'
  263. # show extra output data
  264. B_EXTRA_DATA='false'
  265. # triggered by -xx
  266. B_EXTRA_EXTRA_DATA='false'
  267. B_ID_SET='false'
  268. # override certain errors due to currupted data
  269. B_HANDLE_CORRUPT_DATA='false'
  270. B_LABEL_SET='false'
  271. B_LSPCI='false'
  272. B_LOG_COLORS='false'
  273. B_LOG_FULL_DATA='false'
  274. B_MAPPER_SET='false'
  275. B_OUTPUT_FILTER='false'
  276. B_OVERRIDE_FILTER='false'
  277. B_PCICONF='false'
  278. B_PCICONF_SET='false'
  279. # kde qdbus
  280. B_QDBUS='false'
  281. B_PORTABLE='false'
  282. B_RAID_SET='false'
  283. B_ROOT='false'
  284. B_RUN_COLOR_SELECTOR='false'
  285. # Running in a shell? Defaults to false, and is determined later.
  286. B_RUNNING_IN_SHELL='false'
  287. if tty >/dev/null;then
  288. B_RUNNING_IN_SHELL='true'
  289. fi
  290. # this sets the debug buffer
  291. B_SCRIPT_UP='false'
  292. B_SHOW_ADVANCED_NETWORK='false'
  293. # Show sound card data
  294. B_SHOW_AUDIO='false'
  295. B_SHOW_BASIC_RAID='false'
  296. B_SHOW_BASIC_CPU='false'
  297. B_SHOW_BASIC_DISK='false'
  298. B_SHOW_BASIC_OPTICAL='false'
  299. B_SHOW_CPU='false'
  300. B_SHOW_DISK_TOTAL='false'
  301. B_SHOW_DISK='false'
  302. # Show full hard disk output
  303. B_SHOW_FULL_HDD='false'
  304. B_SHOW_FULL_OPTICAL='false'
  305. B_SHOW_GRAPHICS='false'
  306. # Set this to 'false' to avoid printing the hostname, can be set false now
  307. B_SHOW_HOST='true'
  308. B_SHOW_INFO='false'
  309. B_SHOW_IP='false'
  310. B_SHOW_LABELS='false'
  311. B_SHOW_MACHINE='false'
  312. B_SHOW_NETWORK='false'
  313. # either -v > 3 or -P will show partitions
  314. B_SHOW_PARTITIONS='false'
  315. B_SHOW_PARTITIONS_FULL='false'
  316. B_SHOW_PS_CPU_DATA='false'
  317. B_SHOW_PS_MEM_DATA='false'
  318. B_SHOW_RAID='false'
  319. # because many systems have no mdstat file, -b/-F should not show error if no raid file found
  320. B_SHOW_RAID_R='false'
  321. B_SHOW_REPOS='false'
  322. B_RUNNING_IN_X='false'
  323. B_SHOW_SENSORS='false'
  324. # triggers only short inxi output
  325. B_SHOW_SHORT_OUTPUT='false'
  326. B_SHOW_SYSTEM='false'
  327. B_SHOW_UNMOUNTED_PARTITIONS='false'
  328. B_SHOW_UUIDS='false'
  329. B_SHOW_WEATHER='false'
  330. B_SHOW_X_DATA='false'
  331. B_SYSCTL='false'
  332. # triggers various debugging and new option testing
  333. B_TESTING_1='false'
  334. B_TESTING_2='false'
  335. B_UPLOAD_DEBUG_DATA='false'
  336. B_USB_NETWORKING='false'
  337. # set to true here for debug logging from script start
  338. B_USE_LOGGING='false'
  339. B_UUID_SET='false'
  340. B_XORG_LOG='false'
  341.  
  342. ### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
  343. B_ASOUND_DEVICE_FILE='false'
  344. B_ASOUND_VERSION_FILE='false'
  345. B_BASH_ARRAY='false'
  346. B_CPUINFO_FILE='false'
  347. B_DMESG_BOOT_FILE='false' # bsd only
  348. B_LSB_FILE='false'
  349. B_MDSTAT_FILE='false'
  350. B_MEMINFO_FILE='false'
  351. B_MODULES_FILE='false' #
  352. B_MOUNTS_FILE='false'
  353. B_OS_RELEASE_FILE='false' # new default distro id file? will this one work where lsb-release didn't?
  354. B_PARTITIONS_FILE='false' #
  355. B_PROC_DIR='false'
  356. B_SCSI_FILE='false'
  357.  
  358. ### File's used when present
  359. FILE_ASOUND_DEVICE='/proc/asound/cards'
  360. FILE_ASOUND_MODULES='/proc/asound/modules' # not used but maybe for -A?
  361. FILE_ASOUND_VERSION='/proc/asound/version'
  362. FILE_CPUINFO='/proc/cpuinfo'
  363. FILE_DMESG_BOOT='/var/run/dmesg.boot'
  364. FILE_LSB_RELEASE='/etc/lsb-release'
  365. FILE_MDSTAT='/proc/mdstat'
  366. FILE_MEMINFO='/proc/meminfo'
  367. FILE_MODULES='/proc/modules'
  368. FILE_MOUNTS='/proc/mounts'
  369. FILE_OS_RELEASE='/etc/os-release'
  370. FILE_PARTITIONS='/proc/partitions'
  371. FILE_SCSI='/proc/scsi/scsi'
  372. FILE_XORG_LOG='/var/log/Xorg.0.log' # if not found, search and replace with actual location
  373.  
  374. ## app tested for and present, to avoid repeat tests
  375. B_FILE_TESTED='false'
  376. B_HDDTEMP_TESTED='false'
  377. B_MODINFO_TESTED='false'
  378. B_SUDO_TESTED='false'
  379. FILE_PATH=''
  380. HDDTEMP_PATH=''
  381. MODINFO_PATH=''
  382. SUDO_PATH=''
  383.  
  384. ### Variable initializations: constants
  385. DCOPOBJ="default"
  386. DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels)
  387. # Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up'
  388. DEBUG_BUFFER_INDEX=0
  389. ## note: the debugger rerouting to /dev/null has been moved to the end of the get_parameters function
  390. ## so -@[number] debug levels can be set if there is a failure, otherwise you can't even see the errors
  391.  
  392. # Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Use following variables in config
  393. # files to change defaults for each type, or global
  394. # Same as runtime parameter.
  395. DEFAULT_COLOR_SCHEME=2
  396. # Always leave these blank, these are only going to be set in inxi.conf files, that makes testing
  397. # for user changes easier after sourcing the files
  398. GLOBAL_COLOR_SCHEME=''
  399. IRC_COLOR_SCHEME=''
  400. IRC_CONS_COLOR_SCHEME=''
  401. IRC_X_TERM_COLOR_SCHEME=''
  402. CONSOLE_COLOR_SCHEME=''
  403. VIRT_TERM_COLOR_SCHEME=''
  404.  
  405. # Default indentation level
  406. INDENT=10
  407.  
  408. # logging eval variables, start and end function: Insert to LOGFS LOGFE when debug level >= 8
  409. LOGFS_STRING='log_function_data fs $FUNCNAME "$( echo $@ )"'
  410. LOGFE_STRING='log_function_data fe $FUNCNAME'
  411. LOGFS=''
  412. LOGFE=''
  413. # uncomment for debugging from script start
  414. # LOGFS=$LOGFS_STRING
  415. # LOGFE=$LOGFE_STRING
  416.  
  417. # default to false, no konversation found, 1 is native konvi (qt3/KDE3) script mode, 2 is /cmd inxi start,
  418. ## 3 is Konversation > 1.2 (qt4/KDE4)
  419. KONVI=0
  420. # NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
  421. # This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
  422. PARAMETER_LIMIT=30
  423. SCHEME=0 # set default scheme - do not change this, it's set dynamically
  424. # this is set in user prefs file, to override dynamic temp1/temp2 determination of sensors output in case
  425. # cpu runs colder than mobo
  426. SENSORS_CPU_NO=''
  427. # SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
  428. SHOW_IRC=2
  429. # Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
  430. VERBOSITY_LEVEL=0
  431. # Supported number of verbosity levels, including 0
  432. VERBOSITY_LEVELS=7
  433.  
  434. # Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
  435. # type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
  436. # therefore results in nothing.
  437. shopt -u nullglob
  438. ## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
  439. # Backup the current Internal Field Separator
  440. ORIGINAL_IFS="$IFS"
  441.  
  442. # These two determine separators in single line output, to force irc clients not to break off sections
  443. SEP1='~'
  444. SEP2=' '
  445. # these will assign a separator to non irc states. Important! Using ':' can trigger stupid emoticon
  446. # behaviors in output on IRC, so do not use those.
  447. SEP3_IRC=''
  448. SEP3_CONSOLE=':'
  449. SEP3='' # do not set, will be set dynamically
  450.  
  451. ### Script names/paths - must be non root writable
  452. SCRIPT_DATA_DIR="$HOME/.inxi"
  453. ALTERNATE_FTP='' # for data uploads
  454. ALTERNATE_WEATHER_LOCATION='' # weather alternate location
  455. LOG_FILE="$SCRIPT_DATA_DIR/inxi.log"
  456. LOG_FILE_1="$SCRIPT_DATA_DIR/inxi.1.log"
  457. LOG_FILE_2="$SCRIPT_DATA_DIR/inxi.2.log"
  458. MAN_FILE_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/inxi.1.gz'
  459. MAN_FILE_LOCATION='/usr/share/man/man1'
  460. SCRIPT_NAME='inxi'
  461. SCRIPT_PATCH_NUMBER=''
  462. SCRIPT_PATH='' #filled-in in Main
  463. SCRIPT_VERSION_NUMBER="" #filled-in in Main
  464. SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
  465. SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
  466. SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
  467. SCRIPT_DOWNLOAD_BRANCH_3='http://inxi.googlecode.com/svn/branches/three/'
  468. SCRIPT_DOWNLOAD_BRANCH_4='http://inxi.googlecode.com/svn/branches/four/'
  469. SCRIPT_DOWNLOAD_BRANCH_BSD='http://inxi.googlecode.com/svn/branches/bsd/'
  470. SCRIPT_DOWNLOAD_BRANCH_GNUBSD='http://inxi.googlecode.com/svn/branches/gnubsd/'
  471. SCRIPT_DOWNLOAD_DEV='http://smxi.org/test/'
  472. # note, you can use any ip url here as long as it's the only line on the output page.
  473. # Also the ip address must be the last thing on that line.
  474. WAN_IP_URL='http://smxi.org/opt/ip.php'
  475. KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data)
  476.  
  477. ### Script Localization
  478. # Make sure every program speaks English.
  479. LC_ALL="C"
  480. export LC_ALL
  481.  
  482. ### Output Colors
  483. # A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
  484. unset EMPTY
  485. # DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW
  486. ANSI_COLORS="       "
  487. IRC_COLORS=" \x0314 \x0301 \x0304 \x0305 \x0309 \x0303 \x0308 \x0307"
  488. # BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL
  489. ANSI_COLORS="$ANSI_COLORS         "
  490. IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300 \x0315 \x03"
  491.  
  492. #ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
  493. A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL )
  494.  
  495. # See above for notes on EMPTY
  496. ## note: group 1: 0, 1 are null/normal
  497. ## Following: group 2: generic, light/dark or dark/light; group 3: dark on light; group 4 light on dark;
  498. # this is the count of the first two groups, starting at zero
  499. SAFE_COLOR_COUNT=12
  500. A_COLOR_SCHEMES=(
  501. EMPTY,EMPTY,EMPTY
  502. NORMAL,NORMAL,NORMAL
  503.  
  504. BLUE,NORMAL,NORMAL
  505. BLUE,RED,NORMAL
  506. CYAN,BLUE,NORMAL
  507. DCYAN,NORMAL,NORMAL
  508. DCYAN,BLUE,NORMAL
  509. DGREEN,NORMAL,NORMAL
  510. DYELLOW,NORMAL,NORMAL
  511. GREEN,DGREEN,NORMAL
  512. GREEN,NORMAL,NORMAL
  513. MAGENTA,NORMAL,NORMAL
  514. RED,NORMAL,NORMAL
  515.  
  516. BLACK,DGREY,NORMAL
  517. DBLUE,DGREY,NORMAL
  518. DBLUE,DMAGENTA,NORMAL
  519. DBLUE,DRED,NORMAL
  520. DBLUE,BLACK,NORMAL
  521. DGREEN,DYELLOW,NORMAL
  522. DYELLOW,BLACK,NORMAL
  523. DMAGENTA,BLACK,NORMAL
  524. DCYAN,DBLUE,NORMAL
  525.  
  526. WHITE,GREY,NORMAL
  527. GREY,WHITE,NORMAL
  528. CYAN,GREY,NORMAL
  529. GREEN,WHITE,NORMAL
  530. GREEN,YELLOW,NORMAL
  531. YELLOW,WHITE,NORMAL
  532. MAGENTA,CYAN,NORMAL
  533. MAGENTA,YELLOW,NORMAL
  534. RED,CYAN,NORMAL
  535. RED,WHITE,NORMAL
  536. BLUE,WHITE,NORMAL
  537. )
  538.  
  539. ## Actual color variables
  540. C1=''
  541. C2=''
  542. CN=''
  543.  
  544. ### Distro Data
  545. # In cases of derived distros where the version file of the base distro can also be found under /etc,
  546. # the derived distro's version file should go first. (Such as with Sabayon / Gentoo)
  547. DISTROS_DERIVED="antix-version aptosid-version kanotix-version knoppix-version mandrake-release pardus-release sabayon-release siduction-version sidux-version solusos-release turbolinux-release zenwalk-version"
  548. # debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
  549. DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
  550. DISTROS_PRIMARY="arch-release gentoo-release redhat-release slackware-version SuSE-release"
  551. DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
  552. # this is being used both by core distros and derived distros now, eg, solusos 1 uses it for solusos id, while
  553. # debian, solusos base, uses it as well, so we have to know which it is.
  554. DISTROS_OS_RELEASE_GOOD="arch-release SuSE-release"
  555. ## Distros with known problems
  556. # DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
  557. # Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
  558.  
  559. ### Bans Data
  560. # Note that \<ltd\> bans only words, not parts of strings; in \<corp\> you can't use punctuation characters like . or ,
  561. # we're saving about 10+% of the total script exec time by hand building the ban lists here, using hard quotes.
  562. BAN_LIST_NORMAL='chipset|components|computing|computer|corporation|communications|electronics|electrical|electric|gmbh|group|industrial|international|revision|semiconductor|software|technologies|technology|ltd\.|\<ltd\>|inc\.|\<inc\>|intl\.|co\.|\<co\>|corp\.|\<corp\>|\(tm\)|\(r\)|®|\(rev ..\)'
  563. BAN_LIST_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]'
  564.  
  565. SENSORS_GPU_SEARCH='intel|radeon|nouveau'
  566.  
  567. ### USB networking search string data, because some brands can have other products than
  568. ### wifi/nic cards, they need further identifiers, with wildcards.
  569. ### putting the most common and likely first, then the less common, then some specifics
  570. 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"
  571. 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"
  572. # then a few known hard to ID ones added
  573. # belkin=050d; d-link=07d1; netgear=0846; ralink=148f; realtek=0bda;
  574. USB_NETWORK_SEARCH="$USB_NETWORK_SEARCH|050d:935b|0bda:8189|0bda:8197"
  575.  
  576. # WARNING: In the main part below (search for 'KONVI')
  577. # there's a check for Konversation-specific config files.
  578. # Any one of these can override the above if inxi is run
  579. # from Konversation!
  580.  
  581. ########################################################################
  582. #### MAIN: Where it all begins
  583. ########################################################################
  584. main()
  585. {
  586. eval $LOGFS
  587.  
  588. local color_scheme=''
  589. # this will be used by all functions following
  590. local Ps_aux_Data="$( ps aux )"
  591.  
  592. # This function just initializes variables
  593. initialize_data
  594.  
  595. # Source global config overrides, needs to be here because some things
  596. # can be reset that were set in initialize, but check_required_apps needs
  597. if [[ -s /etc/$SCRIPT_NAME.conf ]];then
  598. source /etc/$SCRIPT_NAME.conf
  599. fi
  600. # Source user config variables override /etc/inxi.conf variables
  601. if [[ -s $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf ]];then
  602. source $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf
  603. fi
  604.  
  605. # Check for dependencies BEFORE running ANYTHING else except above functions
  606. # Not all distro's have these depends installed by default. Don't want to run
  607. # this if the user is requesting to see this information in the first place
  608. # Only continue if required apps tests ok
  609. if [[ $1 != '--recommends' ]];then
  610. check_required_apps
  611. check_recommended_apps
  612. fi
  613.  
  614. SCRIPT_VERSION_NUMBER=$( parse_version_data 'main' )
  615. SCRIPT_PATCH_NUMBER=$( parse_version_data 'patch' )
  616.  
  617. # previous source location, check for bugs
  618.  
  619. ## this needs to run before the KONVI stuff is set below
  620. ## Konversation 1.2 apparently does not like the $PPID test in get_start_client
  621. ## So far there is no known way to detect if qt4_konvi is the parent process
  622. ## this method will infer qt4_konvi as parent
  623. get_start_client
  624.  
  625. # note: this only works if it's run from inside konversation as a script builtin or something
  626. # only do this if inxi has been started as a konversation script, otherwise bypass this
  627. # KONVI=3 ## for testing puroses
  628. if [[ $KONVI -eq 1 || $KONVI -eq 3 ]];then
  629. if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (ie 1.x < 1.2(qt3))
  630. DCPORT="$1"
  631. DCSERVER="$2"
  632. DCTARGET="$3"
  633. shift 3
  634. elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
  635. DCSERVER="$1" ##dbus testing
  636. DCTARGET="$2" ##dbus testing
  637. shift 2
  638. fi
  639.  
  640. # The section below is on request of Argonel from the Konversation developer team:
  641. # it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf
  642. IFS=":"
  643. for kde_config in $( kde-config --path data )
  644. do
  645. if [[ -r ${kde_config}${KONVI_CFG} ]];then
  646. source "${kde_config}${KONVI_CFG}"
  647. break
  648. fi
  649. done
  650. IFS="$ORIGINAL_IFS"
  651. fi
  652.  
  653. ## leave this for debugging dcop stuff if we get that working
  654. # print_screen_output "DCPORT: $DCPORT"
  655. # print_screen_output "DCSERVER: $DCSERVER"
  656. # print_screen_output "DCTARGET: $DCTARGET"
  657.  
  658. # first init function must be set first for colors etc. Remember, no debugger
  659. # stuff works on this function unless you set the debugging flag manually.
  660. # Debugging flag -@ [number] will not work until get_parameters runs.
  661.  
  662. # "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
  663. # must be here to allow debugger and other flags to be set.
  664. get_parameters "$@"
  665.  
  666. # If no colorscheme was set in the parameter handling routine, then set the default scheme
  667. if [[ $B_COLOR_SCHEME_SET != 'true' ]];then
  668. # This let's user pick their color scheme. For IRC, only shows the color schemes, no interactive
  669. # The override value only will be placed in user config files. /etc/inxi.conf can also override
  670. if [[ $B_RUN_COLOR_SELECTOR == 'true' ]];then
  671. select_default_color_scheme
  672. else
  673. # set the default, then override as required
  674. color_scheme=$DEFAULT_COLOR_SCHEME
  675. if [[ -n $GLOBAL_COLOR_SCHEME ]];then
  676. color_scheme=$GLOBAL_COLOR_SCHEME
  677. else
  678. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  679. if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then
  680. color_scheme=$CONSOLE_COLOR_SCHEME
  681. elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
  682. color_scheme=$VIRT_TERM_COLOR_SCHEME
  683. fi
  684. else
  685. if [[ -n $IRC_X_TERM_COLOR_SCHEME && $B_CONSOLE_IRC == 'true' && -n $B_RUNNING_IN_X ]];then
  686. color_scheme=$IRC_X_TERM_COLOR_SCHEME
  687. elif [[ -n $IRC_CONS_COLOR_SCHEME && -z $DISPLAY ]];then
  688. color_scheme=$IRC_CONS_COLOR_SCHEME
  689. elif [[ -n $IRC_COLOR_SCHEME ]];then
  690. color_scheme=$IRC_COLOR_SCHEME
  691. fi
  692. fi
  693. fi
  694. set_color_scheme $color_scheme
  695. fi
  696. fi
  697. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  698. LINE_MAX=$LINE_MAX_CONSOLE
  699. SEP3=$SEP3_CONSOLE
  700. else
  701. # too hard to read if no colors, so force that for users on irc
  702. if [[ $SCHEME == 0 ]];then
  703. SEP3=$SEP3_CONSOLE
  704. else
  705. SEP3=$SEP3_IRC
  706. fi
  707. LINE_MAX=$LINE_MAX_IRC
  708. fi
  709.  
  710. # all the pre-start stuff is in place now
  711. B_SCRIPT_UP='true'
  712. script_debugger "Debugger: $SCRIPT_NAME is up and running..."
  713.  
  714. # then create the output
  715. print_it_out
  716.  
  717. ## last steps
  718. if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
  719. echo -n ""
  720. fi
  721. eval $LOGFE
  722. # weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
  723. # from the last command is taken..
  724. exit 0
  725. }
  726.  
  727. #### -------------------------------------------------------------------
  728. #### basic tests: set script data, booleans, PATH, version numbers
  729. #### -------------------------------------------------------------------
  730.  
  731. # Set PATH data so we can access all programs as user. Set BAN lists.
  732. # initialize some boleans, these directories are used throughout the script
  733. # some apps are used for extended functions any directory used, should be
  734. # checked here first.
  735. # No args taken.
  736. initialize_data()
  737. {
  738. eval $LOGFS
  739. BSD_VERSION=$( uname -s 2>/dev/null | tr '[A-Z]' '[a-z]' )
  740.  
  741. # note: archbsd says they are a freebsd distro, so assuming it's the same as freebsd
  742. if [[ -n $( grep 'bsd' <<< "$BSD_VERSION" ) ]];then
  743. # GNU/kfreebsd will by definition have GNU tools like sed/grep
  744. if [[ -n $( grep 'kfreebsd' <<< "$BSD_VERSION" ) ]];then
  745. BSD_TYPE='debian-bsd' # debian gnu bsd
  746. else
  747. BSD_TYPE='bsd' # all other bsds
  748. SED_I="-i ''"
  749. SED_RX='-E'
  750. fi
  751. fi
  752. # now set the script BOOLEANS for files required to run features
  753. # note that freebsd has /proc but it's empty
  754. if [[ -d "/proc/" && -z $BSD_TYPE ]];then
  755. B_PROC_DIR='true'
  756. elif [[ -n $BSD_TYPE ]];then
  757. B_PROC_DIR='false'
  758. else
  759. error_handler 6
  760. fi
  761.  
  762. initialize_paths
  763.  
  764. if [[ -n $BSD_TYPE ]];then
  765. if [[ -e $FILE_DMESG_BOOT ]];then
  766. B_DMESG_BOOT_FILE='true'
  767. fi
  768. else
  769. # found a case of battery existing but having nothing in it on desktop mobo
  770. # not all laptops show the first,
  771. if [[ -n $( ls /proc/acpi/battery 2>/dev/null ) ]];then
  772. B_PORTABLE='true'
  773. fi
  774. fi
  775.  
  776.  
  777. if [[ -e $FILE_CPUINFO ]]; then
  778. B_CPUINFO_FILE='true'
  779. fi
  780.  
  781. if [[ -e $FILE_MEMINFO ]];then
  782. B_MEMINFO_FILE='true'
  783. fi
  784.  
  785. if [[ -e $FILE_ASOUND_DEVICE ]];then
  786. B_ASOUND_DEVICE_FILE='true'
  787. fi
  788.  
  789. if [[ -e $FILE_ASOUND_VERSION ]];then
  790. B_ASOUND_VERSION_FILE='true'
  791. fi
  792.  
  793. if [[ -f $FILE_LSB_RELEASE ]];then
  794. B_LSB_FILE='true'
  795. fi
  796.  
  797. if [[ -f $FILE_OS_RELEASE ]];then
  798. B_OS_RELEASE_FILE='true'
  799. fi
  800.  
  801. if [[ -e $FILE_SCSI ]];then
  802. B_SCSI_FILE='true'
  803. fi
  804.  
  805. if [[ -n $DISPLAY ]];then
  806. B_SHOW_X_DATA='true'
  807. B_RUNNING_IN_X='true'
  808. fi
  809.  
  810. if [[ -e $FILE_MDSTAT ]];then
  811. B_MDSTAT_FILE='true'
  812. fi
  813.  
  814. if [[ -e $FILE_MODULES ]];then
  815. B_MODULES_FILE='true'
  816. fi
  817.  
  818. if [[ -e $FILE_MOUNTS ]];then
  819. B_MOUNTS_FILE='true'
  820. fi
  821.  
  822. if [[ -e $FILE_PARTITIONS ]];then
  823. B_PARTITIONS_FILE='true'
  824. fi
  825. # default to the normal location, then search for it
  826. if [[ -e $FILE_XORG_LOG ]];then
  827. B_XORG_LOG='true'
  828. else
  829. # Detect location of the Xorg log file
  830. if [[ -n $( type -p xset ) ]]; then
  831. FILE_XORG_LOG=$( xset q 2>/dev/null | grep -i 'Log file' | gawk '{print $3}')
  832. if [[ -e $FILE_XORG_LOG ]];then
  833. B_XORG_LOG='true'
  834. fi
  835. fi
  836. fi
  837. # gfx output will require this flag
  838. if [[ $( whoami ) == 'root' ]];then
  839. B_ROOT='true'
  840. fi
  841. eval $LOGFE
  842. }
  843.  
  844. # arg: $1 - version number: main/patch/date
  845. parse_version_data()
  846. {
  847. local version_data=''
  848.  
  849. # note, using ####[[:space:]]+ to avoid having this function also trip the version datas
  850. case $1 in
  851. date)
  852. version_data="$( gawk -F ': ' '
  853. /####[[:space:]]+Date:/ {
  854. print $NF
  855. }' $SCRIPT_PATH/$SCRIPT_NAME )"
  856. ;;
  857. main)
  858. version_data="$( gawk '
  859. /####[[:space:]]+Version:/ {
  860. print $3
  861. }' $SCRIPT_PATH/$SCRIPT_NAME )"
  862. ;;
  863. patch)
  864. version_data="$( gawk '
  865. /####[[:space:]]+Patch Number:/ {
  866. print $4
  867. }' $SCRIPT_PATH/$SCRIPT_NAME )"
  868. ;;
  869. esac
  870. echo $version_data
  871. }
  872.  
  873. initialize_paths()
  874. {
  875. local path='' added_path='' b_path_found='' sys_path=''
  876. # Extra path variable to make execute failures less likely, merged below
  877. local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
  878.  
  879. # this needs to be set here because various options call the parent initialize function directly.
  880. SCRIPT_PATH=$( dirname $0 )
  881.  
  882. # Fallback paths put into $extra_paths; This might, among others, help on gentoo.
  883. # Now, create a difference of $PATH and $extra_paths and add that to $PATH:
  884. IFS=":"
  885. for path in $extra_paths
  886. do
  887. b_path_found='false'
  888. for sys_path in $PATH
  889. do
  890. if [[ $path == $sys_path ]];then
  891. b_path_found='true'
  892. fi
  893. done
  894. if [[ $b_path_found == 'false' ]];then
  895. added_path="$added_path:$path"
  896. fi
  897. done
  898.  
  899. IFS="$ORIGINAL_IFS"
  900. PATH="${PATH}${added_path}"
  901. ##echo "PATH='$PATH'"
  902. ##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
  903. }
  904.  
  905. # No args taken.
  906. check_recommended_apps()
  907. {
  908. eval $LOGFS
  909. local bash_array_test=( "one" "two" )
  910.  
  911. # check for array ability of bash, this is only good for the warning at this time
  912. # the boolean could be used later
  913. # bash version 2.05b is used in DSL
  914. # bash version 3.0 is used in Puppy Linux; it has a known array bug <reference to be placed here>
  915. # versions older than 3.1 don't handle arrays
  916. # distro's using below 2.05b are unknown, released in 2002
  917. if [[ ${bash_array_test[1]} -eq "two" ]];then
  918. B_BASH_ARRAY='true'
  919. else
  920. script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output"
  921. fi
  922. # test for a few apps that bsds may not have after initial tests
  923. if [[ -n $( type -p lspci ) ]];then
  924. B_LSPCI='true'
  925. fi
  926. if [[ -n $BSD_TYPE ]];then
  927. if [[ -n $( type -p sysctl ) ]];then
  928. B_SYSCTL='true'
  929. fi
  930. if [[ -n $( type -p pciconf ) ]];then
  931. B_PCICONF='true'
  932. fi
  933. fi
  934. # now setting qdbus/dcop for first run, some systems can have both by the way
  935. if [[ -n $( type -p qdbus ) ]];then
  936. B_QDBUS='true'
  937. fi
  938. if [[ -n $( type -p dcop ) ]];then
  939. B_DCOP='true'
  940. fi
  941. eval $LOGFE
  942. }
  943.  
  944. # Determine if any of the absolutely necessary tools are absent
  945. # No args taken.
  946. check_required_apps()
  947. {
  948. eval $LOGFS
  949. local app_name='' app_path=''
  950. # bc removed from deps for now
  951. local depends="df gawk grep ps readlink tr uname uptime wc"
  952.  
  953. if [[ -z $BSD_TYPE ]];then
  954. depends="$depends lspci"
  955. elif [[ $BSD_TYPE == 'bsd' ]];then
  956. depends="$depends sysctl"
  957. # debian-bsd has lspci but you must be root to run it
  958. elif [[ $BSD_TYPE == 'debian-bsd' ]];then
  959. depends="$depends sysctl lspci"
  960. fi
  961. # no need to add xprop because it will just give N/A if not there, but if we expand use of xprop,
  962. # should add that here as a test, then use the B_SHOW_X_DATA flag to trigger the tests in de function
  963. local x_apps="xrandr xdpyinfo glxinfo"
  964.  
  965. if [[ $B_RUNNING_IN_X == 'true' ]];then
  966. for app_name in $x_apps
  967. do
  968. app_path=$( type -p $app_name )
  969. if [[ -z $app_path ]];then
  970. script_debugger "Resuming in non X mode: $app_name not found. For package install advice run: $SCRIPT_NAME --recommends"
  971. B_SHOW_X_DATA='false'
  972. break
  973. fi
  974. done
  975. fi
  976.  
  977. app_name=''
  978.  
  979. for app_name in $depends
  980. do
  981. app_path=$( type -p $app_name )
  982. if [[ -z $app_path ]];then
  983. error_handler 5 "$app_name"
  984. fi
  985. done
  986. eval $LOGFE
  987. }
  988.  
  989. ## note: this is now running inside each gawk sequence directly to avoid exiting gawk
  990. ## looping in bash through arrays, then re-entering gawk to clean up, then writing back to array
  991. ## in bash. For now I'll leave this here because there's still some interesting stuff to get re methods
  992. # Enforce boilerplate and buzzword filters
  993. # args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
  994. sanitize_characters()
  995. {
  996. eval $LOGFS
  997. # Cannot use strong quotes to unquote a string with pipes in it!
  998. # bash will interpret the |'s as usual and try to run a subshell!
  999. # Using weak quotes instead, or use '"..."'
  1000. echo "$2" | gawk "
  1001. BEGIN {
  1002. IGNORECASE=1
  1003. }
  1004. {
  1005. gsub(/${!1}/,\"\")
  1006. gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
  1007. gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
  1008. print ## prints (returns) cleaned input
  1009. }"
  1010. eval $LOGFE
  1011. }
  1012.  
  1013. # Set the colorscheme
  1014. # args: $1 = <scheme number>|<"none">
  1015. set_color_scheme()
  1016. {
  1017. eval $LOGFS
  1018. local i='' a_output_colors='' a_color_codes=''
  1019.  
  1020. if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then
  1021. set -- 1
  1022. fi
  1023. # Set a global variable to allow checking for chosen scheme later
  1024. SCHEME="$1"
  1025. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  1026. a_color_codes=( $ANSI_COLORS )
  1027. else
  1028. a_color_codes=( $IRC_COLORS )
  1029. fi
  1030. for (( i=0; i < ${#A_COLORS_AVAILABLE[@]}; i++ ))
  1031. do
  1032. eval "${A_COLORS_AVAILABLE[i]}=\"${a_color_codes[i]}\""
  1033. done
  1034. IFS=","
  1035. a_output_colors=( ${A_COLOR_SCHEMES[$1]} )
  1036. IFS="$ORIGINAL_IFS"
  1037. # then assign the colors globally
  1038. C1="${!a_output_colors[0]}"
  1039. C2="${!a_output_colors[1]}"
  1040. CN="${!a_output_colors[2]}"
  1041. # ((COLOR_SCHEME++)) ## note: why is this? ##
  1042. eval $LOGFE
  1043. }
  1044.  
  1045. select_default_color_scheme()
  1046. {
  1047. eval $LOGFS
  1048. local spacer=' ' options='' user_selection='' config_variable=''
  1049. local config_file="$HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf"
  1050. local irc_clear=""
  1051. local irc_gui='Unset' irc_console='Unset' irc_x_term='Unset'
  1052. local console='Unset' virt_term='Unset' global='Unset'
  1053.  
  1054. if [[ -n $IRC_COLOR_SCHEME ]];then
  1055. irc_gui="Set: $IRC_COLOR_SCHEME"
  1056. fi
  1057. if [[ -n $IRC_CONS_COLOR_SCHEME ]];then
  1058. irc_console="Set: $IRC_CONS_COLOR_SCHEME"
  1059. fi
  1060. if [[ -n $IRC_X_TERM_COLOR_SCHEME ]];then
  1061. irc_x_term="Set: $IRC_X_TERM_COLOR_SCHEME"
  1062. fi
  1063. if [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
  1064. virt_term="Set: $VIRT_TERM_COLOR_SCHEME"
  1065. fi
  1066. if [[ -n $CONSOLE_COLOR_SCHEME ]];then
  1067. console="Set: $CONSOLE_COLOR_SCHEME"
  1068. fi
  1069. if [[ -n $GLOBAL_COLOR_SCHEME ]];then
  1070. global="Set: $GLOBAL_COLOR_SCHEME"
  1071. fi
  1072.  
  1073. # don't want these printing in irc since they show literally
  1074. if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
  1075. irc_clear=''
  1076. fi
  1077. # first make output neutral so it's just plain default for console client
  1078. set_color_scheme "0"
  1079. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  1080. print_screen_output "Welcome to $SCRIPT_NAME! Please select the default $COLOR_SELECTION color scheme."
  1081. # print_screen_output "You will see this message only one time per user account, unless you set preferences in: /etc/$SCRIPT_NAME.conf"
  1082. print_screen_output " "
  1083. fi
  1084. print_screen_output "Because there is no way to know your $COLOR_SELECTION foreground/background colors, you can"
  1085. print_screen_output "set your color preferences from color scheme option list below. 0 is no colors, 1 neutral."
  1086. print_screen_output "After these, there are 3 sets: 1-dark or light backgrounds; 2-light backgrounds; 3-dark backgrounds."
  1087. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  1088. print_screen_output "Please note that this will set the $COLOR_SELECTION preferences only for user: $(whoami)"
  1089. fi
  1090. print_screen_output "------------------------------------------------------------------------------"
  1091. for (( i=0; i < ${#A_COLOR_SCHEMES[@]}; i++ ))
  1092. do
  1093. if [[ $i -gt 9 ]];then
  1094. spacer=' '
  1095. fi
  1096. # only offer the safe universal defaults
  1097. case $COLOR_SELECTION in
  1098. global|irc|irc-console|irc-virtual-terminal)
  1099. if [[ $i -gt $SAFE_COLOR_COUNT ]];then
  1100. break
  1101. fi
  1102. ;;
  1103. esac
  1104. set_color_scheme $i
  1105. print_screen_output "$irc_clear $i)$spacer${C1}Card:${C2} nVidia G86 [GeForce 8400 GS] ${C1}X.Org${C2} 1.7.7"
  1106. done
  1107. set_color_scheme 0
  1108.  
  1109. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  1110. echo -n ""
  1111. print_screen_output "$irc_clear $i)${spacer}Remove all color settings. Restore $SCRIPT_NAME default."
  1112. print_screen_output "$irc_clear $(($i+1)))${spacer}Continue, no changes or config file setting."
  1113. print_screen_output "$irc_clear $(($i+2)))${spacer}Exit, use another terminal, or set manually."
  1114. print_screen_output "------------------------------------------------------------------------------"
  1115. print_screen_output "Simply type the number for the color scheme that looks best to your eyes for your $COLOR_SELECTION settings"
  1116. print_screen_output "and hit ENTER. NOTE: You can bring this option list up by starting $SCRIPT_NAME with option: -c plus one of these numbers:"
  1117. print_screen_output "94 (console, no X - $console); 95 (terminal, X - $virt_term); 96 (irc, gui, X - $irc_gui);"
  1118. print_screen_output "97 (irc, X, in terminal - $irc_x_term); 98 (irc, no X - $irc_console); 99 (global - $global)"
  1119. print_screen_output "Your selection(s) will be stored here: $config_file"
  1120. print_screen_output "Global overrides all individual color schemes. Individual schemes remove the global setting."
  1121. print_screen_output "------------------------------------------------------------------------------"
  1122. read user_selection
  1123. if [[ -n $( grep -Es '^([0-9]+)$' <<< "$user_selection" ) && $user_selection -lt $i ]];then
  1124. case $COLOR_SELECTION in
  1125. irc)
  1126. config_variable='IRC_COLOR_SCHEME'
  1127. ;;
  1128. irc-console)
  1129. config_variable='IRC_CONS_COLOR_SCHEME'
  1130. ;;
  1131. irc-virtual-terminal)
  1132. config_variable='IRC_X_TERM_COLOR_SCHEME'
  1133. ;;
  1134. console)
  1135. config_variable='CONSOLE_COLOR_SCHEME'
  1136. ;;
  1137. virtual-terminal)
  1138. config_variable='VIRT_TERM_COLOR_SCHEME'
  1139. ;;
  1140. global)
  1141. config_variable='GLOBAL_COLOR_SCHEME'
  1142. ;;
  1143. esac
  1144. set_color_scheme $user_selection
  1145. # make file/directory first if missing
  1146. if [[ ! -f $config_file ]];then
  1147. if [[ ! -d $HOME/.$SCRIPT_NAME ]];then
  1148. mkdir $HOME/.$SCRIPT_NAME
  1149. fi
  1150. touch $config_file
  1151. fi
  1152. if [[ -z $( grep -s "$config_variable=" $config_file ) ]];then
  1153. print_screen_output "Creating and updating config file for $COLOR_SELECTION color scheme now..."
  1154. echo "$config_variable=$user_selection" >> $config_file
  1155. else
  1156. print_screen_output "Updating config file for $COLOR_SELECTION color scheme now..."
  1157. sed $SED_I "s/$config_variable=.*/$config_variable=$user_selection/" $config_file
  1158. fi
  1159. # file exists now so we can go on to cleanup
  1160. case $COLOR_SELECTION in
  1161. irc|irc-console|irc-virtual-terminal|console|virtual-terminal)
  1162. sed $SED_I '/GLOBAL_COLOR_SCHEME=/d' $config_file
  1163. ;;
  1164. global)
  1165. sed $SED_I -e '/VIRT_TERM_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' -e '/IRC_COLOR_SCHEME=/d' \
  1166. -e '/IRC_CONS_COLOR_SCHEME=/d' -e '/IRC_X_TERM_COLOR_SCHEME=/d' $config_file
  1167. ;;
  1168. esac
  1169. elif [[ $user_selection == $i ]];then
  1170. print_screen_output "Removing all color settings from config file now..."
  1171. sed $SED_I -e '/VIRT_TERM_COLOR_SCHEME=/d' -e '/GLOBAL_COLOR_SCHEME=/d' -e '/CONSOLE_COLOR_SCHEME=/d' \
  1172. -e '/IRC_COLOR_SCHEME=/d' -e '/IRC_CONS_COLOR_SCHEME=/d' -e '/IRC_X_TERM_COLOR_SCHEME=/d' $config_file
  1173. set_color_scheme $DEFAULT_COLOR_SCHEME
  1174. elif [[ $user_selection == $(( $i+1 )) ]];then
  1175. print_screen_output "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 95 to 99"
  1176. if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then
  1177. set_color_scheme $CONSOLE_COLOR_SCHEME
  1178. elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then
  1179. set_color_scheme $VIRT_TERM_COLOR_SCHEME
  1180. else
  1181. set_color_scheme $DEFAULT_COLOR_SCHEME
  1182. fi
  1183. elif [[ $user_selection == $(( $i+2 )) ]];then
  1184. set_color_scheme $DEFAULT_COLOR_SCHEME
  1185. print_screen_output "Ok, exiting $SCRIPT_NAME now. You can set the colors later."
  1186. exit 0
  1187. else
  1188. print_screen_output "Error - Invalid Selection. You entered this: $user_selection"
  1189. print_screen_output " "
  1190. select_default_color_scheme
  1191. fi
  1192. else
  1193. print_screen_output "------------------------------------------------------------------------------"
  1194. print_screen_output "After finding the scheme number you like, simply run this again in a terminal to set the configuration"
  1195. print_screen_output "data file for your irc client. You can set color schemes for the following: start inxi with -c plus:"
  1196. print_screen_output "94 (console, no X - $console); 95 (terminal, X - $virt_term); 96 (irc, gui, X - $irc_gui);"
  1197. print_screen_output "97 (irc, X, in terminal - $irc_x_term); 98 (irc, no X - $irc_console); 99 (global - $global)"
  1198. exit 0
  1199. fi
  1200.  
  1201. eval $LOGFE
  1202. }
  1203.  
  1204. ########################################################################
  1205. #### UTILITY FUNCTIONS
  1206. ########################################################################
  1207.  
  1208. #### -------------------------------------------------------------------
  1209. #### error handler, debugger, script updater
  1210. #### -------------------------------------------------------------------
  1211.  
  1212. # Error handling
  1213. # args: $1 - error number; $2 - optional, extra information; $3 - optional extra info
  1214. error_handler()
  1215. {
  1216. eval $LOGFS
  1217. local error_message=''
  1218.  
  1219. # assemble the error message
  1220. case $1 in
  1221. 2) error_message="large flood danger, debug buffer full!"
  1222. ;;
  1223. 3) error_message="unsupported color scheme number: $2"
  1224. ;;
  1225. 4) error_message="unsupported verbosity level: $2"
  1226. ;;
  1227. 5) error_message="dependency not met: $2 not found in path.\nFor distribution installation package names and missing apps information, run: $SCRIPT_NAME --recommends"
  1228. ;;
  1229. 6) error_message="/proc not found! Quitting..."
  1230. ;;
  1231. 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"
  1232. ;;
  1233. 8) error_message="the self-updater failed, wget exited with error: $2.\nYou probably need to be root.\nHint, to make for easy updates without being root, do: chown <user name> $SCRIPT_PATH/$SCRIPT_NAME"
  1234. ;;
  1235. 9) error_message="unsupported debugging level: $2"
  1236. ;;
  1237. 10)
  1238. 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/"
  1239. ;;
  1240. 11)
  1241. error_message="unsupported testing option argument: -! $2"
  1242. ;;
  1243. 12)
  1244. error_message="the svn branch download url: $2\nappears to be empty currently. Make sure there is an actual svn branch version\nactive before you try this again. Check http://code.google.com/p/inxi\nto verify the branch status."
  1245. ;;
  1246. 13)
  1247. 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"
  1248. ;;
  1249. 14)
  1250. 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"
  1251. ;;
  1252. 15)
  1253. 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"
  1254. ;;
  1255. 16)
  1256. error_message="$SCRIPT_NAME downloaded but the file data is corrupted. Purged data and using current version."
  1257. ;;
  1258. 17)
  1259. error_message="All $SCRIPT_NAME self updater features have been disabled by the distribution\npackage maintainer. This includes the option you used: $2"
  1260. ;;
  1261. 18)
  1262. error_message="The argument you provided for $2 does not have supported syntax.\nPlease use the following formatting:\n$3"
  1263. ;;
  1264. 19)
  1265. error_message="The option $2 has been deprecated. Please use $3 instead.\nSee -h for instructions and syntax."
  1266. ;;
  1267. 20)
  1268. error_message="The option you selected has been deprecated. $2\nSee the -h (help) menu for currently supported options."
  1269. ;;
  1270. *) error_message="error unknown: $@"
  1271. set -- 99
  1272. ;;
  1273. esac
  1274. # then print it and exit
  1275. print_screen_output "Error $1: $error_message"
  1276. eval $LOGFE
  1277. exit $1
  1278. }
  1279.  
  1280. # prior to script up set, pack the data into an array
  1281. # then we'll print it out later.
  1282. # args: $1 - $@ debugging string text
  1283. script_debugger()
  1284. {
  1285. eval $LOGFS
  1286. if [[ $B_SCRIPT_UP == 'true' ]];then
  1287. # only return if debugger is off and no pre start up errors have occured
  1288. if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
  1289. return 0
  1290. # print out the stored debugging information if errors occured
  1291. elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
  1292. for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
  1293. do
  1294. print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
  1295. done
  1296. DEBUG_BUFFER_INDEX=0
  1297. fi
  1298. # or print out normal debugger messages if debugger is on
  1299. if [[ $DEBUG -gt 0 ]];then
  1300. print_screen_output "$1"
  1301. fi
  1302. else
  1303. if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
  1304. error_handler 2
  1305. # this case stores the data for later printout, will print out only
  1306. # at B_SCRIPT_UP == 'true' if array index > 0
  1307. else
  1308. A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
  1309. # increment count for next pre script up debugging error
  1310. (( DEBUG_BUFFER_INDEX++ ))
  1311. fi
  1312. fi
  1313. eval $LOGFE
  1314. }
  1315.  
  1316. # NOTE: no logging available until get_parameters is run, since that's what sets logging
  1317. # in order to trigger earlier logging manually set B_USE_LOGGING to true in top variables.
  1318. # $1 alone: logs data; $2 with or without $3 logs func start/end.
  1319. # $1 type (fs/fe/cat/raw) or logged data; [$2 is $FUNCNAME; [$3 - function args]]
  1320. log_function_data()
  1321. {
  1322. if [ "$B_USE_LOGGING" == 'true' ];then
  1323. local logged_data='' spacer=' ' line='----------------------------------------'
  1324. case $1 in
  1325. fs)
  1326. logged_data="Function: $2 - Primary: Start"
  1327. if [ -n "$3" ];then
  1328. logged_data="$logged_data\n${spacer}Args: $3"
  1329. fi
  1330. spacer=''
  1331. ;;
  1332. fe)
  1333. logged_data="Function: $2 - Primary: End"
  1334. spacer=''
  1335. ;;
  1336. cat)
  1337. if [[ $B_LOG_FULL_DATA == 'true' ]];then
  1338. logged_data="\n$line\nFull file data: cat $2\n\n$( cat $2 )\n$line\n"
  1339. spacer=''
  1340. fi
  1341. ;;
  1342. raw)
  1343. if [[ $B_LOG_FULL_DATA == 'true' ]];then
  1344. logged_data="\n$line\nRaw system data:\n\n$2\n$line\n"
  1345. spacer=''
  1346. fi
  1347. ;;
  1348. *)
  1349. logged_data="$1"
  1350. ;;
  1351. esac
  1352. # Create any required line breaks and strip out escape color code, either ansi (case 1)or irc (case 2).
  1353. # This pattern doesn't work for irc colors, if we need that someone can figure it out
  1354. if [[ -n $logged_data ]];then
  1355. if [[ $B_LOG_COLORS != 'true' ]];then
  1356. echo -e "${spacer}$logged_data" | sed $SED_RX 's/\x1b\[[0-9]{1,2}(;[0-9]{1,2}){0,2}m//g' >> $LOG_FILE
  1357. else
  1358. echo -e "${spacer}$logged_data" >> $LOG_FILE
  1359. fi
  1360. fi
  1361. fi
  1362. }
  1363.  
  1364. # called in the initial -@ 10 script args setting so we can get logging as soon as possible
  1365. # will have max 3 files, inxi.log, inxi.1.log, inxi.2.log
  1366. create_rotate_logfiles()
  1367. {
  1368. if [[ ! -d $SCRIPT_DATA_DIR ]];then
  1369. mkdir $SCRIPT_DATA_DIR
  1370. fi
  1371. # do the rotation if logfile exists
  1372. if [[ -f $LOG_FILE ]];then
  1373. # copy if present second to third
  1374. if [[ -f $LOG_FILE_1 ]];then
  1375. mv -f $LOG_FILE_1 $LOG_FILE_2
  1376. fi
  1377. # then copy initial to second
  1378. mv -f $LOG_FILE $LOG_FILE_1
  1379. fi
  1380. # now create the logfile
  1381. touch $LOG_FILE
  1382. # and echo the start data
  1383. echo "=========================================================" >> $LOG_FILE
  1384. echo "START $SCRIPT_NAME LOGGING:" >> $LOG_FILE
  1385. echo "Script started: $( date +%Y-%m-%d-%H:%M:%S )" >> $LOG_FILE
  1386. echo "=========================================================" >> $LOG_FILE
  1387. }
  1388.  
  1389. # args: $1 - download url, not including file name; $2 - string to print out
  1390. # $3 - update type option
  1391. # note that $1 must end in / to properly construct the url path
  1392. script_self_updater()
  1393. {
  1394. eval $LOGFS
  1395. local wget_error=0 file_contents='' wget_man_error=0
  1396. local man_file_path="$MAN_FILE_LOCATION/inxi.1.gz"
  1397.  
  1398. if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
  1399. print_screen_output "Sorry, you can't run the $SCRIPT_NAME self updater option (-$3) in an IRC client."
  1400. exit 1
  1401. fi
  1402.  
  1403. print_screen_output "Starting $SCRIPT_NAME self updater."
  1404. print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER"
  1405. print_screen_output "Current version patch number: $SCRIPT_PATCH_NUMBER"
  1406. print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..."
  1407.  
  1408. file_contents="$( wget -q -O - $1$SCRIPT_NAME )" || wget_error=$?
  1409. # then do the actual download
  1410. if [[ $wget_error -eq 0 ]];then
  1411. # make sure the whole file got downloaded and is in the variable
  1412. if [[ -n $( grep '###\*\*EOF\*\*###' <<< "$file_contents" ) ]];then
  1413. echo "$file_contents" > $SCRIPT_PATH/$SCRIPT_NAME || error_handler 14 "$?"
  1414. chmod +x $SCRIPT_PATH/$SCRIPT_NAME || error_handler 15 "$?"
  1415. SCRIPT_VERSION_NUMBER=$( parse_version_data 'main' )
  1416. SCRIPT_PATCH_NUMBER=$( parse_version_data 'patch' )
  1417. print_screen_output "Successfully updated to $2 version: $SCRIPT_VERSION_NUMBER"
  1418. print_screen_output "New $2 version patch number: $SCRIPT_PATCH_NUMBER"
  1419. print_screen_output "To run the new version, just start $SCRIPT_NAME again."
  1420. print_screen_output "----------------------------------------"
  1421. print_screen_output "Starting download of man page file now."
  1422. if [[ ! -d $MAN_FILE_LOCATION ]];then
  1423. print_screen_output "The required man directory was not detected on your system, unable to continue: $MAN_FILE_LOCATION"
  1424. else
  1425. if [[ $B_ROOT == 'true' ]];then
  1426. print_screen_output "Checking Man page download URL..."
  1427. if [[ -f /usr/share/man/man8/inxi.8.gz ]];then
  1428. print_screen_output "Updating man page location to man1."
  1429. mv -f /usr/share/man/man8/inxi.8.gz /usr/share/man/man1/inxi.1.gz
  1430. if [[ -n $( type -p mandb ) ]];then
  1431. exec $( type -p mandb ) -q
  1432. fi
  1433. fi
  1434. wget -q --spider $MAN_FILE_DOWNLOAD || wget_man_error=$?
  1435. if [[ $wget_man_error -eq 0 ]];then
  1436. print_screen_output "Man file download URL verified: $MAN_FILE_DOWNLOAD"
  1437. print_screen_output "Downloading Man page file now."
  1438. wget -q -O $man_file_path $MAN_FILE_DOWNLOAD || wget_man_error=$?
  1439. if [[ $wget_man_error -gt 0 ]];then
  1440. print_screen_output "Oh no! Something went wrong downloading the Man gz file at: $MAN_FILE_DOWNLOAD"
  1441. print_screen_output "Check the error messages for what happened. Error: $wget_man_error"
  1442. else
  1443. print_screen_output "Download/install of man page successful. Check to make sure it works: man inxi"
  1444. fi
  1445. else
  1446. print_screen_output "Man file download URL failed, unable to continue: $MAN_FILE_DOWNLOAD"
  1447. fi
  1448. else
  1449. print_screen_output "Updating / Installing the Man page requires root user, writing to: $MAN_FILE_LOCATION"
  1450. print_screen_output "If you want the man page, you'll have to run $SCRIPT_NAME -$3 as root."
  1451. fi
  1452. fi
  1453. exit 0
  1454. else
  1455. error_handler 16
  1456. fi
  1457. # now run the error handlers on any wget failure
  1458. else
  1459. if [[ $2 == 'svn server' ]];then
  1460. error_handler 8 "$wget_error"
  1461. elif [[ $2 == 'alt server' ]];then
  1462. error_handler 10 "$1"
  1463. else
  1464. error_handler 12 "$1"
  1465. fi
  1466. fi
  1467. eval $LOGFS
  1468. }
  1469.  
  1470. # args: $1 - debug data type: sys|xorg|disk
  1471. debug_data_collector()
  1472. {
  1473. local xiin_app='' xiin_data_file='' xiin_download='' error='' b_run_xiin='false'
  1474. local debug_data_dir='' bsd_string=''
  1475. local completed_gz_file='' xiin_file='xiin.py' ftp_upload='ftp.techpatterns.com/incoming'
  1476. local Line='-------------------------'
  1477. local start_directory=$( pwd )
  1478.  
  1479. if [[ -n $BSD_TYPE ]];then
  1480. bsd_string="$BSD_TYPE-"
  1481. fi
  1482.  
  1483. debug_data_dir="inxi-$bsd_string$(tr ' ' '-' <<< $HOSTNAME | tr '[A-Z]' '[a-z]' )-$1-$(date +%Y%m%d)"
  1484.  
  1485. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  1486. if [[ -n $ALTERNATE_FTP ]];then
  1487. ftp_upload=$ALTERNATE_FTP
  1488. fi
  1489. echo "Starting debugging data collection type: $1"
  1490. echo -n "Checking/creating required directories... "
  1491. if [[ ! -d $SCRIPT_DATA_DIR ]];then
  1492. mkdir $SCRIPT_DATA_DIR
  1493. fi
  1494. echo 'completed'
  1495. cd $SCRIPT_DATA_DIR
  1496. if [[ -d $SCRIPT_DATA_DIR/$debug_data_dir ]];then
  1497. echo 'Deleting previous xiin data directory...'
  1498. rm -rf $SCRIPT_DATA_DIR/$debug_data_dir
  1499. fi
  1500. mkdir $SCRIPT_DATA_DIR/$debug_data_dir
  1501. if [[ -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz ]];then
  1502. echo 'Deleting previous tar.gz file...'
  1503. rm -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz
  1504. fi
  1505.  
  1506. echo 'Collecting system info: sensors, lsusb, lspci, lspci -v data, plus /proc data'
  1507. echo 'also checking for dmidecode data: note, you must be root to have dmidecode work.'
  1508. echo "Data going into: $SCRIPT_DATA_DIR/$debug_data_dir"
  1509. # bsd tools
  1510. pciconf -vl &> $debug_data_dir/bsd-pciconf-vl.txt
  1511. sysctl -a &> $debug_data_dir/bsd-sysctl-a.txt
  1512.  
  1513. dmidecode &> $debug_data_dir/dmidecode.txt
  1514.  
  1515. lscpu &> $debug_data_dir/lscpu.txt
  1516. lspci &> $debug_data_dir/lspci.txt
  1517. lspci -n &> $debug_data_dir/lspci-n.txt
  1518. lspci -v &> $debug_data_dir/lspci-v.txt
  1519. lsusb &> $debug_data_dir/lsusb.txt
  1520. ps aux &> $debug_data_dir/ps-aux.txt
  1521. sensors &> $debug_data_dir/sensors.txt
  1522. nvidia-smi -q &> $debug_data_dir/nvidia-smi-q.txt
  1523. nvidia-smi -q -x &> $debug_data_dir/nvidia-smi-xq.txt
  1524.  
  1525. ls /usr/bin/gcc* &> $debug_data_dir/gcc-sys-versions.txt
  1526. gcc --version &> $debug_data_dir/gcc-version.txt
  1527. cat /etc/issue &> $debug_data_dir/etc-issue.txt
  1528. cat $FILE_LSB_RELEASE &> $debug_data_dir/lsb-release.txt
  1529. cat $FILE_OS_RELEASE &> $debug_data_dir/os-release.txt
  1530. cat $FILE_ASOUND_DEVICE &> $debug_data_dir/proc-asound-device.txt
  1531. cat $FILE_ASOUND_VERSION &> $debug_data_dir/proc-asound-version.txt
  1532. cat $FILE_CPUINFO &> $debug_data_dir/proc-cpu-info.txt
  1533. cat $FILE_MEMINFO &> $debug_data_dir/proc-meminfo.txt
  1534. cat $FILE_MODULES &> $debug_data_dir/proc-modules.txt
  1535. cat /proc/net/arp &> $debug_data_dir/proc-net-arp.txt
  1536. # bsd data
  1537. cat /var/run/dmesg.boot &> $debug_data_dir/bsd-var-run-dmesg.boot.txt
  1538.  
  1539. check_recommends_user_output &> $debug_data_dir/check-recommends-user-output.txt
  1540. # first download and verify xiin
  1541. if [[ $B_UPLOAD_DEBUG_DATA == 'true' || $1 == 'disk' || $1 == 'sys' || $1 == 'all' ]];then
  1542. touch $SCRIPT_DATA_DIR/$debug_data_dir/xiin-error.txt
  1543. echo "Downloading required tree traverse tool $xiin_file..."
  1544. if [[ -f xiin && ! -f $xiin_file ]];then
  1545. mv -f xiin $xiin_file
  1546. fi
  1547. # -Nc is creating really weird download anomolies, so using -O instead
  1548. xiin_download="$( wget -q -O - http://inxi.googlecode.com/svn/branches/xiin/$xiin_file )"
  1549. # if nothing got downloaded kick out error, otherwise we'll use an older version
  1550. if [[ $? -gt 0 && ! -f $xiin_file ]];then
  1551. echo -e "ERROR: Failed to download required file: $xiin_file\nMaybe the remote site is down or your networking is broken?"
  1552. echo "Continuing with incomplete data collection."
  1553. echo "$xiin_file download failed and no existing $xiin_file" >> $debug_data_dir/xiin-error.txt
  1554. elif [[ -n $( grep -s '# EOF' <<< "$xiin_download" ) || -f $xiin_file ]];then
  1555. if [[ -n $( grep -s '# EOF' <<< "$xiin_download" ) ]];then
  1556. echo "Updating $xiin_file from remote location"
  1557. echo "$xiin_download" > $xiin_file
  1558. else
  1559. echo "Using local $xiin_file due to download failure"
  1560. fi
  1561. b_run_xiin='true'
  1562. else
  1563. echo -e "ERROR: $xiin_file downloaded but the program file data is corrupted.\nContinuing with incomplete data collection."
  1564. echo "$xiin_file downloaded but the program file data is corrupted." >> $debug_data_dir/xiin-error.txt
  1565. fi
  1566. fi
  1567. # note, only bash 4> supports ;;& for case, so using if/then here
  1568. if [[ $1 == 'disk' || $1 == 'sys' || $1 == 'all' ]];then
  1569. xiin_data_file=$SCRIPT_DATA_DIR/$debug_data_dir/xiin-sys.txt
  1570. echo 'Collecting networking data...'
  1571. ifconfig &> $debug_data_dir/ifconfig.txt
  1572. ip addr &> $debug_data_dir/ip-addr.txt
  1573. if [[ $b_run_xiin == 'true' && -z $BSD_TYPE ]];then
  1574. echo $Line
  1575. echo "Running $xiin_file tool now on /sys..."
  1576. echo "Using Python version:" && python --version
  1577. python --version &> $debug_data_dir/python-version.txt
  1578. python ./$xiin_file -d /sys -f $xiin_data_file
  1579. if [[ $? -ne 0 ]];then
  1580. error=$?
  1581. echo -e "ERROR: $xiin_file exited with error $error - removing data file.\nContinuing with incomplete data collection."
  1582. echo "Continuing with incomplete data collection."
  1583. rm -f $xiin_data_file
  1584. echo "$xiin_file data generation failed with python error $error" >> $debug_data_dir/xiin-error.txt
  1585. fi
  1586. echo $Line
  1587. fi
  1588. fi
  1589. if [[ $1 == 'xorg' || $1 == 'all' ]];then
  1590. if [[ $B_RUNNING_IN_X != 'true' ]];then
  1591. echo 'Warning: only some of the data collection can occur if you are not in X'
  1592. touch $debug_data_dir/warning-user-not-in-x
  1593. fi
  1594. if [[ $B_ROOT == 'true' ]];then
  1595. echo 'Warning: only some of the data collection can occur if you are running as Root user'
  1596. touch $debug_data_dir/warning-root-user
  1597. fi
  1598. echo 'Collecting Xorg log and xorg.conf files'
  1599. if [[ -e $FILE_XORG_LOG ]];then
  1600. cat $FILE_XORG_LOG &> $debug_data_dir/xorg-log-file.txt
  1601. else
  1602. touch $debug_data_dir/no-xorg-log-file
  1603. fi
  1604. if [[ -e /etc/X11/xorg.conf ]];then
  1605. cp /etc/X11/xorg.conf $SCRIPT_DATA_DIR/$debug_data_dir
  1606. else
  1607. touch $debug_data_dir/no-xorg-conf-file
  1608. fi
  1609. if [[ -n $( ls /etc/X11/xorg.conf.d/ 2>/dev/null ) ]];then
  1610. ls /etc/X11/xorg.conf.d &> $debug_data_dir/ls-etc-x11-xorg-conf-d.txt
  1611. cp /etc/X11/xorg.conf.d $SCRIPT_DATA_DIR/$debug_data_dir
  1612. else
  1613. touch $debug_data_dir/no-xorg-conf-d-files
  1614. fi
  1615. echo 'Collecting X, xprop, glxinfo, xrandr, xdpyinfo data...'
  1616. xprop -root &> $debug_data_dir/xprop_root.txt
  1617. glxinfo &> $debug_data_dir/glxinfo.txt
  1618. xdpyinfo &> $debug_data_dir/xdpyinfo.txt
  1619. xrandr &> $debug_data_dir/xrandr.txt
  1620. X -version &> $debug_data_dir/x-version.txt
  1621. Xorg -version &> $debug_data_dir/xorg-version.txt
  1622. fi
  1623. if [[ $1 == 'disk' || $1 == 'all' ]];then
  1624. echo 'Collecting dev, label, disk, uuid data, df...'
  1625. ls -l /dev &> $debug_data_dir/dev-data.txt
  1626. ls -l /dev/disk &> $debug_data_dir/dev-disk-data.txt
  1627. ls -l /dev/disk/by-id &> $debug_data_dir/dev-disk-id-data.txt
  1628. ls -l /dev/disk/by-label &> $debug_data_dir/dev-disk-label-data.txt
  1629. ls -l /dev/disk/by-uuid &> $debug_data_dir/dev-disk-uuid-data.txt
  1630. ls -l /dev/disk/by-path &> $debug_data_dir/dev-disk-path-data.txt
  1631. ls -l /dev/mapper &> $debug_data_dir/dev-disk-mapper-data.txt
  1632. readlink /dev/root &> $debug_data_dir/dev-root.txt
  1633. 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
  1634. 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
  1635. df -H -T &> $debug_data_dir/bsd-df-H-T-no-excludes.txt
  1636. df -H &> $debug_data_dir/bsd-df-H-no-excludes.txt
  1637. # bsd tool
  1638. mount &> $debug_data_dir/mount.txt
  1639. gpart list &> $debug_data_dir/bsd-gpart-list.txt
  1640. gpart show &> $debug_data_dir/bsd-gpart-show.txt
  1641. gpart status &> $debug_data_dir/bsd-gpart-status.txt
  1642. swapctl -l &> $debug_data_dir/bsd-swapctl-l.txt
  1643. swapon -s &> $debug_data_dir/swapon-s.txt
  1644. sysctl -b kern.geom.conftxt &> $debug_data_dir/bsd-sysctl-b-kern.geom.conftxt.txt
  1645. sysctl -b kern.geom.confxml &> $debug_data_dir/bsd-sysctl-b-kern.geom.confxml.txt
  1646. zfs list &> $debug_data_dir/bsd-zfs-list.txt
  1647. zpool list &> $debug_data_dir/bsd-zpool-list.txt
  1648. zpool list -v &> $debug_data_dir/bsd-zpool-list-v.txt
  1649. 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
  1650. df -P &> $debug_data_dir/bsd-df-P-no-excludes.txt
  1651. cat /proc/mdstat &> $debug_data_dir/proc-mdstat.txt
  1652. cat $FILE_PARTITIONS &> $debug_data_dir/proc-partitions.txt
  1653. cat $FILE_SCSI &> $debug_data_dir/proc-scsi.txt
  1654. cat $FILE_MOUNTS &> $debug_data_dir/proc-mounts.txt
  1655. cat /proc/sys/dev/cdrom/info &> $debug_data_dir/proc-cdrom-info.txt
  1656. ls /proc/ide/ &> $debug_data_dir/proc-ide.txt
  1657. cat /proc/ide/*/* &> $debug_data_dir/proc-ide-hdx-cat.txt
  1658. cat /etc/fstab &> $debug_data_dir/etc-fstab.txt
  1659. cat /etc/mtab &> $debug_data_dir/etc-mtab.txt
  1660. fi
  1661. echo 'Creating inxi output file now. This can take a few seconds...'
  1662. echo "Starting $SCRIPT_NAME from: $start_directory"
  1663. cd $start_directory
  1664. $SCRIPT_PATH/$SCRIPT_NAME -FRploudxxx -c 0 -@ 8 > $SCRIPT_DATA_DIR/$debug_data_dir/inxi-FRploudxxx.txt
  1665. cp $LOG_FILE $SCRIPT_DATA_DIR/$debug_data_dir
  1666. if [[ -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz ]];then
  1667. echo "Found and removing previous tar.gz data file: $debug_data_dir.tar.gz"
  1668. rm -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz
  1669. fi
  1670. cd $SCRIPT_DATA_DIR
  1671. echo 'Creating tar.gz compressed file of this material now. Contents:'
  1672. echo $Line
  1673. tar -cvzf $debug_data_dir.tar.gz $debug_data_dir
  1674. echo $Line
  1675. echo 'Cleaning up leftovers...'
  1676. rm -rf $debug_data_dir
  1677. echo 'Testing gzip file integrity...'
  1678. gzip -t $debug_data_dir.tar.gz
  1679. if [[ $? -gt 0 ]];then
  1680. echo 'Data in gz is corrupted, removing gzip file, try running data collector again.'
  1681. rm -f $debug_data_dir.tar.gz
  1682. echo "Data in gz is corrupted, removed gzip file" >> $debug_data_dir/gzip-error.txt
  1683. else
  1684. echo 'All done, you can find your data gzipped directory here:'
  1685. completed_gz_file=$SCRIPT_DATA_DIR/$debug_data_dir.tar.gz
  1686. echo $completed_gz_file
  1687. if [[ $B_UPLOAD_DEBUG_DATA == 'true' ]];then
  1688. echo $Line
  1689. if [[ $b_run_xiin == 'true' ]];then
  1690. echo "Running automatic upload of data to remote server $ftp_upload now..."
  1691. python ./$xiin_file --version
  1692. python ./$xiin_file -u $completed_gz_file $ftp_upload
  1693. if [[ $? -gt 0 ]];then
  1694. echo $Line
  1695. echo "Error: looks like the ftp upload failed. Error number: $?"
  1696. echo "The ftp upload failed. Error number: $?" >> $debug_data_dir/xiin-error.txt
  1697. fi
  1698. else
  1699. echo 'Unable to run the automoatic ftp upload because of an error with the xiin download.'
  1700. echo "Unable to run the automoatic ftp upload because of an error with the xiin download" >> $debug_data_dir/xiin-error.txt
  1701. fi
  1702. else
  1703. echo 'You can upload this here using most file managers: ftp.techpatterns.com/incoming'
  1704. echo 'then let a maintainer know it is uploaded.'
  1705. fi
  1706. fi
  1707. else
  1708. echo 'This feature only available in console or shell client! Exiting now.'
  1709. fi
  1710. exit 0
  1711. }
  1712.  
  1713. check_recommends_user_output()
  1714. {
  1715. local Line='-----------------------------------------------------------------------------------------'
  1716. local gawk_version='N/A' sed_version='N/A' sudo_version='N/A' python_version='N/A'
  1717.  
  1718. if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
  1719. print_screen_output "Sorry, you can't run this option in an IRC client."
  1720. exit 1
  1721. fi
  1722.  
  1723. initialize_paths
  1724.  
  1725. echo "$SCRIPT_NAME will now begin checking for the programs it needs to operate. First a check of"
  1726. echo "the main languages and tools $SCRIPT_NAME uses. Python is only for debugging data collection."
  1727. echo $Line
  1728. echo "Bash version: $( bash --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU bash/ {print $4}' )"
  1729. if [[ -n $( type -p gawk ) ]];then
  1730. gawk_version=$( gawk --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU Awk/ {print $3}' )
  1731. fi
  1732. if [[ -n $( type -p sed ) ]];then
  1733. sed_version=$( sed --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU sed version/ {print $4}' )
  1734. if [[ -z $sed_version ]];then
  1735. # note: bsd sed shows error with --version flag
  1736. sed_version=$( sed --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^sed: illegal option/ {print "BSD sed"}' )
  1737. fi
  1738. fi
  1739. if [[ -n $( type -p sudo ) ]];then
  1740. sudo_version=$( sudo -V 2>&1 | awk 'BEGIN {IGNORECASE=1} /^Sudo version/ {print $3}' )
  1741. fi
  1742. if [[ -n $( type -p python ) ]];then
  1743. python_version=$( python --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^Python/ {print $2}' )
  1744. fi
  1745. echo "Gawk version: $gawk_version"
  1746. echo "Sed version: $sed_version"
  1747. echo "Sudo version: $sudo_version"
  1748. echo "Python version: $python_version"
  1749. echo $Line
  1750. echo "Test One: Required System Directories."
  1751. echo "If one of these system directories is missing, $SCRIPT_NAME cannot operate:"
  1752. echo
  1753. check_recommends_items 'required-dirs'
  1754. echo "Test Two: Required Core Applications."
  1755. echo "If one of these applications is missing, $SCRIPT_NAME cannot operate:"
  1756. echo
  1757. check_recommends_items 'required-apps'
  1758. echo 'Test Three: Script Recommends for Graphics Features. If you do not use X these do not matter.'
  1759. echo "If one of these applications is missing, $SCRIPT_NAME will have incomplete output:"
  1760. echo
  1761. check_recommends_items 'recommended-x-apps'
  1762. echo 'Test Four: Script Recommends for Remaining Features.'
  1763. echo "If one of these applications is missing, $SCRIPT_NAME will have incomplete output:"
  1764. echo
  1765. check_recommends_items 'recommended-apps'
  1766. echo 'Test Five: System Directories for Various Information.'
  1767. echo "If one of these directories is missing, $SCRIPT_NAME will have incomplete output:"
  1768. echo
  1769. check_recommends_items 'system-dirs'
  1770. echo 'All tests completed.'
  1771. }
  1772. # args: $1 - check item
  1773. check_recommends_items()
  1774. {
  1775. local item='' item_list='' item_string='' missing_items='' missing_string=''
  1776. local package='' application='' feature='' type='' starter='' finisher=''
  1777. local package_deb='' package_pacman='' package_rpm=''
  1778. local print_string='' separator=''
  1779. local required_dirs='/proc /sys'
  1780. # package-owner: 1 - debian/ubuntu; 2 - arch; 3 - yum/rpm
  1781. # pardus: pisi sf -q /usr/bin/package
  1782. local required_apps='
  1783. df:coreutils~coreutils~coreutils~:partition_data
  1784. gawk:gawk~gawk~gawk~:core_tool
  1785. grep:grep~grep~grep~:string_search
  1786. lspci:pciutils~pciutils~pciutils~:hardware_data
  1787. ps:procps~procps~procps~:process_data
  1788. readlink:coreutils~coreutils~coreutils~:
  1789. sed:sed~sed~sed~:string_replace
  1790. tr:coreutils~coreutils~coreutils~:character_replace
  1791. uname:uname~coreutils~coreutils~:kernel_data
  1792. uptime:procps~procps~procps~:
  1793. wc:coreutils~coreutils~coreutils~:word_character_count
  1794. '
  1795. local x_recommends='
  1796. glxinfo:mesa-utils~mesa-demos~glx-utils_(openSUSE_12.3_and_later_Mesa-demo-x)~:-G_glx_info
  1797. xdpyinfo:X11-utils~xorg-xdpyinfo~xorg-x11-utils~:-G_multi_screen_resolution
  1798. xprop:X11-utils~xorg-xprop~x11-utils~:-S_desktop_data
  1799. xrandr:x11-xserver-utils~xrandr~x11-server-utils~:-G_single_screen_resolution
  1800. '
  1801. local recommended_apps='
  1802. dmidecode:dmidecode~dmidecode~dmidecode~:-M_if_no_sys_machine_data
  1803. file:file~file~file~:-o_unmounted_file_system
  1804. hddtemp:hddtemp~hddtemp~hddtemp~:-Dx_show_hdd_temp
  1805. ifconfig:net-tools~net-tools~net-tools~:-i_ip_lan-deprecated
  1806. ip:iproute~iproute2~iproute~:-i_ip_lan
  1807. sensors:lm-sensors~lm_sensors~lm-sensors~:-s_sensors_output
  1808. lsusb:usbutils~usbutils~usbutils~:-A_usb_audio;-N_usb_networking
  1809. modinfo:module-init-tools~module-init-tools~module-init-tools~:-Ax,-Nx_module_version
  1810. runlevel:sysvinit~sysvinit~systemd~:-I_runlevel
  1811. sudo:sudo~sudo~sudo~:-Dx_hddtemp-user;-o_file-user
  1812. '
  1813. local recommended_dirs='
  1814. /sys/class/dmi/id:-M_system,_motherboard,_bios
  1815. /dev:-l,-u,-o,-p,-P,-D_disk_partition_data
  1816. /dev/disk/by-label:-l,-o,-p,-P_partition_labels
  1817. /dev/disk/by-uuid:-u,-o,-p,-P_partition_uuid
  1818. /var/run/dmesg.boot:-C,-f_(BSD_only)
  1819. '
  1820.  
  1821. case $1 in
  1822. required-dirs)
  1823. item_list=$required_dirs
  1824. item_string='Required file system'
  1825. missing_string='system directories'
  1826. type='directories'
  1827. ;;
  1828. required-apps)
  1829. item_list=$required_apps
  1830. item_string='Required application'
  1831. missing_string='applications, and their corresponding packages,'
  1832. type='applications'
  1833. ;;
  1834. recommended-x-apps)
  1835. item_list=$x_recommends
  1836. item_string='Recommended X application'
  1837. missing_string='applications, and their corresponding packages,'
  1838. type='applications'
  1839. ;;
  1840. recommended-apps)
  1841. item_list=$recommended_apps
  1842. item_string='Recommended application'
  1843. missing_string='applications, and their corresponding packages,'
  1844. type='applications'
  1845. ;;
  1846. system-dirs)
  1847. item_list=$recommended_dirs
  1848. item_string='System directory'
  1849. missing_string='system directories'
  1850. type='directories'
  1851. ;;
  1852. esac
  1853. # great trick from: http://ideatrash.net/2011/01/bash-string-padding-with-sed.html
  1854. # left pad: sed -e :a -e 's/^.\{1,80\}$/& /;ta'
  1855. # right pad: sed -e :a -e 's/^.\{1,80\}$/ &/;ta'
  1856. # center pad: sed -e :a -e 's/^.\{1,80\}$/ & /;ta'
  1857.  
  1858. for item in $item_list
  1859. do
  1860. if [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 0 ]];then
  1861. application=$item
  1862. package=''
  1863. feature=''
  1864. location=''
  1865. elif [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 1 ]];then
  1866. application=$( cut -d ':' -f 1 <<< $item )
  1867. package=''
  1868. feature=$( cut -d ':' -f 2 <<< $item )
  1869. location=''
  1870. else
  1871. application=$( cut -d ':' -f 1 <<< $item )
  1872. package=$( cut -d ':' -f 2 <<< $item )
  1873. location=$( type -p $application )
  1874. if [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 2 ]];then
  1875. feature=$( cut -d ':' -f 3 <<< $item )
  1876. else
  1877. feature=''
  1878. fi
  1879. fi
  1880. if [[ -n $feature ]];then
  1881. print_string="$item_string: $application (info: $( sed 's/_/ /g' <<< $feature ))"
  1882. else
  1883. print_string="$item_string: $application"
  1884. fi
  1885. starter="$( sed -e :a -e 's/^.\{1,75\}$/&./;ta' <<< $print_string )"
  1886. if [[ -z $( grep '^/' <<< $application ) && -n $location ]] || [[ -d $application ]];then
  1887. if [[ -n $location ]];then
  1888. finisher=" $location"
  1889. else
  1890. finisher=" Present"
  1891. fi
  1892. else
  1893. finisher=" Missing"
  1894. missing_items="$missing_items$separator$application:$package"
  1895. separator=' '
  1896. fi
  1897.  
  1898. echo "$starter$finisher"
  1899. done
  1900. echo
  1901. if [[ -n $missing_items ]];then
  1902. echo "The following $type are missing from your system:"
  1903. for item in $missing_items
  1904. do
  1905. application=$( cut -d ':' -f 1 <<< $item )
  1906. if [[ $type == 'applications' ]];then
  1907. # echo '--------------------------------------------------------'
  1908. echo
  1909. package=$( cut -d ':' -f 2 <<< $item )
  1910. package_deb=$( cut -d '~' -f 1 <<< $package )
  1911. package_pacman=$( cut -d '~' -f 2 <<< $package )
  1912. package_rpm=$( cut -d '~' -f 3 <<< $package )
  1913. echo "Application: $application"
  1914. echo "To add to your system, install the proper distribution package for your system:"
  1915. echo "Debian/Ubuntu: $package_deb :: Arch Linux: $package_pacman :: Redhat/Fedora/Suse: $package_rpm"
  1916. else
  1917. echo "Directory: $application"
  1918. fi
  1919. done
  1920. if [[ $item_string == 'System directory' ]];then
  1921. echo "These directories are created by the kernel, so don't worry if they are not present."
  1922. fi
  1923. else
  1924. echo "All the $( cut -d ' ' -f 1 <<< $item_string | sed -e 's/Re/re/' -e 's/Sy/sy/' ) $type are present."
  1925. fi
  1926. echo $Line
  1927. }
  1928.  
  1929. #### -------------------------------------------------------------------
  1930. #### print / output cleaners
  1931. #### -------------------------------------------------------------------
  1932.  
  1933. # inxi speaks through here. When run by Konversation script alias mode, uses DCOP
  1934. # for dcop to work, must use 'say' operator, AND colors must be evaluated by echo -e
  1935. # note: dcop does not seem able to handle \n so that's being stripped out and replaced with space.
  1936. print_screen_output()
  1937. {
  1938. eval $LOGFS
  1939. # the double quotes are needed to avoid losing whitespace in data when certain output types are used
  1940. local print_data="$( echo -e "$1" )"
  1941.  
  1942. # just using basic debugger stuff so you can tell which thing is printing out the data. This
  1943. # should help debug kde 4 konvi issues when that is released into sid, we'll see. Turning off
  1944. # the redundant debugger output which as far as I can tell does exactly nothing to help debugging.
  1945. if [[ $DEBUG -gt 5 ]];then
  1946. if [[ $KONVI -eq 1 ]];then
  1947. # konvi doesn't seem to like \n characters, it just prints them literally
  1948. # print_data="$( tr '\n' ' ' <<< "$print_data" )"
  1949. # dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "konvi='$KONVI' saying : '$print_data'"
  1950. print_data="KP-$KONVI: $print_data"
  1951. elif [[ $KONVI -eq 2 ]];then
  1952. # echo "konvi='$KONVI' saying : '$print_data'"
  1953. print_data="KP-$KONVI: $print_data"
  1954. else
  1955. # echo "printing out: '$print_data'"
  1956. print_data="P: $print_data"
  1957. fi
  1958. fi
  1959.  
  1960. if [[ $KONVI -eq 1 && $B_DCOP == 'true' ]]; then ## dcop Konversation (<= 1.1 (qt3))
  1961. # konvi doesn't seem to like \n characters, it just prints them literally
  1962. $print_data="$( tr '\n' ' ' <<< "$print_data" )"
  1963. dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data"
  1964.  
  1965. elif [[ $KONVI -eq 3 && $B_QDBUS == 'true' ]]; then ## dbus Konversation (> 1.2 (qt4))
  1966. qdbus org.kde.konversation /irc say "$DCSERVER" "$DCTARGET" "$print_data"
  1967.  
  1968. # elif [[ $IRC_CLIENT == 'X-Chat' ]]; then
  1969. # qdbus org.xchat.service print "$print_data\n"
  1970.  
  1971. else
  1972. # the -n is needed to avoid double spacing of output in terminal
  1973. echo -ne "$print_data\n"
  1974. fi
  1975. eval $LOGFE
  1976. }
  1977.  
  1978. ## this handles all verbose line construction with indentation/line starter
  1979. ## args: $1 - null (, actually: " ") or line starter; $2 - line content
  1980. create_print_line()
  1981. {
  1982. eval $LOGFS
  1983. printf "${C1}%-${INDENT}s${C2} %s" "$1" "$2"
  1984. eval $LOGFE
  1985. }
  1986.  
  1987. # this removes newline and pipes.
  1988. # args: $1 - string to clean
  1989. remove_erroneous_chars()
  1990. {
  1991. eval $LOGFS
  1992. ## RS is input record separator
  1993. ## gsub is substitute;
  1994. gawk '
  1995. BEGIN {
  1996. RS=""
  1997. }
  1998. {
  1999. gsub(/\n$/,"") ## (newline; end of string) with (nothing)
  2000. gsub(/\n/," "); ## (newline) with (space)
  2001. gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
  2002. gsub(/ +/, " ") ## ( +) with (space)
  2003. gsub(/ [ ]+/, " ") ## ([ ]+) with (space)
  2004. gsub(/^ +| +$/, "") ## (pipe char) with (nothing)
  2005. printf $0
  2006. }' "$1" ## prints (returns) cleaned input
  2007. eval $LOGFE
  2008. }
  2009.  
  2010. #### -------------------------------------------------------------------
  2011. #### parameter handling, print usage functions.
  2012. #### -------------------------------------------------------------------
  2013.  
  2014. # Get the parameters. Note: standard options should be lower case, advanced or testing, upper
  2015. # args: $1 - full script startup args: $@
  2016. get_parameters()
  2017. {
  2018. eval $LOGFS
  2019. local opt='' wget_test='' debug_data_type='' weather_flag='wW:'
  2020. local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false
  2021.  
  2022. # if distro maintainers don't want the weather feature disable it
  2023. if [[ $B_ALLOW_WEATHER == 'false' ]];then
  2024. weather_flag=''
  2025.  
  2026. fi
  2027. if [[ $1 == '--version' ]];then
  2028. print_version_info
  2029. exit 0
  2030. elif [[ $1 == '--help' ]];then
  2031. show_options
  2032. exit 0
  2033. elif [[ $1 == '--recommends' ]];then
  2034. check_recommends_user_output
  2035. exit 0
  2036. # the short form only runs if no args output args are used
  2037. # no need to run through these if there are no args
  2038. # reserved for future use: -g for extra Graphics; -m for extra Machine; -d for extra Disk
  2039. elif [[ -n $1 ]];then
  2040. while getopts Abc:CdDfFGhHiIlMnNopPrRsSt:uUv:V${weather_flag}xzZ%@:!: opt
  2041. do
  2042. case $opt in
  2043. A) B_SHOW_AUDIO='true'
  2044. use_short='false'
  2045. ;;
  2046. b) use_short='false'
  2047. B_SHOW_BASIC_CPU='true'
  2048. B_SHOW_BASIC_RAID='true'
  2049. B_SHOW_DISK_TOTAL='true'
  2050. B_SHOW_GRAPHICS='true'
  2051. B_SHOW_INFO='true'
  2052. B_SHOW_MACHINE='true'
  2053. B_SHOW_NETWORK='true'
  2054. B_SHOW_SYSTEM='true'
  2055. ;;
  2056. c) if [[ -n $( grep -E '^[0-9][0-9]?$' <<< $OPTARG ) ]];then
  2057. case $OPTARG in
  2058. 99)
  2059. B_RUN_COLOR_SELECTOR='true'
  2060. COLOR_SELECTION='global'
  2061. ;;
  2062. 98)
  2063. B_RUN_COLOR_SELECTOR='true'
  2064. COLOR_SELECTION='irc-console'
  2065. ;;
  2066. 97)
  2067. B_RUN_COLOR_SELECTOR='true'
  2068. COLOR_SELECTION='irc-virtual-terminal'
  2069. ;;
  2070. 96)
  2071. B_RUN_COLOR_SELECTOR='true'
  2072. COLOR_SELECTION='irc'
  2073. ;;
  2074. 95)
  2075. B_RUN_COLOR_SELECTOR='true'
  2076. COLOR_SELECTION='virtual-terminal'
  2077. ;;
  2078. 94)
  2079. B_RUN_COLOR_SELECTOR='true'
  2080. COLOR_SELECTION='console'
  2081. ;;
  2082. *)
  2083. B_COLOR_SCHEME_SET='true'
  2084. ## note: not sure about this, you'd think user values should be overridden, but
  2085. ## we'll leave this for now
  2086. if [[ -z $COLOR_SCHEME ]];then
  2087. set_color_scheme "$OPTARG"
  2088. fi
  2089. ;;
  2090. esac
  2091. else
  2092. error_handler 3 "$OPTARG"
  2093. fi
  2094. ;;
  2095. C) B_SHOW_CPU='true'
  2096. use_short='false'
  2097. ;;
  2098. d) B_SHOW_DISK='true'
  2099. B_SHOW_FULL_OPTICAL='true'
  2100. use_short='false'
  2101. # error_handler 20 "-d has been replaced by -b"
  2102. ;;
  2103. D) B_SHOW_DISK='true'
  2104. use_short='false'
  2105. ;;
  2106. f) B_SHOW_CPU='true'
  2107. B_CPU_FLAGS_FULL='true'
  2108. use_short='false'
  2109. ;;
  2110. F) # B_EXTRA_DATA='true'
  2111. B_SHOW_ADVANCED_NETWORK='true'
  2112. B_SHOW_AUDIO='true'
  2113. # B_SHOW_BASIC_OPTICAL='true'
  2114. B_SHOW_CPU='true'
  2115. B_SHOW_DISK='true'
  2116. B_SHOW_GRAPHICS='true'
  2117. B_SHOW_INFO='true'
  2118. B_SHOW_MACHINE='true'
  2119. B_SHOW_NETWORK='true'
  2120. B_SHOW_PARTITIONS='true'
  2121. B_SHOW_RAID='true'
  2122. B_SHOW_SENSORS='true'
  2123. B_SHOW_SYSTEM='true'
  2124. use_short='false'
  2125. ;;
  2126. G) B_SHOW_GRAPHICS='true'
  2127. use_short='false'
  2128. ;;
  2129. i) B_SHOW_IP='true'
  2130. B_SHOW_NETWORK='true'
  2131. B_SHOW_ADVANCED_NETWORK='true'
  2132. use_short='false'
  2133. ;;
  2134. I) B_SHOW_INFO='true'
  2135. use_short='false'
  2136. ;;
  2137. l) B_SHOW_LABELS='true'
  2138. B_SHOW_PARTITIONS='true'
  2139. use_short='false'
  2140. ;;
  2141. M) B_SHOW_MACHINE='true'
  2142. use_short='false'
  2143. ;;
  2144. n) B_SHOW_ADVANCED_NETWORK='true'
  2145. B_SHOW_NETWORK='true'
  2146. use_short='false'
  2147. ;;
  2148. N) B_SHOW_NETWORK='true'
  2149. use_short='false'
  2150. ;;
  2151. o) B_SHOW_UNMOUNTED_PARTITIONS='true'
  2152. use_short='false'
  2153. ;;
  2154. p) B_SHOW_PARTITIONS_FULL='true'
  2155. B_SHOW_PARTITIONS='true'
  2156. use_short='false'
  2157. ;;
  2158. P) B_SHOW_PARTITIONS='true'
  2159. use_short='false'
  2160. ;;
  2161. r) B_SHOW_REPOS='true'
  2162. use_short='false'
  2163. ;;
  2164. R) B_SHOW_RAID='true'
  2165. # it turns out only users with mdraid software installed will have raid,
  2166. # so unless -R is explicitly called, blank -b/-F/-v6 and less output will not show
  2167. # error if file is missing.
  2168. B_SHOW_RAID_R='true'
  2169. use_short='false'
  2170. ;;
  2171. s) B_SHOW_SENSORS='true'
  2172. use_short='false'
  2173. ;;
  2174. S) B_SHOW_SYSTEM='true'
  2175. use_short='false'
  2176. ;;
  2177. t) if [[ -n $( grep -E '^(c|m|cm|mc)([1-9]|1[0-9]|20)?$' <<< $OPTARG ) ]];then
  2178. use_short='false'
  2179. if [[ -n $( grep -E '[0-9]+' <<< $OPTARG ) ]];then
  2180. PS_COUNT=$( sed 's/[^0-9]//g' <<< $OPTARG )
  2181. fi
  2182. if [[ -n $( grep 'c' <<< $OPTARG ) ]];then
  2183. B_SHOW_PS_CPU_DATA='true'
  2184. fi
  2185. if [[ -n $( grep 'm' <<< $OPTARG ) ]];then
  2186. B_SHOW_PS_MEM_DATA='true'
  2187. fi
  2188. else
  2189. error_handler 13 "$OPTARG"
  2190. fi
  2191. ;;
  2192. u) B_SHOW_UUIDS='true'
  2193. B_SHOW_PARTITIONS='true'
  2194. use_short='false'
  2195. ;;
  2196. v) if [[ -n $( grep -E "^[0-9][0-9]?$" <<< $OPTARG ) && $OPTARG -le $VERBOSITY_LEVELS ]];then
  2197. if [[ $OPTARG -ge 1 ]];then
  2198. use_short='false'
  2199. B_SHOW_BASIC_CPU='true'
  2200. B_SHOW_DISK_TOTAL='true'
  2201. B_SHOW_GRAPHICS='true'
  2202. B_SHOW_INFO='true'
  2203. B_SHOW_SYSTEM='true'
  2204. fi
  2205. if [[ $OPTARG -ge 2 ]];then
  2206. B_SHOW_BASIC_DISK='true'
  2207. B_SHOW_BASIC_RAID='true'
  2208. B_SHOW_MACHINE='true'
  2209. B_SHOW_NETWORK='true'
  2210. fi
  2211. if [[ $OPTARG -ge 3 ]];then
  2212. B_SHOW_ADVANCED_NETWORK='true'
  2213. B_SHOW_CPU='true'
  2214. B_EXTRA_DATA='true'
  2215. fi
  2216. if [[ $OPTARG -ge 4 ]];then
  2217. B_SHOW_DISK='true'
  2218. B_SHOW_PARTITIONS='true'
  2219. fi
  2220. if [[ $OPTARG -ge 5 ]];then
  2221. B_SHOW_AUDIO='true'
  2222. B_SHOW_BASIC_OPTICAL='true'
  2223. B_SHOW_SENSORS='true'
  2224. B_SHOW_LABELS='true'
  2225. B_SHOW_UUIDS='true'
  2226. B_SHOW_RAID='true'
  2227. fi
  2228. if [[ $OPTARG -ge 6 ]];then
  2229. B_SHOW_FULL_OPTICAL='true'
  2230. B_SHOW_PARTITIONS_FULL='true'
  2231. B_SHOW_UNMOUNTED_PARTITIONS='true'
  2232. B_EXTRA_EXTRA_DATA='true'
  2233. fi
  2234. if [[ $OPTARG -ge 7 ]];then
  2235. B_EXTRA_EXTRA_EXTRA_DATA='true'
  2236. B_SHOW_IP='true'
  2237. B_SHOW_RAID_R='true'
  2238. fi
  2239. else
  2240. error_handler 4 "$OPTARG"
  2241. fi
  2242. ;;
  2243. U) if [[ $B_ALLOW_UPDATE == 'true' ]];then
  2244. script_self_updater "$SCRIPT_DOWNLOAD" 'svn server' "$opt"
  2245. else
  2246. error_handler 17 "-$opt"
  2247. fi
  2248. ;;
  2249. V) print_version_info
  2250. exit 0
  2251. ;;
  2252. w) B_SHOW_WEATHER=true
  2253. use_short='false'
  2254. ;;
  2255. W) ALTERNATE_WEATHER_LOCATION=$( sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< $OPTARG )
  2256. if [[ -n $( grep -Esi '([^,]+,.+|[0-9-]+)' <<< $ALTERNATE_WEATHER_LOCATION ) ]];then
  2257. B_SHOW_WEATHER=true
  2258. use_short='false'
  2259. else
  2260. error_handler 18 "-$opt: '$OPTARG'" "city,state OR latitude,longitude OR postal/zip code."
  2261. fi
  2262. ;;
  2263. # this will trigger either with x, xx, xxx or with Fx but not with xF
  2264. x) if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  2265. B_EXTRA_EXTRA_EXTRA_DATA='true'
  2266. elif [[ $B_EXTRA_DATA == 'true' ]];then
  2267. B_EXTRA_EXTRA_DATA='true'
  2268. else
  2269. B_EXTRA_DATA='true'
  2270. fi
  2271. ;;
  2272. z) B_OUTPUT_FILTER='true'
  2273. ;;
  2274. Z) B_OVERRIDE_FILTER='true'
  2275. ;;
  2276. h) show_options
  2277. exit 0
  2278. ;;
  2279. H) show_options 'full'
  2280. exit 0
  2281. ;;
  2282. ## debuggers and testing tools
  2283. %) B_HANDLE_CORRUPT_DATA='true'
  2284. ;;
  2285. @) if [[ -n $( grep -E "^([1-9]|1[0-4])$" <<< $OPTARG ) ]];then
  2286. DEBUG=$OPTARG
  2287. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  2288. B_UPLOAD_DEBUG_DATA='true'
  2289. fi
  2290. exec 2>&1
  2291. # switch on logging only for -@ 8-10
  2292. case $OPTARG in
  2293. 8|9|10)
  2294. if [[ $OPTARG -eq 10 ]];then
  2295. B_LOG_COLORS='true'
  2296. elif [[ $OPTARG -eq 9 ]];then
  2297. B_LOG_FULL_DATA='true'
  2298. fi
  2299. B_USE_LOGGING='true'
  2300. # pack the logging data for evals function start/end
  2301. LOGFS=$LOGFS_STRING
  2302. LOGFE=$LOGFE_STRING
  2303. create_rotate_logfiles # create/rotate logfiles before we do anything else
  2304. ;;
  2305. 11|12|13|14)
  2306. case $OPTARG in
  2307. 11)
  2308. debug_data_type='sys'
  2309. ;;
  2310. 12)
  2311. debug_data_type='xorg'
  2312. ;;
  2313. 13)
  2314. debug_data_type='disk'
  2315. ;;
  2316. 14)
  2317. debug_data_type='all'
  2318. ;;
  2319. esac
  2320. initialize_data
  2321. debug_data_collector $debug_data_type
  2322. ;;
  2323. esac
  2324. else
  2325. error_handler 9 "$OPTARG"
  2326. fi
  2327. ;;
  2328. !) # test for various supported methods
  2329. case $OPTARG in
  2330. 1) B_TESTING_1='true'
  2331. ;;
  2332. 2) B_TESTING_2='true'
  2333. ;;
  2334. 3) B_TESTING_1='true'
  2335. B_TESTING_2='true'
  2336. ;;
  2337. 1[0-6]|http*)
  2338. if [[ $B_ALLOW_UPDATE == 'true' ]];then
  2339. case $OPTARG in
  2340. 10)
  2341. script_self_updater "$SCRIPT_DOWNLOAD_DEV" 'dev server' "$opt $OPTARG"
  2342. ;;
  2343. 11)
  2344. script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_1" 'svn: branch one server' "$opt $OPTARG"
  2345. ;;
  2346. 12)
  2347. script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_2" 'svn: branch two server' "$opt $OPTARG"
  2348. ;;
  2349. 13)
  2350. script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_3" 'svn: branch three server' "$opt $OPTARG"
  2351. ;;
  2352. 14)
  2353. script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_4" 'svn: branch four server' "$opt $OPTARG"
  2354. ;;
  2355. 15)
  2356. script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_BSD" 'svn: branch bsd server' "$opt $OPTARG"
  2357. ;;
  2358. 16)
  2359. script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_GNUBSD" 'svn: branch gnubsd server' "$opt $OPTARG"
  2360. ;;
  2361. http*)
  2362. script_self_updater "$OPTARG" 'alt server' "$opt <http...>"
  2363. ;;
  2364. esac
  2365. else
  2366. error_handler 17 "-$opt $OPTARG"
  2367. fi
  2368. ;;
  2369. 30)
  2370. B_RUNNING_IN_SHELL='true'
  2371. ;;
  2372. 31)
  2373. B_SHOW_HOST='false'
  2374. ;;
  2375. 32)
  2376. B_SHOW_HOST='true'
  2377. ;;
  2378. ftp*)
  2379. ALTERNATE_FTP="$OPTARG"
  2380. ;;
  2381. # for weather function, allows user to set an alternate weather location
  2382. location=*)
  2383. error_handler 19 "-$opt location=" "-W"
  2384. ;;
  2385. *) error_handler 11 "$OPTARG"
  2386. ;;
  2387. esac
  2388. ;;
  2389. *) error_handler 7 "$1"
  2390. ;;
  2391. esac
  2392. done
  2393. fi
  2394. ## this must occur here so you can use the debugging flag to show errors
  2395. ## Reroute all error messages to the bitbucket (if not debugging)
  2396. if [[ $DEBUG -eq 0 ]];then
  2397. exec 2>/dev/null
  2398. fi
  2399. #((DEBUG)) && exec 2>&1 # This is for debugging konversation
  2400.  
  2401. # after all the args have been processed, if no long output args used, run short output
  2402. if [[ $use_short == 'true' ]];then
  2403. B_SHOW_SHORT_OUTPUT='true'
  2404. fi
  2405. # just in case someone insists on using -zZ
  2406. if [[ $B_OVERRIDE_FILTER == 'true' ]];then
  2407. B_OUTPUT_FILTER='false'
  2408. fi
  2409. # change basic to full if user requested it or if arg overrides it
  2410. if [[ $B_SHOW_RAID == 'true' && $B_SHOW_BASIC_RAID == 'true' ]];then
  2411. B_SHOW_BASIC_RAID='false'
  2412. fi
  2413.  
  2414.  
  2415. eval $LOGFE
  2416. }
  2417.  
  2418. ## print out help menu, not including Testing or Debugger stuff because it's not needed
  2419. show_options()
  2420. {
  2421. local color_scheme_count=$(( ${#A_COLOR_SCHEMES[@]} - 1 ))
  2422. local partition_string='partition' partition_string_u='Partition'
  2423.  
  2424. if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
  2425. print_screen_output "Sorry, you can't run the help option in an IRC client."
  2426. exit 1
  2427. fi
  2428. if [[ -n $BSD_TYPE ]];then
  2429. partition_string='slice'
  2430. partition_string_u='Slice'
  2431. fi
  2432. print_screen_output "$SCRIPT_NAME supports the following options. You can combine them, or list them"
  2433. print_screen_output "one by one: Examples: $SCRIPT_NAME -v4 -c6 OR $SCRIPT_NAME -bDc 6"
  2434. print_screen_output " "
  2435. print_screen_output "If you start $SCRIPT_NAME with no arguments, it will show the short form."
  2436. print_screen_output "The following options if used without -F, -b, or -v will show just option line(s):"
  2437. print_screen_output "A,C,D,G,I,M,N,P,R,S,f,i,n,o,p,l,u,r,s,t - you can use these alone or together to show"
  2438. print_screen_output "just the line(s) you want to see."
  2439. print_screen_output "If you use them with -v [level], -b or -F, it will show the full output for that line "
  2440. print_screen_output "along with the output for the chosen verbosity level."
  2441. print_screen_output "- - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  2442. print_screen_output "Output Control Options:"
  2443. print_screen_output "-A Audio/sound card information."
  2444. print_screen_output "-b Basic output, short form. Like $SCRIPT_NAME -v 2, only minus hard disk names."
  2445. print_screen_output "-c Color schemes. Scheme number is required. Color selectors run a color selector option"
  2446. print_screen_output " prior to $SCRIPT_NAME starting which lets you set the config file value for the selection."
  2447. print_screen_output " Supported color schemes: 0-$color_scheme_count Example: $SCRIPT_NAME -c 11"
  2448. print_screen_output " Color selectors for each type display (NOTE: irc and global only show safe color set):"
  2449. print_screen_output " 94 - Console, out of X"
  2450. print_screen_output " 95 - Terminal, running in X - like xTerm"
  2451. print_screen_output " 96 - Gui IRC, running in X - like Xchat, Quassel, Konversation etc."
  2452. print_screen_output " 97 - Console IRC running in X - like irssi in xTerm"
  2453. print_screen_output " 98 - Console IRC not in X"
  2454. print_screen_output " 99 - Global - Overrides/removes all settings. Setting specific removes global."
  2455. print_screen_output "-C Full CPU output, including per CPU clockspeed (if available)."
  2456. print_screen_output "-d Optical drive data. Same as -Dd. See also -x and -xx."
  2457. print_screen_output "-D Full hard Disk info, not only model, ie: /dev/sda ST380817AS 80.0GB. See also -x and -xx."
  2458. print_screen_output "-f All cpu flags, triggers -C. Not shown with -F to avoid spamming. ARM cpus show 'features'."
  2459. print_screen_output "-F Full output for $SCRIPT_NAME. Includes all Upper Case line letters, plus -s and -n."
  2460. print_screen_output " Does not show extra verbose options like -x -d -f -u -l -o -p -t -r"
  2461. print_screen_output "-G Graphic card information (card, x type, resolution, glx renderer, version)."
  2462. print_screen_output "-i Wan IP address, and shows local interfaces (requires ifconfig network tool). Same as -Nni"
  2463. print_screen_output " Not shown with -F for user security reasons, you shouldn't paste your local/wan IP."
  2464. print_screen_output "-I Information: processes, uptime, memory, irc client (or shell type), $SCRIPT_NAME version."
  2465. print_screen_output "-l ${partition_string_u} labels. Default: short ${partition_string} -P. For full -p output, use: -pl (or -plu)."
  2466. print_screen_output "-M Machine data. Motherboard, Bios, and if present, System Builder (Like Lenovo)."
  2467. print_screen_output " Older systems/kernels without the required /sys data can use dmidecode instead, run as root."
  2468. print_screen_output "-n Advanced Network card information. Same as -Nn. Shows interface, speed, mac id, state, etc."
  2469. print_screen_output "-N Network card information. With -x, shows PCI BusID, Port number."
  2470. print_screen_output "-o Unmounted ${partition_string} information (includes UUID and LABEL if available)."
  2471. print_screen_output " Shows file system type if you have file installed, if you are root OR if you have"
  2472. print_screen_output " added to /etc/sudoers (sudo v. 1.7 or newer): <username> ALL = NOPASSWD: /usr/bin/file (sample)"
  2473. print_screen_output "-p Full ${partition_string} information (-P plus all other detected ${partition_string}s)."
  2474. print_screen_output "-P Basic ${partition_string} information (shows what -v 4 would show, but without extra data)."
  2475. print_screen_output " Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted ${partition_string}s."
  2476. print_screen_output "-r Distro repository data. Supported repo types: APT; PACMAN; PISI; YUM; URPMQ; Ports."
  2477. print_screen_output "-R RAID data. Shows RAID devices, states, levels, and components, and extra data with -x/-xx"
  2478. print_screen_output " md-raid: If device is resyncing, shows resync progress line as well."
  2479. print_screen_output "-s Sensors output (if sensors installed/configured): mobo/cpu/gpu temp; detected fan speeds."
  2480. print_screen_output " Gpu temp only for Fglrx/Nvidia drivers. Nvidia shows screen number for > 1 screens."
  2481. print_screen_output "-S System information: host name, kernel, desktop environment (if in X), distro"
  2482. print_screen_output "-t Processes. Requires extra options: c (cpu) m (memory) cm (cpu+memory). If followed by numbers 1-20,"
  2483. print_screen_output " shows that number of processes for each type (default: $PS_COUNT; if in irc, max: 5): -t cm10"
  2484. print_screen_output " Make sure to have no space between letters and numbers (-t cm10 - right, -t cm 10 - wrong)."
  2485. print_screen_output "-u ${partition_string_u} UUIDs. Default: short ${partition_string} -P. For full -p output, use: -pu (or -plu)."
  2486. print_screen_output "-v Script verbosity levels. Verbosity level number is required. Should not be used with -b or -F"
  2487. print_screen_output " Supported levels: 0-${VERBOSITY_LEVELS} Example: $SCRIPT_NAME -v 4"
  2488. print_screen_output " 0 - Short output, same as: $SCRIPT_NAME"
  2489. print_screen_output " 1 - Basic verbose, -S + basic CPU + -G + basic Disk + -I."
  2490. print_screen_output " 2 - Networking card (-N), Machine (-M) data, shows basic hard disk data (names only),"
  2491. print_screen_output " and, if present, basic raid (devices only, and if inactive, notes that). similar to: $SCRIPT_NAME -b"
  2492. print_screen_output " 3 - Advanced CPU (-C), network (-n) data, and switches on -x advanced data option."
  2493. print_screen_output " 4 - ${partition_string_u} size/filled data (-P) for (if present):/, /home, /var/, /boot"
  2494. print_screen_output " Shows full disk data (-D)."
  2495. print_screen_output " 5 - Audio card (-A); sensors (-s), ${partition_string} label (-l) and UUID (-u), short form of optical drives,"
  2496. print_screen_output " standard raid data (-R)."
  2497. print_screen_output " 6 - Full ${partition_string} (-p), unmounted ${partition_string} (-o), optical drive (-d), full raid; triggers -xx."
  2498. print_screen_output " 7 - Network IP data (-i); triggers -xxx."
  2499. # if distro maintainers don't want the weather feature disable it
  2500. if [[ $B_ALLOW_WEATHER == 'true' ]];then
  2501. print_screen_output "-w Local weather data/time. To check an alternate location, see: -W <location>."
  2502. print_screen_output " For extra weather data options see -x, -xx, and -xxx."
  2503. print_screen_output "-W <location> - <location> supported options: postal code; city,[state/country]; latitude,longitude"
  2504. print_screen_output " Only use if you want the weather somewhere other than the machine running $SCRIPT_NAME."
  2505. print_screen_output " Use only ascii characters, replace spaces in city/state/country names with +: new+york,ny"
  2506. fi
  2507. print_screen_output "-x Adds the following extra data (only works with verbose or line output, not short form): "
  2508. print_screen_output " -C - Bogomips on Cpu;"
  2509. print_screen_output " -d - Extra optical drive data; adds rev version to optical drive."
  2510. print_screen_output " -D - Hdd temp with disk data if you have hddtemp installed, if you are root OR if you have added to"
  2511. print_screen_output " /etc/sudoers (sudo v. 1.7 or newer): <username> ALL = NOPASSWD: /usr/sbin/hddtemp (sample)"
  2512. print_screen_output " -G - Direct rendering status for Graphics (in X)."
  2513. print_screen_output " -G - (for single gpu, nvidia driver) screen number gpu is running on."
  2514. print_screen_output " -i - IPv6 as well for LAN interface (IF) devices."
  2515. print_screen_output " -I - System GCC, default. With -xx, also show other installed GCC versions."
  2516. print_screen_output " - If running in console, not in IRC client, shows shell version number if detected."
  2517. print_screen_output " -N -A - Version/port(s)/driver version (if available) for Network/Audio;"
  2518. print_screen_output " -N -A -G - Network, audio, graphics, shows PCI Bus ID/Usb ID number of card;"
  2519. print_screen_output " -R - md-raid: Shows component raid id. Adds second RAID Info line: raid level; report on drives (like 5/5);"
  2520. print_screen_output " blocks; chunk size; bitmap (if present). Resync line, shows blocks synced/total blocks."
  2521. print_screen_output " - zfs-raid: Shows raid array full size; available size; portion allocated to RAID"
  2522. print_screen_output " -S - Desktop toolkit if avaliable (GNOME/XFCE/KDE only); Kernel gcc version"
  2523. print_screen_output " -t - Memory use output to cpu (-xt c), and cpu use to memory (-xt m)."
  2524. if [[ $B_ALLOW_WEATHER == 'true' ]];then
  2525. print_screen_output " -w/-W - Wind speed and time zone (-w only)."
  2526. fi
  2527. print_screen_output "-xx Show extra, extra data (only works with verbose or line output, not short form): "
  2528. print_screen_output " -A - Chip vendor:product ID for each audio device."
  2529. print_screen_output " -D - Disk serial number."
  2530. print_screen_output " -G - Chip vendor:product ID for each video card."
  2531. print_screen_output " -I - Other detected installed gcc versions (if present)."
  2532. print_screen_output " Adds parent program (or tty) for shell info if not in IRC (like Konsole or Gterm)."
  2533. print_screen_output " -M - Chassis information, bios rom size (dmidecode only), if data for either is available."
  2534. print_screen_output " -N - Chip vendor:product ID for each nic."
  2535. print_screen_output " -R - md-raid: Superblock (if present); algorythm, U data. Adds system info line"
  2536. print_screen_output " (kernel support,read ahead, raid events). If present, adds unused device line. "
  2537. print_screen_output " Resync line, shows progress bar."
  2538. print_screen_output " -S - Display manager (dm) in desktop output, if in X (like kdm, gdm3, lightdm)."
  2539. if [[ $B_ALLOW_WEATHER == 'true' ]];then
  2540. print_screen_output " -w/-W - Humidity, barometric pressure."
  2541. fi
  2542. print_screen_output " -xx -@ <11-14> - Automatically uploads debugger data tar.gz file to ftp.techpatterns.com."
  2543. print_screen_output "-xxx Show extra, extra, extra data (only works with verbose or line output, not short form): "
  2544. print_screen_output " -S - Panel/shell information in desktop output, if in X (like gnome-shell, cinnamon, mate-panel)."
  2545. if [[ $B_ALLOW_WEATHER == 'true' ]];then
  2546. print_screen_output " -w/-W - Location (uses -z/irc filter), weather observation time, wind chill, heat index,"
  2547. print_screen_output " dew point (shows extra lines for data where relevant)."
  2548. fi
  2549. print_screen_output "-z Security filters for IP/Mac addresses, location, user home directory name. Default on for irc clients."
  2550. print_screen_output "-Z Absolute override for output filters. Useful for debugging networking issues in irc for example."
  2551. print_screen_output " "
  2552. print_screen_output "Additional Options:"
  2553. print_screen_output "-h --help This help menu."
  2554. print_screen_output "-H This help menu, plus developer options. Do not use dev options in normal operation!"
  2555. print_screen_output "--recommends Checks $SCRIPT_NAME application dependencies + recommends, and directories, then shows"
  2556. print_screen_output " what package(s) you need to install to add support for that feature."
  2557. if [[ $B_ALLOW_UPDATE == 'true' ]];then
  2558. print_screen_output "-U Auto-update script. Will also install/update man page. Note: if you installed as root, you"
  2559. print_screen_output " must be root to update, otherwise user is fine. Man page installs require root user mode."
  2560. fi
  2561. print_screen_output "-V --version $SCRIPT_NAME version information. Prints information then exits."
  2562. print_screen_output " "
  2563. print_screen_output "Debugging Options:"
  2564. print_screen_output "-% Overrides defective or corrupted data."
  2565. print_screen_output "-@ Triggers debugger output. Requires debugging level 1-14 (8-10 - logging of data)."
  2566. print_screen_output " Less than 8 just triggers $SCRIPT_NAME debugger output on screen."
  2567. print_screen_output " 1-7 - On screen debugger output"
  2568. print_screen_output " 8 - Basic logging"
  2569. print_screen_output " 9 - Full file/sys info logging"
  2570. print_screen_output " 10 - Color logging."
  2571. print_screen_output " The following create a tar.gz file of system data, plus collecting the inxi output to file:"
  2572. print_screen_output " To automatically upload debugger data tar.gz file to ftp.techpatterns.com: inxi -xx@ <11-14>"
  2573. print_screen_output " For alternate ftp upload locations: Example: inxi -! ftp.yourserver.com/incoming -xx@ 14"
  2574. print_screen_output " 11 - With data file of xiin read of /sys."
  2575. print_screen_output " 12 - With xorg conf and log data, xrandr, xprop, xdpyinfo, glxinfo etc."
  2576. print_screen_output " 13 - With data from dev, disks, ${partition_string}s, etc., plus xiin data file."
  2577. print_screen_output " 14 - Everything, full data collection."
  2578. print_screen_output "Advanced Options:"
  2579. print_screen_output "-! 31 Turns off hostname in output. Useful if showing output from servers etc."
  2580. print_screen_output "-! 32 Turns on hostname in output. Overrides global B_SHOW_HOST='false'"
  2581.  
  2582. if [[ $1 == 'full' ]];then
  2583. print_screen_output " "
  2584. print_screen_output "Developer and Testing Options (Advanced):"
  2585. print_screen_output "-! 1 - Sets testing flag B_TESTING_1='true' to trigger testing condition 1."
  2586. print_screen_output "-! 2 - Sets testing flag B_TESTING_2='true' to trigger testing condition 2."
  2587. print_screen_output "-! 3 - Sets flags B_TESTING_1='true' and B_TESTING_2='true'."
  2588. if [[ $B_ALLOW_UPDATE == 'true' ]];then
  2589. print_screen_output "-! 10 - Triggers an update from the primary dev download server instead of svn."
  2590. print_screen_output "-! 11 - Triggers an update from svn branch one - if present, of course."
  2591. print_screen_output "-! 12 - Triggers an update from svn branch two - if present, of course."
  2592. print_screen_output "-! 13 - Triggers an update from svn branch three - if present, of course."
  2593. print_screen_output "-! 14 - Triggers an update from svn branch four - if present, of course."
  2594. print_screen_output "-! 15 - Triggers an update from svn branch BSD - if present, of course."
  2595. print_screen_output "-! 16 - Triggers an update from svn branch GNUBSD - if present, of course."
  2596. print_screen_output "-! <http://......> - Triggers an update from whatever server you list."
  2597. fi
  2598. print_screen_output "-! <ftp.......> - Changes debugging data ftp upload location to whatever you enter here."
  2599. print_screen_output " Only used together with -xx@ 11-14, and must be used in front of that."
  2600. print_screen_output " Example: inxi -! ftp.yourserver.com/incoming -xx@ 14"
  2601. print_screen_output " "
  2602. fi
  2603. print_screen_output " "
  2604. }
  2605.  
  2606. ## print out version information for -V/--version
  2607. print_version_info()
  2608. {
  2609. # if not in PATH could be either . or directory name, no slash starting
  2610. local script_path=$SCRIPT_PATH script_symbolic_start=''
  2611. if [[ $script_path == '.' ]];then
  2612. script_path=$( pwd )
  2613. elif [[ -z $( grep '^/' <<< "$script_path" ) ]];then
  2614. script_path="$( pwd )/$script_path"
  2615. fi
  2616. # handle if it's a symbolic link, rare, but can happen with script directories in irc clients
  2617. # which would only matter if user starts inxi with -! 30 override in irc client
  2618. if [[ -L $script_path/$SCRIPT_NAME ]];then
  2619. script_symbolic_start=$script_path/$SCRIPT_NAME
  2620. script_path=$( readlink $script_path/$SCRIPT_NAME )
  2621. script_path=$( dirname $script_path )
  2622. fi
  2623. local last_modified=$( parse_version_data 'date' )
  2624. local year_modified=$( gawk '{print $NF}' <<< "$last_modified" )
  2625.  
  2626. print_screen_output "$SCRIPT_NAME $SCRIPT_VERSION_NUMBER-$SCRIPT_PATCH_NUMBER ($last_modified)"
  2627. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  2628. print_screen_output " "
  2629. print_screen_output "Program Location: $script_path"
  2630. if [[ -n $script_symbolic_start ]];then
  2631. print_screen_output "Started via symbolic link: $script_symbolic_start"
  2632. fi
  2633. print_screen_output "Website: http://inxi.goooglecode.com - IRC: irc.oftc.net channel: #smxi"
  2634. print_screen_output "Forums: http://techpatterns.com/forums/forum-33.html"
  2635. print_screen_output " "
  2636. print_screen_output "$SCRIPT_NAME - the universal, portable, system information tool for console and irc."
  2637. print_screen_output "This program is a fork of Infobash 3.02:"
  2638. print_screen_output "Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif"
  2639. print_screen_output "Subsequent changes and modifications (after Infobash 3.02):"
  2640. print_screen_output "Copyright (C) 2008-$year_modified Scott Rogers, Harald Hope, aka trash80 & h2"
  2641. print_screen_output " "
  2642. print_screen_output "This program is free software; you can redistribute it and/or modify"
  2643. print_screen_output "it under the terms of the GNU General Public License as published by"
  2644. print_screen_output "the Free Software Foundation; either version 3 of the License, or"
  2645. print_screen_output "(at your option) any later version. (http://www.gnu.org/licenses/gpl.html)"
  2646. fi
  2647. }
  2648.  
  2649. ########################################################################
  2650. #### MAIN FUNCTIONS
  2651. ########################################################################
  2652.  
  2653. #### -------------------------------------------------------------------
  2654. #### initial startup stuff
  2655. #### -------------------------------------------------------------------
  2656.  
  2657. # Determine where inxi was run from, set IRC_CLIENT and IRC_CLIENT_VERSION
  2658. get_start_client()
  2659. {
  2660. eval $LOGFS
  2661. local Irc_Client_Path='' irc_client_path_lower='' non_native_konvi='' i=''
  2662. local B_Non_Native_App='false' pppid='' App_Working_Name=''
  2663. local b_qt4_konvi='false' ps_parent=''
  2664.  
  2665. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  2666. IRC_CLIENT='Shell'
  2667. unset IRC_CLIENT_VERSION
  2668. # elif [[ -n $PPID ]];then
  2669. elif [[ -n $PPID && -f /proc/$PPID/exe ]];then
  2670. if [[ $B_OVERRIDE_FILTER != 'true' ]];then
  2671. B_OUTPUT_FILTER='true'
  2672. fi
  2673. Irc_Client_Path=$( readlink /proc/$PPID/exe )
  2674. # Irc_Client_Path=$( ps -p $PPID | gawk '!/[[:space:]]*PID/ {print $5}' )
  2675. # echo $( ps -p $PPID )
  2676. irc_client_path_lower=$( tr '[:upper:]' '[:lower:]' <<< $Irc_Client_Path )
  2677. App_Working_Name=$( basename $irc_client_path_lower )
  2678. # handles the xchat/sh/bash/dash cases, and the konversation/perl cases, where clients
  2679. # report themselves as perl or unknown shell. IE: when konversation starts inxi
  2680. # from inside itself, as a script, the parent is konversation/xchat, not perl/bash etc
  2681. # note: perl can report as: perl5.10.0, so it needs wildcard handling
  2682. case $App_Working_Name in
  2683. # bsd will never use this section
  2684. bash|dash|sh|python*|perl*) # We want to know who wrapped it into the shell or perl.
  2685. pppid="$( ps -p $PPID -o ppid --no-headers | sed 's/[[:space:]]//g' )"
  2686. if [[ -n $pppid && -f /proc/$pppid/exe ]];then
  2687. Irc_Client_Path="$( readlink /proc/$pppid/exe )"
  2688. irc_client_path_lower="$( tr '[:upper:]' '[:lower:]' <<< $Irc_Client_Path )"
  2689. App_Working_Name=$( basename $irc_client_path_lower )
  2690. B_Non_Native_App='true'
  2691. fi
  2692. ;;
  2693. esac
  2694. # sets version number if it can find it
  2695. get_irc_client_version
  2696. else
  2697. ## lets look to see if qt4_konvi is the parent. There is no direct way to tell, so lets infer it.
  2698. ## because $PPID does not work with qt4_konvi, the above case does not work
  2699. if [[ $B_OVERRIDE_FILTER != 'true' ]];then
  2700. B_OUTPUT_FILTER='true'
  2701. fi
  2702. b_qt4_konvi=$( is_this_qt4_konvi )
  2703. if [[ $b_qt4_konvi == 'true' ]];then
  2704. KONVI=3
  2705. IRC_CLIENT='Konversation'
  2706. IRC_CLIENT_VERSION=" $( konversation -v | gawk '
  2707. /Konversation:/ {
  2708. for ( i=2; i<=NF; i++ ) {
  2709. if (i == NF) {
  2710. print $i
  2711. }
  2712. else {
  2713. printf $i" "
  2714. }
  2715. }
  2716. exit
  2717. }' )"
  2718. else
  2719. # this should handle certain cases where it's ssh or some other startup tool
  2720. # that falls through all the other tests
  2721. if [[ $BSD_TYPE != 'bsd' ]];then
  2722. App_Working_Name=$(ps -p $PPID --no-headers 2>/dev/null | gawk '{print $NF}' )
  2723. else
  2724. # without --no-headers we need the second line
  2725. App_Working_Name=$(ps -p $PPID 2>/dev/null | gawk '/^[0-9]+/ {print $5}' )
  2726. fi
  2727.  
  2728. if [[ -n $App_Working_Name ]];then
  2729. Irc_Client_Path=$App_Working_Name
  2730. B_Non_Native_App='false'
  2731. get_irc_client_version
  2732. if [[ -z $IRC_CLIENT ]];then
  2733. IRC_CLIENT=$App_Working_Name
  2734. fi
  2735. else
  2736. IRC_CLIENT="PPID=\"$PPID\" - empty?"
  2737. unset IRC_CLIENT_VERSION
  2738. fi
  2739. fi
  2740. fi
  2741.  
  2742. log_function_data "IRC_CLIENT: $IRC_CLIENT :: IRC_CLIENT_VERSION: $IRC_CLIENT_VERSION :: PPID: $PPID"
  2743. eval $LOGFE
  2744. }
  2745. # note: all variables set in caller so no need to pass
  2746. get_irc_client_version()
  2747. {
  2748. local file_data=''
  2749. # replacing loose detection with tight detection, bugs will be handled with app names
  2750. # as they appear.
  2751. case $App_Working_Name in
  2752. # check for shell first
  2753. bash|dash|sh)
  2754. unset IRC_CLIENT_VERSION
  2755. IRC_CLIENT="Shell wrapper"
  2756. ;;
  2757. # now start on irc clients, alphabetically
  2758. bitchx)
  2759. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk '
  2760. /Version/ {
  2761. a=tolower($2)
  2762. gsub(/[()]|bitchx-/,"",a)
  2763. print a
  2764. exit
  2765. }
  2766. $2 == "version" {
  2767. a=tolower($3)
  2768. sub(/bitchx-/,"",a)
  2769. print a
  2770. exit
  2771. }' )"
  2772. B_CONSOLE_IRC='true'
  2773. IRC_CLIENT="BitchX"
  2774. ;;
  2775. finch)
  2776. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 {
  2777. print $2
  2778. }' )"
  2779. B_CONSOLE_IRC='true'
  2780. IRC_CLIENT="Finch"
  2781. ;;
  2782. gaim)
  2783. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 {
  2784. print $2
  2785. }' )"
  2786. IRC_CLIENT="Gaim"
  2787. ;;
  2788. hexchat)
  2789. # the hexchat author decided to make --version/-v return a gtk dialogue box, lol...
  2790. # so we need to read the actual config file for hexchat. Note that older hexchats
  2791. # used xchat config file, so test first for default, then legacy. Because it's possible
  2792. # for this file to be use edited, doing some extra checks here.
  2793. if [[ -f ~/.config/hexchat/hexchat.conf ]];then
  2794. file_data="$( cat ~/.config/hexchat/hexchat.conf )"
  2795. elif [[ -f ~/.config/hexchat/xchat.conf ]];then
  2796. file_data="$( cat ~/.config/hexchat/xchat.conf )"
  2797. fi
  2798. if [[ -n $file_data ]];then
  2799. IRC_CLIENT_VERSION=$( gawk '
  2800. BEGIN {
  2801. IGNORECASE=1
  2802. FS="="
  2803. }
  2804. /^[[:space:]]*version/ {
  2805. # get rid of the space if present
  2806. gsub(/[[:space:]]*/, "", $2 )
  2807. print $2
  2808. exit # usually this is the first line, no point in continuing
  2809. }' <<< "$file_data" )
  2810.  
  2811. IRC_CLIENT_VERSION=" $IRC_CLIENT_VERSION"
  2812. else
  2813. IRC_CLIENT_VERSION=' N/A'
  2814. fi
  2815. IRC_CLIENT="HexChat"
  2816. ;;
  2817. ircii)
  2818. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 {
  2819. print $3
  2820. }' )"
  2821. B_CONSOLE_IRC='true'
  2822. IRC_CLIENT="ircII"
  2823. ;;
  2824. irssi-text|irssi)
  2825. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 {
  2826. print $2
  2827. }' )"
  2828. B_CONSOLE_IRC='true'
  2829. IRC_CLIENT="Irssi"
  2830. ;;
  2831. konversation) ## konvi < 1.2 (qt4)
  2832. # this is necessary to avoid the dcop errors from starting inxi as a /cmd started script
  2833. if [[ $B_Non_Native_App == 'true' ]];then ## true negative is confusing
  2834. KONVI=2
  2835. else # if native app
  2836. KONVI=1
  2837. fi
  2838. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk '
  2839. /Konversation:/ {
  2840. for ( i=2; i<=NF; i++ ) {
  2841. if (i == NF) {
  2842. print $i
  2843. }
  2844. else {
  2845. printf $i" "
  2846. }
  2847. }
  2848. exit
  2849. }' )"
  2850.  
  2851. T=($IRC_CLIENT_VERSION)
  2852. if [[ ${T[0]} == *+* ]];then
  2853. # < Sho_> locsmif: The version numbers of SVN versions look like this:
  2854. # "<version number of last release>+ #<build number", i.e. "1.0+ #3177" ...
  2855. # for releases we remove the + and build number, i.e. "1.0" or soon "1.0.1"
  2856. IRC_CLIENT_VERSION=" CVS $IRC_CLIENT_VERSION"
  2857. T2="${T[0]/+/}"
  2858. else
  2859. IRC_CLIENT_VERSION=" ${T[0]}"
  2860. T2="${T[0]}"
  2861. fi
  2862. # Remove any dots except the first, and make sure there are no trailing zeroes,
  2863. T2=$( echo "$T2" | gawk '{
  2864. sub(/\./, " ")
  2865. gsub(/\./, "")
  2866. sub(/ /, ".")
  2867. printf("%g\n", $0)
  2868. }' )
  2869. # Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc
  2870. # becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller
  2871. # than 1 and change the DCOP parameter/object accordingly.
  2872. if [[ ${T2} -lt 1 ]];then
  2873. DCOPOBJ="Konversation"
  2874. fi
  2875. IRC_CLIENT="Konversation"
  2876. ;;
  2877. kopete)
  2878. IRC_CLIENT_VERSION=" $( kopete -v | gawk '
  2879. /Kopete:/ {
  2880. print $2
  2881. exit
  2882. }' )"
  2883. IRC_CLIENT="Kopete"
  2884. ;;
  2885. kvirc)
  2886. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v 2>&1 | gawk '{
  2887. for ( i=2; i<=NF; i++) {
  2888. if ( i == NF ) {
  2889. print $i
  2890. }
  2891. else {
  2892. printf $i" "
  2893. }
  2894. }
  2895. exit
  2896. }' )"
  2897. IRC_CLIENT="KVIrc"
  2898. ;;
  2899. pidgin)
  2900. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 {
  2901. print $2
  2902. }' )"
  2903. IRC_CLIENT="Pidgin"
  2904. ;;
  2905. quassel*)
  2906. # sample: quassel -v
  2907. # Qt: 4.5.0
  2908. # KDE: 4.2.65 (KDE 4.2.65 (KDE 4.3 >= 20090226))
  2909. # Quassel IRC: v0.4.0 [+60] (git-22effe5)
  2910. # note: early < 0.4.1 quassels do not have -v
  2911. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v 2>/dev/null | gawk -F ': ' '
  2912. BEGIN {
  2913. IGNORECASE=1
  2914. clientVersion=""
  2915. }
  2916. /Quassel IRC/ {
  2917. clientVersion = $2
  2918. }
  2919. END {
  2920. # this handles pre 0.4.1 cases with no -v
  2921. if ( clientVersion == "" ) {
  2922. clientVersion = "(pre v0.4.1)"
  2923. }
  2924. print clientVersion
  2925. }' )"
  2926. # now handle primary, client, and core. quasselcore doesn't actually
  2927. # handle scripts with exec, but it's here just to be complete
  2928. case $App_Working_Name in
  2929. quassel)
  2930. IRC_CLIENT="Quassel [M]"
  2931. ;;
  2932. quasselclient)
  2933. IRC_CLIENT="Quassel"
  2934. ;;
  2935. quasselcore)
  2936. IRC_CLIENT="Quassel (core)"
  2937. ;;
  2938. esac
  2939. ;;
  2940. weechat-curses)
  2941. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v ) "
  2942. B_CONSOLE_IRC='true'
  2943. IRC_CLIENT="Weechat"
  2944. ;;
  2945. xchat-gnome)
  2946. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 {
  2947. print $2
  2948. }' )"
  2949. IRC_CLIENT="X-Chat-Gnome"
  2950. ;;
  2951. xchat)
  2952. IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 {
  2953. print $2
  2954. }' )"
  2955. IRC_CLIENT="X-Chat"
  2956. ;;
  2957. # then do some perl type searches, do this last since it's a wildcard search
  2958. perl*|ksirc|dsirc)
  2959. unset IRC_CLIENT_VERSION
  2960. # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
  2961. get_cmdline $PPID
  2962. for (( i=0; i <= $CMDL_MAX; i++ ))
  2963. do
  2964. case ${A_CMDL[i]} in
  2965. *dsirc*)
  2966. IRC_CLIENT="KSirc"
  2967. # Dynamic runpath detection is too complex with KSirc, because KSirc is started from
  2968. # kdeinit. /proc/<pid of the grandparent of this process>/exe is a link to /usr/bin/kdeinit
  2969. # with one parameter which contains parameters separated by spaces(??), first param being KSirc.
  2970. # Then, KSirc runs dsirc as the perl irc script and wraps around it. When /exec is executed,
  2971. # dsirc is the program that runs inxi, therefore that is the parent process that we see.
  2972. # You can imagine how hosed I am if I try to make inxi find out dynamically with which path
  2973. # KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
  2974. # (KSirc sucks anyway ;)
  2975. IRC_CLIENT_VERSION=" $( ksirc -v | gawk '
  2976. /KSirc:/ {
  2977. print $2
  2978. exit
  2979. }' )"
  2980. break
  2981. ;;
  2982. esac
  2983. done
  2984. B_CONSOLE_IRC='true'
  2985. set_perl_python_konvi "$App_Working_Name"
  2986. ;;
  2987. python*)
  2988. # B_CONSOLE_IRC='true' # are there even any python type console irc clients? check.
  2989. set_perl_python_konvi "$App_Working_Name"
  2990. ;;
  2991. # then unset, set unknown data
  2992. *)
  2993. IRC_CLIENT="Unknown : ${Irc_Client_Path##*/}"
  2994. unset IRC_CLIENT_VERSION
  2995. ;;
  2996. esac
  2997. if [[ $SHOW_IRC -lt 2 ]];then
  2998. unset IRC_CLIENT_VERSION
  2999. fi
  3000. }
  3001.  
  3002. # args: $1 - App_Working_Name
  3003. set_perl_python_konvi()
  3004. {
  3005. if [[ -z $IRC_CLIENT_VERSION ]];then
  3006. # this is a hack to try to show konversation if inxi is running but started via /cmd
  3007. if [[ -n $( grep -i 'konversation' <<< "$Ps_aux_Data" | grep -v 'grep' ) && $B_RUNNING_IN_X == 'true' ]];then
  3008. IRC_CLIENT='Konversation'
  3009. IRC_CLIENT_VERSION=" $( konversation --version 2>/dev/null | gawk '/^Konversation/ {print $2}' )"
  3010. B_CONSOLE_IRC='false'
  3011. else
  3012. IRC_CLIENT="Unknown $1 client"
  3013. fi
  3014. fi
  3015. }
  3016.  
  3017. ## try to infer the use of Konversation >= 1.2, which shows $PPID improperly
  3018. ## no known method of finding Kovni >= 1.2 as parent process, so we look to see if it is running,
  3019. ## and all other irc clients are not running.
  3020. is_this_qt4_konvi()
  3021. {
  3022. local konvi_qt4_client='' konvi_dbus_exist='' konvi_pid='' konvi_home_dir=''
  3023. local konvi='' konvi_qt4_ver='' b_is_qt4=''
  3024.  
  3025. # fringe cases can throw error, always if untested app, use 2>/dev/null after testing if present
  3026. if [[ $B_QDBUS == 'true' ]];then
  3027. konvi_dbus_exist=$( qdbus 2>/dev/null | grep "org.kde.konversation" )
  3028. fi
  3029. # sabayon uses /usr/share/apps/konversation as path
  3030. if [[ -n $konvi_dbus_exist ]] && [[ -e /usr/share/kde4/apps/konversation || -e /usr/share/apps/konversation ]]; then
  3031. konvi_pid=$( ps -A | gawk 'BEGIN{IGNORECASE=1} /konversation/ { print $1 }' )
  3032. konvi_home_dir=$( readlink /proc/$konvi_pid/exe )
  3033. konvi=$( echo $konvi_home_dir | sed "s/\// /g" )
  3034. konvi=($konvi)
  3035.  
  3036. if [[ ${konvi[2]} == 'konversation' ]];then
  3037. konvi_qt4_ver=$( konversation -v | grep -i 'konversation' )
  3038. # note: we need to change this back to a single dot number, like 1.3, not 1.3.2
  3039. konvi_qt4_client=$( echo "$konvi_qt4_ver" | gawk '{ print $2 }' | cut -d '.' -f 1,2 )
  3040.  
  3041. if [[ $konvi_qt4_client > 1.1 ]]; then
  3042. b_is_qt4='true'
  3043. fi
  3044. fi
  3045. else
  3046. konvi_qt4="qt3"
  3047. b_is_qt4='false'
  3048. fi
  3049. log_function_data "b_is_qt4: $b_is_qt4"
  3050. echo $b_is_qt4
  3051. ## for testing this module
  3052. #qdbus org.kde.konversation /irc say $1 $2 "getpid_dir: $konvi_qt4 qt4_konvi: $konvi_qt4_ver verNum: $konvi_qt4_ver_num pid: $konvi_pid ppid: $PPID konvi_home_dir: ${konvi[2]}"
  3053. }
  3054.  
  3055. # This needs some cleanup and comments, not quite understanding what is happening, although generally output is known
  3056. # Parse the null separated commandline under /proc/<pid passed in $1>/cmdline
  3057. # args: $1 - $PPID
  3058. get_cmdline()
  3059. {
  3060. eval $LOGFS
  3061. local i=0 ppid=$1
  3062.  
  3063. if [[ ! -e /proc/$ppid/cmdline ]];then
  3064. echo 0
  3065. return
  3066. fi
  3067. ##print_screen_output "Marker"
  3068. ##print_screen_output "\$ppid='$ppid' -=- $(< /proc/$ppid/cmdline)"
  3069. unset A_CMDL
  3070. ## note: need to figure this one out, and ideally clean it up and make it readable
  3071. while read -d $'\0' L && [[ $i -lt 32 ]]
  3072. do
  3073. A_CMDL[i++]="$L" ## note: make sure this is valid - What does L mean? ##
  3074. done < /proc/$ppid/cmdline
  3075. ##print_screen_output "\$i='$i'"
  3076. if [[ $i -eq 0 ]];then
  3077. A_CMDL[0]=$(< /proc/$ppid/cmdline)
  3078. if [[ -n ${A_CMDL[0]} ]];then
  3079. i=1
  3080. fi
  3081. fi
  3082. CMDL_MAX=$i
  3083. log_function_data "CMDL_MAX: $CMDL_MAX"
  3084. eval $LOGFE
  3085. }
  3086.  
  3087. #### -------------------------------------------------------------------
  3088. #### get data types
  3089. #### -------------------------------------------------------------------
  3090. ## create array of sound cards installed on system, and if found, use asound data as well
  3091. get_audio_data()
  3092. {
  3093. eval $LOGFS
  3094. local i='' alsa_data='' audio_driver='' device_count='' temp_array=''
  3095.  
  3096. IFS=$'\n'
  3097. # this first step handles the drivers for cases where the second step fails to find one
  3098. device_count=$( echo "$Lspci_v_Data" | grep -iEc '(multimedia audio controller|audio device)' )
  3099. if [[ $device_count -eq 1 ]] && [[ $B_ASOUND_DEVICE_FILE == 'true' ]];then
  3100. audio_driver=$( gawk -F ']: ' '
  3101. BEGIN {
  3102. IGNORECASE=1
  3103. }
  3104. # filtering out modems and usb devices like webcams, this might get a
  3105. # usb audio card as well, this will take some trial and error
  3106. $0 !~ /modem|usb|webcam/ {
  3107. driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
  3108. gsub(/^ +| +$/,"",driver)
  3109. if ( driver != "" ){
  3110. print driver
  3111. }
  3112. }' $FILE_ASOUND_DEVICE )
  3113. log_function_data 'cat' "$FILE_ASOUND_DEVICE"
  3114. fi
  3115.  
  3116. # this is to safeguard against line breaks from results > 1, which if inserted into following
  3117. # array will create a false array entry. This is a hack, not a permanent solution.
  3118. audio_driver=$( echo $audio_driver )
  3119. # now we'll build the main audio data, card name, driver, and port. If no driver is found,
  3120. # and if the first method above is not null, and one card is found, it will use that instead.
  3121. A_AUDIO_DATA=( $( echo "$Lspci_v_Data" | gawk -F ': ' -v audioDriver="$audio_driver" '
  3122. BEGIN {
  3123. IGNORECASE=1
  3124. }
  3125. /multimedia audio controller|audio device/ {
  3126. audioCard=gensub(/^[0-9a-f:\.]+ [^:]+: (.+)$/,"\\1","g",$0)
  3127. # The doublequotes are necessary because of the pipes in the variable.
  3128. gsub(/'"$BAN_LIST_NORMAL"'/, "", audioCard)
  3129. gsub(/,/, " ", audioCard)
  3130. gsub(/^ +| +$/, "", audioCard)
  3131. gsub(/ [ \t]+/, " ", audioCard)
  3132. aPciBusId[audioCard] = gensub(/(^[0-9a-f:\.]+) [^:]+: .+$/,"\\1","g",$0)
  3133. cards[audioCard]++
  3134.  
  3135. # loop until you get to the end of the data block
  3136. while (getline && !/^$/) {
  3137. gsub( /,/, "", $0 )
  3138. if (/driver in use/) {
  3139. drivers[audioCard] = drivers[audioCard] gensub( /(.*): (.*)/ ,"\\2", "g" ,$0 ) ""
  3140. }
  3141. else if (/kernel modules:/) {
  3142. modules[audioCard] = modules[audioCard] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) ""
  3143. }
  3144. else if (/I\/O/) {
  3145. portsTemp = gensub(/\t*I\/O ports at (.*) \[.*\]/,"\\1","g",$0)
  3146. ports[audioCard] = ports[audioCard] portsTemp " "
  3147. }
  3148. }
  3149. }
  3150.  
  3151. END {
  3152. j=0
  3153. for (i in cards) {
  3154. useDrivers=""
  3155. useModules=""
  3156. usePorts=""
  3157. usePciBusId=""
  3158.  
  3159. if (cards[i]>1) {
  3160. a[j]=cards[i]"x "i
  3161. if (drivers[i] != "") {
  3162. useDrivers=drivers[i]
  3163. }
  3164. }
  3165. else {
  3166. a[j]=i
  3167. # little trick here to try to catch the driver if there is
  3168. # only one card and it was null, from the first test of asound/cards
  3169. if (drivers[i] != "") {
  3170. useDrivers=drivers[i]
  3171. }
  3172. else if ( audioDriver != "" ) {
  3173. useDrivers=audioDriver
  3174. }
  3175. }
  3176. if (ports[i] != "") {
  3177. usePorts = ports[i]
  3178. }
  3179. if (modules[i] != "" ) {
  3180. useModules = modules[i]
  3181. }
  3182. if ( aPciBusId[i] != "" ) {
  3183. usePciBusId = aPciBusId[i]
  3184. }
  3185. # create array primary item for master array
  3186. sub( / $/, "", usePorts ) # clean off trailing whitespace
  3187. print a[j] "," useDrivers "," usePorts "," useModules "," usePciBusId
  3188. j++
  3189. }
  3190. }') )
  3191.  
  3192. # in case of failure of first check do this instead
  3193. if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]] && [[ $B_ASOUND_DEVICE_FILE == 'true' ]];then
  3194. A_AUDIO_DATA=( $( gawk -F ']: ' '
  3195. BEGIN {
  3196. IGNORECASE=1
  3197. }
  3198. $1 !~ /modem/ && $2 !~ /modem/ {
  3199. card=gensub( /^(.+)( - )(.+)$/, "\\3", 1, $2 )
  3200. driver=gensub( /^(.+)( - )(.+)$/, "\\1", 1, $2 )
  3201. if ( card != "" ){
  3202. print card","driver
  3203. }
  3204. }' $FILE_ASOUND_DEVICE ) )
  3205. fi
  3206. IFS="$ORIGINAL_IFS"
  3207. get_audio_usb_data
  3208. # handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
  3209. if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]];then
  3210. A_AUDIO_DATA[0]='Failed to Detect Sound Card!'
  3211. fi
  3212. temp_array=${A_AUDIO_DATA[@]}
  3213. log_function_data "A_AUDIO_DATA: $temp_array"
  3214.  
  3215. eval $LOGFE
  3216. }
  3217. # alsa usb detection by damentz
  3218.  
  3219. get_audio_usb_data()
  3220. {
  3221. eval $LOGFS
  3222. local usb_proc_file='' array_count='' usb_data='' usb_id='' lsusb_path='' lsusb_data=''
  3223. local temp_array=''
  3224.  
  3225. IFS=$'\n'
  3226. lsusb_path=$( type -p lsusb )
  3227. if [[ -n $lsusb_path ]];then
  3228. lsusb_data=$( $lsusb_path 2>/dev/null )
  3229. fi
  3230. log_function_data 'raw' "usb_data:\n$lsusb_data"
  3231. if [[ -n $lsusb_data ]];then
  3232. # for every sound card symlink in /proc/asound - display information about it
  3233. for usb_proc_file in /proc/asound/*
  3234. do
  3235. # If the file is a symlink, and contains an important usb exclusive file: continue
  3236. if [[ -L $usb_proc_file && -e $usb_proc_file/usbid ]]; then
  3237. # find the contents of usbid in lsusb and print everything after the 7th word on the
  3238. # corresponding line. Finally, strip out commas as they will change the driver :)
  3239. usb_id=$( cat $usb_proc_file/usbid )
  3240. usb_data=$( grep "$usb_id" <<< "$lsusb_data" )
  3241. if [[ -n $usb_data && -n $usb_id ]];then
  3242. usb_data=$( gawk '
  3243. BEGIN {
  3244. IGNORECASE=1
  3245. string=""
  3246. separator=""
  3247. }
  3248. {
  3249. gsub( /,/, " ", $0 )
  3250. gsub(/'"$BAN_LIST_NORMAL"'/, "", $0)
  3251. gsub(/ [ \t]+/, " ", $0)
  3252. for ( i=7; i<= NF; i++ ) {
  3253. string = string separator $i
  3254. separator = " "
  3255. }
  3256. if ( $2 != "" ){
  3257. sub(/:/,"", $4)
  3258. print string ",USB Audio,,," $2 "-" $4 "," $6
  3259. }
  3260. }' <<< "$usb_data" )
  3261. fi
  3262. # this method is interesting, it shouldn't work but it does
  3263. #A_AUDIO_DATA=( "${A_AUDIO_DATA[@]}" "$usb_data,USB Audio,," )
  3264. # but until we learn why the above worked, I'm using this one, which is safer
  3265. if [[ -n $usb_data ]];then
  3266. array_count=${#A_AUDIO_DATA[@]}
  3267. A_AUDIO_DATA[$array_count]="$usb_data"
  3268. fi
  3269. fi
  3270. done
  3271. fi
  3272. IFS="$ORIGINAL_IFS"
  3273. temp_array=${A_AUDIO_DATA[@]}
  3274. log_function_data "A_AUDIO_DATA: $temp_array"
  3275.  
  3276. eval $LOGFE
  3277. }
  3278.  
  3279. get_audio_alsa_data()
  3280. {
  3281. eval $LOGFS
  3282. local alsa_data='' temp_array=''
  3283.  
  3284. # now we'll get the alsa data if the file exists
  3285. if [[ $B_ASOUND_VERSION_FILE == 'true' ]];then
  3286. IFS=","
  3287. A_ALSA_DATA=( $(
  3288. gawk '
  3289. BEGIN {
  3290. IGNORECASE=1
  3291. alsa=""
  3292. version=""
  3293. }
  3294. # some alsa strings have the build date in (...)
  3295. # remove trailing . and remove possible second line if compiled by user
  3296. $0 !~ /compile/ {
  3297. gsub( /Driver | [(].*[)]|\.$/,"",$0 )
  3298. gsub(/,/, " ", $0)
  3299. gsub(/^ +| +$/, "", $0)
  3300. gsub(/ [ \t]+/, " ", $0)
  3301. sub(/Advanced Linux Sound Architecture/, "ALSA", $0)
  3302. if ( $1 == "ALSA" ){
  3303. alsa=$1
  3304. }
  3305. version=$NF
  3306. print alsa "," version
  3307. }' $FILE_ASOUND_VERSION ) )
  3308. IFS="$ORIGINAL_IFS"
  3309. log_function_data 'cat' "$FILE_ASOUND_VERSION"
  3310. fi
  3311. temp_array=${A_ALSA_DATA[@]}
  3312. log_function_data "A_ALSA_DATA: $temp_array"
  3313. eval $LOGFE
  3314. }
  3315.  
  3316. ## create A_CPU_CORE_DATA, currently with two values: integer core count; core string text
  3317. ## return value cpu core count string, this helps resolve the multi redundant lines of old style output
  3318. get_cpu_core_count()
  3319. {
  3320. eval $LOGFS
  3321. local cpu_physical_count='' cpu_core_count='' cpu_type='' cpu_alpha_count=''
  3322. if [[ $B_CPUINFO_FILE == 'true' ]]; then
  3323. # load the A_CPU_TYPE_PCNT_CCNT core data array
  3324. get_cpu_ht_multicore_smp_data
  3325. ## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10)
  3326. # count the number of processors given
  3327. cpu_physical_count=${A_CPU_TYPE_PCNT_CCNT[1]}
  3328. cpu_core_count=${A_CPU_TYPE_PCNT_CCNT[2]}
  3329. cpu_type=${A_CPU_TYPE_PCNT_CCNT[0]}
  3330.  
  3331. # match the numberic value to an alpha value
  3332. cpu_alpha_count=$( get_cpu_core_count_alpha "$cpu_core_count" )
  3333.  
  3334. # create array, core count integer; core count string
  3335. # A_CPU_CORE_DATA=( "$cpu_core_count" "$cpu_alpha_count Core$cpu_type" )
  3336. A_CPU_CORE_DATA=( "$cpu_physical_count" "$cpu_alpha_count" "$cpu_type" "$cpu_core_count" )
  3337. elif [[ -n $BSD_TYPE ]];then
  3338. local gawk_fs=': '
  3339.  
  3340. if [[ $BSD_VERSION == 'openbsd' ]];then
  3341. gawk_fs='='
  3342. fi
  3343. cpu_core_count=$( gawk -F "$gawk_fs" '
  3344. # note: on openbsd can also be hw.ncpufound so exit after first
  3345. /^hw.ncpu/ {
  3346. print $NF
  3347. exit
  3348. }' <<< "$Sysctl_a_Data" )
  3349. if [[ -n $( grep -E '^[0-9]+$' <<< "$cpu_core_count" ) ]];then
  3350. cpu_alpha_count=$( get_cpu_core_count_alpha "$cpu_core_count" )
  3351. if [[ $cpu_core_count -gt 1 ]];then
  3352. cpu_type='SMP'
  3353. fi
  3354. fi
  3355. cpu_physical_count=1
  3356. A_CPU_CORE_DATA=( "$cpu_physical_count" "$cpu_alpha_count" "$cpu_type" "$cpu_core_count" )
  3357. fi
  3358. temp_array=${A_CPU_CORE_DATA[@]}
  3359. log_function_data "A_CPU_CORE_DATA: $temp_array"
  3360. eval $LOGFE
  3361. }
  3362.  
  3363. # args: $1 - integer core count
  3364. get_cpu_core_count_alpha()
  3365. {
  3366. eval $LOGFS
  3367. local cpu_alpha_count=''
  3368.  
  3369. case $1 in
  3370. 1) cpu_alpha_count='Single';;
  3371. 2) cpu_alpha_count='Dual';;
  3372. 3) cpu_alpha_count='Triple';;
  3373. 4) cpu_alpha_count='Quad';;
  3374. 5) cpu_alpha_count='Penta';;
  3375. 6) cpu_alpha_count='Hexa';;
  3376. 7) cpu_alpha_count='Hepta';;
  3377. 8) cpu_alpha_count='Octa';;
  3378. 9) cpu_alpha_count='Ennea';;
  3379. 10) cpu_alpha_count='Deca';;
  3380. *) cpu_alpha_count='Multi';;
  3381. esac
  3382.  
  3383. echo $cpu_alpha_count
  3384.  
  3385. eval $LOGFE
  3386. }
  3387.  
  3388. ## main cpu data collector
  3389. get_cpu_data()
  3390. {
  3391. eval $LOGFS
  3392. local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits='' temp_array=''
  3393. local bsd_cpu_flags=''
  3394.  
  3395. if [[ $B_CPUINFO_FILE == 'true' ]];then
  3396. # stop script for a bit to let cpu slow down before parsing cpu /proc file
  3397. sleep $CPU_SLEEP
  3398. IFS=$'\n'
  3399. A_CPU_DATA=( $(
  3400. gawk -F': ' '
  3401. BEGIN {
  3402. IGNORECASE=1
  3403. # need to prime nr for arm cpus, which do not have processor number output in some cases
  3404. nr = 0
  3405. count = 0
  3406. bArm = "false"
  3407. }
  3408. # TAKE STRONGER NOTE: \t+ does NOT always work, MUST be [ \t]+
  3409. # TAKE NOTE: \t+ will work for $FILE_CPUINFO, but SOME ARBITRARY FILE used for TESTING might contain SPACES!
  3410. # Therefore PATCH to use [ \t]+ when TESTING!
  3411. /^processor[ \t]+:/ {
  3412. gsub(/,/, " ", $NF)
  3413. gsub(/^ +| +$/, "", $NF)
  3414. if ( $NF ~ "^[0-9]+$" ) {
  3415. nr = $NF
  3416. }
  3417. else {
  3418. if ( $NF ~ "^ARM" ) {
  3419. bArm = "true"
  3420. }
  3421. count += 1
  3422. nr = count - 1
  3423. cpu[nr, "model"] = $NF
  3424. }
  3425. }
  3426.  
  3427. /^model name|^cpu\t+:/ {
  3428. gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
  3429. gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
  3430. gsub(/,/, " ", $NF)
  3431. gsub(/^ +| +$/, "", $NF)
  3432. gsub(/ [ \t]+/, " ", $NF)
  3433. cpu[nr, "model"] = $NF
  3434. if ( $NF ~ "^ARM" ) {
  3435. bArm = "true"
  3436. }
  3437. }
  3438.  
  3439. /^cpu MHz|^clock\t+:/ {
  3440. if (!min) {
  3441. min = $NF
  3442. }
  3443. else {
  3444. if ($NF < min) {
  3445. min = $NF
  3446. }
  3447. }
  3448.  
  3449. if ($NF > max) {
  3450. max = $NF
  3451. }
  3452. gsub(/MHZ/,"",$NF) ## clears out for cell cpu
  3453. gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros
  3454. cpu[nr, "speed"] = $NF
  3455. }
  3456.  
  3457. /^cache size/ {
  3458. cpu[nr, "cache"] = $NF
  3459. }
  3460.  
  3461. /^flags|^features/ {
  3462. cpu[nr, "flags"] = $NF
  3463. # not all ARM cpus show ARM in model name
  3464. if ( $1 ~ /^features/ ) {
  3465. bArm = "true"
  3466. }
  3467. }
  3468.  
  3469. /^bogomips/ {
  3470. cpu[nr, "bogomips"] = $NF
  3471. }
  3472.  
  3473. /vendor_id/ {
  3474. gsub(/genuine|authentic/,"",$NF)
  3475. cpu[nr, "vendor"] = tolower( $NF )
  3476. }
  3477.  
  3478. END {
  3479. #if (!nr) { print ",,,"; exit } # <- should this be necessary or should bash handle that
  3480. for ( i = 0; i <= nr; i++ ) {
  3481. # note: assuming bogomips for arm at 1 x clock
  3482. # http://en.wikipedia.org/wiki/BogoMips ARM could change so watch this
  3483. # maybe add: && bArm == "true" but I think most of the bogomips roughly equal cpu speed if not amd/intel
  3484. if ( cpu[i, "bogomips"] != "" && cpu[i, "speed"] == "" ) {
  3485. cpu[i, "speed"] = cpu[i, "bogomips"]
  3486. }
  3487. print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] "," cpu[nr, "vendor"] "," bArm
  3488. }
  3489. # this is / was used in inxi short output only, but when it is N/A, need to use the previous array
  3490. # value, from above, the actual speed that is, for short output, key 0.
  3491. if (!min) {
  3492. print "N/A"
  3493. exit
  3494. }
  3495. else {
  3496. if (min != max) {
  3497. printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz")
  3498. }
  3499. else {
  3500. printf("%s %s\n", max, "Mhz")
  3501. }
  3502. }
  3503. }
  3504. ' $FILE_CPUINFO ) )
  3505. IFS="$ORIGINAL_IFS"
  3506. log_function_data 'cat' "$FILE_CPUINFO"
  3507. elif [[ -n $BSD_TYPE ]];then
  3508. get_cpu_data_bsd
  3509. fi
  3510.  
  3511. temp_array=${A_CPU_DATA[@]}
  3512. log_function_data "A_CPU_DATA: $temp_array"
  3513. # echo ta: ${temp_array[@]}
  3514. eval $LOGFE
  3515. # echo getMainCpu: ${[@]}
  3516. }
  3517.  
  3518. get_cpu_data_bsd()
  3519. {
  3520. eval $LOGFS
  3521.  
  3522. local bsd_cpu_flags=$( get_cpu_flags_bsd )
  3523. local gawk_fs=': '
  3524.  
  3525. if [[ $BSD_VERSION == 'openbsd' ]];then
  3526. gawk_fs='='
  3527. fi
  3528.  
  3529. IFS=$'\n'
  3530. A_CPU_DATA=( $(
  3531. gawk -F "$gawk_fs" -v cpuFlags="$bsd_cpu_flags" '
  3532. BEGIN {
  3533. IGNORECASE=1
  3534. cpuModel=""
  3535. cpuClock=""
  3536. cpuCache=""
  3537. cpuBogomips=""
  3538. cpuVendor=""
  3539. }
  3540. /^hw.model/ {
  3541. gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
  3542. gsub(/'"$BAN_LIST_CPU"'/, "", $NF )
  3543. sub(//,"",$NF)
  3544. sub(/[a-z]+-core/, "", $NF )
  3545. gsub(/^ +| +$|\"/, "", $NF)
  3546. gsub(/ [ \t]+/, " ", $NF)
  3547. cpuModel=$NF
  3548. if ( cpuClock != "" ) {
  3549. exit
  3550. }
  3551. }
  3552. /^hw.(clock|cpuspeed)/ {
  3553. cpuClock=$NF
  3554. if ( cpuModel != "" ) {
  3555. exit
  3556. }
  3557. }
  3558. END {
  3559. print cpuModel "," cpuClock "," cpuCache "," cpuFlags "," cpuBogomips "," cpuVendor
  3560. print "N/A"
  3561. }' <<< "$Sysctl_a_Data" ) )
  3562. IFS="$ORIGINAL_IFS"
  3563.  
  3564. eval $LOGFE
  3565. }
  3566.  
  3567. get_cpu_flags_bsd()
  3568. {
  3569. eval $LOGFS
  3570.  
  3571. local cpu_flags=$( gawk -F '=' '
  3572. BEGIN {
  3573. IGNORECASE=1
  3574. cpuFlags=""
  3575. }
  3576. /^CPU:/ {
  3577. while ( getline && !/memory/ ) {
  3578. if ( $1 ~ /Features/ ) {
  3579. # clean up odd stuff like <b23>
  3580. gsub(/<[a-z0-9]+>/,"", $2)
  3581. # all the flags are contained within < ... > on freebsd at least
  3582. gsub(/.*<|>.*/,"", $2)
  3583. gsub(/,/," ", $2)
  3584. cpuFlags = cpuFlags " " $2
  3585. }
  3586. }
  3587. cpuFlags=tolower(cpuFlags)
  3588. print cpuFlags
  3589. exit
  3590. }' <<< "$Dmesg_Boot_Data" )
  3591.  
  3592. echo $cpu_flags
  3593. log_function_data "$cpu_flags"
  3594. eval $LOGFE
  3595. }
  3596.  
  3597. ## this is for counting processors and finding HT types
  3598. get_cpu_ht_multicore_smp_data()
  3599. {
  3600. eval $LOGFS
  3601. # in /proc/cpuinfo
  3602. local temp_array=''
  3603.  
  3604. # note: known bug with xeon intel, they show a_core_id/physical_id as 0 for ht 4 core
  3605. if [[ $B_CPUINFO_FILE == 'true' ]]; then
  3606. A_CPU_TYPE_PCNT_CCNT=( $(
  3607. gawk '
  3608. BEGIN {
  3609. FS=": "
  3610. IGNORECASE = 1
  3611. num_of_cores = 0
  3612. num_of_processors = 0
  3613. num_of_physical_cpus = 0
  3614. cpu_core_count = 0
  3615. siblings = 0
  3616. # these 3 arrays cannot be declared because that sets the first element
  3617. # but leaving this here so that we avoid doing that in the future
  3618. # a_core_id = ""
  3619. # a_processor_id = ""
  3620. # a_physical_id = ""
  3621. cpu_type = "-"
  3622. # note: we need separate iterators because some cpuinfo data has only
  3623. # processor, no core id or phys id
  3624. proc_iter = 0
  3625. core_iter = "" # set from actual NF data
  3626. phys_iter = "" # set from actual NF data
  3627. # needed to handle arm cpu, no processor number cases
  3628. arm_count = 0
  3629. nr = 0
  3630. bArm = "false"
  3631. bXeon = "false"
  3632. }
  3633. # hack to handle xeons which can have buggy /proc/cpuinfo files
  3634. /^model name/ && ( $0 ~ /Xeon/ ) {
  3635. bXeon = "true"
  3636. }
  3637. # only do this once since sibling count does not change.
  3638. /^siblings/ && ( bXeon == "true" ) && ( siblings == 0 ) {
  3639. gsub(/[^0-9]/,"",$NF)
  3640. if ( $NF != "" ) {
  3641. siblings = $NF
  3642. }
  3643. }
  3644. # array of logical processors, both HT and physical
  3645.  
  3646. /^processor/ {
  3647. gsub(/,/, " ", $NF)
  3648. gsub(/^ +| +$/, "", $NF)
  3649. if ( $NF ~ "^[0-9]+$" ) {
  3650. a_processor_id[proc_iter] = $NF
  3651. proc_iter++
  3652. }
  3653. else {
  3654. # note, for dual core, this can be off by one because the first
  3655. # line says: Processor : Arm.. but subsequent say: processor : 0 and so on as usual
  3656. if ( $NF ~ "^ARM" ) {
  3657. bArm = "true"
  3658. }
  3659. arm_count += 1
  3660. nr = arm_count - 1
  3661. # note: do not iterate because new ARM syntax puts cpu in processsor : 0 syntax
  3662. a_processor_id[proc_iter] = nr
  3663. }
  3664. }
  3665.  
  3666. # array of physical cpu ids, note, this will be unset for vm cpus in many cases
  3667. # because they have no physical cpu, so we cannot assume this will be here.
  3668. /^physical/ {
  3669. phys_iter = $NF
  3670. a_physical_id[phys_iter] = $NF
  3671. }
  3672. # array of core ids, again, here we may have HT, so we need to create an array of the
  3673. # actual core ids. As With physical, we cannot assume this will be here in a vm
  3674. /^core id/ {
  3675. core_iter = $NF
  3676. a_core_id[core_iter] = $NF
  3677. }
  3678. # this will be used to fix an intel glitch if needed, cause, intel
  3679. # sometimes reports core id as the same number for each core,
  3680. # so if cpu cores shows greater value than number of cores, use this.
  3681. /^cpu cores/ {
  3682. cpu_core_count = $NF
  3683. }
  3684. END {
  3685. ## Look thru the array and filter same numbers.
  3686. ## only unique numbers required
  3687. ## this is to get an accurate count
  3688. ## we are only concerned with array length
  3689. i = 0
  3690. ## count unique processors ##
  3691. # note, this fails for intel cpus at times
  3692. for ( i in a_processor_id ) {
  3693. num_of_processors++
  3694. }
  3695. i = 0
  3696. ## count unique physical cpus ##
  3697. for ( i in a_physical_id ) {
  3698. num_of_physical_cpus++
  3699. }
  3700.  
  3701. i = 0
  3702. ## count unique cores ##
  3703. for ( i in a_core_id ) {
  3704. num_of_cores++
  3705. }
  3706. # xeon may show wrong core / physical id count, if it does, fix it. A xeon
  3707. # may show a repeated core id : 0 which gives a fake num_of_cores=1
  3708. if ( bXeon == "true" && num_of_cores == 1 && siblings > 1 ) {
  3709. num_of_cores = siblings/2
  3710. }
  3711. # final check, override the num of cores value if it clearly is wrong
  3712. # and use the raw core count and synthesize the total instead of real count
  3713. if ( ( num_of_cores == 0 ) && ( cpu_core_count * num_of_physical_cpus > 1 ) ) {
  3714. num_of_cores = cpu_core_count * num_of_physical_cpus
  3715. }
  3716. # last check, seeing some intel cpus and vms with intel cpus that do not show any
  3717. # core id data at all, or siblings.
  3718. if ( num_of_cores == 0 && num_of_processors > 0 ) {
  3719. num_of_cores = num_of_processors
  3720. }
  3721. # ARM/vm cpu fix, if no physical or core found, use count of 1 instead
  3722. if ( num_of_physical_cpus == 0 ) {
  3723. num_of_physical_cpus = 1
  3724. }
  3725. # print "NoCpu: " num_of_physical_cpus
  3726. # print "NoCores: " num_of_cores
  3727. # print "NoProc:" num_of_processors
  3728. # print "CpuCoreCount:" cpu_core_count
  3729. ####################################################################
  3730. # algorithm
  3731. # if > 1 processor && processor id (physical id) == core id then Hyperthreaded (HT)
  3732. # if > 1 processor && processor id (physical id) != core id then Multi-Core Processors (MCP)
  3733. # if > 1 processor && processor ids (physical id) > 1 then Multiple Processors (SMP)
  3734. # if = 1 processor then single core/processor Uni-Processor (UP)
  3735. if ( num_of_processors > 1 || ( bXeon == "true" && siblings > 0 ) ) {
  3736. # non-multicore HT
  3737. if ( num_of_processors == (num_of_cores * 2) ) {
  3738. cpu_type = cpu_type "HT-"
  3739. }
  3740. else if ( bXeon == "true" && siblings > 1 ) {
  3741. cpu_type = cpu_type "HT-"
  3742. }
  3743. # non-HT multi-core or HT multi-core
  3744. if (( num_of_processors == num_of_cores) || ( num_of_physical_cpus < num_of_cores)) {
  3745. cpu_type = cpu_type "MCP-"
  3746. }
  3747. # >1 cpu sockets active
  3748. if ( num_of_physical_cpus > 1 ) {
  3749. cpu_type = cpu_type "SMP-"
  3750. }
  3751. }
  3752. else {
  3753. cpu_type = cpu_type "UP-"
  3754. }
  3755.  
  3756. print cpu_type " " num_of_physical_cpus " " num_of_cores
  3757. }
  3758. ' $FILE_CPUINFO ) )
  3759. fi
  3760. temp_array=${A_CPU_TYPE_PCNT_CCNT[@]}
  3761. log_function_data "A_CPU_TYPE_PCNT_CCNT: $temp_array"
  3762. eval $LOGFE
  3763. }
  3764.  
  3765. # Detect desktop environment in use, initial rough logic from: compiz-check
  3766. # http://forlong.blogage.de/entries/pages/Compiz-Check
  3767. get_desktop_environment()
  3768. {
  3769. eval $LOGFS
  3770.  
  3771. # set the default, this function only runs in X, if null, don't print data out
  3772. local desktop_environment='' xprop_root=''
  3773. local version='' version_data='' toolkit=''
  3774.  
  3775. if [[ -n $( type -p xprop ) ]];then
  3776. xprop_root="$( xprop -root 2>/dev/null )"
  3777. fi
  3778.  
  3779. # note that cinnamon split from gnome, and and can now be id'ed via xprop,
  3780. # but it will still trigger the next gnome true case, so this needs to go before gnome test
  3781. # eventually this needs to be better organized so all the xprop tests are in the same
  3782. # section, but this is good enough for now.
  3783. if [[ -n $xprop_root && -n $( grep -is '^_MUFFIN' <<< "$xprop_root" ) ]];then
  3784. version=$( get_de_app_version 'cinnamon' '^cinnamon' '2' )
  3785. # not certain cinn will always have version, so keep output right if not
  3786. if [[ -n $version ]];then
  3787. version="$version "
  3788. fi
  3789. if [[ $B_EXTRA_DATA == 'true' ]];then
  3790. toolkit=$( get_de_gtk_data )
  3791. if [[ -n $toolkit ]];then
  3792. version="${version}(Gtk ${toolkit})"
  3793. fi
  3794. fi
  3795. desktop_environment="Cinnamon"
  3796. elif [[ -n $xprop_root && -n $( grep -is '^_MARCO' <<< "$xprop_root" ) ]];then
  3797. version=$( get_de_app_version 'mate-about' '^MATE[[:space:]]DESKTOP' 'NF' )
  3798. # not certain cinn/mate will always have version, so keep output right if not
  3799. if [[ -n $version ]];then
  3800. version="$version "
  3801. fi
  3802. if [[ $B_EXTRA_DATA == 'true' ]];then
  3803. toolkit=$( get_de_gtk_data )
  3804. if [[ -n $toolkit ]];then
  3805. version="${version}(Gtk ${toolkit})"
  3806. fi
  3807. fi
  3808. desktop_environment="MATE"
  3809. # note, GNOME_DESKTOP_SESSION_ID is deprecated so we'll see how that works out
  3810. # https://bugzilla.gnome.org/show_bug.cgi?id=542880
  3811. elif [[ -n $GNOME_DESKTOP_SESSION_ID ]]; then
  3812. if [[ -n $( type -p gnome-shell ) ]];then
  3813. version=$( get_de_app_version 'gnome-shell' 'gnome' '3' )
  3814. elif [[ -n $( type -p gnome-about ) ]];then
  3815. version=$( get_de_app_version 'gnome-about' 'gnome' '3' )
  3816. fi
  3817. if [[ $B_EXTRA_DATA == 'true' ]];then
  3818. toolkit=$( get_de_gtk_data )
  3819. if [[ -n $toolkit ]];then
  3820. version="$version (Gtk $toolkit)"
  3821. fi
  3822. fi
  3823. desktop_environment="Gnome"
  3824. # assume 5 will id the same, why not, no need to update in future
  3825. elif [[ $KDE_SESSION_VERSION == '5' ]]; then
  3826. version_data=$( kded5 --version 2>/dev/null )
  3827. version=$( grep -si '^KDE Development Platform:' <<< "$version_data" | gawk '{print $4}' )
  3828. if [[ -z $version ]];then
  3829. version='5'
  3830. fi
  3831. if [[ $B_EXTRA_DATA == 'true' ]];then
  3832. toolkit=$( grep -si '^Qt:' <<< "$version_data" | gawk '{print $2}' )
  3833. if [[ -n $toolkit ]];then
  3834. version="$version (Qt $toolkit)"
  3835. fi
  3836. fi
  3837. desktop_environment="KDE"
  3838. elif [[ $KDE_SESSION_VERSION == '4' ]]; then
  3839. version_data=$( kded4 --version 2>/dev/null )
  3840. version=$( grep -si '^KDE Development Platform:' <<< "$version_data" | gawk '{print $4}' )
  3841. if [[ -z $version ]];then
  3842. version='4'
  3843. fi
  3844. if [[ $B_EXTRA_DATA == 'true' ]];then
  3845. toolkit=$( grep -si '^Qt:' <<< "$version_data" | gawk '{print $2}' )
  3846. if [[ -n $toolkit ]];then
  3847. version="$version (Qt $toolkit)"
  3848. fi
  3849. fi
  3850. desktop_environment="KDE"
  3851. # KDE_FULL_SESSION property is only available since KDE 3.5.5.
  3852. # src: http://humanreadable.nfshost.com/files/startkde
  3853. elif [[ $KDE_FULL_SESSION == 'true' ]]; then
  3854. version_data=$( kded --version 2>/dev/null )
  3855. version=$( grep -si '^KDE:' <<< "$version_data" | gawk '{print $2}' )
  3856. # version=$( get_de_app_version 'kded' '^KDE:' '2' )
  3857. if [[ -z $version ]];then
  3858. version='3.5'
  3859. fi
  3860. if [[ $B_EXTRA_DATA == 'true' ]];then
  3861. toolkit=$( grep -si '^Qt:' <<< "$version_data" | gawk '{print $2}' )
  3862. if [[ -n $toolkit ]];then
  3863. version="$version (Qt $toolkit)"
  3864. fi
  3865. fi
  3866. desktop_environment="KDE"
  3867. # now that the primary ones have been handled, next is to find the ones with unique
  3868. # xprop detections possible
  3869. else
  3870. if [[ -n $xprop_root ]];then
  3871. # String: "This is xfdesktop version 4.2.12"
  3872. if [[ -n $( grep -Eis '\"xfce4\"' <<< "$xprop_root" ) ]];then
  3873. version=$( get_de_app_version 'xfdesktop' 'xfdesktop[[:space:]]version' '5' )
  3874. if [[ -z $version ]];then
  3875. version='4'
  3876. fi
  3877. if [[ $B_EXTRA_DATA == 'true' ]];then
  3878. toolkit=$( get_de_app_version 'xfdesktop' 'Built[[:space:]]with[[:space:]]GTK' '4' )
  3879. if [[ -n $toolkit ]];then
  3880. version="$version (Gtk $toolkit)"
  3881. fi
  3882. fi
  3883. desktop_environment="Xfce"
  3884. # when 5 is released, the string may need updating
  3885. elif [[ -n $( grep -is '\"xfce5\"' <<< "$xprop_root" ) ]];then
  3886. version=$( get_de_app_version 'xfdesktop' 'xfdesktop[[:space:]]version' '5' )
  3887. if [[ -z $version ]];then
  3888. version='5'
  3889. fi
  3890. if [[ $B_EXTRA_DATA == 'true' ]];then
  3891. toolkit=$( get_de_app_version 'xfdesktop' 'Built[[:space:]]with[[:space:]]GTK' '4' )
  3892. if [[ -n $toolkit ]];then
  3893. version="$version (Gtk $toolkit)"
  3894. fi
  3895. fi
  3896. desktop_environment="Xfce"
  3897. elif [[ -n $( grep -is 'BLACKBOX_PID' <<< "$xprop_root" ) ]];then
  3898. if [[ -n $( grep -is 'fluxbox' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3899. version=$( get_de_app_version 'fluxbox' '^fluxbox' '2' )
  3900. desktop_environment='Fluxbox'
  3901. else
  3902. desktop_environment='Blackbox'
  3903. fi
  3904. elif [[ -n $( grep -is 'OPENBOX_PID' <<< "$xprop_root" ) ]];then
  3905. version=$( get_de_app_version 'openbox' '^openbox' '2' )
  3906. if [[ -n $( grep -is 'lxde' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3907. if [[ -n $version ]];then
  3908. version="(Openbox $version)"
  3909. fi
  3910. desktop_environment='LXDE'
  3911. elif [[ -n $( grep -is 'razor-desktop' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3912. if [[ -n $version ]];then
  3913. version="(Openbox $version)"
  3914. fi
  3915. desktop_environment='Razor-QT'
  3916. else
  3917. desktop_environment='Openbox'
  3918. fi
  3919. elif [[ -n $( grep -is 'ICEWM' <<< "$xprop_root" ) ]];then
  3920. version=$( get_de_app_version 'icewm' '^icewm' '2' )
  3921. desktop_environment='IceWM'
  3922. elif [[ -n $( grep -is 'ENLIGHTENMENT' <<< "$xprop_root" ) ]];then
  3923. # no -v or --version but version is in xprop -root
  3924. # ENLIGHTENMENT_VERSION(STRING) = "Enlightenment 0.16.999.49898"
  3925. version=$( grep -is 'ENLIGHTENMENT_VERSION' <<< "$xprop_root" | cut -d '"' -f 2 | gawk '{print $2}' )
  3926. desktop_environment='Enlightenment'
  3927. elif [[ -n $( grep -is '^I3_' <<< "$xprop_root" ) ]];then
  3928. version=$( get_de_app_version 'i3' '^i3' '3' )
  3929. desktop_environment='i3'
  3930. elif [[ -n $( grep -is 'WINDOWMAKER' <<< "$xprop_root" ) ]];then
  3931. version=$( get_de_app_version 'wmaker' '^Window[[:space:]]*Maker' 'NF' )
  3932. if [[ -n $version ]];then
  3933. version="$version "
  3934. fi
  3935. desktop_environment="WindowMaker"
  3936. elif [[ -n $( grep -is '^_WM2' <<< "$xprop_root" ) ]];then
  3937. # note; there isn't actually a wm2 version available but error handling should cover it and return null
  3938. # maybe one day they will add it?
  3939. version=$( get_de_app_version 'wm2' '^wm2' 'NF' )
  3940. # not certain will always have version, so keep output right if not
  3941. if [[ -n $version ]];then
  3942. version="$version "
  3943. fi
  3944. desktop_environment="WM2"
  3945. elif [[ -n $( grep -is 'herbstluftwm' <<< "$xprop_root" ) ]];then
  3946. version=$( get_de_app_version 'herbstluftwm' '^herbstluftwm' 'NF' )
  3947. if [[ -n $version ]];then
  3948. version="$version "
  3949. fi
  3950. desktop_environment="herbstluftwm"
  3951. fi
  3952. fi
  3953. # a few manual hacks for things that don't id with xprop, these are just good guesses
  3954. # note that gawk is going to exit after first occurance of search string, so no need for extra
  3955. if [[ -z $desktop_environment ]];then
  3956. if [[ -n $( grep -is 'fvwm-crystal' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3957. version=$( get_de_app_version 'fvwm' '^fvwm' '2' )
  3958. desktop_environment='FVWM-Crystal'
  3959. elif [[ -n $( grep -is 'fvwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3960. version=$( get_de_app_version 'fvwm' '^fvwm' '2' )
  3961. desktop_environment='FVWM'
  3962. elif [[ -n $( grep -is 'pekwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3963. version=$( get_de_app_version 'pekwm' '^pekwm' '3' )
  3964. desktop_environment='pekwm'
  3965. elif [[ -n $( grep -is 'awesome' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3966. version=$( get_de_app_version 'awesome' '^awesome' '2' )
  3967. desktop_environment='Awesome'
  3968. elif [[ -n $( grep -is 'scrotwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3969. version=$( get_de_app_version 'scrotwm' '^welcome.*scrotwm' '4' )
  3970. desktop_environment='Scrotwm' # no --version for this one
  3971. elif [[ -n $( grep -is 'spectrwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3972. version=$( get_de_app_version 'spectrwm' '^spectrwm.*welcome.*spectrwm' '5' )
  3973. desktop_environment='Spectrwm' # no --version for this one
  3974. elif [[ -n $( grep -Eis '([[:space:]]|/)twm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3975. desktop_environment='Twm' # no --version for this one
  3976. elif [[ -n $( grep -Eis '([[:space:]]|/)dwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3977. version=$( get_de_app_version 'dwm' '^dwm' '1' )
  3978. desktop_environment='dwm'
  3979. elif [[ -n $( grep -is 'wmii2' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3980. version=$( get_de_app_version 'wmii2' '^wmii2' '1' )
  3981. desktop_environment='wmii2'
  3982. # note: in debian at least, wmii is actuall wmii3
  3983. elif [[ -n $( grep -is 'wmii' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3984. version=$( get_de_app_version 'wmii' '^wmii' '1' )
  3985. desktop_environment='wmii'
  3986. elif [[ -n $( grep -Eis '([[:space:]]|/)jwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then
  3987. version=$( get_de_app_version 'jwm' '^jwm' '2' )
  3988. desktop_environment='JWM'
  3989. fi
  3990. fi
  3991. fi
  3992. if [[ -n $version ]];then
  3993. version=" $version"
  3994. fi
  3995. echo "$desktop_environment${version}"
  3996. eval $LOGFE
  3997. }
  3998.  
  3999. # note: gawk doesn't support white spaces in search string, gave errors, so use [[:space:]] instead
  4000. # args: $1 - desktop/app command for --version; $2 - search string; $3 - gawk print number
  4001. get_de_app_version()
  4002. {
  4003. local version_data='' version='' get_version='--version'
  4004.  
  4005. # mate-about -v = MATE Desktop Environment 1.4.0
  4006. case $1 in
  4007. dwm|jwm|mate-about|wmii|wmii2)
  4008. get_version='-v'
  4009. ;;
  4010. esac
  4011.  
  4012. case $1 in
  4013. # note, some wm/apps send version info to stderr instead of stdout
  4014. dwm|ksh|scrotwm|spectrwm)
  4015. version_data="$( $1 $get_version 2>&1 )"
  4016. ;;
  4017. csh)
  4018. version_data="$( tcsh $get_version 2>/dev/null )"
  4019. ;;
  4020. # quick debian/buntu hack until I find a universal way to get version for these
  4021. dash)
  4022. if [[ -n $( type -p dpkg ) ]];then
  4023. version_data="$( dpkg -l $1 2>/dev/null )"
  4024. fi
  4025. ;;
  4026. *)
  4027. version_data="$( $1 $get_version 2>/dev/null )"
  4028. ;;
  4029. esac
  4030.  
  4031. if [[ -n $version_data ]];then
  4032. version=$( gawk '
  4033. BEGIN {
  4034. IGNORECASE=1
  4035. }
  4036. /'$2'/ {
  4037. # sample: dwm-5.8.2, ©.. etc, why no space? who knows. Also get rid of v in number string
  4038. # xfce, and other, output has , in it, so dump all commas
  4039. gsub(/(,|dwm-|wmii2-|wmii-|v|V)/, "",$'$3')
  4040. print $'$3'
  4041. exit # quit after first match prints
  4042. }' <<< "$version_data" )
  4043. fi
  4044. echo $version
  4045. }
  4046.  
  4047. get_desktop_extra_data()
  4048. {
  4049. eval $LOGFS
  4050. local de_data=$( ps -A | gawk '
  4051. BEGIN {
  4052. IGNORECASE=1
  4053. desktops=""
  4054. separator=""
  4055. }
  4056. /(gnome-shell|gnome-panel|kicker|lxpanel|mate-panel|plasma-desktop|xfce4-panel)$/ {
  4057. # only one entry per type, can be multiple
  4058. if ( desktops !~ $NF ) {
  4059. desktops = desktops separator $NF
  4060. separator = ","
  4061. }
  4062. }
  4063. END {
  4064. print desktops
  4065. }
  4066. ' )
  4067. echo $de_data
  4068.  
  4069. eval $LOGFE
  4070. }
  4071.  
  4072. get_de_gtk_data()
  4073. {
  4074. eval $LOGFS
  4075.  
  4076. local toolkit=''
  4077.  
  4078. # this is a hack, and has to be changed with every toolkit version change
  4079. toolkit=$( pkg-config --modversion gtk+-4.0 2>/dev/null )
  4080. # note: opensuse gets null output here, we need the command to get version and output sample
  4081. if [[ -z $toolkit ]];then
  4082. toolkit=$( pkg-config --modversion gtk+-3.0 2>/dev/null )
  4083. fi
  4084. if [[ -z $toolkit ]];then
  4085. toolkit=$( pkg-config --modversion gtk+-2.0 2>/dev/null )
  4086. fi
  4087. echo $toolkit
  4088.  
  4089. eval $LOGFE
  4090. }
  4091.  
  4092. # see which dm has started if any
  4093. get_display_manager()
  4094. {
  4095. eval $LOGFS
  4096. # ldm - LTSP display manager
  4097. local dm_id_list='entranced.pid entrance/entranced.pid gdm.pid gdm3.pid kdm.pid ldm.pid lightdm.pid lxdm.pid mdm.pid nodm.pid slim.lock tint2.pid wdm.pid xdm.pid'
  4098. local dm_id='' dm='' separator=''
  4099. # note we don't need to filter grep if we do it this way
  4100. local x_is_running=$( grep '/usr.*/X' <<< "$Ps_aux_Data" | grep -iv '/Xprt' )
  4101.  
  4102. for dm_id in $dm_id_list
  4103. do
  4104. if [[ -e /var/run/$dm_id || -e /run/$dm_id ]];then
  4105. # just on the off chance that two dms are running, good info to have in that case, if possible
  4106. dm=$dm$separator$( basename $dm_id | cut -d '.' -f 1 )
  4107. separator=','
  4108. fi
  4109. done
  4110. # might add this in, but the rate of new dm's makes it more likely it's an unknown dm, so
  4111. # we'll keep output to N/A
  4112. if [[ -n $x_is_running && -z $dm ]];then
  4113. if [[ -n $( grep 'startx$' <<< "$Ps_aux_Data" ) ]];then
  4114. dm='(startx)'
  4115. fi
  4116. fi
  4117. echo $dm
  4118.  
  4119. log_function_data "display manager: $dm"
  4120.  
  4121. eval $LOGFE
  4122. }
  4123.  
  4124. # for more on distro id, please reference this python thread: http://bugs.python.org/issue1322
  4125. ## return distro name/id if found
  4126. get_distro_data()
  4127. {
  4128. eval $LOGFS
  4129. local i='' j='' distro='' distro_file='' a_distro_glob='' temp_array=''
  4130.  
  4131. # may need modification if archbsd / debian can be id'ed with /etc files
  4132. if [[ -n $BSD_TYPE ]];then
  4133. distro=$( uname -sr )
  4134. echo "$distro"
  4135. log_function_data "distro: $distro"
  4136. eval $LOGFE
  4137. return 0
  4138. fi
  4139.  
  4140. # get the wild carded array of release/version /etc files if present
  4141. shopt -s nullglob
  4142. cd /etc
  4143. # note: always exceptions, so wild card after release/version: /etc/lsb-release-crunchbang
  4144. # wait to handle since crunchbang file is one of the few in the world that uses this method
  4145. a_distro_glob=(*[-_]{release,version})
  4146. cd "$OLDPWD"
  4147. shopt -u nullglob
  4148.  
  4149. temp_array=${a_distro_glob[@]}
  4150. log_function_data "A_GLX_DATA: $temp_array"
  4151.  
  4152. if [[ ${#a_distro_glob[@]} -eq 1 ]];then
  4153. distro_file="${a_distro_glob}"
  4154. # use the file if it's in the known good lists
  4155. elif [[ ${#a_distro_glob[@]} -gt 1 ]];then
  4156. for i in $DISTROS_DERIVED $DISTROS_PRIMARY
  4157. do
  4158. # Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
  4159. # This is a known bug, search for the word "strange" inside comments
  4160. # echo "i='$i' a_distro_glob[@]='${a_distro_glob[@]}'"
  4161. if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then
  4162. # Now lets see if the distro file is in the known-good working-lsb-list
  4163. # if so, use lsb-release, if not, then just use the found file
  4164. # this is for only those distro's with self named release/version files
  4165. # because Mint does not use such, it must be done as below
  4166. ## this if statement requires the spaces and * as it is, else it won't work
  4167. ##
  4168. if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_FILE == 'true' ]];then
  4169. distro_file='lsb-release'
  4170. elif [[ " $DISTROS_OS_RELEASE_GOOD " == *" ${i} "* ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then
  4171. distro_file='os-release'
  4172. else
  4173. distro_file="${i}"
  4174. fi
  4175. break
  4176. fi
  4177. done
  4178. fi
  4179. log_function_data "distro_file: $distro_file"
  4180. # first test for the legacy antiX distro id file
  4181. if [[ -e /etc/antiX ]];then
  4182. distro="$( grep -Eoi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )"
  4183. # this handles case where only one release/version file was found, and it's lsb-release. This would
  4184. # never apply for ubuntu or debian, which will filter down to the following conditions. In general
  4185. # if there's a specific distro release file available, that's to be preferred, but this is a good backup.
  4186. elif [[ -n $distro_file && $B_LSB_FILE == 'true' && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then
  4187. distro=$( get_distro_lsb_os_release_data 'lsb-file' )
  4188. elif [[ $distro_file == 'lsb-release' ]];then
  4189. distro=$( get_distro_lsb_os_release_data 'lsb-file' )
  4190. elif [[ $distro_file == 'os-release' ]];then
  4191. distro=$( get_distro_lsb_os_release_data 'os-release-file' )
  4192. # then if the distro id file was found and it's not in the exluded primary distro file list, read it
  4193. elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
  4194. # new opensuse uses os-release, but older ones may have a similar syntax, so just use the first line
  4195. if [[ $distro_file == 'SuSE-release' ]];then
  4196. # leaving off extra data since all new suse have it, in os-release, this file has line breaks, like os-release
  4197. # but in case we want it, it's: CODENAME = Mantis | VERSION = 12.2
  4198. # for now, just take first occurance, which should be the first line, which does not use a variable type format
  4199. distro=$( grep -i -m 1 'suse' /etc/$distro_file )
  4200. else
  4201. distro=$( remove_erroneous_chars "/etc/$distro_file" )
  4202. fi
  4203. # otherwise try the default debian/ubuntu /etc/issue file
  4204. elif [[ -f /etc/issue ]];then
  4205. # lsb gives more manageable and accurate output than issue, but mint should use issue for now
  4206. # some bashism, boolean must be in parenthesis to work correctly, ie [[ $(boolean) ]] not [[ $boolean ]]
  4207. if [[ $B_LSB_FILE == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then
  4208. distro=$( get_distro_lsb_os_release_data 'lsb-file' )
  4209. else
  4210. distro=$( gawk '
  4211. BEGIN {
  4212. RS=""
  4213. }
  4214. {
  4215. gsub(/\\[a-z]/, "")
  4216. gsub(/,/, " ")
  4217. gsub(/^ +| +$/, "")
  4218. gsub(/ [ \t]+/, " ")
  4219. print
  4220. }' /etc/issue )
  4221.  
  4222. # this handles an arch bug where /etc/arch-release is empty and /etc/issue is corrupted
  4223. # only older arch installs that have not been updated should have this fallback required, new ones use
  4224. # os-release
  4225. if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
  4226. distro='Arch Linux'
  4227. fi
  4228. fi
  4229. fi
  4230.  
  4231. if [[ ${#distro} -gt 80 ]] && [[ $B_HANDLE_CORRUPT_DATA != 'true' ]];then
  4232. distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}"
  4233. fi
  4234. ## note: would like to actually understand the method even if it's not used
  4235. # : ${distro:=Unknown distro o_O}
  4236. ## test for /etc/lsb-release as a backup in case of failure, in cases where > one version/release file
  4237. ## were found but the above resulted in null distro value
  4238. if [[ -z $distro ]] && [[ $B_LSB_FILE == 'true' ]];then
  4239. distro=$( get_distro_lsb_os_release_data 'lsb-file' )
  4240. fi
  4241. if [[ -z $distro ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then
  4242. distro=$( get_distro_lsb_os_release_data 'os-release-file' )
  4243. fi
  4244. # now some final null tries
  4245. if [[ -z $distro ]];then
  4246. # if the file was null but present, which can happen in some cases, then use the file name itself to
  4247. # set the distro value. Why say unknown if we have a pretty good idea, after all?
  4248. if [[ -n $distro_file ]] && [[ " $DISTROS_DERIVED $DISTROS_PRIMARY " == *" $distro_file "* ]];then
  4249. distro=$( sed $SED_RX -e 's/[-_]//' -e 's/(release|version)//' <<< $distro_file | sed $SED_RX 's/^([a-z])/\u\1/' )
  4250. fi
  4251. ## finally, if all else has failed, give up
  4252. if [[ -z $distro ]];then
  4253. distro='unknown'
  4254. fi
  4255. fi
  4256. # final step cleanup of unwanted information
  4257. # opensuse has the x86 etc type string in names, not needed as redundant since -S already shows that
  4258. distro=$( gawk '
  4259. BEGIN {
  4260. IGNORECASE=1
  4261. }
  4262. {
  4263. sub(/ *\(*(x86_64|i486|i586|i686|686|586|486)\)*/, "", $0)
  4264. print $0
  4265. }' <<< $distro )
  4266. echo "$distro"
  4267. log_function_data "distro: $distro"
  4268. eval $LOGFE
  4269. }
  4270.  
  4271. # args: $1 - lsb-file/lsb-app/os-release-file
  4272. get_distro_lsb_os_release_data()
  4273. {
  4274. eval $LOGFS
  4275. local distro=''
  4276.  
  4277. case $1 in
  4278. lsb-file)
  4279. if [[ $B_LSB_FILE == 'true' ]];then
  4280. distro=$( gawk -F '=' '
  4281. BEGIN {
  4282. IGNORECASE=1
  4283. }
  4284. # clean out unwanted characters
  4285. {
  4286. gsub(/\\|\"|[:\47]/,"", $0 )
  4287. gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2 )
  4288. gsub(/^[[:space:]]+|[[:space:]]+$/, "", $1 )
  4289. }
  4290. # note: adding the spacing directly to variable to make sure distro output is null if not found
  4291. /^DISTRIB_ID/ {
  4292. # this is needed because grep for "arch" is too loose to be safe
  4293. if ( $2 == "arch" ) {
  4294. distroId = "Arch Linux"
  4295. }
  4296. else if ( $2 != "n/a" ) {
  4297. distroId = $2 " "
  4298. }
  4299. }
  4300. /^DISTRIB_RELEASE/ {
  4301. if ( $2 != "n/a" ) {
  4302. distroRelease = $2 " "
  4303. }
  4304. }
  4305. /^DISTRIB_CODENAME/ {
  4306. if ( $2 != "n/a" ) {
  4307. distroCodename = $2 " "
  4308. }
  4309. }
  4310. # sometimes some distros cannot do their lsb-release files correctly, so here is
  4311. # one last chance to get it right.
  4312. /^DISTRIB_DESCRIPTION/ {
  4313. if ( $2 != "n/a" ) {
  4314. distroDescription = $2
  4315. }
  4316. }
  4317. END {
  4318. fullString=""
  4319. if ( distroId == "" && distroRelease == "" && distroCodename == "" && distroDescription != "" ){
  4320. fullString = distroDescription
  4321. }
  4322. else {
  4323. fullString = distroId distroRelease distroCodename
  4324. }
  4325. print fullString
  4326. }
  4327. ' $FILE_LSB_RELEASE )
  4328. log_function_data 'cat' "$FILE_LSB_RELEASE"
  4329. fi
  4330. ;;
  4331. lsb-app)
  4332. # this is HORRIBLY slow, not using
  4333. if [[ -n $( type -p lsb_release ) ]];then
  4334. distro=$( echo "$( lsb_release -irc )" | gawk -F ':' '
  4335. BEGIN {
  4336. IGNORECASE=1
  4337. }
  4338. # clean out unwanted characters
  4339. {
  4340. gsub(/\\|\"|[:\47]/,"", $0 )
  4341. gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2 )
  4342. gsub(/^[[:space:]]+|[[:space:]]+$/, "", $1 )
  4343. }
  4344. /^Distributor ID/ {
  4345. distroId = $2
  4346. }
  4347. /^Release/ {
  4348. distroRelease = $2
  4349. }
  4350. /^Codename/ {
  4351. distroCodename = $2
  4352. }
  4353. END {
  4354. print distroId " " distroRelease " (" distroCodename ")"
  4355. }' )
  4356. fi
  4357. ;;
  4358. os-release-file)
  4359. if [[ $B_OS_RELEASE_FILE == 'true' ]];then
  4360. distro=$( gawk -F '=' '
  4361. BEGIN {
  4362. IGNORECASE=1
  4363. prettyName=""
  4364. regularName=""
  4365. versionName=""
  4366. versionId=""
  4367. distroName=""
  4368. }
  4369. # clean out unwanted characters
  4370. {
  4371. gsub(/\\|\"|[:\47]/,"", $0 )
  4372. gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2 )
  4373. gsub(/^[[:space:]]+|[[:space:]]+$/, "", $1 )
  4374. }
  4375. # note: adding the spacing directly to variable to make sure distro output is null if not found
  4376. /^PRETTY_NAME/ {
  4377. if ( $2 != "n/a" ) {
  4378. prettyName = $2
  4379. }
  4380. }
  4381. /^NAME/ {
  4382. if ( $2 != "n/a" ) {
  4383. regularName = $2
  4384. }
  4385. }
  4386. /^VERSION/ {
  4387. if ( $2 != "n/a" && $1 == "VERSION" ) {
  4388. versionName = $2
  4389. }
  4390. else if ( $2 != "n/a" && $1 == "VERSION_ID" ) {
  4391. versionId = $2
  4392. }
  4393. }
  4394. END {
  4395. if ( prettyName != "" ) {
  4396. distroName = prettyName
  4397. }
  4398. else if ( regularName != "" ) {
  4399. distroName = regularName
  4400. if ( versionName != "" ) {
  4401. distroName = distroName " " versionName
  4402. }
  4403. else if ( versionId != "" ) {
  4404. distroName = distroName " " versionId
  4405. }
  4406.  
  4407. }
  4408. print distroName
  4409. }
  4410. ' $FILE_OS_RELEASE )
  4411. log_function_data 'cat' "$FILE_OS_RELEASE"
  4412. fi
  4413. ;;
  4414. esac
  4415. echo $distro
  4416. log_function_data "distro: $distro"
  4417. eval $LOGFE
  4418. }
  4419.  
  4420. get_dmidecode_data()
  4421. {
  4422. eval $LOGFS
  4423.  
  4424. local dmidecodePath=''
  4425.  
  4426. if [[ $B_DMIDECODE_SET != 'true' ]];then
  4427. dmidecodePath=$( type -p dmidecode 2>/dev/null )
  4428. if [[ -n $dmidecodePath ]];then
  4429. # note stripping out these lines: Handle 0x0016, DMI type 17, 27 bytes
  4430. # but NOT deleting them, in case the dmidecode data is missing empty lines which will be
  4431. # used to separate results. Then we remove the doubled empty lines to keep it clean and
  4432. # strip out all the stuff we don't want to see in the results.
  4433. DMIDECODE_DATA="$( $dmidecodePath 2>/dev/null \
  4434. | gawk -F ':' '
  4435. BEGIN {
  4436. IGNORECASE=1
  4437. cutExtraTab="false"
  4438. twoData=""
  4439. oneData=""
  4440. }
  4441. {
  4442. # no idea why, but freebsd gawk does not do this right
  4443. oneData=$1
  4444. twoData=$2
  4445. if ( twoData != "" ) {
  4446. twoHolder="true"
  4447. }
  4448. else {
  4449. twoHolder="false"
  4450. }
  4451. if ( $0 ~ /^\tDMI type/ ) {
  4452. sub(/^\tDMI type.*/, "", $0)
  4453. cutExtraTab="true"
  4454. }
  4455. gsub(/'"$BAN_LIST_NORMAL"'/, "", twoData)
  4456. gsub(/,/, " ", $0)
  4457. # clean out Handle line
  4458. sub(/^Handle.*/,"", $0)
  4459. sub(/^[[:space:]]*Inactive.*/,"",$0)
  4460. # yes, there is a typo in a user data set, unknow
  4461. # Base Board Version|Base Board Serial Number
  4462. # Chassis Manufacturer|Chassis Version|Chassis Serial Number
  4463. # System manufacturer|System Product Name|System Version
  4464. # To Be Filled By O.E.M.
  4465. # strip out starting white space so that the following stuff will clear properly
  4466. sub(/^[[:space:]]+/, "", twoData)
  4467. sub(/^Base Board .*|^Chassis .*|.*O\.E\.M\..*|.*OEM.*|^Not .*|^System .*|.*unknow.*|.*N\/A.*|none|^To be filled.*/, "", twoData)
  4468. gsub(/bios|acpi/, "", twoData)
  4469. sub(/http:\/\/www.abit.com.tw\//, "Abit", twoData)
  4470.  
  4471. # for double indented values replace with ~ so later can test for it, we are trusting that
  4472. # indentation will be tabbed in this case
  4473. # special case, dmidecode 2.2 has an extra tab and a DMI type line
  4474. if ( cutExtraTab == "true" ) {
  4475. sub(/^\t\t\t+/, "~", oneData)
  4476. }
  4477. else {
  4478. sub(/^\t\t+/, "~", oneData)
  4479. }
  4480.  
  4481. gsub(/^[[:space:]]+|[[:space:]]+$/, "", twoData)
  4482. gsub(/^[[:space:]]+|[[:space:]]+$/, "", oneData)
  4483. gsub(/ [ \t]+/, " ", twoData)
  4484. # reconstructing the line for processing so gawk can use -F : again
  4485. if ( oneData != "" && twoHolder == "true" ) {
  4486. print oneData ":" twoData
  4487. }
  4488. else {
  4489. print $0
  4490. }
  4491. }' \
  4492. | sed '/^$/{
  4493. N
  4494. /^\n$/D
  4495. }' \
  4496. )"
  4497. fi
  4498. B_DMIDECODE_SET='true'
  4499. log_function_data "DMIDECODE_DATA: $DMIDECODE_DATA"
  4500. fi
  4501.  
  4502. eval $LOGFE
  4503. }
  4504. # get_dmidecode_data;echo "$DMIDECODE_DATA";exit
  4505.  
  4506. # BSD only
  4507. get_dmesg_boot_data()
  4508. {
  4509. eval $LOGFS
  4510.  
  4511. local dmsg_boot_data=''
  4512.  
  4513. if [[ $B_DMESG_BOOT_FILE == 'true' ]];then
  4514. # replace all indented items with ~ so we can id them easily while processing
  4515. dmsg_boot_data="$( cat $FILE_DMESG_BOOT | sed $SED_RX 's/"//g' )"
  4516. fi
  4517. echo "$dmsg_boot_data"
  4518. # log_function_data "$dmsg_boot_data"
  4519. eval $LOGFE
  4520. }
  4521.  
  4522. get_gcc_kernel_version()
  4523. {
  4524. # note that we use gawk to get the last part because beta, alpha, git versions can be non-numeric
  4525. local gccVersion=''
  4526.  
  4527. if [[ -e /proc/version ]];then
  4528. gccVersion=$( grep -Eio 'gcc[[:space:]]*version[[:space:]]*([^ \t]*)' /proc/version 2>/dev/null | gawk '{print $3}' )
  4529. fi
  4530. echo $gccVersion
  4531. }
  4532.  
  4533. get_gcc_system_version()
  4534. {
  4535. eval $LOGFS
  4536. local separator='' gcc_installed='' gcc_list='' gcc_others='' temp_array=''
  4537. local gcc_version=$(
  4538. gcc --version 2>/dev/null | sed $SED_RX 's/\([^\)]*\)//g' | gawk '
  4539. BEGIN {
  4540. IGNORECASE=1
  4541. }
  4542. /^gcc/ {
  4543. print $2
  4544. exit
  4545. }' )
  4546.  
  4547. # can't use xargs -L basename because not all systems support thats
  4548. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  4549. gcc_others=$( ls /usr/bin/gcc-* 2>/dev/null )
  4550. if [[ -n $gcc_others ]];then
  4551. for item in $gcc_others
  4552. do
  4553. gcc_installed=$( basename $item | gawk -F '-' '
  4554. $2 ~ /^[0-9\.]+$/ {
  4555. print $2
  4556. }' )
  4557. if [[ -n $gcc_installed && -z $( grep "^$gcc_installed" <<< $gcc_version ) ]];then
  4558. gcc_list=$gcc_list$separator$gcc_installed
  4559. separator=','
  4560. fi
  4561. done
  4562. fi
  4563. fi
  4564. if [[ -n $gcc_version ]];then
  4565. A_GCC_VERSIONS=( "$gcc_version" $gcc_list )
  4566. fi
  4567. temp_array=${A_GCC_VERSIONS[@]}
  4568. log_function_data "A_GCC_VERSIONS: $temp_array"
  4569. eval $LOGFE
  4570. }
  4571. get_gpu_temp_data()
  4572. {
  4573. local gpu_temp='' gpu_fan='' screens='' screen_nu='' gpu_temp_looper=''
  4574.  
  4575. # we'll try for nvidia/ati, then add if more are shown
  4576. if [[ -n $( type -p nvidia-settings ) ]];then
  4577. # first get the number of screens
  4578. screens=$( nvidia-settings -q screens | gawk '
  4579. /:[0-9]\.[0-9]/ {
  4580. screens=screens gensub(/(.*)(:[0-9]\.[0-9])(.*)/, "\\2", "1", $0) " "
  4581. }
  4582. END {
  4583. print screens
  4584. }
  4585. ' )
  4586. # now we'll get the gpu temp for each screen discovered. The print out function
  4587. # will handle removing screen data for single gpu systems
  4588. for screen_nu in $screens
  4589. do
  4590. gpu_temp_looper=$( nvidia-settings -c $screen_nu -q GPUCoreTemp | gawk -F ': ' '
  4591. BEGIN {
  4592. IGNORECASE=1
  4593. gpuTemp=""
  4594. gpuTempWorking=""
  4595. }
  4596. /Attribute (.*)[0-9]+\.$/ {
  4597. gsub(/\./, "", $2)
  4598. if ( $2 ~ /^[0-9]+$/ ) {
  4599. gpuTemp=gpuTemp $2 "C "
  4600. }
  4601. }
  4602. END {
  4603. print gpuTemp
  4604. }' )
  4605. screen_nu=$( cut -d ':' -f 2 <<< $screen_nu )
  4606. gpu_temp="$gpu_temp$screen_nu:$gpu_temp_looper "
  4607. done
  4608. elif [[ -n $( type -p aticonfig ) ]];then
  4609. # gpu_temp=$( aticonfig --adapter=0 --od-gettemperature | gawk -F ': ' '
  4610. gpu_temp=$( aticonfig --adapter=all --od-gettemperature | gawk -F ': ' '
  4611. BEGIN {
  4612. IGNORECASE=1
  4613. gpuTemp=""
  4614. gpuTempWorking=""
  4615. }
  4616. /Sensor (.*)[0-9\.]+ / {
  4617. gpuTempWorking=gensub(/(.*) ([0-9\.]+) (.*)/, "\\2", "1", $2)
  4618. if ( gpuTempWorking ~ /^[0-9\.]+$/ ) {
  4619. gpuTemp=gpuTemp gpuTempWorking "C "
  4620. }
  4621. }
  4622. END {
  4623. print gpuTemp
  4624. }' )
  4625. # this handles some newer cases of free driver temp readouts, will require modifications as
  4626. # more user data appears.
  4627. elif [[ -n $Sensors_Data ]];then
  4628. gpu_temp=$(
  4629. gawk '
  4630. BEGIN {
  4631. IGNORECASE=1
  4632. gpuTemp=""
  4633. separator=""
  4634. }
  4635. /^('"$SENSORS_GPU_SEARCH"')-pci/ {
  4636. while ( getline && !/^$/ ) {
  4637. if ( /^temp/ ) {
  4638. sub(/^[[:alnum:]]*.*:/, "", $0 ) # clear out everything to the :
  4639. gsub(/[\+ \t°]/, "", $1) # ° is a special case, like a space for gawk
  4640. gpuTemp=gpuTemp separator $1
  4641. separator=","
  4642. }
  4643. }
  4644. }
  4645. END {
  4646. print gpuTemp
  4647. }' <<< "$Sensors_Data" )
  4648. fi
  4649.  
  4650. if [[ -n $gpu_temp ]];then
  4651. echo $gpu_temp
  4652. fi
  4653. }
  4654.  
  4655. ## for possible future data, not currently used
  4656. get_graphics_agp_data()
  4657. {
  4658. eval $LOGFS
  4659. local agp_module=''
  4660.  
  4661. if [[ $B_MODULES_FILE == 'true' ]];then
  4662. ## not used currently
  4663. agp_module=$( gawk '
  4664. /agp/ && !/agpgart/ && $3 > 0 {
  4665. print(gensub(/(.*)_agp.*/,"\\1","g",$1))
  4666. }' $FILE_MODULES )
  4667. log_function_data 'cat' "$FILE_MODULES"
  4668. fi
  4669. log_function_data "agp_module: $agp_module"
  4670. eval $LOGFE
  4671. }
  4672.  
  4673. ## create array of gfx cards installed on system
  4674. get_graphics_card_data()
  4675. {
  4676. eval $LOGFS
  4677. local i='' temp_array=''
  4678.  
  4679. IFS=$'\n'
  4680. A_GFX_CARD_DATA=( $( gawk -F': ' '
  4681. BEGIN {
  4682. IGNORECASE=1
  4683. busId=""
  4684. }
  4685. /vga compatible controller/ {
  4686. gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
  4687. gsub(/,/, " ", $NF)
  4688. gsub(/^ +| +$/, "", $NF)
  4689. gsub(/ [ \t]+/, " ", $NF)
  4690. busId=gensub(/^([0-9a-f:\.]+) (.+)$/,"\\1","",$1)
  4691. print $NF "," busId
  4692. }' <<< "$Lspci_v_Data" ) )
  4693. IFS="$ORIGINAL_IFS"
  4694. # for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
  4695. # do
  4696. # A_GFX_CARD_DATA[i]=$( sanitize_characters BAN_LIST_NORMAL "${A_GFX_CARD_DATA[i]}" )
  4697. # done
  4698.  
  4699. # GFXMEM is UNUSED at the moment, because it shows AGP aperture size, which is not necessarily equal to GFX memory..
  4700. # GFXMEM="size=[$(echo "$Lspci_v_Data" | gawk '/VGA/{while (!/^$/) {getline;if (/size=[0-9][0-9]*M/) {size2=gensub(/.*\[size=([0-9]+)M\].*/,"\\1","g",$0);if (size<size2){size=size2}}}}END{print size2}')M]"
  4701. temp_array=${A_GFX_CARD_DATA[@]}
  4702. log_function_data "A_GFX_CARD_DATA: $temp_array"
  4703. eval $LOGFE
  4704. }
  4705.  
  4706. get_graphics_driver()
  4707. {
  4708. eval $LOGFS
  4709.  
  4710. # list is from sgfxi plus non-free drivers
  4711. local driver_list='apm|ark|ati|chips|cirrus|cyrix|fbdev|fglrx|glint|i128|i740|intel|i810|imstt|mach64|mga|neomagic|nsc|nvidia|nv|openchrome|nouveau|radeon|radeonhd|rendition|s3virge|s3|savage|siliconmotion|sisusb|sis|tdfx|tga|trident|tseng|unichrome|vboxvideo|vesa|vga|via|voodoo|vmware|v4l'
  4712. local driver='' driver_string='' xorg_log_data='' status='' temp_array=''
  4713.  
  4714. if [[ $B_XORG_LOG == 'true' ]];then
  4715. A_GRAPHIC_DRIVERS=( $(
  4716. gawk '
  4717. BEGIN {
  4718. driver=""
  4719. bLoaded="false"
  4720. IGNORECASE=1
  4721. }
  4722. # note that in file names, driver is always lower case
  4723. /[[:space:]]Loading.*('"$driver_list"')_drv.so$/ {
  4724. driver=gensub(/.*[[:space:]]Loading.*('"$driver_list"')_drv.so/, "\\1", 1, $0 )
  4725. # we get all the actually loaded drivers first, we will use this to compare the
  4726. # failed/unloaded, which have not always actually been truly loaded
  4727. aDrivers[driver]="loaded"
  4728. }
  4729. /Unloading[[:space:]].*('"$driver_list"')(|_drv.so)$/ {
  4730. driver=gensub(/(.*)Unloading[[:space:]].*('"$driver_list"')(|_drv.so)$/, "\\2", 1, $0 )
  4731. # we need to make sure that the driver has already been truly loaded, not just discussed
  4732. if ( driver in aDrivers ) {
  4733. aDrivers[driver]="unloaded"
  4734. }
  4735. }
  4736. /Failed.*('"$driver_list"')_drv.so|Failed.*\"('"$driver_list"')\"/ {
  4737. driver=gensub(/(.*)Failed.*('"$driver_list"')_drv.so/, "\\2", 1, $0 )
  4738. if ( driver == $0 ) {
  4739. driver=gensub(/(.*)Failed.*\"('"$driver_list"')\".*|fred/, "\\2", 1, $0 )
  4740. }
  4741. # we need to make sure that the driver has already been truly loaded, not just discussed
  4742. if ( driver != $0 && driver in aDrivers ) {
  4743. aDrivers[driver]="failed"
  4744. }
  4745. }
  4746. # verify that the driver actually started the desktop, even with false failed messages which can occur
  4747. # this is the driver that is actually driving the display
  4748. /.*\([0-9]+\):[[:space:]]Depth.*framebuffer/ {
  4749. driver=gensub(/.*('"$driver_list"')\([0-9]+\):[[:space:]]Depth.*framebuffer.*/, "\\1", 1, $0 )
  4750. # we need to make sure that the driver has already been truly loaded, not just discussed, also
  4751. # set driver to lower case because sometimes it will show as RADEON or NVIDIA in the actual x start
  4752. driver=tolower(driver)
  4753. if ( driver != $0 && driver in aDrivers ) {
  4754. aDrivers[driver]="loaded"
  4755. }
  4756. }
  4757. END {
  4758. for ( driver in aDrivers ) {
  4759. print driver "," aDrivers[driver]
  4760. }
  4761. }' < $FILE_XORG_LOG ) )
  4762. fi
  4763. temp_array=${A_GRAPHIC_DRIVERS[@]}
  4764. log_function_data "A_GRAPHIC_DRIVERS: $temp_array"
  4765.  
  4766. eval $LOGFE
  4767. }
  4768.  
  4769. ## create array of glx data
  4770. get_graphics_glx_data()
  4771. {
  4772. eval $LOGFS
  4773. local temp_array=''
  4774. if [[ $B_SHOW_X_DATA == 'true' && $B_ROOT != 'true' ]];then
  4775. IFS=$'\n'
  4776. A_GLX_DATA=( $( glxinfo | gawk -F ': ' '
  4777. # note: function declarations go before BEGIN? It appears so, confirm.
  4778. # the real question here though is why this function is even here, seems
  4779. # just to be a complicated way to pack/print a variable, but maybe the
  4780. # original idea was to handle > 1 cases of detections I guess
  4781. function join( arr, sep ) {
  4782. s=""
  4783. i=flag=0
  4784. for ( i in arr ) {
  4785. if ( flag++ ) {
  4786. s = s sep
  4787. }
  4788. s = s i
  4789. }
  4790. return s
  4791. }
  4792.  
  4793. BEGIN {
  4794. IGNORECASE=1
  4795. }
  4796. /opengl renderer/ {
  4797. gsub(/'"$BAN_LIST_NORMAL"'/, "", $2)
  4798. gsub(/ [ \t]+/, " ", $2) # get rid of the created white spaces
  4799. gsub(/^ +| +$/, "", $2)
  4800. if ( $2 ~ /mesa/ ) {
  4801. # Allow all mesas
  4802. # if ( $2 ~ / r[3-9][0-9][0-9] / ) {
  4803. a[$2]
  4804. # this counter failed in one case, a bug, and is not needed now
  4805. # f++
  4806. # }
  4807. next
  4808. }
  4809.  
  4810. $2 && a[$2]
  4811. }
  4812. # dropping all conditions from this test to just show full mesa information
  4813. # there is a user case where not f and mesa apply, atom mobo
  4814. # /opengl version/ && ( f || $2 !~ /mesa/ ) {
  4815. /opengl version/ {
  4816. # fglrx started appearing with this extra string, does not appear to communicate anything of value
  4817. sub(/Compatibility Profile Context/, "- CPC", $2 )
  4818. gsub(/ [ \t]+/, " ", $2) # get rid of the created white spaces
  4819. gsub(/^ +| +$/, "", $2)
  4820. $2 && b[$2]
  4821. }
  4822. /direct rendering/ {
  4823. $2 && c[$2]
  4824. }
  4825. END {
  4826. printf( "%s\n%s\n%s\n", join( a, ", " ), join( b, ", " ), join( c, ", " ) )
  4827. }' ) )
  4828. IFS="$ORIGINAL_IFS"
  4829.  
  4830. # GLXR=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl renderer/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
  4831. # GLXV=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl version/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
  4832. fi
  4833. temp_array=${A_GLX_DATA[@]}
  4834. log_function_data "A_GLX_DATA: $temp_array"
  4835. eval $LOGFE
  4836. }
  4837.  
  4838. ## return screen resolution / tty resolution
  4839. get_graphics_res_data()
  4840. {
  4841. eval $LOGFS
  4842. local screen_resolution='' xdpy_data='' screens_count=0 tty_session=''
  4843.  
  4844. if [[ $B_SHOW_X_DATA == 'true' && $B_ROOT != 'true' ]];then
  4845. # Added the two ?'s , because the resolution is now reported without spaces around the 'x', as in
  4846. # 1400x1050 instead of 1400 x 1050. Change as of X.org version 1.3.0
  4847. xdpy_data="$( xdpyinfo )"
  4848. xdpy_count=$( grep -c 'dimensions' <<< "$xdpy_data" )
  4849. # we get a bit more info from xrandr than xdpyinfo, but xrandr fails to handle
  4850. # multiple screens from different video cards
  4851. if [[ $xdpy_count -eq 1 ]];then
  4852. screen_resolution=$( xrandr | gawk '
  4853. /\*/ {
  4854. res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0)
  4855. }
  4856. END {
  4857. for (n in res) {
  4858. if (res[n] ~ /^[[:digit:]]+x[[:digit:]]+/) {
  4859. line = line ? line ", " res[n] : res[n]
  4860. }
  4861. }
  4862. if (line) {
  4863. print(line)
  4864. }
  4865. }' )
  4866. fi
  4867. if [[ -z $screen_resolution || $xdpy_count -gt 1 ]];then
  4868. screen_resolution=$( gawk '
  4869. BEGIN {
  4870. IGNORECASE=1
  4871. screens = ""
  4872. separator = ""
  4873. }
  4874. /dimensions/ {
  4875. screens = screens separator # first time, this is null, next, has comma last
  4876. screens = screens $2 # then tack on the new value for nice comma list
  4877. separator = ", "
  4878. }
  4879. END {
  4880. print screens
  4881. }' <<< "$xdpy_data" )
  4882. fi
  4883. else
  4884. if [[ $B_PROC_DIR == 'true' && -z $BSD_TYPE ]];then
  4885. screen_resolution=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{
  4886. print $2"x"$1
  4887. }' )
  4888. # note: this works fine for all systems but keeping the above for now since
  4889. # the above is probably more accurate for linux systems.
  4890. else
  4891. if [[ $B_CONSOLE_IRC != 'true' ]];then
  4892. screen_resolution=$( stty -a | gawk -F ';' '
  4893. /^speed/ {
  4894. gsub(/[[:space:]]*(rows|columns)[[:space:]]*/,"",$0)
  4895. gsub(/[[:space:]]*/,"",$2)
  4896. gsub(/[[:space:]]*/,"",$3)
  4897. print $3"x"$2
  4898. }' )
  4899. else
  4900. if [[ -n $BSD_TYPE ]];then
  4901. tty_session=$( get_tty_console_irc )
  4902. # getting information for tty that owns the irc client
  4903. screen_resolution="$( stty -f /dev/pts/$tty_session size | gawk '{print $2"x"$1}' )"
  4904. fi
  4905. fi
  4906. fi
  4907. fi
  4908. echo "$screen_resolution"
  4909. log_function_data "screen_resolution: $screen_resolution"
  4910. eval $LOGFE
  4911. }
  4912.  
  4913. ## create array of x vendor/version data
  4914. get_graphics_x_data()
  4915. {
  4916. eval $LOGFS
  4917. local x_vendor='' x_version='' temp_array='' xdpy_info='' a_x_working=''
  4918.  
  4919. if [[ $B_SHOW_X_DATA == 'true' && $B_ROOT != 'true' ]];then
  4920. # X vendor and version detection.
  4921. # new method added since radeon and X.org and the disappearance of <X server name> version : ...etc
  4922. # Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2
  4923. # A failover mechanism is in place. (if $x_version is empty, the release number is parsed instead)
  4924. # xdpy_info="$( xdpyinfo )"
  4925. IFS=","
  4926. a_x_working=( $( xdpyinfo | gawk -F': +' '
  4927. BEGIN {
  4928. IGNORECASE=1
  4929. vendorString=""
  4930. version=""
  4931. vendorRelease=""
  4932. }
  4933. /vendor string/ {
  4934. gsub(/the|inc|foundation|project|corporation/, "", $2)
  4935. gsub(/,/, " ", $2)
  4936. gsub(/^ +| +$/, "", $2)
  4937. gsub(/ [ \t]+/, " ", $2)
  4938. vendorString = $2
  4939. }
  4940. /version:/ {
  4941. version = $NF
  4942. }
  4943. /vendor release number/ {
  4944. gsub(/0+$/, "", $2)
  4945. gsub(/0+/, ".", $2)
  4946. vendorRelease = $2
  4947. }
  4948. END {
  4949. print vendorString "," version "," vendorRelease
  4950. }' ) )
  4951. x_vendor=${a_x_working[0]}
  4952. x_version=${a_x_working[1]}
  4953.  
  4954. # this gives better output than the failure last case, which would only show:
  4955. # for example: X.org: 1.9 instead of: X.org: 1.9.0
  4956. if [[ -z $x_version ]];then
  4957. x_version=$( get_graphics_x_version )
  4958. fi
  4959. if [[ -z $x_version ]];then
  4960. x_version=${a_x_working[2]}
  4961. fi
  4962.  
  4963. # some distros, like fedora, report themselves as the xorg vendor, so quick check
  4964. # here to make sure the vendor string includes Xorg in string
  4965. if [[ -z $( grep -E '(X|xorg|x\.org)' <<< $x_vendor ) ]];then
  4966. x_vendor="$x_vendor X.org"
  4967. fi
  4968. IFS="$ORIGINAL_IFS"
  4969. A_X_DATA[0]="$x_vendor"
  4970. A_X_DATA[1]="$x_version"
  4971. else
  4972. x_version=$( get_graphics_x_version )
  4973. if [[ -n $x_version ]];then
  4974. x_vendor='X.org'
  4975. A_X_DATA[0]="$x_vendor"
  4976. A_X_DATA[1]="$x_version"
  4977. fi
  4978. fi
  4979. temp_array=${A_X_DATA[@]}
  4980. log_function_data "A_X_DATA: $temp_array"
  4981. eval $LOGFE
  4982. }
  4983.  
  4984. # if other tests fail, try this one, this works for root, out of X also
  4985. get_graphics_x_version()
  4986. {
  4987. eval $LOGFS
  4988. local x_version='' x_data=''
  4989. # note that some users can have /usr/bin/Xorg but not /usr/bin/X
  4990. if [[ -n $( type -p X ) ]];then
  4991. # note: MUST be this syntax: X -version 2>&1
  4992. # otherwise X -version overrides everything and this comes out null.
  4993. # two knowns id strings: X.Org X Server 1.7.5 AND X Window System Version 1.7.5
  4994. #X -version 2>&1 | gawk '/^X Window System Version/ { print $5 }'
  4995. x_data="$( X -version 2>&1 )"
  4996. elif [[ -n $( type -p Xorg ) ]];then
  4997. x_data="$( Xorg -version 2>&1)"
  4998. fi
  4999. if [[ -n $x_data ]];then
  5000. x_version=$(
  5001. gawk '
  5002. BEGIN {
  5003. IGNORECASE=1
  5004. }
  5005. /^x.org x server/ {
  5006. print $4
  5007. exit
  5008. }
  5009. /^X Window System Version/ {
  5010. print $5
  5011. exit
  5012. }' <<< "$x_data" )
  5013. fi
  5014. echo $x_version
  5015. log_function_data " x_version: $x_version"
  5016. eval $LOGFE
  5017. }
  5018.  
  5019. # this gets just the raw data, total space/percent used and disk/name/per disk capacity
  5020. get_hdd_data_basic()
  5021. {
  5022. eval $LOGFS
  5023. local hdd_used='' temp_array='' df_string=''
  5024. local hdd_data='' df_test=''
  5025.  
  5026. if [[ -z $BSD_TYPE ]];then
  5027. df_string='df -P -T --exclude-type=aufs --exclude-type=devfs --exclude-type=devtmpfs
  5028. --exclude-type=fdescfs --exclude-type=iso9660 --exclude-type=linprocfs --exclude-type=procfs
  5029. --exclude-type=squashfs --exclude-type=sysfs --exclude-type=tmpfs --exclude-type=unionfs'
  5030. else
  5031. # default size is 512, so use -k for 1024
  5032. df_string='df -T -k'
  5033. # default size is 512, -H only for size in human readable format
  5034. # older bsds don't support -T, pain, so we'll use partial output there
  5035. df_test=$( df -H -T 2>/dev/null )
  5036. if [[ -n $df_test ]];then
  5037. df_string='df -k -T'
  5038. else
  5039. df_string='df -k'
  5040. fi
  5041. fi
  5042. hdd_data="$( eval $df_string )"
  5043. log_function_data 'raw' "hdd_data:\n$hdd_data"
  5044. hdd_used=$( echo "$hdd_data" | gawk -v bsdType=$BSD_TYPE '
  5045. BEGIN {
  5046. # this is used for specific cases where bind, or incorrect multiple mounts to same partitions,
  5047. # is present. The value is searched for an earlier appearance of that partition and if it is
  5048. # present, the data is not added into the partition used size.
  5049. partitionsSet=""
  5050. # this handles a case where the same dev item is mounted twice to different points
  5051. devSet=""
  5052. devWorking=""
  5053. mountWorking=""
  5054. }
  5055. # using $1, not $2, because older bsd df do not have -T, filesystem type
  5056. ( bsdType != "" ) && $1 ~ /^(aufs|devfs|devtmpfs|fdescfs|filesystem|iso9660|linprocfs|procfs|squashfs|sysfs|tmpfs|type|unionfs)$/ {
  5057. # note use next, not getline or it does not work right
  5058. next
  5059. }
  5060. # also handles odd dm-1 type, from lvm, and mdraid, and some other bsd partition syntax
  5061. # note that linux 3.2.45-grsec-9th types kernels have this type of partition name: /dev/xvdc (no number, letter)
  5062. /^\/dev\/(mapper\/|[hsv]d[a-z][0-9]+|dm[-]?[0-9]+|ada[0-9]+p[0-9]+.*|md[0-9]+|[aw]d[0-9]+s.*|xvd[a-z])/ {
  5063. # this handles the case where the first item is too long
  5064. # and makes df wrap output to next line, so here we advance
  5065. # it to the next line for that single case. Using df -P should
  5066. # make this unneeded but leave it in just in case
  5067. if ( NF < 6 && $0 !~ /.*%/ ) {
  5068. devSet = devSet "~" $1 "~"
  5069. getline
  5070. }
  5071. # if the first item caused a wrap, use one less than standard
  5072. # testing for the field with % in it, ie: 34%, then go down from there
  5073. # this also protects against cases where the mount point has a space in the
  5074. # file name, thus breaking going down from $NF directly.
  5075. # some bsds will also have only 6 items
  5076. if ( $5 ~ /.*%/ ) {
  5077. devWorking="~" $1 "~"
  5078. mountWorking="~" $6 "~"
  5079. if ( partitionsSet !~ mountWorking && devSet !~ devWorking ) {
  5080. used += $3
  5081. }
  5082. partitionsSet = partitionsSet mountWorking
  5083. # make sure to only include bsd real lines here, ie, short df output
  5084. if ( $1 ~ /^\/dev\// ) {
  5085. devSet = devSet devWorking
  5086. }
  5087. }
  5088. # otherwise use standard
  5089. else if ( $6 ~ /.*%/ ) {
  5090. devWorking="~" $1 "~"
  5091. mountWorking="~" $7 "~"
  5092. if ( partitionsSet !~ mountWorking && devSet !~ devWorking ) {
  5093. used += $4
  5094. }
  5095. partitionsSet = partitionsSet mountWorking
  5096. devSet = devSet devWorking
  5097. }
  5098. # and if this is not detected, give up, we need user data to debug
  5099. else {
  5100. next
  5101. }
  5102. }
  5103. END {
  5104. print used
  5105. }' )
  5106.  
  5107. if [[ -z $hdd_used ]];then
  5108. hdd_used='na'
  5109. fi
  5110. log_function_data "hdd_used: $hdd_used"
  5111. # create the initial array strings:
  5112. # disk-dev, capacity, name, usb or not
  5113. # final item is the total of the disk
  5114. IFS=$'\n'
  5115.  
  5116. if [[ $B_PARTITIONS_FILE == 'true' ]];then
  5117. A_HDD_DATA=( $(
  5118. gawk -v hddused="$hdd_used" '
  5119. /[hsv]d[a-z]$/ {
  5120. driveSize = $(NF - 1)*1024/1000**3
  5121. gsub(/,/, " ", driveSize)
  5122. gsub(/^ +| +$/, "", driveSize)
  5123. printf( $NF",%.1fGB,,\n", driveSize )
  5124. }
  5125. # See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
  5126. # $1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {
  5127. # size += $3
  5128. # }
  5129. # special case from this data: 8 0 156290904 sda
  5130. # note: vm has 252/253/254 known starter, grsec has 202
  5131. $1 ~ /^(3|8|22|33|202|252|253|254)$/ && $NF ~ /[hsv]d[a-z]$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) {
  5132. size += $3
  5133. }
  5134.  
  5135. END {
  5136. size = size*1024/1000**3 # calculate size in GB size
  5137. workingUsed = hddused*1024/1000**3 # calculate workingUsed in GB used
  5138. # this handles a special case with livecds where no hdd_used is detected
  5139. if ( size > 0 && hddused == "na" ) {
  5140. size = sprintf( "%.1f", size )
  5141. print size "GB,-"
  5142. }
  5143. else if ( size > 0 && workingUsed > 0 ) {
  5144. diskUsed = workingUsed*100/size # calculate used percentage
  5145. diskUsed = sprintf( "%.1f", diskUsed )
  5146. size = sprintf( "%.1f", size )
  5147. print size "GB," diskUsed "% used"
  5148. }
  5149. else {
  5150. print "NA,-" # print an empty array, this will be further handled in the print out function
  5151. }
  5152. }' $FILE_PARTITIONS ) )
  5153. log_function_data 'cat' "$FILE_PARTITIONS"
  5154. fi
  5155. IFS="$ORIGINAL_IFS"
  5156. temp_array=${A_HDD_DATA[@]}
  5157. log_function_data "A_HDD_DATA: $temp_array"
  5158. eval $LOGFE
  5159. }
  5160.  
  5161. ## fills out the A_HDD_DATA array with disk names
  5162. get_hard_drive_data_advanced()
  5163. {
  5164. eval $LOGFS
  5165. local a_temp_working='' a_temp_scsi='' temp_holder='' temp_name='' i='' j=''
  5166. local sd_ls_by_id='' ls_disk_by_id='' usb_exists='' temp_array=''
  5167.  
  5168. ## check for all ide type drives, non libata, only do it if hdx is in array
  5169. ## this is now being updated for new /sys type paths, this may handle that ok too
  5170. if [[ -n $( grep -E 'hd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
  5171. # remember, we're using the last array item to store the total size of disks
  5172. for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
  5173. do
  5174. IFS=","
  5175. a_temp_working=( ${A_HDD_DATA[i]} )
  5176. IFS="$ORIGINAL_IFS"
  5177. if [[ -n $( grep -E '^hd[a-z]' <<< ${a_temp_working[0]} ) ]];then
  5178. if [[ -e /proc/ide/${a_temp_working[0]}/model ]];then
  5179. a_temp_working[2]="$( remove_erroneous_chars /proc/ide/${a_temp_working[0]}/model )"
  5180. else
  5181. a_temp_working[2]="Name n/a"
  5182. fi
  5183. # these loops are to easily extend the cpu array created in the gawk script above with more fields per cpu.
  5184. for (( j=0; j < ${#a_temp_working[@]}; j++ ))
  5185. do
  5186. if [[ $j -gt 0 ]];then
  5187. A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
  5188. else
  5189. A_HDD_DATA[i]="${a_temp_working[$j]}"
  5190. fi
  5191. done
  5192. fi
  5193. done
  5194. fi
  5195.  
  5196. ## then handle libata names
  5197. # first get the ata device names, put them into an array
  5198. IFS=$'\n'
  5199. if [[ $B_SCSI_FILE == 'true' ]]; then
  5200. a_temp_scsi=( $( gawk '
  5201. BEGIN {
  5202. IGNORECASE=1
  5203. }
  5204. /host/ {
  5205. getline a[$0]
  5206. getline b[$0]
  5207. }
  5208. END {
  5209. for (i in a) {
  5210. if (b[i] ~ / *type: *direct-access.*/) {
  5211. #c=gensub(/^ *vendor: (.+) +model: (.+) +rev: (.+)$/,"\\1 \\2 \\3","g",a[i])
  5212. #c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i] )
  5213. # the vendor: string is useless, and is a bug, ATA is not a vendor for example
  5214. c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/, "\\2", "g", a[i] )
  5215. gsub(/,/, " ", c)
  5216. gsub(/^ +| +$/, "", c)
  5217. gsub(/ [ \t]+/, " ", c)
  5218. #print a[i]
  5219. # we actually want this data, so leaving this off for now
  5220. # if (c ~ /\<flash\>|\<pendrive\>|memory stick|memory card/) {
  5221. # continue
  5222. # }
  5223. print c
  5224. }
  5225. }
  5226. }' $FILE_SCSI ) )
  5227. log_function_data 'cat' "$FILE_SCSI"
  5228. fi
  5229. IFS="$ORIGINAL_IFS"
  5230.  
  5231. ## then we'll loop through that array looking for matches.
  5232. if [[ -n $( grep -E 'sd[a-z]' <<< ${A_HDD_DATA[@]} ) ]];then
  5233. # first pack the main ls variable so we don't have to keep using ls /dev...
  5234. # not all systems have /dev/disk/by-id
  5235. ls_disk_by_id="$( ls -l /dev/disk/by-id 2>/dev/null )"
  5236. for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
  5237. do
  5238. if [[ -n $( grep -E '^sd[a-z]' <<< ${A_HDD_DATA[$i]} ) ]];then
  5239. IFS=","
  5240. a_temp_working=( ${A_HDD_DATA[$i]} )
  5241. IFS="$ORIGINAL_IFS"
  5242. # /sys/block/[sda,hda]/device/model
  5243. # this is handles the new /sys data types first
  5244. if [[ -e /sys/block/${a_temp_working[0]}/device/model ]];then
  5245. temp_name="$( remove_erroneous_chars /sys/block/${a_temp_working[0]}/device/model )"
  5246. temp_name=$( tr ' ' '_' <<< $temp_name | cut -d '-' -f 1 )
  5247. elif [[ ${#a_temp_scsi[@]} -gt 0 ]];then
  5248. for (( j=0; j < ${#a_temp_scsi[@]}; j++ ))
  5249. do
  5250. ## ok, ok, it's incomprehensible, search /dev/disk/by-id for a line that contains the
  5251. # discovered disk name AND ends with the correct identifier, sdx
  5252. # get rid of whitespace for some drive names and ids, and extra data after - in name
  5253. temp_name=$( tr ' ' '_' <<< ${a_temp_scsi[$j]} | cut -d '-' -f 1 )
  5254. sd_ls_by_id=$( grep -Em1 ".*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" )
  5255.  
  5256. if [[ -n $sd_ls_by_id ]];then
  5257. temp_name=${a_temp_scsi[$j]}
  5258. break
  5259. else
  5260. # test to see if we can get a better name output when null
  5261. if [[ -n $temp_name ]];then
  5262. temp_name=$temp_name
  5263. fi
  5264. fi
  5265. done
  5266. fi
  5267.  
  5268. if [[ -z $temp_name ]];then
  5269. temp_name="Name n/a"
  5270. else
  5271. usb_exists=$( grep -Em1 "usb-.*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" )
  5272. if [[ -n $usb_exists ]];then
  5273. a_temp_working[3]='USB'
  5274. fi
  5275. fi
  5276. a_temp_working[2]=$temp_name
  5277. # these loops are to easily extend the cpu array created in the gawk script above with more fields per cpu.
  5278. for (( j=0; j < ${#a_temp_working[@]}; j++ ))
  5279. do
  5280. if [[ $j -gt 0 ]];then
  5281. A_HDD_DATA[i]="${A_HDD_DATA[i]},${a_temp_working[$j]}"
  5282. else
  5283. A_HDD_DATA[i]="${a_temp_working[$j]}"
  5284. fi
  5285. done
  5286. fi
  5287. done
  5288. unset ls_disk_by_id # and then let's dump the data we don't need
  5289. fi
  5290. temp_array=${A_HDD_DATA[@]}
  5291. log_function_data "A_HDD_DATA: $temp_array"
  5292. eval $LOGFE
  5293. }
  5294.  
  5295. # args: $1 - which drive to get serial number of
  5296. get_hdd_serial_number()
  5297. {
  5298. eval $LOGFS
  5299.  
  5300. local hdd_serial=''
  5301.  
  5302. get_partition_dev_data 'id'
  5303.  
  5304. # lrwxrwxrwx 1 root root 9 Apr 26 09:32 scsi-SATA_ST3160827AS_5MT2HMH6 -> ../../sdc
  5305. # exit on the first instance
  5306. hdd_serial=$( gawk '
  5307. /'$1'$/ {
  5308. serial=gensub( /^(.+)_([^_]+)$/, "\\2", 1, $9 )
  5309. print serial
  5310. exit
  5311. }' <<< "$DEV_DISK_ID" )
  5312.  
  5313. echo $hdd_serial
  5314. log_function_data "hdd serial: $hdd_serial"
  5315. eval $LOGFE
  5316. }
  5317.  
  5318. # a few notes, normally hddtemp requires root, but you can set user rights in /etc/sudoers.
  5319. # args: $1 - /dev/<disk> to be tested for
  5320. get_hdd_temp_data()
  5321. {
  5322. eval $LOGFS
  5323. local hdd_temp='' sudo_command=''
  5324.  
  5325. if [[ $B_HDDTEMP_TESTED != 'true' ]];then
  5326. B_HDDTEMP_TESTED='true'
  5327. HDDTEMP_PATH=$( type -p hddtemp )
  5328. fi
  5329. if [[ $B_SUDO_TESTED != 'true' ]];then
  5330. B_SUDO_TESTED='true'
  5331. SUDO_PATH=$( type -p sudo )
  5332. fi
  5333.  
  5334. if [[ -n $HDDTEMP_PATH && -n $1 ]];then
  5335. # only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
  5336. # which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
  5337. # important: -n makes it non interactive, no prompt for password
  5338. if [[ $B_ROOT != 'true' && -n $SUDO_PATH ]];then
  5339. sudo_command='sudo -n '
  5340. fi
  5341. # this will fail if regular user and no sudo present, but that's fine, it will just return null
  5342. hdd_temp=$( eval $sudo_command $HDDTEMP_PATH -nq -u C $1 )
  5343. if [[ -n $hdd_temp && -n $( grep -E '^([0-9\.]+)$' <<< $hdd_temp ) ]];then
  5344. echo $hdd_temp
  5345. fi
  5346. fi
  5347. eval $LOGFE
  5348. }
  5349.  
  5350. get_kernel_version()
  5351. {
  5352. eval $LOGFS
  5353.  
  5354. local kernel_version='' ksplice_kernel_version=''
  5355.  
  5356. kernel_version=$( uname -rm )
  5357.  
  5358. if [[ -n $( type -p uptrack-uname ) && -n $kernel_version ]];then
  5359. ksplice_kernel_version=$( uptrack-uname -rm )
  5360. if [[ $kernel_version != $ksplice_kernel_version ]];then
  5361. kernel_version="$ksplice_kernel_version (ksplice)"
  5362. fi
  5363. fi
  5364. log_function_data "kernel_version: $kernel_version - ksplice_kernel_version: $ksplice_kernel_version"
  5365.  
  5366. echo $kernel_version
  5367.  
  5368. eval $LOGFE
  5369. }
  5370.  
  5371. # args: $1 - v/n
  5372. get_lspci_data()
  5373. {
  5374. eval $LOGFS
  5375. local lspci_data=''
  5376.  
  5377. if [[ $B_LSPCI == 'true' ]];then
  5378. lspci_data="$( lspci -$1 | gawk '{
  5379. gsub(/\(prog-if[^)]*\)/,"")
  5380. sub(/^0000:/, "", $0) # seen case where the 0000: is prepended, rare, but happens
  5381. print
  5382. }' )"
  5383. fi
  5384.  
  5385. echo "$lspci_data"
  5386. log_function_data 'raw' "lspci_data $1:\n$lspci_data"
  5387. eval $LOGFE
  5388. }
  5389.  
  5390. # args: $1 - busid
  5391. get_lspci_vendor_product()
  5392. {
  5393. eval $LOGFS
  5394.  
  5395. local vendor_product=''
  5396.  
  5397. vendor_product=$( gawk '
  5398. /^'$1'/ {
  5399. if ( $3 != "" ) {
  5400. print $3
  5401. }
  5402. }' <<< "$Lspci_n_Data" )
  5403.  
  5404. echo $vendor_product
  5405.  
  5406. eval $LOGFE
  5407. }
  5408.  
  5409. get_machine_data()
  5410. {
  5411. eval $LOGFS
  5412. local temp_array='' separator='' id_file='' file_data='' array_string=''
  5413. local id_dir='/sys/class/dmi/id/' dmi_data=''
  5414. local machine_files="
  5415. sys_vendor product_name product_version product_serial product_uuid
  5416. board_vendor board_name board_version board_serial
  5417. bios_vendor bios_version bios_date
  5418. "
  5419.  
  5420. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  5421. machine_files="$machine_files
  5422. chassis_vendor chassis_type chassis_version chassis_serial
  5423. "
  5424. fi
  5425. if [[ -d $id_dir ]];then
  5426. for id_file in $machine_files
  5427. do
  5428. file_data=''
  5429. if [[ -r $id_dir$id_file ]];then
  5430. file_data=$( gawk '
  5431. BEGIN {
  5432. IGNORECASE=1
  5433. }
  5434. {
  5435. gsub(/'"$BAN_LIST_NORMAL"'/, "", $0)
  5436. gsub(/,/, " ", $0)
  5437. # yes, there is a typo in a user data set, unknow
  5438. # Base Board Version|Base Board Serial Number
  5439. # Chassis Manufacturer|Chassis Version|Chassis Serial Number
  5440. # System manufacturer|System Product Name|System Version
  5441. # To Be Filled By O.E.M.
  5442. sub(/^Base Board .*|^Chassis .*|.*O\.E\.M\..*|.*OEM.*|^Not .*|^System .*|.*unknow.*|.*N\/A.*|none|^To be filled.*/, "", $0)
  5443. gsub(/bios|acpi/, "", $0)
  5444. sub(/http:\/\/www.abit.com.tw\//, "Abit", $0)
  5445. gsub(/^ +| +$/, "", $0)
  5446. gsub(/ [ \t]+/, " ", $0)
  5447. print $0
  5448. }' < $id_dir$id_file )
  5449. fi
  5450. array_string="$array_string$separator$file_data"
  5451. separator=','
  5452. done
  5453. else
  5454. get_dmidecode_data
  5455. if [[ -n $DMIDECODE_DATA ]];then
  5456. if [[ $B_ROOT == 'true' ]];then
  5457. # this handles very old systems, like Lenny 2.6.26, with dmidecode, but no data
  5458. if [[ -n $( grep -i 'no smbios ' <<< "$DMIDECODE_DATA" ) ]];then
  5459. array_string='dmidecode-no-smbios-dmi-data'
  5460. # please note: only dmidecode version 2.11 or newer supports consistently the -s flag
  5461. else
  5462. array_string=$( gawk -F ':' '
  5463. BEGIN {
  5464. IGNORECASE=1
  5465. baseboardManufacturer=""
  5466. baseboardProductName=""
  5467. baseboardSerialNumber=""
  5468. baseboardVersion=""
  5469. biosReleaseDate=""
  5470. biosRevision="" # only available from dmidecode
  5471. biosRomSize="" # only available from dmidecode
  5472. biosVendor=""
  5473. biosVersion=""
  5474. chassisManufacturer=""
  5475. chassisSerialNumber=""
  5476. chassisType=""
  5477. chassisVersion=""
  5478. systemManufacturer=""
  5479. systemProductName=""
  5480. systemVersion=""
  5481. systemSerialNumber=""
  5482. systemUuid=""
  5483. bItemFound="" # we will only output if at least one item was found
  5484. fullString=""
  5485. testString=""
  5486. bSys=""
  5487. bCha=""
  5488. bBio=""
  5489. bBas=""
  5490. }
  5491. /^Bios Information/ {
  5492. while ( getline && !/^$/ ) {
  5493. if ( $1 ~ /^Release Date/ ) { biosReleaseDate=$2 }
  5494. if ( $1 ~ /^BIOS Revision/ ) { biosRevision=$2 }
  5495. if ( $1 ~ /^ROM Size/ ) { biosRomSize=$2 }
  5496. if ( $1 ~ /^Vendor/ ) { biosVendor=$2 }
  5497. if ( $1 ~ /^Version/ ) { biosVersion=$2 }
  5498. }
  5499. testString=biosReleaseDate biosRevision biosRomSize biosVendor biosVersion
  5500. if ( testString != "" ) {
  5501. bItemFound="true"
  5502. }
  5503. bBio="true"
  5504. }
  5505. /^Base Board Information/ {
  5506. while ( getline && !/^$/ ) {
  5507. if ( $1 ~ /^Manufacturer/ ) { baseboardManufacturer=$2 }
  5508. if ( $1 ~ /^Product Name/ ) { baseboardProductName=$2 }
  5509. if ( $1 ~ /^Serial Number/ ) { baseboardSerialNumber=$2 }
  5510. }
  5511. testString=baseboardManufacturer baseboardProductName baseboardSerialNumber
  5512. if ( testString != "" ) {
  5513. bItemFound="true"
  5514. }
  5515. bBas="true"
  5516. }
  5517. /^Chassis Information/ {
  5518. while ( getline && !/^$/ ) {
  5519. if ( $1 ~ /^Manufacturer/ ) { chassisManufacturer=$2 }
  5520. if ( $1 ~ /^Serial Number/ ) { chassisSerialNumber=$2 }
  5521. if ( $1 ~ /^Type/ ) { chassisType=$2 }
  5522. if ( $1 ~ /^Version/ ) { chassisVersion=$2 }
  5523. }
  5524. testString=chassisManufacturer chassisSerialNumber chassisType chassisVersion
  5525. if ( testString != "" ) {
  5526. bItemFound="true"
  5527. }
  5528. bCha="true"
  5529. }
  5530. /^System Information/ {
  5531. while ( getline && !/^$/ ) {
  5532. if ( $1 ~ /^Manufacturer/ ) { systemManufacturer=$2 }
  5533. if ( $1 ~ /^Product Name/ ) { systemProductName=$2 }
  5534. if ( $1 ~ /^Version/ ) { systemVersion=$2 }
  5535. if ( $1 ~ /^Serial Number/ ) { systemSerialNumber=$2 }
  5536. if ( $1 ~ /^UUID/ ) { systemUuid=$2 }
  5537. }
  5538. testString=systemManufacturer systemProductName systemVersion systemSerialNumber systemUuid
  5539. if ( testString != "" ) {
  5540. bItemFound="true"
  5541. }
  5542. bSys="true"
  5543. }
  5544. ( bSys == "true" && bCha="true" && bBio == "true" && bBas == "true" ) {
  5545. exit # stop the loop
  5546. }
  5547. END {
  5548. if ( bItemFound == "true" ) {
  5549. fullString = systemManufacturer "," systemProductName "," systemVersion "," systemSerialNumber
  5550. fullString = fullString "," systemUuid "," baseboardManufacturer "," baseboardProductName
  5551. fullString = fullString "," baseboardVersion "," baseboardSerialNumber "," biosVendor
  5552. fullString = fullString "," biosVersion "," biosReleaseDate "," chassisManufacturer
  5553. fullString = fullString "," chassisType "," chassisVersion "," chassisSerialNumber
  5554. fullString = fullString "," biosRevision "," biosRomSize
  5555.  
  5556. print fullString
  5557. }
  5558. }' <<< "$DMIDECODE_DATA" )
  5559. fi
  5560. else
  5561. array_string='dmidecode-non-root-user'
  5562. fi
  5563. fi
  5564. fi
  5565. IFS=','
  5566. A_MACHINE_DATA=( $array_string )
  5567. IFS="$ORIGINAL_IFS"
  5568. temp_array=${A_MACHINE_DATA[@]}
  5569. # echo ${temp_array[@]}
  5570. log_function_data "A_MACHINE_DATA: $temp_array"
  5571. eval $LOGFE
  5572. }
  5573. # B_ROOT='true';get_machine_data;exit
  5574. ## return memory used/installed
  5575. get_memory_data()
  5576. {
  5577. eval $LOGFS
  5578. local memory='' memory_full=''
  5579. if [[ $B_MEMINFO_FILE == 'true' ]];then
  5580. memory=$( gawk '
  5581. /^MemTotal:/ {
  5582. tot = $2
  5583. }
  5584. /^(MemFree|Buffers|Cached):/ {
  5585. notused+=$2
  5586. }
  5587. END {
  5588. used = tot - notused
  5589. printf("%.1f/%.1fMB\n", used/1024, tot/1024)
  5590. }' $FILE_MEMINFO )
  5591. log_function_data 'cat' "$FILE_MEMINFO"
  5592. elif [[ $B_SYSCTL == 'true' && -n $Sysctl_a_Data ]];then
  5593. local gawk_fs=': '
  5594.  
  5595. if [[ $BSD_VERSION == 'openbsd' ]];then
  5596. gawk_fs='='
  5597. fi
  5598. memory=$( grep -i 'mem' <<< "$Sysctl_a_Data" | gawk -F "$gawk_fs" '
  5599. BEGIN {
  5600. realMemory=""
  5601. freeMemory=""
  5602. }
  5603. # freebsd seems to use bytes here
  5604. /^hw.physmem/ {
  5605. gsub(/^[^0-9]+|[^0-9]+$/,"",$2)
  5606. realMemory = $2/1024
  5607. if ( freeMemory != "" ) {
  5608. exit
  5609. }
  5610. }
  5611. # But, it uses K here. Openbsd does not seem to have this item
  5612. # this can be either: Free Memory OR Free Memory Pages
  5613. $1 ~ /^Free Memory/ {
  5614. gsub(/[^0-9]/,"",$NF)
  5615. freeMemory = $NF
  5616. if ( realMemory != "" ) {
  5617. exit
  5618. }
  5619. }
  5620. END {
  5621. # hack: temp fix for openbsd: in case no free mem was detected but we have physmem
  5622. if ( freeMemory == "" && realMemory != "" ) {
  5623. printf("NA/%.1fMB\n", realMemory/1024)
  5624. }
  5625. else if ( freeMemory != "" && realMemory != "" ) {
  5626. used = realMemory - freeMemory
  5627. printf("%.1f/%.1fMB\n", used/1024, realMemory/1024)
  5628. }
  5629. }' )
  5630. fi
  5631. echo "$memory"
  5632. log_function_data "memory: $memory"
  5633. eval $LOGFE
  5634. }
  5635.  
  5636. # process and return module version data
  5637. get_module_version_number()
  5638. {
  5639. eval $LOGFS
  5640. local module_version=''
  5641.  
  5642. if [[ $B_MODINFO_TESTED != 'true' ]];then
  5643. B_MODINFO_TESTED='true'
  5644. MODINFO_PATH=$( type -p modinfo )
  5645. fi
  5646.  
  5647. if [[ -n $MODINFO_PATH ]];then
  5648. module_version=$( $MODINFO_PATH $1 2>/dev/null | gawk '
  5649. BEGIN {
  5650. IGNORECASE=1
  5651. }
  5652. /^version/ {
  5653. gsub(/,/, " ", $2)
  5654. gsub(/^ +| +$/, "", $2)
  5655. gsub(/ [ \t]+/, " ", $2)
  5656. print $2
  5657. }
  5658. ' )
  5659. fi
  5660.  
  5661. echo "$module_version"
  5662. log_function_data "module_version: $module_version"
  5663. eval $LOGFE
  5664. }
  5665.  
  5666. ## create array of network cards
  5667. get_networking_data()
  5668. {
  5669. eval $LOGFS
  5670.  
  5671. local B_USB_NETWORKING='false' temp_array=''
  5672.  
  5673. IFS=$'\n'
  5674. A_NETWORK_DATA=( $(
  5675. echo "$Lspci_v_Data" | gawk '
  5676. BEGIN {
  5677. IGNORECASE=1
  5678. counter=0 # required to handle cases of > 1 instance of the same chipset
  5679. }
  5680. /^[0-9a-f:\.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:\.]+ [^:]+: .*(ethernet|network).*$/ {
  5681. nic=gensub(/^[0-9a-f:\.]+ [^:]+: (.+)$/,"\\1","g",$0)
  5682. #gsub(/realtek semiconductor/, "Realtek", nic)
  5683. #gsub(/davicom semiconductor/, "Davicom", nic)
  5684. # The doublequotes are necessary because of the pipes in the variable.
  5685. gsub(/'"$BAN_LIST_NORMAL"'/, "", nic)
  5686. gsub(/,/, " ", nic)
  5687. gsub(/^ +| +$/, "", nic)
  5688. gsub(/ [ \t]+/, " ", nic)
  5689. # construct a unique string ending for each chipset detected, this allows for
  5690. # multiple instances of the same exact chipsets, ie, dual gigabit
  5691. nic = nic "~~" counter++
  5692. aPciBusId[nic] = gensub(/(^[0-9a-f:\.]+) [^:]+: .+$/,"\\1","g",$0)
  5693. # I do not understand why incrementing a string index makes sense?
  5694. eth[nic]++
  5695. while ( getline && !/^$/ ) {
  5696. gsub(/,/, "", $0)
  5697. if ( /I\/O/ ) {
  5698. ports[nic] = ports[nic] $4 " "
  5699. }
  5700. if ( /driver in use/ ) {
  5701. drivers[nic] = drivers[nic] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) ""
  5702. }
  5703. else if ( /kernel modules/ ) {
  5704. modules[nic] = modules[nic] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) ""
  5705. }
  5706. }
  5707. }
  5708.  
  5709. END {
  5710. j=0
  5711. for (i in eth) {
  5712. useDrivers=""
  5713. usePorts=""
  5714. useModules=""
  5715. usePciBusId=""
  5716.  
  5717. if ( eth[i] > 1 ) {
  5718. a[j] = eth[i] "x " i
  5719. }
  5720. else {
  5721. a[j] = i
  5722. }
  5723. ## note: this loses the plural ports case, is it needed anyway?
  5724. if ( ports[i] != "" ) {
  5725. usePorts = ports[i]
  5726. }
  5727. if ( drivers[i] != "" ) {
  5728. useDrivers = drivers[i]
  5729. }
  5730. if ( modules[i] != "" ) {
  5731. useModules = modules[i]
  5732. }
  5733. if ( aPciBusId[i] != "" ) {
  5734. usePciBusId = aPciBusId[i]
  5735. }
  5736. # create array primary item for master array
  5737. # and strip out the counter again, this handled dual cards with same chipset
  5738. sub( /~~[0-9]+$/, "", a[j] )
  5739. sub( / $/, "", usePorts ) # clean off trailing whitespace
  5740. print a[j] "," useDrivers "," usePorts "," useModules, "," usePciBusId
  5741. j++
  5742. }
  5743. }' ) )
  5744. IFS="$ORIGINAL_IFS"
  5745. get_networking_usb_data
  5746. if [[ $B_SHOW_ADVANCED_NETWORK == 'true' || $B_USB_NETWORKING == 'true' ]];then
  5747. get_network_advanced_data
  5748. fi
  5749. temp_array=${A_NETWORK_DATA[@]}
  5750. log_function_data "A_NETWORK_DATA: $temp_array"
  5751.  
  5752. eval $LOGFE
  5753. }
  5754.  
  5755. get_network_advanced_data()
  5756. {
  5757. eval $LOGFS
  5758. local a_network_adv_working='' if_path='' working_path='' working_uevent_path='' dir_path=''
  5759. local if_id='' speed='' duplex='' mac_id='' oper_state='' vendor_product=''
  5760. local usb_data='' usb_vendor='' usb_product='' product_path='' driver_test=''
  5761.  
  5762. for (( i=0; i < ${#A_NETWORK_DATA[@]}; i++ ))
  5763. do
  5764. IFS=","
  5765. a_network_adv_working=( ${A_NETWORK_DATA[i]} )
  5766. # reset these every go round
  5767. driver_test=''
  5768. if_id=''
  5769. speed=''
  5770. duplex=''
  5771. mac_id=''
  5772. oper_state=''
  5773. usb_data=''
  5774. vendor_product=''
  5775. if [[ -z $( grep '^usb-' <<< ${a_network_adv_working[4]} ) ]];then
  5776. # note although this may exist technically don't use it, it's a virtual path
  5777. # and causes weird cat errors when there's a missing file as well as a virtual path
  5778. # /sys/bus/pci/devices/0000:02:02.0/net/eth1
  5779. # real paths are: /sys/devices/pci0000:00/0000:00:1e/0/0000:02:02.0/net/eth1/uevent
  5780. # and on older debian kernels: /sys/devices/pci0000:00/0000:02:02.0/net:eth1/uevent
  5781. # but broadcom shows this sometimes:
  5782. # /sys/devices/pci0000:00/0000:00:03.0/0000:03:00.0/ssb0:0/uevent:['DRIVER=b43', 'MODALIAS=ssb:v4243id0812rev0D']:
  5783. working_path="/sys/bus/pci/devices/0000:${a_network_adv_working[4]}"
  5784. # now we want the real one, that xiin also displays, without symbolic links.
  5785. if [[ -e $working_path ]];then
  5786. working_path=$( readlink -f $working_path 2>/dev/null )
  5787. # sometimes there is another directory between the path and /net
  5788. if [[ ! -e $working_path/net ]];then
  5789. # using find here, probably will need to also use it in usb part since the grep
  5790. # method seems to not be working now. Slice off the rest, which leaves the basic path
  5791. working_path=$( find $working_path/*/net/*/uevent 2>/dev/null | \
  5792. sed 's|/net.*||' )
  5793. fi
  5794. fi
  5795. # working_path=$( ls /sys/devices/pci*/*/0000:${a_network_adv_working[4]}/net/*/uevent )
  5796. else
  5797. # now we'll use the actual vendor:product string instead
  5798. usb_data=${a_network_adv_working[10]}
  5799. usb_vendor=$( cut -d ':' -f 1 <<< $usb_data )
  5800. usb_product=$( cut -d ':' -f 2 <<< $usb_data )
  5801. # this grep returns the path plus the contents of the file, with a colon separator, so slice that off
  5802. # /sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1/idVendor
  5803. working_path=$( grep -s "$usb_vendor" /sys/devices/pci*/*/usb*/*/*/idVendor | \
  5804. sed -e "s/idVendor:$usb_vendor//" -e '/driver/d' )
  5805. # try an alternate path if first one doesn't work
  5806. # /sys/devices/pci0000:00/0000:00:0b.1/usb1/1-1/idVendor
  5807. if [[ -z $working_path ]];then
  5808. working_path=$( grep -s "$usb_vendor" /sys/devices/pci*/*/usb*/*/idVendor | \
  5809. sed -e "s/idVendor:$usb_vendor//" -e '/driver/d' )
  5810. product_path=$( grep -s "$usb_product" /sys/devices/pci*/*/usb*/*/idProduct | \
  5811. sed -e "s/idProduct:$usb_product//" -e '/driver/d' )
  5812. else
  5813. product_path=$( grep -s "$usb_product" /sys/devices/pci*/*/usb*/*/*/idProduct | \
  5814. sed -e "s/idProduct:$usb_product//" -e '/driver/d' )
  5815. fi
  5816.  
  5817. # make sure it's the right product/vendor match here, it will almost always be but let's be sure
  5818. if [[ -n $working_path && -n $product_path ]] && [[ $working_path == $product_path ]];then
  5819. #if [[ -n $working_path ]];then
  5820. # now ls that directory and get the numeric starting sub directory and that should be the full path
  5821. # to the /net directory part
  5822. dir_path=$( ls ${working_path} 2>/dev/null | grep -sE '^[0-9]' )
  5823. working_uevent_path="${working_path}${dir_path}"
  5824. fi
  5825. fi
  5826. # /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/uevent grep for DRIVER=
  5827. # /sys/devices/pci0000:00/0000:00:0b.1/usb1/1-1/1-1:1.0/uevent
  5828. if [[ -n $usb_data ]];then
  5829. driver_test=$( grep -si 'DRIVER=' $working_uevent_path/uevent | cut -d '=' -f 2 )
  5830. if [[ -n $driver_test ]];then
  5831. a_network_adv_working[1]=$driver_test
  5832. fi
  5833. fi
  5834. log_function_data "PRE: working_path: $working_path\nworking_uevent_path: $working_uevent_path"
  5835.  
  5836. # this applies in two different cases, one, default, standard, two, for usb, this is actually
  5837. # the short path, minus the last longer numeric directory name, ie:
  5838. # from debian squeeze 2.6.32-5-686:
  5839. # /sys/devices/pci0000:00/0000:00:0b.1/usb1/1-1/net/wlan0/address
  5840. if [[ -e $working_path/net ]];then
  5841. if_path=$( ls $working_path/net 2>/dev/null )
  5842. if_id=$if_path
  5843. working_path=$working_path/net/$if_path
  5844. # this is the normal usb detection if the first one didn't work
  5845. elif [[ -n $usb_data && -e $working_uevent_path/net ]];then
  5846. if_path=$( ls $working_uevent_path/net 2>/dev/null )
  5847. if_id=$if_path
  5848. working_path=$working_uevent_path/net/$if_path
  5849. # 2.6.32 debian lenny kernel shows not: /net/eth0 but /net:eth0
  5850. else
  5851. if_path=$( ls $working_path 2>/dev/null | grep 'net:' )
  5852. if_id=$( cut -d ':' -f 2 <<< "$if_path" )
  5853. working_path=$working_path/$if_path
  5854. fi
  5855. log_function_data "POST: working_path: $working_path\nif_path: $if_path - if_id: $if_id"
  5856.  
  5857. if [[ -n $if_path ]];then
  5858. if [[ -r $working_path/speed ]];then
  5859. speed=$( cat $working_path/speed 2>/dev/null )
  5860. fi
  5861. if [[ -r $working_path/duplex ]];then
  5862. duplex=$( cat $working_path/duplex 2>/dev/null )
  5863. fi
  5864. if [[ -r $working_path/address ]];then
  5865. mac_id=$( cat $working_path/address 2>/dev/null )
  5866. fi
  5867. if [[ -r $working_path/operstate ]];then
  5868. oper_state=$( cat $working_path/operstate 2>/dev/null )
  5869. fi
  5870. fi
  5871.  
  5872. if [[ -n ${a_network_adv_working[10]} ]];then
  5873. vendor_product=${a_network_adv_working[10]}
  5874. fi
  5875. A_NETWORK_DATA[i]=${a_network_adv_working[0]}","${a_network_adv_working[1]}","${a_network_adv_working[2]}","${a_network_adv_working[3]}","${a_network_adv_working[4]}","$if_id","$oper_state","$speed","$duplex","$mac_id","$vendor_product
  5876. IFS="$ORIGINAL_IFS"
  5877. done
  5878.  
  5879. eval $LOGFE
  5880. }
  5881.  
  5882. get_networking_usb_data()
  5883. {
  5884. eval $LOGFS
  5885. local lsusb_path='' lsusb_data='' a_usb='' array_count=''
  5886.  
  5887. # now we'll check for usb wifi, a work in progress
  5888. # USB_NETWORK_SEARCH
  5889. # alsa usb detection by damentz
  5890. # for every sound card symlink in /proc/asound - display information about it
  5891. lsusb_path=$( type -p lsusb )
  5892. # if lsusb exists, the file is a symlink, and contains an important usb exclusive file: continue
  5893. if [[ -n $lsusb_path ]]; then
  5894. # send error messages of lsusb to /dev/null as it will display a bunch if not a super user
  5895. lsusb_data="$( $lsusb_path 2>/dev/null )"
  5896. # also, find the contents of usbid in lsusb and print everything after the 7th word on the
  5897. # corresponding line. Finally, strip out commas as they will change the driver :)
  5898. if [[ -n $lsusb_data ]];then
  5899. IFS=$'\n'
  5900. a_usb=( $(
  5901. gawk '
  5902. BEGIN {
  5903. IGNORECASE=1
  5904. string=""
  5905. separator=""
  5906. }
  5907. /'"$USB_NETWORK_SEARCH"'/ && !/bluetooth| hub|keyboard|mouse|printer| ps2|reader|scan|storage/ {
  5908. string=""
  5909. gsub( /,/, " ", $0 )
  5910. gsub(/'"$BAN_LIST_NORMAL"'/, "", $0)
  5911. gsub(/ [ \t]+/, " ", $0)
  5912. #sub(/realtek semiconductor/, "Realtek", $0)
  5913. #sub(/davicom semiconductor/, "Davicom", $0)
  5914. #sub(/Belkin Components/, "Belkin", $0)
  5915.  
  5916. for ( i=7; i<= NF; i++ ) {
  5917. string = string separator $i
  5918. separator = " "
  5919. }
  5920. if ( $2 != "" ){
  5921. sub(/:/, "", $4 )
  5922. print string ",,,,usb-" $2 "-" $4 ",,,,,," $6
  5923. }
  5924. }' <<< "$lsusb_data" ) )
  5925. IFS="$ORIGINAL_IFS"
  5926. if [[ ${#a_usb[@]} -gt 0 ]];then
  5927. array_count=${#A_NETWORK_DATA[@]}
  5928. for (( i=0; i < ${#a_usb[@]}; i++ ))
  5929. do
  5930. A_NETWORK_DATA[$array_count]=${a_usb[i]}
  5931. ((array_count++))
  5932. done
  5933. # need this to get the driver data for -N regular output, but no need
  5934. # to run the advanced stuff unless required
  5935. B_USB_NETWORKING='true'
  5936. fi
  5937. fi
  5938. fi
  5939. # echo $B_USB_NETWORKING
  5940. eval $LOGFE
  5941. }
  5942.  
  5943. get_networking_wan_ip_data()
  5944. {
  5945. eval $LOGFS
  5946. local ip=''
  5947.  
  5948. # get ip using wget redirect to stdout. This is a clean, text only IP output url,
  5949. # single line only, ending in the ip address. May have to modify this in the future
  5950. # to handle ipv4 and ipv6 addresses but should not be necessary.
  5951. # awk has bad regex handling so checking it with grep -E instead
  5952. # ip=$( echo 2001:0db8:85a3:0000:0000:8a2e:0370:7334 | gawk --re-interval '
  5953. # ip=$( wget -q -O - $WAN_IP_URL | gawk --re-interval '
  5954. ip=$( wget -t 1 -T $WGET_TIMEOUT -q -O - $WAN_IP_URL | gawk --re-interval '
  5955. {
  5956. #gsub("\n","",$2")
  5957. print $NF
  5958. }' )
  5959. # validate the data
  5960. if [[ -z $ip ]];then
  5961. ip='None Detected!'
  5962. elif [[ -z $( grep -Es \
  5963. '^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4}:[[:alnum:]]{0,4})$' <<< $ip ) ]];then
  5964. ip='IP Source Corrupt!'
  5965. fi
  5966. echo "$ip"
  5967. log_function_data "ip: $ip"
  5968. eval $LOGFE
  5969. }
  5970.  
  5971. get_networking_local_ip_data()
  5972. {
  5973. eval $LOGFS
  5974.  
  5975. local ip_tool_command=$( type -p ip )
  5976. local temp_array='' ip_tool='ip' ip_tool_data=''
  5977. # the chances for all new systems to have ip by default are far higher than
  5978. # the deprecated ifconfig. Only try for ifconfig if ip is not present in system
  5979. if [[ -z $ip_tool_command ]];then
  5980. ip_tool_command=$( type -p ifconfig )
  5981. ip_tool='ifconfig'
  5982. else
  5983. ip_tool_command="$ip_tool_command addr"
  5984. fi
  5985. if [[ -n "$ip_tool_command" ]];then
  5986. if [[ $ip_tool == 'ifconfig' ]];then
  5987. ip_tool_data="$( $ip_tool_command | gawk '
  5988. {
  5989. line=gensub(/^([a-z]+[0-9][:]?[[:space:]].*)/, "\n\\1", $0)
  5990. print line
  5991. }' )"
  5992. # note, ip addr does not have proper record separation, so creating new lines explicitly here at start
  5993. # of each IF record item. Also getting rid of the unneeded numeric line starters, now it can be parsed
  5994. # like ifconfig more or less
  5995. elif [[ $ip_tool == 'ip' ]];then
  5996. ip_tool_data="$( eval ${ip_tool_command} | sed 's/^[0-9]\+:[[:space:]]\+/\n/' )"
  5997. fi
  5998. fi
  5999. if [[ -z $ip_tool_command ]];then
  6000. A_INTERFACES_DATA=( "Interfaces program 'ip' missing. Please check: $SCRIPT_NAME --recommends" )
  6001. elif [[ -n "$ip_tool_data" ]];then
  6002. IFS=$'\n' # $ip_tool_command
  6003. A_INTERFACES_DATA=( $(
  6004. gawk -v ipTool=$ip_tool -v bsdType=$BSD_TYPE '
  6005. BEGIN {
  6006. IGNORECASE=1
  6007. interface=""
  6008. ifIp=""
  6009. ifIpV6=""
  6010. ifMask=""
  6011. }
  6012. # skip past the lo item
  6013. /^lo/ {
  6014. while (getline && !/^$/ ) {
  6015. # do nothing, just get past this entry item
  6016. }
  6017. }
  6018. /^[a-zA-Z]+[0-9]/ {
  6019. # not clear on why inet is coming through, but this gets rid of it
  6020. # as first line item.
  6021. gsub(/,/, " ", $0)
  6022. gsub(/^ +| +$/, "", $0)
  6023. gsub(/ [ \t]+/, " ", $0)
  6024. interface = $1
  6025. # prep this this for ip addr: eth0:
  6026. sub(/:/, "", interface)
  6027. ifIp=""
  6028. ifIpV6=""
  6029. ifMask=""
  6030. aInterfaces[interface]++
  6031.  
  6032. while (getline && !/^$/ ) {
  6033. if ( ipTool == "ifconfig" ) {
  6034. if (/inet addr:/) {
  6035. ifIp = gensub( /addr:([0-9\.]+)/, "\\1", "g", $2 )
  6036. if (/mask:/) {
  6037. ifMask = gensub( /mask:([0-9\.]+)/, "\\1", "g", $NF )
  6038. }
  6039. }
  6040. if (/inet6 addr:/) {
  6041. ifIpV6 = $3
  6042. }
  6043. if ( bsdType == "bsd" ) {
  6044. if ( $1 == "inet" ) {
  6045. ifIp = $2
  6046. if ( $3 == "netmask" ) {
  6047. ifMask = $4
  6048. }
  6049. }
  6050. if ( $0 ~ /inet6.*%/ ) {
  6051. sub(/%.*/,"",$2)
  6052. ifIpV6 = $2
  6053. }
  6054. }
  6055. }
  6056. else if ( ipTool == "ip" ) {
  6057. if ( $1 == "inet" ) {
  6058. ifIp = $2
  6059. }
  6060. if ( $1 == "inet6" ) {
  6061. ifIpV6 = $2
  6062. }
  6063. }
  6064. }
  6065. # slice off the digits that are sometimes tacked to the end of the address,
  6066. # like: /64 or /24
  6067. sub(/\/[0-9]+/, "", ifIp)
  6068. sub(/\/[0-9]+/, "", ifIpV6)
  6069. ipAddresses[interface] = ifIp "," ifMask "," ifIpV6
  6070. }
  6071. END {
  6072. j=0
  6073. for (i in aInterfaces) {
  6074. ifData = ""
  6075. a[j] = i
  6076. if (ipAddresses[i] != "") {
  6077. ifData = ipAddresses[i]
  6078. }
  6079. # create array primary item for master array
  6080. # tested needed to avoid bad data from above, if null it is garbage
  6081. # this is the easiest way to handle junk I found, improve if you want
  6082. if ( ifData != "" ) {
  6083. print a[j] "," ifData
  6084. }
  6085. j++
  6086. }
  6087. }' <<< "$ip_tool_data" ) )
  6088. IFS="$ORIGINAL_IFS"
  6089. else
  6090. A_INTERFACES_DATA=( "Interfaces program $ip_tool present but created no data. " )
  6091. fi
  6092. temp_array=${A_INTERFACES_DATA[@]}
  6093. log_function_data "A_INTERFACES_DATA: $temp_array"
  6094. eval $LOGFE
  6095. }
  6096. # get_networking_local_ip_data;exit
  6097.  
  6098. # get_networking_local_ip_data;exit
  6099. get_optical_drive_data()
  6100. {
  6101. eval $LOGFS
  6102.  
  6103. local temp_array='' sys_uevent_path='' proc_cdrom='' link_list=''
  6104. local separator='' linked='' disk='' item_string='' proc_info_string=''
  6105. local dev_disks_links="$( ls /dev/dvd* /dev/cd* /dev/scd* 2>/dev/null )"
  6106. # get the actual disk dev location, first try default which is easier to run, need to preserve line breaks
  6107. local dev_disks_real="$( echo "$dev_disks_links" | xargs -L 1 readlink 2>/dev/null | sort -u )"
  6108. # Some systems don't support xargs -L so we need to do it manually
  6109. if [[ -z $dev_disks_real ]];then
  6110. for linked in $dev_disks_links
  6111. do
  6112. disk=$( readlink $linked 2>/dev/null )
  6113. if [[ -n $disk ]];then
  6114. disk=$( basename $disk ) # puppy shows this as /dev/sr0, not sr0
  6115. if [[ -z $dev_disks_real || -z $( grep $disk <<< $dev_disks_real ) ]];then
  6116. # need line break IFS for below, no white space
  6117. dev_disks_real="$dev_disks_real$separator$disk"
  6118. separator=$'\n'
  6119. fi
  6120. fi
  6121. done
  6122. dev_disks_real="$( sort -u <<< "$dev_disks_real" )"
  6123. linked=''
  6124. disk=''
  6125. separator=''
  6126. fi
  6127.  
  6128. # A_OPTICAL_DRIVE_DATA indexes: not going to use all these, but it's just as easy to build the full
  6129. # data array and use what we need from it as to update it later to add features or items
  6130. # 0 - true dev path, ie, sr0, hdc
  6131. # 1 - dev links to true path
  6132. # 2 - device vendor - for hdx drives, vendor model are one string from proc
  6133. # 3 - device model
  6134. # 4 - device rev version
  6135. # 5 - speed
  6136. # 6 - multisession support
  6137. # 7 - MCN support
  6138. # 8 - audio read
  6139. # 9 - cdr
  6140. # 10 - cdrw
  6141. # 11 - dvd read
  6142. # 12 - dvdr
  6143. # 13 - dvdram
  6144. # 14 - state
  6145.  
  6146. if [[ -n $dev_disks_real ]];then
  6147. if [[ $B_SHOW_FULL_OPTICAL == 'true' ]];then
  6148. proc_cdrom="$( cat /proc/sys/dev/cdrom/info 2>/dev/null )"
  6149. fi
  6150. IFS=$'\n'
  6151. A_OPTICAL_DRIVE_DATA=( $(
  6152. for disk in $dev_disks_real
  6153. do
  6154. for linked in $dev_disks_links
  6155. do
  6156. if [[ -n $( readlink $linked | grep $disk ) ]];then
  6157. linked=$( basename $linked )
  6158. link_list="$link_list$separator$linked"
  6159. separator='~'
  6160. fi
  6161. done
  6162. item_string="$disk,$link_list"
  6163. link_list=''
  6164. linked=''
  6165. separator=''
  6166. vendor=''
  6167. model=''
  6168. proc_info_string=''
  6169. rev_number=''
  6170. state=""
  6171. sys_path=''
  6172. # this is only for new sd type paths in /sys, otherwise we'll use /proc/ide
  6173. if [[ -z $( grep '^hd' <<< $disk ) ]];then
  6174. sys_path=$( ls /sys/devices/pci*/*/host*/target*/*/block/$disk/uevent 2>/dev/null | sed "s|/block/$disk/uevent||" )
  6175. # no need to test for errors yet, probably other user systems will require some alternate paths though
  6176. if [[ -n $sys_path ]];then
  6177. vendor=$( cat $sys_path/vendor 2>/dev/null )
  6178. model=$( cat $sys_path/model 2>/dev/null | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/,//g' )
  6179. state=$( cat $sys_path/state 2>/dev/null | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/,//g' )
  6180. rev_number=$( cat $sys_path/rev 2>/dev/null | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/,//g' )
  6181. fi
  6182. elif [[ -e /proc/ide/$disk/model ]];then
  6183. vendor=$( cat /proc/ide/$disk/model 2>/dev/null )
  6184. fi
  6185. if [[ -n $vendor ]];then
  6186. vendor=$( gawk '
  6187. BEGIN {
  6188. IGNORECASE=1
  6189. }
  6190. {
  6191. gsub(/'"$BAN_LIST_NORMAL"'/, "", $0)
  6192. sub(/TSSTcorp/, "TSST ", $0) # seen more than one of these weird ones
  6193. gsub(/,/, " ", $0)
  6194. gsub(/^[[:space:]]*|[[:space:]]*$/, "", $0)
  6195. gsub(/ [[:space:]]+/, " ", $0)
  6196. print $0
  6197. }' <<< $vendor )
  6198. fi
  6199. # this needs to run no matter if there's proc data or not to create the array comma list
  6200. if [[ $B_SHOW_FULL_OPTICAL == 'true' ]];then
  6201. proc_info_string=$( gawk -v diskId=$disk '
  6202. BEGIN {
  6203. IGNORECASE=1
  6204. position=""
  6205. speed=""
  6206. multisession=""
  6207. mcn=""
  6208. audio=""
  6209. cdr=""
  6210. cdrw=""
  6211. dvd=""
  6212. dvdr=""
  6213. dvdram=""
  6214. }
  6215. # first get the position of the device name from top field
  6216. # we will use this to get all the other data for that column
  6217. /drive name:/ {
  6218. for ( position=3; position <= NF; position++ ) {
  6219. if ( $position == diskId ) {
  6220. break
  6221. }
  6222. }
  6223. }
  6224. /drive speed:/ {
  6225. speed = $position
  6226. }
  6227. /Can read multisession:/ {
  6228. multisession=$( position + 1 )
  6229. }
  6230. /Can read MCN:/ {
  6231. mcn=$( position + 1 )
  6232. }
  6233. /Can play audio:/ {
  6234. audio=$( position + 1 )
  6235. }
  6236. /Can write CD-R:/ {
  6237. cdr=$( position + 1 )
  6238. }
  6239. /Can write CD-RW:/ {
  6240. cdrw=$( position + 1 )
  6241. }
  6242. /Can read DVD:/ {
  6243. dvd=$( position + 1 )
  6244. }
  6245. /Can write DVD-R:/ {
  6246. dvdr=$( position + 1 )
  6247. }
  6248. /Can write DVD-RAM:/ {
  6249. dvdram=$( position + 1 )
  6250. }
  6251. END {
  6252. print speed "," multisession "," mcn "," audio "," cdr "," cdrw "," dvd "," dvdr "," dvdram
  6253. }
  6254. ' <<< "$proc_cdrom" )
  6255. fi
  6256. item_string="$item_string,$vendor,$model,$rev_number,$proc_info_string,$state"
  6257. echo $item_string
  6258. done \
  6259. ) )
  6260. IFS="$ORIGINAL_IFS"
  6261. fi
  6262. temp_array=${A_OPTICAL_DRIVE_DATA[@]}
  6263. log_function_data "A_OPTICAL_DRIVE_DATA: $temp_array"
  6264. eval $LOGFE
  6265. }
  6266.  
  6267. get_partition_data()
  6268. {
  6269. eval $LOGFS
  6270.  
  6271. local a_partition_working='' dev_item='' temp_array='' dev_working_item=''
  6272. local swap_data='' df_string='' main_partition_data='' df_test='' fs_type=''
  6273. local mount_data='' dev_bsd_item=''
  6274. #local excluded_file_types='--exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660'
  6275. # df doesn't seem to work in script with variables like at the command line
  6276. # added devfs linprocfs sysfs fdescfs which show on debian kfreebsd kernel output
  6277. if [[ -z $BSD_TYPE ]];then
  6278. swap_data="$( swapon -s 2>/dev/null )"
  6279. df_string='df -h -T -P --exclude-type=aufs --exclude-type=devfs --exclude-type=devtmpfs
  6280. --exclude-type=fdescfs --exclude-type=iso9660 --exclude-type=linprocfs --exclude-type=procfs
  6281. --exclude-type=squashfs --exclude-type=sysfs --exclude-type=tmpfs --exclude-type=unionfs'
  6282. else
  6283. swap_data="$( swapctl -l 2>/dev/null )"
  6284. # default size is 512, -H only for size in human readable format
  6285. # older bsds don't support -T, pain, so we'll use partial output there
  6286. df_test=$( df -H -T 2>/dev/null )
  6287. if [[ -n $df_test ]];then
  6288. df_string='df -H -T'
  6289. else
  6290. df_string='df -H'
  6291. fi
  6292. fi
  6293. main_partition_data="$( eval $df_string )"
  6294. # set dev disk label/mapper/uuid data globals
  6295. get_partition_dev_data 'label'
  6296. get_partition_dev_data 'mapper'
  6297. get_partition_dev_data 'uuid'
  6298.  
  6299. log_function_data 'raw' "main_partition_data:\n$main_partition_data\n\nswap_data:\n$swap_data"
  6300.  
  6301. # new kernels/df have rootfs and / repeated, creating two entries for the same partition
  6302. # so check for two string endings of / then slice out the rootfs one, I could check for it
  6303. # before slicing it out, but doing that would require the same action twice re code execution
  6304. if [[ $( grep -cs '[[:space:]]/$' <<< "$main_partition_data" ) -gt 1 ]];then
  6305. main_partition_data="$( grep -vs '^rootfs' <<< "$main_partition_data" )"
  6306. fi
  6307. log_function_data 'raw' "main_partition_data_post_rootfs:\n$main_partition_data\n\nswap_data:\n$swap_data"
  6308. IFS=$'\n'
  6309. # sample line: /dev/sda2 ext3 15G 8.9G 4.9G 65% /home
  6310. # $NF = partition name; $(NF - 4) = partition size; $(NF - 3) = used, in gB; $(NF - 1) = percent used
  6311. ## note: by subtracting from the last field number NF, we avoid a subtle issue with LVM df output, where if
  6312. ## the first field is too long, it will occupy its own line, this way we are getting only the needed data
  6313. A_PARTITION_DATA=( $( echo "$main_partition_data" | gawk -v bsdType=$BSD_TYPE '
  6314. BEGIN {
  6315. IGNORECASE=1
  6316. fileSystem=""
  6317. }
  6318. # this has to be nulled for every iteration so it does not retain value from last iteration
  6319. devBase=""
  6320. # skipping these file systems because bsds do not support df --exclude-type=<fstype>
  6321. # note that using $1 to handle older bsd df, which do not support -T. This will not be reliable but we will see
  6322. ( bsdType != "" ) {
  6323. # skip if non disk/partition, or if raid primary id, which will not have a / in it
  6324. if ( $1 ~ /^(aufs|devfs|devtmpfs|fdescfs|iso9660|linprocfs|procfs|squashfs|sysfs|tmpfs|type|unionfs)$/ ||
  6325. $1 ~ /^([^\/]+)$/ ) {
  6326. # note use next, not getline or it does not work right
  6327. next
  6328. }
  6329. }
  6330. # this is required because below we are subtracting from NF, so it has to be > 5
  6331. # the real issue is long file system names that force the wrap of df output: //fileserver/main
  6332. # but we still need to handle more dynamically long space containing file names, but later.
  6333. # Using df -P should fix this, ie, no wrapping of line lines, but leaving this for now
  6334. ( NF < 6 ) && ( $0 !~ /[0-9]+%/ ) {
  6335. # set the dev location here for cases of wrapped output
  6336. if ( NF == 1 ) {
  6337. devBase=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
  6338. }
  6339. getline
  6340. }
  6341.  
  6342. # next set devBase if it didn not get set above here
  6343. ( devBase == "" ) && ( $1 ~ /^\/dev\/|:\/|\/\// ) {
  6344. devBase=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
  6345. }
  6346. # this handles zfs type devices/partitions, which do not start with / but contain /
  6347. ( bsdType != "" && devBase == "" && $1 ~ /^[^\/]+\/.+/ ) {
  6348. devBase=gensub( /^([^\/]+\/)([^\/]+)$/, "non-dev-\\1\\2", 1, $1 )
  6349. }
  6350. # this handles yet another fredforfaen special case where a mounted drive
  6351. # has the search string in its name
  6352. $NF ~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$/ {
  6353. # note, older df in bsd do not have file system column
  6354. if ( NF == "7" && $(NF - 1) ~ /[0-9]+%/ ) {
  6355. fileSystem=$(NF - 5)
  6356. }
  6357. else {
  6358. fileSystem=""
  6359. }
  6360. print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main," fileSystem "," devBase
  6361. }
  6362. # skip all these, including the first, header line. Use the --exclude-type
  6363. # to handle new filesystems types we do not want listed here
  6364. $NF !~ /^\/$|^\/boot$|^\/var$|^\/home$|^\/tmp$|^\/usr$|^filesystem/ {
  6365. # this is to avoid file systems with spaces in their names, that will make
  6366. # the test show the wrong data in each of the fields, if no x%, then do not use
  6367. # using 3 cases, first default, standard, 2nd, 3rd, handles one and two spaces in name
  6368. if ( $(NF - 1) ~ /[0-9]+%/ ) {
  6369. # note, older df in bsd do not have file system column
  6370. if ( NF == "7" ) {
  6371. fileSystem=$(NF - 5)
  6372. }
  6373. else {
  6374. fileSystem=""
  6375. }
  6376. print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",secondary," fileSystem "," devBase
  6377. }
  6378. # these two cases construct the space containing name
  6379. else if ( $(NF - 2) ~ /[0-9]+%/ ) {
  6380. # note, older df in bsd do not have file system column
  6381. if ( NF == "8" && $(NF - 6) !~ /^[0-9]+/ ) {
  6382. fileSystem=$(NF - 6)
  6383. }
  6384. else {
  6385. fileSystem=""
  6386. }
  6387. print $(NF - 1) " " $NF "," $(NF - 5) "," $(NF - 4) "," $(NF - 2) ",secondary," fileSystem "," devBase
  6388. }
  6389. else if ( $(NF - 3) ~ /[0-9]+%/ ) {
  6390. # note, older df in bsd do not have file system column
  6391. if ( NF == "9" && $(NF - 7) !~ /^[0-9]+/ ) {
  6392. fileSystem=$(NF - 7)
  6393. }
  6394. else {
  6395. fileSystem=""
  6396. }
  6397. print $(NF - 2) " " $(NF - 1) " " $NF "," $(NF - 6) "," $(NF - 5) "," $(NF - 3) ",secondary," fileSystem "," devBase
  6398. }
  6399. }' )
  6400.  
  6401. # now add the swap partition data, don't want to show swap files, just partitions,
  6402. # though this can include /dev/ramzswap0. Note: you can also use /proc/swaps for this
  6403. # data, it's the same exact output as swapon -s
  6404. $( echo "$swap_data" | gawk -v bsdType=$BSD_TYPE '
  6405. BEGIN {
  6406. swapCounter = 1
  6407. usedHolder=""
  6408. sizeHolder=""
  6409. }
  6410. /^\/dev/ {
  6411. if ( bsdType == "" ) {
  6412. usedHolder=$4
  6413. sizeHolder=$3
  6414. }
  6415. else {
  6416. usedHolder=$3
  6417. sizeHolder=$2
  6418. }
  6419. size = sprintf( "%.2f", sizeHolder*1024/1000**3 )
  6420. devBase = gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
  6421. used = sprintf( "%.2f", usedHolder*1024/1000**3 )
  6422. percentUsed = sprintf( "%.0f", ( usedHolder/sizeHolder )*100 )
  6423. print "swap-" swapCounter "," size "GB," used "GB," percentUsed "%,main," "swap," devBase
  6424. swapCounter = ++swapCounter
  6425. }' ) )
  6426. IFS="$ORIGINAL_IFS"
  6427.  
  6428. temp_array=${A_PARTITION_DATA[@]}
  6429. # echo $temp_array
  6430. log_function_data "1: A_PARTITION_DATA:\n$temp_array"
  6431.  
  6432. # we'll use this for older systems where no filesystem type is shown in df
  6433. if [[ $BSD_TYPE == 'bsd' ]];then
  6434. mount_data="$( mount )"
  6435. fi
  6436. # now we'll handle some fringe cases where irregular df -hT output shows /dev/disk/.. instead of
  6437. # /dev/h|sdxy type data for column 1, . A_PARTITION_DATA[6]
  6438. # Here we just search for the uuid/label and then grab the end of the line to get the right dev item.
  6439. for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
  6440. do
  6441. IFS=","
  6442. a_partition_working=( ${A_PARTITION_DATA[i]} )
  6443. IFS="$ORIGINAL_IFS"
  6444.  
  6445. dev_item=${a_partition_working[6]} # reset each loop
  6446. fs_type=${a_partition_working[5]}
  6447. # older bsds have df minus -T so can't get fs type easily, try using mount instead
  6448. if [[ $BSD_TYPE == 'bsd' && -z $fs_type && -n $dev_item ]];then
  6449. dev_bsd_item=$( sed -e 's/non-dev-//' -e 's|/|\\/|g' <<< "$dev_item" )
  6450. fs_type=$( gawk -F '(' '
  6451. /'$dev_bsd_item'/ {
  6452. # slice out everything after / plus the first comma
  6453. sub( /,.*/, "", $2 )
  6454. print $2
  6455. exit
  6456. }' <<< "$mount_data" )
  6457. fi
  6458. # note: for swap this will already be set
  6459. if [[ -n $( grep -E '(by-uuid|by-label)' <<< $dev_item ) ]];then
  6460. dev_working_item=$( basename $dev_item )
  6461. if [[ -n $DEV_DISK_UUID ]];then
  6462. dev_item=$( echo "$DEV_DISK_UUID" | gawk '
  6463. $0 ~ /[ /t]'$dev_working_item'[ /t]/ {
  6464. item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
  6465. print item
  6466. exit
  6467. }' )
  6468. fi
  6469. # if we didn't find anything for uuid try label
  6470. if [[ -z $dev_item && -n $DEV_DISK_LABEL ]];then
  6471. dev_item=$( echo "$DEV_DISK_LABEL" | gawk '
  6472. $0 ~ /[ /t]'$dev_working_item'[ /t]/ {
  6473. item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
  6474. print item
  6475. exit
  6476. }' )
  6477. fi
  6478. elif [[ -n $( grep 'mapper/' <<< $dev_item ) ]];then
  6479. # get the mapper actual dev item
  6480. dev_item=$( get_dev_processed_item "$dev_item" )
  6481. fi
  6482.  
  6483. if [[ -n $dev_item ]];then
  6484. # assemble everything we could get for dev/h/dx, label, and uuid
  6485. IFS=","
  6486. A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","$fs_type","$dev_item
  6487. IFS="$ORIGINAL_IFS"
  6488. fi
  6489. done
  6490. temp_array=${A_PARTITION_DATA[@]}
  6491. # echo $temp_array
  6492. log_function_data "2: A_PARTITION_DATA:\n$temp_array"
  6493. if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
  6494. get_partition_data_advanced
  6495. fi
  6496. eval $LOGFE
  6497. }
  6498.  
  6499. # first get the locations of the mount points for label/uuid detection
  6500. get_partition_data_advanced()
  6501. {
  6502. eval $LOGFS
  6503. local a_partition_working='' dev_partition_data=''
  6504. local dev_item='' dev_label='' dev_uuid='' temp_array=''
  6505. local mount_point=''
  6506. # set dev disk label/mapper/uuid data globals
  6507. get_partition_dev_data 'label'
  6508. get_partition_dev_data 'mapper'
  6509. get_partition_dev_data 'uuid'
  6510.  
  6511. if [[ $B_MOUNTS_FILE == 'true' ]];then
  6512. for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
  6513. do
  6514. IFS=","
  6515. a_partition_working=( ${A_PARTITION_DATA[i]} )
  6516. IFS="$ORIGINAL_IFS"
  6517.  
  6518. # note: for swap this will already be set
  6519. if [[ -z ${a_partition_working[6]} ]];then
  6520.  
  6521. mount_point=$( sed 's|/|\\/|g' <<< ${a_partition_working[0]} )
  6522. #echo mount_point $mount_point
  6523. dev_partition_data=$( gawk '
  6524. BEGIN {
  6525. IGNORECASE = 1
  6526. partition = ""
  6527. partTemp = ""
  6528. }
  6529. # trying to handle space in name
  6530. # gsub( /\\040/, " ", $0 )
  6531. /[ \t]'$mount_point'[ \t]/ && $1 != "rootfs" {
  6532. # initialize the variables
  6533. label = ""
  6534. uuid = ""
  6535.  
  6536. # slice out the /dev
  6537. partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, $1 )
  6538. # label and uuid can occur for root, set partition to null now
  6539. if ( partition ~ /by-label/ ) {
  6540. label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, $1 )
  6541. partition = ""
  6542. }
  6543. if ( partition ~ /by-uuid/ ) {
  6544. uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, $1 )
  6545. partition = ""
  6546. }
  6547.  
  6548. # handle /dev/root for / id
  6549. if ( partition == "root" ) {
  6550. # if this works, great, otherwise, just set this to null values
  6551. partTemp="'$( readlink /dev/root 2>/dev/null )'"
  6552. if ( partTemp != "" ) {
  6553. if ( partTemp ~ /[hsv]d[a-z][0-9]{1,2}/ ) {
  6554. partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, partTemp )
  6555. }
  6556. else if ( partTemp ~ /by-uuid/ ) {
  6557. uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, partTemp )
  6558. partition="" # set null to let real location get discovered
  6559. }
  6560. else if ( partTemp ~ /by-label/ ) {
  6561. label=gensub( /^(\/dev\/disk\/by-label\/)(.+)$/, "\\2", 1, partTemp )
  6562. partition="" # set null to let real location get discovered
  6563. }
  6564. }
  6565. else {
  6566. partition = ""
  6567. label = ""
  6568. uuid = ""
  6569. }
  6570. }
  6571. print partition "," label "," uuid
  6572. exit
  6573. }' $FILE_MOUNTS )
  6574.  
  6575. # assemble everything we could get for dev/h/dx, label, and uuid
  6576. IFS=","
  6577. A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","${a_partition_working[5]}","$dev_partition_data
  6578. IFS="$ORIGINAL_IFS"
  6579. fi
  6580. ## now we're ready to proceed filling in the data
  6581. IFS=","
  6582. a_partition_working=( ${A_PARTITION_DATA[i]} )
  6583. IFS="$ORIGINAL_IFS"
  6584. # get the mapper actual dev item first, in case it's mapped
  6585. dev_item=$( get_dev_processed_item "${a_partition_working[6]}" )
  6586. # make sure not to slice off rest if it's a network mounted file system
  6587. if [[ -n $dev_item && -z $( grep -E '(^//|:/)' <<< $dev_item ) ]];then
  6588. dev_item=$( basename $dev_item ) ## needed to avoid error in case name still has / in it
  6589. fi
  6590. dev_label=${a_partition_working[7]}
  6591. dev_uuid=${a_partition_working[8]}
  6592. # then if dev data/uuid is incomplete, try to get missing piece
  6593. # it's more likely we'll get a uuid than a label. But this should get the
  6594. # dev item set no matter what, so then we can get the rest of any missing data
  6595. # first we'll get the dev_item if it's missing
  6596. if [[ -z $dev_item ]];then
  6597. if [[ -n $DEV_DISK_UUID && -n $dev_uuid ]];then
  6598. dev_item=$( echo "$DEV_DISK_UUID" | gawk '
  6599. $0 ~ /[ \t]'$dev_uuid'[ \t]/ {
  6600. item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
  6601. print item
  6602. exit
  6603. }' )
  6604. elif [[ -n $DEV_DISK_LABEL && -n $dev_label ]];then
  6605. dev_item=$( echo "$DEV_DISK_LABEL" | gawk '
  6606. # first we need to change space x20 in by-label back to a real space
  6607. #gsub( /x20/, " ", $0 )
  6608. # then we can see if the string is there
  6609. $0 ~ /[ \t]'$dev_label'[ \t]/ {
  6610. item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF )
  6611. print item
  6612. exit
  6613. }' )
  6614. fi
  6615. fi
  6616.  
  6617. # this can trigger all kinds of weird errors if it is a non /dev path, like: remote:/machine/name
  6618. if [[ -n $dev_item && -z $( grep -E '(^//|:/)' <<< $dev_item ) ]];then
  6619. if [[ -n $DEV_DISK_UUID && -z $dev_uuid ]];then
  6620. dev_uuid=$( echo "$DEV_DISK_UUID" | gawk '
  6621. /'$dev_item'$/ {
  6622. print $(NF - 2)
  6623. exit
  6624. }' )
  6625. fi
  6626. if [[ -n $DEV_DISK_LABEL && -z $dev_label ]];then
  6627. dev_label=$( echo "$DEV_DISK_LABEL" | gawk '
  6628. /'$dev_item'$/ {
  6629. print $(NF - 2)
  6630. exit
  6631. }' )
  6632. fi
  6633. fi
  6634.  
  6635. # assemble everything we could get for dev/h/dx, label, and uuid
  6636. IFS=","
  6637. A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","${a_partition_working[5]}","$dev_item","$dev_label","$dev_uuid
  6638. IFS="$ORIGINAL_IFS"
  6639. done
  6640. log_function_data 'cat' "$FILE_MOUNTS"
  6641. else
  6642. if [[ $BSD_TYPE == 'bsd' ]];then
  6643. get_partition_data_advanced_bsd
  6644. fi
  6645. fi
  6646. temp_array=${A_PARTITION_DATA[@]}
  6647. # echo $temp_array
  6648. log_function_data "3-advanced: A_PARTITION_DATA:\n$temp_array"
  6649. eval $LOGFE
  6650. }
  6651.  
  6652. get_partition_data_advanced_bsd()
  6653. {
  6654. eval $LOGFS
  6655. local gpart_data="$( gpart list 2>/dev/null )"
  6656. local a_partition_working='' label_uuid='' dev_item=''
  6657.  
  6658. if [[ -n $gpart_data ]];then
  6659. for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
  6660. do
  6661. IFS=","
  6662. a_partition_working=( ${A_PARTITION_DATA[i]} )
  6663. IFS="$ORIGINAL_IFS"
  6664. # no need to use the rest of the name if it's not a straight /dev/item
  6665. dev_item=$( basename ${a_partition_working[6]} )
  6666.  
  6667. label_uuid=$( gawk -F ':' '
  6668. BEGIN {
  6669. IGNORECASE=1
  6670. label=""
  6671. uuid=""
  6672. }
  6673. /^[0-9]+\.[[:space:]]*Name.*'$dev_item'/ {
  6674. while ( getline && $1 !~ /^[0-9]+\.[[:space:]]*Name/ ) {
  6675. if ( $1 ~ /rawuuid/ ) {
  6676. gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
  6677. uuid=$2
  6678. }
  6679. if ( $1 ~ /label/ ) {
  6680. gsub(/^[[:space:]]+|[[:space:]]+$|none|\(null\)/,"",$2)
  6681. label=$2
  6682. }
  6683. }
  6684. print label","uuid
  6685. exit
  6686. }' <<< "$gpart_data" )
  6687.  
  6688. # assemble everything we could get for dev/h/dx, label, and uuid
  6689. IFS=","
  6690. A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","${a_partition_working[5]}","${a_partition_working[6]}","$label_uuid
  6691. IFS="$ORIGINAL_IFS"
  6692. done
  6693. fi
  6694. eval $LOGFE
  6695. }
  6696.  
  6697. # args: $1 - uuid/label/id/mapper
  6698. get_partition_dev_data()
  6699. {
  6700. eval $LOGFS
  6701.  
  6702. # only run these tests once per directory to avoid excessive queries to fs
  6703. case $1 in
  6704. id)
  6705. if [[ $B_ID_SET != 'true' ]];then
  6706. if [[ -d /dev/disk/by-id ]];then
  6707. DEV_DISK_ID="$( ls -l /dev/disk/by-id )"
  6708. fi
  6709. B_ID_SET='true'
  6710. fi
  6711. ;;
  6712. label)
  6713. if [[ $B_LABEL_SET != 'true' ]];then
  6714. if [[ -d /dev/disk/by-label ]];then
  6715. DEV_DISK_LABEL="$( ls -l /dev/disk/by-label )"
  6716. fi
  6717. B_LABEL_SET='true'
  6718. fi
  6719. ;;
  6720. mapper)
  6721. if [[ $B_MAPPER_SET != 'true' ]];then
  6722. if [[ -d /dev/mapper ]];then
  6723. DEV_DISK_MAPPER="$( ls -l /dev/mapper )"
  6724. fi
  6725. B_MAPPER_SET='true'
  6726. fi
  6727. ;;
  6728. uuid)
  6729. if [[ $B_UUID_SET != 'true' ]];then
  6730. if [[ -d /dev/disk/by-uuid ]];then
  6731. DEV_DISK_UUID="$( ls -l /dev/disk/by-uuid )"
  6732. fi
  6733. B_UUID_SET='true'
  6734. fi
  6735. ;;
  6736.  
  6737. esac
  6738. log_function_data 'raw' "DEV_DISK_LABEL:\n$DEV_DISK_LABEL\n\nDEV_DISK_UUID:\n$DEV_DISK_UUID\n\nDEV_DISK_ID:\n$DEV_DISK_ID\n\nDEV_DISK_MAPPER:\n$DEV_DISK_MAPPER"
  6739. # debugging section, uncomment to insert user data
  6740. # DEV_DISK_LABEL='
  6741. #
  6742. # '
  6743. # DEV_DISK_UUID='
  6744. #
  6745. # '
  6746. # DEV_DISK_MAPPER='
  6747. #
  6748. # '
  6749. eval $LOGFE
  6750. }
  6751.  
  6752. # args: $1 - dev item, check for mapper, then get actual dev item if mapped
  6753. # eg: lrwxrwxrwx 1 root root 7 Sep 26 15:10 truecrypt1 -> ../dm-2
  6754. get_dev_processed_item()
  6755. {
  6756. eval $LOGFS
  6757.  
  6758. local dev_item=$1 dev_return=''
  6759.  
  6760. if [[ -n $DEV_DISK_MAPPER && -n $( grep -is 'mapper/' <<< $dev_item ) ]];then
  6761. dev_return=$( echo "$DEV_DISK_MAPPER" | gawk '
  6762. $( NF - 2 ) ~ /^'$( basename $dev_item )'$/ {
  6763. item=gensub( /..\/(.+)/, "\\1", 1, $NF )
  6764. print item
  6765. }' )
  6766. fi
  6767. if [[ -z $dev_return ]];then
  6768. dev_return=$dev_item
  6769. fi
  6770.  
  6771. echo $dev_return
  6772.  
  6773. eval $LOGFE
  6774. }
  6775.  
  6776. get_patch_version_string()
  6777. {
  6778. local patch_version_number=$( sed 's/^[0]*//' <<< $SCRIPT_PATCH_NUMBER )
  6779.  
  6780. if [[ -n $patch_version_number ]];then
  6781. patch_version_number="-$patch_version_number"
  6782. # for cases where it was for example: 00-bsd cleaned to --bsd trim out one -
  6783. if [[ -n $( grep '\--' <<< $patch_version_number ) ]];then
  6784. patch_version_number=$( sed 's/--/-/' <<< $patch_version_number )
  6785. fi
  6786. fi
  6787. echo $patch_version_number
  6788. }
  6789.  
  6790. get_pciconf_data()
  6791. {
  6792. eval $LOGFS
  6793.  
  6794. local pciconf_data='' temp_array=''
  6795.  
  6796. if [[ $B_PCICONF == 'true' ]];then
  6797. pciconf_data="$( pciconf -lv 2>/dev/null )"
  6798. if [[ -n $pciconf_data ]];then
  6799. pciconf_data=$( gawk '
  6800. BEGIN {
  6801. IGNORECASE=1
  6802. }
  6803. {
  6804. gsub(/'"$BAN_LIST_NORMAL"'/, "", $0)
  6805. gsub(/[[:space:]]+=[[:space:]]+/, "=",$0)
  6806. gsub(/^[[:space:]]+|'"'"'|\"|,/, "", $0)
  6807. gsub(/=0x/,"=",$0)
  6808. # line=gensub(/.*[[:space:]]+(class=[^[:space:]]*|card=[^[:space:]]*)|chip=[^[:space:]]*|rev=[^[:space:]]*|hdr=[^[:space:]]*).*/,"\n\\1","g",$0)
  6809. line=gensub(/(.*@.*)/,"\n\\1",$0)
  6810. print line
  6811. }' <<< "$pciconf_data" )
  6812. # create empty last line with this spacing trick
  6813. pciconf_data="$pciconf_data
  6814.  
  6815. EOF"
  6816. # echo "$pciconf_data"
  6817. # now insert into arrays
  6818. IFS=$'\n'
  6819. A_PCICONF_DATA=( $( gawk '
  6820. BEGIN {
  6821. fullLine=""
  6822. driver=""
  6823. vendor=""
  6824. device=""
  6825. class=""
  6826. chipId=""
  6827. pciId=""
  6828. itemData=""
  6829. IGNORECASE=1
  6830. }
  6831. /^.*@/ {
  6832. pciId=""
  6833. vendor=""
  6834. class=""
  6835. driver=""
  6836. device=""
  6837. chipId=""
  6838. itemData=$1
  6839.  
  6840. driver=gensub(/^([^@]+)@.*/, "\\1", itemData )
  6841. pciId=gensub(/^.*@pci([0-9\.:]+).*/, "\\1", itemData )
  6842. sub(/:$/, "", pciId)
  6843. itemData=$4
  6844. chipId=gensub(/.*chip=([0-9a-f][0-9a-f][0-9a-f][0-9a-f])([0-9a-f][0-9a-f][0-9a-f][0-9a-f]).*/, "\\2:\\1", itemData )
  6845. if ( $2 == "class=020000" ) {
  6846. class="network"
  6847. }
  6848. else if ( $2 == "class=030000" ) {
  6849. class="display"
  6850. }
  6851. else if ( $2 == "class=040300" ) {
  6852. class="audio"
  6853. }
  6854.  
  6855. while ( getline && $1 !~ /^$/ ) {
  6856. if ( $1 ~ /^vendor/ ) {
  6857. sub(/^vendor=/, "", $1 )
  6858. vendor=$0
  6859. }
  6860. else if ( $1 ~ /^device/ ) {
  6861. sub(/^device=/, "", $1 )
  6862. device=$0
  6863. }
  6864. else if ( $1 ~ /^class=/ && class == "" ) {
  6865. sub(/^class=/, "", $1)
  6866. class=$0
  6867. }
  6868. }
  6869. if ( device == "" ) {
  6870. device=vendor
  6871. }
  6872.  
  6873. fullLine=class "," device "," vendor "," driver "," pciId "," chipId
  6874. print fullLine
  6875.  
  6876. }' <<< "$pciconf_data" ))
  6877. IFS="$ORIGINAL_IFS"
  6878. fi
  6879. else
  6880. A_PCICONF_DATA='pciconf-not-installed'
  6881. fi
  6882. B_PCICONF_SET='true'
  6883. temp_array=${A_PCICONF_DATA[@]}
  6884. log_function_data "$temp_array"
  6885. log_function_data "$pciconf_data"
  6886. eval $LOGFE
  6887. }
  6888.  
  6889. # packs standard card arrays using the pciconf stuff
  6890. # args: $1 - audio/network/display - matches first item in A_PCICONF_DATA arrays
  6891. get_pciconf_card_data()
  6892. {
  6893. eval $LOGFS
  6894. local a_temp='' array_string='' j=0 device_string=''
  6895. local ip_tool_command=$( type -p ifconfig )
  6896. local mac='' state='' speed='' duplex='' network_string=''
  6897.  
  6898. for (( i=0;i<${#A_PCICONF_DATA[@]};i++ ))
  6899. do
  6900. IFS=','
  6901. a_temp=( ${A_PCICONF_DATA[i]} )
  6902. IFS="$ORIGINAL_IFS"
  6903.  
  6904. if [[ ${a_temp[0]} == $1 ]];then
  6905. # don't print the vendor if it's already in the device name
  6906. if [[ -z $( grep -i "${a_temp[2]}" <<< "${a_temp[1]}" ) ]];then
  6907. device_string="${a_temp[2]} ${a_temp[1]}"
  6908. else
  6909. device_string=${a_temp[1]}
  6910. fi
  6911. case $1 in
  6912. audio)
  6913. array_string="$device_string,${a_temp[3]},,,${a_temp[4]},,${a_temp[5]}"
  6914. A_AUDIO_DATA[j]=$array_string
  6915. ;;
  6916. display)
  6917. array_string="$device_string,${a_temp[4]},${a_temp[5]}"
  6918. A_GFX_CARD_DATA[j]=$array_string
  6919. ;;
  6920. network)
  6921. if [[ -n $ip_tool_command && -n ${a_temp[3]} ]];then
  6922. network_string=$( $ip_tool_command ${a_temp[3]} | gawk '
  6923. BEGIN {
  6924. IGNORECASE=1
  6925. mac=""
  6926. state=""
  6927. speed=""
  6928. duplex=""
  6929. }
  6930. /^[[:space:]]*ether/ {
  6931. mac = $2
  6932. }
  6933. /^[[:space:]]*media/ {
  6934. if ( $0 ~ /<.*>/ ) {
  6935. duplex=gensub(/.*<([^>]+)>.*/,"\\1",$0)
  6936. }
  6937. if ( $0 ~ /\(.*\)/ ) {
  6938. speed=gensub(/.*\(([^<[:space:]]+).*\).*/,"\\1",$0)
  6939. }
  6940. }
  6941. /^[[:space:]]*status/ {
  6942. sub(/.*status[:]?[[:space:]]*/,"", $0)
  6943. state=$0
  6944. }
  6945. END {
  6946. print state "~" speed "~" mac "~" duplex
  6947. }')
  6948. fi
  6949. if [[ -n $network_string ]];then
  6950. mac=$( cut -d '~' -f 3 <<< $network_string )
  6951. state=$( cut -d '~' -f 1 <<< $network_string )
  6952. speed=$( cut -d '~' -f 2 <<< $network_string )
  6953. duplex=$( cut -d '~' -f 4 <<< $network_string )
  6954. fi
  6955. array_string="$device_string,${a_temp[3]},,,${a_temp[4]},${a_temp[3]},$state,$speed,$duplex,$mac,${a_temp[5]}"
  6956. A_NETWORK_DATA[j]=$array_string
  6957. ;;
  6958. esac
  6959. ((j++))
  6960. fi
  6961. done
  6962.  
  6963. eval $LOGFE
  6964. }
  6965.  
  6966. # args: $1 - type cpu/mem
  6967. get_ps_tcm_data()
  6968. {
  6969. eval $LOGFS
  6970. local array_length='' reorder_temp='' i=0 head_tail='' sort_type='' ps_data=''
  6971.  
  6972. # bummer, have to make it more complex here because of reverse sort
  6973. # orders in output, pesky lack of support of +rss in old systems
  6974. case $1 in
  6975. mem)
  6976. if [[ $BSD_TYPE != 'bsd' ]];then
  6977. sort_type='ps aux --sort -rss'
  6978. head_tail='head'
  6979. else
  6980. sort_type='ps aux -m'
  6981. head_tail='head'
  6982. fi
  6983. ;;
  6984. cpu)
  6985. if [[ $BSD_TYPE != 'bsd' ]];then
  6986. sort_type='ps aux --sort %cpu'
  6987. head_tail='tail'
  6988. else
  6989. sort_type='ps aux -r'
  6990. head_tail='head'
  6991. fi
  6992. ;;
  6993. esac
  6994.  
  6995. # throttle potential irc abuse
  6996. if [[ $B_RUNNING_IN_SHELL != 'true' && $PS_COUNT -gt 5 ]];then
  6997. PS_THROTTLED=$PS_COUNT
  6998. PS_COUNT=5
  6999. fi
  7000. # use eval here to avoid glitches with -
  7001. ps_data="$( eval $sort_type )"
  7002.  
  7003. IFS=$'\n'
  7004. # note that inxi can use a lot of cpu, and can actually show up here as the script runs
  7005. A_PS_DATA=( $( echo "$ps_data" | grep -Ev "($SCRIPT_NAME|%CPU|[[:space:]]ps[[:space:]])" | $head_tail -n $PS_COUNT | gawk '
  7006. BEGIN {
  7007. IGNORECASE=1
  7008. appName=""
  7009. appPath=""
  7010. appStarterName=""
  7011. appStarterPath=""
  7012. cpu=""
  7013. mem=""
  7014. pid=""
  7015. user=""
  7016. rss=""
  7017. }
  7018. {
  7019. cpu=$3
  7020. mem=$4
  7021. pid=$2
  7022. user=$1
  7023. rss=sprintf( "%.2f", $6/1024 )
  7024. # have to get rid of [,],(,) eg: [lockd] which break the printout function compare in bash
  7025. gsub(/\[|\]|\(|\)/,"~", $0 )
  7026. if ( $12 ~ /^\// ){
  7027. appStarterPath=$11
  7028. appPath=$12
  7029. }
  7030. else {
  7031. appStarterPath=$11
  7032. appPath=$11
  7033. }
  7034. appStarterName=gensub( /(\/.*\/)(.*)/, "\\2", "1", appStarterPath )
  7035. appName=gensub( /(\/.*\/)(.*)/, "\\2", "1", appPath )
  7036. print appName "," appPath "," appStarterName "," appStarterPath "," cpu "," mem "," pid "," rss "," user
  7037. }
  7038. ' ) )
  7039. # make the array ordered highest to lowest so output looks the way we expect it to
  7040. # this isn't necessary for -rss, and we can't make %cpu ordered the other way, so
  7041. # need to reverse it here. -rss is used because on older systems +rss is not supported
  7042. if [[ $1 == 'cpu' && $BSD_TYPE != 'bsd' ]];then
  7043. array_length=${#A_PS_DATA[@]};
  7044. while (( $i < $array_length/2 ))
  7045. do
  7046. reorder_temp=${A_PS_DATA[i]}f
  7047. A_PS_DATA[i]=${A_PS_DATA[$array_length-$i-1]}
  7048. A_PS_DATA[$array_length-$i-1]=$reorder_temp
  7049. (( i++ ))
  7050. done
  7051. fi
  7052.  
  7053. IFS="$ORIGINAL_IFS"
  7054.  
  7055. # echo ${A_PS_DATA[@]}
  7056. eval $LOGFE
  7057. }
  7058.  
  7059. # mdstat syntax information: http://www-01.ibm.com/support/docview.wss?uid=isg3T1011259
  7060. # note that this does NOT use either Disk or Partition information for now, ie, there
  7061. # is no connection between the data types, but the output should still be consistent
  7062. get_raid_data()
  7063. {
  7064. eval $LOGFS
  7065.  
  7066. local mdstat=''
  7067.  
  7068. if [[ $B_MDSTAT_FILE == 'true' ]];then
  7069. mdstat="$( cat $FILE_MDSTAT 2>/dev/null )"
  7070. fi
  7071.  
  7072. if [[ -n $mdstat ]];then
  7073. # need to make sure there's always a newline in front of each record type, and
  7074. # also correct possible weird formats for the output from older kernels etc.
  7075. mdstat="$( sed -e 's/^md/\nmd/' -e 's/^unused[[:space:]]/\nunused /' \
  7076. -e 's/read_ahead/\nread_ahead/' -e 's/^resync=/\nresync=/' -e 's/^Event/\nEvent/' \
  7077. -e 's/^[[:space:]]*$//' -e 's/[[:space:]]read_ahead/\nread_ahead/' <<< "$mdstat" )"
  7078. # some fringe cases do not end as expected, so need to add newlines plus EOF to make sure while loop doesn't spin
  7079. mdstat=$( echo -e "$mdstat\n\nEOF" )
  7080.  
  7081. IFS=$'\n'
  7082. A_RAID_DATA=( $(
  7083. gawk '
  7084. BEGIN {
  7085. IGNORECASE=1
  7086. RS="\n"
  7087. }
  7088.  
  7089. /^personalities/ {
  7090. KernelRaidSupport = gensub(/personalities[[:space:]]*:[[:space:]]*(.*)/, "\\1", 1, $0)
  7091. # clean off the brackets
  7092. gsub(/[\[\]]/,"",KernelRaidSupport)
  7093. print "KernelRaidSupport," KernelRaidSupport
  7094. }
  7095. /^read_ahead/ {
  7096. ReadAhead=gensub(/read_ahead (.*)/, "\\1", 1 )
  7097. print "ReadAhead," ReadAhead
  7098. }
  7099. /^Event:/ {
  7100. print "raidEvent," $NF
  7101. }
  7102. # print logic will search for this value and use it to print out the unused devices data
  7103. /^unused devices/ {
  7104. unusedDevices = gensub(/^unused devices:[[:space:]][<]?([^>]*)[>]?.*/, "\\1", 1, $0)
  7105. print "UnusedDevices," unusedDevices
  7106. }
  7107.  
  7108. /^md/ {
  7109. # reset for each record loop through
  7110. deviceState = ""
  7111. bitmapValues = ""
  7112. blocks = ""
  7113. chunkSize = ""
  7114. components = ""
  7115. device = ""
  7116. deviceReport = ""
  7117. finishTime = ""
  7118. recoverSpeed = ""
  7119. recoveryProgressBar = ""
  7120. recoveryPercent = ""
  7121. raidLevel = ""
  7122. sectorsRecovered = ""
  7123. separator = ""
  7124. superBlock = ""
  7125. uData = ""
  7126.  
  7127. while ( !/^[[:space:]]*$/ ) {
  7128. gsub(/,/, " ", $0 )
  7129. gsub(/[[:space:]]+/, " ", $0 )
  7130. if ( $0 ~ /^md/ ) {
  7131. device = gensub(/(md.*)[[:space:]]?:/, "\\1", "1", $1 )
  7132. }
  7133. if ( $0 ~ /mirror|raid[0-9]+/ ) {
  7134. raidLevel = gensub(/(.*)raid([0-9]+)(.*)/, "\\2", "g", $0 )
  7135. }
  7136. if ( $0 ~ /(active \(auto-read-only\)|active|inactive)/ ) {
  7137. deviceState = gensub(/(.*) (active \(auto-read-only\)|active|inactive) (.*)/, "\\2", "1", $0 )
  7138. }
  7139. # gawk will not return all the components using gensub, only last one
  7140. separator = ""
  7141. for ( i=3; i<=NF; i++ ) {
  7142. if ( $i ~ /[hs]d[a-z][0-9]*(\[[0-9]+\])?(\([SF]\))?/ ) {
  7143. components = components separator $i
  7144. separator=" "
  7145. }
  7146. }
  7147. if ( $0 ~ /blocks/ ) {
  7148. blocks = gensub(/(.*[[:space:]]+)?([0-9]+)[[:space:]]blocks.*/, "\\2", "1", $0)
  7149. }
  7150. if ( $0 ~ /super[[:space:]][0-9\.]+/ ) {
  7151. superBlock = gensub(/.*[[:space:]]super[[:space:]]([0-9\.]+)[[:space:]].*/, "\\1", "1", $0)
  7152. }
  7153. if ( $0 ~ /algorithm[[:space:]][0-9\.]+/ ) {
  7154. algorithm = gensub(/.*[[:space:]]algorithm[[:space:]]([0-9\.]+)[[:space:]].*/, "\\1", "1", $0)
  7155. }
  7156. if ( $0 ~ /\[[0-9]+\/[0-9]+\]/ ) {
  7157. deviceReport = gensub(/.*[[:space:]]\[([0-9]+\/[0-9]+)\][[:space:]].*/, "\\1", "1", $0)
  7158. uData = gensub(/.*[[:space:]]\[([U_]+)\]/, "\\1", "1", $0)
  7159. }
  7160. # need to avoid this: bitmap: 0/10 pages [0KB], 16384KB chunk
  7161. # while currently all the normal chunks are marked with k, not kb, this can change in the future
  7162. if ( $0 ~ /[0-9]+[k] chunk/ && $0 !~ /bitmap/ ) {
  7163. chunkSize = gensub(/(.*) ([0-9]+[k]) chunk.*/, "\\2", "1", $0)
  7164. }
  7165. if ( $0 ~ /^resync=/ ) {
  7166. sub(/resync=/,"")
  7167. print "resyncStatus," $0
  7168. }
  7169. if ( $0 ~ /\[[=]*>[\.]*\].*(resync|recovery)/ ) {
  7170. recoveryProgressBar = gensub(/.*(\[[=]*>[\.]*\]).*/, "\\1",1,$0)
  7171. }
  7172. if ( $0 ~ / (resync|recovery)[[:space:]]*=/ ) {
  7173. recoveryPercent = gensub(/.* (resync|recovery)[[:space:]]*=[[:space:]]*([0-9\.]+%).*/, "\\1~\\2", 1 )
  7174. if ( $0 ~ /[[:space:]]\([0-9]+\/[0-9]+\)/ ) {
  7175. sectorsRecovered = gensub(/.* \(([0-9]+\/[0-9]+)\).*/, "\\1", 1, $0 )
  7176. }
  7177. if ( $0 ~ /finish[[:space:]]*=/ ) {
  7178. finishTime = gensub(/.* finish[[:space:]]*=[[:space:]]*([[0-9\.]+)([a-z]+) .*/, "\\1 \\2", 1, $0 )
  7179. }
  7180. if ( $0 ~ /speed[[:space:]]*=/ ) {
  7181. recoverSpeed = gensub(/.* speed[[:space:]]*=[[:space:]]*([[0-9\.]+)([a-z]+\/[a-z]+)/, "\\1 \\2", 1, $0 )
  7182. }
  7183. }
  7184. if ( $0 ~ /bitmap/ ) {
  7185. bitmapValues = gensub(/(.*[[:space:]])?bitmap:(.*)/, "\\2", 1, $0 )
  7186. }
  7187.  
  7188. getline
  7189. }
  7190. raidString = device "," deviceState "," raidLevel "," components "," deviceReport "," uData
  7191. raidString = raidString "," blocks "," superBlock "," algorithm "," chunkSize "," bitmapValues
  7192. raidString = raidString "," recoveryProgressBar "," recoveryPercent "," sectorsRecovered "," finishTime "," recoverSpeed
  7193.  
  7194. print raidString
  7195. }
  7196. ' <<< "$mdstat" ) )
  7197. IFS="$ORIGINAL_IFS"
  7198. else
  7199. if [[ $BSD_TYPE == 'bsd' ]];then
  7200. get_raid_data_bsd
  7201. fi
  7202. fi
  7203. B_RAID_SET='true'
  7204. temp_array=${A_RAID_DATA[@]}
  7205. log_function_data "A_RAID_DATA: $temp_array"
  7206. # echo -e "A_RAID_DATA:\n${temp_array}"
  7207.  
  7208. eval $LOGFE
  7209. }
  7210.  
  7211. get_raid_data_bsd()
  7212. {
  7213. eval $LOGFS
  7214. local zpool_path=$( type -p zpool 2>/dev/null )
  7215. local zpool_data=''
  7216.  
  7217. if [[ -n $zpool_path ]];then
  7218. B_BSD_RAID='true'
  7219. # bsd sed does not support inserting a true \n so use this trick
  7220. zpool_data="$( $zpool_path list -v | sed $SED_RX 's/^([^[:space:]])/\
  7221. \1/' )"
  7222. # echo "$zpool_data"
  7223. IFS=$'\n'
  7224. A_RAID_DATA=( $(
  7225. gawk '
  7226. BEGIN {
  7227. raidString=""
  7228. separator=""
  7229. components=""
  7230. reportSize=""
  7231. blocksAvailable=""
  7232. chunkRaidAllocated=""
  7233. }
  7234. /SIZE.*ALLOC/ {
  7235. sub(/.*ALLOC.*/,"", $0)
  7236. }
  7237. /^[^[:space:]]/ {
  7238. components=""
  7239. separator=""
  7240. raidLevel=""
  7241. device=$1
  7242. deviceState=$7
  7243. reportSize=$2
  7244. blocksAvailable=$4
  7245. chunkRaidAllocated=$3
  7246.  
  7247. # go to the next line now, this will probably need fixing later with weird data sets
  7248. getline
  7249. if ( $1 != "" ) {
  7250. raidLevel="zfs " $1
  7251. }
  7252.  
  7253. while ( getline && $1 !~ /^$/ ) {
  7254. # print $1
  7255. components = components separator $1
  7256. separator=" "
  7257. }
  7258.  
  7259. # print $1
  7260. raidString = device "," deviceState "," raidLevel "," components "," reportSize "," uData
  7261. raidString = raidString "," blocksAvailable "," superBlock "," algorithm "," chunkRaidAllocated
  7262. # none of these are used currently
  7263. raidString = raidString "," bitmapValues "," recoveryProgressBar "," recoveryPercent
  7264. raidString = raidString "," sectorsRecovered "," finishTime "," recoverSpeed
  7265. gsub(/~/,"",raidString)
  7266. print raidString
  7267. }' <<< "$zpool_data" ) )
  7268. IFS="$ORIGINAL_IFS"
  7269. get_raid_component_data_bsd
  7270. fi
  7271. eval $LOGFE
  7272. }
  7273.  
  7274. # note, we've already tested for zpool so no further tests required
  7275. get_raid_component_data_bsd()
  7276. {
  7277. eval $LOGFS
  7278. local a_raid_data='' array_string='' component='' component_string=''
  7279. local zpool_status='' device='' separator='' component_status=''
  7280.  
  7281. for (( i=0; i<${#A_RAID_DATA[@]}; i++))
  7282. do
  7283. IFS=","
  7284. a_raid_data=( ${A_RAID_DATA[i]} )
  7285. IFS="$ORIGINAL_IFS"
  7286. separator=''
  7287. component_string=''
  7288. component_status=''
  7289. zpool_status=''
  7290. device=${a_raid_data[0]}
  7291. zpool_status="$( zpool status $device )"
  7292. # we will remove ONLINE for status and only use OFFLINE/DEGRADED as tests
  7293. # for print output display of issues with components
  7294. for component in ${a_raid_data[3]}
  7295. do
  7296. component_status=$( gawk '
  7297. BEGIN {
  7298. IGNORECASE=1
  7299. }
  7300. $1 ~ /^'$component'$/ {
  7301. sub( /ONLINE/, "", $2 )
  7302. print "'$component'" $2
  7303. exit
  7304. }' <<< "$zpool_status" )
  7305. component_string="$component_string$separator$component_status"
  7306. separator=' '
  7307. done
  7308. array_string="$device,${a_raid_data[1]},${a_raid_data[2]},$component_string,${a_raid_data[4]}"
  7309. array_string="$array_string,${a_raid_data[5]},${a_raid_data[6]},${a_raid_data[7]},${a_raid_data[8]}"
  7310. array_string="$array_string,${a_raid_data[9]},${a_raid_data[10]},${a_raid_data[11]},${a_raid_data[12]},"
  7311. array_string="$array_string${a_raid_data[13]},${a_raid_data[14]},${a_raid_data[15]}"
  7312. IFS=","
  7313. A_RAID_DATA[i]=$array_string
  7314. IFS="$ORIGINAL_IFS"
  7315. done
  7316.  
  7317. eval $LOGFE
  7318. }
  7319. # get_raid_data_bsd;exit
  7320.  
  7321. # Repos will be added as we get distro package manager data to create the repo data.
  7322. # This method will output the file name also, which is useful to create output that's
  7323. # neat and readable. Each line of the total number contains the following sections,
  7324. # separated by a : for splitting in the print function
  7325. # part one, repo type/string : part two, file name, if present, of info : part 3, repo data
  7326. get_repo_data()
  7327. {
  7328. eval $LOGFS
  7329. local repo_file='' repo_data_working='' repo_data_working2='' repo_line='' repo_files=''
  7330. local repo_name=''
  7331. local apt_file='/etc/apt/sources.list' yum_repo_dir='/etc/yum.repos.d/' yum_conf='/etc/yum.conf'
  7332. local pacman_conf='/etc/pacman.conf' pacman_repo_dir='/etc/pacman.d/' pisi_dir='/etc/pisi/'
  7333. local zypp_repo_dir='/etc/zypp/repos.d/' freebsd_conf='/etc/portsnap.conf'
  7334.  
  7335. # apt - debian, buntus, also sometimes some yum/rpm repos may create apt repos here as well
  7336. if [[ -f $apt_file || -d $apt_file.d ]];then
  7337. REPO_DATA="$( grep -Esv '(^[[:space:]]*$|^[[:space:]]*#)' $apt_file $apt_file.d/*.list | sed $SED_RX 's/^(.*)/apt sources:\1/' )"
  7338. fi
  7339. # yum - fedora, redhat, centos, etc. Note that rpmforge also may create apt sources
  7340. # in /etc/apt/sources.list.d/. Therefore rather than trying to assume what package manager is
  7341. # actually running, inxi will merely note the existence of each repo type for apt/yum.
  7342. # Also, in rpm, you can install apt-rpm for the apt-get command, so it's not good to check for
  7343. # only the commands in terms of selecting which repos to show.
  7344. if [[ -d $yum_repo_dir || -f $yum_conf || -d $zypp_repo_dir ]];then
  7345. if [[ -d $yum_repo_dir || -f $yum_conf ]];then
  7346. # older redhats put their yum data in /etc/yum.conf
  7347. repo_files=$( ls $yum_repo_dir*.repo $yum_conf 2>/dev/null )
  7348. repo_name='yum'
  7349. elif [[ -d $zypp_repo_dir ]];then
  7350. repo_files=$( ls $zypp_repo_dir*.repo 2>/dev/null )
  7351. repo_name='zypp'
  7352. fi
  7353. if [[ -n $repo_files ]];then
  7354. for repo_file in $repo_files
  7355. do
  7356. repo_data_working="$( gawk -v repoFile=$repo_file '
  7357. # construct the string for the print function to work with, file name: data
  7358. function print_line( fileName, repoId, repoUrl ){
  7359. print "'$repo_name' sources:" fileName ":" repoId repoUrl
  7360. }
  7361. BEGIN {
  7362. FS="\n"
  7363. IGNORECASE=1
  7364. enabledStatus=""
  7365. repoTitle=""
  7366. urlData=""
  7367. }
  7368. # this is a hack, assuming that each item has these fields listed, we collect the 3
  7369. # items one by one, then when the url/enabled fields are set, we print it out and
  7370. # reset the data. Not elegant but it works. Note that if enabled was not present
  7371. # we assume it is enabled then, and print the line, reset the variables. This will
  7372. # miss the last item, so it is printed if found in END
  7373. /^\[.+\]/ {
  7374. if ( urlData != "" && repoTitle != "" ){
  7375. print_line( repoFile, repoTitle, urlData )
  7376. enabledStatus=""
  7377. urlData=""
  7378. repoTitle=""
  7379. }
  7380. gsub( /\[|\]/, "", $1 ) # strip out the brackets
  7381. repoTitle = $1 " ~ "
  7382. }
  7383. /^(mirrorlist|baseurl)/ {
  7384. sub( /(mirrorlist|baseurl)[[:space:]]*=[[:space:]]*/, "", $1 ) # strip out the field starter
  7385. urlData = $1
  7386. }
  7387. # note: enabled = 1. enabled = 0 means disabled
  7388. /^enabled[[:space:]]*=/ {
  7389. enabledStatus = $1
  7390. }
  7391. # print out the line if all 3 values are found, otherwise if a new
  7392. # repoTitle is hit above, it will print out the line there instead
  7393. {
  7394. if ( urlData != "" && enabledStatus != "" && repoTitle != "" ){
  7395. if ( enabledStatus !~ /enabled[[:space:]]*=[[:space:]]*0/ ){
  7396. print_line( repoFile, repoTitle, urlData )
  7397. }
  7398. enabledStatus=""
  7399. urlData=""
  7400. repoTitle=""
  7401. }
  7402. }
  7403. END {
  7404. # print the last one if there is data for it
  7405. if ( urlData != "" && repoTitle != "" ){
  7406. print_line( repoFile, repoTitle, urlData )
  7407. }
  7408. }
  7409. ' $repo_file )"
  7410.  
  7411. # then load the global for each file as it gets filled
  7412. if [[ -n $repo_data_working ]];then
  7413. if [[ -z $REPO_DATA ]];then
  7414. REPO_DATA="$repo_data_working"
  7415. else
  7416. REPO_DATA="$REPO_DATA
  7417. $repo_data_working"
  7418. fi
  7419. repo_data_working=''
  7420. fi
  7421. done
  7422. fi
  7423. # pacman - archlinux, going to assume that pisi and arch/pacman, etc don't have the above issue with apt/yum
  7424. elif [[ -f $pacman_conf ]];then
  7425. # get list of mirror include files, trim white space off ends
  7426. repo_data_working="$( gawk '
  7427. BEGIN {
  7428. FS="="
  7429. IGNORECASE=1
  7430. }
  7431. /^[[:space:]]*Include/ {
  7432. sub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
  7433. print $2
  7434. }
  7435. ' $pacman_conf )"
  7436. # sort into unique paths only, to be used to search for server = data
  7437. repo_data_working=$( sort -bu <<< "$repo_data_working" | uniq )
  7438. repo_data_working="$repo_data_working $pacman_conf"
  7439. for repo_file in $repo_data_working
  7440. do
  7441. if [[ -f $repo_file ]];then
  7442. # inserting a new line after each found / processed match
  7443. repo_data_working2="$repo_data_working2$( gawk -v repoFile=$repo_file '
  7444. BEGIN {
  7445. FS="="
  7446. IGNORECASE=1
  7447. }
  7448. /^[[:space:]]*Server/ {
  7449. sub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
  7450. print "pacman repo servers:" repoFile ":" $2 "\\n"
  7451. }
  7452. ' $repo_file )"
  7453. else
  7454. echo "Error: file listed in $pacman_conf does not exist - $repo_file"
  7455. fi
  7456. done
  7457. # execute line breaks
  7458. REPO_DATA="$( echo -e $repo_data_working2 )"
  7459. # pisi - pardus
  7460. elif [[ -d $pisi_dir && -n $( type -p pisi ) ]];then
  7461. REPO_DATA="$( pisi list-repo )"
  7462. # now we need to create the structure: repo info: repo path
  7463. # we do that by looping through the lines of the output and then
  7464. # putting it back into the <data>:<url> format print repos expects to see
  7465. # note this structure in the data, so store first line and make start of line
  7466. # then when it's an http line, add it, and create the full line collection.
  7467. # Pardus-2009.1 [Aktiv]
  7468. # http://packages.pardus.org.tr/pardus-2009.1/pisi-index.xml.bz2
  7469. # Contrib [Aktiv]
  7470. # http://packages.pardus.org.tr/contrib-2009/pisi-index.xml.bz2
  7471. while read repo_line
  7472. do
  7473. repo_line=$( gawk '
  7474. {
  7475. # need to dump leading/trailing spaces and clear out color codes for irc output
  7476. sub(/^[[:space:]]+|[[:space:]]+$/,"",$0)
  7477. # gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/,"",$0) # leaving this pattern in case need it
  7478. gsub(/\[([0-9];)?[0-9]+m/,"",$0)
  7479. print $0
  7480. }' <<< $repo_line )
  7481. if [[ -n $( grep '://' <<< $repo_line ) ]];then
  7482. repo_data_working="$repo_data_working:$repo_line\n"
  7483. else
  7484. repo_data_working="${repo_data_working}pisi repo:$repo_line"
  7485. fi
  7486. done <<< "$REPO_DATA"
  7487. # echo and execute the line breaks inserted
  7488. REPO_DATA="$( echo -e $repo_data_working )"
  7489. # Mandriva/Mageia using: urpmq
  7490. elif [[ -n $( type -p urpmq ) ]];then
  7491. REPO_DATA="$( urpmq --list-media active --list-url )"
  7492. # now we need to create the structure: repo info: repo path
  7493. # we do that by looping through the lines of the output and then
  7494. # putting it back into the <data>:<url> format print repos expects to see
  7495. # note this structure in the data, so store first line and make start of line
  7496. # then when it's an http line, add it, and create the full line collection.
  7497. # Contrib ftp://ftp.uwsg.indiana.edu/linux/mandrake/official/2011/x86_64/media/contrib/release
  7498. # Contrib Updates ftp://ftp.uwsg.indiana.edu/linux/mandrake/official/2011/x86_64/media/contrib/updates
  7499. # Non-free ftp://ftp.uwsg.indiana.edu/linux/mandrake/official/2011/x86_64/media/non-free/release
  7500. # Non-free Updates ftp://ftp.uwsg.indiana.edu/linux/mandrake/official/2011/x86_64/media/non-free/updates
  7501. # Nonfree Updates (Local19) /mnt/data/mirrors/mageia/distrib/cauldron/x86_64/media/nonfree/updates
  7502. while read repo_line
  7503. do
  7504. repo_line=$( gawk '
  7505. {
  7506. # need to dump leading/trailing spaces and clear out color codes for irc output
  7507. sub(/^[[:space:]]+|[[:space:]]+$/,"",$0)
  7508. # gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/,"",$0) # leaving this pattern in case need it
  7509. gsub(/\[([0-9];)?[0-9]+m/,"",$0)
  7510. print $0
  7511. }' <<< $repo_line )
  7512. # urpmq output is the same each line, repo name space repo url, can be:
  7513. # rsync://, ftp://, file://, http:// OR repo is locally mounted on FS in some cases
  7514. if [[ -n $( grep -E '(://|[[:space:]]/)' <<< $repo_line ) ]];then
  7515. # cut out the repo first
  7516. repo_data_working2=$( grep -Eo '([^[:space:]]+://|[[:space:]]/).*' <<< $repo_line )
  7517. # then get the repo name string by slicing out the url string
  7518. repo_name=$( sed "s|[[:space:]]*$repo_data_working2||" <<< $repo_line )
  7519. repo_data_working="${repo_data_working}urpmq repo:$repo_name:$repo_data_working2\n"
  7520. fi
  7521. done <<< "$REPO_DATA"
  7522. # echo and execute the line breaks inserted
  7523. REPO_DATA="$( echo -e $repo_data_working )"
  7524. elif [[ -f $freebsd_conf ]];then
  7525. REPO_DATA="$( gawk -F '=' -v repoFile=$freebsd_conf '
  7526. BEGIN {
  7527. IGNORECASE=1
  7528. }
  7529. /^SERVERNAME/ {
  7530. print "BSD ports servers:" repoFile ":" $2
  7531. }
  7532. ' $freebsd_conf )"
  7533. fi
  7534. eval $LOGFE
  7535. }
  7536.  
  7537. get_runlevel_data()
  7538. {
  7539. eval $LOGFS
  7540. local runlvl=''
  7541. local runlevel_path=$( type -p runlevel )
  7542. if [[ -n $runlevel_path ]];then
  7543. runlvl="$( $runlevel_path | gawk '{ print $2 }' )"
  7544. fi
  7545. echo $runlvl
  7546. eval $LOGFE
  7547. }
  7548.  
  7549. get_sensors_data()
  7550. {
  7551. eval $LOGFS
  7552.  
  7553.  
  7554. local temp_array=''
  7555.  
  7556. IFS=$'\n'
  7557. if [[ -n $Sensors_Data ]];then
  7558. # note: non-configured sensors gives error message, which we need to redirect to stdout
  7559. # also, -F ':' no space, since some cases have the data starting right after,like - :1287
  7560. A_SENSORS_DATA=( $(
  7561. gawk -F ':' -v userCpuNo="$SENSORS_CPU_NO" '
  7562. BEGIN {
  7563. IGNORECASE=1
  7564. core0Temp="" # only if all else fails...
  7565. cpuTemp=""
  7566. cpuTempReal=""
  7567. fanWorking=""
  7568. indexCountaFanMain=0
  7569. indexCountaFanDefault=0
  7570. i=""
  7571. j=""
  7572. moboTemp=""
  7573. moboTempReal=""
  7574. psuTemp=""
  7575. separator=""
  7576. sysFanString=""
  7577. temp1=""
  7578. temp2=""
  7579. tempFanType="" # set to 1 or 2
  7580. tempUnit=""
  7581. tempWorking=""
  7582. tempWorkingUnit=""
  7583. }
  7584. # new data arriving: gpu temp in sensors, have to skip that
  7585. /^('"$SENSORS_GPU_SEARCH"')-pci/ {
  7586. while ( getline && !/^$/ ) {
  7587. # do nothing, just skip it
  7588. }
  7589. }
  7590. # dumping the extra + signs after testing for them, nobody has negative temps.
  7591. # also, note gawk treats ° as a space, so we have to get the C/F data
  7592. # there are some guesses here, but with more sensors samples it will get closer.
  7593. # note: using arrays starting at 1 for all fan arrays to make it easier overall
  7594. # more validation because gensub if fails to get match returns full string, so
  7595. # we have to be sure we are working with the actual real string before assiging
  7596. # data to real variables and arrays. Extracting C/F degree unit as well to use
  7597. # when constructing temp items for array.
  7598. # note that because of charset issues, no tempUnit="°" tempWorkingUnit degree sign
  7599. # used, but it is required in testing regex to avoid error.
  7600. /^(M\/B|MB|SIO|SYS)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
  7601. moboTemp=gensub( /[ \t]+\+([0-9\.]*)(.*)/, "\\1", 1, $2 )
  7602. tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
  7603. if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
  7604. tempUnit=tempWorkingUnit
  7605. }
  7606. }
  7607. /^CPU(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
  7608. cpuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
  7609. tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
  7610. if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
  7611. tempUnit=tempWorkingUnit
  7612. }
  7613. }
  7614. /^(P\/S|Power)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
  7615. psuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
  7616. tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
  7617. if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
  7618. tempUnit=tempWorkingUnit
  7619. }
  7620. }
  7621. $1 ~ /^temp1$/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
  7622. tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
  7623. if ( temp1 == "" || tempWorking > 0 ) {
  7624. temp1=tempWorking
  7625. }
  7626. tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
  7627. if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
  7628. tempUnit=tempWorkingUnit
  7629. }
  7630. }
  7631. $1 ~ /^temp2$/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
  7632. tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
  7633. if ( temp2 == "" || tempWorking > 0 ) {
  7634. temp2=tempWorking
  7635. }
  7636. tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
  7637. if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
  7638. tempUnit=tempWorkingUnit
  7639. }
  7640. }
  7641.  
  7642. # final fallback if all else fails, funtoo user showed sensors putting
  7643. # temp on wrapped second line, not handled
  7644. /^(core0|core 0)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
  7645. tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
  7646. if ( core0Temp == "" || tempWorking > 0 ) {
  7647. core0Temp=tempWorking
  7648. }
  7649. tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
  7650. if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
  7651. tempUnit=tempWorkingUnit
  7652. }
  7653. }
  7654.  
  7655. # note: can be cpu fan:, cpu fan speed:, etc. Some cases have no space before
  7656. # $2 starts (like so :1234 RPM), so skip that space test in regex
  7657. /^CPU(.*)[ \t]*([0-9]+)[ \t]RPM/ {
  7658. aFanMain[1]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
  7659. }
  7660. /^(M\/B|MB|SYS)(.*)[ \t]*([0-9]+)[ \t]RPM/ {
  7661. aFanMain[2]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
  7662. }
  7663. /(Power|P\/S|POWER)(.*)[ \t]*([0-9]+)[ \t]RPM/ {
  7664. aFanMain[3]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
  7665. }
  7666. # note that the counters are dynamically set for fan numbers here
  7667. # otherwise you could overwrite eg aux fan2 with case fan2 in theory
  7668. # note: cpu/mobo/ps are 1/2/3
  7669. # NOTE: test: ! i in array does NOT work, this appears to be an awk/gawk bug
  7670. /^(AUX(1)? |CASE(1)? |CHASSIS(1)? )(.*)[ \t]*([0-9]+)[ \t]RPM/ {
  7671. for ( i = 4; i < 7; i++ ){
  7672. if ( i in aFanMain ){
  7673. ##
  7674. }
  7675. else {
  7676. aFanMain[i]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
  7677. break
  7678. }
  7679. }
  7680. }
  7681. /^(AUX([2-9]) |CASE([2-9]) |CHASSIS([2-9]) )(.*)[ \t]*([0-9]+)[ \t]RPM/ {
  7682. for ( i = 5; i < 30; i++ ){
  7683. if ( i in aFanMain ) {
  7684. ##
  7685. }
  7686. else {
  7687. sysFanNu = i
  7688. aFanMain[i]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
  7689. break
  7690. }
  7691. }
  7692. }
  7693. # in rare cases syntax is like: fan1: xxx RPM
  7694. /^(FAN(1)?[ \t:])(.*)[ \t]*([0-9]+)[ \t]RPM/ {
  7695. aFanDefault[1]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
  7696. }
  7697. /^FAN([2-9]|1[0-9])(.*)[ \t]*([0-9]+)[ \t]RPM/ {
  7698. fanWorking=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
  7699. sysFanNu=gensub( /fan([0-9]+)/, "\\1", 1, $1 )
  7700. if ( sysFanNu ~ /^([0-9]+)$/ ) {
  7701. # add to array if array index does not exist OR if number is > existing number
  7702. if ( sysFanNu in aFanDefault ) {
  7703. if ( fanWorking >= aFanDefault[sysFanNu] ) {
  7704. aFanDefault[sysFanNu]=fanWorking
  7705. }
  7706. }
  7707. else {
  7708. aFanDefault[sysFanNu]=fanWorking
  7709. }
  7710. }
  7711. }
  7712.  
  7713. END {
  7714. # first we need to handle the case where we have to determine which temp/fan to use for cpu and mobo:
  7715. # note, for rare cases of weird cool cpus, user can override in their prefs and force the assignment
  7716. if ( temp1 != "" && temp2 != "" ){
  7717. if ( userCpuNo != "" && userCpuNo ~ /(1|2)/ ) {
  7718. tempFanType=userCpuNo
  7719. }
  7720. else {
  7721. # first some fringe cases with cooler cpu than mobo: assume which is cpu temp based on fan speed
  7722. # but only if other fan speed is 0
  7723. if ( temp1 >= temp2 && 1 in aFanDefault && 2 in aFanDefault && aFanDefault[1] == 0 && aFanDefault[2] > 0 ) {
  7724. tempFanType=2
  7725. }
  7726. else if ( temp2 >= temp1 && 1 in aFanDefault && 2 in aFanDefault && aFanDefault[2] == 0 && aFanDefault[1] > 0 ) {
  7727. tempFanType=1
  7728. }
  7729. # then handle the standard case if these fringe cases are false
  7730. else if ( temp1 >= temp2 ) {
  7731. tempFanType=1
  7732. }
  7733. else {
  7734. tempFanType=2
  7735. }
  7736. }
  7737. }
  7738. # need a case for no temps at all reported, like with old intels
  7739. else if ( temp2 == "" && cpuTemp == "" ){
  7740. if ( temp1 == "" && moboTemp == "" ){
  7741. tempFanType=1
  7742. }
  7743. else if ( temp1 != "" && moboTemp == "" ){
  7744. tempFanType=1
  7745. }
  7746. else if ( temp1 != "" && moboTemp != "" ){
  7747. tempFanType=1
  7748. }
  7749. }
  7750.  
  7751. # then get the real cpu temp, best guess is hottest is real
  7752. if ( cpuTemp != "" ){
  7753. cpuTempReal=cpuTemp
  7754. }
  7755. else if ( tempFanType != "" ){
  7756. if ( tempFanType == 1 ){
  7757. cpuTempReal=temp1
  7758. }
  7759. else {
  7760. cpuTempReal=temp2
  7761. }
  7762. }
  7763. else {
  7764. cpuTempReal=temp1
  7765. }
  7766. # if all else fails, use core0 temp if it is present and cpu is null
  7767. if ( cpuTempReal == "" && core0Temp != "" ) {
  7768. cpuTempReal=core0Temp
  7769. }
  7770.  
  7771. # then the real mobo temp
  7772. if ( moboTemp != "" ){
  7773. moboTempReal=moboTemp
  7774. }
  7775. else if ( tempFanType != "" ){
  7776. if ( tempFanType == 1 ) {
  7777. moboTempReal=temp2
  7778. }
  7779. else {
  7780. moboTempReal=temp1
  7781. }
  7782. }
  7783. else {
  7784. moboTempReal=temp2
  7785. }
  7786. # then set the cpu fan speed
  7787. if ( aFanMain[1] == "" ) {
  7788. # note, you cannot test for aFanDefault[1] or [2] != ""
  7789. # because that creates an array item in gawk just by the test itself
  7790. if ( tempFanType == 1 && 1 in aFanDefault ) {
  7791. aFanMain[1]=aFanDefault[1]
  7792. aFanDefault[1]=""
  7793. }
  7794. else if ( tempFanType == 2 && 2 in aFanDefault ) {
  7795. aFanMain[1]=aFanDefault[2]
  7796. aFanDefault[2]=""
  7797. }
  7798. }
  7799.  
  7800. # then we need to get the actual numeric max array count for both fan arrays
  7801. for (i = 0; i <= 29; i++) {
  7802. if ( i in aFanMain && i > indexCountaFanMain ) {
  7803. indexCountaFanMain=i
  7804. }
  7805. }
  7806. for (i = 0; i <= 14; i++) {
  7807. if ( i in aFanDefault && i > indexCountaFanDefault ) {
  7808. indexCountaFanDefault=i
  7809. }
  7810. }
  7811.  
  7812. # clear out any duplicates. Primary fan real trumps fan working always if same speed
  7813. for (i = 1; i <= indexCountaFanMain; i++) {
  7814. if ( i in aFanMain && aFanMain[i] != "" && aFanMain[i] != 0 ) {
  7815. for (j = 1; j <= indexCountaFanDefault; j++) {
  7816. if ( j in aFanDefault && aFanMain[i] == aFanDefault[j] ) {
  7817. aFanDefault[j] = ""
  7818. }
  7819. }
  7820. }
  7821. }
  7822.  
  7823. # now see if you can find the fast little mobo fan, > 5000 rpm and put it as mobo
  7824. # note that gawk is returning true for some test cases when aFanDefault[j] < 5000
  7825. # which has to be a gawk bug, unless there is something really weird with arrays
  7826. # note: 500 > aFanDefault[j] < 1000 is the exact trigger, and if you manually
  7827. # assign that value below, the > 5000 test works again, and a print of the value
  7828. # shows the proper value, so the corruption might be internal in awk.
  7829. # Note: gensub is the culprit I think, assigning type string for range 501-1000 but
  7830. # type integer for all others, this triggers true for >
  7831. for (j = 1; j <= indexCountaFanDefault; j++) {
  7832. if ( j in aFanDefault && int( aFanDefault[j] ) > 5000 && aFanMain[2] == "" ) {
  7833. aFanMain[2] = aFanDefault[j]
  7834. aFanDefault[j] = ""
  7835. # then add one if required for output
  7836. if ( indexCountaFanMain < 2 ) {
  7837. indexCountaFanMain = 2
  7838. }
  7839. }
  7840. }
  7841.  
  7842. # then construct the sys_fan string for echo, note that iteration 1
  7843. # makes: fanDefaultString separator null, ie, no space or ,
  7844. for (j = 1; j <= indexCountaFanDefault; j++) {
  7845. fanDefaultString = fanDefaultString separator aFanDefault[j]
  7846. separator=","
  7847. }
  7848. separator="" # reset to null for next loop
  7849. # then construct the sys_fan string for echo
  7850. for (j = 1; j <= indexCountaFanMain; j++) {
  7851. fanMainString = fanMainString separator aFanMain[j]
  7852. separator=","
  7853. }
  7854.  
  7855. # and then build the temps:
  7856. if ( moboTempReal != "" ) {
  7857. moboTempReal = moboTempReal tempUnit
  7858. }
  7859. if ( cpuTempReal != "" ) {
  7860. cpuTempReal = cpuTempReal tempUnit
  7861. }
  7862.  
  7863. # if they are ALL null, print error message. psFan is not used in output currently
  7864. if ( cpuTempReal == "" && moboTempReal == "" && aFanMain[1] == "" && aFanMain[2] == "" && aFanMain[3] == "" && fanDefaultString == "" ) {
  7865. print "No active sensors found. Have you configured your sensors yet?"
  7866. }
  7867. else {
  7868. # then build array arrays:
  7869. print cpuTempReal "," moboTempReal "," psuTemp
  7870. # this is for output, a null print line does NOT create a new array index in bash
  7871. if ( fanMainString == "" ) {
  7872. fanMainString=","
  7873. }
  7874. print fanMainString
  7875. print fanDefaultString
  7876. }
  7877. }' <<< "$Sensors_Data" ) )
  7878. fi
  7879.  
  7880. IFS="$ORIGINAL_IFS"
  7881. temp_array=${A_SENSORS_DATA[@]}
  7882. log_function_data "A_SENSORS_DATA: $temp_array"
  7883. # echo "A_SENSORS_DATA: ${A_SENSORS_DATA[@]}"
  7884. eval $LOGFE
  7885. }
  7886.  
  7887. get_sensors_output()
  7888. {
  7889. local sensors_path=$( type -p sensors ) sensors_data=''
  7890.  
  7891. if [[ -n $sensors_path ]];then
  7892. sensors_data="$( $sensors_path 2>/dev/null )"
  7893. if [[ -n "$sensors_data" ]];then
  7894. # make sure the file ends in newlines then characters, the newlines are lost in the echo unless
  7895. # the data ends in some characters
  7896. sensors_data="$sensors_data\n\n###"
  7897. fi
  7898. fi
  7899. echo -e "$sensors_data"
  7900. }
  7901.  
  7902. get_shell_data()
  7903. {
  7904. eval $LOGFS
  7905.  
  7906. local shell_type="$( ps -p $PPID -o comm= 2>/dev/null )"
  7907. local shell_version=''
  7908.  
  7909. if [[ $B_EXTRA_DATA == 'true' && -n $shell_type ]];then
  7910. case $shell_type in
  7911. bash)
  7912. shell_version=$( get_de_app_version "$shell_type" "^GNU[[:space:]]bash,[[:space:]]version" "4" | \
  7913. sed $SED_RX 's/(\(.*|-release|-version)//' )
  7914. ;;
  7915. # csh/dash use dpkg package version data, debian/buntu only
  7916. csh)
  7917. shell_version=$( get_de_app_version "$shell_type" "^tcsh" "2" )
  7918. ;;
  7919. dash)
  7920. shell_version=$( get_de_app_version "$shell_type" "$shell_type" "3" )
  7921. ;;
  7922. ksh)
  7923. shell_version=$( get_de_app_version "$shell_type" "version" "5" )
  7924. ;;
  7925. tcsh)
  7926. shell_version=$( get_de_app_version "$shell_type" "^tcsh" "2" )
  7927. ;;
  7928. zsh)
  7929. shell_version=$( get_de_app_version "$shell_type" "^zsh" "2" )
  7930. ;;
  7931. esac
  7932. fi
  7933. if [[ -n $shell_version ]];then
  7934. shell_type="$shell_type $shell_version"
  7935. fi
  7936. echo $shell_type
  7937.  
  7938. eval $LOGFS
  7939. }
  7940.  
  7941. get_shell_parent()
  7942. {
  7943. eval $LOGFS
  7944. local shell_parent='' script_parent=''
  7945.  
  7946. # removed --no-headers to make bsd safe, adding in -j to make output the same
  7947. script_parent=$( ps -j -fp $PPID 2>/dev/null | gawk '/'"$PPID"'/ { print $3 }' )
  7948. log_function_data "script parent: $script_parent"
  7949. shell_parent=$( ps -j -p $script_parent 2>/dev/null | gawk '/'"$script_parent"'/ { print $NF}' )
  7950. # no idea why have to do script_parent action twice in su case, but you do, oh well.
  7951. if [[ $shell_parent == 'su' ]];then
  7952. script_parent=$( ps -j -fp $script_parent 2>/dev/null | gawk '/'"$script_parent"'/ { print $3 }' )
  7953. script_parent=$( ps -j -fp $script_parent 2>/dev/null | gawk '/'"$script_parent"'/ { print $3 }' )
  7954. shell_parent=$( ps -j -p $script_parent 2>/dev/null | gawk '/'"$script_parent"'/ { print $NF}' )
  7955. fi
  7956. echo $shell_parent
  7957. log_function_data "shell parent final: $shell_parent"
  7958. eval $LOGFE
  7959. }
  7960.  
  7961. # this will be used for some bsd data types
  7962. # args: $1 - option type
  7963. get_sysctl_data()
  7964. {
  7965. eval $LOGFS
  7966.  
  7967. local sysctl_data=''
  7968.  
  7969. if [[ $B_SYSCTL ]];then
  7970. sysctl_data="$( sysctl -$1 )"
  7971. fi
  7972. # log_function_data "sysctl_data: $sysctl_data"
  7973. echo "$sysctl_data"
  7974. eval $LOGFE
  7975. }
  7976.  
  7977. get_tty_console_irc()
  7978. {
  7979. eval $LOGFS
  7980. local tty_number=''
  7981. if [[ -n ${IRC_CLIENT} ]];then
  7982. tty_number=$( gawk '
  7983. BEGIN {
  7984. IGNORECASE=1
  7985. }
  7986. # if multiple irc clients open, can give wrong results
  7987. # so make sure to also use the PPID number to get the right tty
  7988. /.*'$PPID'.*'${IRC_CLIENT}'/ {
  7989. gsub(/[^0-9]/, "", $7)
  7990. print $7
  7991. exit
  7992. }' <<< "$Ps_aux_Data" )
  7993. fi
  7994. log_function_data "tty_number: $tty_number"
  7995. echo $tty_number
  7996. eval $LOGFE
  7997. }
  7998.  
  7999. get_tty_number()
  8000. {
  8001. eval $LOGFS
  8002.  
  8003. local tty_number=$( basename "$( tty 2>/dev/null )" | sed 's/[^0-9]*//g' )
  8004.  
  8005. echo $tty_number
  8006.  
  8007. eval $LOGFE
  8008. }
  8009.  
  8010. get_unmounted_partition_data()
  8011. {
  8012. eval $LOGFS
  8013. local a_unmounted_working='' mounted_partitions='' separator='|' unmounted_fs=''
  8014. local dev_working='' uuid_working='' label_working='' a_raid_working='' raid_partitions=''
  8015.  
  8016. if [[ $B_PARTITIONS_FILE == 'true' ]];then
  8017. # set dev disk label/uuid data globals
  8018. get_partition_dev_data 'label'
  8019. get_partition_dev_data 'uuid'
  8020. # load the raid data array here so we can exclude its partitions
  8021. if [[ $B_RAID_SET != 'true' ]];then
  8022. get_raid_data
  8023. fi
  8024. # sr0 type cd drives are showing up now as unmounted partitions
  8025. mounted_partitions="scd[0-9]+|sr[0-9]+|cdrom[0-9]*|cdrw[0-9]*|dvd[0-9]*|dvdrw[0-9]*"
  8026. # create list for slicing out the mounted partitions
  8027. for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
  8028. do
  8029. IFS=","
  8030. a_unmounted_working=( ${A_PARTITION_DATA[i]} )
  8031. IFS="$ORIGINAL_IFS"
  8032. if [[ -n ${a_unmounted_working[6]} ]];then
  8033. mounted_partitions="$mounted_partitions$separator${a_unmounted_working[6]}"
  8034. fi
  8035. done
  8036. # now we need to exclude the mdraid partitions from the unmounted partition output as well
  8037. for (( i=0; i < ${#A_RAID_DATA[@]}; i++ ))
  8038. do
  8039. IFS=","
  8040. a_raid_working=( ${A_RAID_DATA[i]} )
  8041. IFS="$ORIGINAL_IFS"
  8042. if [[ -n ${a_raid_working[3]} ]];then
  8043. raid_partitions=$( sed $SED_RX 's/(\([^\)]*\)|\[[^\]]*\])//g' <<< ${a_raid_working[3]}\
  8044. | sed 's/[[:space:]]\+/|/g' )
  8045. mounted_partitions="$mounted_partitions$separator$raid_partitions"
  8046. fi
  8047. done
  8048.  
  8049. A_UNMOUNTED_PARTITION_DATA=( $( grep -Ev '[[:space:]]('$mounted_partitions')$' $FILE_PARTITIONS | gawk '
  8050. BEGIN {
  8051. IGNORECASE=1
  8052. }
  8053. # note that size 1 means it is a logical extended partition container
  8054. # lvm might have dm-1 type syntax
  8055. # need to exclude loop type file systems, squashfs for example
  8056. /[a-z][0-9]+$|dm-[0-9]+$/ && $3 != 1 && $NF !~ /loop/ {
  8057. size = sprintf( "%.2f", $3*1024/1000**3 )
  8058. print $4 "," size "G"
  8059. }' ) )
  8060.  
  8061. for (( i=0; i < ${#A_UNMOUNTED_PARTITION_DATA[@]}; i++ ))
  8062. do
  8063. IFS=","
  8064. a_unmounted_working=( ${A_UNMOUNTED_PARTITION_DATA[i]} )
  8065. IFS="$ORIGINAL_IFS"
  8066.  
  8067. label_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$DEV_DISK_LABEL" | gawk '{
  8068. print $(NF - 2)
  8069. }' )
  8070. uuid_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$DEV_DISK_UUID" | gawk '{
  8071. print $(NF - 2)
  8072. }' )
  8073. unmounted_fs=$( get_unmounted_partition_filesystem "/dev/${a_unmounted_working[0]}" )
  8074.  
  8075. IFS=","
  8076. A_UNMOUNTED_PARTITION_DATA[i]=${a_unmounted_working[0]}","${a_unmounted_working[1]}","$label_working","$uuid_working","$unmounted_fs
  8077. IFS="$ORIGINAL_IFS"
  8078. done
  8079. fi
  8080. # echo "${A_PARTITION_DATA[@]}"
  8081. # echo "${A_UNMOUNTED_PARTITION_DATA[@]}"
  8082. eval $LOGFE
  8083. }
  8084.  
  8085. # a few notes, normally file -s requires root, but you can set user rights in /etc/sudoers.
  8086. # list of file systems: http://en.wikipedia.org/wiki/List_of_file_systems
  8087. # args: $1 - /dev/<disk><part> to be tested for
  8088. get_unmounted_partition_filesystem()
  8089. {
  8090. eval $LOGFS
  8091. local partition_filesystem='' sudo_command=''
  8092.  
  8093. if [[ $B_FILE_TESTED != 'true' ]];then
  8094. B_FILE_TESTED='true'
  8095. FILE_PATH=$( type -p file )
  8096. fi
  8097.  
  8098. if [[ $B_SUDO_TESTED != 'true' ]];then
  8099. B_SUDO_TESTED='true'
  8100. SUDO_PATH=$( type -p sudo )
  8101. fi
  8102.  
  8103. if [[ -n $FILE_PATH && -n $1 ]];then
  8104. # only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
  8105. # which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
  8106. # important: -n makes it non interactive, no prompt for password
  8107. if [[ $B_ROOT != 'true' && -n $SUDO_PATH ]];then
  8108. sudo_command='sudo -n '
  8109. fi
  8110. # this will fail if regular user and no sudo present, but that's fine, it will just return null
  8111. # note the hack that simply slices out the first line if > 1 items found in string
  8112. # also, if grub/lilo is on partition boot sector, no file system data is available
  8113. # BSD fix: -Eio -Em 1
  8114. partition_filesystem=$( eval $sudo_command $FILE_PATH -s $1 | grep -Eio '(ext2|ext3|ext4|ext5|ext[[:space:]]|ntfs|fat32|fat16|fat[[:space:]]\(.*\)|vfat|fatx|tfat|swap|btrfs|ffs[[:space:]]|hfs\+|hfs[[:space:]]plus|hfs[[:space:]]extended[[:space:]]version[[:space:]][1-9]|hfsj|hfs[[:space:]]|jfs[[:space:]]|nss[[:space:]]|reiserfs|reiser4|ufs2|ufs[[:space:]]|xfs[[:space:]]|zfs[[:space:]])' | grep -Em 1 '.*' )
  8115. if [[ -n $partition_filesystem ]];then
  8116. echo $partition_filesystem
  8117. fi
  8118. fi
  8119. eval $LOGFE
  8120. }
  8121.  
  8122. ## return uptime string
  8123. get_uptime()
  8124. {
  8125. eval $LOGFS
  8126. ## note: removing gsub(/ /,"",a); to get get space back in there, goes right before print a
  8127. local uptime_value="$( uptime | gawk '{
  8128. a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0)
  8129. print a
  8130. }' )"
  8131. echo "$uptime_value"
  8132. log_function_data "uptime_value: $uptime_value"
  8133. eval $LOGFE
  8134. }
  8135.  
  8136. get_weather_data()
  8137. {
  8138. eval $LOGFS
  8139.  
  8140. local location_site='http://geoip.ubuntu.com/lookup'
  8141. local weather_feed='http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query='
  8142. local weather_spider='http://wunderground.com/'
  8143. local data_grab_error='' wget_error=0
  8144. local b_test_loc=false b_test_weather=false b_debug=false
  8145. local test_dir="$HOME/bin/scripts/inxi/data/weather/"
  8146. local test_location='location2.xml' test_weather='weather-feed.xml'
  8147. local location_data='' location='' weather_data='' location_array_value='' a_location=''
  8148. local weather_array_value='' site_elevation='' temp_array=''
  8149.  
  8150. # first we get the location data, once that is parsed and handled, we move to getting the
  8151. # actual weather data, assuming no errors
  8152. if [[ -n $ALTERNATE_WEATHER_LOCATION ]];then
  8153. # note, this api does not support spaces in names, replace spaces with + sign.
  8154. location=$ALTERNATE_WEATHER_LOCATION
  8155. # echo $ALTERNATE_WEATHER_LOCATION;exit
  8156. else
  8157. if [[ $b_test_loc != 'true' ]];then
  8158. location_data=$( wget -q -t 1 -T $WGET_TIMEOUT -O- $location_site || wget_error=$? )
  8159. log_function_data "$location_data"
  8160. if [[ $wget_error -ne 0 ]];then
  8161. data_grab_error="Error: location server up but download error - wget: $wget_error"
  8162. fi
  8163. wget_error=0
  8164. else
  8165. if [[ -f $test_dir$test_location ]];then
  8166. location_data="$( cat $test_dir$test_location )"
  8167. else
  8168. data_grab_error="Error: location xml local file not found."
  8169. fi
  8170. fi
  8171. if [[ -n $data_grab_error ]];then
  8172. :
  8173. elif [[ -z $( grep -i '<Response' <<< $location_data ) ]];then
  8174. data_grab_error="Error: location downloaded but data contains no xml."
  8175. else
  8176. # clean up xml and make easy to process with newlines, note, bsd sed has no support for inserting
  8177. # \n dircctly so we have to use this hack
  8178. # location_data="$( sed $SED_RX 's|><|>\n<|g' <<< $location_data )"
  8179. location_data="$( sed $SED_RX 's|><|>\
  8180. <|g' <<< $location_data )"
  8181. # echo -e "ld:\n$location_data"
  8182. location_array_value=$( gawk '
  8183. function clean(data) {
  8184. returnData=""
  8185. # some lines might be empty, so ignore those
  8186. if (data !~ /^<[^>]+>$/ ) {
  8187. returnData=gensub(/(.*>)([^<]*)(<.*)/, "\\2", 1, data)
  8188. }
  8189. return returnData
  8190. }
  8191. BEGIN {
  8192. IGNORECASE=1
  8193. locationString=""
  8194. countryCode=""
  8195. countryCode3=""
  8196. countryName=""
  8197. regionCode=""
  8198. regionName=""
  8199. city=""
  8200. postalCode=""
  8201. latitude=""
  8202. longitude=""
  8203. timeZone=""
  8204. areaCode=""
  8205. }
  8206. /CountryCode/ {
  8207. if ( $0 ~ /CountryCode3/ ){
  8208. countryCode3=clean($0)
  8209. }
  8210. else {
  8211. countryCode=clean($0)
  8212. }
  8213. }
  8214. /CountryName/ {
  8215. countryName = clean($0)
  8216. }
  8217. /RegionCode/ {
  8218. regionCode = clean($0)
  8219. }
  8220. /RegionName/ {
  8221. regionName = clean($0)
  8222. }
  8223. /City/ {
  8224. city = clean($0)
  8225. }
  8226. /ZipPostalCode/ {
  8227. postalCode = clean($0)
  8228. }
  8229. /Latitude/ {
  8230. latitude = clean($0)
  8231. }
  8232. /Longitude/ {
  8233. longitude = clean($0)
  8234. }
  8235. /TimeZone/ {
  8236. timeZone = clean($0)
  8237. }
  8238. END {
  8239. locationString = city ";" regionCode ";" regionName ";" countryName ";" countryCode ";" countryCode3
  8240. locationString = locationString ";" latitude "," longitude ";" postalCode ";" timeZone
  8241. print locationString
  8242. }' <<< "$location_data" )
  8243. fi
  8244. A_WEATHER_DATA[0]=$location_array_value
  8245. IFS=";"
  8246. a_location=( ${A_WEATHER_DATA[0]} )
  8247. IFS="$ORIGINAL_IFS"
  8248.  
  8249. # assign location, cascade from most accurate
  8250. # latitude,longitude first
  8251. if [[ -n ${a_location[6]} ]];then
  8252. location="${a_location[6]}"
  8253. # city,state next
  8254. elif [[ -n ${a_location[0]} && -n ${a_location[1]} ]];then
  8255. location="${a_location[0]},${a_location[1]}"
  8256. # postal code last, that can be a very large region
  8257. elif [[ -n ${a_location[7]} ]];then
  8258. location=${a_location[7]}
  8259. fi
  8260. fi
  8261. if [[ $b_debug == 'true' ]];then
  8262. echo -e "location array:\n${A_WEATHER_DATA[0]}"
  8263. echo "location: $location"
  8264. fi
  8265. log_function_data "location: $location"
  8266.  
  8267. if [[ -z $location && -z $data_grab_error ]];then
  8268. data_grab_error="Error: location data downloaded but no location detected."
  8269. fi
  8270.  
  8271. # now either dump process or go on to get weather data
  8272. if [[ -z $data_grab_error ]];then
  8273. if [[ $b_test_weather != 'true' ]];then
  8274. weather_data="$( wget -q -t 1 -T $WGET_TIMEOUT -O- $weather_feed"$location" || wget_error=$? )"
  8275. if [[ $wget_error -ne 0 ]];then
  8276. data_grab_error="Error: weather server up but download error - wget: $wget_error"
  8277. fi
  8278. log_function_data "$weather_data"
  8279. else
  8280. if [[ -f $test_dir$test_weather ]];then
  8281. weather_data="$( cat $test_dir$test_weather)"
  8282. else
  8283. data_grab_error="Error: weather feed xml local file not found."
  8284. fi
  8285. fi
  8286. if [[ -z $data_grab_error && -z $( grep -i '<current_observation' <<< $weather_data ) ]];then
  8287. data_grab_error="Error: weather data downloaded but shows no xml start."
  8288. fi
  8289. if [[ -z $data_grab_error ]];then
  8290. # trim off zeros
  8291. weather_data=$( sed 's/^[[:space:]]*//' <<< "$weather_data" )
  8292. site_elevation=$( grep -im 1 '<elevation>' <<< "$weather_data" | sed $SED_RX -e 's/<[^>]*>//g' \
  8293. -e 's/\.[0-9]*//' )
  8294. # we need to grab the location data from the feed for remote checks
  8295. if [[ -n $ALTERNATE_WEATHER_LOCATION && -n $weather_data ]];then
  8296. location_data=$( sed -e '/<current_observation>/,/<display_location>/d' -e '/<\/display_location>/,/<\/current_observation>/d' <<< "$weather_data" )
  8297. # echo -e "ld1:\n$location_data"
  8298. A_WEATHER_DATA[0]=$( gawk '
  8299. function clean(data) {
  8300. returnData=""
  8301. # some lines might be empty, so ignore those
  8302. if (data !~ /^<[^>]+>$/ ) {
  8303. returnData=gensub(/(.*>)([^<]*)(<.*)/, "\\2", 1, data)
  8304. gsub(/^[[:space:]]+|[[:space:]]+$|^NA$|^N\/A$/, "", returnData)
  8305. }
  8306. return returnData
  8307. }
  8308. BEGIN {
  8309. IGNORECASE=1
  8310. city=""
  8311. state=""
  8312. country=""
  8313. }
  8314. /<city>/ {
  8315. city=clean($0)
  8316. }
  8317. /<state>/ {
  8318. state=clean($0)
  8319. }
  8320. /<country>/ {
  8321. country=clean($0)
  8322. }
  8323. END {
  8324. print city ";" state ";;;;" country
  8325. }' <<< "$location_data" )
  8326. # echo -e "location:\n${A_WEATHER_DATA[0]}"
  8327. fi
  8328.  
  8329. # clean off everything before/after observation_location
  8330. weather_data=$( sed -e '/<current_observation>/,/<observation_location>/d' \
  8331. -e '/<icons>/,/<\/current_observation>/d' <<< "$weather_data" -e 's/^[[:space:]]*$//g' -e '/^$/d' )
  8332.  
  8333. # echo "$weather_data";exit
  8334. weather_array_value=$( gawk -v siteElevation="$site_elevation" '
  8335. function clean(data) {
  8336. returnData=""
  8337. # some lines might be empty, so ignore those
  8338. if (data !~ /^<[^>]+>$/ ) {
  8339. returnData=gensub(/(.*>)([^<]*)(<.*)/, "\\2", 1, data)
  8340. gsub(/^[[:space:]]+|[[:space:]]+$|^NA$|^N\/A$/, "", returnData)
  8341. }
  8342. return returnData
  8343. }
  8344. BEGIN {
  8345. IGNORECASE=1
  8346. observationTime=""
  8347. localTime=""
  8348. weather=""
  8349. tempString=""
  8350. humidity=""
  8351. windString=""
  8352. pressureString=""
  8353. dewpointString=""
  8354. heatIndexString=""
  8355. windChillString=""
  8356. weatherString=""
  8357. }
  8358. /observation_time>/ {
  8359. observationTime=clean($0)
  8360. sub(/Last Updated on /, "", observationTime )
  8361. }
  8362. /local_time>/ {
  8363. localTime=clean($0)
  8364. }
  8365. /<weather/ {
  8366. weather=clean($0)
  8367. }
  8368. /temperature_string/ {
  8369. tempString=clean($0)
  8370. }
  8371. /relative_humidity/ {
  8372. humidity=clean($0)
  8373. }
  8374. /wind_string/ {
  8375. windString=clean($0)
  8376. }
  8377. /pressure_string/ {
  8378. pressureString=clean($0)
  8379. }
  8380. /heat_index_string/ {
  8381. heatIndexString=clean($0)
  8382. }
  8383. /windchill_string/ {
  8384. windChillString=clean($0)
  8385. }
  8386. END {
  8387. weatherString = observationTime ";" localTime ";" weather ";" tempString ";" humidity
  8388. weatherString = weatherString ";" windString ";" pressureString ";" dewpointString ";" heatIndexString
  8389. weatherString = weatherString ";" windChillString ";" siteElevation
  8390. print weatherString
  8391. }' <<< "$weather_data" )
  8392. fi
  8393. if [[ -z $weather_array_value ]];then
  8394. data_grab_error="Error: weather info downloaded but no data detected."
  8395. else
  8396. A_WEATHER_DATA[1]=$weather_array_value
  8397. fi
  8398. fi
  8399. # now either dump process or go on to get weather data
  8400. if [[ -n $data_grab_error ]];then
  8401. A_WEATHER_DATA=$data_grab_error
  8402. log_function_data "data grab error: $data_grab_error"
  8403. fi
  8404.  
  8405. if [[ $b_debug == 'true' ]];then
  8406. echo "site_elevation: $site_elevation"
  8407. echo "${A_WEATHER_DATA[1]}"
  8408. fi
  8409. temp_array=${A_WEATHER_DATA[@]}
  8410. log_function_data "A_WEATHER_DATA: $temp_array"
  8411.  
  8412. eval $LOGFE
  8413. }
  8414. # ALTERNATE_WEATHER_LOCATION='portland,or'
  8415. # get_weather_data;exit
  8416.  
  8417. #### -------------------------------------------------------------------
  8418. #### special data handling for specific options and conditions
  8419. #### -------------------------------------------------------------------
  8420.  
  8421. # args: $1 - string to strip color code characters out of
  8422. # returns count of string length minus colors
  8423. calculate_line_length()
  8424. {
  8425. local string="$1"
  8426. # ansi:  irc: \x0312
  8427. string=$( sed -e "s/\x1b\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g" -e "s/\\\x0[0-9]\{1,3\}//g" <<< $string )
  8428. count=$( wc -c <<< $string )
  8429. echo $count
  8430. }
  8431.  
  8432. ## multiply the core count by the data to be calculated, bmips, cache
  8433. # args: $1 - string to handle; $2 - cpu count
  8434. calculate_multicore_data()
  8435. {
  8436. eval $LOGFS
  8437. local string_number=$1 string_data=''
  8438.  
  8439. if [[ -n $( grep -Ei '( mb| kb)' <<< $1 ) ]];then
  8440. string_data=" $( gawk '{print $2}' <<< $1 )" # add a space for output
  8441. string_number=$( gawk '{print $1}' <<< $1 )
  8442. fi
  8443. # handle weird error cases where it's not a number
  8444. if [[ -n $( grep -E '^[0-9\.,]+$' <<< $string_number ) ]];then
  8445. string_number=$( echo $string_number $2 | gawk '{
  8446. total = $1*$2
  8447. print total
  8448. }' )
  8449. elif [[ $string_number == '' ]];then
  8450. string_number='N/A'
  8451. else
  8452. # I believe that the above returns 'unknown' by default so no need for extra text
  8453. string_number="$string_number "
  8454. fi
  8455. echo "$string_number$string_data"
  8456. log_function_data "string_numberstring_data: $string_number$string_data"
  8457. eval $LOGFE
  8458. }
  8459.  
  8460. # prints out shortened list of flags, the main ones of interest
  8461. # args: $1 - string of cpu flags to process
  8462. process_cpu_flags()
  8463. {
  8464. eval $LOGFS
  8465.  
  8466. local cpu_flags_working=$1
  8467. local bits=$( uname -m | grep 64 )
  8468.  
  8469. # no need to show pae for 64 bit cpus, it's pointless
  8470. if [[ -n $bits ]];then
  8471. cpu_flags_working=$( sed 's/[[:space:]]*pae//' <<< "$cpu_flags_working" )
  8472. fi
  8473. # must have a space after last item in list for RS=" "
  8474. cpu_flags_working="$cpu_flags_working "
  8475.  
  8476. # nx = AMD stack protection extensions
  8477. # lm = Intel 64bit extensions
  8478. # sse, sse2, pni = sse1,2,3,4,5 gfx extensions
  8479. # svm = AMD pacifica virtualization extensions
  8480. # vmx = Intel IVT (vanderpool) virtualization extensions
  8481. cpu_flags=$(
  8482. echo "$cpu_flags_working" | gawk '
  8483. BEGIN {
  8484. RS=" "
  8485. count = 0
  8486. i = 1 # start at one because of for increment issue
  8487. flag_string = ""
  8488. }
  8489.  
  8490. /^(lm|nx|pae|pni|svm|vmx|(sss|ss)e([2-9])?([a-z])?(_[0-9])?)$/ {
  8491. if ( $0 == "pni" ){
  8492. a_flags[i] = "sse3"
  8493. }
  8494. else {
  8495. a_flags[i] = $0
  8496. }
  8497. i++
  8498. }
  8499. END {
  8500. count = asort( a_flags )
  8501. # note: why does gawk increment before the loop and not after? weird.
  8502. for ( i=0; i <= count; i++ ){
  8503. if ( flag_string == "" ) {
  8504. flag_string = a_flags[i]
  8505. }
  8506. else {
  8507. flag_string = flag_string " " a_flags[i]
  8508. }
  8509. }
  8510. print flag_string
  8511. }' )
  8512.  
  8513. #grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
  8514. if [[ -z $cpu_flags ]];then
  8515. cpu_flags="-"
  8516. fi
  8517. echo "$cpu_flags"
  8518. log_function_data "cpu_flags: $cpu_flags"
  8519. eval $LOGFE
  8520. }
  8521.  
  8522. #### -------------------------------------------------------------------
  8523. #### print and processing of output data
  8524. #### -------------------------------------------------------------------
  8525.  
  8526. #### MASTER PRINT FUNCTION - triggers all line item print functions
  8527. ## main function to print out, master for all sub print functions.
  8528. print_it_out()
  8529. {
  8530. eval $LOGFS
  8531. # note that print_it_out passes local variable values on to its children,
  8532. # and in some cases, their children, with Lspci_v_Data
  8533. local Lspci_v_Data='' Lspci_n_Data='' # only for verbose
  8534. local Sysctl_a_Data='' Dmesg_Boot_Data=''
  8535.  
  8536. if [[ -n $BSD_TYPE ]];then
  8537. Sysctl_a_Data="$( get_sysctl_data 'a' )"
  8538. Dmesg_Boot_Data="$( get_dmesg_boot_data )"
  8539. fi
  8540.  
  8541. if [[ $B_SHOW_SHORT_OUTPUT == 'true' ]];then
  8542. print_short_data
  8543. else
  8544. Lspci_v_Data="$( get_lspci_data 'v' )"
  8545. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  8546. Lspci_n_Data="$( get_lspci_data 'n' )"
  8547. fi
  8548. if [[ $B_SHOW_SYSTEM == 'true' ]];then
  8549. print_system_data
  8550. fi
  8551. if [[ $B_SHOW_MACHINE == 'true' ]];then
  8552. print_machine_data
  8553. fi
  8554. if [[ $B_SHOW_WEATHER == 'true' ]];then
  8555. print_weather_data
  8556. fi
  8557. if [[ $B_SHOW_BASIC_CPU == 'true' || $B_SHOW_CPU == 'true' ]];then
  8558. print_cpu_data
  8559. fi
  8560. if [[ $B_SHOW_GRAPHICS == 'true' ]];then
  8561. print_gfx_data
  8562. fi
  8563. if [[ $B_SHOW_AUDIO == 'true' ]];then
  8564. print_audio_data
  8565. fi
  8566. if [[ $B_SHOW_NETWORK == 'true' ]];then
  8567. print_networking_data
  8568. fi
  8569. if [[ $B_SHOW_DISK_TOTAL == 'true' || $B_SHOW_BASIC_DISK == 'true' || $B_SHOW_DISK == 'true' ]];then
  8570. print_hard_disk_data
  8571. fi
  8572. if [[ $B_SHOW_PARTITIONS == 'true' ]];then
  8573. print_partition_data
  8574. fi
  8575. if [[ $B_SHOW_RAID == 'true' || $B_SHOW_BASIC_RAID == 'true' ]];then
  8576. print_raid_data
  8577. fi
  8578. if [[ $B_SHOW_UNMOUNTED_PARTITIONS == 'true' ]];then
  8579. print_unmounted_partition_data
  8580. fi
  8581. if [[ $B_SHOW_SENSORS == 'true' ]];then
  8582. print_sensors_data
  8583. fi
  8584. if [[ $B_SHOW_REPOS == 'true' ]];then
  8585. print_repo_data
  8586. fi
  8587. if [[ $B_SHOW_PS_CPU_DATA == 'true' || $B_SHOW_PS_MEM_DATA == 'true' ]];then
  8588. print_ps_data
  8589. fi
  8590. if [[ $B_SHOW_INFO == 'true' ]];then
  8591. print_info_data
  8592. fi
  8593. fi
  8594. eval $LOGFE
  8595. }
  8596.  
  8597. #### SHORT OUTPUT PRINT FUNCTION, ie, verbosity 0
  8598. # all the get data stuff is loaded here to keep execution time down for single line print commands
  8599. # these will also be loaded in each relevant print function for long output
  8600. print_short_data()
  8601. {
  8602. eval $LOGFS
  8603. local current_kernel=$( get_kernel_version )
  8604. local processes=$(( $( wc -l <<< "$Ps_aux_Data" ) - 1 ))
  8605. local short_data='' i='' b_background_black='false'
  8606. local memory=$( get_memory_data )
  8607. local up_time="$( get_uptime )"
  8608.  
  8609. # set A_CPU_CORE_DATA
  8610. get_cpu_core_count
  8611. local cpc_plural='' cpu_count_print='' model_plural=''
  8612. local cpu_physical_count=${A_CPU_CORE_DATA[0]}
  8613. local cpu_core_count=${A_CPU_CORE_DATA[3]}
  8614. local cpu_core_alpha=${A_CPU_CORE_DATA[1]}
  8615. local cpu_type=${A_CPU_CORE_DATA[2]}
  8616.  
  8617. if [[ $cpu_physical_count -gt 1 ]];then
  8618. cpc_plural='(s)'
  8619. model_plural='s'
  8620. cpu_count_print="$cpu_physical_count "
  8621. fi
  8622.  
  8623. local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
  8624. # local cpu_core_count=${A_CPU_CORE_DATA[0]}
  8625.  
  8626. # load A_HDD_DATA
  8627. get_hdd_data_basic
  8628. ## note: if hdd_model is declared prior to use, whatever string you want inserted will
  8629. ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
  8630. local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
  8631. IFS=","
  8632. local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
  8633. IFS="$ORIGINAL_IFS"
  8634. local hdd_capacity=${a_hdd_basic_working[0]}
  8635. local hdd_used=${a_hdd_basic_working[1]}
  8636.  
  8637. # load A_CPU_DATA
  8638. get_cpu_data
  8639.  
  8640. IFS=","
  8641. local a_cpu_working=(${A_CPU_DATA[0]})
  8642. IFS="$ORIGINAL_IFS"
  8643. local cpu_model="${a_cpu_working[0]}"
  8644. ## assemble data for output
  8645. local cpu_clock="${a_cpu_working[1]}" # old CPU3
  8646. # this gets that weird min/max final array item, which almost never contains any data of use
  8647. local min_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 ))
  8648. local min_max_clock=${A_CPU_DATA[$min_max_clock_nu]}
  8649. # this handles the case of for example ARM cpus, which will not have data for
  8650. # min/max, since they don't have speed. Since that sets a flag, not found, just
  8651. # look for that and use the speed from the first array array, same where we got
  8652. # model from
  8653. if [[ "$min_max_clock" == 'N/A' && ${a_cpu_working[1]} != '' ]];then
  8654. min_max_clock="${a_cpu_working[1]} MHz"
  8655. fi
  8656. local patch_version_number=$( get_patch_version_string )
  8657.  
  8658. #set_color_scheme 12
  8659. if [[ $B_RUNNING_IN_SHELL == 'false' ]];then
  8660. for i in $C1 $C2 $CN
  8661. do
  8662. case "$i" in
  8663. "$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN")
  8664. b_background_black='true'
  8665. ;;
  8666. esac
  8667. done
  8668. if [[ $b_background_black == 'true' ]];then
  8669. for i in C1 C2 CN
  8670. do
  8671. ## these need to be in quotes, don't know why
  8672. if [[ ${!i} == $NORMAL ]];then
  8673. declare $i="${!i}15,1"
  8674. else
  8675. declare $i="${!i},1"
  8676. fi
  8677. done
  8678. #C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
  8679. fi
  8680. fi
  8681. short_data="${C1}CPU$cpc_plural${C2}${SEP1}${cpu_data_string} ${cpu_model}$model_plural (${cpu_type}) clocked at ${min_max_clock}${SEP2}${C1}Kernel${C2}${SEP1}${current_kernel}${SEP2}${C1}Up${C2}${SEP1}${up_time}${SEP2}${C1}Mem${C2}${SEP1}${memory}${SEP2}${C1}HDD${C2}${SEP1}${hdd_capacity}($hdd_used)${SEP2}${C1}Procs${C2}${SEP1}${processes}${SEP2}"
  8682.  
  8683. if [[ $SHOW_IRC -gt 0 ]];then
  8684. short_data="${short_data}${C1}Client${C2}${SEP1}${IRC_CLIENT}${IRC_CLIENT_VERSION}${SEP2}"
  8685. fi
  8686. short_data="${short_data}${C1}$SCRIPT_NAME${C2}${SEP1}$SCRIPT_VERSION_NUMBER$patch_version_number${SEP2}${CN}"
  8687. if [[ $SCHEME -gt 0 ]];then
  8688. short_data="${short_data} $NORMAL"
  8689. fi
  8690. print_screen_output "$short_data"
  8691. eval $LOGFE
  8692. }
  8693.  
  8694. #### LINE ITEM PRINT FUNCTIONS
  8695.  
  8696. # print sound card data
  8697. print_audio_data()
  8698. {
  8699. eval $LOGFS
  8700. local i='' card_id='' audio_data='' a_audio_data='' port_data='' pci_bus_id='' card_string=''
  8701. local a_audio_working='' audio_driver='' alsa_data='' port_plural='' module_version=''
  8702. local bus_usb_text='' bus_usb_id='' line_starter='Audio:' alsa='' alsa_version='' print_data=''
  8703. local driver=''
  8704. # set A_AUDIO_DATA and get alsa data
  8705. if [[ $BSD_TYPE == 'bsd' ]];then
  8706. if [[ $B_PCICONF_SET == 'false' ]];then
  8707. get_pciconf_data
  8708. fi
  8709. get_pciconf_card_data 'audio'
  8710. else
  8711. get_audio_data
  8712. fi
  8713.  
  8714. get_audio_alsa_data
  8715. # alsa driver data now prints out no matter what
  8716. if [[ -n $A_ALSA_DATA ]];then
  8717. IFS=","
  8718. if [[ -n ${A_ALSA_DATA[0]} ]];then
  8719. alsa=${A_ALSA_DATA[0]}
  8720. else
  8721. alsa='N/A'
  8722. fi
  8723. if [[ -n ${A_ALSA_DATA[1]} ]];then
  8724. alsa_version=${A_ALSA_DATA[1]}
  8725. else
  8726. alsa_version='N/A'
  8727. fi
  8728. alsa_data="${C1}Sound:${C2} $alsa ${C1}ver$SEP3${C2} $alsa_version"
  8729. IFS="$ORIGINAL_IFS"
  8730. fi
  8731. # note, error handling is done in the get function, so this will never be null, but
  8732. # leaving the test just in case it's changed.
  8733. if [[ -n ${A_AUDIO_DATA[@]} ]];then
  8734. for (( i=0; i< ${#A_AUDIO_DATA[@]}; i++ ))
  8735. do
  8736. IFS=","
  8737. a_audio_working=( ${A_AUDIO_DATA[i]} )
  8738. IFS="$ORIGINAL_IFS"
  8739. port_data=''
  8740. audio_driver=''
  8741. audio_data=''
  8742. card_string=''
  8743. port_plural=''
  8744. module_version=''
  8745. pci_bus_id=''
  8746. bus_usb_text=''
  8747. bus_usb_id=''
  8748. print_data=''
  8749. vendor_product=''
  8750.  
  8751. if [[ ${#A_AUDIO_DATA[@]} -gt 1 ]];then
  8752. card_id="-$(( $i + 1 ))"
  8753. fi
  8754. if [[ $BSD_TYPE != 'bsd' ]];then
  8755. if [[ -n ${a_audio_working[3]} && $B_EXTRA_DATA == 'true' ]];then
  8756. module_version=$( print_module_version "${a_audio_working[3]}" 'audio' )
  8757. elif [[ -n ${a_audio_working[1]} && $B_EXTRA_DATA == 'true' ]];then
  8758. module_version=$( print_module_version "${a_audio_working[1]}" 'audio' )
  8759. fi
  8760. fi
  8761. # we're testing for the presence of the 2nd array item here, which is the driver name
  8762. if [[ -n ${a_audio_working[1]} ]];then
  8763. # note: linux drivers can have numbers, like tg3
  8764. if [[ $BSD_TYPE == 'bsd' ]];then
  8765. driver=$( sed 's/[0-9]$//' <<< ${a_audio_working[1]} )
  8766. else
  8767. driver=${a_audio_working[1]}
  8768. fi
  8769. audio_driver="${C1}driver$SEP3${C2} ${driver} "
  8770. fi
  8771. if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then
  8772. if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then
  8773. port_plural='s'
  8774. fi
  8775. port_data="${C1}port$port_plural$SEP3${C2} ${a_audio_working[2]} "
  8776. fi
  8777. if [[ -n ${a_audio_working[4]} && $B_EXTRA_DATA == 'true' ]];then
  8778. if [[ ${a_audio_working[1]} != 'USB Audio' ]];then
  8779. bus_usb_text='bus-ID'
  8780. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  8781. if [[ $BSD_TYPE != 'bsd' ]];then
  8782. vendor_product=$( get_lspci_vendor_product "${a_audio_working[4]}" )
  8783. else
  8784. vendor_product=${a_audio_working[6]}
  8785. fi
  8786. fi
  8787. else
  8788. bus_usb_text='usb-ID'
  8789. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  8790. vendor_product=${a_audio_working[5]}
  8791. fi
  8792. fi
  8793. bus_usb_id=${a_audio_working[4]}
  8794. pci_bus_id="${C1}$bus_usb_text$SEP3${C2} $bus_usb_id "
  8795. if [[ -n $vendor_product ]];then
  8796. vendor_product="${C1}chip-ID$SEP3${C2} $vendor_product "
  8797. fi
  8798. fi
  8799. if [[ -n ${a_audio_working[0]} ]];then
  8800. card_string="${C1}Card$card_id:${C2} ${a_audio_working[0]} "
  8801. audio_data="$audio_driver$port_data$pci_bus_id$vendor_product"
  8802. fi
  8803. # only print alsa on last line if short enough, otherwise print on its own line
  8804. if [[ $i -eq 0 ]];then
  8805. if [[ -n $alsa_data && $( calculate_line_length "$card_string${audio_data}$alsa_data" ) -lt $LINE_MAX ]];then
  8806. audio_data="$audio_data$alsa_data"
  8807. alsa_data=''
  8808. fi
  8809. fi
  8810. if [[ -n $audio_data ]];then
  8811. if [[ $( calculate_line_length "$card_string$audio_data" ) -lt $LINE_MAX ]];then
  8812. print_data=$( create_print_line "$line_starter" "$card_string$audio_data" )
  8813. print_screen_output "$print_data"
  8814. # print the line
  8815. else
  8816. # keep the driver on the same line no matter what, looks weird alone on its own line
  8817. if [[ $B_EXTRA_DATA != 'true' ]];then
  8818. print_data=$( create_print_line "$line_starter" "$card_string$audio_data" )
  8819. print_screen_output "$print_data"
  8820. else
  8821. print_data=$( create_print_line "$line_starter" "$card_string" )
  8822. print_screen_output "$print_data"
  8823. line_starter=' '
  8824. print_data=$( create_print_line "$line_starter" "$audio_data" )
  8825. print_screen_output "$print_data"
  8826. fi
  8827. fi
  8828. line_starter=' '
  8829. fi
  8830. done
  8831. fi
  8832. if [[ -n $alsa_data ]];then
  8833. alsa_data=$( sed 's/ALSA/Advanced Linux Sound Architecture/' <<< $alsa_data )
  8834. alsa_data=$( create_print_line "$line_starter" "$alsa_data" )
  8835. print_screen_output "$alsa_data"
  8836. fi
  8837. eval $LOGFE
  8838. }
  8839.  
  8840. print_cpu_data()
  8841. {
  8842. eval $LOGFS
  8843. local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data=''
  8844. local bmip_data='' cpu_cache='' cpu_vendor='' cpu_flags='' flag_feature='flags'
  8845. local a_cpu_working='' cpu_model='' cpu_clock='' cpu_null_error=''
  8846. local cpc_plural='' cpu_count_print='' model_plural='' cpu_data_string=''
  8847. local cpu_physical_count='' cpu_core_count='' cpu_core_alpha='' cpu_type=''
  8848.  
  8849. ##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\""
  8850. # Array A_CPU_DATA always has one extra element: max clockfreq found.
  8851. # that's why its count is one more than you'd think from cores/cpus alone
  8852. # load A_CPU_DATA
  8853. get_cpu_data
  8854.  
  8855. IFS=","
  8856. a_cpu_working=(${A_CPU_DATA[0]})
  8857. IFS="$ORIGINAL_IFS"
  8858.  
  8859. # Strange (and also some expected) behavior encountered. If print_screen_output() uses $1
  8860. # as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
  8861. # will output only <text1> and first element of ARR. That "@" splits in elements and "*" _doesn't_,
  8862. # is to be expected. However, that text2 is consecutively truncated is somewhat strange, so take note.
  8863. # This has been confirmed by #bash on freenode.
  8864. # The above mentioned only emerges when using the debugging markers below
  8865. ## print_screen_output "a_cpu_working=\"***${a_cpu_working[@]} $hostName+++++++\"----------"
  8866. # unless all these are null, process whatever you have
  8867. if [[ -n ${a_cpu_working[0]} || -n ${a_cpu_working[1]} || -n ${a_cpu_working[2]} || -n ${a_cpu_working[3]} ]];then
  8868. cpu_model="${a_cpu_working[0]}"
  8869. ## assemble data for output
  8870. cpu_clock="${a_cpu_working[1]}"
  8871.  
  8872. cpu_vendor=${a_cpu_working[5]}
  8873.  
  8874. # set A_CPU_CORE_DATA
  8875. get_cpu_core_count
  8876. cpu_physical_count=${A_CPU_CORE_DATA[0]}
  8877. cpu_core_count=${A_CPU_CORE_DATA[3]}
  8878. cpu_core_alpha=${A_CPU_CORE_DATA[1]}
  8879. cpu_type=${A_CPU_CORE_DATA[2]}
  8880.  
  8881. if [[ $cpu_physical_count -gt 1 ]];then
  8882. cpc_plural='(s)'
  8883. cpu_count_print="$cpu_physical_count "
  8884. model_plural='s'
  8885. fi
  8886.  
  8887. cpu_data_string="${cpu_count_print}${cpu_core_alpha} core"
  8888. cpu_data=$( create_print_line "CPU$cpc_plural:" "${C1}${cpu_data_string}${C2} ${a_cpu_working[0]}$model_plural (${cpu_type})" )
  8889. if [[ $B_SHOW_CPU == 'true' ]];then
  8890. # update for multicore, bogomips x core count.
  8891. if [[ $B_EXTRA_DATA == 'true' ]];then
  8892. # if [[ $cpu_vendor != 'intel' ]];then
  8893. # ARM may use the faked 1 cpucorecount to make this work
  8894. # echo $cpu_core_count $cpu_physical_count
  8895. if [[ -n ${a_cpu_working[4]} ]];then
  8896. bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$(( $cpu_core_count * $cpu_physical_count ))" )
  8897. fi
  8898. # else
  8899. # bmip_data="${a_cpu_working[4]}"
  8900. # fi
  8901. # bogomips are a linux thing, but my guess is over time bsds will use them somewhere anyway
  8902. if [[ $BSD_TYPE == 'bsd' && -z $bmip_data ]];then
  8903. bmip_data=''
  8904. else
  8905. bmip_data=" ${C1}bmips$SEP3${C2} $bmip_data"
  8906. fi
  8907. fi
  8908. ## note: this handles how intel reports L2, total instead of per core like AMD does
  8909. # note that we need to multiply by number of actual cpus here to get true cache size
  8910. if [[ -n ${a_cpu_working[2]} ]];then
  8911. if [[ $cpu_vendor != 'intel' ]];then
  8912. cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$(( $cpu_core_count * $cpu_physical_count ))" )
  8913. else
  8914. cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$cpu_physical_count" )
  8915. fi
  8916. else
  8917. cpu_cache='N/A'
  8918. fi
  8919. # only print shortened list
  8920. if [[ $B_CPU_FLAGS_FULL != 'true' ]];then
  8921. # gawk has already sorted this output, no flags returns -
  8922. cpu_flags=$( process_cpu_flags "${a_cpu_working[3]}" "${a_cpu_working[6]}" )
  8923. cpu_flags="($cpu_flags)"
  8924. if [[ ${a_cpu_working[6]} == 'true' ]];then
  8925. flag_feature='features'
  8926. fi
  8927. cpu_flags=" ${C1}$flag_feature$SEP3${C2} $cpu_flags"
  8928. fi
  8929. # arm cpus do not have flags or cache
  8930. if [[ ${a_cpu_working[6]} != 'true' ]];then
  8931. cpu_data="$cpu_data${C2} ${C1}cache$SEP3${C2} $cpu_cache$cpu_flags$bmip_data${CN}"
  8932. else
  8933. cpu_data="$cpu_data${C2} (ARM)$bmip_data${CN}"
  8934. fi
  8935. fi
  8936. # we don't this printing out extra line unless > 1 cpu core
  8937. if [[ ${#A_CPU_DATA[@]} -gt 2 && $B_SHOW_CPU == 'true' ]];then
  8938. cpu_clock_speed='' # null < verbosity level 5
  8939. else
  8940. cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}"
  8941. fi
  8942. cpu_data="$cpu_data $cpu_clock_speed"
  8943. else
  8944. if [[ $BSD_TYPE == 'bsd' && $B_ROOT != 'true' ]];then
  8945. cpu_null_error=' No permissions for sysctl use?'
  8946. fi
  8947. cpu_data=$( create_print_line "CPU:" "${C2}No CPU data available.$cpu_null_error" )
  8948. fi
  8949. print_screen_output "$cpu_data"
  8950. # we don't this printing out extra line unless > 1 cpu core
  8951. # note the numbering, the last array item is the min/max/not found for cpu speeds
  8952. if [[ ${#A_CPU_DATA[@]} -gt 2 && $B_SHOW_CPU == 'true' ]];then
  8953. for (( i=0; i < ${#A_CPU_DATA[@]}-1; i++ ))
  8954. do
  8955. IFS=","
  8956. a_cpu_working=(${A_CPU_DATA[i]})
  8957. IFS="$ORIGINAL_IFS"
  8958. # note: the first iteration will create a first space, for color code separation below
  8959. cpu_multi_clock_data="$cpu_multi_clock_data ${C1}$(( i + 1 )):${C2} ${a_cpu_working[1]} MHz${CN}"
  8960. # someone actually appeared with a 16 core system, so going to stop the cpu core throttle
  8961. # if this had some other purpose which we can't remember we'll add it back in
  8962. #if [[ $i -gt 10 ]];then
  8963. # break
  8964. #fi
  8965. done
  8966. if [[ -n $cpu_multi_clock_data ]];then
  8967. cpu_multi_clock_data=$( create_print_line " " "${C1}Clock Speeds:${C2}$cpu_multi_clock_data" )
  8968. print_screen_output "$cpu_multi_clock_data"
  8969. fi
  8970. fi
  8971. if [[ $B_CPU_FLAGS_FULL == 'true' ]];then
  8972. print_cpu_flags_full "${a_cpu_working[3]}" "${a_cpu_working[6]}"
  8973. fi
  8974. eval $LOGFE
  8975. }
  8976.  
  8977. # takes list of all flags, split them and prints x per line
  8978. # args: $1 - cpu flag string; $2 - arm true/false
  8979. print_cpu_flags_full()
  8980. {
  8981. eval $LOGFS
  8982. # note: sort only sorts lines, not words in a string, so convert to lines
  8983. local cpu_flags_full="$( echo $1 | tr " " "\n" | sort )"
  8984. local a_cpu_flags='' line_starter=''
  8985. local i=0 counter=0 max_length=85 max_length_minus=15 flag='' flag_data=''
  8986. local line_length_max='' flag_feature='Flags'
  8987.  
  8988. if [[ $2 == 'true' ]];then
  8989. flag_feature='Features'
  8990. fi
  8991.  
  8992.  
  8993. # build the flag line array
  8994. for flag in $cpu_flags_full
  8995. do
  8996. a_cpu_flags[$counter]="${a_cpu_flags[$counter]}$flag "
  8997. if [[ $counter -eq 0 ]];then
  8998. line_length_max=$(( $max_length - $max_length_minus ))
  8999. else
  9000. line_length_max=$max_length
  9001. fi
  9002.  
  9003. if [[ $( wc -c <<< ${a_cpu_flags[$counter]} ) -gt $line_length_max ]];then
  9004. (( counter++ ))
  9005. fi
  9006. done
  9007. # then print it out
  9008. for (( i=0; i < ${#a_cpu_flags[@]};i++ ))
  9009. do
  9010. if [[ $i -eq 0 ]];then
  9011. line_starter="${C1}CPU $flag_feature$SEP3${C2} "
  9012. else
  9013. line_starter=''
  9014. fi
  9015. flag_data=$( create_print_line " " "$line_starter${a_cpu_flags[$i]}" )
  9016. print_screen_output "$flag_data"
  9017. done
  9018. eval $LOGFE
  9019. }
  9020.  
  9021. print_gfx_data()
  9022. {
  9023. eval $LOGFS
  9024. local gfx_data='' i='' card_id='' root_alert='' root_x_string='' a_gfx_working=''
  9025. local b_is_mesa='false' display_full_string='' gfx_bus_id='' gfx_card_data=''
  9026. local res_tty='Resolution' xorg_data='' x_vendor_string='' vendor_product=''
  9027. local spacer='' x_driver='' x_driver_string='' x_driver_plural='' direct_render_string=''
  9028. local separator_loaded='' separator_unloaded='' separator_failed=''
  9029. local loaded='' unloaded='' failed=''
  9030. local line_starter='Graphics:'
  9031. local screen_resolution="$( get_graphics_res_data )"
  9032.  
  9033. # set A_X_DATA
  9034. get_graphics_x_data
  9035. local x_vendor=${A_X_DATA[0]}
  9036. local x_version=${A_X_DATA[1]}
  9037. # set A_GLX_DATA
  9038. get_graphics_glx_data
  9039. local glx_renderer="${A_GLX_DATA[0]}"
  9040. local glx_version="${A_GLX_DATA[1]}"
  9041. # this can contain a long No case debugging message, so it's being sliced off
  9042. # note: using grep -ioE '(No|Yes)' <<< ${A_GLX_DATA[2]} did not work in Arch, no idea why
  9043. local glx_direct_render=$( gawk '{print $1}' <<< "${A_GLX_DATA[2]}" )
  9044.  
  9045. # set A_GFX_CARD_DATA
  9046. if [[ $BSD_TYPE == 'bsd' ]];then
  9047. if [[ $B_PCICONF_SET == 'false' ]];then
  9048. get_pciconf_data
  9049. fi
  9050. get_pciconf_card_data 'display'
  9051. else
  9052. get_graphics_card_data
  9053. fi
  9054. # set A_GRAPHIC_DRIVERS
  9055. get_graphics_driver
  9056.  
  9057. if [[ ${#A_GRAPHIC_DRIVERS[@]} -eq 0 ]];then
  9058. x_driver=' N/A'
  9059. else
  9060. for (( i=0; i < ${#A_GRAPHIC_DRIVERS[@]}; i++ ))
  9061. do
  9062. IFS=","
  9063. a_gfx_working=( ${A_GRAPHIC_DRIVERS[i]} )
  9064. IFS="$ORIGINAL_IFS"
  9065. case ${a_gfx_working[1]} in
  9066. loaded)
  9067. loaded="$loaded$separator_loaded${a_gfx_working[0]}"
  9068. separator_loaded=','
  9069. ;;
  9070. unloaded)
  9071. unloaded="$unloaded$separator_unloaded${a_gfx_working[0]}"
  9072. separator_unloaded=','
  9073. ;;
  9074. failed)
  9075. failed="$failed$separator_failed${a_gfx_working[0]}"
  9076. separator_failed=','
  9077. ;;
  9078. esac
  9079. done
  9080. fi
  9081. if [[ -n $loaded ]];then
  9082. x_driver="${x_driver} $loaded"
  9083. fi
  9084. if [[ -n $unloaded ]];then
  9085. x_driver="${x_driver} (unloaded: $unloaded)"
  9086. fi
  9087. if [[ -n $failed ]];then
  9088. x_driver="${x_driver} ${RED}FAILED:${C2} $failed"
  9089. fi
  9090. # sometimes for some reason there is no driver found but the array is started
  9091. if [[ -z $x_driver ]];then
  9092. x_driver=' N/A'
  9093. fi
  9094.  
  9095. if [[ ${#A_GRAPHIC_DRIVERS[@]} -gt 1 ]];then
  9096. x_driver_plural='s'
  9097. fi
  9098. x_driver_string="${C1}driver$x_driver_plural$SEP3${C2}$x_driver "
  9099.  
  9100. # some basic error handling:
  9101. if [[ -z $screen_resolution ]];then
  9102. screen_resolution='N/A'
  9103. fi
  9104. if [[ -z $x_vendor || -z $x_version ]];then
  9105. x_vendor_string="${C1}X-Vendor:${C2} N/A "
  9106. else
  9107. x_vendor_string="${C1}$x_vendor$SEP3${C2} $x_version "
  9108. fi
  9109.  
  9110. if [[ $B_ROOT == 'true' ]];then
  9111. root_x_string='for root '
  9112. if [[ $B_RUNNING_IN_SHELL == 'true' || $B_CONSOLE_IRC == 'true' ]];then
  9113. res_tty='tty size'
  9114. fi
  9115. fi
  9116. if [[ $B_RUNNING_IN_X != 'true' ]];then
  9117. root_x_string="${root_x_string}out of X"
  9118. res_tty='tty size'
  9119. fi
  9120.  
  9121. if [[ -n $root_x_string ]];then
  9122. root_x_string="${C1}Advanced Data:${C2} N/A $root_x_string"
  9123. fi
  9124.  
  9125. display_full_string="$x_vendor_string$x_driver_string${C1}${res_tty}$SEP3${C2} ${screen_resolution} $root_x_string"
  9126.  
  9127. if [[ ${#A_GFX_CARD_DATA[@]} -gt 0 ]];then
  9128. for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
  9129. do
  9130. IFS=","
  9131. a_gfx_working=( ${A_GFX_CARD_DATA[i]} )
  9132. IFS="$ORIGINAL_IFS"
  9133. gfx_bus_id=''
  9134. gfx_card_data=${a_gfx_working[0]}
  9135. if [[ $B_EXTRA_DATA == 'true' ]];then
  9136. if [[ -n ${a_gfx_working[1]} ]];then
  9137. gfx_bus_id=" ${C1}bus-ID$SEP3${C2} ${a_gfx_working[1]}"
  9138. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  9139. if [[ $BSD_TYPE != 'bsd' ]];then
  9140. vendor_product=$( get_lspci_vendor_product "${a_gfx_working[1]}" )
  9141. else
  9142. vendor_product=${a_gfx_working[2]}
  9143. fi
  9144. fi
  9145. else
  9146. gfx_bus_id=" ${C1}bus-ID$SEP3${C2} N/A"
  9147. fi
  9148. fi
  9149. if [[ -n $vendor_product ]];then
  9150. vendor_product=" ${C1}chip-ID$SEP3${C2} $vendor_product"
  9151. fi
  9152. if [[ ${#A_GFX_CARD_DATA[@]} -gt 1 ]];then
  9153. card_id="Card-$(($i+1)):"
  9154. else
  9155. card_id='Card:'
  9156. fi
  9157. gfx_data="${C1}$card_id${C2} $gfx_card_data$gfx_bus_id$vendor_product "
  9158. if [[ ${#A_GFX_CARD_DATA[@]} -gt 1 ]];then
  9159. gfx_data=$( create_print_line "$line_starter" "${gfx_data}" )
  9160. print_screen_output "$gfx_data"
  9161. line_starter=' '
  9162. gfx_data=''
  9163. fi
  9164. done
  9165. # handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
  9166. else
  9167. gfx_data="${C1}Card:${C2} Failed to Detect Video Card! "
  9168. fi
  9169. if [[ -n $gfx_data && $( calculate_line_length "${gfx_data}$display_full_string" ) -lt $LINE_MAX ]];then
  9170. gfx_data=$( create_print_line "$line_starter" "${gfx_data}$display_full_string" )
  9171. else
  9172. if [[ -n $gfx_data ]];then
  9173. gfx_data=$( create_print_line "$line_starter" "$gfx_data" )
  9174. print_screen_output "$gfx_data"
  9175. line_starter=' '
  9176. fi
  9177. gfx_data=$( create_print_line "$line_starter" "$display_full_string" )
  9178. fi
  9179. print_screen_output "$gfx_data"
  9180. # if [[ -z $glx_renderer || -z $glx_version ]];then
  9181. # b_is_mesa='true'
  9182. # fi
  9183.  
  9184. ## note: if glx render or version have no content, then mesa is true
  9185. # if [[ $B_SHOW_X_DATA == 'true' ]] && [[ $b_is_mesa != 'true' ]];then
  9186. if [[ $B_SHOW_X_DATA == 'true' && $B_ROOT != 'true' ]];then
  9187. if [[ -z $glx_renderer ]];then
  9188. glx_renderer='N/A'
  9189. fi
  9190. if [[ -z $glx_version ]];then
  9191. glx_version='N/A'
  9192. fi
  9193. if [[ -z $glx_direct_render ]];then
  9194. glx_direct_render='N/A'
  9195. fi
  9196. if [[ $B_HANDLE_CORRUPT_DATA == 'true' || $B_EXTRA_DATA == 'true' ]];then
  9197. direct_render_string=" ${C1}Direct Rendering$SEP3${C2} ${glx_direct_render}${CN}"
  9198. fi
  9199. gfx_data="${C1}GLX Renderer$SEP3${C2} ${glx_renderer} ${C1}GLX Version$SEP3${C2} ${glx_version}${CN}$direct_render_string"
  9200. gfx_data=$( create_print_line " " "$gfx_data" )
  9201.  
  9202. print_screen_output "$gfx_data"
  9203. fi
  9204. eval $LOGFE
  9205. }
  9206.  
  9207. print_hard_disk_data()
  9208. {
  9209. eval $LOGFS
  9210. local hdd_data='' hdd_data_2='' a_hdd_working='' hdd_temp_data='' hdd_string=''
  9211. local hdd_serial=''
  9212. local dev_data='' size_data='' hdd_model='' usb_data='' hdd_name='' divisor=5
  9213. local Line_Starter='Drives:' # inherited by print_optical_drives
  9214.  
  9215. # load A_HDD_DATA
  9216. get_hdd_data_basic
  9217. ## note: if hdd_model is declared prior to use, whatever string you want inserted will
  9218. ## be inserted first. In this case, it's desirable to print out (x) before each disk found.
  9219. local a_hdd_data_count=$(( ${#A_HDD_DATA[@]} - 1 ))
  9220. IFS=","
  9221. local a_hdd_basic_working=( ${A_HDD_DATA[$a_hdd_data_count]} )
  9222. IFS="$ORIGINAL_IFS"
  9223. local hdd_capacity="${a_hdd_basic_working[0]}"
  9224. local hdd_used=${a_hdd_basic_working[1]}
  9225. local bsd_unsupported='Hard drive data not yet supported for BSD systems.'
  9226. local hdd_name_temp=''
  9227.  
  9228. if [[ $B_SHOW_BASIC_DISK == 'true' || $B_SHOW_DISK == 'true' ]];then
  9229. ## note: the output part of this should be in the print hdd data function, not here
  9230. get_hard_drive_data_advanced
  9231. for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ ))
  9232. do
  9233. # this adds the (x) numbering in front of each disk found, and creates the full disk string
  9234. IFS=","
  9235. a_hdd_working=( ${A_HDD_DATA[i]} )
  9236. IFS="$ORIGINAL_IFS"
  9237. if [[ $B_SHOW_DISK == 'true' ]];then
  9238. if [[ -n ${a_hdd_working[3]} ]];then
  9239. usb_data="${a_hdd_working[3]} "
  9240. else
  9241. usb_data=''
  9242. fi
  9243. dev_data="/dev/${a_hdd_working[0]} "
  9244. size_data=" ${C1}size$SEP3${C2} ${a_hdd_working[1]}"
  9245. if [[ $B_EXTRA_DATA == 'true' && -n $dev_data ]];then
  9246. hdd_temp_data=$( get_hdd_temp_data "$dev_data" )
  9247. # error handling is done in get data function
  9248. if [[ -n $hdd_temp_data ]];then
  9249. hdd_temp_data=" ${C1}temp$SEP3${C2} ${hdd_temp_data}C"
  9250. else
  9251. hdd_temp_data=''
  9252. fi
  9253. fi
  9254. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  9255. hdd_serial=$( get_hdd_serial_number "${a_hdd_working[0]}" )
  9256. if [[ -z $hdd_serial ]];then
  9257. hdd_serial='N/A'
  9258. fi
  9259. hdd_serial=" ${C1}serial$SEP3${C2} $hdd_serial"
  9260. divisor=1 # print every line
  9261. else
  9262. divisor=2 # for modulus line print out, either 2 items for full, or default for short
  9263. fi
  9264. dev_data="${C1}id$SEP3${C2} /dev/${a_hdd_working[0]} "
  9265. fi
  9266. if [[ -n ${a_hdd_working[2]} ]];then
  9267. hdd_name_temp=${a_hdd_working[2]}
  9268. else
  9269. hdd_name_temp='N/A'
  9270. fi
  9271. hdd_name="${C1}model$SEP3${C2} $hdd_name_temp"
  9272. hdd_string="$usb_data$dev_data$hdd_name$size_data$hdd_serial$hdd_temp_data"
  9273. hdd_model="${hdd_model}${C1}$(($i+1)):${C2} $hdd_string "
  9274. # printing line one, then new lines according to $divisor setting, and after, if leftovers, print that line.
  9275. case $i in
  9276. 0)
  9277. if [[ $divisor -eq 1 ]];then
  9278. hdd_data=$( create_print_line "$Line_Starter" "${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used})" )
  9279. print_screen_output "$hdd_data"
  9280. Line_Starter=' '
  9281. hdd_data=$( create_print_line "$Line_Starter" "${hdd_model}" )
  9282. print_screen_output "$hdd_data"
  9283. hdd_model=''
  9284. else
  9285. hdd_data=$( create_print_line "$Line_Starter" "${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used}) ${hdd_model}" )
  9286. print_screen_output "$hdd_data"
  9287. hdd_model=''
  9288. Line_Starter=' '
  9289. fi
  9290. ;;
  9291. *)
  9292. # using modulus here, if divisible by $divisor, print line, otherwise skip
  9293. if [[ $(( $i % $divisor )) -eq 0 ]];then
  9294. hdd_data=$( create_print_line "$Line_Starter" "${hdd_model}${CN}" )
  9295. print_screen_output "$hdd_data"
  9296. hdd_model=''
  9297. Line_Starter=' '
  9298. fi
  9299. ;;
  9300. esac
  9301. done
  9302. # then print any leftover items
  9303. if [[ -n $hdd_model ]];then
  9304. hdd_data=$( create_print_line "$Line_Starter" "${hdd_model}${CN}" )
  9305. print_screen_output "$hdd_data"
  9306. fi
  9307. # temporary message to indicate not yet supported
  9308. if [[ $BSD_TYPE == 'bsd' ]];then
  9309. hdd_data=$bsd_unsupported
  9310. hdd_data=$( create_print_line "$Line_Starter" "$hdd_data${CN}" )
  9311. print_screen_output "$hdd_data"
  9312. Line_Starter=' '
  9313. fi
  9314. else
  9315. # temporary message to indicate not yet supported
  9316. hdd_data="${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used})"
  9317. if [[ $BSD_TYPE == 'bsd' ]];then
  9318. hdd_data=$bsd_unsupported
  9319. fi
  9320. hdd_data=$( create_print_line "$Line_Starter" "$hdd_data${CN}" )
  9321. print_screen_output "$hdd_data"
  9322. Line_Starter=' '
  9323. fi
  9324. if [[ $B_SHOW_FULL_OPTICAL == 'true' || $B_SHOW_BASIC_OPTICAL == 'true' ]];then
  9325. print_optical_drive_data
  9326. fi
  9327.  
  9328. eval $LOGFE
  9329. }
  9330.  
  9331. print_info_data()
  9332. {
  9333. eval $LOGFS
  9334.  
  9335. local info_data='' line_starter='Info:'
  9336. local runlvl='' client_data='' shell_data='' shell_parent='' tty_session=''
  9337. local memory="$( get_memory_data )"
  9338. local processes=$(( $( wc -l <<< "$Ps_aux_Data" ) - 1 ))
  9339. local up_time="$( get_uptime )"
  9340. local patch_version_number=$( get_patch_version_string )
  9341. local gcc_string='' gcc_installed='' gcc_others='' closing_data=''
  9342.  
  9343. if [[ -z $memory ]];then
  9344. memory='N/A'
  9345. fi
  9346.  
  9347. if [[ $B_EXTRA_DATA == 'true' ]];then
  9348. get_gcc_system_version
  9349. if [[ ${#A_GCC_VERSIONS[@]} -gt 0 ]];then
  9350. if [[ -n ${A_GCC_VERSIONS[0]} ]];then
  9351. gcc_installed=${A_GCC_VERSIONS[0]}
  9352. else
  9353. gcc_installed='N/A'
  9354. fi
  9355. if [[ $B_EXTRA_EXTRA_DATA == 'true' && -n ${A_GCC_VERSIONS[1]} ]];then
  9356. gcc_others=" ${C1}alt$SEP3${C2} $( tr ',' '/' <<< ${A_GCC_VERSIONS[1]} )"
  9357. fi
  9358. gcc_installed="${C1}Gcc sys$SEP3${C2} $gcc_installed$gcc_others "
  9359. fi
  9360. fi
  9361. if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
  9362. shell_data=$( get_shell_data )
  9363. if [[ -n $shell_data ]];then
  9364. # note, if you start this in tty, it will give 'login' as the parent, which we don't want.
  9365. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  9366. if [[ $B_RUNNING_IN_X != 'true' ]];then
  9367. shell_parent=$( get_tty_number )
  9368. shell_parent="tty $shell_parent"
  9369. else
  9370. shell_parent=$( get_shell_parent )
  9371. fi
  9372. if [[ $shell_parent == 'login' ]];then
  9373. shell_parent=''
  9374. elif [[ -n $shell_parent ]];then
  9375. shell_parent=" running in $shell_parent"
  9376. fi
  9377. fi
  9378. IRC_CLIENT="$IRC_CLIENT ($shell_data$shell_parent)"
  9379. fi
  9380. fi
  9381.  
  9382. # Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch!
  9383. # long_last=$( echo -ne "${C1}Processes$SEP3${C2} ${processes}${CN} | ${C1}Uptime$SEP3${C2} ${up_time}${CN} | ${C1}Memory$SEP3${C2} ${MEM}${CN}" )
  9384. info_data="${C1}Processes$SEP3${C2} ${processes} ${C1}Uptime$SEP3${C2} ${up_time} ${C1}Memory$SEP3${C2} ${memory}${CN} "
  9385.  
  9386. # this only triggers if no X data is present or if extra data switch is on
  9387. if [[ $B_SHOW_X_DATA != 'true' || $B_EXTRA_DATA == 'true' ]];then
  9388. runlvl="$( get_runlevel_data )"
  9389. if [[ -n $runlvl ]];then
  9390. info_data="${info_data}${C1}Runlevel$SEP3${C2} ${runlvl} "
  9391. fi
  9392. fi
  9393. if [[ $SHOW_IRC -gt 0 ]];then
  9394. client_data="${C1}Client$SEP3${C2} ${IRC_CLIENT}${IRC_CLIENT_VERSION} "
  9395. fi
  9396. info_data="${info_data}$gcc_installed"
  9397. closing_data="$client_data${C1}$SCRIPT_NAME$SEP3${C2} $SCRIPT_VERSION_NUMBER$patch_version_number${CN}"
  9398. if [[ -n $info_data && $( calculate_line_length "$info_data$closing_data" ) -gt $LINE_MAX ]];then
  9399. info_data=$( create_print_line "$line_starter" "$info_data" )
  9400. print_screen_output "$info_data"
  9401. info_data="$closing_data"
  9402. line_starter=' '
  9403. else
  9404. info_data="${info_data}$closing_data"
  9405. fi
  9406. info_data=$( create_print_line "$line_starter" "$info_data" )
  9407. if [[ $SCHEME -gt 0 ]];then
  9408. info_data="${info_data} ${NORMAL}"
  9409. fi
  9410. print_screen_output "$info_data"
  9411. eval $LOGFE
  9412. }
  9413.  
  9414. print_machine_data()
  9415. {
  9416. eval $LOGFS
  9417.  
  9418. local system_line='' mobo_line='' bios_line='' chassis_line=''
  9419. local mobo_vendor='' mobo_model='' mobo_version='' mobo_serial=''
  9420. local bios_vendor='' bios_version='' bios_date='' bios_rom=''
  9421. local system_vendor='' product_name='' product_version='' product_serial='' product_uuid=''
  9422. local chassis_vendor='' chassis_type='' chassis_version='' chassis_serial=''
  9423. local b_skip_system='false' b_skip_chassis='false'
  9424. local sysDmiError='No /sys/class/dmi, using '
  9425. local sysDmiNull='No /sys/class/dmi machine data: try newer kernel, or install dmidecode'
  9426. # set A_MACHINE_DATA
  9427. get_machine_data
  9428.  
  9429. if [[ -n $BSD_TYPE ]];then
  9430. sysDmiError=''
  9431. sysDmiNull='No machine data available. Is dmidecode installed?'
  9432. fi
  9433.  
  9434. IFS=','
  9435. ## keys for machine data are:
  9436. # 0-sys_vendor 1-product_name 2-product_version 3-product_serial 4-product_uuid
  9437. # 5-board_vendor 6-board_name 7-board_version 8-board_serial
  9438. # 9-bios_vendor 10-bios_version 11-bios_date
  9439. ## with extra data:
  9440. # 12-chassis_vendor 13-chassis_type 14-chassis_version 15-chassis_serial
  9441.  
  9442. if [[ ${#A_MACHINE_DATA[@]} -gt 0 ]];then
  9443. # note: in some case a mobo/version will match a product name/version, do not print those
  9444. # but for laptops, or even falsely id'ed desktops with batteries, let's print it all if it matches
  9445. # there can be false id laptops if battery appears so need to make sure system is filled
  9446. if [[ -z ${A_MACHINE_DATA[0]} ]];then
  9447. b_skip_system='true'
  9448. else
  9449. if [[ $B_PORTABLE != 'true' ]];then
  9450. # ibm / ibm can be true; dell / quantum is false, so in other words, only do this
  9451. # in case where the vendor is the same and the version is the same and not null,
  9452. # otherwise the version information is going to be different in all cases I think
  9453. if [[ -n ${A_MACHINE_DATA[0]} && ${A_MACHINE_DATA[0]} == ${A_MACHINE_DATA[5]} ]];then
  9454. if [[ -n ${A_MACHINE_DATA[2]} && ${A_MACHINE_DATA[2]} == ${A_MACHINE_DATA[7]} ]] || \
  9455. [[ -z ${A_MACHINE_DATA[2]} && ${A_MACHINE_DATA[1]} == ${A_MACHINE_DATA[6]} ]];then
  9456. b_skip_system='true'
  9457. fi
  9458. fi
  9459. fi
  9460. fi
  9461. # no point in showing chassis if system isn't there, it's very unlikely that would be correct
  9462. if [[ $B_EXTRA_EXTRA_DATA == 'true' && $b_skip_system != 'true' ]];then
  9463. if [[ -n ${A_MACHINE_DATA[7]} && ${A_MACHINE_DATA[14]} == ${A_MACHINE_DATA[7]} ]];then
  9464. b_skip_chassis='true'
  9465. fi
  9466. if [[ -n ${A_MACHINE_DATA[12]} && $b_skip_chassis != 'true' ]];then
  9467. # no need to print the vendor string again if it's the same
  9468. if [[ ${A_MACHINE_DATA[12]} != ${A_MACHINE_DATA[0]} ]];then
  9469. chassis_vendor=" ${A_MACHINE_DATA[12]}"
  9470. fi
  9471. if [[ -n ${A_MACHINE_DATA[13]} ]];then
  9472. chassis_type=" ${C1}type$SEP3${C2} ${A_MACHINE_DATA[13]}"
  9473. fi
  9474. if [[ -n ${A_MACHINE_DATA[14]} ]];then
  9475. chassis_version=" ${C1}version$SEP3${C2} ${A_MACHINE_DATA[14]}"
  9476. fi
  9477. if [[ -n ${A_MACHINE_DATA[15]} && $B_OUTPUT_FILTER != 'true' ]];then
  9478. chassis_serial=" ${C1}serial$SEP3${C2} ${A_MACHINE_DATA[15]}"
  9479. fi
  9480. if [[ -n "$chassis_vendor$chassis_type$chassis_version$chassis_serial" ]];then
  9481. chassis_line="${C1}Chassis$SEP3${C2}$chassis_vendor$chassis_type$chassis_version$chassis_serial"
  9482. fi
  9483. fi
  9484. fi
  9485. if [[ -n ${A_MACHINE_DATA[5]} ]];then
  9486. mobo_vendor=${A_MACHINE_DATA[5]}
  9487. else
  9488. mobo_vendor='N/A'
  9489. fi
  9490. if [[ -n ${A_MACHINE_DATA[6]} ]];then
  9491. mobo_model=${A_MACHINE_DATA[6]}
  9492. else
  9493. mobo_model='N/A'
  9494. fi
  9495. if [[ -n ${A_MACHINE_DATA[7]} ]];then
  9496. mobo_version=" ${C1}version$SEP3${C2} ${A_MACHINE_DATA[7]}"
  9497. fi
  9498. if [[ -n ${A_MACHINE_DATA[8]} && $B_OUTPUT_FILTER != 'true' ]];then
  9499. mobo_serial=" ${C1}serial$SEP3${C2} ${A_MACHINE_DATA[8]}"
  9500. fi
  9501. if [[ -n ${A_MACHINE_DATA[9]} ]];then
  9502. bios_vendor=${A_MACHINE_DATA[9]}
  9503. else
  9504. bios_vendor='N/A'
  9505. fi
  9506. if [[ -n ${A_MACHINE_DATA[10]} ]];then
  9507. bios_version=${A_MACHINE_DATA[10]}
  9508. if [[ -n ${A_MACHINE_DATA[16]} ]];then
  9509. bios_version="$bios_version rv ${A_MACHINE_DATA[16]}"
  9510. fi
  9511. else
  9512. bios_version='N/A'
  9513. fi
  9514. if [[ -n ${A_MACHINE_DATA[11]} ]];then
  9515. bios_date=${A_MACHINE_DATA[11]}
  9516. else
  9517. bios_date='N/A'
  9518. fi
  9519. if [[ $B_EXTRA_EXTRA_DATA == 'true' && -n ${A_MACHINE_DATA[17]} ]];then
  9520. bios_rom=" ${C1}rom size$SEP3${C2} ${A_MACHINE_DATA[17]}"
  9521. fi
  9522. mobo_line="${C1}Mobo$SEP3${C2} $mobo_vendor ${C1}model$SEP3${C2} $mobo_model$mobo_version$mobo_serial"
  9523. bios_line="${C1}Bios$SEP3${C2} $bios_vendor ${C1}version$SEP3${C2} $bios_version ${C1}date$SEP3${C2} $bios_date$bios_rom"
  9524. if [[ $( calculate_line_length "$mobo_line$bios_line" ) -lt $LINE_MAX ]];then
  9525. mobo_line="$mobo_line $bios_line"
  9526. bios_line=''
  9527. fi
  9528. if [[ $b_skip_system == 'true' ]];then
  9529. system_line=$mobo_line
  9530. mobo_line=''
  9531. else
  9532. # this has already been tested for above so we know it's not null
  9533. system_vendor=${A_MACHINE_DATA[0]}
  9534. if [[ $B_PORTABLE == 'true' ]];then
  9535. system_vendor="$system_vendor (portable)"
  9536. fi
  9537. if [[ -n ${A_MACHINE_DATA[1]} ]];then
  9538. product_name=${A_MACHINE_DATA[1]}
  9539. else
  9540. product_name='N/A'
  9541. fi
  9542. if [[ -n ${A_MACHINE_DATA[2]} ]];then
  9543. product_version=" ${C1}version$SEP3${C2} ${A_MACHINE_DATA[2]}"
  9544. fi
  9545. if [[ -n ${A_MACHINE_DATA[3]} && $B_OUTPUT_FILTER != 'true' ]];then
  9546. product_serial=" ${C1}serial$SEP3${C2} ${A_MACHINE_DATA[3]} "
  9547. fi
  9548. system_line="${C1}System$SEP3${C2} $system_vendor ${C1}product$SEP3${C2} $product_name$product_version$product_serial"
  9549. if [[ -n $chassis_line && $( calculate_line_length "$system_line$chassis_line" ) -lt $LINE_MAX ]];then
  9550. system_line="$system_line $chassis_line"
  9551. chassis_line=''
  9552. fi
  9553. fi
  9554. IFS="$ORIGINAL_IFS"
  9555. else
  9556. system_line="${C2}$sysDmiNull${CN}"
  9557. fi
  9558. # patch to dump all of above if dmidecode was data source and non root user
  9559. if [[ ${A_MACHINE_DATA[0]} == 'dmidecode-non-root-user' || ${A_MACHINE_DATA[0]} == 'dmidecode-no-smbios-dmi-data' ]];then
  9560. if [[ ${A_MACHINE_DATA[0]} == 'dmidecode-non-root-user' ]];then
  9561. system_line="${C2}${sysDmiError}dmidecode: you must be root to run dmidecode${CN}"
  9562. elif [[ ${A_MACHINE_DATA[0]} == 'dmidecode-no-smbios-dmi-data' ]];then
  9563. system_line="${C2}${sysDmiError}dmidecode: no machine data available${CN}"
  9564. fi
  9565. mobo_line=''
  9566. bios_line=''
  9567. chassis_line=''
  9568. fi
  9569. system_line=$( create_print_line "Machine:" "$system_line" )
  9570. print_screen_output "$system_line"
  9571. if [[ -n $mobo_line ]];then
  9572. mobo_line=$( create_print_line " " "$mobo_line" )
  9573. print_screen_output "$mobo_line"
  9574. fi
  9575. if [[ -n $bios_line ]];then
  9576. bios_line=$( create_print_line " " "$bios_line" )
  9577. print_screen_output "$bios_line"
  9578. fi
  9579. if [[ -n $chassis_line ]];then
  9580. chassis_line=$( create_print_line " " "$chassis_line" )
  9581. print_screen_output "$chassis_line"
  9582. fi
  9583.  
  9584. eval $LOGFE
  9585. }
  9586.  
  9587. # args: $1 - module name (could be > 1, so loop it ); $2 - audio (optional)
  9588. print_module_version()
  9589. {
  9590. eval $LOGFS
  9591. local module_versions='' module='' version='' prefix='' modules=$1
  9592.  
  9593. # note that sound driver data tends to have upper case, but modules are lower
  9594. if [[ $2 == 'audio' ]];then
  9595. if [[ -z $( grep -E '^snd' <<< $modules ) ]];then
  9596. prefix='snd_' # sound modules start with snd_
  9597. fi
  9598. modules=$( tr '[A-Z]' '[a-z]' <<< $modules )
  9599. modules=$( tr '-' '_' <<< $modules )
  9600. # special intel processing, generally no version info though
  9601. if [[ $modules == 'hda intel' ]];then
  9602. modules='hda_intel'
  9603. elif [[ $modules == 'intel ich' ]];then
  9604. modules='intel8x0'
  9605. fi
  9606. fi
  9607.  
  9608. for module in $modules
  9609. do
  9610. version=$( get_module_version_number "$prefix$module" )
  9611. if [[ -n $version ]];then
  9612. module_versions="$module_versions $version"
  9613. fi
  9614. done
  9615.  
  9616. if [[ -n $module_versions ]];then
  9617. echo " ${C1}ver$SEP3${C2}$module_versions"
  9618. fi
  9619. eval $LOGFE
  9620. }
  9621.  
  9622. print_networking_data()
  9623. {
  9624. eval $LOGFS
  9625. local i='' card_id='' network_data='' a_network_working='' port_data='' driver_data=''
  9626. local card_string='' port_plural='' module_version='' pci_bus_id='' bus_usb_text=''
  9627. local bus_usb_id='' line_starter='Network:' card_string='' card_data='' vendor_product=''
  9628. local driver=''
  9629. # set A_NETWORK_DATA
  9630. if [[ $BSD_TYPE == 'bsd' ]];then
  9631. if [[ $B_PCICONF_SET == 'false' ]];then
  9632. get_pciconf_data
  9633. fi
  9634. get_pciconf_card_data 'network'
  9635. else
  9636. get_networking_data
  9637. fi
  9638.  
  9639. # will never be null because null is handled in get_network_data, but in case we change
  9640. # that leaving this test in place.
  9641. if [[ -n ${A_NETWORK_DATA[@]} ]];then
  9642. for (( i=0; i < ${#A_NETWORK_DATA[@]}; i++ ))
  9643. do
  9644. IFS=","
  9645. a_network_working=( ${A_NETWORK_DATA[i]} )
  9646. IFS="$ORIGINAL_IFS"
  9647. bus_usb_id=''
  9648. bus_usb_text=''
  9649. card_data=''
  9650. card_string=''
  9651. driver_data=''
  9652. module_version=''
  9653. network_data=''
  9654. pci_bus_id=''
  9655. port_data=''
  9656. port_plural=''
  9657. vendor_product=''
  9658.  
  9659. if [[ ${#A_NETWORK_DATA[@]} -gt 1 ]];then
  9660. card_id="-$(( $i + 1 ))"
  9661. fi
  9662. if [[ -n ${a_network_working[1]} && $B_EXTRA_DATA == 'true' && $BSD_TYPE != 'bsd' ]];then
  9663. module_version=$( print_module_version "${a_network_working[1]}" )
  9664. fi
  9665. if [[ -n ${a_network_working[1]} ]];then
  9666. # note: linux drivers can have numbers, like tg3
  9667. if [[ $BSD_TYPE == 'bsd' ]];then
  9668. driver=$( sed 's/[0-9]*$//' <<< ${a_network_working[1]} )
  9669. else
  9670. driver=${a_network_working[1]}
  9671. fi
  9672. driver_data="${C1}driver$SEP3${C2} ${driver}$module_version "
  9673. fi
  9674. if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then
  9675. if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then
  9676. port_plural='s'
  9677. fi
  9678. port_data="${C1}port$port_plural$SEP3${C2} ${a_network_working[2]} "
  9679. fi
  9680. if [[ -n ${a_network_working[4]} && $B_EXTRA_DATA == 'true' ]];then
  9681. if [[ -z $( grep '^usb-' <<< ${a_network_working[4]} ) ]];then
  9682. bus_usb_text='bus-ID'
  9683. bus_usb_id=${a_network_working[4]}
  9684. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  9685. if [[ $BSD_TYPE != 'bsd' ]];then
  9686. vendor_product=$( get_lspci_vendor_product "${a_network_working[4]}" )
  9687. else
  9688. vendor_product=${a_network_working[10]}
  9689. fi
  9690. fi
  9691. else
  9692. bus_usb_text='usb-ID'
  9693. bus_usb_id=$( cut -d '-' -f '2-4' <<< ${a_network_working[4]} )
  9694. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  9695. vendor_product=${a_network_working[10]}
  9696. fi
  9697. fi
  9698. pci_bus_id="${C1}$bus_usb_text$SEP3${C2} $bus_usb_id"
  9699. if [[ -n $vendor_product ]];then
  9700. vendor_product=" ${C1}chip-ID$SEP3${C2} $vendor_product"
  9701. fi
  9702. fi
  9703. card_string="${C1}Card$card_id:${C2} ${a_network_working[0]} "
  9704. card_data="$driver_data$port_data$pci_bus_id$vendor_product"
  9705. if [[ $( calculate_line_length "$card_string$card_data" ) -gt $LINE_MAX ]];then
  9706. network_data=$( create_print_line "$line_starter" "$card_string" )
  9707. line_starter=' '
  9708. card_string=''
  9709. print_screen_output "$network_data"
  9710. fi
  9711. network_data=$( create_print_line "$line_starter" "$card_string$card_data" )
  9712. line_starter=' '
  9713. print_screen_output "$network_data"
  9714. if [[ $B_SHOW_ADVANCED_NETWORK == 'true' ]];then
  9715. print_network_advanced_data
  9716. fi
  9717. done
  9718. else
  9719. network_data="${C1}Card:${C2} Failed to Detect Network Card! "
  9720. network_data=$( create_print_line "$line_starter" "$network_data" )
  9721. print_screen_output "$network_data"
  9722. fi
  9723. if [[ $B_SHOW_IP == 'true' ]];then
  9724. print_networking_ip_data
  9725. fi
  9726. eval $LOGFE
  9727. }
  9728.  
  9729. print_network_advanced_data()
  9730. {
  9731. eval $LOGFS
  9732. local network_data='' if_id='N/A' duplex='N/A' mac_id='N/A' speed='N/A' oper_state='N/A'
  9733. local b_is_wifi='false' speed_string='' duplex_string=''
  9734.  
  9735. # first check if it's a known wifi id'ed card, if so, no print of duplex/speed
  9736. if [[ -n $( grep -Esi '(wireless|wifi|wi-fi|wlan|802\.11|centrino)' <<< ${a_network_working[0]} ) ]];then
  9737. b_is_wifi='true'
  9738. fi
  9739. if [[ -n ${a_network_working[5]} ]];then
  9740. if_id=${a_network_working[5]}
  9741. fi
  9742. if [[ -n ${a_network_working[6]} ]];then
  9743. oper_state=${a_network_working[6]}
  9744. fi
  9745. # no print out for wifi since it doesn't have duplex/speed data availabe
  9746. # note that some cards show 'unknown' for state, so only testing explicitly
  9747. # for 'down' string in that to skip showing speed/duplex
  9748. if [[ $b_is_wifi != 'true' && $oper_state != 'down' ]];then
  9749. if [[ -n ${a_network_working[7]} ]];then
  9750. # make sure the value is strictly numeric before appending Mbps
  9751. if [[ -n $( grep -E '^[0-9\.,]+$' <<< "${a_network_working[7]}" ) ]];then
  9752. speed="${a_network_working[7]} Mbps"
  9753. else
  9754. speed=${a_network_working[7]}
  9755. fi
  9756. fi
  9757. speed_string="${C1}speed$SEP3${C2} $speed "
  9758. if [[ -n ${a_network_working[8]} ]];then
  9759. duplex=${a_network_working[8]}
  9760. fi
  9761. duplex_string="${C1}duplex$SEP3${C2} $duplex "
  9762. fi
  9763. if [[ -n ${a_network_working[9]} ]];then
  9764. if [[ $B_OUTPUT_FILTER == 'true' ]];then
  9765. mac_id=$FILTER_STRING
  9766. else
  9767. mac_id=${a_network_working[9]}
  9768. fi
  9769. fi
  9770. network_data="${C1}IF:${C2} $if_id ${C1}state$SEP3${C2} $oper_state $speed_string$duplex_string${C1}mac$SEP3${C2} $mac_id"
  9771. network_data=$( create_print_line " " "$network_data" )
  9772. print_screen_output "$network_data"
  9773.  
  9774. eval $LOGFE
  9775. }
  9776.  
  9777. print_networking_ip_data()
  9778. {
  9779. eval $LOGFS
  9780. local ip=$( get_networking_wan_ip_data )
  9781. local wan_ip_data='' a_interfaces_working='' interfaces='' i=''
  9782. local if_id='' if_ip='' if_ipv6='' if_ipv6_string='' full_string='' if_string=''
  9783. local if_id_string='' if_ip_string=''
  9784. local line_max=$(( $LINE_MAX - 50 ))
  9785.  
  9786. # set A_INTERFACES_DATA
  9787. get_networking_local_ip_data
  9788. # first print output for wan ip line. Null is handled in the get function
  9789. if [[ -z $ip ]];then
  9790. ip='N/A'
  9791. else
  9792. if [[ $B_OUTPUT_FILTER == 'true' ]];then
  9793. ip=$FILTER_STRING
  9794. fi
  9795. fi
  9796. wan_ip_data="${C1}WAN IP:${C2} $ip "
  9797. # then create the list of local interface/ip
  9798. i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1
  9799. while [[ -n ${A_INTERFACES_DATA[i]} ]]
  9800. do
  9801. IFS=","
  9802. a_interfaces_working=(${A_INTERFACES_DATA[i]})
  9803. IFS="$ORIGINAL_IFS"
  9804. if_id='N/A'
  9805. if_ip='N/A'
  9806. if_ipv6='N/A'
  9807. if_ipv6_string=''
  9808. if [[ -z $( grep '^Interface' <<< ${a_interfaces_working[0]} ) ]];then
  9809. if [[ -n ${a_interfaces_working[1]} ]];then
  9810. if [[ $B_OUTPUT_FILTER == 'true' ]];then
  9811. if_ip=$FILTER_STRING
  9812. else
  9813. if_ip=${a_interfaces_working[1]}
  9814. fi
  9815. fi
  9816. if_ip_string=" ${C1}ip$SEP3${C2} $if_ip"
  9817. if [[ $B_EXTRA_DATA == 'true' ]];then
  9818. if [[ -n ${a_interfaces_working[3]} ]];then
  9819. if [[ $B_OUTPUT_FILTER == 'true' ]];then
  9820. if_ipv6=$FILTER_STRING
  9821. else
  9822. if_ipv6=${a_interfaces_working[3]}
  9823. fi
  9824. fi
  9825. if_ipv6_string=" ${C1}ip-v6$SEP3${C2} $if_ipv6"
  9826. fi
  9827. fi
  9828. if [[ -n ${a_interfaces_working[0]} ]];then
  9829. if_id=${a_interfaces_working[0]}
  9830. fi
  9831. if_string="$wan_ip_data$if_string${C1}IF:${C2} $if_id$if_ip_string$if_ipv6_string "
  9832. wan_ip_data=''
  9833. if [[ $( calculate_line_length "$if_string" ) -gt $line_max ]];then
  9834. full_string=$( create_print_line " " "$if_string" )
  9835. print_screen_output "$full_string"
  9836. if_string=''
  9837. fi
  9838. ((i++))
  9839. done
  9840.  
  9841. # then print out anything not printed already
  9842. if [[ -n $if_string ]];then
  9843. full_string=$( create_print_line " " "$if_string" )
  9844. print_screen_output "$full_string"
  9845. fi
  9846. eval $LOGFE
  9847. }
  9848.  
  9849. print_optical_drive_data()
  9850. {
  9851. eval $LOGFS
  9852. local a_drives='' drive_data='' counter=''
  9853. local drive_id='' drive_links='' vendor='' speed='' multisession='' mcn='' audio=''
  9854. local dvd='' state='' rw_support='' rev='' separator='' drive_string=''
  9855. get_optical_drive_data
  9856. # 0 - true dev path, ie, sr0, hdc
  9857. # 1 - dev links to true path
  9858. # 2 - device vendor - for hdx drives, vendor model are one string from proc
  9859. # 3 - device model
  9860. # 4 - device rev version
  9861. if [[ ${#A_OPTICAL_DRIVE_DATA[@]} -gt 0 ]];then
  9862. for (( i=0; i < ${#A_OPTICAL_DRIVE_DATA[@]}; i++ ))
  9863. do
  9864. IFS=","
  9865. a_drives=(${A_OPTICAL_DRIVE_DATA[i]})
  9866. IFS="$ORIGINAL_IFS"
  9867. audio=''
  9868. drive_data=''
  9869. drive_id=''
  9870. drive_links=''
  9871. dvd=''
  9872. mcn=''
  9873. multisession=''
  9874. rev=''
  9875. rw_support=''
  9876. separator=''
  9877. speed=''
  9878. state=''
  9879. vendor=''
  9880. if [[ ${#A_OPTICAL_DRIVE_DATA[@]} -eq 1 && -z ${a_drives[0]} && -z ${a_drives[1]} ]];then
  9881. drive_string="No optical drives detected."
  9882. B_SHOW_FULL_OPTICAL='false'
  9883. else
  9884. if [[ ${#A_OPTICAL_DRIVE_DATA[@]} -gt 1 ]];then
  9885. counter="-$(( i + 1 ))"
  9886. fi
  9887. if [[ -z ${a_drives[0]} ]];then
  9888. drive_id='N/A'
  9889. else
  9890. drive_id="/dev/${a_drives[0]}"
  9891. fi
  9892. drive_links=$( sed 's/~/,/g' <<< ${a_drives[1]} )
  9893. if [[ -z $drive_links ]];then
  9894. drive_links='N/A'
  9895. fi
  9896. if [[ -n ${a_drives[2]} ]];then
  9897. vendor=${a_drives[2]}
  9898. if [[ -n ${a_drives[3]} ]];then
  9899. vendor="$vendor ${a_drives[3]}"
  9900. fi
  9901. fi
  9902. if [[ -z $vendor ]];then
  9903. if [[ -n ${a_drives[3]} ]];then
  9904. vendor=${a_drives[3]}
  9905. else
  9906. vendor='N/A'
  9907. fi
  9908. fi
  9909. if [[ $B_EXTRA_DATA == 'true' ]];then
  9910. if [[ -n ${a_drives[4]} ]];then
  9911. rev=${a_drives[4]}
  9912. else
  9913. rev='N/A'
  9914. fi
  9915. rev=" ${C1}rev$SEP3${C2} $rev"
  9916. fi
  9917. drive_string="$drive_id ${C1}model$SEP3${C2} $vendor$rev ${C1}dev-links$SEP3${C2} $drive_links"
  9918. fi
  9919. drive_data="${C1}Optical${counter}:${C2} $drive_string"
  9920. drive_data=$( create_print_line "$Line_Starter" "$drive_data" )
  9921. print_screen_output "$drive_data"
  9922. Line_Starter=' '
  9923. # 5 - speed
  9924. # 6 - multisession support
  9925. # 7 - MCN support
  9926. # 8 - audio read
  9927. # 9 - cdr
  9928. # 10 - cdrw
  9929. # 11 - dvd read
  9930. # 12 - dvdr
  9931. # 13 - dvdram
  9932. # 14 - state
  9933. if [[ $B_SHOW_FULL_OPTICAL == 'true' ]];then
  9934. if [[ -z ${a_drives[5]} ]];then
  9935. speed='N/A'
  9936. else
  9937. speed="${a_drives[5]}x"
  9938. fi
  9939. if [[ -z ${a_drives[8]} ]];then
  9940. audio='N/A'
  9941. elif [[ ${a_drives[8]} == 1 ]];then
  9942. audio='yes'
  9943. else
  9944. audio='no'
  9945. fi
  9946. audio=" ${C1}audio$SEP3${C2} $audio"
  9947. if [[ -z ${a_drives[6]} ]];then
  9948. multisession='N/A'
  9949. elif [[ ${a_drives[6]} == 1 ]];then
  9950. multisession='yes'
  9951. else
  9952. multisession='no'
  9953. fi
  9954. multisession=" ${C1}multisession$SEP3${C2} $multisession"
  9955. if [[ -z ${a_drives[11]} ]];then
  9956. dvd='N/A'
  9957. elif [[ ${a_drives[11]} == 1 ]];then
  9958. dvd='yes'
  9959. else
  9960. dvd='no'
  9961. fi
  9962. if [[ $B_EXTRA_DATA == 'true' ]];then
  9963. if [[ -z ${a_drives[14]} ]];then
  9964. state='N/A'
  9965. else
  9966. state="${a_drives[14]}"
  9967. fi
  9968. state=" ${C1}state$SEP3${C2} $state"
  9969. fi
  9970. if [[ -n ${a_drives[9]} && ${a_drives[9]} == 1 ]];then
  9971. rw_support='cd-r'
  9972. separator=','
  9973. fi
  9974. if [[ -n ${a_drives[10]} && ${a_drives[10]} == 1 ]];then
  9975. rw_support="${rw_support}${separator}cd-rw"
  9976. separator=','
  9977. fi
  9978. if [[ -n ${a_drives[12]} && ${a_drives[12]} == 1 ]];then
  9979. rw_support="${rw_support}${separator}dvd-r"
  9980. separator=','
  9981. fi
  9982. if [[ -n ${a_drives[13]} && ${a_drives[13]} == 1 ]];then
  9983. rw_support="${rw_support}${separator}dvd-ram"
  9984. separator=','
  9985. fi
  9986. if [[ -z $rw_support ]];then
  9987. rw_support='none'
  9988. fi
  9989.  
  9990. drive_data="${C1}Features: speed$SEP3${C2} $speed$multisession$audio ${C1}dvd$SEP3${C2} $dvd ${C1}rw$SEP3${C2} $rw_support$state"
  9991. drive_data=$( create_print_line "$Line_Starter" "$drive_data" )
  9992. print_screen_output "$drive_data"
  9993. fi
  9994. done
  9995. else
  9996. :
  9997. fi
  9998. eval $LOGFE
  9999. }
  10000.  
  10001. print_partition_data()
  10002. {
  10003. eval $LOGFS
  10004. local a_partition_working='' partition_used='' partition_data=''
  10005. local counter=0 i=0 a_partition_data='' line_starter='' line_max=$(( $LINE_MAX - 35 ))
  10006. local partitionIdClean='' part_dev='' full_dev='' part_label='' full_label=''
  10007. local part_uuid='' full_uuid='' dev_remote='' full_fs='' line_max_label_uuid=$(( $LINE_MAX - 10 ))
  10008. local b_non_dev='false' holder=''
  10009.  
  10010. # set A_PARTITION_DATA
  10011. get_partition_data
  10012.  
  10013. for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ ))
  10014. do
  10015. IFS=","
  10016. a_partition_working=(${A_PARTITION_DATA[i]})
  10017. IFS="$ORIGINAL_IFS"
  10018. full_label=''
  10019. full_uuid=''
  10020.  
  10021. if [[ $B_SHOW_PARTITIONS_FULL == 'true' ]] || [[ ${a_partition_working[4]} == 'main' ]];then
  10022. if [[ -n ${a_partition_working[2]} ]];then
  10023. partition_used="${C1}used$SEP3${C2} ${a_partition_working[2]} (${a_partition_working[3]}) "
  10024. else
  10025. partition_used='' # reset partition used to null
  10026. fi
  10027. if [[ -n ${a_partition_working[5]} ]];then
  10028. full_fs="${a_partition_working[5]}"
  10029. else
  10030. full_fs='N/A' # reset partition fs type
  10031. fi
  10032. full_fs="${C1}fs$SEP3${C2} $full_fs "
  10033.  
  10034. if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then
  10035. if [[ -n ${a_partition_working[6]} ]];then
  10036. if [[ -z $( grep -E '(^//|:/|non-dev)' <<< ${a_partition_working[6]} ) ]];then
  10037. part_dev="/dev/${a_partition_working[6]}"
  10038. dev_remote='dev'
  10039. elif [[ -n $( grep '^non-dev' <<< ${a_partition_working[6]} ) ]];then
  10040. holder=$( sed 's/non-dev-//' <<< ${a_partition_working[6]} )
  10041. part_dev="$holder"
  10042. dev_remote='raid'
  10043. else
  10044. part_dev="${a_partition_working[6]}"
  10045. dev_remote='remote'
  10046. fi
  10047. else
  10048. dev_remote='dev'
  10049. part_dev='N/A'
  10050. fi
  10051. full_dev="${C1}$dev_remote$SEP3${C2} $part_dev "
  10052. if [[ $B_SHOW_LABELS == 'true' && $dev_remote != 'remote' ]];then
  10053. if [[ -n ${a_partition_working[7]} ]];then
  10054. part_label="${a_partition_working[7]}"
  10055. else
  10056. part_label='N/A'
  10057. fi
  10058. full_label="${C1}label$SEP3${C2} $part_label "
  10059. fi
  10060. if [[ $B_SHOW_UUIDS == 'true' && $dev_remote != 'remote' ]];then
  10061. if [[ -n ${a_partition_working[8]} ]];then
  10062. part_uuid="${a_partition_working[8]}"
  10063. else
  10064. part_uuid='N/A'
  10065. fi
  10066. full_uuid="${C1}uuid$SEP3${C2} $part_uuid"
  10067. fi
  10068. fi
  10069. # don't show user names in output
  10070. if [[ $B_OUTPUT_FILTER == 'true' ]];then
  10071. partitionIdClean=$( sed $SED_RX "s|/home/([^/]+)/(.*)|/home/$FILTER_STRING/\2|" <<< ${a_partition_working[0]} )
  10072. else
  10073. partitionIdClean=${a_partition_working[0]}
  10074. fi
  10075. id_size_fs="${C1}ID:${C2} $partitionIdClean ${C1}size$SEP3${C2} ${a_partition_working[1]} $partition_used$full_fs$full_dev"
  10076. label_uuid="$full_label$full_uuid"
  10077. # label/uuid always print one per line, so only wrap if it's very long
  10078. if [[ $B_SHOW_UUIDS == 'true' && $B_SHOW_LABELS == 'true' && $( calculate_line_length "$id_size_fs$label_uuid" ) -gt $line_max_label_uuid ]];then
  10079. a_partition_data[$counter]="$id_size_fs"
  10080. ((counter++))
  10081. a_partition_data[$counter]="$label_uuid"
  10082. else
  10083. a_partition_data[$counter]="${a_partition_data[$counter]}$id_size_fs$label_uuid"
  10084. fi
  10085. # because these lines can vary widely, using dynamic length handling here
  10086. if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]] || [[ $( calculate_line_length "${a_partition_data[$counter]}" ) -gt $line_max ]];then
  10087. ((counter++))
  10088. fi
  10089. fi
  10090. done
  10091. # print out all lines, line starter on first line
  10092. for (( i=0; i < ${#a_partition_data[@]};i++ ))
  10093. do
  10094. if [[ $i -eq 0 ]];then
  10095. line_starter='Partition:'
  10096. else
  10097. line_starter=' '
  10098. fi
  10099. partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}" )
  10100. print_screen_output "$partition_data"
  10101. done
  10102.  
  10103. eval $LOGFE
  10104. }
  10105.  
  10106. print_program_version()
  10107. {
  10108. local patch_version_number=$( get_patch_version_string )
  10109. local program_version="${C1}$SCRIPT_NAME$SEP3${C2} $SCRIPT_VERSION_NUMBER$patch_version_number${CN}"
  10110. # great trick from: http://ideatrash.net/2011/01/bash-string-padding-with-sed.html
  10111. # left pad: sed -e :a -e 's/^.\{1,80\}$/& /;ta'
  10112. # right pad: sed -e :a -e 's/^.\{1,80\}$/ &/;ta'
  10113. # center pad: sed -e :a -e 's/^.\{1,80\}$/ & /;ta'
  10114. #local line_max=$(( $LINE_MAX - 10 ))
  10115. #program_version="$( sed -e :a -e "s/^.\{1,$line_max\}$/ &/;ta" <<< $program_version )" # use to create padding if needed
  10116. # program_version=$( create_print_line "Version:" "$program_version" )
  10117. print_screen_output "$program_version"
  10118. }
  10119.  
  10120. print_ps_data()
  10121. {
  10122. eval $LOGFS
  10123.  
  10124. local b_print_first='true'
  10125.  
  10126. if [[ $B_SHOW_PS_CPU_DATA == 'true' ]];then
  10127. get_ps_tcm_data 'cpu'
  10128. print_ps_item 'cpu' "$b_print_first"
  10129. b_print_first='false'
  10130. fi
  10131. if [[ $B_SHOW_PS_MEM_DATA == 'true' ]];then
  10132. get_ps_tcm_data 'mem'
  10133. print_ps_item 'mem' "$b_print_first"
  10134. fi
  10135.  
  10136. eval $LOGFE
  10137. }
  10138.  
  10139. # args: $1 - cpu/mem; $2 true/false
  10140. print_ps_item()
  10141. {
  10142. eval $LOGFS
  10143. local a_ps_data='' ps_data='' line_starter='' line_start_data='' full_line=''
  10144. local app_name='' app_pid='' app_cpu='' app_mem='' throttled='' app_daemon=''
  10145. local b_print_first=$2 line_counter=0 i=0 count_nu='' extra_data=''
  10146.  
  10147. if [[ -n $PS_THROTTLED ]];then
  10148. throttled=" ${C1} - throttled from${C2} $PS_THROTTLED"
  10149. fi
  10150. case $1 in
  10151. cpu)
  10152. line_start_data="${C1}CPU - % used - top ${C2} $PS_COUNT ${C1}active$throttled "
  10153. ;;
  10154. mem)
  10155. line_start_data="${C1}Memory - MB / % used - top ${C2} $PS_COUNT ${C1}active$throttled"
  10156. ;;
  10157. esac
  10158.  
  10159. if [[ $b_print_first == 'true' ]];then
  10160. line_starter='Processes:'
  10161. else
  10162. line_starter=' '
  10163. fi
  10164.  
  10165. # appName, appPath, appStarterName, appStarterPath, cpu, mem, pid, vsz, user
  10166. ps_data=$( create_print_line "$line_starter" "$line_start_data" )
  10167. print_screen_output "$ps_data"
  10168.  
  10169. for (( i=0; i < ${#A_PS_DATA[@]}; i++ ))
  10170. do
  10171. IFS=","
  10172. a_ps_data=(${A_PS_DATA[i]})
  10173. IFS="$ORIGINAL_IFS"
  10174.  
  10175. # handle the converted app names, with ~..~ means it didn't have a path
  10176. if [[ -n $( grep -E '^~.*~$' <<< ${a_ps_data[0]} ) ]];then
  10177. app_daemon='daemon'
  10178. else
  10179. app_daemon='command'
  10180. fi
  10181.  
  10182. app_name=" ${C1}$app_daemon$SEP3${C2} ${a_ps_data[0]}"
  10183. if [[ ${a_ps_data[0]} != ${a_ps_data[2]} ]];then
  10184. app_name="$app_name ${C1}(started by$SEP3${C2} ${a_ps_data[2]}${C1})${C2}"
  10185. fi
  10186. app_pid=" ${C1}pid$SEP3${C2} ${a_ps_data[6]}"
  10187. # ${C1}user:${C2} ${a_ps_data[8]}
  10188. case $1 in
  10189. cpu)
  10190. app_cpu=" ${C1}cpu$SEP3${C2} ${a_ps_data[4]}%"
  10191. if [[ $B_EXTRA_DATA == 'true' ]];then
  10192. extra_data=" ${C1}mem$SEP3${C2} ${a_ps_data[7]}MB (${a_ps_data[5]}%)${C2}"
  10193. fi
  10194. ;;
  10195. mem)
  10196. app_mem=" ${C1}mem$SEP3${C2} ${a_ps_data[7]}MB (${a_ps_data[5]}%)${C2}"
  10197. if [[ $B_EXTRA_DATA == 'true' ]];then
  10198. extra_data=" ${C1}cpu$SEP3${C2} ${a_ps_data[4]}%"
  10199. fi
  10200. ;;
  10201. esac
  10202. (( line_counter++ ))
  10203. count_nu="${C1}$line_counter:${C2}"
  10204. full_line="$count_nu$app_cpu$app_mem$app_name$app_pid$extra_data"
  10205. ps_data=$( create_print_line " " "$full_line" )
  10206. print_screen_output "$ps_data"
  10207. done
  10208.  
  10209. eval $LOGFE
  10210. }
  10211.  
  10212. print_raid_data()
  10213. {
  10214. eval $LOGFS
  10215. local device='' device_string='' device_state='' raid_level='' device_components=''
  10216. local device_report='' u_data='' blocks='' super_blocks='' algorithm='' chunk_size=''
  10217. local bitmap_values='' recovery_progress_bar='' recovery_percent='' recovered_sectors=''
  10218. local finish_time='' recovery_speed='' raid_counter=0 device_counter=1 basic_counter=1
  10219. local a_raid_working='' raid_data='' kernel_support='' read_ahead='' unused_devices=''
  10220. local basic_raid='' basic_raid_separator='' basic_raid_plural='' inactive=''
  10221. local component_separator='' device_id='' print_string='' loop_limit=0 array_count_unused=''
  10222. local array_count='' raid_event='' b_print_lines='true'
  10223. local no_raid_detected='' dev_string='/dev/'
  10224. local empty_raid_data='' report_size='report' blocks_avail='blocks' chunk_raid_usage='chunk size'
  10225.  
  10226. if [[ -n $BSD_TYPE ]];then
  10227. no_raid_detected='No zfs software RAID detected - other types not yet supported.'
  10228. empty_raid_data='No zfs RAID data available - other types not yet supported.'
  10229. report_size='full size'
  10230. blocks_avail='available size'
  10231. chunk_raid_usage='raid allocated'
  10232. else
  10233. no_raid_detected="No RAID data available - $FILE_MDSTAT is missing - is md_mod kernel module loaded?"
  10234. empty_raid_data="No RAID devices detected - $FILE_MDSTAT and md_mod kernel raid module present"
  10235. fi
  10236.  
  10237. if [[ $BSD_TYPE == 'bsd' ]];then
  10238. dev_string=''
  10239. fi
  10240. if [[ $B_RAID_SET != 'true' ]];then
  10241. get_raid_data
  10242. fi
  10243.  
  10244. for (( i=0; i < ${#A_RAID_DATA[@]}; i++ ))
  10245. do
  10246. IFS=","
  10247. a_raid_working=(${A_RAID_DATA[i]})
  10248. IFS="$ORIGINAL_IFS"
  10249.  
  10250. # reset on each iteration
  10251. algorithm=''
  10252. bitmap_values=''
  10253. blocks=''
  10254. component_separator=''
  10255. device=''
  10256. device_components=''
  10257. device_id=''
  10258. device_report=''
  10259. device_state=''
  10260. failed=''
  10261. finish_time=''
  10262. inactive=''
  10263. raid_event=''
  10264. raid_level=''
  10265. recovery_percent=''
  10266. recovery_progress_bar=''
  10267. recovered_sectors=''
  10268. recovery_speed=''
  10269. spare=''
  10270. super_blocks=''
  10271. u_data=''
  10272.  
  10273. if [[ -n $( grep '^md' <<< ${a_raid_working[0]} ) && -z $BSD_TYPE ]] || \
  10274. [[ -n $BSD_TYPE && ${a_raid_working[0]} != '' ]];then
  10275. if [[ $B_SHOW_BASIC_RAID == 'true' ]];then
  10276. if [[ $basic_raid != '' ]];then
  10277. basic_raid_plural='s'
  10278. fi
  10279. if [[ ${a_raid_working[1]} == 'inactive' ]];then
  10280. inactive=" - ${a_raid_working[1]}"
  10281. fi
  10282. basic_raid="$basic_raid$basic_raid_separator${C1}$basic_counter${SEP3}${C2} $dev_string${a_raid_working[0]}$inactive"
  10283. basic_raid_separator=' '
  10284. (( basic_counter++ ))
  10285. else
  10286. device_id="-$device_counter"
  10287. device="$dev_string${a_raid_working[0]}"
  10288.  
  10289. (( device_counter++ ))
  10290. if [[ ${a_raid_working[1]} != '' ]];then
  10291. device_state=" - ${a_raid_working[1]}"
  10292. fi
  10293.  
  10294. if [[ ${a_raid_working[2]} == '' ]];then
  10295. raid_level='N/A'
  10296. else
  10297. raid_level=${a_raid_working[2]}
  10298. fi
  10299. # there's one case: md0 : inactive that has to be protected against
  10300. if [[ ${a_raid_working[2]} == '' && ${a_raid_working[1]} == 'inactive' ]];then
  10301. raid_level=''
  10302. else
  10303. raid_level=" ${C1}raid${SEP3}${C2} $raid_level"
  10304. fi
  10305. if [[ ${a_raid_working[4]} != '' ]];then
  10306. device_report="${a_raid_working[4]}"
  10307. else
  10308. device_report="N/A"
  10309. fi
  10310. if [[ $B_EXTRA_DATA == 'true' ]];then
  10311. if [[ ${a_raid_working[6]} != '' ]];then
  10312. blocks=${a_raid_working[6]}
  10313. else
  10314. blocks='N/A'
  10315. fi
  10316. blocks=" ${C1}$blocks_avail${SEP3}${C2} $blocks"
  10317.  
  10318. if [[ ${a_raid_working[9]} != '' ]];then
  10319. chunk_size=${a_raid_working[9]}
  10320. else
  10321. chunk_size='N/A'
  10322. fi
  10323. chunk_size=" ${C1}$chunk_raid_usage${SEP3}${C2} $chunk_size"
  10324. if [[ ${a_raid_working[10]} != '' ]];then
  10325. bitmap_value='true'
  10326. bitmap_value=" ${C1}bitmap${SEP3}${C2} $bitmap_value"
  10327. fi
  10328. fi
  10329. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  10330. if [[ ${a_raid_working[5]} != '' ]];then
  10331. u_data=" ${a_raid_working[5]}"
  10332. fi
  10333. if [[ ${a_raid_working[7]} != '' ]];then
  10334. super_blocks=" ${C1}super blocks${SEP3}${C2} ${a_raid_working[7]}"
  10335. fi
  10336. if [[ ${a_raid_working[8]} != '' ]];then
  10337. algorithm=" ${C1}algorithm${SEP3}${C2} ${a_raid_working[8]}"
  10338. fi
  10339. fi
  10340. if [[ ${a_raid_working[3]} == '' ]];then
  10341. if [[ ${a_raid_working[1]} != 'inactive' ]];then
  10342. device_components='N/A'
  10343. fi
  10344. else
  10345. for component in ${a_raid_working[3]}
  10346. do
  10347. if [[ $B_EXTRA_DATA != 'true' ]];then
  10348. component=$( sed 's/\[[0-9]\+\]//' <<< $component )
  10349. fi
  10350. # NOTE: for bsd zfs, states are: ONLINE,DEGRADED,OFFLINE (at least)
  10351. if [[ -n $( grep -E '(F|DEGRADED)' <<< $component ) ]];then
  10352. component=$( sed -e 's/(F)//' -e 's/F//' -e 's/DEGRADED//' <<< $component )
  10353. failed="$failed $component"
  10354. component=''
  10355. elif [[ -n $( grep -E '(S|OFFLINE)' <<< $component ) ]];then
  10356. component=$( sed -e 's/(S)//' -e 's/S//' -e 's/OFFLINE//' <<< $component )
  10357. spare="$spare $component"
  10358. component=''
  10359. else
  10360. device_components="$device_components$component_separator$component"
  10361. component_separator=' '
  10362. fi
  10363. done
  10364.  
  10365. if [[ $failed != '' ]];then
  10366. failed=" ${C1}FAILED${SEP3}${C2}$failed${C2}"
  10367. fi
  10368. if [[ $spare != '' ]];then
  10369. spare=" ${C1}spare${SEP3}${C2}$spare${C2}"
  10370. fi
  10371.  
  10372. if [[ -n $device_components || -n $spare || -n $failed ]];then
  10373. if [[ $B_EXTRA_DATA != 'true' && -z $BSD_TYPE ]];then
  10374. if [[ $device_report != 'N/A' && -n $device_components ]];then
  10375. device_components="$device_report - $device_components"
  10376. fi
  10377. fi
  10378. if [[ $device_components == '' ]];then
  10379. device_components='none'
  10380. fi
  10381. device_components="${C1}online${SEP3}${C2} $device_components"
  10382. device_components=" ${C1}components${SEP3}${C2} $device_components$failed$spare"
  10383. fi
  10384. fi
  10385. a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components"
  10386.  
  10387. if [[ $B_EXTRA_DATA == 'true' && ${a_raid_working[1]} != 'inactive' ]];then
  10388. a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$device_components"
  10389. (( raid_counter++ ))
  10390. print_string="${C1}Info${SEP3}${C2}$raid_level ${C1}$report_size${SEP3}${C2} $device_report$u_data"
  10391. print_string="$print_string$blocks$chunk_size$bitmap_value$super_blocks$algorithm"
  10392. a_raid_data[$raid_counter]="$print_string"
  10393. else
  10394. a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components"
  10395. fi
  10396. (( raid_counter++ ))
  10397.  
  10398. # now let's do the recover line if required
  10399. if [[ ${a_raid_working[12]} != '' ]];then
  10400. recovery_percent=$( cut -d '~' -f 2 <<< ${a_raid_working[12]} )
  10401. if [[ ${a_raid_working[14]} != '' ]];then
  10402. finish_time=${a_raid_working[14]}
  10403. else
  10404. finish_time='N/A'
  10405. fi
  10406. finish_time=" ${C1}time remaining${SEP3}${C2} $finish_time"
  10407. if [[ $B_EXTRA_DATA == 'true' ]];then
  10408. if [[ ${a_raid_working[13]} != '' ]];then
  10409. recovered_sectors=" ${C1}sectors${SEP3}${C2} ${a_raid_working[13]}"
  10410. fi
  10411. fi
  10412. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  10413. if [[ ${a_raid_working[11]} != '' ]];then
  10414. recovery_progress_bar=" ${a_raid_working[11]}"
  10415. fi
  10416. if [[ ${a_raid_working[15]} != '' ]];then
  10417. recovery_speed=" ${C1}speed${SEP3}${C2} ${a_raid_working[15]}"
  10418. fi
  10419. fi
  10420.  
  10421. a_raid_data[$raid_counter]="${C1}Recovering${SEP3}${C2} $recovery_percent$recovery_progress_bar$recovered_sectors$finish_time$recovery_speed"
  10422. (( raid_counter++ ))
  10423. fi
  10424. fi
  10425. elif [[ ${a_raid_working[0]} == 'KernelRaidSupport' ]];then
  10426. if [[ ${a_raid_working[1]} == '' ]];then
  10427. kernel_support='N/A'
  10428. else
  10429. kernel_support=${a_raid_working[1]}
  10430. fi
  10431. kernel_support=" ${C1}supported${SEP3}${C2} $kernel_support"
  10432. elif [[ ${a_raid_working[0]} == 'ReadAhead' ]];then
  10433. if [[ ${a_raid_working[1]} != '' ]];then
  10434. read_ahead=${a_raid_working[1]}
  10435. read_ahead=" ${C1}read ahead${SEP3}${C2} $read_ahead"
  10436. fi
  10437. elif [[ ${a_raid_working[0]} == 'UnusedDevices' ]];then
  10438. if [[ ${a_raid_working[1]} == '' ]];then
  10439. unused_devices='N/A'
  10440. else
  10441. unused_devices=${a_raid_working[1]}
  10442. fi
  10443. unused_devices="${C1}Unused Devices${SEP3}${C2} $unused_devices"
  10444. elif [[ ${a_raid_working[0]} == 'raidEvent' ]];then
  10445. if [[ ${a_raid_working[1]} != '' ]];then
  10446. raid_event=${a_raid_working[1]}
  10447. raid_event=" ${C1}Raid Event${SEP3}${C2} ${a_raid_working[1]}"
  10448. fi
  10449. fi
  10450. done
  10451.  
  10452. if [[ $B_SHOW_BASIC_RAID == 'true' && $basic_raid != '' ]];then
  10453. a_raid_data[0]="${C1}Device$basic_raid_plural${SEP3}${C2} $basic_raid"
  10454. fi
  10455. # note bsd temp test hack to make it run
  10456. if [[ $B_MDSTAT_FILE != 'true' && -z $BSD_TYPE ]] || \
  10457. [[ -n $BSD_TYPE && $B_BSD_RAID == 'false' ]];then
  10458. if [[ $B_SHOW_RAID_R == 'true' ]];then
  10459. a_raid_data[0]="$no_raid_detected"
  10460. else
  10461. b_print_lines='false'
  10462. fi
  10463. else
  10464. if [[ ${a_raid_data[0]} == '' ]];then
  10465. if [[ $B_SHOW_BASIC_RAID != 'true' ]];then
  10466. a_raid_data[0]="$empty_raid_data"
  10467. else
  10468. b_print_lines='false'
  10469. fi
  10470. fi
  10471. # now let's add on the system line and the unused device line. Only print on -xx
  10472. if [[ $kernel_support$read_ahead$raid_event != '' ]];then
  10473. array_count=${#a_raid_data[@]}
  10474. a_raid_data[array_count]="${C1}System${SEP3}${C2}$kernel_support$read_ahead$raid_event"
  10475. loop_limit=1
  10476. fi
  10477. if [[ $unused_devices != '' ]];then
  10478. array_count_unused=${#a_raid_data[@]}
  10479. a_raid_data[array_count_unused]="$unused_devices"
  10480. loop_limit=2
  10481. fi
  10482. fi
  10483.  
  10484. # we don't want to print anything if it's -b and no data is present, just a waste of a line
  10485. if [[ $b_print_lines == 'true' ]];then
  10486. # print out all lines, line starter on first line
  10487. for (( i=0; i < ${#a_raid_data[@]} - $loop_limit;i++ ))
  10488. do
  10489. if [[ $i -eq 0 ]];then
  10490. line_starter='RAID:'
  10491. else
  10492. line_starter=' '
  10493. fi
  10494. if [[ $B_EXTRA_EXTRA_DATA == 'true' && $array_count != '' ]];then
  10495. if [[ $i == 0 ]];then
  10496. raid_data=$( create_print_line "$line_starter" "${a_raid_data[array_count]}" )
  10497. print_screen_output "$raid_data"
  10498. line_starter=' '
  10499. fi
  10500. fi
  10501. raid_data=$( create_print_line "$line_starter" "${a_raid_data[i]}" )
  10502. print_screen_output "$raid_data"
  10503. if [[ $B_EXTRA_EXTRA_DATA == 'true' && $array_count_unused != '' ]];then
  10504. if [[ $i == $(( array_count_unused - 2 )) ]];then
  10505. raid_data=$( create_print_line "$line_starter" "${a_raid_data[array_count_unused]}" )
  10506. print_screen_output "$raid_data"
  10507. fi
  10508. fi
  10509. done
  10510. fi
  10511.  
  10512. eval $LOGFE
  10513. }
  10514.  
  10515. # currently only apt using distros support this feature, but over time we can add others
  10516. print_repo_data()
  10517. {
  10518. eval $LOGFS
  10519. local repo_count=0 repo_line='' file_name='' file_content='' file_name_holder=''
  10520. local repo_full='' b_print_next_line='false' repo_type=''
  10521.  
  10522. get_repo_data
  10523.  
  10524. if [[ -n $REPO_DATA ]];then
  10525. # loop through the variable's lines one by one, update counter each iteration
  10526. while read repo_line
  10527. do
  10528. (( repo_count++ ))
  10529. repo_type=$( cut -d ':' -f 1 <<< $repo_line )
  10530. file_name=$( cut -d ':' -f 2 <<< $repo_line )
  10531. file_content=$( cut -d ':' -f 3-7 <<< $repo_line )
  10532. # this will dump unwanted white space line starters. Some irc channels
  10533. # use bots that show page title for urls, so need to break the url by adding
  10534. # a white space.
  10535. if [[ $B_RUNNING_IN_SHELL != 'true' ]];then
  10536. file_content=$( echo $file_content | sed 's|://|: //|' )
  10537. else
  10538. file_content=$( echo $file_content )
  10539. fi
  10540. # echo $file_name : $file_name_holder : $repo_type : $file_content
  10541. # check file name, if different, update the holder for print out
  10542. if [[ $file_name != $file_name_holder ]];then
  10543. if [[ $repo_type == 'pisi repo' || $repo_type == 'urpmq repo' ]];then
  10544. repo_full="${C1}$repo_type:${C2} $file_name"
  10545. else
  10546. repo_full="${C1}Active $repo_type in file:${C2} $file_name"
  10547. fi
  10548. file_name_holder=$file_name
  10549. b_print_next_line='true'
  10550. else
  10551. repo_full=$file_content
  10552. fi
  10553. # first line print Repos:
  10554. if [[ $repo_count -eq 1 ]];then
  10555. repo_full=$( create_print_line "Repos:" "$repo_full" )
  10556. else
  10557. repo_full=$( create_print_line " " "$repo_full" )
  10558. fi
  10559. print_screen_output "$repo_full"
  10560. # this prints the content of the file as well as the file name
  10561. if [[ $b_print_next_line == 'true' ]];then
  10562. repo_full=$( create_print_line " " "$file_content" )
  10563. print_screen_output "$repo_full"
  10564. b_print_next_line='false'
  10565. fi
  10566. done <<< "$REPO_DATA"
  10567. else
  10568. repo_full=$( create_print_line "Repos:" "${C1}Error:${C2} $SCRIPT_NAME does not support this feature for your distro yet." )
  10569. print_screen_output "$repo_full"
  10570. fi
  10571. eval $LOGFE
  10572. }
  10573.  
  10574. print_sensors_data()
  10575. {
  10576. eval $LOGFS
  10577. local mobo_temp='' cpu_temp='' psu_temp='' cpu_fan='' mobo_fan='' ps_fan='' sys_fans='' sys_fans2=''
  10578. local temp_data='' fan_data='' fan_data2='' b_is_error='false' fan_count=0 gpu_temp=''
  10579. local a_sensors_working=''
  10580. local no_sensors_message='None detected - is lm-sensors installed and configured?'
  10581. local Sensors_Data="$( get_sensors_output )"
  10582. get_sensors_data
  10583.  
  10584. if [[ $BSD_TYPE == 'bsd' ]];then
  10585. no_sensors_message='This feature is not yet supported for BSD systems.'
  10586. fi
  10587.  
  10588. IFS=","
  10589. a_sensors_working=( ${A_SENSORS_DATA[0]} )
  10590. IFS="$ORIGINAL_IFS"
  10591. # initial error cases, for missing app or unconfigured sensors. Note that array 0
  10592. # always has at least 3 items, cpu/mobo/psu temp in it. If the count is 0, then
  10593. # no sensors are installed/configured
  10594. if [[ ${#a_sensors_working[@]} -eq 0 ]];then
  10595. cpu_temp=$no_sensors_message
  10596. b_is_error='true'
  10597. else
  10598. for (( i=0; i < ${#A_SENSORS_DATA[@]}; i++ ))
  10599. do
  10600. IFS=","
  10601. a_sensors_working=( ${A_SENSORS_DATA[i]} )
  10602. IFS="$ORIGINAL_IFS"
  10603. case $i in
  10604. # first the temp data
  10605. 0)
  10606. if [[ -n ${a_sensors_working[0]} ]];then
  10607. cpu_temp=${a_sensors_working[0]}
  10608. else
  10609. cpu_temp='N/A'
  10610. fi
  10611. cpu_temp="${C1}System Temperatures: cpu$SEP3${C2} $cpu_temp "
  10612.  
  10613. if [[ -n ${a_sensors_working[1]} ]];then
  10614. mobo_temp=${a_sensors_working[1]}
  10615. else
  10616. mobo_temp='N/A'
  10617. fi
  10618. mobo_temp="${C1}mobo$SEP3${C2} $mobo_temp "
  10619.  
  10620. if [[ -n ${a_sensors_working[2]} ]];then
  10621. psu_temp="${C1}psu$SEP3${C2} ${a_sensors_working[2]} "
  10622. fi
  10623. gpu_temp=$( get_gpu_temp_data )
  10624. # dump the unneeded screen data for single gpu systems
  10625. if [[ $( wc -w <<< $gpu_temp ) -eq 1 && $B_EXTRA_DATA != 'true' ]];then
  10626. gpu_temp=$( cut -d ':' -f 2 <<< $gpu_temp )
  10627. fi
  10628. if [[ -n $gpu_temp ]];then
  10629. gpu_temp="${C1}gpu$SEP3${C2} ${gpu_temp} "
  10630. fi
  10631. ;;
  10632. # then the fan data from main fan array
  10633. 1)
  10634. for (( j=0; j < ${#a_sensors_working[@]}; j++ ))
  10635. do
  10636. case $j in
  10637. 0)
  10638. # we need to make sure it's either cpu fan OR cpu fan and sys fan 1
  10639. if [[ -n ${a_sensors_working[0]} ]];then
  10640. cpu_fan="${a_sensors_working[0]}"
  10641. elif [[ -z ${a_sensors_working[0]} && -n ${a_sensors_working[1]} ]];then
  10642. cpu_fan="${a_sensors_working[1]}"
  10643. else
  10644. cpu_fan='N/A'
  10645. fi
  10646. cpu_fan="${C1}Fan Speeds (in rpm): cpu$SEP3${C2} $cpu_fan "
  10647. (( fan_count++ ))
  10648. ;;
  10649. 1)
  10650. if [[ -n ${a_sensors_working[1]} ]];then
  10651. mobo_fan="${C1}mobo$SEP3${C2} ${a_sensors_working[1]} "
  10652. (( fan_count++ ))
  10653. fi
  10654. ;;
  10655. 2)
  10656. if [[ -n ${a_sensors_working[2]} ]];then
  10657. ps_fan="${C1}psu$SEP3${C2} ${a_sensors_working[2]} "
  10658. (( fan_count++ ))
  10659. fi
  10660. ;;
  10661. [3-9]|[1-9][0-9])
  10662. if [[ -n ${a_sensors_working[$j]} ]];then
  10663. fan_number=$(( $j - 2 )) # sys fans start on array key 5
  10664. # wrap after fan 6 total
  10665. if [[ $fan_count -lt 7 ]];then
  10666. sys_fans="$sys_fans${C1}sys-$fan_number$SEP3${C2} ${a_sensors_working[$j]} "
  10667. else
  10668. sys_fans2="$sys_fans2${C1}sys-$fan_number$SEP3${C2} ${a_sensors_working[$j]} "
  10669. fi
  10670. (( fan_count++ ))
  10671. fi
  10672. ;;
  10673. esac
  10674. done
  10675. ;;
  10676. 2)
  10677. for (( j=0; j < ${#a_sensors_working[@]}; j++ ))
  10678. do
  10679. case $j in
  10680. [0-9]|[1-9][0-9])
  10681. if [[ -n ${a_sensors_working[$j]} ]];then
  10682. fan_number=$(( $j + 1 )) # sys fans start on array key 5
  10683. # wrap after fan 6 total
  10684. if [[ $fan_count -lt 7 ]];then
  10685. sys_fans="$sys_fans${C1}fan-$fan_number$SEP3${C2} ${a_sensors_working[$j]} "
  10686. else
  10687. sys_fans2="$sys_fans2${C1}fan-$fan_number$SEP3${C2} ${a_sensors_working[$j]} "
  10688. fi
  10689. (( fan_count++ ))
  10690. fi
  10691. ;;
  10692. esac
  10693. done
  10694. ;;
  10695. esac
  10696. done
  10697. fi
  10698. # turning off all output for case where no sensors detected or no sensors output
  10699. # unless -s used explicitly. So for -F type output won't show unless valid or -! 1 used
  10700. if [[ $b_is_error != 'true' || $B_SHOW_SENSORS == 'true' || $B_TESTING_1 == 'true' ]];then
  10701. temp_data="$cpu_temp$mobo_temp$psu_temp$gpu_temp"
  10702. temp_data=$( create_print_line "Sensors:" "$temp_data" )
  10703. print_screen_output "$temp_data"
  10704. # don't print second or subsequent lines if error data
  10705. fan_data="$cpu_fan$mobo_fan$ps_fan$sys_fans"
  10706. if [[ $b_is_error != 'true' && -n $fan_data ]];then
  10707. fan_data=$( create_print_line " " "$fan_data" )
  10708. print_screen_output "$fan_data"
  10709. # and then second wrapped fan line if needed
  10710. if [[ -n $sys_fans2 ]];then
  10711. fan_data2=$( create_print_line " " "$sys_fans2" )
  10712. print_screen_output "$fan_data2"
  10713. fi
  10714. fi
  10715. fi
  10716. eval $LOGFE
  10717. }
  10718.  
  10719. print_system_data()
  10720. {
  10721. eval $LOGFS
  10722. local system_data='' bits='' desktop_environment='' dm_data='' de_extra_data=''
  10723. local host_kernel_string='' de_distro_string='' host_string='' desktop_type='Desktop'
  10724. local host_name=$HOSTNAME
  10725. local current_kernel=$( get_kernel_version )
  10726. local distro="$( get_distro_data )"
  10727. local tty_session=''
  10728.  
  10729. # I think these will work, maybe, if logged in as root and in X
  10730. if [[ $B_RUNNING_IN_X == 'true' ]];then
  10731. desktop_environment=$( get_desktop_environment )
  10732. if [[ -z $desktop_environment ]];then
  10733. desktop_environment='N/A'
  10734. fi
  10735.  
  10736. if [[ $B_EXTRA_EXTRA_EXTRA_DATA == 'true' ]];then
  10737. de_extra_data=$( get_desktop_extra_data )
  10738. if [[ -n $de_extra_data ]];then
  10739. de_extra_data=" ${C1}info$SEP3${C2} $de_extra_data"
  10740. fi
  10741. fi
  10742. else
  10743. tty_session=$( get_tty_number )
  10744. if [[ -z $tty_session && $B_CONSOLE_IRC == 'true' ]];then
  10745. tty_session=$( get_tty_console_irc )
  10746. fi
  10747. if [[ -n $tty_session ]];then
  10748. tty_session=" $tty_session"
  10749. fi
  10750. desktop_environment="tty$tty_session"
  10751. desktop_type='Console'
  10752. fi
  10753. # having dm type can be useful if you are accessing remote system
  10754. # or are out of X and don't remember which dm is running the system
  10755. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  10756. dm_data=$( get_display_manager )
  10757. # here we only want the dm info to show N/A if in X
  10758. if [[ -z $dm_data && $B_RUNNING_IN_X == 'true' ]];then
  10759. dm_data='N/A'
  10760. fi
  10761. # only print out of X if dm_data has info, then it's actually useful, but
  10762. # for headless servers, no need to print dm stuff.
  10763. if [[ -n $dm_data ]];then
  10764. dm_data=" ${C1}dm$SEP3${C2} $dm_data"
  10765. fi
  10766. fi
  10767.  
  10768. de_distro_string="${C1}$desktop_type$SEP3${C2} $desktop_environment$de_extra_data$dm_data ${C1}Distro$SEP3${C2} $distro"
  10769. if [[ $B_EXTRA_DATA == 'true' ]];then
  10770. gcc_string=$( get_gcc_kernel_version )
  10771. if [[ -n $gcc_string ]];then
  10772. gcc_string=", ${C1}gcc$SEP3${C2} $gcc_string"
  10773. fi
  10774. fi
  10775. # check for 64 bit first
  10776. if [[ -n $( uname -m | grep -E '(x86_64|amd64)' ) ]];then
  10777. bits="64"
  10778. else
  10779. bits="32"
  10780. fi
  10781. bits=" (${bits} bit${gcc_string})"
  10782. if [[ $B_SHOW_HOST == 'true' ]];then
  10783. if [[ -z $HOSTNAME ]];then
  10784. if [[ -n $( type p hostname ) ]];then
  10785. host_name=$( hostname )
  10786. fi
  10787. if [[ -z $host_name ]];then
  10788. host_name='N/A'
  10789. fi
  10790. fi
  10791. host_string="${C1}Host$SEP3${C2} $host_name "
  10792. system_data=$( create_print_line "System:" "$host_string$host_name ${C1}Kernel$SEP3${C2}" )
  10793. fi
  10794. host_kernel_string="$host_string${C1}Kernel$SEP3${C2} $current_kernel$bits "
  10795. if [[ $( calculate_line_length "$host_kernel_string$de_distro_string" ) -lt $LINE_MAX ]];then
  10796. system_data="$host_kernel_string$de_distro_string"
  10797. system_data=$( create_print_line "System:" "$system_data" )
  10798. else
  10799. system_data=$( create_print_line "System:" "$host_kernel_string" )
  10800. print_screen_output "$system_data"
  10801. system_data=$( create_print_line " " "$de_distro_string" )
  10802. fi
  10803. print_screen_output "$system_data"
  10804. eval $LOGFE
  10805. }
  10806.  
  10807. print_unmounted_partition_data()
  10808. {
  10809. eval $LOGFS
  10810. local a_unmounted_data='' line_starter='' unmounted_data='' full_fs=''
  10811. local full_dev='' full_size='' full_label='' full_uuid='' full_string=''
  10812. local bsd_unsupported='This feature is not yet supported for BSD systems.'
  10813.  
  10814. if [[ -z ${A_PARTITION_DATA} ]];then
  10815. get_partition_data
  10816. fi
  10817. get_unmounted_partition_data
  10818.  
  10819. if [[ ${#A_UNMOUNTED_PARTITION_DATA[@]} -ge 1 ]];then
  10820. for (( i=0; i < ${#A_UNMOUNTED_PARTITION_DATA[@]}; i++ ))
  10821. do
  10822. IFS=","
  10823. a_unmounted_data=(${A_UNMOUNTED_PARTITION_DATA[i]})
  10824. IFS="$ORIGINAL_IFS"
  10825. if [[ -z ${a_unmounted_data[0]} ]];then
  10826. full_dev='N/A'
  10827. else
  10828. full_dev="/dev/${a_unmounted_data[0]}"
  10829. fi
  10830. full_dev="${C1}ID:${C2} $full_dev"
  10831. if [[ -z ${a_unmounted_data[1]} ]];then
  10832. full_size='N/A'
  10833. else
  10834. full_size=${a_unmounted_data[1]}
  10835. fi
  10836. full_size="${C1}size$SEP3${C2} $full_size"
  10837. if [[ -z ${a_unmounted_data[2]} ]];then
  10838. full_label='N/A'
  10839. else
  10840. full_label=${a_unmounted_data[2]}
  10841. fi
  10842. full_label="${C1}label$SEP3${C2} $full_label"
  10843. if [[ -z ${a_unmounted_data[3]} ]];then
  10844. full_uuid='N/A'
  10845. else
  10846. full_uuid=${a_unmounted_data[3]}
  10847. fi
  10848. full_uuid="${C1}uuid$SEP3${C2} $full_uuid"
  10849. if [[ -z ${a_unmounted_data[4]} ]];then
  10850. full_fs=''
  10851. else
  10852. full_fs="${C1}fs$SEP3${C2} ${a_unmounted_data[4]}"
  10853. fi
  10854. full_string="$full_dev $full_size $full_label $full_uuid $full_fs"
  10855. if [[ $i -eq 0 ]];then
  10856. line_starter='Unmounted:'
  10857. else
  10858. line_starter=' '
  10859. fi
  10860. # temporary message to indicate not yet supported
  10861. if [[ $BSD_TYPE == 'bsd' ]];then
  10862. full_string=$bsd_unsupported
  10863. fi
  10864. unmounted_data=$( create_print_line "$line_starter" "$full_string" )
  10865. print_screen_output "$unmounted_data"
  10866. done
  10867. else
  10868. unmounted_data=$( create_print_line "Unmounted:" "No unmounted partitions detected" )
  10869. print_screen_output "$unmounted_data"
  10870. fi
  10871.  
  10872. eval $LOGFE
  10873. }
  10874.  
  10875. print_weather_data()
  10876. {
  10877. eval $LOGFS
  10878.  
  10879. local weather_data='' location_string='' local_time='' time_string='' pressure=''
  10880. local a_location='' a_weather='' weather_string='' weather='' temp='' winds='' humidity=''
  10881. local time_zone='' observation_time='' city='' state='' country='' altitude=''
  10882. local heat_index="" wind_chill='' dewpoint='' xxx_humidity=''
  10883. local openP='(' closeP=')'
  10884.  
  10885. if [[ $B_RUNNING_IN_SHELL == 'false' ]];then
  10886. openP=''
  10887. closeP=''
  10888. fi
  10889.  
  10890. get_weather_data
  10891.  
  10892. # city ";" regionCode ";" regionName ";" countryName ";" countryCode ";" countryCode3
  10893. # ";" latitude "," longitude ";" postalCode ";" timeZone
  10894.  
  10895. # observationTime ";" localTime ";" weather ";" tempString ";" humidity
  10896. # ";" windString ";" pressureString ";" dewpointString ";" heatIndexString
  10897. # ";" windChillString ";" siteElevation
  10898.  
  10899. if [[ ${#A_WEATHER_DATA[@]} -eq 2 ]];then
  10900. IFS=";"
  10901. a_location=(${A_WEATHER_DATA[0]})
  10902. a_weather=(${A_WEATHER_DATA[1]})
  10903. IFS="$ORIGINAL_IFS"
  10904.  
  10905. if [[ -n ${a_weather[3]} ]];then
  10906. temp=${a_weather[3]}
  10907. else
  10908. temp='N/A'
  10909. fi
  10910. if [[ -n ${a_weather[2]} ]];then
  10911. weather=" - ${a_weather[2]}"
  10912. else
  10913. weather=''
  10914. fi
  10915. if [[ $B_EXTRA_DATA == 'true' ]];then
  10916. if [[ -n ${a_weather[5]} ]];then
  10917. winds=" ${C1}Wind$SEP3${C2} ${a_weather[5]}"
  10918. fi
  10919. fi
  10920. if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
  10921. if [[ -n ${a_weather[4]} ]];then
  10922. humidity=" ${C1}Humidity$SEP3${C2} ${a_weather[4]}"
  10923. fi
  10924. if [[ -n ${a_weather[6]} ]];then
  10925. pressure="${C1}Pressure$SEP3${C2} ${a_weather[6]} "
  10926. fi
  10927. fi
  10928. weather_string="${C1}Conditions$SEP3${C2} $temp$weather$winds$humidity"
  10929.  
  10930. if [[ -n ${a_weather[1]} ]];then
  10931. local_time=" ${a_weather[1]}"
  10932. else
  10933. local_time=" $(date)"
  10934. fi
  10935. if [[ $B_EXTRA_DATA == 'true' && -n ${a_location[8]} ]];then
  10936. time_zone=" (${a_location[8]})"
  10937. fi
  10938. time_string="${C1}Time$SEP3${C2}$local_time$time_zone"
  10939.  
  10940. if [[ $B_EXTRA_DATA != 'true' ]];then
  10941. weather_data="$weather_string $time_string"
  10942. weather_data=$( create_print_line "Weather:" "$weather_data" )
  10943. print_screen_output "$weather_data"
  10944. else
  10945. weather_data="$weather_string"
  10946. weather_data=$( create_print_line "Weather:" "$weather_data" )
  10947. print_screen_output "$weather_data"
  10948. if [[ $B_EXTRA_EXTRA_EXTRA_DATA == 'true' ]];then
  10949. if [[ -n ${a_weather[8]} ]];then
  10950. heat_index="${C1}Heat Index$SEP3${C2} ${a_weather[8]} "
  10951. fi
  10952. if [[ -n ${a_weather[9]} ]];then
  10953. wind_chill="${C1}Wind Chill$SEP3${C2} ${a_weather[9]} "
  10954. fi
  10955. if [[ -n ${a_weather[7]} ]];then
  10956. dew_point="${C1}Dew Point$SEP3${C2} ${a_weather[7]} "
  10957. fi
  10958. if [[ -n ${a_weather[0]} ]];then
  10959. observation_time=" ${C1}Observation Time$SEP3${C2} ${a_weather[0]} "
  10960. fi
  10961. if [[ $B_OUTPUT_FILTER != 'true' ]];then
  10962. if [[ -n ${a_location[0]} ]];then
  10963. city=" ${a_location[0]}"
  10964. fi
  10965. if [[ -n ${a_location[1]} ]];then
  10966. state=" ${a_location[1]}"
  10967. fi
  10968. if [[ -n ${a_location[5]} ]];then
  10969. country=" $openP${a_location[5]}$closeP"
  10970. fi
  10971. if [[ -n ${a_weather[10]} ]];then
  10972. altitude=" ${C1}Altitude$SEP3${C2} ${a_weather[10]}"
  10973. fi
  10974. location_string="${C1}Location$SEP3${C2}$city$state$country$altitude "
  10975. else
  10976. location_string=$time_string$observation_time
  10977. time_string=''
  10978. observation_time=''
  10979. fi
  10980. # the last three are oftenblank
  10981. if [[ -z "$heat_index$wind_chill$dew_point" ]];then
  10982. weather_data=$( create_print_line " " "$pressure$location_string" )
  10983. print_screen_output "$weather_data"
  10984. else
  10985. weather_data=$( create_print_line " " "$pressure$heat_index$wind_chill$dew_point" )
  10986. print_screen_output "$weather_data"
  10987. if [[ $B_OUTPUT_FILTER != 'true' ]];then
  10988. weather_data=$( create_print_line " " "$location_string" )
  10989. print_screen_output "$weather_data"
  10990. fi
  10991. fi
  10992. if [[ -n $time_string$observation_time ]];then
  10993. weather_data=$( create_print_line " " "$time_string$observation_time" )
  10994. print_screen_output "$weather_data"
  10995. fi
  10996. else
  10997. if [[ -n $pressure$time_string ]];then
  10998. weather_data="$pressure$time_string"
  10999. weather_data=$( create_print_line " " "$weather_data" )
  11000. print_screen_output "$weather_data"
  11001. fi
  11002. fi
  11003. fi
  11004. else
  11005. weather_data=$( create_print_line "Weather:" "Weather data failure: $(date)" )
  11006. print_screen_output "$weather_data"
  11007. weather_data=$( create_print_line " " "${A_WEATHER_DATA}" )
  11008. print_screen_output "$weather_data"
  11009. fi
  11010. eval $LOGFE
  11011. }
  11012.  
  11013. ########################################################################
  11014. #### SCRIPT EXECUTION
  11015. ########################################################################
  11016.  
  11017. main $@ ## From the End comes the Beginning
  11018.  
  11019. ## note: this EOF is needed for smxi handling, this is what triggers the full download ok
  11020. ###**EOF**###
Advertisement
Add Comment
Please, Sign In to add comment