From 3ebdd7404e4e6504e875b3444f30297d63b8f33a Mon Sep 17 00:00:00 2001 From: Michael Marley Date: Mon, 6 Jun 2016 17:46:02 -0400 Subject: [PATCH] Update inxi to version 2.3.0 Closes GH-204. (cherry picked from commit 83923d7c121dbcf514d4ff5b0ac2abb6eb08c6b9) --- data/scripts/inxi | 6399 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 4852 insertions(+), 1547 deletions(-) mode change 100755 => 100644 data/scripts/inxi diff --git a/data/scripts/inxi b/data/scripts/inxi old mode 100755 new mode 100644 index 0c55bb8e..fc9550f7 --- a/data/scripts/inxi +++ b/data/scripts/inxi @@ -1,8 +1,8 @@ #!/usr/bin/env bash ######################################################################## #### Script Name: inxi -#### Version: 2.1.2 -#### Date: 2014-03-14 +#### Version: 2.3.0 +#### Date: 2016-04-18 #### Patch Number: 00 ######################################################################## #### SPECIAL THANKS @@ -20,14 +20,19 @@ #### Gaim/Pidgin, Weechat, KVIrc and Kopete. #### Original infobash author and copyright holder: #### Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif -#### inxi version: Copyright (C) 2008-2014 Scott Rogers & Harald Hope +#### inxi version: Copyright (C) 2008-2016 Scott Rogers & Harald Hope #### Further fixes (listed as known): Horst Tritremmel #### Steven Barrett (aka: damentz) - usb audio patch; swap percent used patch #### Jarett.Stevens - dmidecde -M patch for older systems with the /sys #### -#### Current script home page/wiki/svn: http://inxi.googlecode.com +#### Current script home page/wiki/git: https://github.com/smxi/inxi +#### Documentation/wiki pages will move to http://smxi.org soon. #### Script forums: http://techpatterns.com/forums/forum-33.html #### IRC support: irc.oftc.net channel #smxi +#### Version control: +#### * https://github.com/smxi/inxi +#### * git: git pull https://github.com/smxi/inxi master +#### * svn checkout url: https://github.com/smxi/inxi #### #### This program is free software; you can redistribute it and/or modify #### it under the terms of the GNU General Public License as published by @@ -45,6 +50,9 @@ #### If you don't understand what Free Software is, please read (or reread) #### this page: http://www.gnu.org/philosophy/free-sw.html ######################################################################## + +#### +#### PACKAGE NAME NOTES #### * Package names in (...) are the Debian Squeeze package name. Check your #### distro for proper package name by doing this: which #### then find what package owns that application file. Or run --recommends @@ -53,8 +61,8 @@ #### DEPENDENCIES #### * bash >=3.0 (bash); df, readlink, stty, tr, uname, wc (coreutils); #### gawk (gawk); grep (grep); lspci (pciutils); -#### ps, uptime (procps); find (findutils) -#### * Also the proc filesystem should be present and mounted +#### ps, find (findutils) +#### * Also the proc filesystem should be present and mounted for Linux #### * Some features, like -M and -d will not work, or will work incompletely, #### if /sys is missing #### @@ -74,7 +82,9 @@ #### -G - full graphics output requires: glxinfo (mesa-utils); xdpyinfo (X11-utils); #### xrandr (x11-xserver-utils) #### -i - IP information, local/wan - ip (iproute) legacy, not used if ip present: ifconfig (net-tools) +#### -I - uptime (procps, check Debian if changed) #### -Ix - view current runlevel while not in X window system (or with -x): runlevel (sysvinit) +#### -m - all systems, dmidecode, unless someone can find a better way. #### -M - for older systems whose kernel does not have /sys data for machine, dmidecode (dmidecode) #### -o - for unmounted file system information in unmounted drives (root only default): file (file) #### Note: requires user action for this feature to run as user (edit /etc/sudoers file) @@ -108,12 +118,17 @@ #### * Note: [[ -n $something ]] - double brackets does not require quotes for variables: ie, "$something". #### * Always use quotes, double or single, for all string values. #### * All new code/methods must be in a function. + #### * For all boolean tests, use 'true' / 'false'. #### !! Do NOT use 0 or 1 unless it's a function return. #### * Avoid complicated tests in the if condition itself. #### * To 'return' a value in a function, use 'echo '. #### * For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks #### This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc +#### * Using ${VAR} is about 30% slower than $VAR because bash has to check the stuff for actions +#### SUBSHELLS ARE EXPENSIVE! - run these two if you do not believe me. +#### time for (( i=0; i<1000; i++ )) do ff='/usr/local/bin/foo.pid';ff=${ff##*/};ff=${ff%.*};done;echo $ff +#### time for (( i=0; i<1000; i++ )) do ff='/usr/local/bin/foo.pid';ff=$( basename $ff | cut -d '.' -f 1 );done;echo $ff #### #### VARIABLE/FUNCTION NAMING: #### * All functions should follow standard naming--verb adjective noun. @@ -139,7 +154,7 @@ #### ln -s /usr/share/apps/konversation/scripts/inxi #### DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages. #### * print_screen_output " " # requires space, not null, to avoid error in for example in irssi -#### * For logging of array data, array must be placed into the temp_array, otherwise only the first key logs +#### * For logging of array data, array must be placed into the a_temp, otherwise only the first key logs #### * In gawk search patterns, . is a wildcard EXCEPT in [0-9.] type containers, then it's a literal #### So outside of bracketed items, it must be escaped, \. but inside, no need. Outside of gawk it should #### be escaped in search patterns if you are using it as a literal. @@ -211,9 +226,12 @@ FILTER_STRING='' # widths will be dynamically set in main() based on cols in term/console COLS_MAX_CONSOLE='115' COLS_MAX_IRC='105' +# note, this is console out of x/display server, will also be set dynamically +# not used currently, but maybe in future +COLS_MAX_NO_DISPLAY='140' PS_COUNT=5 # change to less, or more if you have very slow connection -WGET_TIMEOUT=8 +DL_TIMEOUT=8 ### END USER CONFIGS ### ### LOCALIZATION - DO NOT CHANGE! ### @@ -236,6 +254,7 @@ ORIGINAL_IFS="$IFS" ## Initialize A_ALSA_DATA='' A_AUDIO_DATA='' +A_BATTERY_DATA='' A_CMDL='' A_CPU_CORE_DATA='' A_CPU_DATA='' @@ -249,6 +268,7 @@ A_HDD_DATA='' A_INIT_DATA='' A_INTERFACES_DATA='' A_MACHINE_DATA='' +A_MEMORY_DATA='' A_NETWORK_DATA='' A_OPTICAL_DRIVE_DATA='' A_PARTITION_DATA='' @@ -262,6 +282,7 @@ A_DISPLAY_SERVER_DATA='' ### BOOLEANS ### ## standard boolean flags ## +B_BSD_DISK_SET='false' B_BSD_RAID='false' B_COLOR_SCHEME_SET='false' B_CONSOLE_IRC='false' @@ -273,11 +294,14 @@ B_DBUS_CLIENT='false' B_DCOP='false' # Debug flood override: make 'true' to allow long debug output B_DEBUG_FLOOD='false' +# for special -i debugging cases +B_DEBUG_I='false' B_DMIDECODE_SET='false' # show extra output data B_EXTRA_DATA='false' # triggered by -xx B_EXTRA_EXTRA_DATA='false' +B_FORCE_DMIDECODE='false' B_ID_SET='false' # override certain errors due to currupted data B_HANDLE_CORRUPT_DATA='false' @@ -298,9 +322,9 @@ B_ROOT='false' B_RUN_COLOR_SELECTOR='false' B_RUNNING_IN_DISPLAY='false' # in x type display server if tty >/dev/null;then - B_RUNNING_IN_SHELL='true' + B_IRC='false' else - B_RUNNING_IN_SHELL='false' + B_IRC='true' fi # this sets the debug buffer B_SCRIPT_UP='false' @@ -311,6 +335,8 @@ B_SHOW_BASIC_RAID='false' B_SHOW_BASIC_CPU='false' B_SHOW_BASIC_DISK='false' B_SHOW_BASIC_OPTICAL='false' +B_SHOW_BATTERY='false' +B_SHOW_BATTERY_FORCED='false' B_SHOW_CPU='false' B_SHOW_DISPLAY_DATA='false' B_SHOW_DISK_TOTAL='false' @@ -325,6 +351,7 @@ B_SHOW_INFO='false' B_SHOW_IP='false' B_SHOW_LABELS='false' B_SHOW_MACHINE='false' +B_SHOW_MEMORY='false' B_SHOW_NETWORK='false' # either -v > 3 or -P will show partitions B_SHOW_PARTITIONS='false' @@ -440,22 +467,23 @@ ALTERNATE_WEATHER_LOCATION='' # weather alternate location LOG_FILE="$SCRIPT_DATA_DIR/inxi.log" LOG_FILE_1="$SCRIPT_DATA_DIR/inxi.1.log" LOG_FILE_2="$SCRIPT_DATA_DIR/inxi.2.log" -MAN_FILE_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/inxi.1.gz' +MAN_FILE_DOWNLOAD='https://github.com/smxi/inxi/raw/master/inxi.1.gz' MAN_FILE_LOCATION='/usr/share/man/man1' SCRIPT_NAME='inxi' SCRIPT_PATCH_NUMBER='' SCRIPT_PATH='' #filled-in in Main SCRIPT_VERSION_NUMBER="" #filled-in in Main -SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/' -SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/' -SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/' -SCRIPT_DOWNLOAD_BRANCH_3='http://inxi.googlecode.com/svn/branches/three/' -SCRIPT_DOWNLOAD_BRANCH_4='http://inxi.googlecode.com/svn/branches/four/' -SCRIPT_DOWNLOAD_BRANCH_BSD='http://inxi.googlecode.com/svn/branches/bsd/' -SCRIPT_DOWNLOAD_BRANCH_GNUBSD='http://inxi.googlecode.com/svn/branches/gnubsd/' +SCRIPT_DOWNLOAD='https://github.com/smxi/inxi/raw/master/' +SCRIPT_DOWNLOAD_BRANCH_1='https://github.com/smxi/inxi/raw/one/' +SCRIPT_DOWNLOAD_BRANCH_2='https://github.com/smxi/inxi/raw/two/' +SCRIPT_DOWNLOAD_BRANCH_3='https://github.com/smxi/inxi/raw/three/' +SCRIPT_DOWNLOAD_BRANCH_4='https://github.com/smxi/inxi/raw/four/' +SCRIPT_DOWNLOAD_BRANCH_BSD='https://github.com/smxi/inxi/raw/bsd/' +SCRIPT_DOWNLOAD_BRANCH_GNUBSD='https://github.com/smxi/inxi/raw/gnubsd/' SCRIPT_DOWNLOAD_DEV='http://smxi.org/test/' # note, you can use any ip url here as long as it's the only line on the output page. -# Also the ip address must be the last thing on that line. +# Also the ip address must be the last thing on that line. If you abuse this ip tool +# you will be banned from further access. Most > 24x daily automated queries to it are abuse. WAN_IP_URL='http://smxi.org/opt/ip.php' KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data) @@ -469,6 +497,8 @@ DEV_DISK_LABEL='' DEV_DISK_MAPPER='' DEV_DISK_UUID='' DMIDECODE_DATA='' +DNSTOOL='' +DOWNLOADER='wget' IRC_CLIENT='' IRC_CLIENT_VERSION='' PS_THROTTLED='' @@ -483,6 +513,8 @@ SEP2=' ' SEP3_IRC='' SEP3_CONSOLE=':' SEP3='' # do not set, will be set dynamically +LINE1='---------------------------------------------------------------------------' +LINE2='- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -' # Default indentation level. NOTE: actual indent is 1 greater to allow for spacing INDENT=10 @@ -491,22 +523,10 @@ INDENT=10 COLS_INNER='' ## for width minus INDENT COLS_MAX='' +# these will be set dynamically in main() TERM_COLUMNS=80 TERM_LINES=100 -## sometimes will trigger an error (mageia) if not in shell -if [[ $B_RUNNING_IN_SHELL == 'true' ]];then - if [[ -n $( type -p tput ) ]];then - TERM_COLUMNS=$(tput cols) - TERM_LINES=$(tput lines) - fi - # double check, just in case it's missing functionality or whatever - if [[ -n ${TERM_COLUMNS##[0-9]*} ]];then - TERM_COLUMNS=80 - TERM_LINES=100 - fi -fi - # Only for legacy user config files se we can test and convert the var name LINE_MAX_CONSOLE='' LINE_MAX_IRC='' @@ -523,6 +543,7 @@ C2='' CN='' ## Always leave these blank, these are only going to be set in inxi.conf files, that makes testing ## for user changes easier after sourcing the files +ESC='\x1b' GLOBAL_COLOR_SCHEME='' IRC_COLOR_SCHEME='' IRC_CONS_COLOR_SCHEME='' @@ -585,8 +606,21 @@ MAGENTA,YELLOW,NORMAL RED,CYAN,NORMAL RED,WHITE,NORMAL BLUE,WHITE,NORMAL + +RED,BLUE,NORMAL +RED,DBLUE,NORMAL +BLACK,BLUE,NORMAL +BLACK,DBLUE,NORMAL +NORMAL,BLUE,NORMAL +BLUE,MAGENTA,NORMAL +DBLUE,MAGENTA,NORMAL +BLACK,MAGENTA,NORMAL +MAGENTA,BLUE,NORMAL +MAGENTA,DBLUE,NORMAL ) +#echo ${#A_COLOR_SCHEMES[@]};exit + # WARNING: In the main part below (search for 'KONVI') # there's a check for Konversation-specific config files. # Any one of these can override the above if inxi is run @@ -595,14 +629,14 @@ BLUE,WHITE,NORMAL ## DISTRO DATA/ID ## # In cases of derived distros where the version file of the base distro can also be found under /etc, # the derived distro's version file should go first. (Such as with Sabayon / Gentoo) -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" +DISTROS_DERIVED="antix-version aptosid-version kanotix-version knoppix-version mandrake-release pardus-release porteus-version sabayon-release siduction-version sidux-version slitaz-release solusos-release turbolinux-release zenwalk-version" # debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu. -DISTROS_EXCLUDE_LIST="debian_version ubuntu_version" +DISTROS_EXCLUDE_LIST="debian_version devuan_version ubuntu_version" DISTROS_PRIMARY="arch-release gentoo-release redhat-release slackware-version SuSE-release" DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release" # this is being used both by core distros and derived distros now, eg, solusos 1 uses it for solusos id, while # debian, solusos base, uses it as well, so we have to know which it is. -DISTROS_OS_RELEASE_GOOD="arch-release SuSE-release" +DISTROS_OS_RELEASE_GOOD="arch-release SuSE-release " ## Distros with known problems # DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output # Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially @@ -610,10 +644,15 @@ DISTROS_OS_RELEASE_GOOD="arch-release SuSE-release" ## OUTPUT FILTERS/SEARCH ## # Note that \ bans only words, not parts of strings; in \ you can't use punctuation characters like . or , # we're saving about 10+% of the total script exec time by hand building the ban lists here, using hard quotes. -BAN_LIST_NORMAL='chipset|components|computing|computer|corporation|communications|electronics|electrical|electric|gmbh|group|industrial|international|revision|semiconductor|software|technologies|technology|ltd\.|\|inc\.|\|intl\.|co\.|\|corp\.|\|\(tm\)|\(r\)|®|\(rev ..\)' -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]' -SENSORS_GPU_SEARCH='intel|radeon|nouveau' +BAN_LIST_NORMAL='chipset|components|computing|computer|corporation|communications|electronics|electrical|electric|gmbh|group|incorporation|industrial|international|nee|revision|semiconductor|software|technologies|technology|ltd\.|\|inc\.|\|intl\.|co\.|\|corp\.|\|\(tm\)|\(r\)|®|\(rev ..\)' +BAN_LIST_CPU='@||cpu |cpu deca|dual core|dual-core|tri core|tri-core|quad core|quad-core|ennea|genuine|hepta|hexa|multi|octa|penta|processor|single|triple|[0-9\.]+ *[MmGg][Hh][Zz]' +# See github issue 75 for more details on value: *, triggers weird behaviors if present in value +# /sys/devices/virtual/dmi/id/product_name:['*'] +# this is for bash arrays AND avoiding * in arrays: ( fred * greg ) expands to the contents of the directory +BAN_LIST_ARRAY=',|\*' + +SENSORS_GPU_SEARCH='amdgpu|intel|radeon|nouveau' ### USB networking search string data, because some brands can have other products than ### wifi/nic cards, they need further identifiers, with wildcards. @@ -631,7 +670,7 @@ main() { eval $LOGFS - local color_scheme='' + local color_scheme='' kde_config_app='' # this will be used by all functions following local Ps_aux_Data="$( ps aux )" @@ -647,35 +686,11 @@ main() if [[ -s $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf ]];then source $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf fi - # Convert to new variable names if set in config files, legacy test - if [[ -n $LINE_MAX_CONSOLE ]];then - COLS_MAX_CONSOLE=$LINE_MAX_CONSOLE - fi - if [[ -n $LINE_MAX_IRC ]];then - COLS_MAX_IRC=$LINE_MAX_IRC - fi - # TERM_COLUMNS is set in top globals, using tput cols - if [[ $TERM_COLUMNS -lt $COLS_MAX_CONSOLE ]];then - COLS_MAX_CONSOLE=$TERM_COLUMNS - fi - # adjust, some terminals will wrap if output cols == term cols - COLS_MAX_CONSOLE=$(( $COLS_MAX_CONSOLE - 2 )) - - # comes after source for user set stuff - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then - COLS_MAX=$COLS_MAX_CONSOLE - SEP3=$SEP3_CONSOLE - else - # too hard to read if no colors, so force that for users on irc - if [[ $SCHEME == 0 ]];then - SEP3=$SEP3_CONSOLE - else - SEP3=$SEP3_IRC - fi - COLS_MAX=$COLS_MAX_IRC - fi + set_display_width 'live' # can be reset with -y - COLS_INNER=$(( $COLS_MAX - $INDENT - 1 )) + # echo SCHEME $SCHEME + # echo B_IRC $B_IRC + # echo sep3: $SEP3 # Check for dependencies BEFORE running ANYTHING else except above functions # Not all distro's have these depends installed by default. Don't want to run # this if the user is requesting to see this information in the first place @@ -698,7 +713,7 @@ main() # note: this only works if it's run from inside konversation as a script builtin or something # only do this if inxi has been started as a konversation script, otherwise bypass this -# KONVI=3 ## for testing puroses + # KONVI=3 ## for testing puroses if [[ $KONVI -eq 1 || $KONVI -eq 3 ]];then if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (ie 1.x < 1.2(qt3)) DCPORT="$1" @@ -710,18 +725,28 @@ main() DCTARGET="$2" ##dbus testing shift 2 fi - + # always have the current stable kde version tested first, + # then use fallbacks and future proofing + if type -p kde4-config &>/dev/null;then + kde_config_app='kde4-config' + elif type -p kde5-config &>/dev/null;then + kde_config_app='kde5-config' + elif type -p kde-config &>/dev/null;then + kde_config_app='kde-config' + fi # The section below is on request of Argonel from the Konversation developer team: # it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf - IFS=":" - for kde_config in $( kde-config --path data ) - do - if [[ -r ${kde_config}${KONVI_CFG} ]];then - source "${kde_config}${KONVI_CFG}" - break - fi - done - IFS="$ORIGINAL_IFS" + if [[ -n $kde_config_app ]];then + IFS=":" + for kde_config in $( $kde_config_app --path data ) + do + if [[ -r $kde_config$KONVI_CFG ]];then + source "$kde_config$KONVI_CFG" + break + fi + done + IFS="$ORIGINAL_IFS" + fi fi ## leave this for debugging dcop stuff if we get that working @@ -749,7 +774,7 @@ main() if [[ -n $GLOBAL_COLOR_SCHEME ]];then color_scheme=$GLOBAL_COLOR_SCHEME else - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ $B_IRC == 'false' ]];then if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then color_scheme=$CONSOLE_COLOR_SCHEME elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then @@ -768,6 +793,16 @@ main() set_color_scheme $color_scheme fi fi + if [[ $B_IRC == 'false' ]];then + SEP3=$SEP3_CONSOLE + else + # too hard to read if no colors, so force that for users on irc + if [[ $SCHEME == 0 ]];then + SEP3=$SEP3_CONSOLE + else + SEP3=$SEP3_IRC + fi + fi # all the pre-start stuff is in place now B_SCRIPT_UP='true' @@ -776,10 +811,6 @@ main() # then create the output print_it_out - ## last steps - if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then - echo -n "" - fi eval $LOGFE # weechat's executor plugin forced me to do this, and rightfully so, because else the exit code # from the last command is taken.. @@ -799,16 +830,21 @@ initialize_data() { eval $LOGFS BSD_VERSION=$( uname -s 2>/dev/null | tr '[A-Z]' '[a-z]' ) - # note: archbsd says they are a freebsd distro, so assuming it's the same as freebsd - if [[ -n $( grep 'bsd' <<< "$BSD_VERSION" ) ]];then + if [[ -z ${BSD_VERSION/*bsd*/} || -z ${BSD_VERSION/*dragonfly*/} || -z ${BSD_VERSION/*darwin*/} ]];then + if [[ -z ${BSD_VERSION/*openbsd*/} ]];then + BSD_VERSION='openbsd' + elif [[ -z ${BSD_VERSION/*darwin*/} ]];then + BSD_VERSION='darwin' + fi # GNU/kfreebsd will by definition have GNU tools like sed/grep - if [[ -n $( grep 'kfreebsd' <<< "$BSD_VERSION" ) ]];then + if [[ -z ${BSD_VERSION/*kfreebsd*/} ]];then BSD_TYPE='debian-bsd' # debian gnu bsd else BSD_TYPE='bsd' # all other bsds SED_I="-i ''" SED_RX='-E' + ESC=$(echo | tr '\n' '\033') fi fi # now set the script BOOLEANS for files required to run features @@ -823,64 +859,69 @@ initialize_data() initialize_paths + if type -p dig &>/dev/null;then + DNSTOOL='dig' + fi + + # set downloaders. + if ! type -p wget &>/dev/null;then + # first check for bsd stuff + if type -p fetch &>/dev/null;then + DOWNLOADER='fetch' + elif type -p curl &>/dev/null;then + DOWNLOADER='curl' + elif [[ $BSD_VERSION == 'openbsd' && -n $( type -p ftp ) ]];then + DOWNLOADER='ftp' + else + DOWNLOADER='no-downloader' + fi + fi + if [[ -n $BSD_TYPE ]];then if [[ -e $FILE_DMESG_BOOT ]];then B_DMESG_BOOT_FILE='true' fi else # found a case of battery existing but having nothing in it on desktop mobo - # not all laptops show the first, - if [[ -n $( ls /proc/acpi/battery 2>/dev/null ) ]];then + # not all laptops show the first. /proc/acpi/battery is deprecated. + if [[ -n $( ls /proc/acpi/battery 2>/dev/null ) || -n $( ls /sys/class/power_supply/ 2>/dev/null ) ]];then B_PORTABLE='true' fi fi - - if [[ -e $FILE_CPUINFO ]]; then B_CPUINFO_FILE='true' fi - if [[ -e $FILE_MEMINFO ]];then B_MEMINFO_FILE='true' fi - if [[ -e $FILE_ASOUND_DEVICE ]];then B_ASOUND_DEVICE_FILE='true' fi - if [[ -e $FILE_ASOUND_VERSION ]];then B_ASOUND_VERSION_FILE='true' fi - if [[ -f $FILE_LSB_RELEASE ]];then B_LSB_FILE='true' fi - if [[ -f $FILE_OS_RELEASE ]];then B_OS_RELEASE_FILE='true' fi - if [[ -e $FILE_SCSI ]];then B_SCSI_FILE='true' fi - if [[ -n $DISPLAY ]];then B_SHOW_DISPLAY_DATA='true' B_RUNNING_IN_DISPLAY='true' fi - if [[ -e $FILE_MDSTAT ]];then B_MDSTAT_FILE='true' fi - if [[ -e $FILE_MODULES ]];then B_MODULES_FILE='true' fi - if [[ -e $FILE_MOUNTS ]];then B_MOUNTS_FILE='true' fi - if [[ -e $FILE_PARTITIONS ]];then B_PARTITIONS_FILE='true' fi @@ -889,7 +930,7 @@ initialize_data() B_XORG_LOG='true' else # Detect location of the Xorg log file - if [[ -n $( type -p xset ) ]]; then + if type -p xset &>/dev/null; then FILE_XORG_LOG=$( xset q 2>/dev/null | grep -i 'Log file' | gawk '{print $3}') if [[ -e $FILE_XORG_LOG ]];then B_XORG_LOG='true' @@ -903,6 +944,56 @@ initialize_data() eval $LOGFE } +# args: $1 - default OR override default cols max integer count +set_display_width() +{ + local cols_max_override=$1 + + if [[ $cols_max_override == 'live' ]];then + ## sometimes tput will trigger an error (mageia) if irc client + if [[ $B_IRC == 'false' ]];then + if type -p tput &>/dev/null;then + TERM_COLUMNS=$(tput cols) + TERM_LINES=$(tput lines) + fi + # double check, just in case it's missing functionality or whatever + if [[ -z $TERM_COLUMNS || -n ${TERM_COLUMNS//[0-9]/} ]];then + TERM_COLUMNS=80 + TERM_LINES=100 + fi + fi + # Convert to new variable names if set in config files, legacy test + if [[ -n $LINE_MAX_CONSOLE ]];then + COLS_MAX_CONSOLE=$LINE_MAX_CONSOLE + fi + if [[ -n $LINE_MAX_IRC ]];then + COLS_MAX_IRC=$LINE_MAX_IRC + fi + # this lets you set different widths for in or out of display server + # if [[ $B_RUNNING_IN_DISPLAY == 'false' && -n $COLS_MAX_NO_DISPLAY ]];then + # COLS_MAX_CONSOLE=$COLS_MAX_NO_DISPLAY + # fi + # TERM_COLUMNS is set in top globals, using tput cols + # echo tc: $TERM_COLUMNS cmc: $COLS_MAX_CONSOLE + if [[ $TERM_COLUMNS -lt $COLS_MAX_CONSOLE ]];then + COLS_MAX_CONSOLE=$TERM_COLUMNS + fi + # adjust, some terminals will wrap if output cols == term cols + COLS_MAX_CONSOLE=$(( $COLS_MAX_CONSOLE - 2 )) + # echo cmc: $COLS_MAX_CONSOLE + # comes after source for user set stuff + if [[ $B_IRC == 'false' ]];then + COLS_MAX=$COLS_MAX_CONSOLE + else + COLS_MAX=$COLS_MAX_IRC + fi + else + COLS_MAX=$cols_max_override + fi + COLS_INNER=$(( $COLS_MAX - $INDENT - 1 )) + # echo cm: $COLS_MAX ci: $COLS_INNER +} + # arg: $1 - version number: main/patch/date parse_version_data() { @@ -911,22 +1002,22 @@ parse_version_data() # note, using ####[[:space:]]+ to avoid having this function also trip the version datas case $1 in date) - version_data="$( gawk -F ': ' ' + version_data=$( gawk -F ': ' ' /####[[:space:]]+Date:/ { print $NF - }' $SCRIPT_PATH/$SCRIPT_NAME )" + }' "$SCRIPT_PATH/$SCRIPT_NAME" ) ;; main) - version_data="$( gawk ' + version_data=$( gawk ' /####[[:space:]]+Version:/ { print $3 - }' $SCRIPT_PATH/$SCRIPT_NAME )" + }' "$SCRIPT_PATH/$SCRIPT_NAME" ) ;; patch) - version_data="$( gawk ' + version_data=$( gawk ' /####[[:space:]]+Patch Number:/ { print $4 - }' $SCRIPT_PATH/$SCRIPT_NAME )" + }' "$SCRIPT_PATH/$SCRIPT_NAME" ) ;; esac echo $version_data @@ -936,10 +1027,10 @@ initialize_paths() { local path='' added_path='' b_path_found='' sys_path='' # Extra path variable to make execute failures less likely, merged below - local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" + local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/local/bin" # this needs to be set here because various options call the parent initialize function directly. - SCRIPT_PATH=$( dirname $0 ) + SCRIPT_PATH=$( dirname "$0" ) # Fallback paths put into $extra_paths; This might, among others, help on gentoo. # Now, create a difference of $PATH and $extra_paths and add that to $PATH: @@ -959,11 +1050,10 @@ initialize_paths() done IFS="$ORIGINAL_IFS" - PATH="${PATH}${added_path}" - ##echo "PATH='$PATH'" + PATH="$PATH$added_path" + # echo "PATH='$PATH'" ##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""' } - # No args taken. check_recommended_apps() { @@ -982,22 +1072,22 @@ check_recommended_apps() script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output" fi # test for a few apps that bsds may not have after initial tests - if [[ -n $( type -p lspci ) ]];then + if type -p lspci &>/dev/null;then B_LSPCI='true' fi if [[ -n $BSD_TYPE ]];then - if [[ -n $( type -p sysctl ) ]];then + if type -p sysctl &>/dev/null;then B_SYSCTL='true' fi - if [[ -n $( type -p pciconf ) ]];then + if type -p pciconf &>/dev/null;then B_PCICONF='true' fi fi # now setting qdbus/dcop for first run, some systems can have both by the way - if [[ -n $( type -p qdbus ) ]];then + if type -p qdbus &>/dev/null;then B_QDBUS='true' fi - if [[ -n $( type -p dcop ) ]];then + if type -p dcop &>/dev/null;then B_DCOP='true' fi eval $LOGFE @@ -1008,9 +1098,9 @@ check_recommended_apps() check_required_apps() { eval $LOGFS - local app_name='' app_path='' + local app_name='' # bc removed from deps for now - local depends="df gawk grep ps readlink tr uname uptime wc" + local depends="df gawk grep ps readlink tr uname wc" if [[ -z $BSD_TYPE ]];then depends="$depends lspci" @@ -1027,8 +1117,7 @@ check_required_apps() if [[ $B_RUNNING_IN_DISPLAY == 'true' ]];then for app_name in $x_apps do - app_path=$( type -p $app_name ) - if [[ -z $app_path ]];then + if ! type -p $app_name &>/dev/null;then script_debugger "Resuming in non X mode: $app_name not found. For package install advice run: $SCRIPT_NAME --recommends" B_SHOW_DISPLAY_DATA='false' break @@ -1040,8 +1129,7 @@ check_required_apps() for app_name in $depends do - app_path=$( type -p $app_name ) - if [[ -z $app_path ]];then + if ! type -p $app_name &>/dev/null;then error_handler 5 "$app_name" fi done @@ -1084,7 +1172,7 @@ set_color_scheme() fi # Set a global variable to allow checking for chosen scheme later SCHEME="$1" - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ $B_IRC == 'false' ]];then a_color_codes=( $ANSI_COLORS ) else a_color_codes=( $IRC_COLORS ) @@ -1101,6 +1189,11 @@ set_color_scheme() C2="${!a_output_colors[1]}" CN="${!a_output_colors[2]}" # ((COLOR_SCHEME++)) ## note: why is this? ## + # handle some explicit colors that are used for no color 0 + if [[ $SCHEME -eq 0 ]];then + NORMAL='' + RED='' + fi eval $LOGFE } @@ -1133,23 +1226,22 @@ select_default_color_scheme() fi # don't want these printing in irc since they show literally - if [[ $B_RUNNING_IN_SHELL != 'true' ]];then + if [[ $B_IRC == 'true' ]];then irc_clear='' fi # first make output neutral so it's just plain default for console client set_color_scheme "0" - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then - print_screen_output "Welcome to $SCRIPT_NAME! Please select the default $COLOR_SELECTION color scheme." + # print_lines_basic "0" "" "" + if [[ $B_IRC == 'false' ]];then + print_lines_basic "0" "" "Welcome to $SCRIPT_NAME! Please select the default $COLOR_SELECTION color scheme." # print_screen_output "You will see this message only one time per user account, unless you set preferences in: /etc/$SCRIPT_NAME.conf" print_screen_output " " fi - print_screen_output "Because there is no way to know your $COLOR_SELECTION foreground/background colors, you can" - print_screen_output "set your color preferences from color scheme option list below. 0 is no colors, 1 neutral." - print_screen_output "After these, there are 3 sets: 1-dark or light backgrounds; 2-light backgrounds; 3-dark backgrounds." - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then - print_screen_output "Please note that this will set the $COLOR_SELECTION preferences only for user: $(whoami)" + print_lines_basic "0" "" "Because there is no way to know your $COLOR_SELECTION foreground/background colors, you can set your color preferences from color scheme option list below. 0 is no colors, 1 neutral. After these, there are 4 sets: 1-dark or light backgrounds; 2-light backgrounds; 3-dark backgrounds; 4-miscellaneous." + if [[ $B_IRC == 'false' ]];then + print_lines_basic "0" "" "Please note that this will set the $COLOR_SELECTION preferences only for user: $(whoami)" fi - print_screen_output "------------------------------------------------------------------------------" + print_screen_output "$LINE1" for (( i=0; i < ${#A_COLOR_SCHEMES[@]}; i++ )) do if [[ $i -gt 9 ]];then @@ -1168,21 +1260,21 @@ select_default_color_scheme() done set_color_scheme 0 - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ $B_IRC == 'false' ]];then echo -n "" + print_screen_output "$irc_clear $i)${spacer}Remove all color settings. Restore $SCRIPT_NAME default." print_screen_output "$irc_clear $(($i+1)))${spacer}Continue, no changes or config file setting." print_screen_output "$irc_clear $(($i+2)))${spacer}Exit, use another terminal, or set manually." - print_screen_output "------------------------------------------------------------------------------" - print_screen_output "Simply type the number for the color scheme that looks best to your eyes for your $COLOR_SELECTION settings" - 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:" - print_screen_output "94 (console, no X - $console); 95 (terminal, X - $virt_term); 96 (irc, gui, X - $irc_gui);" - print_screen_output "97 (irc, X, in terminal - $irc_x_term); 98 (irc, no X - $irc_console); 99 (global - $global)" + print_screen_output "$LINE1" + print_lines_basic "0" "" "Simply type the number for the color scheme that looks best to your eyes for your $COLOR_SELECTION settings and hit ENTER. NOTE: You can bring this option list up by starting $SCRIPT_NAME with option: -c plus one of these numbers:" + print_lines_basic "0" "" "94^(console,^no X^-^$console); 95^(terminal,^X^-^$virt_term); 96^(irc,^gui,^X^-^$irc_gui); 97^(irc,^X,^in^terminal^-^$irc_x_term); 98^(irc,^no^X^-^$irc_console); 99^(global^-^$global)" + print_lines_basic "0" "" "" print_screen_output "Your selection(s) will be stored here: $config_file" - print_screen_output "Global overrides all individual color schemes. Individual schemes remove the global setting." - print_screen_output "------------------------------------------------------------------------------" + print_lines_basic "0" "" "Global overrides all individual color schemes. Individual schemes remove the global setting." + print_screen_output "$LINE1" read user_selection - if [[ -n $( grep -Es '^([0-9]+)$' <<< "$user_selection" ) && $user_selection -lt $i ]];then + if [[ "$user_selection" =~ ^([0-9]+)$ && $user_selection -lt $i ]];then case $COLOR_SELECTION in irc) config_variable='IRC_COLOR_SCHEME' @@ -1212,7 +1304,7 @@ select_default_color_scheme() touch $config_file fi if [[ -z $( grep -s "$config_variable=" $config_file ) ]];then - print_screen_output "Creating and updating config file for $COLOR_SELECTION color scheme now..." + print_lines_basic "0" "" "Creating and updating config file for $COLOR_SELECTION color scheme now..." echo "$config_variable=$user_selection" >> $config_file else print_screen_output "Updating config file for $COLOR_SELECTION color scheme now..." @@ -1234,7 +1326,7 @@ select_default_color_scheme() -e '/IRC_COLOR_SCHEME=/d' -e '/IRC_CONS_COLOR_SCHEME=/d' -e '/IRC_X_TERM_COLOR_SCHEME=/d' $config_file set_color_scheme $DEFAULT_COLOR_SCHEME elif [[ $user_selection == $(( $i+1 )) ]];then - print_screen_output "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 95 to 99" + print_lines_basic "0" "" "Ok, continuing $SCRIPT_NAME unchanged. You can set the colors anytime by starting with: -c 95 to 99" if [[ -n $CONSOLE_COLOR_SCHEME && -z $DISPLAY ]];then set_color_scheme $CONSOLE_COLOR_SCHEME elif [[ -n $VIRT_TERM_COLOR_SCHEME ]];then @@ -1252,9 +1344,8 @@ select_default_color_scheme() select_default_color_scheme fi else - print_screen_output "------------------------------------------------------------------------------" - print_screen_output "After finding the scheme number you like, simply run this again in a terminal to set the configuration" - print_screen_output "data file for your irc client. You can set color schemes for the following: start inxi with -c plus:" + print_screen_output "$LINE1" + print_lines_basic "0" "" "After finding the scheme number you like, simply run this again in a terminal to set the configuration data file for your irc client. You can set color schemes for the following: start inxi with -c plus:" print_screen_output "94 (console, no X - $console); 95 (terminal, X - $virt_term); 96 (irc, gui, X - $irc_gui);" print_screen_output "97 (irc, X, in terminal - $irc_x_term); 98 (irc, no X - $irc_console); 99 (global - $global)" exit 0 @@ -1292,7 +1383,7 @@ error_handler() ;; 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" ;; - 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 $SCRIPT_PATH/$SCRIPT_NAME" + 8) error_message="the self-updater failed, $DOWNLOADER exited with error: $2.\nYou probably need to be root.\nHint, to make for easy updates without being root, do: chown $SCRIPT_PATH/$SCRIPT_NAME" ;; 9) error_message="unsupported debugging level: $2" ;; @@ -1303,7 +1394,7 @@ error_handler() error_message="unsupported testing option argument: -! $2" ;; 12) - 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." + error_message="the git branch download url: $2\nappears to be empty currently. Make sure there is an actual svn branch version\nactive before you try this again. Check https://github.com/smxi/inxi\nto verify the branch status." ;; 13) 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" @@ -1329,6 +1420,9 @@ error_handler() 20) error_message="The option you selected has been deprecated. $2\nSee the -h (help) menu for currently supported options." ;; + 21) + error_message="Width option requires an integer value of 80 or more.\nYou entered: $2" + ;; *) error_message="error unknown: $@" set -- 99 ;; @@ -1397,7 +1491,10 @@ log_function_data() ;; cat) if [[ $B_LOG_FULL_DATA == 'true' ]];then - logged_data="\n$line\nFull file data: cat $2\n\n$( cat $2 )\n$line\n" + for cat_file in $2 + do + logged_data="$logged_data\n$line\nFull file data: cat $cat_file\n\n$( cat $cat_file )\n$line\n" + done spacer='' fi ;; @@ -1454,10 +1551,10 @@ create_rotate_logfiles() script_self_updater() { eval $LOGFS - local wget_error=0 file_contents='' wget_man_error=0 + local downloader_error=0 file_contents='' downloader_man_error=0 local man_file_path="$MAN_FILE_LOCATION/inxi.1.gz" - if [[ $B_RUNNING_IN_SHELL != 'true' ]];then + if [[ $B_IRC == 'true' ]];then print_screen_output "Sorry, you can't run the $SCRIPT_NAME self updater option (-$3) in an IRC client." exit 1 fi @@ -1466,10 +1563,26 @@ script_self_updater() print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER" print_screen_output "Current version patch number: $SCRIPT_PATCH_NUMBER" print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..." + case $DOWNLOADER in + curl) + file_contents="$( curl -s $1$SCRIPT_NAME )" || downloader_error=$? + ;; + fetch) + file_contents="$( fetch -q -o - $1$SCRIPT_NAME )" || downloader_error=$? + ;; + ftp) + file_contents="$( ftp -o - $1$SCRIPT_NAME 2>/dev/null )" || downloader_error=$? + ;; + wget) + file_contents="$( wget -q -O - $1$SCRIPT_NAME )" || downloader_error=$? + ;; + no-downloader) + downloader_error=1 + ;; + esac - file_contents="$( wget -q -O - $1$SCRIPT_NAME )" || wget_error=$? # then do the actual download - if [[ $wget_error -eq 0 ]];then + if [[ $downloader_error -eq 0 ]];then # make sure the whole file got downloaded and is in the variable if [[ -n $( grep '###\*\*EOF\*\*###' <<< "$file_contents" ) ]];then echo "$file_contents" > $SCRIPT_PATH/$SCRIPT_NAME || error_handler 14 "$?" @@ -1489,18 +1602,38 @@ script_self_updater() if [[ -f /usr/share/man/man8/inxi.8.gz ]];then print_screen_output "Updating man page location to man1." mv -f /usr/share/man/man8/inxi.8.gz /usr/share/man/man1/inxi.1.gz - if [[ -n $( type -p mandb ) ]];then + if type -p mandb &>/dev/null;then exec $( type -p mandb ) -q fi fi - wget -q --spider $MAN_FILE_DOWNLOAD || wget_man_error=$? - if [[ $wget_man_error -eq 0 ]];then - print_screen_output "Man file download URL verified: $MAN_FILE_DOWNLOAD" + if [[ $DOWNLOADER == 'wget' ]];then + wget -q --spider $MAN_FILE_DOWNLOAD || downloader_man_error=$? + fi + if [[ $downloader_man_error -eq 0 ]];then + if [[ $DOWNLOADER == 'wget' ]];then + print_screen_output "Man file download URL verified: $MAN_FILE_DOWNLOAD" + fi print_screen_output "Downloading Man page file now." - wget -q -O $man_file_path $MAN_FILE_DOWNLOAD || wget_man_error=$? - if [[ $wget_man_error -gt 0 ]];then + case $DOWNLOADER in + curl) + curl -s -o $man_file_path $MAN_FILE_DOWNLOAD || downloader_man_error=$? + ;; + fetch) + fetch -q -o $man_file_path $MAN_FILE_DOWNLOAD || downloader_man_error=$? + ;; + ftp) + ftp -o $man_file_path $MAN_FILE_DOWNLOAD 2>/dev/null || downloader_man_error=$? + ;; + wget) + wget -q -O $man_file_path $MAN_FILE_DOWNLOAD || downloader_man_error=$? + ;; + no-downloader) + downloader_man_error=1 + ;; + esac + if [[ $downloader_man_error -gt 0 ]];then print_screen_output "Oh no! Something went wrong downloading the Man gz file at: $MAN_FILE_DOWNLOAD" - print_screen_output "Check the error messages for what happened. Error: $wget_man_error" + print_screen_output "Check the error messages for what happened. Error: $downloader_man_error" else print_screen_output "Download/install of man page successful. Check to make sure it works: man inxi" fi @@ -1519,7 +1652,7 @@ script_self_updater() # now run the error handlers on any wget failure else if [[ $2 == 'svn server' ]];then - error_handler 8 "$wget_error" + error_handler 8 "$downloader_error" elif [[ $2 == 'alt server' ]];then error_handler 10 "$1" else @@ -1533,18 +1666,33 @@ script_self_updater() debug_data_collector() { local xiin_app='' xiin_data_file='' xiin_download='' error='' b_run_xiin='false' - local debug_data_dir='' bsd_string='' + local debug_data_dir='' bsd_string='' xorg_d_files='' xorg_file='' a_distro_ids='' local completed_gz_file='' xiin_file='xiin.py' ftp_upload='ftp.techpatterns.com/incoming' - local Line='-------------------------' + local xiin_url="https://github.com/smxi/inxi/raw/xiin/$xiin_file" + local Line='-------------------------' root_string='' local start_directory=$( pwd ) + local host=$( tr '[A-Z]' '[a-z]' <<< "$HOSTNAME" ) + local downloader_error=0 debug_i='' + if [[ $B_DEBUG_I == 'true' ]];then + debug_i='i' + fi + + if [[ -n $host ]];then + host=${host// /-} + else + host="-no-host" + fi if [[ -n $BSD_TYPE ]];then - bsd_string="$BSD_TYPE-" + bsd_string="-$BSD_TYPE-$BSD_VERSION" + fi + if [[ $( whoami ) == 'root' ]];then + root_string='-root' fi - debug_data_dir="inxi-$bsd_string$(tr ' ' '-' <<< $HOSTNAME | tr '[A-Z]' '[a-z]' )-$1-$(date +%Y%m%d)" + debug_data_dir="inxi$bsd_string-$host-$(date +%Y%m%d-%H%M%S)-$1$root_string" - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ $B_IRC == 'false' ]];then if [[ -n $ALTERNATE_FTP ]];then ftp_upload=$ALTERNATE_FTP fi @@ -1568,29 +1716,150 @@ debug_data_collector() echo 'Collecting system info: sensors, lsusb, lspci, lspci -v data, plus /proc data' echo 'also checking for dmidecode data: note, you must be root to have dmidecode work.' echo "Data going into: $SCRIPT_DATA_DIR/$debug_data_dir" - # bsd tools - pciconf -vl &> $debug_data_dir/bsd-pciconf-vl.txt - sysctl -a &> $debug_data_dir/bsd-sysctl-a.txt - + # bsd tools http://cb.vu/unixtoolbox.xhtml + # freebsd + if type -p pciconf &>/dev/null;then + pciconf -l -cv &> $debug_data_dir/bsd-pciconf-cvl.txt + pciconf -vl &> $debug_data_dir/bsd-pciconf-vl.txt + pciconf -l &> $debug_data_dir/bsd-pciconf-l.txt + else + touch $debug_data_dir/bsd-pciconf-absent + fi + # openbsd + if type -p pcidump &>/dev/null;then + pcidump &> $debug_data_dir/bsd-pcidump-openbsd.txt + pcidump -v &> $debug_data_dir/bsd-pcidump-v-openbsd.txt + else + touch $debug_data_dir/bsd-pcidump-openbsd-absent + fi + # netbsd + if type -p pcictl &>/dev/null;then + pcictl list &> $debug_data_dir/bsd-pcictl-list-netbsd.txt + pcictl list -n &> $debug_data_dir/bsd-pcictl-list-n-netbsd.txt + else + touch $debug_data_dir/bsd-pcictl-netbsd-absent + fi + if type -p sysctl &>/dev/null;then + sysctl -a &> $debug_data_dir/bsd-sysctl-a.txt + else + touch $debug_data_dir/bsd-sysctl-absent + fi + if type -p usbdevs &>/dev/null;then + usbdevs -v &> $debug_data_dir/bsd-usbdevs-v.txt + else + touch $debug_data_dir/bsd-usbdevs-absent + fi + if type -p kldstat &>/dev/null;then + kldstat &> $debug_data_dir/bsd-kldstat.txt + else + touch $debug_data_dir/bsd-kldstat-absent + fi + # diskinfo -v + # fdisk dmidecode &> $debug_data_dir/dmidecode.txt + get_repo_data "$SCRIPT_DATA_DIR/$debug_data_dir" + + if type -p shopt &>/dev/null;then + shopt -s nullglob + a_distro_ids=(/etc/*[-_]{release,version}) + shopt -u nullglob + echo ${a_distro_ids[@]} &> $debug_data_dir/etc-distro-files.txt + for distro_file in ${a_distro_ids[@]} /etc/issue + do + if [[ -f $distro_file ]];then + cat $distro_file &> $debug_data_dir/distro-file${distro_file//\//-} + fi + done + fi + dmesg &> $debug_data_dir/dmesg.txt lscpu &> $debug_data_dir/lscpu.txt lspci &> $debug_data_dir/lspci.txt + lspci -k &> $debug_data_dir/lspci-k.txt + lspci -knn &> $debug_data_dir/lspci-knn.txt lspci -n &> $debug_data_dir/lspci-n.txt + lspci -nn &> $debug_data_dir/lspci-nn.txt + lspci -mm &> $debug_data_dir/lspci-mm.txt + lspci -mmnn &> $debug_data_dir/lspci-mmnn.txt + lspci -mmnnv &> $debug_data_dir/lspci-mmnnv.txt lspci -v &> $debug_data_dir/lspci-v.txt lsusb &> $debug_data_dir/lsusb.txt + if type -p hciconfig &>/dev/null;then + hciconfig -a &> $debug_data_dir/hciconfig-a.txt + else + touch $debug_data_dir/hciconfig-absent + fi + ls /sys &> $debug_data_dir/ls-sys.txt ps aux &> $debug_data_dir/ps-aux.txt + ps -e &> $debug_data_dir/ps-e.txt + ps -p 1 &> $debug_data_dir/ps-p-1.txt + cat /proc/1/comm &> $debug_data_dir/proc-1-comm.txt runlevel &> $debug_data_dir/runlevel.txt - systemctl list-units &> $debug_data_dir/systemctl-list-units.txt - systemctl list-units --type=target &> $debug_data_dir/systemctl-list-units-target.txt - initctl list &> $debug_data_dir/initctl-list.txt + if type -p rc-status &>/dev/null;then + rc-status -a &> $debug_data_dir/rc-status-a.txt + rc-status -l &> $debug_data_dir/rc-status-l.txt + rc-status -r &> $debug_data_dir/rc-status-r.txt + else + touch $debug_data_dir/rc-status-absent + fi + if type -p systemctl &>/dev/null;then + systemctl list-units &> $debug_data_dir/systemctl-list-units.txt + systemctl list-units --type=target &> $debug_data_dir/systemctl-list-units-target.txt + else + touch $debug_data_dir/systemctl-absent + fi + if type -p initctl &>/dev/null;then + initctl list &> $debug_data_dir/initctl-list.txt + else + touch $debug_data_dir/initctl-absent + fi sensors &> $debug_data_dir/sensors.txt - strings --version &> $debug_data_dir/strings.txt - nvidia-smi -q &> $debug_data_dir/nvidia-smi-q.txt - nvidia-smi -q -x &> $debug_data_dir/nvidia-smi-xq.txt + if type -p strings &>/dev/null;then + touch $debug_data_dir/strings-present + else + touch $debug_data_dir/strings-absent + fi + local id_dir='/sys/class/power_supply/' + local ids=$( ls $id_dir 2>/dev/null ) + if [[ -n $ids ]];then + for batid in $ids + do + cat $id_dir$batid'/uevent' &> $debug_data_dir/sys-power-supply-$batid.txt + done + else + touch $debug_data_dir/sys-power-supply-none + fi + # leaving this commented out to remind that some systems do not + # support strings --version, but will just simply hang at that command + # which you can duplicate by simply typing: strings then hitting enter, you will get hang. + # strings --version &> $debug_data_dir/strings.txt + if type -p nvidia-smi &>/dev/null;then + nvidia-smi -q &> $debug_data_dir/nvidia-smi-q.txt + nvidia-smi -q -x &> $debug_data_dir/nvidia-smi-xq.txt + else + touch $debug_data_dir/nvidia-smi-absent + fi + head -n 1 /proc/asound/card*/codec* &> $debug_data_dir/proc-asound-card-codec.txt + if [[ -f /proc/version ]];then + cat /proc/version &> $debug_data_dir/proc-version.txt + else + touch $debug_data_dir/proc-version-absent + fi + echo $CC &> $debug_data_dir/cc-content.txt ls /usr/bin/gcc* &> $debug_data_dir/gcc-sys-versions.txt - gcc --version &> $debug_data_dir/gcc-version.txt + if type -p gcc &>/dev/null;then + gcc --version &> $debug_data_dir/gcc-version.txt + else + touch $debug_data_dir/gcc-absent + fi + if type -p clang &>/dev/null;then + clang --version &> $debug_data_dir/clang-version.txt + else + touch $debug_data_dir/clang-absent + fi + cat /etc/src.conf &> $debug_data_dir/bsd-etc-src-conf.txt + cat /etc/make.conf &> $debug_data_dir/bsd-etc-make-conf.txt cat /etc/issue &> $debug_data_dir/etc-issue.txt cat $FILE_LSB_RELEASE &> $debug_data_dir/lsb-release.txt cat $FILE_OS_RELEASE &> $debug_data_dir/os-release.txt @@ -1602,6 +1871,7 @@ debug_data_collector() cat /proc/net/arp &> $debug_data_dir/proc-net-arp.txt # bsd data cat /var/run/dmesg.boot &> $debug_data_dir/bsd-var-run-dmesg.boot.txt + echo $COLS_INNER &> $debug_data_dir/cols-inner.txt check_recommends_user_output &> $debug_data_dir/check-recommends-user-output.txt # first download and verify xiin @@ -1612,9 +1882,25 @@ debug_data_collector() mv -f xiin $xiin_file fi # -Nc is creating really weird download anomolies, so using -O instead - xiin_download="$( wget -q -O - http://inxi.googlecode.com/svn/branches/xiin/$xiin_file )" + case $DOWNLOADER in + curl) + xiin_download="$( curl -s $xiin_url )" || downloader_error=$? + ;; + fetch) + xiin_download="$( fetch -q -o - $xiin_url )" || downloader_error=$? + ;; + ftp) + xiin_download="$( ftp -o - $xiin_url 2>/dev/null )" || downloader_error=$? + ;; + wget) + xiin_download="$( wget -q -O - $xiin_url )" || downloader_error=$? + ;; + no-downloader) + downloader_error=1 + ;; + esac # if nothing got downloaded kick out error, otherwise we'll use an older version - if [[ $? -gt 0 && ! -f $xiin_file ]];then + if [[ $downloader_error -gt 0 && ! -f $xiin_file ]];then echo -e "ERROR: Failed to download required file: $xiin_file\nMaybe the remote site is down or your networking is broken?" echo "Continuing with incomplete data collection." echo "$xiin_file download failed and no existing $xiin_file" >> $debug_data_dir/xiin-error.txt @@ -1666,31 +1952,103 @@ debug_data_collector() if [[ -e $FILE_XORG_LOG ]];then cat $FILE_XORG_LOG &> $debug_data_dir/xorg-log-file.txt else - touch $debug_data_dir/no-xorg-log-file + touch $debug_data_dir/xorg-log-file-absent fi if [[ -e /etc/X11/xorg.conf ]];then - cp /etc/X11/xorg.conf $SCRIPT_DATA_DIR/$debug_data_dir + cat /etc/X11/xorg.conf &> $debug_data_dir/xorg-conf.txt else - touch $debug_data_dir/no-xorg-conf-file + touch $debug_data_dir/xorg-conf-file-absent fi if [[ -n $( ls /etc/X11/xorg.conf.d/ 2>/dev/null ) ]];then ls /etc/X11/xorg.conf.d &> $debug_data_dir/ls-etc-x11-xorg-conf-d.txt - cp /etc/X11/xorg.conf.d $SCRIPT_DATA_DIR/$debug_data_dir + xorg_d_files=$(ls /etc/X11/xorg.conf.d) + for xorg_file in $xorg_d_files + do + cat /etc/X11/xorg.conf.d/$xorg_file &> $debug_data_dir/xorg-conf-d-$xorg_file.txt + done + else + touch $debug_data_dir/xorg-conf-d-files-absent + fi + echo 'Collecting X, xprop, glxinfo, xrandr, xdpyinfo data, wayland, weston...' + if type -p weston-info &>/dev/null; then + weston-info &> $debug_data_dir/weston-info.txt + else + touch $debug_data_dir/weston-info-absent + fi + if type -p weston &>/dev/null; then + weston --version &> $debug_data_dir/weston-version.txt + else + touch $debug_data_dir/weston-absent + fi + if type -p xprop &>/dev/null; then + xprop -root &> $debug_data_dir/xprop_root.txt else - touch $debug_data_dir/no-xorg-conf-d-files - fi - echo 'Collecting X, xprop, glxinfo, xrandr, xdpyinfo data...' - xprop -root &> $debug_data_dir/xprop_root.txt - glxinfo &> $debug_data_dir/glxinfo.txt - xdpyinfo &> $debug_data_dir/xdpyinfo.txt - xrandr &> $debug_data_dir/xrandr.txt - X -version &> $debug_data_dir/x-version.txt - Xorg -version &> $debug_data_dir/xorg-version.txt + touch $debug_data_dir/xprop-absent + fi + if type -p xprop &>/dev/null; then + glxinfo &> $debug_data_dir/glxinfo.txt + else + touch $debug_data_dir/glxinfo-absent + fi + if type -p xdpyinfo &>/dev/null; then + xdpyinfo &> $debug_data_dir/xdpyinfo.txt + else + touch $debug_data_dir/xdpyinfo-absent + fi + if type -p xrandr &>/dev/null; then + xrandr &> $debug_data_dir/xrandr.txt + else + touch $debug_data_dir/xrandr-absent + fi + if type -p X &>/dev/null; then + X -version &> $debug_data_dir/x-version.txt + else + touch $debug_data_dir/x-absent + fi + if type -p Xorg &>/dev/null; then + Xorg -version &> $debug_data_dir/xorg-version.txt + else + touch $debug_data_dir/xorg-absent + fi + echo $GNOME_DESKTOP_SESSION_ID &> $debug_data_dir/gnome-desktop-session-id.txt # kde 3 id - echo $KDE_FULL_SESSION &> $debug_data_dir/kde3-ful-session.txt - echo $KDE_SESSION_VERSION &> $debug_data_dir/kde456-session-version.txt - echo "$(kded$KDE_SESSION_VERSION --version )" &> $debug_data_dir/kde-version-data.txt + echo $KDE_FULL_SESSION &> $debug_data_dir/kde3-full-session.txt + echo $KDE_SESSION_VERSION &> $debug_data_dir/kde-gte-4-session-version.txt + if type -p kf5-config &>/dev/null; then + kf5-config --version &> $debug_data_dir/kde-kf5-config-version-data.txt + elif type -p kf6-config &>/dev/null; then + kf6-config --version &> $debug_data_dir/kde-kf6-config-version-data.txt + elif type -p kf$KDE_SESSION_VERSION-config &>/dev/null; then + kf$KDE_SESSION_VERSION-config --version &> $debug_data_dir/kde-kf$KDE_SESSION_VERSION-KSV-config-version-data.txt + else + touch $debug_data_dir/kde-kf-config-absent + fi + if type -p plasmashell &>/dev/null; then + plasmashell --version &> $debug_data_dir/kde-plasmashell-version-data.txt + else + touch $debug_data_dir/kde-plasmashell-absent + fi + if type -p kwin_x11 &>/dev/null; then + kwin_x11 --version &> $debug_data_dir/kde-kwin_x11-version-data.txt + else + touch $debug_data_dir/kde-kwin_x11-absent + fi + if type -p kded4 &>/dev/null; then + kded4 --version &> $debug_data_dir/kded4-version-data.txt + elif type -p kded5 &>/dev/null; then + kded5 --version &> $debug_data_dir/kded5-version-data.txt + elif type -p kded &>/dev/null; then + kded --version &> $debug_data_dir/kded-version-data.txt + else + touch $debug_data_dir/kded-$KDE_SESSION_VERSION-absent + fi + # kde 5/plasma desktop 5, this is maybe an extra package and won't be used + if type -p about-distro &>/dev/null; then + about-distro &> $debug_data_dir/kde-about-distro.txt + else + touch $debug_data_dir/kde-about-distro-absent + fi echo $XDG_CURRENT_DESKTOP &> $debug_data_dir/xdg-current-desktop.txt fi if [[ $1 == 'disk' || $1 == 'all' ]];then @@ -1700,21 +2058,31 @@ debug_data_collector() ls -l /dev/disk/by-id &> $debug_data_dir/dev-disk-id-data.txt ls -l /dev/disk/by-label &> $debug_data_dir/dev-disk-label-data.txt ls -l /dev/disk/by-uuid &> $debug_data_dir/dev-disk-uuid-data.txt + # http://comments.gmane.org/gmane.linux.file-systems.zfs.user/2032 + ls -l /dev/disk/by-wwn &> $debug_data_dir/dev-disk-wwn-data.txt ls -l /dev/disk/by-path &> $debug_data_dir/dev-disk-path-data.txt ls -l /dev/mapper &> $debug_data_dir/dev-disk-mapper-data.txt readlink /dev/root &> $debug_data_dir/dev-root.txt 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 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 - df -H -T &> $debug_data_dir/bsd-df-H-T-no-excludes.txt - df -H &> $debug_data_dir/bsd-df-H-no-excludes.txt + df -T -P --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 --exclude-type=devfs --exclude-type=linprocfs --exclude-type=sysfs --exclude-type=fdescfs --total &> $debug_data_dir/df-T-P-excludes-total.txt + df -h -T &> $debug_data_dir/bsd-df-h-T-no-excludes.txt + df -h &> $debug_data_dir/bsd-df-h-no-excludes.txt + df -k -T &> $debug_data_dir/bsd-df-k-T-no-excludes.txt + df -k &> $debug_data_dir/bsd-df-k-no-excludes.txt + atacontrol list &> $debug_data_dir/bsd-atacontrol-list.txt + camcontrol devlist &> $debug_data_dir/bsd-camcontrol-devlist.txt # bsd tool mount &> $debug_data_dir/mount.txt + btrfs filesystem show &> $debug_data_dir/btrfs-filesystem-show.txt + btrfs filesystem show --mounted &> $debug_data_dir/btrfs-filesystem-show-mounted.txt + # btrfs filesystem show --all-devices &> $debug_data_dir/btrfs-filesystem-show-all-devices.txt gpart list &> $debug_data_dir/bsd-gpart-list.txt gpart show &> $debug_data_dir/bsd-gpart-show.txt gpart status &> $debug_data_dir/bsd-gpart-status.txt - swapctl -l &> $debug_data_dir/bsd-swapctl-l.txt + swapctl -l -k &> $debug_data_dir/bsd-swapctl-l-k.txt swapon -s &> $debug_data_dir/swapon-s.txt - sysctl -b kern.geom.conftxt &> $debug_data_dir/bsd-sysctl-b-kern.geom.conftxt.txt + sysctl -b kern.geom.conftxt &> $debug_data_dir/bsd-sysctl-b-kern.geom.conftxt.txt sysctl -b kern.geom.confxml &> $debug_data_dir/bsd-sysctl-b-kern.geom.confxml.txt zfs list &> $debug_data_dir/bsd-zfs-list.txt zpool list &> $debug_data_dir/bsd-zpool-list.txt @@ -1734,7 +2102,7 @@ debug_data_collector() echo 'Creating inxi output file now. This can take a few seconds...' echo "Starting $SCRIPT_NAME from: $start_directory" cd $start_directory - $SCRIPT_PATH/$SCRIPT_NAME -FRploudxxx -c 0 -@ 8 > $SCRIPT_DATA_DIR/$debug_data_dir/inxi-FRploudxxx.txt + $SCRIPT_PATH/$SCRIPT_NAME -F${debug_i}Rfrploudmxxx -c 0 -@ 8 -y 120 > $SCRIPT_DATA_DIR/$debug_data_dir/inxi-F${debug_i}Rfrploudmxxxy120.txt cp $LOG_FILE $SCRIPT_DATA_DIR/$debug_data_dir if [[ -f $SCRIPT_DATA_DIR/$debug_data_dir.tar.gz ]];then echo "Found and removing previous tar.gz data file: $debug_data_dir.tar.gz" @@ -1785,34 +2153,37 @@ debug_data_collector() check_recommends_user_output() { - local Line='-----------------------------------------------------------------------------------------' + local Line=$LINE1 local gawk_version='N/A' sed_version='N/A' sudo_version='N/A' python_version='N/A' + local downloaders_bsd='' - if [[ $B_RUNNING_IN_SHELL != 'true' ]];then + if [[ $B_IRC == 'true' ]];then print_screen_output "Sorry, you can't run this option in an IRC client." exit 1 fi - + if [[ -n $BSD_TYPE ]];then + downloaders_bsd=' + fetch:BSD-only~BSD-only~BSD-only~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(BSDs) + ftp:ftp-OpenBSD-only~ftp-OpenBSD-only~ftp-OpenBSD-only~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(OpenBSD_only)' + fi initialize_paths - - echo "$SCRIPT_NAME will now begin checking for the programs it needs to operate. First a check of" - echo "the main languages and tools $SCRIPT_NAME uses. Python is only for debugging data collection." + print_lines_basic "0" "" "$SCRIPT_NAME will now begin checking for the programs it needs to operate. First a check of the main languages and tools $SCRIPT_NAME uses. Python is only for debugging data collection." echo $Line echo "Bash version: $( bash --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU bash/ {print $4}' )" - if [[ -n $( type -p gawk ) ]];then + if type -p gawk &>/dev/null;then gawk_version=$( gawk --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU Awk/ {print $3}' ) fi - if [[ -n $( type -p sed ) ]];then + if type -p sed &>/dev/null;then sed_version=$( sed --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU sed version/ {print $4}' ) if [[ -z $sed_version ]];then # note: bsd sed shows error with --version flag sed_version=$( sed --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^sed: illegal option/ {print "BSD sed"}' ) fi fi - if [[ -n $( type -p sudo ) ]];then + if type -p sudo &>/dev/null;then sudo_version=$( sudo -V 2>&1 | awk 'BEGIN {IGNORECASE=1} /^Sudo version/ {print $3}' ) fi - if [[ -n $( type -p python ) ]];then + if type -p python &>/dev/null;then python_version=$( python --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^Python/ {print $2}' ) fi echo "Gawk version: $gawk_version" @@ -1820,26 +2191,44 @@ check_recommends_user_output() echo "Sudo version: $sudo_version" echo "Python version: $python_version" echo $Line - echo "Test One: Required System Directories." - echo "If one of these system directories is missing, $SCRIPT_NAME cannot operate:" + + echo "Test One: Required System Directories (Linux Only)." + print_lines_basic "0" "" "If one of these system directories is missing, $SCRIPT_NAME cannot operate:" echo check_recommends_items 'required-dirs' + echo "Test Two: Required Core Applications." - echo "If one of these applications is missing, $SCRIPT_NAME cannot operate:" + print_lines_basic "0" "" "If one of these applications is missing, $SCRIPT_NAME cannot operate:" echo check_recommends_items 'required-apps' - echo 'Test Three: Script Recommends for Graphics Features. If you do not use X these do not matter.' - echo "If one of these applications is missing, $SCRIPT_NAME will have incomplete output:" + + print_lines_basic "0" "" "Test Three: Script Recommends for Graphics Features." + print_lines_basic "0" "" "NOTE: If you do not use X these do not matter (like a headless server). Otherwise, if one of these applications is missing, $SCRIPT_NAME will have incomplete output:" echo check_recommends_items 'recommended-x-apps' + echo 'Test Four: Script Recommends for Remaining Features.' - echo "If one of these applications is missing, $SCRIPT_NAME will have incomplete output:" + print_lines_basic "0" "" "If one of these applications is missing, $SCRIPT_NAME will have incomplete output:" echo check_recommends_items 'recommended-apps' - echo 'Test Five: System Directories for Various Information.' - echo "If one of these directories is missing, $SCRIPT_NAME will have incomplete output:" + + echo 'Test Five: Script Recommends for Remaining Features.' + print_lines_basic "0" "" "One of these downloaders needed for options -i/-w/-W (-U/-! [11-15], if supported):" + echo + check_recommends_items 'downloaders' + + echo 'Test Six: System Directories for Various Information.' + echo '(Unless otherwise noted, these are for GNU/Linux systems)' + print_lines_basic "0" "" "If one of these directories is missing, $SCRIPT_NAME may have incomplete output:" echo check_recommends_items 'system-dirs' + + echo 'Test Seven: System Files for Various Information.' + echo '(Unless otherwise noted, these are for GNU/Linux systems)' + print_lines_basic "0" "" "If one of these files is missing, $SCRIPT_NAME may have incomplete output:" + echo + check_recommends_items 'system-files' + echo 'All tests completed.' } # args: $1 - check item @@ -1848,7 +2237,7 @@ check_recommends_items() local item='' item_list='' item_string='' missing_items='' missing_string='' local package='' application='' feature='' type='' starter='' finisher='' local package_deb='' package_pacman='' package_rpm='' - local print_string='' separator='' + local print_string='' separator='' width=56 local required_dirs='/proc /sys' # package-owner: 1 - debian/ubuntu; 2 - arch; 3 - yum/rpm # pardus: pisi sf -q /usr/bin/package @@ -1862,7 +2251,6 @@ check_recommends_items() sed:sed~sed~sed~:string_replace tr:coreutils~coreutils~coreutils~:character_replace uname:uname~coreutils~coreutils~:kernel_data - uptime:procps~procps~procps~: wc:coreutils~coreutils~coreutils~:word_character_count ' local x_recommends=' @@ -1872,8 +2260,10 @@ check_recommends_items() xrandr:x11-xserver-utils~xrandr~x11-server-utils~:-G_single_screen_resolution ' local recommended_apps=' - dmidecode:dmidecode~dmidecode~dmidecode~:-M_if_no_sys_machine_data + dig:dnsutils~dnsutils~bind-utils:-i_first_wlan_ip_default_test + dmidecode:dmidecode~dmidecode~dmidecode~:-M_if_no_sys_machine_data;_-m_memory file:file~file~file~:-o_unmounted_file_system + hciconfig:bluez~bluez-utils~bluez-utils~:-n_-i_bluetooth_data hddtemp:hddtemp~hddtemp~hddtemp~:-Dx_show_hdd_temp ifconfig:net-tools~net-tools~net-tools~:-i_ip_lan-deprecated ip:iproute~iproute2~iproute~:-i_ip_lan @@ -1883,46 +2273,94 @@ check_recommends_items() modinfo:module-init-tools~module-init-tools~module-init-tools~:-Ax,-Nx_module_version runlevel:sysvinit~sysvinit~systemd~:-I_runlevel sudo:sudo~sudo~sudo~:-Dx_hddtemp-user;-o_file-user + uptime:procps~procps~procps~:-I_uptime_(check_which_package_owns_Debian) ' + + local downloaders=" + wget:wget~wget~wget~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(if_supported) + curl:curl~curl~curl~:-i_wan_ip;-w/-W;-U/-!_[11-15]_(if_supported) + $downloaders_bsd + " local recommended_dirs=' /sys/class/dmi/id:-M_system,_motherboard,_bios /dev:-l,-u,-o,-p,-P,-D_disk_partition_data /dev/disk/by-label:-l,-o,-p,-P_partition_labels /dev/disk/by-uuid:-u,-o,-p,-P_partition_uuid - /var/run/dmesg.boot:-C,-f_(BSD_only) ' + local recommended_files=" + $FILE_ASOUND_DEVICE:-A_sound_card_data + $FILE_ASOUND_VERSION:-A_ALSA_data + $FILE_CPUINFO:-C_cpu_data + $FILE_LSB_RELEASE:-S_distro_version_data_[deprecated] + $FILE_MDSTAT:-R_mdraid_data + $FILE_MEMINFO:-I_memory_data + $FILE_OS_RELEASE:-S_distro_version_data + $FILE_PARTITIONS:-p,-P_partitions_data + $FILE_MODULES:-G_module_data + $FILE_MOUNTS:-P,-p_partition_advanced_data + $FILE_DMESG_BOOT:-D,-d_disk_data_[BSD_only] + $FILE_SCSI:-D_Advanced_hard_disk_data_[used_rarely] + $FILE_XORG_LOG:-G_graphics_driver_load_status + " + + if [[ -n $COLS_INNER ]];then + if [[ $COLS_INNER -ge 90 ]];then + width=${#LINE1} # match width of $LINE1 + elif [[ $COLS_INNER -ge 78 ]];then + width=$(( $COLS_INNER - 11 )) + fi + fi case $1 in + downloaders) + item_list=$downloaders + item_string='Downloaders' + item_string='' + missing_string='downloaders, and their corresponding packages,' + type='applications' + ;; required-dirs) item_list=$required_dirs item_string='Required file system' + item_string='' missing_string='system directories' type='directories' ;; required-apps) item_list=$required_apps item_string='Required application' + item_string='' missing_string='applications, and their corresponding packages,' type='applications' ;; recommended-x-apps) item_list=$x_recommends item_string='Recommended X application' + item_string='' missing_string='applications, and their corresponding packages,' type='applications' ;; recommended-apps) item_list=$recommended_apps item_string='Recommended application' + item_string='' missing_string='applications, and their corresponding packages,' type='applications' ;; system-dirs) item_list=$recommended_dirs item_string='System directory' + item_string='' missing_string='system directories' type='directories' ;; + system-files) + item_list=$recommended_files + item_string='System file' + item_string='' + missing_string='system files' + type='files' + ;; esac # great trick from: http://ideatrash.net/2011/01/bash-string-padding-with-sed.html # left pad: sed -e :a -e 's/^.\{1,80\}$/& /;ta' @@ -1952,13 +2390,13 @@ check_recommends_items() fi fi if [[ -n $feature ]];then - print_string="$item_string: $application (info: $( sed 's/_/ /g' <<< $feature ))" + print_string="$item_string$application (info: $( sed 's/_/ /g' <<< $feature ))" else - print_string="$item_string: $application" + print_string="$item_string$application" fi - starter="$( sed -e :a -e 's/^.\{1,75\}$/&./;ta' <<< $print_string )" - if [[ -z $( grep '^/' <<< $application ) && -n $location ]] || [[ -d $application ]];then + starter="$( sed -e :a -e 's/^.\{1,'$width'\}$/&./;ta' <<< $print_string )" + if [[ -z $( grep '^/' <<< $application ) && -n $location ]] || [[ -d $application || -f $application ]];then if [[ -n $location ]];then finisher=" $location" else @@ -1979,21 +2417,22 @@ check_recommends_items() do application=$( cut -d ':' -f 1 <<< $item ) if [[ $type == 'applications' ]];then - # echo '--------------------------------------------------------' echo package=$( cut -d ':' -f 2 <<< $item ) package_deb=$( cut -d '~' -f 1 <<< $package ) package_pacman=$( cut -d '~' -f 2 <<< $package ) package_rpm=$( cut -d '~' -f 3 <<< $package ) echo "Application: $application" - echo "To add to your system, install the proper distribution package for your system:" - echo "Debian/Ubuntu: $package_deb :: Arch Linux: $package_pacman :: Redhat/Fedora/Suse: $package_rpm" - else + print_lines_basic "0" "" "To add to your system, install the proper distribution package for your system:" + print_lines_basic "0" "" "Debian/Ubuntu:^$package_deb^:: Arch Linux:^$package_pacman^:: Redhat/Fedora/Suse:^$package_rpm" + elif [[ $type == 'directories' ]];then echo "Directory: $application" + elif [[ $type == 'files' ]];then + echo "File: $application" fi done if [[ $item_string == 'System directory' ]];then - echo "These directories are created by the kernel, so don't worry if they are not present." + print_lines_basic "0" "" "These directories are created by the kernel, so don't worry if they are not present." fi else echo "All the $( cut -d ' ' -f 1 <<< $item_string | sed -e 's/Re/re/' -e 's/Sy/sy/' ) $type are present." @@ -2032,18 +2471,14 @@ print_screen_output() print_data="P: $print_data" fi fi - if [[ $KONVI -eq 1 && $B_DCOP == 'true' ]]; then ## dcop Konversation (<= 1.1 (qt3)) # konvi doesn't seem to like \n characters, it just prints them literally $print_data="$( tr '\n' ' ' <<< "$print_data" )" dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data" - elif [[ $KONVI -eq 3 && $B_QDBUS == 'true' ]]; then ## dbus Konversation (> 1.2 (qt4)) qdbus org.kde.konversation /irc say "$DCSERVER" "$DCTARGET" "$print_data" - # elif [[ $IRC_CLIENT == 'X-Chat' ]]; then # qdbus org.xchat.service print "$print_data\n" - else # the -n is needed to avoid double spacing of output in terminal echo -ne "$print_data\n" @@ -2056,8 +2491,9 @@ print_screen_output() create_print_line() { eval $LOGFS - local line=$2 - printf "${C1}%-${INDENT}s${C2} %s" "$1" "$line" + # convoluted, yes, but it works to trim spaces off end + local line=${2%${2##*[![:space:]]}} + printf "${C1}%-${INDENT}s${C2} %s" "$1" "$line${CN}" eval $LOGFE } @@ -2093,13 +2529,12 @@ remove_erroneous_chars() get_parameters() { eval $LOGFS - local opt='' wget_test='' debug_data_type='' weather_flag='wW:' + local opt='' downloader_test='' debug_data_type='' weather_flag='wW:' local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false # if distro maintainers don't want the weather feature disable it if [[ $B_ALLOW_WEATHER == 'false' ]];then weather_flag='' - fi if [[ $1 == '--version' ]];then print_version_info @@ -2114,7 +2549,7 @@ get_parameters() # no need to run through these if there are no args # reserved for future use: -g for extra Graphics; -m for extra Machine; -d for extra Disk elif [[ -n $1 ]];then - while getopts Abc:CdDfFGhHiIlMnNopPrRsSt:uUv:V${weather_flag}xzZ%@:!: opt + while getopts AbBc:CdDfFGhHiIlmMnNopPrRsSt:uUv:V${weather_flag}xy:zZ%@:!: opt do case $opt in A) B_SHOW_AUDIO='true' @@ -2127,10 +2562,15 @@ get_parameters() B_SHOW_GRAPHICS='true' B_SHOW_INFO='true' B_SHOW_MACHINE='true' + B_SHOW_BATTERY='true' B_SHOW_NETWORK='true' B_SHOW_SYSTEM='true' ;; - c) if [[ -n $( grep -E '^[0-9][0-9]?$' <<< $OPTARG ) ]];then + B) B_SHOW_BATTERY_FORCED='true' + B_SHOW_BATTERY='true' + use_short='false' + ;; + c) if [[ $OPTARG =~ ^[0-9][0-9]?$ ]];then case $OPTARG in 99) B_RUN_COLOR_SELECTOR='true' @@ -2193,6 +2633,7 @@ get_parameters() B_SHOW_GRAPHICS='true' B_SHOW_INFO='true' B_SHOW_MACHINE='true' + B_SHOW_BATTERY='true' B_SHOW_NETWORK='true' B_SHOW_PARTITIONS='true' B_SHOW_RAID='true' @@ -2215,7 +2656,11 @@ get_parameters() B_SHOW_PARTITIONS='true' use_short='false' ;; + m) B_SHOW_MEMORY='true' + use_short='false' + ;; M) B_SHOW_MACHINE='true' + B_SHOW_BATTERY='true' use_short='false' ;; n) B_SHOW_ADVANCED_NETWORK='true' @@ -2251,7 +2696,7 @@ get_parameters() S) B_SHOW_SYSTEM='true' use_short='false' ;; - t) if [[ -n $( grep -E '^(c|m|cm|mc)([1-9]|1[0-9]|20)?$' <<< $OPTARG ) ]];then + t) if [[ $OPTARG =~ ^(c|m|cm|mc)([1-9]|1[0-9]|20)?$ ]];then use_short='false' if [[ -n $( grep -E '[0-9]+' <<< $OPTARG ) ]];then PS_COUNT=$( sed 's/[^0-9]//g' <<< $OPTARG ) @@ -2270,7 +2715,7 @@ get_parameters() B_SHOW_PARTITIONS='true' use_short='false' ;; - v) if [[ -n $( grep -E "^[0-9][0-9]?$" <<< $OPTARG ) && $OPTARG -le $VERBOSITY_LEVELS ]];then + v) if [[ $OPTARG =~ ^[0-9][0-9]?$ && $OPTARG -le $VERBOSITY_LEVELS ]];then if [[ $OPTARG -ge 1 ]];then use_short='false' B_SHOW_BASIC_CPU='true' @@ -2282,6 +2727,7 @@ get_parameters() if [[ $OPTARG -ge 2 ]];then B_SHOW_BASIC_DISK='true' B_SHOW_BASIC_RAID='true' + B_SHOW_BATTERY='true' B_SHOW_MACHINE='true' B_SHOW_NETWORK='true' fi @@ -2297,6 +2743,7 @@ get_parameters() if [[ $OPTARG -ge 5 ]];then B_SHOW_AUDIO='true' B_SHOW_BASIC_OPTICAL='true' + B_SHOW_MEMORY='true' B_SHOW_SENSORS='true' B_SHOW_LABELS='true' B_SHOW_UUIDS='true' @@ -2346,6 +2793,12 @@ get_parameters() B_EXTRA_DATA='true' fi ;; + y) if [[ -z ${OPTARG//[0-9]/} && $OPTARG -ge 80 ]];then + set_display_width "$OPTARG" + else + error_handler 21 "$OPTARG" + fi + ;; z) B_OUTPUT_FILTER='true' ;; Z) B_OVERRIDE_FILTER='true' @@ -2359,7 +2812,7 @@ get_parameters() ## debuggers and testing tools %) B_HANDLE_CORRUPT_DATA='true' ;; - @) if [[ -n $( grep -E "^([1-9]|1[0-4])$" <<< $OPTARG ) ]];then + @) if [[ -n $( grep -E "^([1-9]|1[0-5])$" <<< $OPTARG ) ]];then DEBUG=$OPTARG if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then B_UPLOAD_DEBUG_DATA='true' @@ -2379,7 +2832,7 @@ get_parameters() LOGFE=$LOGFE_STRING create_rotate_logfiles # create/rotate logfiles before we do anything else ;; - 11|12|13|14) + 11|12|13|14|15) case $OPTARG in 11) debug_data_type='sys' @@ -2393,6 +2846,10 @@ get_parameters() 14) debug_data_type='all' ;; + 15) + debug_data_type='all' + B_DEBUG_I='true' + ;; esac initialize_data debug_data_collector $debug_data_type @@ -2444,7 +2901,7 @@ get_parameters() fi ;; 30) - B_RUNNING_IN_SHELL='true' + B_IRC='false' ;; 31) B_SHOW_HOST='false' @@ -2452,6 +2909,9 @@ get_parameters() 32) B_SHOW_HOST='true' ;; + 33) + B_FORCE_DMIDECODE='true' + ;; ftp*) ALTERNATE_FTP="$OPTARG" ;; @@ -2498,7 +2958,7 @@ show_options() local color_scheme_count=$(( ${#A_COLOR_SCHEMES[@]} - 1 )) local partition_string='partition' partition_string_u='Partition' - if [[ $B_RUNNING_IN_SHELL != 'true' ]];then + if [[ $B_IRC == 'true' ]];then print_screen_output "Sorry, you can't run the help option in an IRC client." exit 1 fi @@ -2512,14 +2972,14 @@ show_options() # print_screen_output " " print_lines_basic "0" "" "$SCRIPT_NAME supports the following options. You can combine them, or list them one by one. Examples: $SCRIPT_NAME^-v4^-c6 OR $SCRIPT_NAME^-bDc^6. If you start $SCRIPT_NAME with no arguments, it will show the short form." print_screen_output " " - print_lines_basic "0" "" "The following options if used without -F, -b, or -v will show just option line(s): 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 just the line(s) you want to see. If you use them with -v [level], -b or -F, it will show the full output for that line along with the output for the chosen verbosity level." - + print_lines_basic "0" "" "The following options if used without -F, -b, or -v will show just option line(s): A, B, C, D, G, I, M, N, P, R, S, f, i, m, n, o, p, l, u, r, s, t - you can use these alone or together to show just the line(s) you want to see. If you use them with -v^[level], -b or -F, it will show the full output for that line along with the output for the chosen verbosity level." print_screen_output "- - - - - - - - - - - - - - - - - - - - - - - - - - - - -" print_screen_output "Output Control Options:" print_lines_basic "1" "-A" "Audio/sound card information." - print_lines_basic "1" "-b" "Basic output, short form. Like $SCRIPT_NAME^-v^2, only minus hard disk names." + print_lines_basic "1" "-b" "Basic output, short form. Like $SCRIPT_NAME^-v^2, only minus hard disk names ." + print_lines_basic "1" "-B" "Battery info, shows charge, condition, plus extra information (if battery present)." print_lines_basic "1" "-c" "Color schemes. Scheme number is required. Color selectors run a color selector option prior to $SCRIPT_NAME starting which lets you set the config file value for the selection." - print_lines_basic "1" "" "Supported color schemes: 0-$color_scheme_count Example: $SCRIPT_NAME^-c^11" + print_lines_basic "1" "" "Supported color schemes: 0-$color_scheme_count Example:^$SCRIPT_NAME^-c^11" print_lines_basic "1" "" "Color selectors for each type display (NOTE: irc and global only show safe color set):" # print_screen_output " Supported color schemes: 0-$color_scheme_count Example: $SCRIPT_NAME -c 11" # print_screen_output " Color selectors for each type display (NOTE: irc and global only show safe color set):" @@ -2529,45 +2989,48 @@ show_options() print_lines_basic "2" "97" "Console IRC running in X - like irssi in xTerm" print_lines_basic "2" "98" "Console IRC not in X" print_lines_basic "2" "99" "Global - Overrides/removes all settings. Setting specific removes global." - print_lines_basic "1" "-C" "CPU output, including per CPU clockspeed (if available)." + print_lines_basic "1" "-C" "CPU output, including per CPU clockspeed and max CPU speed (if available)." print_lines_basic "1" "-d" "Optical drive data. Same as -Dd. See also -x and -xx." - print_lines_basic "1" "-D" "Full hard Disk info, not only model, ie: /dev/sda ST380817AS 80.0GB. See also -x and -xx." + print_lines_basic "1" "-D" "Full hard Disk info, not only model, ie: /dev/sda ST380817AS 80.0GB. See also -x and -xx. Disk total used percentage includes swap partition size(s)." print_lines_basic "1" "-f" "All cpu flags, triggers -C. Not shown with -F to avoid spamming. ARM cpus show 'features'." - print_lines_basic "1" "-F" "Full output for $SCRIPT_NAME. Includes all Upper Case line letters, plus -s and -n. Does not show extra verbose options like -x -d -f -u -l -o -p -t -r" + print_lines_basic "1" "-F" "Full output for $SCRIPT_NAME. Includes all Upper Case line letters, plus -s and -n. Does not show extra verbose options like -d -f -l -m -o -p -r -t -u -x" print_lines_basic "1" "-G" "Graphic card information (card, display server type/version, resolution, glx renderer, version)." - print_lines_basic "1" "-i" "Wan IP address, and shows local interfaces (requires ifconfig network tool). Same as -Nni. Not shown with -F for user security reasons, you shouldn't paste your local/wan IP." + print_lines_basic "1" "-i" "Wan IP address, and shows local interfaces (requires ifconfig + network tool). Same as -Nni. Not shown with -F for user security reasons, you shouldn't paste your local/wan IP." print_lines_basic "1" "-I" "Information: processes, uptime, memory, irc client (or shell type), $SCRIPT_NAME version." - print_lines_basic "1" "-l" "${partition_string_u} labels. Default: short ${partition_string} -P. For full -p output, use: -pl (or -plu)." - print_lines_basic "1" "-M" "Machine data. Motherboard, Bios, and if present, System Builder (Like Lenovo). Older systems/kernels without the required /sys data can use dmidecode instead, run as root." + print_lines_basic "1" "-l" "$partition_string_u labels. Default: short $partition_string -P. For full -p output, use: -pl (or -plu)." + print_lines_basic "1" "-m" "Memory (RAM) data. Physical system memory array(s), capacity, how many devices (slots) supported, and individual memory devices (sticks of memory etc). For devices, shows device locator, size, speed, type (like: DDR3). Also see -x, -xx, -xxx" + print_lines_basic "1" "-M" "Machine data. Motherboard, Bios, and if present, System Builder (Like Lenovo). Older systems/kernels without the required /sys data can use dmidecode instead, run as root. Dmidecode can be forced with -! 33" print_lines_basic "1" "-n" "Advanced Network card information. Same as -Nn. Shows interface, speed, mac id, state, etc." print_lines_basic "1" "-N" "Network card information. With -x, shows PCI BusID, Port number." - print_lines_basic "1" "-o" "Unmounted ${partition_string} information (includes UUID and LABEL if available). Shows file system type if you have file installed, if you are root OR if you have added to /etc/sudoers (sudo v. 1.7 or newer) Example:^^ALL^=^NOPASSWD:^/usr/bin/file^" - print_lines_basic "1" "-p" "Full ${partition_string} information (-P plus all other detected ${partition_string}s)." - print_lines_basic "1" "-P" "Basic ${partition_string} information (shows what -v 4 would show, but without extra data). Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted ${partition_string}s." - print_lines_basic "1" "-r" "Distro repository data. Supported repo types: APT; PACMAN; PISI; YUM; URPMQ; Ports." + print_lines_basic "1" "-o" "Unmounted $partition_string information (includes UUID and LABEL if available). Shows file system type if you have file installed, if you are root OR if you have added to /etc/sudoers (sudo v. 1.7 or newer) Example:^^ALL^=^NOPASSWD:^/usr/bin/file^" + print_lines_basic "1" "-p" "Full $partition_string information (-P plus all other detected ${partition_string}s)." + print_lines_basic "1" "-P" "Basic $partition_string information (shows what -v^4 would show, but without extra data). Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted ${partition_string}s." + print_lines_basic "1" "-r" "Distro repository data. Supported repo types: APT; PACMAN; PISI; PORTAGE; PORTS (BSDs); SLACKPKG; URPMQ; YUM; ZYPP." print_lines_basic "1" "-R" "RAID data. Shows RAID devices, states, levels, and components, and extra data with -x/-xx. md-raid: If device is resyncing, shows resync progress line as well." print_lines_basic "1" "-s" "Sensors output (if sensors installed/configured): mobo/cpu/gpu temp; detected fan speeds. Gpu temp only for Fglrx/Nvidia drivers. Nvidia shows screen number for > 1 screens." print_lines_basic "1" "-S" "System information: host name, kernel, desktop environment (if in X), distro" - print_lines_basic "1" "-t" "Processes. Requires extra options: c (cpu) m (memory) cm (cpu+memory). If followed by numbers 1-20, shows that number of processes for each type (default:^$PS_COUNT; if in irc, max:^5): -t^cm10" + print_lines_basic "1" "-t" "Processes. Requires extra options: c^(cpu) m^(memory) cm^(cpu+memory). If followed by numbers 1-20, shows that number of processes for each type (default:^$PS_COUNT; if in irc, max:^5): -t^cm10" print_lines_basic "1" "" "Make sure to have no space between letters and numbers (-t^cm10 - right, -t^cm^10 - wrong)." - print_lines_basic "1" "-u" "${partition_string_u} UUIDs. Default: short ${partition_string} -P. For full -p output, use: -pu (or -plu)." + print_lines_basic "1" "-u" "$partition_string_u UUIDs. Default: short $partition_string -P. For full -p output, use: -pu (or -plu)." print_lines_basic "1" "-v" "Script verbosity levels. Verbosity level number is required. Should not be used with -b or -F" - print_lines_basic "1" "" "Supported levels: 0-${VERBOSITY_LEVELS} Example: $SCRIPT_NAME^-v^4" + print_lines_basic "1" "" "Supported levels: 0-$VERBOSITY_LEVELS Example: $SCRIPT_NAME^-v^4" print_lines_basic "2" "0" "Short output, same as: $SCRIPT_NAME" print_lines_basic "2" "1" "Basic verbose, -S + basic CPU + -G + basic Disk + -I." - print_lines_basic "2" "2" "Networking card (-N), Machine (-M) data, shows basic hard disk data (names only), and, if present, basic raid (devices only, and if inactive, notes that). similar to: $SCRIPT_NAME^-b" - print_lines_basic "2" "3" "Advanced CPU (-C), network (-n) data, and switches on -x advanced data option." - print_lines_basic "2" "4" "${partition_string_u} size/filled data (-P) for (if present):/, /home, /var/, /boot. Shows full disk data (-D)." - print_lines_basic "2" "5" "Audio card (-A); sensors (-s), ${partition_string} label (-l) and UUID (-u), short form of optical drives, standard raid data (-R)." - print_lines_basic "2" "6" "Full ${partition_string} (-p), unmounted ${partition_string} (-o), optical drive (-d), full raid; triggers -xx." + print_lines_basic "2" "2" "Networking card (-N), Machine (-M) data, if present, Battery (-B), basic hard disk data (names only), and, if present, basic raid (devices only, and if inactive, notes that). similar to: $SCRIPT_NAME^-b" + print_lines_basic "2" "3" "Advanced CPU (-C), battery, network (-n) data, and switches on -x advanced data option." + print_lines_basic "2" "4" "$partition_string_u size/filled data (-P) for (if present): /, /home, /var/, /boot. Shows full disk data (-D)." + print_lines_basic "2" "5" "Audio card (-A); sensors^(-s), memory/ram^(-m), $partition_string label^(-l) and UUID^(-u), short form of optical drives, standard raid data (-R)." + print_lines_basic "2" "6" "Full $partition_string (-p), unmounted $partition_string (-o), optical drive (-d), full raid; triggers -xx." print_lines_basic "2" "7" "Network IP data (-i); triggers -xxx." # if distro maintainers don't want the weather feature disable it if [[ $B_ALLOW_WEATHER == 'true' ]];then print_lines_basic "1" "-w" "Local weather data/time. To check an alternate location, see: -W^. For extra weather data options see -x, -xx, and -xxx." - print_lines_basic "1" "-W" " Supported options for : postal code; city, state/country; latitude/longitude. Only use if you want the weather somewhere other than the machine running $SCRIPT_NAME. Use only ascii characters, replace spaces in city/state/country names with '+'. Example:^$SCRIPT_NAME^-W^new+york,ny" + print_lines_basic "1" "-W" " Supported options for : postal code; city, state/country; latitude, longitude. Only use if you want the weather somewhere other than the machine running $SCRIPT_NAME. Use only ascii characters, replace spaces in city/state/country names with '+'. Example:^$SCRIPT_NAME^-W^new+york,ny" fi print_lines_basic "1" "-x" "Adds the following extra data (only works with verbose or line output, not short form):" + print_lines_basic "2" "-B" "Vendor/model, status (if available)" print_lines_basic "2" "-C" "CPU Flags, Bogomips on Cpu;" print_lines_basic "2" "-d" "Extra optical drive data; adds rev version to optical drive." print_lines_basic "2" "-D" "Hdd temp with disk data if you have hddtemp installed, if you are root OR if you have added to /etc/sudoers (sudo v. 1.7 or newer) Example:^^ALL^=^NOPASSWD:^/usr/sbin/hddtemp" @@ -2575,9 +3038,10 @@ show_options() print_lines_basic "2" "-G" "(for single gpu, nvidia driver) screen number gpu is running on." print_lines_basic "2" "-i" "IPv6 as well for LAN interface (IF) devices." print_lines_basic "2" "-I" "System GCC, default. With -xx, also show other installed GCC versions. If running in console, not in IRC client, shows shell version number, if detected. Init/RC Type and runlevel (if available)." + print_lines_basic "2" "-m" "Part number; Max memory module size (if available)." print_lines_basic "2" "-N -A" "Version/port(s)/driver version (if available) for Network/Audio;" print_lines_basic "2" "-N -A -G" "Network, audio, graphics, shows PCI Bus ID/Usb ID number of card." - print_lines_basic "2" "-R" "md-raid: Shows component raid id. Adds second RAID Info line: raid level; report on drives (like 5/5); blocks; chunk size; bitmap (if present). Resync line, shows blocks synced/total blocks. zfs-raid: Shows raid array full size; available size; portion allocated to RAID" + print_lines_basic "2" "-R" "md-raid: Shows component raid id. Adds second RAID Info line: raid level; report on drives (like 5/5); blocks; chunk size; bitmap (if present). Resync line, shows blocks synced/total blocks. zfs-raid: Shows raid array full size; available size; portion allocated to RAID" print_lines_basic "2" "-S" "Desktop toolkit if avaliable (GNOME/XFCE/KDE only); Kernel gcc version" print_lines_basic "2" "-t" "Memory use output to cpu (-xt c), and cpu use to memory (-xt m)." if [[ $B_ALLOW_WEATHER == 'true' ]];then @@ -2585,9 +3049,12 @@ show_options() fi print_lines_basic "1" "-xx" "Show extra, extra data (only works with verbose or line output, not short form):" print_lines_basic "2" "-A" "Chip vendor:product ID for each audio device." + print_lines_basic "2" "-B" "serial number, voltage (if available)." + print_lines_basic "2" "-C" "Minimum CPU speed, if available." print_lines_basic "2" "-D" "Disk serial number." print_lines_basic "2" "-G" "Chip vendor:product ID for each video card." print_lines_basic "2" "-I" "Other detected installed gcc versions (if present). System default runlevel. Adds parent program (or tty) for shell info if not in IRC (like Konsole or Gterm). Adds Init/RC (if found) version number." + print_lines_basic "2" "-m" "Manufacturer, Serial Number, single/double bank (if found)." print_lines_basic "2" "-M" "Chassis information, bios rom size (dmidecode only), if data for either is available." print_lines_basic "2" "-N" "Chip vendor:product ID for each nic." print_lines_basic "2" "-R" "md-raid: Superblock (if present); algorythm, U data. Adds system info line (kernel support,read ahead, raid events). If present, adds unused device line. Resync line, shows progress bar." @@ -2597,10 +3064,13 @@ show_options() fi print_lines_basic "2" "-@ 11-14" "Automatically uploads debugger data tar.gz file to ftp.techpatterns.com. EG: $SCRIPT_NAME^-xx@14" print_lines_basic "1" "-xxx" "Show extra, extra, extra data (only works with verbose or line output, not short form):" + print_lines_basic "2" "-B" "chemistry, cycles, location (if available)." + print_lines_basic "2" "-m" "Width of memory bus, data and total (if present and greater than data); Detail, if present, for Type; module voltage, if available." print_lines_basic "2" "-S" "Panel/shell information in desktop output, if in X (like gnome-shell, cinnamon, mate-panel)." if [[ $B_ALLOW_WEATHER == 'true' ]];then print_lines_basic "2" "-w -W" "Location (uses -z/irc filter), weather observation time, wind chill, heat index, dew point (shows extra lines for data where relevant)." fi + print_lines_basic "1" "-y" "Required extra option: integer, 80 or greater. Set the output line width max. Overrides IRC/Terminal settings or actual widths. If used with -h, put -y option first. Example:^inxi^-y^130" print_lines_basic "1" "-z" "Security filters for IP/Mac addresses, location, user home directory name. Default on for irc clients." print_lines_basic "1" "-Z" "Absolute override for output filters. Useful for debugging networking issues in irc for example." print_screen_output " " @@ -2621,7 +3091,7 @@ show_options() print_lines_basic "2" "9" "Full file/sys info logging" print_lines_basic "2" "10" "Color logging." print_lines_basic "1" "" "The following create a tar.gz file of system data, plus collecting the inxi output to file. To automatically upload debugger data tar.gz file to ftp.techpatterns.com: inxi^-xx@^<11-14>" - print_lines_basic "1" "" "For alternate ftp upload locations: Example: inxi^-!^ftp.yourserver.com/incoming^-xx@^14" + print_lines_basic "1" "" "For alternate ftp upload locations: Example:^inxi^-!^ftp.yourserver.com/incoming^-xx@^14" print_lines_basic "2" "11" "With data file of xiin read of /sys." print_lines_basic "2" "12" "With xorg conf and log data, xrandr, xprop, xdpyinfo, glxinfo etc." print_lines_basic "2" "13" "With data from dev, disks, ${partition_string}s, etc., plus xiin data file." @@ -2630,6 +3100,7 @@ show_options() print_screen_output "Advanced Options:" print_lines_basic "1" "-! 31" "Turns off hostname in output. Useful if showing output from servers etc." print_lines_basic "1" "-! 32" "Turns on hostname in output. Overrides global B_SHOW_HOST='false'" + print_lines_basic "1" "-! 33" "Forces use of dmidecode data instead of /sys where relevant (-M)." if [[ $1 == 'full' ]];then print_screen_output " " @@ -2645,9 +3116,10 @@ show_options() print_lines_basic "1" "-! 14" "Triggers an update from svn branch four - if present, of course." print_lines_basic "1" "-! 15" "Triggers an update from svn branch BSD - if present, of course." print_lines_basic "1" "-! 16" "Triggers an update from svn branch GNUBSD - if present, of course." - print_lines_basic "1" "-! " "Triggers an update from whatever server you list." + print_lines_basic "1" "-! " " Triggers an update from whatever server you list." + print_lines_basic "1" "" "Example: inxi^-!^http://yourserver.com/testing/inxi" fi - print_lines_basic "1" "-! " "Changes debugging data ftp upload location to whatever you enter here. Only used together with -xx@^11-14, and must be used in front of that. " + print_lines_basic "1" "-! " " Changes debugging data ftp upload location to whatever you enter here. Only used together with -xx@^11-14, and must be used in front of that." print_lines_basic "1" "" "Example: inxi^-!^ftp.yourserver.com/incoming^-xx@^14" fi print_screen_output " " @@ -2655,6 +3127,8 @@ show_options() # uses $TERM_COLUMNS to set width using $COLS_MAX as max width # IMPORTANT: minimize use of subshells here or the output is too slow +# IMPORTANT: each text chunk must be a continuous line, no line breaks. For anyone who uses a +# code editor that can't do visual (not hard coded) line wrapping, upgrade to one that can. # args: $1 - 0 1 2 3 4 for indentation level; $2 -line starter, like -m; $3 - content of block. print_lines_basic() { @@ -2793,19 +3267,19 @@ print_version_info() local year_modified=$( gawk '{print $NF}' <<< "$last_modified" ) print_screen_output "$SCRIPT_NAME $SCRIPT_VERSION_NUMBER-$SCRIPT_PATCH_NUMBER ($last_modified)" - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ $B_IRC == 'false' ]];then print_screen_output "Program Location: $script_path" if [[ -n $script_symbolic_start ]];then print_screen_output "Started via symbolic link: $script_symbolic_start" fi - print_lines_basic "0" "" "Website:^http://inxi.goooglecode.com" + print_lines_basic "0" "" "Website:^https://github.com/smxi/inxi^or^http://smxi.org/" print_lines_basic "0" "" "IRC:^irc.oftc.net channel:^#smxi" print_lines_basic "0" "" "Forums:^http://techpatterns.com/forums/forum-33.html" print_screen_output " " print_lines_basic "0" "" "$SCRIPT_NAME - the universal, portable, system information tool for console and irc." print_screen_output " " - print_lines_basic "0" "" "This program started life as a fork of Infobash 3.02: Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif." - print_lines_basic "0" "" "Subsequent changes and modifications (after Infobash 3.02): Copyright (C) 2008-$year_modified Scott Rogers, Harald Hope, aka trash80 & h2" + print_lines_basic "0" "" "This program started life as a fork of Infobash 3.02: Copyright^(C)^2005-2007^Michiel^de^Boer^a.k.a.^locsmif." + print_lines_basic "0" "" "Subsequent changes and modifications (after Infobash 3.02): Copyright^(C)^2008-${year_modified%%-*}^Harald^Hope,^Scott^Rogers,^aka^h2^&trash80." print_screen_output " " print_lines_basic "0" "" "This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. (http://www.gnu.org/licenses/gpl.html)" fi @@ -2827,7 +3301,7 @@ get_start_client() local B_Non_Native_App='false' pppid='' App_Working_Name='' local b_qt4_konvi='false' ps_parent='' - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ $B_IRC == 'false' ]];then IRC_CLIENT='Shell' unset IRC_CLIENT_VERSION # elif [[ -n $PPID ]];then @@ -2838,8 +3312,8 @@ get_start_client() Irc_Client_Path=$( readlink /proc/$PPID/exe ) # Irc_Client_Path=$( ps -p $PPID | gawk '!/[[:space:]]*PID/ {print $5}' ) # echo $( ps -p $PPID ) - irc_client_path_lower=$( tr '[:upper:]' '[:lower:]' <<< $Irc_Client_Path ) - App_Working_Name=$( basename $irc_client_path_lower ) + irc_client_path_lower=$( tr '[A-Z]' '[a-z]' <<< $Irc_Client_Path ) + App_Working_Name=${irc_client_path_lower##*/} # handles the xchat/sh/bash/dash cases, and the konversation/perl cases, where clients # report themselves as perl or unknown shell. IE: when konversation starts inxi # from inside itself, as a script, the parent is konversation/xchat, not perl/bash etc @@ -2847,11 +3321,16 @@ get_start_client() case $App_Working_Name in # bsd will never use this section bash|dash|sh|python*|perl*) # We want to know who wrapped it into the shell or perl. - pppid="$( ps -p $PPID -o ppid --no-headers | sed 's/[[:space:]]//g' )" + if [[ $BSD_TYPE != 'bsd' ]];then + pppid=$( ps -p $PPID -o ppid --no-headers 2>/dev/null | gawk '{print $NF}' ) + else + # without --no-headers we need the second line + pppid=$( ps -p $PPID -o ppid 2>/dev/null | gawk '$1 ~ /^[0-9]+/ {print $5}' ) + fi if [[ -n $pppid && -f /proc/$pppid/exe ]];then Irc_Client_Path="$( readlink /proc/$pppid/exe )" - irc_client_path_lower="$( tr '[:upper:]' '[:lower:]' <<< $Irc_Client_Path )" - App_Working_Name=$( basename $irc_client_path_lower ) + irc_client_path_lower=$( tr '[A-Z]' '[a-z]' <<< $Irc_Client_Path ) + App_Working_Name=${irc_client_path_lower##*/} B_Non_Native_App='true' fi ;; @@ -2882,16 +3361,18 @@ get_start_client() }' )" else # this should handle certain cases where it's ssh or some other startup tool - # that falls through all the other tests + # that falls through all the other tests. Also bsd irc clients will land here if [[ $BSD_TYPE != 'bsd' ]];then App_Working_Name=$(ps -p $PPID --no-headers 2>/dev/null | gawk '{print $NF}' ) else # without --no-headers we need the second line - App_Working_Name=$(ps -p $PPID 2>/dev/null | gawk '/^[0-9]+/ {print $5}' ) + App_Working_Name=$(ps -p $PPID 2>/dev/null | gawk '$1 ~ /^[0-9]+/ {print $5}' ) fi if [[ -n $App_Working_Name ]];then Irc_Client_Path=$App_Working_Name + irc_client_path_lower=$( tr '[A-Z]' '[a-z]' <<< $Irc_Client_Path ) + App_Working_Name=${irc_client_path_lower##*/} B_Non_Native_App='false' get_irc_client_version if [[ -z $IRC_CLIENT ]];then @@ -2986,7 +3467,7 @@ get_irc_client_version() B_CONSOLE_IRC='true' IRC_CLIENT="ircII" ;; - irssi-text|irssi) + irssi|irssi-text) IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 { print $2 }' )" @@ -3012,7 +3493,6 @@ get_irc_client_version() } exit }' )" - T=($IRC_CLIENT_VERSION) if [[ ${T[0]} == *+* ]];then # < Sho_> locsmif: The version numbers of SVN versions look like this: @@ -3034,7 +3514,7 @@ get_irc_client_version() # Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc # becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller # than 1 and change the DCOP parameter/object accordingly. - if [[ ${T2} -lt 1 ]];then + if [[ $T2 -lt 1 ]];then DCOPOBJ="Konversation" fi IRC_CLIENT="Konversation" @@ -3067,24 +3547,33 @@ get_irc_client_version() }' )" IRC_CLIENT="Pidgin" ;; + # possible failure of wildcard so make it explicit quassel*) # sample: quassel -v - # Qt: 4.5.0 + ## Qt: 4.5.0 - in Qt4 the output came from src/common/quassel.cpp # KDE: 4.2.65 (KDE 4.2.65 (KDE 4.3 >= 20090226)) # Quassel IRC: v0.4.0 [+60] (git-22effe5) # note: early < 0.4.1 quassels do not have -v - IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v 2>/dev/null | gawk -F ': ' ' + ## Qt: 5: sample: quassel -v + # quassel v0.13-pre (0.12.0+5 git-8e2f578) + # because in Qt5 the internal CommandLineParser is used + IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v 2>/dev/null | gawk ' BEGIN { IGNORECASE=1 clientVersion="" } - /Quassel IRC/ { + # qt 4 -v syntax + /^Quassel IRC:/ { + clientVersion = $3 + } + # qt 5 -v syntax + /^quassel\s[v]?[0-9]/ { clientVersion = $2 } END { # this handles pre 0.4.1 cases with no -v if ( clientVersion == "" ) { - clientVersion = "(pre v0.4.1)" + clientVersion = "(pre v0.4.1)?" } print clientVersion }' )" @@ -3102,10 +3591,22 @@ get_irc_client_version() ;; esac ;; - weechat-curses) + gribble|limnoria|supybot) + IRC_CLIENT_VERSION=" $( get_program_version 'supybot' '^Supybot' '2' )" + if [[ -n $IRC_CLIENT_VERSION ]];then + if [[ -n ${IRC_CLIENT_VERSION/*gribble*/} || $App_Working_Name == 'gribble' ]];then + IRC_CLIENT="Gribble" + elif [[ -n ${IRC_CLIENT_VERSION/*limnoria*/} || $App_Working_Name == 'limnoria' ]];then + IRC_CLIENT="Limnoria" + else + IRC_CLIENT="Supybot" + fi + fi + ;; + weechat|weechat-curses) IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v ) " B_CONSOLE_IRC='true' - IRC_CLIENT="Weechat" + IRC_CLIENT="WeeChat" ;; xchat-gnome) IRC_CLIENT_VERSION=" $( $Irc_Client_Path -v | gawk 'NR == 1 { @@ -3147,11 +3648,11 @@ get_irc_client_version() esac done B_CONSOLE_IRC='true' - set_perl_python_konvi "$App_Working_Name" + set_perl_python_client_data "$App_Working_Name" ;; python*) # B_CONSOLE_IRC='true' # are there even any python type console irc clients? check. - set_perl_python_konvi "$App_Working_Name" + set_perl_python_client_data "$App_Working_Name" ;; # then unset, set unknown data *) @@ -3165,27 +3666,50 @@ get_irc_client_version() } # args: $1 - App_Working_Name -set_perl_python_konvi() +set_perl_python_client_data() { if [[ -z $IRC_CLIENT_VERSION ]];then + local version='' # this is a hack to try to show konversation if inxi is running but started via /cmd - if [[ -n $( grep -i 'konversation' <<< "$Ps_aux_Data" | grep -v 'grep' ) && $B_RUNNING_IN_DISPLAY == 'true' ]];then + # OR via script shortcuts, both cases in fact now + if [[ $B_RUNNING_IN_DISPLAY == 'true' && -z ${Ps_aux_Data/*konversation*/} ]];then IRC_CLIENT='Konversation' - IRC_CLIENT_VERSION=" $( konversation --version 2>/dev/null | gawk '/^Konversation/ {print $2}' )" + version=$( get_program_version 'konversation' '^konversation' '2' ) B_CONSOLE_IRC='false' + ## NOTE: supybot only appears in ps aux using 'SHELL' command; the 'CALL' command + ## gives the user system irc priority, and you don't see supybot listed, so use SHELL + elif [[ $B_RUNNING_IN_DISPLAY == 'false' && -z ${Ps_aux_Data/*supybot*/} ]];then + version=$( get_program_version 'supybot' '^Supybot' '2' ) + if [[ -n $version ]];then + IRC_CLIENT_VERSION=" $version" + if [[ -z ${version/*gribble*/} ]];then + IRC_CLIENT='Gribble' + elif [[ -z ${version/*limnoria*/} ]];then + IRC_CLIENT='Limnoria' + else + IRC_CLIENT='Supybot' + fi + else + IRC_CLIENT='Supybot' + # currently all use the same actual app name, this will probably change. + fi + B_CONSOLE_IRC='true' else IRC_CLIENT="Unknown $1 client" fi + if [[ -n $version ]];then + IRC_CLIENT_VERSION=" $version" + fi fi } ## try to infer the use of Konversation >= 1.2, which shows $PPID improperly ## no known method of finding Kovni >= 1.2 as parent process, so we look to see if it is running, -## and all other irc clients are not running. +## and all other irc clients are not running. As of 2014-03-25 this isn't used in my cases is_this_qt4_konvi() { local konvi_qt4_client='' konvi_dbus_exist='' konvi_pid='' konvi_home_dir='' - local konvi='' konvi_qt4_ver='' b_is_qt4='' + local konvi='' b_is_qt4='' # fringe cases can throw error, always if untested app, use 2>/dev/null after testing if present if [[ $B_QDBUS == 'true' ]];then @@ -3198,11 +3722,10 @@ is_this_qt4_konvi() konvi=$( echo $konvi_home_dir | sed "s/\// /g" ) konvi=($konvi) - if [[ ${konvi[2]} == 'konversation' ]];then - konvi_qt4_ver=$( konversation -v | grep -i 'konversation' ) + if [[ ${konvi[2]} == 'konversation' ]];then # note: we need to change this back to a single dot number, like 1.3, not 1.3.2 - konvi_qt4_client=$( echo "$konvi_qt4_ver" | gawk '{ print $2 }' | cut -d '.' -f 1,2 ) - + konvi_qt4_client=$( konversation -v | grep -i 'konversation' | \ + gawk '{ print $2 }' | cut -d '.' -f 1,2 ) if [[ $konvi_qt4_client > 1.1 ]]; then b_is_qt4='true' fi @@ -3256,7 +3779,7 @@ get_cmdline() get_audio_data() { eval $LOGFS - local i='' alsa_data='' audio_driver='' device_count='' temp_array='' + local i='' alsa_data='' audio_driver='' device_count='' a_temp='' IFS=$'\n' # this first step handles the drivers for cases where the second step fails to find one @@ -3291,7 +3814,7 @@ get_audio_data() audioCard=gensub(/^[0-9a-f:\.]+ [^:]+: (.+)$/,"\\1","g",$0) # The doublequotes are necessary because of the pipes in the variable. gsub(/'"$BAN_LIST_NORMAL"'/, "", audioCard) - gsub(/,/, " ", audioCard) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", audioCard) gsub(/^ +| +$/, "", audioCard) gsub(/ [ \t]+/, " ", audioCard) aPciBusId[audioCard] = gensub(/(^[0-9a-f:\.]+) [^:]+: .+$/,"\\1","g",$0) @@ -3299,15 +3822,15 @@ get_audio_data() # loop until you get to the end of the data block while (getline && !/^$/) { - gsub( /,/, "", $0 ) + gsub(/'"$BAN_LIST_ARRAY"'/, "", $0 ) if (/driver in use/) { drivers[audioCard] = drivers[audioCard] gensub( /(.*): (.*)/ ,"\\2", "g" ,$0 ) "" } else if (/kernel modules:/) { modules[audioCard] = modules[audioCard] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) "" } - else if (/I\/O/) { - portsTemp = gensub(/\t*I\/O ports at (.*) \[.*\]/,"\\1","g",$0) + else if (/^[[:space:]]*I\/O/) { + portsTemp = gensub(/\t*I\/O ports at ([a-z0-9]+)(| \[.*\])/,"\\1","g",$0) ports[audioCard] = ports[audioCard] portsTemp " " } } @@ -3374,8 +3897,8 @@ get_audio_data() if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]];then A_AUDIO_DATA[0]='Failed to Detect Sound Card!' fi - temp_array=${A_AUDIO_DATA[@]} - log_function_data "A_AUDIO_DATA: $temp_array" + a_temp=${A_AUDIO_DATA[@]} + log_function_data "A_AUDIO_DATA: $a_temp" eval $LOGFE } @@ -3384,16 +3907,15 @@ get_audio_data() get_audio_usb_data() { eval $LOGFS - local usb_proc_file='' array_count='' usb_data='' usb_id='' lsusb_path='' lsusb_data='' - local temp_array='' + local usb_proc_file='' array_count='' usb_data='' usb_id='' lsusb_data='' + local a_temp='' IFS=$'\n' - lsusb_path=$( type -p lsusb ) - if [[ -n $lsusb_path ]];then - lsusb_data=$( $lsusb_path 2>/dev/null ) + if type -p lsusb &>/dev/null;then + lsusb_data=$( lsusb 2>/dev/null ) fi log_function_data 'raw' "usb_data:\n$lsusb_data" - if [[ -n $lsusb_data ]];then + if [[ -n $lsusb_data && -d /proc/asound/ ]];then # for every sound card symlink in /proc/asound - display information about it for usb_proc_file in /proc/asound/* do @@ -3411,7 +3933,7 @@ get_audio_usb_data() separator="" } { - gsub( /,/, " ", $0 ) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $0 ) gsub(/'"$BAN_LIST_NORMAL"'/, "", $0) gsub(/ [ \t]+/, " ", $0) for ( i=7; i<= NF; i++ ) { @@ -3435,8 +3957,8 @@ get_audio_usb_data() done fi IFS="$ORIGINAL_IFS" - temp_array=${A_AUDIO_DATA[@]} - log_function_data "A_AUDIO_DATA: $temp_array" + a_temp=${A_AUDIO_DATA[@]} + log_function_data "A_AUDIO_DATA: $a_temp" eval $LOGFE } @@ -3444,7 +3966,7 @@ get_audio_usb_data() get_audio_alsa_data() { eval $LOGFS - local alsa_data='' temp_array='' + local alsa_data='' a_temp='' # now we'll get the alsa data if the file exists if [[ $B_ASOUND_VERSION_FILE == 'true' ]];then @@ -3459,8 +3981,8 @@ get_audio_alsa_data() # some alsa strings have the build date in (...) # remove trailing . and remove possible second line if compiled by user $0 !~ /compile/ { - gsub( /Driver | [(].*[)]|\.$/,"",$0 ) - gsub(/,/, " ", $0) + gsub(/Driver | [(].*[)]|\.$/,"",$0 ) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $0) gsub(/^ +| +$/, "", $0) gsub(/ [ \t]+/, " ", $0) sub(/Advanced Linux Sound Architecture/, "ALSA", $0) @@ -3473,55 +3995,315 @@ get_audio_alsa_data() IFS="$ORIGINAL_IFS" log_function_data 'cat' "$FILE_ASOUND_VERSION" fi - temp_array=${A_ALSA_DATA[@]} - log_function_data "A_ALSA_DATA: $temp_array" + a_temp=${A_ALSA_DATA[@]} + log_function_data "A_ALSA_DATA: $a_temp" eval $LOGFE } -## create A_CPU_CORE_DATA, currently with two values: integer core count; core string text -## return value cpu core count string, this helps resolve the multi redundant lines of old style output -get_cpu_core_count() +get_battery_data() { eval $LOGFS - local cpu_physical_count='' cpu_core_count='' cpu_type='' cpu_alpha_count='' - if [[ $B_CPUINFO_FILE == 'true' ]]; then - # load the A_CPU_TYPE_PCNT_CCNT core data array - get_cpu_ht_multicore_smp_data - ## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10) - # count the number of processors given - cpu_physical_count=${A_CPU_TYPE_PCNT_CCNT[1]} - cpu_core_count=${A_CPU_TYPE_PCNT_CCNT[2]} - cpu_type=${A_CPU_TYPE_PCNT_CCNT[0]} - - # match the numberic value to an alpha value - cpu_alpha_count=$( get_cpu_core_count_alpha "$cpu_core_count" ) - - # create array, core count integer; core count string + local a_temp='' id_file='' count=0 + local id_dir='/sys/class/power_supply/' + local ids=$( ls $id_dir 2>/dev/null ) battery_file='' + + # ids='BAT0 BAT1 BAT2' + if [[ -n $ids && $B_FORCE_DMIDECODE == 'false' ]];then + for idx in $ids + do + battery_file=$id_dir$idx'/uevent' + if [[ -r $battery_file ]];then + # echo $battery_file + count=$(( $count + 1 )) + IFS=$'\n' + battery_data=$( + gawk -F '=' ' + BEGIN { + IGNORECASE=1 + name="" + status="" + present="" + chemistry="" + cycles="" + voltage_min_design="" + voltage_now="" + power_now="" + charge_full_design="" + charge_full="" + charge_now="" + capacity="" + capacity_level="" + model="" + company="" + serial="" + of_orig="" + location="" + } + { + gsub(/'"$BAN_LIST_NORMAL"'|,|battery|unknown/, "", $2) + gsub(/^ +| +$/, "", $2) + } + $1 ~ /^POWER_SUPPLY_NAME$/ { + name=$NF + } + $1 ~ /^POWER_SUPPLY_STATUS$/ { + status=$NF + } + $1 ~ /^POWER_SUPPLY$/ { + present=$NF + } + $1 ~ /^POWER_SUPPLY_TECHNOLOGY$/ { + chemistry=$NF + } + $1 ~ /^POWER_SUPPLY_CYCLE_COUNT$/ { + cycles=$NF + } + $1 ~ /^POWER_SUPPLY_VOLTAGE_MIN_DESIGN$/ { + voltage_min_design = $NF / 1000000 + voltage_min_design = sprintf( "%.1f", voltage_min_design ) + } + $1 ~ /^POWER_SUPPLY_VOLTAGE_NOW$/ { + voltage_now = $NF / 1000000 + voltage_now = sprintf( "%.1f", voltage_now ) + } + $1 ~ /^POWER_SUPPLY_POWER_NOW$/ { + power_now=$NF + } + $1 ~ /^POWER_SUPPLY_ENERGY_FULL_DESIGN$/ { + charge_full_design = $NF / 1000000 + } + $1 ~ /^POWER_SUPPLY_ENERGY_FULL$/ { + charge_full = $NF / 1000000 + } + $1 ~ /^POWER_SUPPLY_ENERGY_NOW$/ { + charge_now = $NF / 1000000 + charge_now = sprintf( "%.1f", charge_now ) + } + $1 ~ /^POWER_SUPPLY_CHARGE_FULL_DESIGN$/ { + charge_full_design = $NF / 100000 + } + $1 ~ /^POWER_SUPPLY_CHARGE_FULL$/ { + charge_full = $NF / 100000 + } + $1 ~ /^POWER_SUPPLY_CHARGE_NOW$/ { + charge_now = $NF / 100000 + } + $1 ~ /^POWER_SUPPLY_CAPACITY$/ { + if ( $NF != "" ){ + capacity=$NF "%" + } + } + $1 ~ /^POWER_SUPPLY_CAPACITY_LEVEL$/ { + capacity_level=$NF + } + $1 ~ /^POWER_SUPPLY_MODEL_NAME$/ { + model=$NF + } + $1 ~ /^POWER_SUPPLY_MANUFACTURER$/ { + company=$NF + } + $1 ~ /^POWER_SUPPLY_SERIAL_NUMBER$/ { + serial=$NF + } + END { + if (charge_now != "" && charge_full != "" ){ + capacity = 100*charge_now/charge_full + capacity = sprintf( "%.1f%", capacity ) + } + if (charge_full_design != "" && charge_full != "" ){ + of_orig=100*charge_full/charge_full_design + of_orig = sprintf( "%.0f%", of_orig ) + } + if (charge_now != "" ){ + charge_now = sprintf( "%.1f", charge_now ) + } + if (charge_full_design != "" ){ + charge_full_design = sprintf( "%.1f", charge_full_design ) + } + if ( charge_full != "" ){ + charge_full = sprintf( "%.1f", charge_full ) + } + entry = name "," status "," present "," chemistry "," cycles "," voltage_min_design "," voltage_now "," + entry = entry power_now "," charge_full_design "," charge_full "," charge_now "," capacity "," + entry = entry capacity_level "," of_orig "," model "," company "," serial "," location + print entry + }' < $battery_file ) + # <<< "$data" ) + # < $battery_file ) + A_BATTERY_DATA[$count]=$battery_data + IFS="$ORIGINAL_IFS" + fi + done + elif [[ $B_FORCE_DMIDECODE == 'true' ]] || [[ ! -d $id_dir && -z $ids ]];then + get_dmidecode_data + if [[ -n $DMIDECODE_DATA ]];then + if [[ $DMIDECODE_DATA == 'dmidecode-error-'* ]];then + A_BATTERY_DATA[0]=$DMIDECODE_DATA + # please note: only dmidecode version 2.11 or newer supports consistently the -s flag + else + IFS=$'\n' + # NOTE: this logic has a flaw, which is multiple batteries, which won't work without + # gawk arrays, but sorry, too much of a pain given how little useful data from dmidecode + A_BATTERY_DATA=( $( gawk -F ':' ' + BEGIN { + IGNORECASE=1 + name="" + status="" + present="" + chemistry="" + cycles="" + voltage_min_design="" + voltage_now="" + power_now="" + charge_full_design="" + charge_full="" + charge_now="" + capacity="" + capacity_level="" + model="" + company="" + serial="" + of_orig="" + location="" + bItemFound="false" + } + { + gsub(/'"$BAN_LIST_NORMAL"'|,|battery|unknown/, "", $2) + gsub(/^ +| +$/, "", $1) + gsub(/^ +| +$/, "", $2) + } + /^Portable Battery/ { + while ( getline && !/^$/ ) { + if ( $1 ~ /^Location/ ) { location=$2 } + if ( $1 ~ /^Manufacturer/ ) { company=$2 } + if ( $1 ~ /^Serial/ ) { serial=$2 } + if ( $1 ~ /^Name/ ) { model=$2 } + if ( $1 ~ /^Design Capacity/ ) { + sub(/^[[:space:]]*mwh/, "", $2) + charge_full_design = $NF / 1000 + charge_full_design = sprintf( "%.1f", charge_full_design ) + } + if ( $1 ~ /^Design Voltage/ ) { + sub(/^[[:space:]]*mv/, "", $2) + voltage_min_design = $NF / 1000 + voltage_min_design = sprintf( "%.1f", voltage_min_design ) + } + if ( $1 ~ /^SBDS Chemistry/ ) { chemistry=$2 } + } + testString=company serial model charge_full_design voltage_min_design + if ( testString != "" ) { + bItemFound="true" + exit # exit loop, we are not handling > 1 batteries + } + } + END { + if ( bItemFound == "true" ) { + name="BAT-1" + if (charge_now != "" && charge_full != "" ){ + capacity = 100*charge_now/charge_full + capacity = sprintf( "%.1f%", capacity ) + } + if (charge_full_design != "" && charge_full != "" ){ + of_orig=100*charge_full/charge_full_design + of_orig = sprintf( "%.0f%", of_orig ) + } + entry = name "," status "," present "," chemistry "," cycles "," voltage_min_design "," voltage_now "," + entry = entry power_now "," charge_full_design "," charge_full "," charge_now "," capacity "," + entry = entry capacity_level "," of_orig "," model "," company "," serial "," location + print entry + } + }' <<< "$DMIDECODE_DATA" ) ) + IFS="$ORIGINAL_IFS" + fi + fi + fi + # echo $array_string + + #echo ${#A_BATTERY_DATA[@]} + a_temp=${A_BATTERY_DATA[@]} + + # echo $a_temp + log_function_data "A_BATTERY_DATA: $a_temp" + eval $LOGFE +} + +## create A_CPU_CORE_DATA, currently with two values: integer core count; core string text +## return value cpu core count string, this helps resolve the multi redundant lines of old style output +get_cpu_core_count() +{ + eval $LOGFS + local cpu_physical_count='' cpu_core_count='' cpu_type='' cpu_alpha_count='' cores_per_cpu='' + local array_data='' + + if [[ $B_CPUINFO_FILE == 'true' ]]; then + # load the A_CPU_TYPE_PCNT_CCNT core data array + get_cpu_ht_multicore_smp_data + ## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10) + # count the number of processors given + cpu_physical_count=${A_CPU_TYPE_PCNT_CCNT[1]} + cpu_core_count=${A_CPU_TYPE_PCNT_CCNT[2]} + cpu_type=${A_CPU_TYPE_PCNT_CCNT[0]} + + # match the numberic value to an alpha value + cpu_alpha_count=$( get_cpu_core_count_alpha "$cpu_core_count" ) + + # create array, core count integer; core count string # A_CPU_CORE_DATA=( "$cpu_core_count" "$cpu_alpha_count Core$cpu_type" ) - A_CPU_CORE_DATA=( "$cpu_physical_count" "$cpu_alpha_count" "$cpu_type" "$cpu_core_count" ) + array_data="$cpu_physical_count,$cpu_alpha_count,$cpu_type,$cpu_core_count" + IFS=',' + A_CPU_CORE_DATA=( $array_data ) + IFS="$ORIGINAL_IFS" elif [[ -n $BSD_TYPE ]];then local gawk_fs=': ' if [[ $BSD_VERSION == 'openbsd' ]];then gawk_fs='=' fi - cpu_core_count=$( gawk -F "$gawk_fs" ' + cpu_core_count=$( gawk -F "$gawk_fs" -v bsdVersion="$BSD_VERSION" ' # note: on openbsd can also be hw.ncpufound so exit after first - /^hw.ncpu/ { + BEGIN { + coreCount="" + } + $1 ~ /^hw.ncpu$/ { + coreCount=$NF + } + /^machdep.cpu.core_count/ { + coreCount=$NF + } + END { + print coreCount + }' <<< "$Sysctl_a_Data" ) + cores_per_cpu=$( gawk -F "$gawk_fs" ' + /^machdep.cpu.cores_per_package/ { print $NF - exit }' <<< "$Sysctl_a_Data" ) + if [[ -n $( grep -E '^[0-9]+$' <<< "$cpu_core_count" ) ]];then cpu_alpha_count=$( get_cpu_core_count_alpha "$cpu_core_count" ) if [[ $cpu_core_count -gt 1 ]];then - cpu_type='SMP' + cpu_type='-SMP-' + else + cpu_type='-UP-' fi fi - cpu_physical_count=1 - A_CPU_CORE_DATA=( "$cpu_physical_count" "$cpu_alpha_count" "$cpu_type" "$cpu_core_count" ) + if [[ -n $cores_per_cpu ]];then + cpu_physical_count=$(( $cpu_core_count / $cores_per_cpu )) + if [[ $cores_per_cpu -gt 1 ]];then + cpu_type='-MCP-' + fi + # do not guess here, only use phys count if it actually exists, otherwise handle in print_cpu.. + # this 1 value should not be used for output, and is just to avoid math errors + else + cpu_physical_count=1 + fi + array_data="$cpu_physical_count,$cpu_alpha_count,$cpu_type,$cpu_core_count" + IFS=',' + A_CPU_CORE_DATA=( $array_data ) + IFS="$ORIGINAL_IFS" fi - temp_array=${A_CPU_CORE_DATA[@]} - log_function_data "A_CPU_CORE_DATA: $temp_array" + a_temp=${A_CPU_CORE_DATA[@]} + # echo $a_temp :: ${#A_CPU_CORE_DATA[@]} + log_function_data "A_CPU_CORE_DATA: $a_temp" eval $LOGFE } @@ -3554,27 +4336,39 @@ get_cpu_core_count_alpha() get_cpu_data() { eval $LOGFS - local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits='' temp_array='' - local bsd_cpu_flags='' + local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits='' a_temp='' + local bsd_cpu_flags='' min_speed='' max_speed='' + + if [[ -f /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq ]];then + max_speed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq) + if [[ -f /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq ]];then + min_speed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq) + fi + fi if [[ $B_CPUINFO_FILE == 'true' ]];then # stop script for a bit to let cpu slow down before parsing cpu /proc file sleep $CPU_SLEEP IFS=$'\n' A_CPU_DATA=( $( - gawk -F': ' ' + gawk -v cpuMin="$min_speed" -v cpuMax="$max_speed" -F': ' ' BEGIN { IGNORECASE=1 # need to prime nr for arm cpus, which do not have processor number output in some cases nr = 0 count = 0 bArm = "false" + # ARM cpus are erratic in /proc/cpuinfo this hack can sometimes resolve it. Linux only. + sysSpeed="'$(get_cpu_speed_hack)'" + speed = 0 + max = 0 + min = 0 } # TAKE STRONGER NOTE: \t+ does NOT always work, MUST be [ \t]+ # TAKE NOTE: \t+ will work for $FILE_CPUINFO, but SOME ARBITRARY FILE used for TESTING might contain SPACES! # Therefore PATCH to use [ \t]+ when TESTING! /^processor[ \t]+:/ { - gsub(/,/, " ", $NF) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $NF) gsub(/^ +| +$/, "", $NF) if ( $NF ~ "^[0-9]+$" ) { nr = $NF @@ -3588,11 +4382,10 @@ get_cpu_data() cpu[nr, "model"] = $NF } } - /^model name|^cpu\t+:/ { gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF ) gsub(/'"$BAN_LIST_CPU"'/, "", $NF ) - gsub(/,/, " ", $NF) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $NF) gsub(/^ +| +$/, "", $NF) gsub(/ [ \t]+/, " ", $NF) cpu[nr, "model"] = $NF @@ -3600,17 +4393,15 @@ get_cpu_data() bArm = "true" } } - /^cpu MHz|^clock\t+:/ { - if (!min) { - min = $NF + if (speed == 0) { + speed = $NF } else { - if ($NF < min) { - min = $NF + if ($NF < speed) { + speed = $NF } } - if ($NF > max) { max = $NF } @@ -3618,11 +4409,9 @@ get_cpu_data() gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros cpu[nr, "speed"] = $NF } - /^cache size/ { cpu[nr, "cache"] = $NF } - /^flags|^features/ { cpu[nr, "flags"] = $NF # not all ARM cpus show ARM in model name @@ -3630,101 +4419,202 @@ get_cpu_data() bArm = "true" } } - /^bogomips/ { cpu[nr, "bogomips"] = $NF } - /vendor_id/ { gsub(/genuine|authentic/,"",$NF) cpu[nr, "vendor"] = tolower( $NF ) } - END { #if (!nr) { print ",,,"; exit } # <- should this be necessary or should bash handle that for ( i = 0; i <= nr; i++ ) { # note: assuming bogomips for arm at 1 x clock # http://en.wikipedia.org/wiki/BogoMips ARM could change so watch this # maybe add: && bArm == "true" but I think most of the bogomips roughly equal cpu speed if not amd/intel - if ( cpu[i, "bogomips"] != "" && cpu[i, "speed"] == "" ) { + # 2014-04-08: trying to use sysSpeed hack first, that is more accurate anyway. + if ( ( cpu[i, "speed"] == "" && sysSpeed != "" ) || \ + ( cpu[i, "speed"] == "" && cpu[i, "bogomips"] != "" && cpu[i, "bogomips"] < 50 ) ) { + cpu[i, "speed"] = sysSpeed + } + else if ( cpu[i, "bogomips"] != "" && cpu[i, "speed"] == "" ) { cpu[i, "speed"] = cpu[i, "bogomips"] } print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] "," cpu[nr, "vendor"] "," bArm } - # this is / was used in inxi short output only, but when it is N/A, need to use the previous array - # value, from above, the actual speed that is, for short output, key 0. - if (!min) { - print "N/A" - exit + if (cpuMin != "") { + min=cpuMin/1000 + } + if (cpuMax != "") { + max=cpuMax/1000 + } + # create last array index, to be used for min/max output + sub(/\.[0-9]+$/,"",max) + sub(/\.[0-9]+$/,"",speed) + sub(/\.[0-9]+$/,"",min) + if (speed == 0) { + print "N/A," min "," max } else { - if (min != max) { - printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz") - } - else { - printf("%s %s\n", max, "Mhz") - } + print speed "," min "," max } - } - ' $FILE_CPUINFO ) ) + } + ' $FILE_CPUINFO ) ) + IFS="$ORIGINAL_IFS" log_function_data 'cat' "$FILE_CPUINFO" elif [[ -n $BSD_TYPE ]];then get_cpu_data_bsd fi - temp_array=${A_CPU_DATA[@]} - log_function_data "A_CPU_DATA: $temp_array" -# echo ta: ${temp_array[@]} + a_temp=${A_CPU_DATA[@]} + log_function_data "A_CPU_DATA: $a_temp" +# echo ta: ${a_temp[@]} eval $LOGFE # echo getMainCpu: ${[@]} } +# this triggers in one and only one case, ARM cpus that have fake bogomips data +get_cpu_speed_hack() +{ + local speed=$( cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 2>/dev/null ) + + if [[ -n $speed ]];then + speed=${speed%[0-9][0-9][0-9]} # trim off last 3 digits + fi + echo $speed +} get_cpu_data_bsd() { eval $LOGFS local bsd_cpu_flags=$( get_cpu_flags_bsd ) - local gawk_fs=': ' + local gawk_fs=': ' cpu_max='' if [[ $BSD_VERSION == 'openbsd' ]];then gawk_fs='=' fi - - IFS=$'\n' - A_CPU_DATA=( $( - gawk -F "$gawk_fs" -v cpuFlags="$bsd_cpu_flags" ' - BEGIN { - IGNORECASE=1 - cpuModel="" - cpuClock="" - cpuCache="" - cpuBogomips="" - cpuVendor="" - } - /^hw.model/ { - gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF ) - gsub(/'"$BAN_LIST_CPU"'/, "", $NF ) - sub(//,"",$NF) - sub(/[a-z]+-core/, "", $NF ) - gsub(/^ +| +$|\"/, "", $NF) - gsub(/ [ \t]+/, " ", $NF) - cpuModel=$NF - if ( cpuClock != "" ) { - exit + # avoid setting this for systems where you have no read/execute permissions + # might be cases where the dmesg boot file was readable but sysctl perms failed + if [[ -n $Sysctl_a_Data || -n $bsd_cpu_flags ]];then + if [[ -n $Dmesg_Boot_Data ]];then + cpu_max=$( gawk -F ':' ' + BEGIN { + IGNORECASE=1 + } + # NOTE: freebsd may say: 2300-MHz, so check for dash as well + $1 ~ /^(CPU|cpu0)$/ { + if ( $NF ~ /[^0-9\.][0-9\.]+[\-[:space:]]*[MG]Hz/) { + max=gensub(/.*[^0-9\.]([0-9\.]+[\-[:space:]]*[MG]Hz).*/,"\\1",1,$NF) + if (max ~ /MHz/) { + sub(/[-[:space:]]*MHz/,"",max) + } + if (max ~ /GHz/) { + sub(/[-[:space:]]*GHz/,"",max) + max=max*1000 + } + print max + exit + } + }' <<< "$Dmesg_Boot_Data" ) + fi + IFS=$'\n' + A_CPU_DATA=( $( + gawk -F "$gawk_fs" -v bsdVersion=$BSD_VERSION -v cpuFlags="$bsd_cpu_flags" -v cpuMax="$cpu_max" ' + BEGIN { + IGNORECASE=1 + cpuModel="" + cpuClock="" + cpuCache="" + cpuBogomips="" + cpuVendor="" + bSwitchFs="false" + min=0 + max=0 } - } - /^hw.(clock|cpuspeed)/ { - cpuClock=$NF - if ( cpuModel != "" ) { - exit + /^hw.model/ && ( bsdVersion != "darwin" ) { + gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF ) + gsub(/'"$BAN_LIST_CPU"'/, "", $NF ) + gsub(/'"$BAN_LIST_ARRAY"'/," ",$NF) + sub(/[a-z]+-core/, "", $NF ) + gsub(/^ +| +$|\"/, "", $NF) + gsub(/ [ \t]+/, " ", $NF) + # cut L2 cache/cpu max speed out of model string, if available + if ( $NF ~ /[0-9]+[[:space:]]*[KM]B[[:space:]]+L2 cache/) { + cpuCache=gensub(/.*[^0-9]([0-9]+[[:space:]]*[KM]B)[[:space:]]+L2 cach.*/,"\\1",1,$NF) + } + if ( $NF ~ /[^0-9\.][0-9\.]+[\-[:space:]]*[MG]Hz/) { + max=gensub(/.*[^0-9\.]([0-9\.]+[\-[:space:]]*[MG]Hz).*/,"\\1",1,$NF) + if (max ~ /MHz/) { + sub(/[\-[:space:]]*MHz/,"",max) + } + if (max ~ /GHz/) { + sub(/[\-[:space:]]*GHz/,"",max) + max=max*1000 + } + } + if ( $NF ~ /\)$/ ){ + sub(/[[:space:]]*\(.*\)$/,"",$NF) + } + cpuModel=$NF +# if ( cpuClock != "" ) { +# exit +# } } - } - END { - print cpuModel "," cpuClock "," cpuCache "," cpuFlags "," cpuBogomips "," cpuVendor - print "N/A" - }' <<< "$Sysctl_a_Data" ) ) - IFS="$ORIGINAL_IFS" + /^hw.clock/ { + cpuClock=$NF +# if ( cpuModel != "" ) { +# exit +# } + } + /^hw.cpufrequency/ { + cpuClock = $NF / 1000000 + } + /^hw.cpuspeed/ { + cpuClock=$NF + } + /^hw.l2cachesize/ { + cpuCache=$NF/1024 + cpuCache=cpuCache " kB" + } + /^machdep.cpu.vendor/ { + cpuVendor=$NF + } + # Freebsd does some voltage hacking to actually run at lowest listed frequencies. + # The cpu does not actually support all the speeds output here but works in freebsd. + /^dev.cpu.0.freq_levels/ { + gsub(/^[[:space:]]+|\/[0-9]+|[[:space:]]+$/,"",$NF) + if ( $NF ~ /[0-9]+[[:space:]]+[0-9]+/ ) { + min=gensub(/.*[[:space:]]([0-9]+)$/,"\\1",1,$NF) + max=gensub(/^([0-9]+)[[:space:]].*/,"\\1",1,$NF) + } + } + /^machdep.cpu.brand_string/ { + gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF ) + gsub(/'"$BAN_LIST_CPU"'/, "", $NF ) + gsub(/'"$BAN_LIST_ARRAY"'/," ",$NF) + sub(/[a-z]+-core/, "", $NF ) + gsub(/^ +| +$|\"/, "", $NF) + gsub(/ [ \t]+/, " ", $NF) + sub(/[[:space:]]*@.*/,"",$NF) + cpuModel=$NF + } + END { + if ( max == 0 && cpuMax != "" ) { + max=cpuMax + } + if ( cpuClock == "" ) { + cpuClock="N/A" + } + sub(/\.[0-9]+/,"",cpuClock) + sub(/\.[0-9]+/,"",min) + sub(/\.[0-9]+/,"",max) + print cpuModel "," cpuClock "," cpuCache "," cpuFlags "," cpuBogomips "," cpuVendor + # triggers print case + print cpuClock "," min "," max + }' <<< "$Sysctl_a_Data" ) ) + IFS="$ORIGINAL_IFS" + fi eval $LOGFE } @@ -3733,27 +4623,44 @@ get_cpu_flags_bsd() { eval $LOGFS - local cpu_flags=$( gawk -F '=' ' - BEGIN { - IGNORECASE=1 - cpuFlags="" - } - /^CPU:/ { - while ( getline && !/memory/ ) { - if ( $1 ~ /Features/ ) { - # clean up odd stuff like - gsub(/<[a-z0-9]+>/,"", $2) - # all the flags are contained within < ... > on freebsd at least - gsub(/.*<|>.*/,"", $2) - gsub(/,/," ", $2) - cpuFlags = cpuFlags " " $2 - } - } - cpuFlags=tolower(cpuFlags) - print cpuFlags - exit - }' <<< "$Dmesg_Boot_Data" ) + local cpu_flags='' + local gawk_fs=':' + if [[ -n $Dmesg_Boot_Data ]];then + cpu_flags=$( gawk -v bsdVersion="$BSD_VERSION" -F ":" ' + BEGIN { + IGNORECASE=1 + cpuFlags="" + } + /^(CPU:|cpu0:)/ { + while ( getline && !/memory|real mem/ ) { + if ( $1 ~ /Features/ || ( bsdVersion == "openbsd" && $0 ~ /^cpu0.*[[:space:]][a-z][a-z][a-z][[:space:]][a-z][a-z][a-z][[:space:]]/ ) ) { + # clean up odd stuff like + gsub(/<[a-z0-9]+>/,"", $2) + # all the flags are contained within < ... > on freebsd at least + gsub(/.*<|>.*/,"", $2) + gsub(/'"$BAN_LIST_ARRAY"'/," ", $2) + cpuFlags = cpuFlags " " $2 + } + } + cpuFlags=tolower(cpuFlags) + print cpuFlags + exit + }' <<< "$Dmesg_Boot_Data" ) + elif [[ -n $Sysctl_a_Data ]];then + if [[ $BSD_VERSION == 'openbsd' ]];then + gawk_fs=':' + fi + cpu_flags=$( gawk -F "$gawk_fs" ' + BEGIN { + cpuFlags="" + } + /^machdep.cpu.features/ { + cpuFlags=tolower($NF) + print cpuFlags + exit + }' <<< "$Sysctl_a_Data" ) + fi echo $cpu_flags log_function_data "$cpu_flags" eval $LOGFE @@ -3764,7 +4671,7 @@ get_cpu_ht_multicore_smp_data() { eval $LOGFS # in /proc/cpuinfo - local temp_array='' + local a_temp='' # note: known bug with xeon intel, they show a_core_id/physical_id as 0 for ht 4 core if [[ $B_CPUINFO_FILE == 'true' ]]; then @@ -3807,9 +4714,8 @@ get_cpu_ht_multicore_smp_data() } } # array of logical processors, both HT and physical - /^processor/ { - gsub(/,/, " ", $NF) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $NF) gsub(/^ +| +$/, "", $NF) if ( $NF ~ "^[0-9]+$" ) { a_processor_id[proc_iter] = $NF @@ -3827,7 +4733,6 @@ get_cpu_ht_multicore_smp_data() a_processor_id[proc_iter] = nr } } - # array of physical cpu ids, note, this will be unset for vm cpus in many cases # because they have no physical cpu, so we cannot assume this will be here. /^physical/ { @@ -3862,7 +4767,6 @@ get_cpu_ht_multicore_smp_data() for ( i in a_physical_id ) { num_of_physical_cpus++ } - i = 0 ## count unique cores ## for ( i in a_core_id ) { @@ -3922,8 +4826,8 @@ get_cpu_ht_multicore_smp_data() } ' $FILE_CPUINFO ) ) fi - temp_array=${A_CPU_TYPE_PCNT_CCNT[@]} - log_function_data "A_CPU_TYPE_PCNT_CCNT: $temp_array" + a_temp=${A_CPU_TYPE_PCNT_CCNT[@]} + log_function_data "A_CPU_TYPE_PCNT_CCNT: $a_temp" eval $LOGFE } @@ -3936,31 +4840,52 @@ get_desktop_environment() eval $LOGFS # set the default, this function only runs in X, if null, don't print data out - local desktop_environment='' xprop_root='' - local version='' version_data='' toolkit='' + local desktop_environment='' xprop_root='' version2='' + local version='' version_data='' version2_data='' toolkit='' # works on 4, assume 5 will id the same, why not, no need to update in future # KDE_SESSION_VERSION is the integer version of the desktop + # NOTE: as of plasma 5, the tool: about-distro MAY be available, that will show + # actual desktop data, so once that's in debian/ubuntu, if it gets in, add that test if [[ $XDG_CURRENT_DESKTOP == 'KDE' || -n $KDE_SESSION_VERSION ]]; then # note the command is actually like, kded4 --version, so we construct it - version_data=$( kded$KDE_SESSION_VERSION --version 2>/dev/null ) - version=$( grep -si '^KDE Development Platform:' <<< "$version_data" | gawk '{print $4}' ) + # this was supposed to extend to 5, but 5 changed it, so it uses the more reliable way + if [[ $KDE_SESSION_VERSION -le 4 ]];then + version_data=$( kded$KDE_SESSION_VERSION --version 2>/dev/null ) + version=$( grep -si '^KDE Development Platform:' <<< "$version_data" | gawk '{print $4}' ) + else + # NOTE: this command string is almost certain to change, and break, with next major plasma desktop, ie, 6 + # version=$( qdbus org.kde.plasmashell /MainApplication org.qtproject.Qt.QCoreApplication.applicationVersion 2>/dev/null ) + #Qt: 5.4.2 + #KDE Frameworks: 5.11.0 + #kf5-config: 1.0 + # for QT, and Frameworks if we use it + if type -p kf$KDE_SESSION_VERSION-config &>/dev/null;then + version_data=$( kf$KDE_SESSION_VERSION-config --version 2>/dev/null ) + # version=$( grep -si '^KDE Frameworks:' <<< "$version_data" | gawk '{print $NF}' ) + fi + # plasmashell 5.3.90 + if type -p plasmashell &>/dev/null;then + version2_data=$( plasmashell --version 2>/dev/null ) + version=$( grep -si '^plasmashell' <<< "$version2_data" | gawk '{print $NF}' ) + fi + fi if [[ -z $version ]];then version=$KDE_SESSION_VERSION fi - if [[ $B_EXTRA_DATA == 'true' ]];then + if [[ $B_EXTRA_DATA == 'true' && -n $version_data ]];then toolkit=$( grep -si '^Qt:' <<< "$version_data" | gawk '{print $2}' ) if [[ -n $toolkit ]];then version="$version (Qt $toolkit)" fi fi - desktop_environment="KDE" + desktop_environment="KDE Plasma" # KDE_FULL_SESSION property is only available since KDE 3.5.5. # src: http://humanreadable.nfshost.com/files/startkde elif [[ $KDE_FULL_SESSION == 'true' ]]; then version_data=$( kded --version 2>/dev/null ) version=$( grep -si '^KDE:' <<< "$version_data" | gawk '{print $2}' ) - # version=$( get_de_app_version 'kded' '^KDE:' '2' ) + # version=$( get_program_version 'kded' '^KDE:' '2' ) if [[ -z $version ]];then version='3.5' fi @@ -3972,22 +4897,52 @@ get_desktop_environment() fi desktop_environment="KDE" elif [[ $XDG_CURRENT_DESKTOP == 'Unity' ]];then - version=$( get_de_app_version 'unity' '^unity' '2' ) - # not certain cinn will always have version, so keep output right if not + version=$( get_program_version 'unity' '^unity' '2' ) + # not certain will always have version, so keep output right if not if [[ -n $version ]];then version="$version " fi if [[ $B_EXTRA_DATA == 'true' ]];then toolkit=$( get_de_gtk_data ) if [[ -n $toolkit ]];then - version="${version}(Gtk ${toolkit})" + version="$version(Gtk $toolkit)" fi fi desktop_environment="Unity" + elif [[ $XDG_CURRENT_DESKTOP == 'LXQt' ]];then +# if type -p lxqt-about &>/dev/null;then +# version=$( get_program_version 'lxqt-about' '^lxqt-about' '2' ) +# fi + if [[ $B_EXTRA_DATA == 'true' ]];then + if kded$KDE_SESSION_VERSION &>/dev/null;then + version_data=$( kded$KDE_SESSION_VERSION --version 2>/dev/null ) + toolkit=$( grep -si '^Qt:' <<< "$version_data" | gawk '{print $2}' ) + elif type -p qtdiag &>/dev/null;then + toolkit=$( get_program_version 'qtdiag' '^qt' '2' ) + fi + if [[ -n $toolkit ]];then + version="$version (Qt $toolkit)" + fi + fi + desktop_environment='LXQt' + # note, X-Cinnamon value strikes me as highly likely to change, so just search for the last part + elif [[ -n $XDG_CURRENT_DESKTOP && -z ${XDG_CURRENT_DESKTOP/*innamon*/} ]];then + version=$( get_program_version 'cinnamon' '^cinnamon' '2' ) + # not certain cinn will always have version, so keep output right if not + if [[ -n $version ]];then + version="$version " + fi + if [[ $B_EXTRA_DATA == 'true' ]];then + toolkit=$( get_de_gtk_data ) + if [[ -n $toolkit ]];then + version="$version(Gtk $toolkit)" + fi + fi + desktop_environment="Cinnamon" fi # did we find it? If not, start the xprop tests if [[ -z $desktop_environment ]];then - if [[ -n $( type -p xprop ) ]];then + if type -p xprop &>/dev/null;then xprop_root="$( xprop -root 2>/dev/null )" fi # note that cinnamon split from gnome, and and can now be id'ed via xprop, @@ -3995,7 +4950,7 @@ get_desktop_environment() # eventually this needs to be better organized so all the xprop tests are in the same # section, but this is good enough for now. if [[ -n $xprop_root && -n $( grep -is '^_MUFFIN' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'cinnamon' '^cinnamon' '2' ) + version=$( get_program_version 'cinnamon' '^cinnamon' '2' ) # not certain cinn will always have version, so keep output right if not if [[ -n $version ]];then version="$version " @@ -4003,12 +4958,12 @@ get_desktop_environment() if [[ $B_EXTRA_DATA == 'true' ]];then toolkit=$( get_de_gtk_data ) if [[ -n $toolkit ]];then - version="${version}(Gtk ${toolkit})" + version="$version(Gtk $toolkit)" fi fi desktop_environment="Cinnamon" - elif [[ -n $xprop_root && -n $( grep -is '^_MARCO' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'mate-about' '^MATE[[:space:]]DESKTOP' 'NF' ) + elif [[ $XDG_CURRENT_DESKTOP == 'MATE' ]] || [[ -n $xprop_root && -n $( grep -is '^_MARCO' <<< "$xprop_root" ) ]];then + version=$( get_program_version 'mate-about' '^MATE[[:space:]]DESKTOP' 'NF' ) # not certain cinn/mate will always have version, so keep output right if not if [[ -n $version ]];then version="$version " @@ -4016,17 +4971,17 @@ get_desktop_environment() if [[ $B_EXTRA_DATA == 'true' ]];then toolkit=$( get_de_gtk_data ) if [[ -n $toolkit ]];then - version="${version}(Gtk ${toolkit})" + version="$version(Gtk $toolkit)" fi fi desktop_environment="MATE" # note, GNOME_DESKTOP_SESSION_ID is deprecated so we'll see how that works out # https://bugzilla.gnome.org/show_bug.cgi?id=542880 - elif [[ -n $GNOME_DESKTOP_SESSION_ID ]]; then - if [[ -n $( type -p gnome-shell ) ]];then - version=$( get_de_app_version 'gnome-shell' 'gnome' '3' ) - elif [[ -n $( type -p gnome-about ) ]];then - version=$( get_de_app_version 'gnome-about' 'gnome' '3' ) + elif [[ -n $GNOME_DESKTOP_SESSION_ID || $XDG_CURRENT_DESKTOP == 'GNOME' ]]; then + if type -p gnome-shell &>/dev/null;then + version=$( get_program_version 'gnome-shell' 'gnome' '3' ) + elif type -p gnome-about &>/dev/null;then + version=$( get_program_version 'gnome-about' 'gnome' '3' ) fi if [[ $B_EXTRA_DATA == 'true' ]];then toolkit=$( get_de_gtk_data ) @@ -4043,16 +4998,16 @@ get_desktop_environment() # String: "This is xfdesktop version 4.2.12" # alternate: xfce4-about --version > xfce4-about 4.10.0 (Xfce 4.10) if [[ -n $( grep -Eis '\"xfce4\"' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'xfdesktop' 'xfdesktop[[:space:]]version' '5' ) + version=$( get_program_version 'xfdesktop' 'xfdesktop[[:space:]]version' '5' ) # arch linux reports null, so use alternate if null if [[ -z $version ]];then - version=$( get_de_app_version 'xfce4-panel' '^xfce4-panel' '2' ) + version=$( get_program_version 'xfce4-panel' '^xfce4-panel' '2' ) if [[ -z $version ]];then version='4' fi fi if [[ $B_EXTRA_DATA == 'true' ]];then - toolkit=$( get_de_app_version 'xfdesktop' 'Built[[:space:]]with[[:space:]]GTK' '4' ) + toolkit=$( get_program_version 'xfdesktop' 'Built[[:space:]]with[[:space:]]GTK' '4' ) if [[ -n $toolkit ]];then version="$version (Gtk $toolkit)" fi @@ -4060,47 +5015,75 @@ get_desktop_environment() desktop_environment="Xfce" # when 5 is released, the string may need updating elif [[ -n $( grep -is '\"xfce5\"' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'xfdesktop' 'xfdesktop[[:space:]]version' '5' ) + version=$( get_program_version 'xfdesktop' 'xfdesktop[[:space:]]version' '5' ) # arch linux reports null, so use alternate if null if [[ -z $version ]];then - version=$( get_de_app_version 'xfce5-panel' '^xfce5-panel' '2' ) + version=$( get_program_version 'xfce5-panel' '^xfce5-panel' '2' ) if [[ -z $version ]];then version='5' fi fi if [[ $B_EXTRA_DATA == 'true' ]];then - toolkit=$( get_de_app_version 'xfdesktop' 'Built[[:space:]]with[[:space:]]GTK' '4' ) + toolkit=$( get_program_version 'xfdesktop' 'Built[[:space:]]with[[:space:]]GTK' '4' ) + if [[ -n $toolkit ]];then + version="$version (Gtk $toolkit)" + fi + fi + desktop_environment="Xfce" + # case where no xfce number exists, just xfce + elif [[ -n $( grep -is 'xfce' <<< "$xprop_root" ) ]];then + version=$( get_program_version 'xfdesktop' 'xfdesktop[[:space:]]version' '5' ) + # arch linux reports null, so use alternate if null + if [[ -z $version ]];then + version=$( get_program_version 'xfce4-panel' '^xfce5-panel' '2' ) + if [[ -z $version ]];then + # version=$( get_program_version 'xfce5-panel' '^xfce5-panel' '2' ) + #if [[ -z $version ]];then + # version='5' + #fi + version='4' + fi + fi + if [[ $B_EXTRA_DATA == 'true' ]];then + toolkit=$( get_program_version 'xfdesktop' 'Built[[:space:]]with[[:space:]]GTK' '4' ) if [[ -n $toolkit ]];then version="$version (Gtk $toolkit)" fi fi desktop_environment="Xfce" elif [[ -n $( grep -is 'BLACKBOX_PID' <<< "$xprop_root" ) ]];then - if [[ -n $( grep -is 'fluxbox' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'fluxbox' '^fluxbox' '2' ) + if [[ -n $( grep -is 'fluxbox' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'fluxbox' '^fluxbox' '2' ) desktop_environment='Fluxbox' else desktop_environment='Blackbox' fi elif [[ -n $( grep -is 'OPENBOX_PID' <<< "$xprop_root" ) ]];then # note: openbox-lxde --version may be present, but returns openbox data - version=$( get_de_app_version 'openbox' '^openbox' '2' ) + version=$( get_program_version 'openbox' '^openbox' '2' ) if [[ $XDG_CURRENT_DESKTOP == 'LXDE' || \ - -n $( grep -is 'lxde' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then + -n $( grep -is '/lxsession' <<< "$Ps_aux_Data" ) ]];then if [[ -n $version ]];then version="(Openbox $version)" fi desktop_environment='LXDE' - elif [[ -n $( grep -is 'razor-desktop' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then + elif [[ $XDG_CURRENT_DESKTOP == 'Razor' || $XDG_CURRENT_DESKTOP == 'LXQt' ]] || \ + [[ -n $( grep -Eis '(razor-desktop|lxqt-session)' <<< "$Ps_aux_Data" ) ]];then + if [[ -n $( grep -is 'lxqt-session' <<< "$Ps_aux_Data" ) ]];then + desktop_environment='LXQt' + elif [[ -n $( grep -is 'razor-desktop' <<< "$Ps_aux_Data" ) ]];then + desktop_environment='Razor-Qt' + else + desktop_environment='LX-Qt-Variant' + fi if [[ -n $version ]];then version="(Openbox $version)" fi - desktop_environment='Razor-QT' else - desktop_environment='Openbox' + desktop_environment='Openbox' fi elif [[ -n $( grep -is 'ICEWM' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'icewm' '^icewm' '2' ) + version=$( get_program_version 'icewm' '^icewm' '2' ) desktop_environment='IceWM' elif [[ -n $( grep -is 'ENLIGHTENMENT' <<< "$xprop_root" ) ]];then # no -v or --version but version is in xprop -root @@ -4108,10 +5091,10 @@ get_desktop_environment() version=$( grep -is 'ENLIGHTENMENT_VERSION' <<< "$xprop_root" | cut -d '"' -f 2 | gawk '{print $2}' ) desktop_environment='Enlightenment' elif [[ -n $( grep -is '^I3_' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'i3' '^i3' '3' ) + version=$( get_program_version 'i3' '^i3' '3' ) desktop_environment='i3' elif [[ -n $( grep -is 'WINDOWMAKER' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'wmaker' '^Window[[:space:]]*Maker' 'NF' ) + version=$( get_program_version 'wmaker' '^Window[[:space:]]*Maker' 'NF' ) if [[ -n $version ]];then version="$version " fi @@ -4119,14 +5102,14 @@ get_desktop_environment() elif [[ -n $( grep -is '^_WM2' <<< "$xprop_root" ) ]];then # note; there isn't actually a wm2 version available but error handling should cover it and return null # maybe one day they will add it? - version=$( get_de_app_version 'wm2' '^wm2' 'NF' ) + version=$( get_program_version 'wm2' '^wm2' 'NF' ) # not certain will always have version, so keep output right if not if [[ -n $version ]];then version="$version " fi desktop_environment="WM2" elif [[ -n $( grep -is 'herbstluftwm' <<< "$xprop_root" ) ]];then - version=$( get_de_app_version 'herbstluftwm' '^herbstluftwm' 'NF' ) + version=$( get_program_version 'herbstluftwm' '^herbstluftwm' 'NF' ) if [[ -n $version ]];then version="$version " fi @@ -4136,38 +5119,38 @@ get_desktop_environment() # a few manual hacks for things that don't id with xprop, these are just good guesses # note that gawk is going to exit after first occurance of search string, so no need for extra if [[ -z $desktop_environment ]];then - if [[ -n $( grep -is 'fvwm-crystal' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'fvwm' '^fvwm' '2' ) + if [[ -n $( grep -is 'fvwm-crystal' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'fvwm' '^fvwm' '2' ) desktop_environment='FVWM-Crystal' - elif [[ -n $( grep -is 'fvwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'fvwm' '^fvwm' '2' ) + elif [[ -n $( grep -is 'fvwm' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'fvwm' '^fvwm' '2' ) desktop_environment='FVWM' - elif [[ -n $( grep -is 'pekwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'pekwm' '^pekwm' '3' ) + elif [[ -n $( grep -is 'pekwm' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'pekwm' '^pekwm' '3' ) desktop_environment='pekwm' - elif [[ -n $( grep -is 'awesome' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'awesome' '^awesome' '2' ) + elif [[ -n $( grep -is 'awesome' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'awesome' '^awesome' '2' ) desktop_environment='Awesome' - elif [[ -n $( grep -is 'scrotwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'scrotwm' '^welcome.*scrotwm' '4' ) + elif [[ -n $( grep -is 'scrotwm' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'scrotwm' '^welcome.*scrotwm' '4' ) desktop_environment='Scrotwm' # no --version for this one - elif [[ -n $( grep -is 'spectrwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'spectrwm' '^spectrwm.*welcome.*spectrwm' '5' ) + elif [[ -n $( grep -is 'spectrwm' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'spectrwm' '^spectrwm.*welcome.*spectrwm' '5' ) desktop_environment='Spectrwm' # no --version for this one - elif [[ -n $( grep -Eis '([[:space:]]|/)twm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then + elif [[ -n $( grep -Eis '([[:space:]]|/)twm' <<< "$Ps_aux_Data" ) ]];then desktop_environment='Twm' # no --version for this one - elif [[ -n $( grep -Eis '([[:space:]]|/)dwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'dwm' '^dwm' '1' ) + elif [[ -n $( grep -Eis '([[:space:]]|/)dwm' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'dwm' '^dwm' '1' ) desktop_environment='dwm' - elif [[ -n $( grep -is 'wmii2' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'wmii2' '^wmii2' '1' ) + elif [[ -n $( grep -is 'wmii2' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'wmii2' '^wmii2' '1' ) desktop_environment='wmii2' # note: in debian at least, wmii is actuall wmii3 - elif [[ -n $( grep -is 'wmii' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'wmii' '^wmii' '1' ) + elif [[ -n $( grep -is 'wmii' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'wmii' '^wmii' '1' ) desktop_environment='wmii' - elif [[ -n $( grep -Eis '([[:space:]]|/)jwm' <<< "$Ps_aux_Data" | grep -v 'grep' ) ]];then - version=$( get_de_app_version 'jwm' '^jwm' '2' ) + elif [[ -n $( grep -Eis '([[:space:]]|/)jwm' <<< "$Ps_aux_Data" ) ]];then + version=$( get_program_version 'jwm' '^jwm' '2' ) desktop_environment='JWM' fi fi @@ -4176,13 +5159,14 @@ get_desktop_environment() if [[ -n $version ]];then version=" $version" fi - echo "$desktop_environment${version}" + log_function_data "desktop_environment version: $desktop_environment$version" + echo "$desktop_environment$version" eval $LOGFE } # note: gawk doesn't support white spaces in search string, gave errors, so use [[:space:]] instead # args: $1 - desktop/app command for --version; $2 - search string; $3 - gawk print number -get_de_app_version() +get_program_version() { local version_data='' version='' get_version='--version' @@ -4206,7 +5190,7 @@ get_de_app_version() ;; # quick debian/buntu hack until I find a universal way to get version for these dash) - if [[ -n $( type -p dpkg ) ]];then + if type -p dpkg &>/dev/null;then version_data="$( dpkg -l $1 2>/dev/null )" fi ;; @@ -4214,7 +5198,7 @@ get_de_app_version() version_data="$( $1 $get_version 2>/dev/null )" ;; esac - + log_function_data "version data: $version_data" if [[ -n $version_data ]];then version=$( gawk ' BEGIN { @@ -4228,6 +5212,7 @@ get_de_app_version() exit # quit after first match prints }' <<< "$version_data" ) fi + log_function_data "program version: $version" echo $version } @@ -4240,7 +5225,7 @@ get_desktop_extra_data() desktops="" separator="" } - /(gnome-shell|gnome-panel|kicker|lxpanel|mate-panel|plasma-desktop|xfce4-panel)$/ { + /(gnome-shell|gnome-panel|kicker|lxpanel|mate-panel|plasma-desktop|plasma-netbook|xfce4-panel)$/ { # only one entry per type, can be multiple if ( desktops !~ $NF ) { desktops = desktops separator $NF @@ -4251,6 +5236,7 @@ get_desktop_extra_data() print desktops } ' ) + log_function_data "de_data: $de_data" echo $de_data eval $LOGFE @@ -4264,7 +5250,7 @@ get_de_gtk_data() # this is a hack, and has to be changed with every toolkit version change, and only dev systems # have this installed, but it's a cross distro command so let's test it first - if [[ -n $( type -p pkg-config ) ]];then + if type -p pkg-config &>/dev/null;then toolkit=$( pkg-config --modversion gtk+-4.0 2>/dev/null ) # note: opensuse gets null output here, we need the command to get version and output sample if [[ -z $toolkit ]];then @@ -4279,42 +5265,76 @@ get_de_gtk_data() # we'll try some known package managers next. dpkg will handle a lot of distros # this is the most likely order as of: 2014-01-13. Not going to try to support all package managers # too much work, just the very biggest ones. - if [[ -n $( type -p dpkg ) ]];then - toolkit=$( dpkg -s libgtk-3-0 2>/dev/null | gawk -F ':' '/^Version/ {print $2}' ) + if type -p dpkg &>/dev/null;then + toolkit=$( dpkg -s libgtk-3-0 2>/dev/null | gawk -F ':' '/^[[:space:]]*Version/ {print $2}' ) + # just guessing on gkt 4 package name + if [[ -z $toolkit ]];then + toolkit=$( dpkg -s libgtk-4-0 2>/dev/null | gawk -F ':' '/^[[:space:]]*Version/ {print $2}' ) + fi if [[ -z $toolkit ]];then - toolkit=$( dpkg -s libgtk2.0-0 2>/dev/null | gawk -F ':' '/^Version/ {print $2}' ) + toolkit=$( dpkg -s libgtk2.0-0 2>/dev/null | gawk -F ':' '/^[[:space:]]*Version/ {print $2}' ) fi + elif type -p pacman &>/dev/null;then + toolkit=$( pacman -Qi gtk3 2>/dev/null | gawk -F ':' '/^[[:space:]]*Version/ {print $2}' ) # just guessing on gkt 4 package name if [[ -z $toolkit ]];then - toolkit=$( dpkg -s libgtk-4-0 2>/dev/null | gawk -F ':' '/^Version/ {print $2}' ) + toolkit=$( pacman -Qi gtk4 2>/dev/null | gawk -F ':' '/^[[:space:]]*Version/ {print $2}' ) + fi + if [[ -z $toolkit ]];then + toolkit=$( pacman -Qi gtk2 2>/dev/null | gawk -F ':' '/^[[:space:]]*Version/ {print $2}' ) + fi + # Name : libgtk-3-0 + # Version : 3.12.2 + elif type -p rpm &>/dev/null;then + toolkit=$( rpm -qi libgtk-3-0 2>/dev/null | gawk -F ':' ' + /^[[:space:]]*Version/ { + gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2) + print $2 + }' ) + if [[ -z $toolkit ]];then + toolkit=$( rpm -qi libgtk-4-0 2>/dev/null | gawk -F ':' ' + /^[[:space:]]*Version/ { + gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2) + print $2 + }' ) fi - elif [[ -n $( type -p pacman ) ]];then - toolkit=$( pacman -Qi gtk3 2>/dev/null | gawk -F ':' '/^Version/ {print $2}' ) if [[ -z $toolkit ]];then - toolkit=$( pacman -Qi gtk2 2>/dev/null | gawk -F ':' '/^Version/ {print $2}' ) + toolkit=$( rpm -qi libgtk-2-0 2>/dev/null | gawk -F ':' ' + /^[[:space:]]*Version/ { + gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2) + print $2 + }' ) fi fi fi + log_function_data "toolkit: $toolkit" echo $toolkit eval $LOGFE } + # see which dm has started if any get_display_manager() { eval $LOGFS - # ldm - LTSP display manager - 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' + # ldm - LTSP display manager. Note that sddm does not appear to have a .pid extension in Arch + # note: to avoid positives with directories, test for -f explicitly, not -e + local dm_id_list='entranced.pid gdm.pid gdm3.pid kdm.pid ldm.pid lightdm.pid lxdm.pid mdm.pid nodm.pid sddm.pid sddm slim.lock tint2.pid wdm.pid xdm.pid' local dm_id='' dm='' separator='' # note we don't need to filter grep if we do it this way local x_is_running=$( grep '/usr.*/X' <<< "$Ps_aux_Data" | grep -iv '/Xprt' ) for dm_id in $dm_id_list do - if [[ -e /var/run/$dm_id || -e /run/$dm_id ]];then + # note: ${dm_id%.*}/$dm_id will create a dir name out of the dm id, then test if pid is in that + # note: sddm, in an effort to be unique and special, do not use a pid/lock file, but rather a random + # string inside a directory called /run/sddm/ so assuming the existence of the pid inside a directory named + # from the dm. Hopefully this change will not have negative results. + if [[ -f /run/$dm_id || -d /run/${dm_id%.*}/ || -f /var/run/$dm_id || \ + -d /var/run/${dm_id%.*}/ ]];then # just on the off chance that two dms are running, good info to have in that case, if possible - dm=$dm$separator$( basename $dm_id | cut -d '.' -f 1 ) + dm=$dm$separator${dm_id%.*} separator=',' fi done @@ -4337,11 +5357,21 @@ get_display_manager() get_distro_data() { eval $LOGFS - local i='' j='' distro='' distro_file='' a_distro_glob='' temp_array='' + local i='' j='' distro='' distro_file='' a_distro_glob='' a_temp='' b_osr='false' # may need modification if archbsd / debian can be id'ed with /etc files if [[ -n $BSD_TYPE ]];then - distro=$( uname -sr ) + if [[ $BSD_VERSION != 'darwin' ]];then + distro=$( uname -sr ) + else + if [[ -f /System/Library/CoreServices/SystemVersion.plist ]];then + distro=$( grep -A1 -E '(ProductName|ProductVersion)' /System/Library/CoreServices/SystemVersion.plist | grep '' | sed -E 's/<[\/]?string>//g' ) + distro=$( echo $distro ) + fi + if [[ -z $distro ]];then + distro='Mac OS X' + fi + fi echo "$distro" log_function_data "distro: $distro" eval $LOGFE @@ -4357,11 +5387,11 @@ get_distro_data() cd "$OLDPWD" shopt -u nullglob - temp_array=${a_distro_glob[@]} - log_function_data "A_GLX_DATA: $temp_array" + a_temp=${a_distro_glob[@]} + log_function_data "a_distro_glob: $a_temp" if [[ ${#a_distro_glob[@]} -eq 1 ]];then - distro_file="${a_distro_glob}" + distro_file="$a_distro_glob" # use the file if it's in the known good lists elif [[ ${#a_distro_glob[@]} -gt 1 ]];then for i in $DISTROS_DERIVED $DISTROS_PRIMARY @@ -4376,12 +5406,12 @@ get_distro_data() # because Mint does not use such, it must be done as below ## this if statement requires the spaces and * as it is, else it won't work ## - if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_FILE == 'true' ]];then + if [[ " $DISTROS_LSB_GOOD " == *" $i "* ]] && [[ $B_LSB_FILE == 'true' ]];then distro_file='lsb-release' - elif [[ " $DISTROS_OS_RELEASE_GOOD " == *" ${i} "* ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then + elif [[ " $DISTROS_OS_RELEASE_GOOD " == *" $i "* ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then distro_file='os-release' else - distro_file="${i}" + distro_file="$i" fi break fi @@ -4400,6 +5430,7 @@ get_distro_data() distro=$( get_distro_lsb_os_release_data 'lsb-file' ) elif [[ $distro_file == 'os-release' ]];then distro=$( get_distro_lsb_os_release_data 'os-release-file' ) + b_osr='true' # then if the distro id file was found and it's not in the exluded primary distro file list, read it elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then # new opensuse uses os-release, but older ones may have a similar syntax, so just use the first line @@ -4413,9 +5444,12 @@ get_distro_data() fi # otherwise try the default debian/ubuntu /etc/issue file elif [[ -f /etc/issue ]];then - # lsb gives more manageable and accurate output than issue, but mint should use issue for now + # os-release/lsb gives more manageable and accurate output than issue, but mint should use issue for now # some bashism, boolean must be in parenthesis to work correctly, ie [[ $(boolean) ]] not [[ $boolean ]] - if [[ $B_LSB_FILE == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then + if [[ $B_OS_RELEASE_FILE == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then + distro=$( get_distro_lsb_os_release_data 'os-release-file' ) + b_osr='true' + elif [[ $B_LSB_FILE == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then distro=$( get_distro_lsb_os_release_data 'lsb-file' ) else distro=$( gawk ' @@ -4424,7 +5458,7 @@ get_distro_data() } { gsub(/\\[a-z]/, "") - gsub(/,/, " ") + gsub(/'"$BAN_LIST_ARRAY"'/, " ") gsub(/^ +| +$/, "") gsub(/ [ \t]+/, " ") print @@ -4438,20 +5472,28 @@ get_distro_data() fi fi fi - + # a final check. If a long value, before assigning the debugger output, if os-release + # exists then let's use that if it wasn't tried already. Maybe that will be better. if [[ ${#distro} -gt 80 ]] && [[ $B_HANDLE_CORRUPT_DATA != 'true' ]];then - distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}" + if [[ $B_OS_RELEASE_FILE == 'true' && $b_osr == 'false' ]];then + distro=$( get_distro_lsb_os_release_data 'os-release-file' ) + fi + if [[ ${#distro} -gt 80 ]];then + distro="${RED}/etc/$distro_file corrupted, use -% to override${NORMAL}" + fi fi ## note: would like to actually understand the method even if it's not used # : ${distro:=Unknown distro o_O} ## test for /etc/lsb-release as a backup in case of failure, in cases where > one version/release file ## were found but the above resulted in null distro value - if [[ -z $distro ]] && [[ $B_LSB_FILE == 'true' ]];then - distro=$( get_distro_lsb_os_release_data 'lsb-file' ) - fi + # Because os-release is now more common, we'll test for it first. if [[ -z $distro ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then distro=$( get_distro_lsb_os_release_data 'os-release-file' ) fi + if [[ -z $distro ]] && [[ $B_LSB_FILE == 'true' ]];then + distro=$( get_distro_lsb_os_release_data 'lsb-file' ) + fi + # now some final null tries if [[ -z $distro ]];then # if the file was null but present, which can happen in some cases, then use the file name itself to @@ -4541,7 +5583,7 @@ get_distro_lsb_os_release_data() ;; lsb-app) # this is HORRIBLY slow, not using - if [[ -n $( type -p lsb_release ) ]];then + if type -p lsb_release &>/dev/null;then distro=$( echo "$( lsb_release -irc )" | gawk -F ':' ' BEGIN { IGNORECASE=1 @@ -4632,82 +5674,109 @@ get_dmidecode_data() { eval $LOGFS - local dmidecodePath='' + local dmiData="" b_debugger='false' if [[ $B_DMIDECODE_SET != 'true' ]];then dmidecodePath=$( type -p dmidecode 2>/dev/null ) - if [[ -n $dmidecodePath ]];then + if [[ -z $dmidecodePath ]];then + DMIDECODE_DATA='dmidecode-error-not-installed' + else # note stripping out these lines: Handle 0x0016, DMI type 17, 27 bytes # but NOT deleting them, in case the dmidecode data is missing empty lines which will be # used to separate results. Then we remove the doubled empty lines to keep it clean and - # strip out all the stuff we don't want to see in the results. - DMIDECODE_DATA="$( $dmidecodePath 2>/dev/null \ - | gawk -F ':' ' - BEGIN { - IGNORECASE=1 - cutExtraTab="false" - twoData="" - oneData="" - } - { - # no idea why, but freebsd gawk does not do this right - oneData=$1 - twoData=$2 - if ( twoData != "" ) { - twoHolder="true" - } - else { - twoHolder="false" - } - if ( $0 ~ /^\tDMI type/ ) { - sub(/^\tDMI type.*/, "", $0) - cutExtraTab="true" - } - gsub(/'"$BAN_LIST_NORMAL"'/, "", twoData) - gsub(/,/, " ", $0) - # clean out Handle line - sub(/^Handle.*/,"", $0) - sub(/^[[:space:]]*Inactive.*/,"",$0) - # yes, there is a typo in a user data set, unknow - # Base Board Version|Base Board Serial Number - # Chassis Manufacturer|Chassis Version|Chassis Serial Number - # System manufacturer|System Product Name|System Version - # To Be Filled By O.E.M. - # strip out starting white space so that the following stuff will clear properly - sub(/^[[:space:]]+/, "", twoData) - sub(/^Base Board .*|^Chassis .*|.*O\.E\.M\..*|.*OEM.*|^Not .*|^System .*|.*unknow.*|.*N\/A.*|none|^To be filled.*/, "", twoData) - gsub(/bios|acpi/, "", twoData) - sub(/http:\/\/www.abit.com.tw\//, "Abit", twoData) - - # for double indented values replace with ~ so later can test for it, we are trusting that - # indentation will be tabbed in this case - # special case, dmidecode 2.2 has an extra tab and a DMI type line - if ( cutExtraTab == "true" ) { - sub(/^\t\t\t+/, "~", oneData) - } - else { - sub(/^\t\t+/, "~", oneData) - } - - gsub(/^[[:space:]]+|[[:space:]]+$/, "", twoData) - gsub(/^[[:space:]]+|[[:space:]]+$/, "", oneData) - gsub(/ [ \t]+/, " ", twoData) - # reconstructing the line for processing so gawk can use -F : again - if ( oneData != "" && twoHolder == "true" ) { - print oneData ":" twoData - } - else { - print $0 + # strip out all the stuff we don't want to see in the results. We want the error data in + # stdout for error handling + if [[ $b_debugger == 'true' && $HOSTNAME == 'yawn' ]];then + dmiData="$( cat ~/bin/scripts/inxi/svn/misc/data/dmidecode/dmidecode-memory-variants-2.txt )" + else + dmiData="$( $dmidecodePath 2>&1 )" + fi + # these tests first, because bsd error messages like this (note how many : are in the string) + # inxi: line 4928: /usr/local/sbin/dmidecode: Permission denied + if [[ ${#dmiData} -lt 200 ]];then + if [[ -z ${dmiData/*Permission denied*/} ]];then + # if [[ -n $( grep -i 'Permission denied' <<< "$dmiData" ) ]];then + DMIDECODE_DATA='dmidecode-error-requires-root' + # this handles very old systems, like Lenny 2.6.26, with dmidecode, but no data + elif [[ -n $( grep -i 'no smbios ' <<< "$dmiData" ) ]];then + DMIDECODE_DATA='dmidecode-error-no-smbios-dmi-data' + else + DMIDECODE_DATA='dmidecode-error-unknown-error' + fi + else + DMIDECODE_DATA="$( echo "$dmiData" | gawk -F ':' ' + BEGIN { + IGNORECASE=1 + cutExtraTab="false" + twoData="" + oneData="" } - }' \ - | sed '/^$/{ + { + # no idea why, but freebsd gawk does not do this right + oneData=$1 + twoData=$2 + if ( twoData != "" ) { + twoHolder="true" + } + else { + twoHolder="false" + } + if ( $0 ~ /^\tDMI type/ ) { + sub(/^\tDMI type.*/, "", $0) + cutExtraTab="true" + } + gsub(/'"$BAN_LIST_NORMAL"'/, "", twoData) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", twoData) + # clean out Handle line + # sub(/^Handle.*/,"", $0) + sub(/^[[:space:]]*Inactive.*/,"",twoData) + # yes, there is a typo in a user data set, unknow + # Base Board Version|Base Board Serial Number + # Chassis Manufacturer|Chassis Version|Chassis Serial Number + # System manufacturer|System Product Name|System Version + # To Be Filled By O.E.M. + # strip out starting white space so that the following stuff will clear properly + sub(/^[[:space:]]+/, "", twoData) + sub(/^Base Board .*|^Chassis .*|empty|.*O\.E\.M\..*|.*OEM.*|^Not .*|^System .*|.*unknow.*|.*N\/A.*|none|^To be filled.*|^0x[0]+$|\[Empty\]||^\.\.$/, "", twoData) + sub(/.*(AssetTagNum|Manufacturer| Or Motherboard|PartNum.*|SerNum).*/, "", twoData) + gsub(/bios|acpi/, "", twoData) + sub(/http:\/\/www.abit.com.tw\//, "Abit", twoData) + + # for double indented values replace with ~ so later can test for it, we are trusting that + # indentation will be tabbed in this case + # special case, dmidecode 2.2 has an extra tab and a DMI type line + if ( cutExtraTab == "true" ) { + sub(/^\t\t\t+/, "~", oneData) + } + else { + sub(/^\t\t+/, "~", oneData) + } + gsub(/ [ \t]+/, " ", twoData) + gsub(/^[[:space:]]+|[[:space:]]+$/, "", twoData) + gsub(/^[[:space:]]+|[[:space:]]+$/, "", oneData) + + # reconstructing the line for processing so gawk can use -F : again + if ( oneData != "" && twoHolder == "true" ) { + print oneData ":" twoData + } + else { + # make sure all null lines have no spaces in them! + gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0) + print $0 + } + }' \ + | sed '/^$/{ N /^\n$/D }' \ - )" + )" + fi + # echo ":${DMIDECODE_DATA}:" + log_function_data "DMIDECODE_DATA (PRE): $DMIDECODE_DATA" + fi B_DMIDECODE_SET='true' - log_function_data "DMIDECODE_DATA: $DMIDECODE_DATA" + log_function_data "DMIDECODE_DATA (POST): $DMIDECODE_DATA" fi eval $LOGFE @@ -4723,28 +5792,26 @@ get_dmesg_boot_data() if [[ $B_DMESG_BOOT_FILE == 'true' ]];then # replace all indented items with ~ so we can id them easily while processing - dmsg_boot_data="$( cat $FILE_DMESG_BOOT | sed $SED_RX 's/"//g' )" + # note that if user, may get error of read permissions + # for some weird reason, real mem and avail mem are use a '=' separator, who knows why, the others are ':' + dmsg_boot_data="$( cat $FILE_DMESG_BOOT 2>/dev/null | gawk ' + { + sub(/[[:space:]]*=[[:space:]]*|:[[:space:]]*/,":", $0) + gsub(/'"$BAN_LIST_ARRAY"'/," ", $0) + gsub(/\"/, "", $0) + gsub(/[[:space:]][[:space:]]/, " ", $0) + print $0 + }' )" fi echo "$dmsg_boot_data" # log_function_data "$dmsg_boot_data" eval $LOGFE } -get_gcc_kernel_version() -{ - # note that we use gawk to get the last part because beta, alpha, git versions can be non-numeric - local gccVersion='' - - if [[ -e /proc/version ]];then - gccVersion=$( grep -Eio 'gcc[[:space:]]*version[[:space:]]*([^ \t]*)' /proc/version 2>/dev/null | gawk '{print $3}' ) - fi - echo $gccVersion -} - get_gcc_system_version() { eval $LOGFS - local separator='' gcc_installed='' gcc_list='' gcc_others='' temp_array='' + local separator='' gcc_installed='' gcc_list='' gcc_others='' a_temp='' local gcc_version=$( gcc --version 2>/dev/null | sed $SED_RX 's/\([^\)]*\)//g' | gawk ' BEGIN { @@ -4753,18 +5820,18 @@ get_gcc_system_version() /^gcc/ { print $2 exit - }' ) - + }' ) # can't use xargs -L basename because not all systems support thats if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then gcc_others=$( ls /usr/bin/gcc-* 2>/dev/null ) if [[ -n $gcc_others ]];then for item in $gcc_others do - gcc_installed=$( basename $item | gawk -F '-' ' + item=${item##*/} + gcc_installed=$( gawk -F '-' ' $2 ~ /^[0-9\.]+$/ { print $2 - }' ) + }' <<< $item ) if [[ -n $gcc_installed && -z $( grep "^$gcc_installed" <<< $gcc_version ) ]];then gcc_list=$gcc_list$separator$gcc_installed separator=',' @@ -4775,30 +5842,36 @@ get_gcc_system_version() if [[ -n $gcc_version ]];then A_GCC_VERSIONS=( "$gcc_version" $gcc_list ) fi - temp_array=${A_GCC_VERSIONS[@]} - log_function_data "A_GCC_VERSIONS: $temp_array" + a_temp=${A_GCC_VERSIONS[@]} + log_function_data "A_GCC_VERSIONS: $a_temp" eval $LOGFE } + get_gpu_temp_data() { local gpu_temp='' gpu_fan='' screens='' screen_nu='' gpu_temp_looper='' # we'll try for nvidia/ati, then add if more are shown - if [[ -n $( type -p nvidia-settings ) ]];then - # first get the number of screens - screens=$( nvidia-settings -q screens | gawk ' - /:[0-9]\.[0-9]/ { - screens=screens gensub(/(.*)(:[0-9]\.[0-9])(.*)/, "\\2", "1", $0) " " - } - END { - print screens - } - ' ) + if type -p nvidia-settings &>/dev/null;then + # first get the number of screens. This only work if you are in X + if [[ $B_RUNNING_IN_DISPLAY == 'true' ]];then + screens=$( nvidia-settings -q screens | gawk ' + /:[0-9]\.[0-9]/ { + screens=screens gensub(/(.*)(:[0-9]\.[0-9])(.*)/, "\\2", "1", $0) " " + } + END { + print screens + } + ' ) + else + # do a guess, this will work for most users, it's better than nothing for out of X + screens=':0.0' + fi # now we'll get the gpu temp for each screen discovered. The print out function # will handle removing screen data for single gpu systems for screen_nu in $screens do - gpu_temp_looper=$( nvidia-settings -c $screen_nu -q GPUCoreTemp | gawk -F ': ' ' + gpu_temp_looper=$( nvidia-settings -c $screen_nu -q GPUCoreTemp 2>/dev/null | gawk -F ': ' ' BEGIN { IGNORECASE=1 gpuTemp="" @@ -4816,7 +5889,7 @@ get_gpu_temp_data() screen_nu=$( cut -d ':' -f 2 <<< $screen_nu ) gpu_temp="$gpu_temp$screen_nu:$gpu_temp_looper " done - elif [[ -n $( type -p aticonfig ) ]];then + elif type -p aticonfig &>/dev/null;then # gpu_temp=$( aticonfig --adapter=0 --od-gettemperature | gawk -F ': ' ' gpu_temp=$( aticonfig --adapter=all --od-gettemperature | gawk -F ': ' ' BEGIN { @@ -4885,21 +5958,30 @@ get_graphics_agp_data() get_graphics_card_data() { eval $LOGFS - local i='' temp_array='' + local i='' a_temp='' IFS=$'\n' A_GRAPHICS_CARD_DATA=( $( gawk -F': ' ' BEGIN { IGNORECASE=1 busId="" + trueCard="" } - /vga compatible controller/ { + # not using 3D controller yet, needs research: |3D controller |display controller + # note: this is strange, but all of these can be either a separate or the same + # card. However, by comparing bus id, say: 00:02.0 we can determine that the + # cards are either the same or different. We want only the .0 version as a valid + # card. .1 would be for example: Display Adapter with bus id x:xx.1, not the right one + /vga compatible controller|3D controller|Display controller/ { gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF) - gsub(/,/, " ", $NF) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $NF) gsub(/^ +| +$/, "", $NF) gsub(/ [ \t]+/, " ", $NF) busId=gensub(/^([0-9a-f:\.]+) (.+)$/,"\\1","",$1) - print $NF "," busId + trueCard=gensub(/(.*)\.([0-9]+)$/,"\\2","",busId) + if ( trueCard == 0 ) { + print $NF "," busId + } }' <<< "$Lspci_v_Data" ) ) IFS="$ORIGINAL_IFS" # for (( i=0; i < ${#A_GRAPHICS_CARD_DATA[@]}; i++ )) @@ -4909,8 +5991,8 @@ get_graphics_card_data() # GFXMEM is UNUSED at the moment, because it shows AGP aperture size, which is not necessarily equal to GFX memory.. # 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/dev/null;then # note: MUST be this syntax: X -version 2>&1 # otherwise X -version overrides everything and this comes out null. # two knowns id strings: X.Org X Server 1.7.5 AND X Window System Version 1.7.5 #X -version 2>&1 | gawk '/^X Window System Version/ { print $5 }' x_data="$( X -version 2>&1 )" - elif [[ -n $( type -p Xorg ) ]];then + elif type -p Xorg &>/dev/null;then x_data="$( Xorg -version 2>&1)" fi if [[ -n $x_data ]];then @@ -5231,28 +6315,62 @@ get_graphics_display_server_version() get_hdd_data_basic() { eval $LOGFS - local hdd_used='' temp_array='' df_string='' - local hdd_data='' df_test='' + local hdd_used='' a_temp='' df_string='' + local hdd_data='' df_test='' swap_size=0 if [[ -z $BSD_TYPE ]];then - df_string='df -P -T --exclude-type=aufs --exclude-type=devfs --exclude-type=devtmpfs - --exclude-type=fdescfs --exclude-type=iso9660 --exclude-type=linprocfs --exclude-type=procfs - --exclude-type=squashfs --exclude-type=sysfs --exclude-type=tmpfs --exclude-type=unionfs' + ## NOTE: older df do not have --total (eg: v: 6.10 2008) + ## keep in mind the only value of use with --total is 'used' in blocks, which + ## we can use later to calculate the real percentags based on disk sizes, not + ## mounted partitions. Not using --total because it's more reliable to exclude non /dev + df_string="df -P -T --exclude-type=aufs --exclude-type=devfs --exclude-type=devtmpfs + --exclude-type=fdescfs --exclude-type=iso9660 --exclude-type=linprocfs --exclude-type=nfs + --exclude-type=nfs3 --exclude-type=nfs4 --exclude-type=nfs5 --exclude-type=procfs --exclude-type=smbfs + --exclude-type=squashfs --exclude-type=sysfs --exclude-type=tmpfs --exclude-type=unionfs" + if swapon -s &>/dev/null;then + swap_size=$( swapon -s 2>/dev/null | gawk ' + BEGIN { + swapSize=0 + total=0 + } + ( $2 == "partition" ) && ( $3 ~ /^[0-9]+$/ ) { + total += ( 1000 / 1024 ) * $3 + } + END { + # result in kB, change to 1024 Byte blocks + total = total * 1000 / 1024 + total = sprintf( "%.1f", total ) + print total + }' ) + fi else - # default size is 512, so use -k for 1024 - df_string='df -T -k' - # default size is 512, -H only for size in human readable format + # default size is 512, , so use -k for 1024 -H only for size in human readable format # older bsds don't support -T, pain, so we'll use partial output there - df_test=$( df -H -T 2>/dev/null ) - if [[ -n $df_test ]];then + if df -k -T &>/dev/null;then df_string='df -k -T' else df_string='df -k' fi + if swapctl -l -k &>/dev/null;then + swap_size=$( swapctl -l -k 2>/dev/null | gawk ' + BEGIN { + swapSize=0 + total=0 + } + ( $1 ~ /^\/dev/ ) && ( $2 ~ /^[0-9]+$/ ) { + total += $2 + } + END { + # result in blocks already + print total + }' ) + fi fi + # echo ss: $swap_size hdd_data="$( eval $df_string )" + # eval $df_string | awk 'BEGIN{tot=0} !/total/ {tot+=$4} END{print tot}' log_function_data 'raw' "hdd_data:\n$hdd_data" - hdd_used=$( echo "$hdd_data" | gawk -v bsdType=$BSD_TYPE ' + hdd_used=$( echo "$hdd_data" | gawk -v bsdType="$BSD_TYPE" -v swapSize="$swap_size" ' BEGIN { # this is used for specific cases where bind, or incorrect multiple mounts to same partitions, # is present. The value is searched for an earlier appearance of that partition and if it is @@ -5262,15 +6380,18 @@ get_hdd_data_basic() devSet="" devWorking="" mountWorking="" + used=0 } # using $1, not $2, because older bsd df do not have -T, filesystem type - ( bsdType != "" ) && $1 ~ /^(aufs|devfs|devtmpfs|fdescfs|filesystem|iso9660|linprocfs|procfs|squashfs|sysfs|tmpfs|type|unionfs)$/ { + ( bsdType != "" ) && $1 ~ /^(aufs|devfs|devtmpfs|fdescfs|filesystem|iso9660|linprocfs|nfs|nfs3|nfs4|nfs5|procfs|squashfs|smbfs|sysfs|tmpfs|type|unionfs)$/ { # note use next, not getline or it does not work right next } # also handles odd dm-1 type, from lvm, and mdraid, and some other bsd partition syntax # note that linux 3.2.45-grsec-9th types kernels have this type of partition name: /dev/xvdc (no number, letter) - /^\/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])/ { + # note: btrfs does not seem to use partition integers, just the primary /dev/sdx identifier + # df can also show /dev/disk/(by-label|by-uuid etc) + /^\/dev\/(disk\/|mapper\/|[hsv]d[a-z]+[0-9]*|dm[-]?[0-9]+|(ada|mmcblk|nvme[0-9]+n)[0-9]+p[0-9]+.*|(ad|sd|wd)[0-9]+[a-z]|md[0-9]+|[aw]d[0-9]+s.*|xvd[a-z]+)|^ROOT/ { # this handles the case where the first item is too long # and makes df wrap output to next line, so here we advance # it to the next line for that single case. Using df -P should @@ -5312,9 +6433,11 @@ get_hdd_data_basic() } } END { - print used + used=used + swapSize + used = sprintf( "%.1f", used ) + print used }' ) - + # echo hdu:$hdd_used if [[ -z $hdd_used ]];then hdd_used='na' fi @@ -5326,10 +6449,10 @@ get_hdd_data_basic() if [[ $B_PARTITIONS_FILE == 'true' ]];then A_HDD_DATA=( $( - gawk -v hddused="$hdd_used" ' - /[hsv]d[a-z]$/ { + gawk -v hddUsed=$hdd_used ' + /([hsv]d[a-z]+|(ada|mmcblk|nvme[0-9]+n)[0-9]+)$/ { driveSize = $(NF - 1)*1024/1000**3 - gsub(/,/, " ", driveSize) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", driveSize) gsub(/^ +| +$/, "", driveSize) printf( $NF",%.1fGB,,\n", driveSize ) } @@ -5339,33 +6462,43 @@ get_hdd_data_basic() # } # special case from this data: 8 0 156290904 sda # note: vm has 252/253/254 known starter, grsec has 202 - $1 ~ /^(3|8|22|33|202|252|253|254)$/ && $NF ~ /[hsv]d[a-z]$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) { + $1 ~ /^(3|8|22|33|202|252|253|254)$/ && $NF ~ /[hsv]d[a-z]+$/ && ( $2 % 16 == 0 || $2 % 16 == 8 ) { size += $3 } - END { size = size*1024/1000**3 # calculate size in GB size - workingUsed = hddused*1024/1000**3 # calculate workingUsed in GB used + workingUsed = hddUsed*1024/1000**3 # calculate workingUsed in GB used # this handles a special case with livecds where no hdd_used is detected - if ( size > 0 && hddused == "na" ) { + if ( size > 0 && hddUsed == "na" ) { size = sprintf( "%.1f", size ) - print size "GB,-" + print size "GB,-,,.." } else if ( size > 0 && workingUsed > 0 ) { diskUsed = workingUsed*100/size # calculate used percentage diskUsed = sprintf( "%.1f", diskUsed ) + if ( int(diskUsed) > 100 ) { + diskUsed = "Used Error!" + } + else { + diskUsed = diskUsed "% used" + } size = sprintf( "%.1f", size ) - print size "GB," diskUsed "% used" + print size "GB," diskUsed ",,.." } else { - print "NA,-" # print an empty array, this will be further handled in the print out function + print "NA,-,,.." # print an empty array, this will be further handled in the print out function } }' $FILE_PARTITIONS ) ) log_function_data 'cat' "$FILE_PARTITIONS" + else + if [[ -n $BSD_TYPE ]];then + get_hard_drive_data_bsd "$hdd_used" + fi fi IFS="$ORIGINAL_IFS" - temp_array=${A_HDD_DATA[@]} - log_function_data "A_HDD_DATA: $temp_array" + a_temp=${A_HDD_DATA[@]} + # echo ${a_temp[@]} + log_function_data "A_HDD_DATA: $a_temp" eval $LOGFE } @@ -5374,7 +6507,8 @@ get_hard_drive_data_advanced() { eval $LOGFS local a_temp_working='' a_temp_scsi='' temp_holder='' temp_name='' i='' j='' - local sd_ls_by_id='' ls_disk_by_id='' usb_exists='' temp_array='' + local sd_ls_by_id='' ls_disk_by_id='' ls_disk_by_path='' usb_exists='' a_temp='' + local firewire_exists='' thunderbolt_exists='' thunderbolt_exists='' hdd_temp hdd_serial='' ## check for all ide type drives, non libata, only do it if hdx is in array ## this is now being updated for new /sys type paths, this may handle that ok too @@ -5423,7 +6557,7 @@ get_hard_drive_data_advanced() #c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/,"\\1 \\2","g",a[i] ) # the vendor: string is useless, and is a bug, ATA is not a vendor for example c=gensub( /^ *vendor: (.+) +model: (.+) +rev:.*$/, "\\2", "g", a[i] ) - gsub(/,/, " ", c) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", c) gsub(/^ +| +$/, "", c) gsub(/ [ \t]+/, " ", c) #print a[i] @@ -5444,6 +6578,7 @@ get_hard_drive_data_advanced() # first pack the main ls variable so we don't have to keep using ls /dev... # not all systems have /dev/disk/by-id ls_disk_by_id="$( ls -l /dev/disk/by-id 2>/dev/null )" + ls_disk_by_path="$( ls -l /dev/disk/by-path 2>/dev/null )" for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ )) do if [[ -n $( grep -E '^sd[a-z]' <<< ${A_HDD_DATA[$i]} ) ]];then @@ -5454,16 +6589,15 @@ get_hard_drive_data_advanced() # this is handles the new /sys data types first if [[ -e /sys/block/${a_temp_working[0]}/device/model ]];then temp_name="$( remove_erroneous_chars /sys/block/${a_temp_working[0]}/device/model )" - temp_name=$( tr ' ' '_' <<< $temp_name | cut -d '-' -f 1 ) + temp_name=$( cut -d '-' -f 1 <<< ${temp_name// /_} ) elif [[ ${#a_temp_scsi[@]} -gt 0 ]];then for (( j=0; j < ${#a_temp_scsi[@]}; j++ )) do ## ok, ok, it's incomprehensible, search /dev/disk/by-id for a line that contains the # discovered disk name AND ends with the correct identifier, sdx # get rid of whitespace for some drive names and ids, and extra data after - in name - temp_name=$( tr ' ' '_' <<< ${a_temp_scsi[$j]} | cut -d '-' -f 1 ) + temp_name=$( cut -d '-' -f 1 <<< ${a_temp_scsi[$j]// /_} ) sd_ls_by_id=$( grep -Em1 ".*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" ) - if [[ -n $sd_ls_by_id ]];then temp_name=${a_temp_scsi[$j]} break @@ -5478,11 +6612,24 @@ get_hard_drive_data_advanced() if [[ -z $temp_name ]];then temp_name="Name n/a" - else + # maybe remove this from the conditional, detection of usb may not depend on the name + else # usb_exists=$( grep -Em1 "usb-.*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" ) + firewire_exists=$( grep -Em1 "ieee1394-.*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" ) + # thunderbolt_exists=$( grep -Em1 "ieee1394-.*$temp_name.*${a_temp_working[0]}$" <<< "$ls_disk_by_id" ) + # note: sometimes with wwn- numbering usb does not appear in by-id but it does in by-path + if [[ -z $usb_exists ]];then + usb_exists=$( grep -Em1 "usb-.*${a_temp_working[0]}$" <<< "$ls_disk_by_path" ) + fi if [[ -n $usb_exists ]];then a_temp_working[3]='USB' fi + if [[ -z $firewire_exists ]];then + firewire_exists=$( grep -Em1 "ieee1394-.*${a_temp_working[0]}$" <<< "$ls_disk_by_path" ) + fi + if [[ -n $firewire_exists ]];then + a_temp_working[3]='FireWire' + fi fi a_temp_working[2]=$temp_name # these loops are to easily extend the cpu array created in the gawk script above with more fields per cpu. @@ -5495,11 +6642,130 @@ get_hard_drive_data_advanced() fi done fi + if [[ $B_EXTRA_DATA == 'true' ]];then + IFS="," + a_temp_working=( ${A_HDD_DATA[i]} ) + # echo "a:" ${a_temp_working[@]} + IFS="$ORIGINAL_IFS" + hdd_temp='' + hdd_serial='' + if [[ -n ${a_temp_working[1]} ]];then + hdd_temp=$( get_hdd_temp_data "/dev/${a_temp_working[0]}" ) + fi + if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then + hdd_serial=$( get_hdd_serial_number "${a_temp_working[0]}" ) + fi + A_HDD_DATA[i]="${a_temp_working[0]},${a_temp_working[1]},${a_temp_working[2]},${a_temp_working[3]},$hdd_serial,$hdd_temp" + # echo b: ${A_HDD_DATA[i]} + fi done - unset ls_disk_by_id # and then let's dump the data we don't need fi - temp_array=${A_HDD_DATA[@]} - log_function_data "A_HDD_DATA: $temp_array" + a_temp=${A_HDD_DATA[@]} + log_function_data "A_HDD_DATA: $a_temp" + eval $LOGFE +} + +# args: $1 ~ hdd_used +get_hard_drive_data_bsd() +{ + eval $LOGFS + + local a_temp='' + + if [[ -n $Dmesg_Boot_Data ]];then + IFS=$'\n' + A_HDD_DATA=( $( gawk -v hddUsed="$1" -F ':' ' + BEGIN { + IGNORECASE=1 + size=0 + bSetSize="false" + } + $1 ~ /^(ad|ada|mmcblk|nvme[0-9]+n|sd|wd)[0-9]+(|[[:space:]]at.*)$/ { + diskId=gensub(/^((ad|ada|mmcblk|nvme[0-9]+n|sd|wd)[0-9]+)[^0-9].*/,"\\1",1,$1) + # note: /var/run/dmesg.boot may repeat items since it is not created + # fresh every boot, this way, only the last items will be used per disk id + if (aIds[diskId] == "" ) { + aIds[diskId]=diskId + if ( $0 !~ /raid/) { + bSetSize="true" + } + } + aDisks[diskId, "id"] = diskId + if ($0 ~ /[^0-9][0-9\.]+[[:space:]]*[MG]B/ && $0 !~ /MB\/s/) { + workingSize=gensub(/.*[^0-9]([0-9\.]+[[:space:]]*[MG]B).*/,"\\1",1,$0) + if (workingSize ~ /GB/ ) { + sub(/[[:space:]]*GB/,"",workingSize) + workingSize=workingSize*1000 + } + else if (workingSize ~ /MB/ ) { + sub(/[[:space:]]*MB/,"",workingSize) + workingSize=workingSize + } + aDisks[diskId, "size"] = workingSize + if ( bSetSize == "true" ) { + if ( workingSize != "" ){ + size=size+workingSize + bSetSize="false" + } + } + } + if ( $NF ~ /<.*>/ ){ + gsub(/.*<|>.*/,"",$NF) + aDisks[diskId, "model"] = $NF + } + if ( $NF ~ /serial number/ ){ + sub(/serial[[:space:]]+number[[:space:]]*/,"",$NF) + aDisks[diskId, "serial"] = $NF + } + } + END { + # sde,3.9GB,STORE_N_GO,USB,C200431546D3CF49-0:0,0 + # sdd,250.1GB,ST3250824AS,,9ND08GKX,45 + # multi dimensional pseudo arrays are sorted at total random, not in order of + # creation, so force a sort of the aIds, which deletes the array index but preserves + # the sorted keys. + asort(aIds) + + for ( key in aIds ) { + # we are not adding to size above for raid, and we do not print it for raid + # this is re openbsd raid, which uses sd0 for raid array, even though sd is for scsi + if ( aDisks[aIds[key], "model"] !~ /raid/ ) { + workingSize = aDisks[aIds[key], "size"]/1000 + workingSize = sprintf( "%.1fGB", workingSize ) + print aDisks[aIds[key], "id"] "," workingSize "," aDisks[aIds[key], "model"] "," "," aDisks[aIds[key], "serial"] "," + } + } + size = size/1000 # calculate size in GB size + # in kb + workingUsed = hddUsed*1024/1000**3 # calculate workingUsed in GB used + # this handles a special case with livecds where no hdd_used is detected + if ( size > 0 && hddUsed == "na" ) { + size = sprintf( "%.1f", size ) + print size "GB,-,,.." + } + else if ( size > 0 && workingUsed > 0 ) { + diskUsed = workingUsed*100/size # calculate used percentage + diskUsed = sprintf( "%.1f", diskUsed ) + if ( int(diskUsed) > 100 ) { + diskUsed = "Used Error!" + } + else { + diskUsed = diskUsed "% used" + } + size = sprintf( "%.1f", size ) + print size "GB," diskUsed ",,.." + } + else { + print "NA,-,,.." # print an empty array, this will be further handled in the print out function + } + }' <<< "$Dmesg_Boot_Data" ) ) + IFS="$ORIGINAL_IFS" + fi + + a_temp=${A_HDD_DATA[@]} + # echo ${a_temp[@]} + log_function_data "A_HDD_DATA: $a_temp" + eval $LOGFE } @@ -5562,7 +6828,7 @@ get_init_data() { eval $LOGFS - local init_type='' init_version='' rc_type='' rc_version='' temp_array='' + local init_type='' init_version='' rc_type='' rc_version='' a_temp='' local ls_run='' strings_init_version='' local runlevel=$( get_runlevel_data ) local default_runlevel=$( get_runlevel_default ) @@ -5572,11 +6838,13 @@ get_init_data() # more data may be needed for other init systems. if [[ -e /proc/1/comm && -n $( grep -s 'systemd' /proc/1/comm ) ]];then init_type='systemd' - if [[ -n $( type -p systemd ) ]];then - init_version=$( get_de_app_version 'systemd' '^systemd' '2' ) + if type -p systemd &>/dev/null;then + init_version=$( get_program_version 'systemd' '^systemd' '2' ) fi - if [[ -z $init_version && -n $( type -p systemctl ) ]];then - init_version=$( get_de_app_version 'systemctl' '^systemd' '2' ) + if [[ -z $init_version ]];then + if type -p systemctl &>/dev/null;then + init_version=$( get_program_version 'systemctl' '^systemd' '2' ) + fi fi else ls_run=$(ls /run) @@ -5584,37 +6852,49 @@ get_init_data() if [[ -n $( /sbin/init --version 2>/dev/null | grep 'upstart' ) ]];then init_type='Upstart' # /sbin/init --version == init (upstart 1.12.1) - init_version=$( get_de_app_version 'init' 'upstart' '3' ) - elif [[ -n $( type -p epoch ) ]];then + init_version=$( get_program_version 'init' 'upstart' '3' ) + elif [[ -e /proc/1/comm && -n $( grep -s 'epoch' /proc/1/comm ) ]];then init_type='Epoch' # epoch version == Epoch Init System 1.0.1 "Sage" - init_version=$( get_de_app_version 'epoch' '^Epoch' '4' ) - # missing data: + init_version=$( get_program_version 'epoch' '^Epoch' '4' ) + # missing data: note, runit can install as a dependency without being the init system # http://smarden.org/runit/sv.8.html - elif [[ -e /sbin/runit-init || -e /etc/runit || -n $( type -p sv ) ]];then + # NOTE: the proc test won't work on bsds, so if runit is used on bsds we will need more data + elif [[ -e /proc/1/comm && -n $( grep -s 'runit' /proc/1/comm ) ]];then + # elif [[ -e /sbin/runit-init || -e /etc/runit || -n $( type -p sv ) ]];then init_type='runit' # lower case # no data on version yet + # freebsd at least + elif type -p launchctl &>/dev/null;then + init_type='launchd' + # / launchd/ version.plist /etc/launchd.conf + # init_version=$( get_program_version 'Launchd' '^Launchd' '4' ) elif [[ -f /etc/inittab ]];then init_type='SysVinit' - if [[ -n $( type -p strings ) ]];then + if type -p strings &>/dev/null;then strings_init_version="$( strings /sbin/init | grep -E 'version[[:space:]]+[0-9]' )" fi if [[ -n $strings_init_version ]];then init_version=$( gawk '{print $2}' <<< "$strings_init_version" ) fi - # freebsd at least elif [[ -f /etc/ttys ]];then init_type='init (bsd)' fi - if [[ -n $( grep 'openrc' <<< "$ls_run" ) ]];then rc_type='OpenRC' # /sbin/openrc --version == openrc (OpenRC) 0.13 - if [[ -n $( type -p openrc ) ]];then - rc_version=$( get_de_app_version 'openrc' '^openrc' '3' ) + if type -p openrc &>/dev/null;then + rc_version=$( get_program_version 'openrc' '^openrc' '3' ) # /sbin/rc --version == rc (OpenRC) 0.11.8 (Gentoo Linux) - elif [[ -n $( type -p rc ) ]];then - rc_version=$( get_de_app_version 'rc' '^rc' '3' ) + elif type -p rc &>/dev/null;then + rc_version=$( get_program_version 'rc' '^rc' '3' ) + fi + if [[ -e /run/openrc/softlevel ]];then + runlevel=$( cat /run/openrc/softlevel 2>/dev/null ) + elif [[ -e /var/run/openrc/softlevel ]];then + runlevel=$( cat /var/run/openrc/softlevel 2>/dev/null ) + elif type -p rc-status &>/dev/null;then + runlevel=$( rc-status -r 2>/dev/null ) fi ## assume sysvrc, but this data is too buggy and weird and inconsistent to have meaning # leaving this off for now @@ -5624,7 +6904,6 @@ get_init_data() # rc_version=$init_version fi fi - IFS=$'\n' A_INIT_DATA=( @@ -5637,12 +6916,55 @@ get_init_data() IFS="$ORIGINAL_IFS" - temp_array=${A_INIT_DATA[@]} - log_function_data "A_INIT_DATA: $temp_array" + a_temp=${A_INIT_DATA[@]} + log_function_data "A_INIT_DATA: $a_temp" eval $LOGFE } +get_kernel_compiler_version() +{ + # note that we use gawk to get the last part because beta, alpha, git versions can be non-numeric + local compiler_version='' compiler_type='' + + if [[ -e /proc/version ]];then + compiler_version=$( grep -Eio 'gcc[[:space:]]*version[[:space:]]*([^ \t]*)' /proc/version 2>/dev/null | gawk '{print $3}' ) + if [[ -n $compiler_version ]];then + compiler_type='gcc' + fi + else + if [[ $BSD_VERSION == 'darwin' ]];then + if type -p gcc &>/dev/null;then + compiler_version=$( get_program_version 'gcc' 'Apple[[:space:]]LLVM' '4' ) + if [[ -n $compiler_version ]];then + compiler_type='LLVM-GCC' + fi + fi + else + if [[ -f /etc/src.conf ]];then + compiler_type=$( grep '^CC' /etc/src.conf | cut -d '=' -f 2 ) + elif [[ -f /etc/make.conf ]];then + compiler_type=$( grep '^CC' /etc/make.conf | cut -d '=' -f 2 ) + fi + if [[ -n $compiler_type ]];then + if type -p $compiler_type &>/dev/null;then + if [[ $compiler_type == 'gcc' ]];then + compiler_version=$( get_program_version 'gcc' '^gcc' '3' ) + elif [[ $compiler_type == 'clang' ]];then + # FreeBSD clang version 3.0 (tags/RELEASE_30/final 145349) 20111210 + compiler_version=$( get_program_version 'clang' 'clang' '4' ) + fi + fi + fi + fi + fi + if [[ -n $compiler_version ]];then + compiler_version="$compiler_type^$compiler_version" + fi + echo $compiler_version +} + + get_kernel_version() { eval $LOGFS @@ -5650,7 +6972,9 @@ get_kernel_version() local kernel_version='' ksplice_kernel_version='' kernel_version=$( uname -rm ) - + if [[ $BSD_VERSION == 'darwin' ]];then + kernel_version="Darwin $kernel_version" + fi if [[ -n $( type -p uptrack-uname ) && -n $kernel_version ]];then ksplice_kernel_version=$( uptrack-uname -rm ) if [[ $kernel_version != $ksplice_kernel_version ]];then @@ -5705,20 +7029,19 @@ get_lspci_chip_id() get_machine_data() { eval $LOGFS - local temp_array='' separator='' id_file='' file_data='' array_string='' + local a_temp='' separator='' id_file='' file_data='' array_string='' local id_dir='/sys/class/dmi/id/' dmi_data='' local machine_files=" sys_vendor product_name product_version product_serial product_uuid board_vendor board_name board_version board_serial bios_vendor bios_version bios_date " - if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then machine_files="$machine_files chassis_vendor chassis_type chassis_version chassis_serial " fi - if [[ -d $id_dir ]];then + if [[ -d $id_dir && $B_FORCE_DMIDECODE == 'false' ]];then for id_file in $machine_files do file_data='' @@ -5729,13 +7052,13 @@ get_machine_data() } { gsub(/'"$BAN_LIST_NORMAL"'/, "", $0) - gsub(/,/, " ", $0) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $0) # yes, there is a typo in a user data set, unknow # Base Board Version|Base Board Serial Number # Chassis Manufacturer|Chassis Version|Chassis Serial Number # System manufacturer|System Product Name|System Version # To Be Filled By O.E.M. - sub(/^Base Board .*|^Chassis .*|.*O\.E\.M\..*|.*OEM.*|^Not .*|^System .*|.*unknow.*|.*N\/A.*|none|^To be filled.*/, "", $0) + sub(/^Base Board .*|^Chassis .*|.*O\.E\.M\..*|.*OEM.*|^Not .*|^System .*|.*unknow.*|.*N\/A.*|none|^To be filled.*/, "", $0) gsub(/bios|acpi/, "", $0) sub(/http:\/\/www.abit.com.tw\//, "Abit", $0) gsub(/^ +| +$/, "", $0) @@ -5749,121 +7072,121 @@ get_machine_data() else get_dmidecode_data if [[ -n $DMIDECODE_DATA ]];then - if [[ $B_ROOT == 'true' ]];then - # this handles very old systems, like Lenny 2.6.26, with dmidecode, but no data - if [[ -n $( grep -i 'no smbios ' <<< "$DMIDECODE_DATA" ) ]];then - array_string='dmidecode-no-smbios-dmi-data' - # please note: only dmidecode version 2.11 or newer supports consistently the -s flag - else - array_string=$( gawk -F ':' ' - BEGIN { - IGNORECASE=1 - baseboardManufacturer="" - baseboardProductName="" - baseboardSerialNumber="" - baseboardVersion="" - biosReleaseDate="" - biosRevision="" # only available from dmidecode - biosRomSize="" # only available from dmidecode - biosVendor="" - biosVersion="" - chassisManufacturer="" - chassisSerialNumber="" - chassisType="" - chassisVersion="" - systemManufacturer="" - systemProductName="" - systemVersion="" - systemSerialNumber="" - systemUuid="" - bItemFound="" # we will only output if at least one item was found - fullString="" - testString="" - bSys="" - bCha="" - bBio="" - bBas="" - } - /^Bios Information/ { - while ( getline && !/^$/ ) { - if ( $1 ~ /^Release Date/ ) { biosReleaseDate=$2 } - if ( $1 ~ /^BIOS Revision/ ) { biosRevision=$2 } - if ( $1 ~ /^ROM Size/ ) { biosRomSize=$2 } - if ( $1 ~ /^Vendor/ ) { biosVendor=$2 } - if ( $1 ~ /^Version/ ) { biosVersion=$2 } - } - testString=biosReleaseDate biosRevision biosRomSize biosVendor biosVersion - if ( testString != "" ) { - bItemFound="true" - } - bBio="true" - } - /^Base Board Information/ { - while ( getline && !/^$/ ) { - if ( $1 ~ /^Manufacturer/ ) { baseboardManufacturer=$2 } - if ( $1 ~ /^Product Name/ ) { baseboardProductName=$2 } - if ( $1 ~ /^Serial Number/ ) { baseboardSerialNumber=$2 } - } - testString=baseboardManufacturer baseboardProductName baseboardSerialNumber - if ( testString != "" ) { - bItemFound="true" - } - bBas="true" - } - /^Chassis Information/ { - while ( getline && !/^$/ ) { - if ( $1 ~ /^Manufacturer/ ) { chassisManufacturer=$2 } - if ( $1 ~ /^Serial Number/ ) { chassisSerialNumber=$2 } - if ( $1 ~ /^Type/ ) { chassisType=$2 } - if ( $1 ~ /^Version/ ) { chassisVersion=$2 } - } - testString=chassisManufacturer chassisSerialNumber chassisType chassisVersion - if ( testString != "" ) { - bItemFound="true" - } - bCha="true" - } - /^System Information/ { - while ( getline && !/^$/ ) { - if ( $1 ~ /^Manufacturer/ ) { systemManufacturer=$2 } - if ( $1 ~ /^Product Name/ ) { systemProductName=$2 } - if ( $1 ~ /^Version/ ) { systemVersion=$2 } - if ( $1 ~ /^Serial Number/ ) { systemSerialNumber=$2 } - if ( $1 ~ /^UUID/ ) { systemUuid=$2 } - } - testString=systemManufacturer systemProductName systemVersion systemSerialNumber systemUuid - if ( testString != "" ) { - bItemFound="true" - } - bSys="true" - } - ( bSys == "true" && bCha="true" && bBio == "true" && bBas == "true" ) { - exit # stop the loop - } - END { - if ( bItemFound == "true" ) { - fullString = systemManufacturer "," systemProductName "," systemVersion "," systemSerialNumber - fullString = fullString "," systemUuid "," baseboardManufacturer "," baseboardProductName - fullString = fullString "," baseboardVersion "," baseboardSerialNumber "," biosVendor - fullString = fullString "," biosVersion "," biosReleaseDate "," chassisManufacturer - fullString = fullString "," chassisType "," chassisVersion "," chassisSerialNumber - fullString = fullString "," biosRevision "," biosRomSize - - print fullString - } - }' <<< "$DMIDECODE_DATA" ) - fi + if [[ $DMIDECODE_DATA == 'dmidecode-error-'* ]];then + array_string=$DMIDECODE_DATA + # please note: only dmidecode version 2.11 or newer supports consistently the -s flag else - array_string='dmidecode-non-root-user' + array_string=$( gawk -F ':' ' + BEGIN { + IGNORECASE=1 + baseboardManufacturer="" + baseboardProductName="" + baseboardSerialNumber="" + baseboardVersion="" + biosReleaseDate="" + biosRevision="" # only available from dmidecode + biosRomSize="" # only available from dmidecode + biosVendor="" + biosVersion="" + chassisManufacturer="" + chassisSerialNumber="" + chassisType="" + chassisVersion="" + systemManufacturer="" + systemProductName="" + systemVersion="" + systemSerialNumber="" + systemUuid="" + bItemFound="" # we will only output if at least one item was found + fullString="" + testString="" + bSys="" + bCha="" + bBio="" + bBas="" + } + /^Bios Information/ { + while ( getline && !/^$/ ) { + if ( $1 ~ /^Release Date/ ) { biosReleaseDate=$2 } + if ( $1 ~ /^BIOS Revision/ ) { biosRevision=$2 } + if ( $1 ~ /^ROM Size/ ) { biosRomSize=$2 } + if ( $1 ~ /^Vendor/ ) { biosVendor=$2 } + if ( $1 ~ /^Version/ ) { biosVersion=$2 } + } + testString=biosReleaseDate biosRevision biosRomSize biosVendor biosVersion + if ( testString != "" ) { + bItemFound="true" + } + bBio="true" + } + /^Base Board Information/ { + while ( getline && !/^$/ ) { + if ( $1 ~ /^Manufacturer/ ) { baseboardManufacturer=$2 } + if ( $1 ~ /^Product Name/ ) { baseboardProductName=$2 } + if ( $1 ~ /^Serial Number/ ) { baseboardSerialNumber=$2 } + } + testString=baseboardManufacturer baseboardProductName baseboardSerialNumber + if ( testString != "" ) { + bItemFound="true" + } + bBas="true" + } + /^Chassis Information/ { + while ( getline && !/^$/ ) { + if ( $1 ~ /^Manufacturer/ ) { chassisManufacturer=$2 } + if ( $1 ~ /^Serial Number/ ) { chassisSerialNumber=$2 } + if ( $1 ~ /^Type/ ) { chassisType=$2 } + if ( $1 ~ /^Version/ ) { chassisVersion=$2 } + } + testString=chassisManufacturer chassisSerialNumber chassisType chassisVersion + if ( testString != "" ) { + bItemFound="true" + } + bCha="true" + } + /^System Information/ { + while ( getline && !/^$/ ) { + if ( $1 ~ /^Manufacturer/ ) { systemManufacturer=$2 } + if ( $1 ~ /^Product Name/ ) { systemProductName=$2 } + if ( $1 ~ /^Version/ ) { systemVersion=$2 } + if ( $1 ~ /^Serial Number/ ) { systemSerialNumber=$2 } + if ( $1 ~ /^UUID/ ) { systemUuid=$2 } + } + testString=systemManufacturer systemProductName systemVersion systemSerialNumber systemUuid + if ( testString != "" ) { + bItemFound="true" + } + bSys="true" + } + ( bSys == "true" && bCha="true" && bBio == "true" && bBas == "true" ) { + exit # stop the loop + } + END { + # sys_vendor product_name product_version product_serial product_uuid + # board_vendor board_name board_version board_serial + # bios_vendor bios_version bios_date + if ( bItemFound == "true" ) { + fullString = systemManufacturer "," systemProductName "," systemVersion "," systemSerialNumber + fullString = fullString "," systemUuid "," baseboardManufacturer "," baseboardProductName + fullString = fullString "," baseboardVersion "," baseboardSerialNumber "," biosVendor + fullString = fullString "," biosVersion "," biosReleaseDate "," chassisManufacturer + fullString = fullString "," chassisType "," chassisVersion "," chassisSerialNumber + fullString = fullString "," biosRevision "," biosRomSize + + print fullString + } + }' <<< "$DMIDECODE_DATA" ) fi fi fi + # echo $array_string IFS=',' A_MACHINE_DATA=( $array_string ) IFS="$ORIGINAL_IFS" - temp_array=${A_MACHINE_DATA[@]} -# echo ${temp_array[@]} - log_function_data "A_MACHINE_DATA: $temp_array" + # echo ${A_MACHINE_DATA[5]} + a_temp=${A_MACHINE_DATA[@]} + # echo $a_temp + log_function_data "A_MACHINE_DATA: $a_temp" eval $LOGFE } # B_ROOT='true';get_machine_data;exit @@ -5871,7 +7194,7 @@ get_machine_data() get_memory_data() { eval $LOGFS - local memory='' memory_full='' + local memory='' memory_full='' used_memory='' if [[ $B_MEMINFO_FILE == 'true' ]];then memory=$( gawk ' /^MemTotal:/ { @@ -5887,17 +7210,62 @@ get_memory_data() log_function_data 'cat' "$FILE_MEMINFO" elif [[ $B_SYSCTL == 'true' && -n $Sysctl_a_Data ]];then local gawk_fs=': ' - + # darwin sysctl is broken and uses both : and = and repeats these items if [[ $BSD_VERSION == 'openbsd' ]];then gawk_fs='=' fi - memory=$( grep -i 'mem' <<< "$Sysctl_a_Data" | gawk -F "$gawk_fs" ' + # use this for all bsds, maybe we can get some useful data on other ones + if [[ -n $( type -p vmstat) ]];then + # avail mem:2037186560 (1942MB) + used_memory=$( vmstat 2>/dev/null | tail -n 1 | gawk ' + # openbsd/linux + # procs memory page disks traps cpu + # r b w avm fre flt re pi po fr sr wd0 wd1 int sys cs us sy id + # 0 0 0 55256 1484092 171 0 0 0 0 0 2 0 12 460 39 3 1 96 + # freebsd: + # procs memory page disks faults cpu + # r b w avm fre flt re pi po fr sr ad0 ad1 in sy cs us sy id + # 0 0 0 21880M 6444M 924 32 11 0 822 827 0 0 853 832 463 8 3 88 + # dragonfly + # procs memory page disks faults cpu + # r b w avm fre flt re pi po fr sr ad0 ad1 in sy cs us sy id + # 0 0 0 0 84060 30273993 2845 12742 1164 407498171 320960902 0 0 424453025 1645645889 1254348072 35 38 26 + + BEGIN { + IGNORECASE=1 + memory="" + } + { + if ($4 ~ /M/ ){ + sub(/M/,"",$4) + memory=$4*1024 + } + else if ($4 ~ /G/ ){ + sub(/G/,"",$4) + memory=$4*1024*1000 + } + else { + sub(/K/,"",$4) + # dragonfly can have 0 avm, but they may fix that so make test dynamic + if ( $4 != 0 ) { + memory=$4 + } + else { + memory="avm-0-" $5 + } + } + print memory " " + exit + }' ) + fi + # for dragonfly, we will use free mem, not used because free is 0 + memory=$( grep -i 'mem' <<< "$Sysctl_a_Data" | gawk -v usedMemory="$used_memory" -F "$gawk_fs" ' BEGIN { realMemory="" freeMemory="" } # freebsd seems to use bytes here - /^hw.physmem/ { + /^hw.physmem/ && ( realMemory == "" ) { gsub(/^[^0-9]+|[^0-9]+$/,"",$2) realMemory = $2/1024 if ( freeMemory != "" ) { @@ -5914,9 +7282,24 @@ get_memory_data() } } END { - # hack: temp fix for openbsd: in case no free mem was detected but we have physmem + # hack: temp fix for openbsd/darwin: in case no free mem was detected but we have physmem if ( freeMemory == "" && realMemory != "" ) { - printf("NA/%.1fMB\n", realMemory/1024) + # use openbsd/dragonfly avail mem data if available + if (usedMemory != "" ) { + if (usedMemory !~ /^avm-0-/ ) { + printf("%.1f/%.1fMB\n", usedMemory/1024, realMemory/1024) + } + else { + sub(/avm-0-/,"",usedMemory) + int(usedMemory) + # using free mem, not used for dragonfly + usedMemory = realMemory - usedMemory + printf("%.1f/%.1fMB\n", usedMemory/1024, realMemory/1024) + } + } + else { + printf("NA/%.1fMB\n", realMemory/1024) + } } else if ( freeMemory != "" && realMemory != "" ) { used = realMemory - freeMemory @@ -5946,7 +7329,7 @@ get_module_version_number() IGNORECASE=1 } /^version/ { - gsub(/,/, " ", $2) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $2) gsub(/^ +| +$/, "", $2) gsub(/ [ \t]+/, " ", $2) print $2 @@ -5959,91 +7342,86 @@ get_module_version_number() eval $LOGFE } + ## create array of network cards get_networking_data() { eval $LOGFS - local B_USB_NETWORKING='false' temp_array='' + local B_USB_NETWORKING='false' a_temp='' IFS=$'\n' A_NETWORK_DATA=( $( echo "$Lspci_v_Data" | gawk ' + # NOTE: see version 2.1.28 or earlier for old logic if for some reason it is needed again + # that used a modified string made from nic name for index, why, I have no idea, makes no sense and leads + # to wrong ordered output as well. get_audio_data uses the old logic for now too. BEGIN { IGNORECASE=1 - counter=0 # required to handle cases of > 1 instance of the same chipset + counter=0 } - /^[0-9a-f:\.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:\.]+ [^:]+: .*(ethernet|network).*$/ { - nic=gensub(/^[0-9a-f:\.]+ [^:]+: (.+)$/,"\\1","g",$0) - #gsub(/realtek semiconductor/, "Realtek", nic) - #gsub(/davicom semiconductor/, "Davicom", nic) + /^[0-9a-f:\.]+ ((ethernet|network) (controller|bridge)|infiniband)/ || /^[0-9a-f:\.]+ [^:]+: .*(ethernet|infiniband|network).*$/ { + aNic[counter]=gensub(/^[0-9a-f:\.]+ [^:]+: (.+)$/,"\\1","g",$0) + #gsub(/realtek semiconductor/, "Realtek", aNic[counter]) + #gsub(/davicom semiconductor/, "Davicom", aNic[counter]) # The doublequotes are necessary because of the pipes in the variable. - gsub(/'"$BAN_LIST_NORMAL"'/, "", nic) - gsub(/,/, " ", nic) - gsub(/^ +| +$/, "", nic) - gsub(/ [ \t]+/, " ", nic) - # construct a unique string ending for each chipset detected, this allows for - # multiple instances of the same exact chipsets, ie, dual gigabit - nic = nic "~~" counter++ - aPciBusId[nic] = gensub(/(^[0-9a-f:\.]+) [^:]+: .+$/,"\\1","g",$0) - # I do not understand why incrementing a string index makes sense? - eth[nic]++ + gsub(/'"$BAN_LIST_NORMAL"'/, "", aNic[counter]) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", aNic[counter]) + gsub(/^ +| +$/, "", aNic[counter]) + gsub(/ [ \t]+/, " ", aNic[counter]) + aPciBusId[counter] = gensub(/(^[0-9a-f:\.]+) [^:]+: .+$/,"\\1","g",$0) while ( getline && !/^$/ ) { - gsub(/,/, "", $0) - if ( /I\/O/ ) { - ports[nic] = ports[nic] $4 " " + gsub(/'"$BAN_LIST_ARRAY"'/, "", $0) + if ( /^[[:space:]]*I\/O/ ) { + aPorts[counter] = aPorts[counter] $4 " " } if ( /driver in use/ ) { - drivers[nic] = drivers[nic] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) "" + aDrivers[counter] = aDrivers[counter] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) "" } else if ( /kernel modules/ ) { - modules[nic] = modules[nic] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) "" + aModules[counter] = aModules[counter] gensub( /(.*): (.*)/ ,"\\2" ,"g" ,$0 ) "" } } + counter++ } - END { - j=0 - for (i in eth) { + for (i=0;i 1 ) { - a[j] = eth[i] "x " i - } - else { - a[j] = i - } ## note: this loses the plural ports case, is it needed anyway? - if ( ports[i] != "" ) { - usePorts = ports[i] + if ( aPorts[i] != "" ) { + usePorts = aPorts[i] } - if ( drivers[i] != "" ) { - useDrivers = drivers[i] + if ( aDrivers[i] != "" ) { + useDrivers = aDrivers[i] } - if ( modules[i] != "" ) { - useModules = modules[i] + if ( aModules[i] != "" ) { + useModules = aModules[i] + } + if ( aNic[i] != "" ) { + useNic=aNic[i] } if ( aPciBusId[i] != "" ) { usePciBusId = aPciBusId[i] } # create array primary item for master array - # and strip out the counter again, this handled dual cards with same chipset - sub( /~~[0-9]+$/, "", a[j] ) sub( / $/, "", usePorts ) # clean off trailing whitespace - print a[j] "," useDrivers "," usePorts "," useModules, "," usePciBusId - j++ + print useNic "," useDrivers "," usePorts "," useModules, "," usePciBusId } }' ) ) IFS="$ORIGINAL_IFS" get_networking_usb_data if [[ $B_SHOW_ADVANCED_NETWORK == 'true' || $B_USB_NETWORKING == 'true' ]];then - get_network_advanced_data + if [[ -z $BSD_TYPE ]];then + get_network_advanced_data + fi fi - temp_array=${A_NETWORK_DATA[@]} - log_function_data "A_NETWORK_DATA: $temp_array" + a_temp=${A_NETWORK_DATA[@]} + log_function_data "A_NETWORK_DATA: $a_temp" eval $LOGFE } @@ -6051,42 +7429,59 @@ get_networking_data() get_network_advanced_data() { eval $LOGFS - local a_network_adv_working='' if_path='' working_path='' working_uevent_path='' dir_path='' - local if_id='' speed='' duplex='' mac_id='' oper_state='' chip_id='' - local usb_data='' usb_vendor='' usb_product='' product_path='' driver_test='' + local a_network_adv_working='' if_data='' working_path='' working_uevent_path='' dir_path='' + local if_id='' speed='' duplex='' mac_id='' oper_state='' chip_id='' b_path_made='true' + local usb_data='' usb_vendor='' usb_product='' product_path='' driver_test='' array_counter=0 + local full_path='' + # we need to change to holder since we are updating the main array + IFS=$'\n' + local a_main_working=(${A_NETWORK_DATA[@]}) + IFS="$ORIGINAL_IFS" - for (( i=0; i < ${#A_NETWORK_DATA[@]}; i++ )) + for (( i=0; i < ${#a_main_working[@]}; i++ )) do IFS="," - a_network_adv_working=( ${A_NETWORK_DATA[i]} ) + a_network_adv_working=( ${a_main_working[i]} ) + IFS="$ORIGINAL_IFS" # reset these every go round driver_test='' - if_id='' - speed='' - duplex='' - mac_id='' - oper_state='' + if_data='' + product_path='' usb_data='' - chip_id='' + usb_product='' + usb_vendor='' + working_path='' + working_uevent_path='' if [[ -z $( grep '^usb-' <<< ${a_network_adv_working[4]} ) ]];then # note although this may exist technically don't use it, it's a virtual path # and causes weird cat errors when there's a missing file as well as a virtual path # /sys/bus/pci/devices/0000:02:02.0/net/eth1 # real paths are: /sys/devices/pci0000:00/0000:00:1e/0/0000:02:02.0/net/eth1/uevent # and on older debian kernels: /sys/devices/pci0000:00/0000:02:02.0/net:eth1/uevent - # but broadcom shows this sometimes: + # but broadcom shows this sometimes, and older kernels maybe: + # /sys/devices/pci0000:00/0000:00:01.0/0000:05:00.0/net/eth0/ # /sys/devices/pci0000:00/0000:00:03.0/0000:03:00.0/ssb0:0/uevent:['DRIVER=b43', 'MODALIAS=ssb:v4243id0812rev0D']: - working_path="/sys/bus/pci/devices/0000:${a_network_adv_working[4]}" + # echo a ${a_network_adv_working[4]} + if [[ -d /sys/bus/pci/devices/ ]];then + working_path="/sys/bus/pci/devices/0000:${a_network_adv_working[4]}" + elif [[ -d /sys/devices/pci0000:00/ ]];then + working_path="/sys/devices/pci0000:00/0000:00:01.0/0000:${a_network_adv_working[4]}" + fi + #echo wp ${a_network_adv_working[4]} $i # now we want the real one, that xiin also displays, without symbolic links. - if [[ -e $working_path ]];then + if [[ -n $working_path && -e $working_path ]];then working_path=$( readlink -f $working_path 2>/dev/null ) - # sometimes there is another directory between the path and /net - if [[ ! -e $working_path/net ]];then - # using find here, probably will need to also use it in usb part since the grep - # method seems to not be working now. Slice off the rest, which leaves the basic path - working_path=$( find $working_path/*/net/*/uevent 2>/dev/null | \ - sed 's|/net.*||' ) - fi + else + working_path=$( find -P /sys/ -type d -name "*:${a_network_adv_working[4]}" 2>/dev/null ) + # just on off chance we get two returns, just one one + working_path=${working_path%% *} + fi + # sometimes there is another directory between the path and /net + if [[ -n $working_path && ! -e $working_path/net ]];then + # using find here, probably will need to also use it in usb part since the grep + # method seems to not be working now. Slice off the rest, which leaves the basic path + working_path=$( find $working_path/*/net/*/uevent 2>/dev/null | \ + sed 's|/net.*||' ) fi # working_path=$( ls /sys/devices/pci*/*/0000:${a_network_adv_working[4]}/net/*/uevent ) else @@ -6109,14 +7504,13 @@ get_network_advanced_data() product_path=$( grep -s "$usb_product" /sys/devices/pci*/*/usb*/*/*/idProduct | \ sed -e "s/idProduct:$usb_product//" -e '/driver/d' ) fi - # make sure it's the right product/vendor match here, it will almost always be but let's be sure if [[ -n $working_path && -n $product_path ]] && [[ $working_path == $product_path ]];then #if [[ -n $working_path ]];then # now ls that directory and get the numeric starting sub directory and that should be the full path # to the /net directory part - dir_path=$( ls ${working_path} 2>/dev/null | grep -sE '^[0-9]' ) - working_uevent_path="${working_path}${dir_path}" + dir_path=$( ls $working_path 2>/dev/null | grep -sE '^[0-9]' ) + working_uevent_path="$working_path$dir_path" fi fi # /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/uevent grep for DRIVER= @@ -6127,50 +7521,90 @@ get_network_advanced_data() a_network_adv_working[1]=$driver_test fi fi + #echo wp: $working_path log_function_data "PRE: working_path: $working_path\nworking_uevent_path: $working_uevent_path" - # this applies in two different cases, one, default, standard, two, for usb, this is actually # the short path, minus the last longer numeric directory name, ie: # from debian squeeze 2.6.32-5-686: # /sys/devices/pci0000:00/0000:00:0b.1/usb1/1-1/net/wlan0/address if [[ -e $working_path/net ]];then - if_path=$( ls $working_path/net 2>/dev/null ) - if_id=$if_path - working_path=$working_path/net/$if_path + # in cases like infiniband dual port devices, there can be two ids, like ib0 ib1, + # with line break in output + if_data=$( ls $working_path/net 2>/dev/null ) + b_path_made='false' # this is the normal usb detection if the first one didn't work elif [[ -n $usb_data && -e $working_uevent_path/net ]];then - if_path=$( ls $working_uevent_path/net 2>/dev/null ) - if_id=$if_path - working_path=$working_uevent_path/net/$if_path + if_data=$( ls $working_uevent_path/net 2>/dev/null ) + working_path=$working_uevent_path/net/$if_data # 2.6.32 debian lenny kernel shows not: /net/eth0 but /net:eth0 - else - if_path=$( ls $working_path 2>/dev/null | grep 'net:' ) - if_id=$( cut -d ':' -f 2 <<< "$if_path" ) - working_path=$working_path/$if_path - fi - log_function_data "POST: working_path: $working_path\nif_path: $if_path - if_id: $if_id" - - if [[ -n $if_path ]];then - if [[ -r $working_path/speed ]];then - speed=$( cat $working_path/speed 2>/dev/null ) - fi - if [[ -r $working_path/duplex ]];then - duplex=$( cat $working_path/duplex 2>/dev/null ) - fi - if [[ -r $working_path/address ]];then - mac_id=$( cat $working_path/address 2>/dev/null ) - fi - if [[ -r $working_path/operstate ]];then - oper_state=$( cat $working_path/operstate 2>/dev/null ) + elif [[ -n ${working_path/\/sys*/} ]];then + if_data=$( ls $working_path 2>/dev/null | grep 'net:' ) + if [[ -n $if_data ]];then + working_path=$working_path/$if_data + # we won't be using this for path any more, just the actual if id output + # so prep it for the loop below + if_data=$( cut -d ':' -f 2 <<< "$if_data" ) + fi + fi + # just in case we got a failed path, like /net or /, clear it out for tests below + if [[ -n ${working_path/\/sys*/} ]];then + working_path='' + fi + #echo id: $if_data + log_function_data "POST: working_path: $working_path\nif_data: $if_data - if_id: $if_id" + # there are virtual devices that will have no if data but which we still want in the array + # as it loops. These will also have null working_path as well since no **/net is found + # echo if_data: $if_data + if [[ -z $if_data ]];then + if_data='null-if-id' + fi + ## note: in cases of dual ports with different ids, this loop will create extra array items + for if_item in $if_data + do + chip_id= + duplex='' + full_path='' + if_id='' + mac_id='' + oper_state='' + speed='' + # strip out trailing spaces + if_item=${if_item%% } + #echo wp1: $working_path + if [[ $working_path != '' ]];then + if_id=$if_item + if [[ $b_path_made == 'false' ]];then + full_path=$working_path/net/$if_item + else + full_path=$working_path + fi + if [[ -r $full_path/speed ]];then + speed=$( cat $full_path/speed 2>/dev/null ) + fi + if [[ -r $full_path/duplex ]];then + duplex=$( cat $full_path/duplex 2>/dev/null ) + fi + if [[ -r $full_path/address ]];then + mac_id=$( cat $full_path/address 2>/dev/null ) + fi + if [[ -r $full_path/operstate ]];then + oper_state=$( cat $full_path/operstate 2>/dev/null ) + fi + if [[ -n ${a_network_adv_working[10]} ]];then + chip_id=${a_network_adv_working[10]} + fi fi - fi - - if [[ -n ${a_network_adv_working[10]} ]];then - chip_id=${a_network_adv_working[10]} - fi - 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","$chip_id - IFS="$ORIGINAL_IFS" + + #echo fp: $full_path + #echo id: $if_id + # echo "$if_data ii: $if_item $array_counter i: $i" + A_NETWORK_DATA[$array_counter]=${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","$chip_id + + ((array_counter++)) + done done + a_temp=${A_NETWORK_DATA[@]} + log_function_data "A_NETWORK_DATA (advanced): $a_temp" eval $LOGFE } @@ -6202,7 +7636,7 @@ get_networking_usb_data() } /'"$USB_NETWORK_SEARCH"'/ && !/bluetooth| hub|keyboard|mouse|printer| ps2|reader|scan|storage/ { string="" - gsub( /,/, " ", $0 ) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $0 ) gsub(/'"$BAN_LIST_NORMAL"'/, "", $0) gsub(/ [ \t]+/, " ", $0) #sub(/realtek semiconductor/, "Realtek", $0) @@ -6239,19 +7673,51 @@ get_networking_usb_data() get_networking_wan_ip_data() { eval $LOGFS - local ip='' - + local ip='' ip_data='' downloader_error=0 ua='' b_ipv4_good=true + # get ip using wget redirect to stdout. This is a clean, text only IP output url, # single line only, ending in the ip address. May have to modify this in the future # to handle ipv4 and ipv6 addresses but should not be necessary. # awk has bad regex handling so checking it with grep -E instead # ip=$( echo 2001:0db8:85a3:0000:0000:8a2e:0370:7334 | gawk --re-interval ' # ip=$( wget -q -O - $WAN_IP_URL | gawk --re-interval ' - ip=$( wget -t 1 -T $WGET_TIMEOUT -q -O - $WAN_IP_URL | gawk --re-interval ' - { - #gsub("\n","",$2") - print $NF - }' ) + # this generates a direct dns based ipv4 ip address, but if opendns.com goes down, the fall + # note: consistently slower than domain based: dig +short +time=1 +tries=1 myip.opendns.com. A @208.67.222.222 + # backs will still work. + if [[ -n $DNSTOOL ]];then + ip=$( dig +short +time=1 +tries=1 myip.opendns.com @resolver1.opendns.com 2>/dev/null) + fi + if [[ $ip == '' ]];then + case $DOWNLOADER in + curl) + if [[ -n $( grep 'smxi.org' <<< $WAN_IP_URL ) ]];then + ua="-A s-tools/inxi-ip" + fi + ip_data="$( curl $ua -y $DL_TIMEOUT -s $WAN_IP_URL )" || downloader_error=$? + ;; + fetch) + ip_data="$( fetch -T $DL_TIMEOUT -q -o - $WAN_IP_URL )" || downloader_error=$? + ;; + ftp) + ip_data="$( ftp -o - $WAN_IP_URL 2>/dev/null )" || downloader_error=$? + ;; + wget) + if [[ -n $( grep 'smxi.org' <<< $WAN_IP_URL ) ]];then + ua="-U s-tools/inxi-ip" + fi + ip_data="$( wget $ua -T $DL_TIMEOUT -q -O - $WAN_IP_URL )" || downloader_error=$? + ;; + no-downloader) + downloader_error=1 + ;; + esac + ip=$( gawk --re-interval ' + { + #gsub("\n","",$2") + print $NF + }' <<< "$ip_data" ) + fi + # validate the data if [[ -z $ip ]];then ip='None Detected!' @@ -6269,7 +7735,7 @@ get_networking_local_ip_data() eval $LOGFS local ip_tool_command=$( type -p ip ) - local temp_array='' ip_tool='ip' ip_tool_data='' + local a_temp='' ip_tool='ip' ip_tool_data='' # the chances for all new systems to have ip by default are far higher than # the deprecated ifconfig. Only try for ifconfig if ip is not present in system if [[ -z $ip_tool_command ]];then @@ -6289,7 +7755,7 @@ get_networking_local_ip_data() # of each IF record item. Also getting rid of the unneeded numeric line starters, now it can be parsed # like ifconfig more or less elif [[ $ip_tool == 'ip' ]];then - ip_tool_data="$( eval ${ip_tool_command} | sed 's/^[0-9]\+:[[:space:]]\+/\n/' )" + ip_tool_data="$( eval $ip_tool_command | sed 's/^[0-9]\+:[[:space:]]\+/\n/' )" fi fi if [[ -z $ip_tool_command ]];then @@ -6314,7 +7780,7 @@ get_networking_local_ip_data() /^[a-zA-Z]+[0-9]/ { # not clear on why inet is coming through, but this gets rid of it # as first line item. - gsub(/,/, " ", $0) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $0) gsub(/^ +| +$/, "", $0) gsub(/ [ \t]+/, " ", $0) interface = $1 @@ -6385,41 +7851,46 @@ get_networking_local_ip_data() else A_INTERFACES_DATA=( "Interfaces program $ip_tool present but created no data. " ) fi - temp_array=${A_INTERFACES_DATA[@]} - log_function_data "A_INTERFACES_DATA: $temp_array" + a_temp=${A_INTERFACES_DATA[@]} + log_function_data "A_INTERFACES_DATA: $a_temp" eval $LOGFE } # get_networking_local_ip_data;exit -# get_networking_local_ip_data;exit get_optical_drive_data() { eval $LOGFS - local temp_array='' sys_uevent_path='' proc_cdrom='' link_list='' - local separator='' linked='' disk='' item_string='' proc_info_string='' - local dev_disks_links="$( ls /dev/dvd* /dev/cd* /dev/scd* 2>/dev/null )" + local a_temp='' sys_uevent_path='' proc_cdrom='' link_list='' + local separator='' linked='' working_disk='' disk='' item_string='' proc_info_string='' + local dev_disks_full='' + dev_disks_full="$( ls /dev/dvd* /dev/cd* /dev/scd* /dev/sr* 2>/dev/null | grep -vE 'random' )" + ## Not using this now because newer kernel is NOT linking all optical drives. Some, but not all + # Some systems don't support xargs -L plus the unlinked optical drive unit make this not a good option # get the actual disk dev location, first try default which is easier to run, need to preserve line breaks - local dev_disks_real="$( echo "$dev_disks_links" | xargs -L 1 readlink 2>/dev/null | sort -u )" - # Some systems don't support xargs -L so we need to do it manually - if [[ -z $dev_disks_real ]];then - for linked in $dev_disks_links - do - disk=$( readlink $linked 2>/dev/null ) - if [[ -n $disk ]];then - disk=$( basename $disk ) # puppy shows this as /dev/sr0, not sr0 - if [[ -z $dev_disks_real || -z $( grep $disk <<< $dev_disks_real ) ]];then - # need line break IFS for below, no white space - dev_disks_real="$dev_disks_real$separator$disk" - separator=$'\n' - fi - fi - done - dev_disks_real="$( sort -u <<< "$dev_disks_real" )" - linked='' - disk='' - separator='' - fi + # local dev_disks_real="$( echo "$dev_disks_full" | xargs -L 1 readlink 2>/dev/null | sort -u )" + + #echo ddl: $dev_disks_full + for working_disk in $dev_disks_full + do + disk=$( readlink $working_disk 2>/dev/null ) + if [[ -z $disk ]];then + disk=$working_disk + fi + disk=${disk##*/} # puppy shows this as /dev/sr0, not sr0 + # if [[ -z $dev_disks_real || -z $( grep $disk <<< $dev_disks_real ) ]];then + if [[ -n $disk && -z $( grep "$disk" <<< $dev_disks_real ) ]];then + # need line break IFS for below, no white space + dev_disks_real="$dev_disks_real$separator$disk" + separator=$'\n' + #separator=' ' + fi + done + dev_disks_real="$( sort -u <<< "$dev_disks_real" )" + working_disk='' + disk='' + separator='' + #echo ddr: $dev_disks_real # A_OPTICAL_DRIVE_DATA indexes: not going to use all these, but it's just as easy to build the full # data array and use what we need from it as to update it later to add features or items @@ -6438,7 +7909,7 @@ get_optical_drive_data() # 12 - dvdr # 13 - dvdram # 14 - state - + if [[ -n $dev_disks_real ]];then if [[ $B_SHOW_FULL_OPTICAL == 'true' ]];then proc_cdrom="$( cat /proc/sys/dev/cdrom/info 2>/dev/null )" @@ -6447,10 +7918,10 @@ get_optical_drive_data() A_OPTICAL_DRIVE_DATA=( $( for disk in $dev_disks_real do - for linked in $dev_disks_links + for working_disk in $dev_disks_full do - if [[ -n $( readlink $linked | grep $disk ) ]];then - linked=$( basename $linked ) + if [[ -n $( readlink $working_disk | grep $disk ) ]];then + linked=${working_disk##*/} link_list="$link_list$separator$linked" separator='~' fi @@ -6465,9 +7936,15 @@ get_optical_drive_data() rev_number='' state="" sys_path='' + working_disk='' # this is only for new sd type paths in /sys, otherwise we'll use /proc/ide if [[ -z $( grep '^hd' <<< $disk ) ]];then - sys_path=$( ls /sys/devices/pci*/*/host*/target*/*/block/$disk/uevent 2>/dev/null | sed "s|/block/$disk/uevent||" ) + # maybe newer kernels use this, not enough data. + sys_path=$( ls /sys/devices/pci*/*/ata*/host*/target*/*/block/$disk/uevent 2>/dev/null | sed "s|/block/$disk/uevent||" ) + # maybe older kernels, this used to work (2014-03-16) + if [[ -z $sys_path ]];then + sys_path=$( ls /sys/devices/pci*/*/host*/target*/*/block/$disk/uevent 2>/dev/null | sed "s|/block/$disk/uevent||" ) + fi # no need to test for errors yet, probably other user systems will require some alternate paths though if [[ -n $sys_path ]];then vendor=$( cat $sys_path/vendor 2>/dev/null ) @@ -6486,7 +7963,7 @@ get_optical_drive_data() { gsub(/'"$BAN_LIST_NORMAL"'/, "", $0) sub(/TSSTcorp/, "TSST ", $0) # seen more than one of these weird ones - gsub(/,/, " ", $0) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $0) gsub(/^[[:space:]]*|[[:space:]]*$/, "", $0) gsub(/ [[:space:]]+/, " ", $0) print $0 @@ -6547,16 +8024,83 @@ get_optical_drive_data() END { print speed "," multisession "," mcn "," audio "," cdr "," cdrw "," dvd "," dvdr "," dvdram } - ' <<< "$proc_cdrom" ) - fi - item_string="$item_string,$vendor,$model,$rev_number,$proc_info_string,$state" - echo $item_string - done \ - ) ) + ' <<< "$proc_cdrom" ) + fi + item_string="$item_string,$vendor,$model,$rev_number,$proc_info_string,$state" + echo $item_string + done \ + ) ) + IFS="$ORIGINAL_IFS" + fi + a_temp=${A_OPTICAL_DRIVE_DATA[@]} + # echo "$a_temp" + log_function_data "A_OPTICAL_DRIVE_DATA: $a_temp" + eval $LOGFE +} +# get_optical_drive_data;exit + +get_optical_drive_data_bsd() +{ + eval $LOGFS + + local a_temp='' + + if [[ -n $Dmesg_Boot_Data ]];then + IFS=$'\n' + A_OPTICAL_DRIVE_DATA=( $( gawk -F ':' ' + BEGIN { + IGNORECASE=1 + } + # sde,3.9GB,STORE_N_GO,USB,C200431546D3CF49-0:0,0 + # sdd,250.1GB,ST3250824AS,,9ND08GKX,45 + $1 ~ /^(cd|dvd)[0-9]+/ { + diskId=gensub(/^((cd|dvd)[0-9]+)[^0-9].*/,"\\1",1,$1) + # note: /var/run/dmesg.boot may repeat items since it is not created + # fresh every boot, this way, only the last items will be used per disk id + if (aIds[diskId] == "" ) { + aIds[diskId]=diskId + } + aDisks[diskId, "id"] = diskId + if ( $NF ~ /<.*>/ ){ + gsub(/.*<|>.*/,"",$NF) + rev_number=gensub(/.*[^0-9\.]([0-9\.]+)$/,"\\1",1,$NF) + if (rev_number ~ /^[0-9\.]+$/) { + aDisks[diskId, "rev"] = rev_number + } + model=gensub(/(.*[^0-9\.])[0-9\.]+$/,"\\1",1,$NF) + sub(/[[:space:]]+$/,"",model) + aDisks[diskId, "model"] = model + } + if ( $NF ~ /serial number/ ){ + sub(/serial[[:space:]]+number[[:space:]]*/,"",$NF) + aDisks[diskId, "serial"] = $NF + } + if ( $NF ~ /[GM]B\/s/ ){ + speed=gensub(/^([0-9\.]+[[:space:]]*[GM]B\/s).*/,"\\1",1,$NF) + sub(/\.[0-9]+/,"",speed) + if ( speed ~ /^[0-9]+/ ) { + aDisks[diskId, "speed"] = speed + } + } + } + # "$link,dev-readlinks,$vendor,$model,$rev_number,$proc_info_string,$state" + # $proc_info_string: print speed "," multisession "," mcn "," audio "," cdr "," cdrw "," dvd "," dvdr "," dvdram + END { + # multi dimensional pseudo arrays are sorted at total random, not in order of + # creation, so force a sort of the aIds, which deletes the array index but preserves + # the sorted keys. + asort(aIds) + for ( key in aIds ) { + print aDisks[aIds[key], "id"] ",,," aDisks[aIds[key], "model"] "," aDisks[aIds[key], "rev"] "," aDisks[aIds[key], "speed"] ",,,,,,,," + } + }' <<< "$Dmesg_Boot_Data" ) ) IFS="$ORIGINAL_IFS" fi - temp_array=${A_OPTICAL_DRIVE_DATA[@]} - log_function_data "A_OPTICAL_DRIVE_DATA: $temp_array" + + a_temp=${A_OPTICAL_DRIVE_DATA[@]} + # echo ${a_temp[@]} + log_function_data "A_OPTICAL_DRIVE_DATA: $a_temp" + eval $LOGFE } @@ -6564,8 +8108,8 @@ get_partition_data() { eval $LOGFS - local a_partition_working='' dev_item='' temp_array='' dev_working_item='' - local swap_data='' df_string='' main_partition_data='' df_test='' fs_type='' + local a_partition_working='' dev_item='' a_temp='' dev_working_item='' + local swap_data='' df_string='' main_partition_data='' fs_type='' local mount_data='' dev_bsd_item='' #local excluded_file_types='--exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660' # df doesn't seem to work in script with variables like at the command line @@ -6576,14 +8120,13 @@ get_partition_data() --exclude-type=fdescfs --exclude-type=iso9660 --exclude-type=linprocfs --exclude-type=procfs --exclude-type=squashfs --exclude-type=sysfs --exclude-type=tmpfs --exclude-type=unionfs' else - swap_data="$( swapctl -l 2>/dev/null )" + swap_data="$( swapctl -l -k 2>/dev/null )" # default size is 512, -H only for size in human readable format # older bsds don't support -T, pain, so we'll use partial output there - df_test=$( df -H -T 2>/dev/null ) - if [[ -n $df_test ]];then - df_string='df -H -T' + if df -h -T &>/dev/null;then + df_string='df -h -T' else - df_string='df -H' + df_string='df -h' fi fi main_partition_data="$( eval $df_string )" @@ -6600,13 +8143,13 @@ get_partition_data() if [[ $( grep -cs '[[:space:]]/$' <<< "$main_partition_data" ) -gt 1 ]];then main_partition_data="$( grep -vs '^rootfs' <<< "$main_partition_data" )" fi + # echo "$main_partition_data" log_function_data 'raw' "main_partition_data_post_rootfs:\n$main_partition_data\n\nswap_data:\n$swap_data" IFS=$'\n' - # sample line: /dev/sda2 ext3 15G 8.9G 4.9G 65% /home # $NF = partition name; $(NF - 4) = partition size; $(NF - 3) = used, in gB; $(NF - 1) = percent used ## note: by subtracting from the last field number NF, we avoid a subtle issue with LVM df output, where if ## the first field is too long, it will occupy its own line, this way we are getting only the needed data - A_PARTITION_DATA=( $( echo "$main_partition_data" | gawk -v bsdType=$BSD_TYPE ' + A_PARTITION_DATA=( $( echo "$main_partition_data" | gawk -v bsdType="$BSD_TYPE" -v bsdVersion="$BSD_VERSION" ' BEGIN { IGNORECASE=1 fileSystem="" @@ -6616,9 +8159,10 @@ get_partition_data() # skipping these file systems because bsds do not support df --exclude-type= # note that using $1 to handle older bsd df, which do not support -T. This will not be reliable but we will see ( bsdType != "" ) { - # skip if non disk/partition, or if raid primary id, which will not have a / in it - if ( $1 ~ /^(aufs|devfs|devtmpfs|fdescfs|iso9660|linprocfs|procfs|squashfs|sysfs|tmpfs|type|unionfs)$/ || - $1 ~ /^([^\/]+)$/ ) { + # skip if non disk/partition, or if raid primary id, which will not have a / in it. + # Note: kfreebsd uses /sys, not sysfs, is this a bug or expected behavior? + if ( $1 ~ /^(aufs|devfs|devtmpfs|fdescfs|iso9660|linprocfs|procfs|squashfs|\/sys|sysfs|tmpfs|type|unionfs)$/ || + ( $1 ~ /^([^\/]+)$/ && $1 !~ /^ROOT/ ) ) { # note use next, not getline or it does not work right next } @@ -6653,7 +8197,13 @@ get_partition_data() else { fileSystem="" } - print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main," fileSystem "," devBase + # /dev/disk0s2 249G 24G 225G 10% 5926984 54912758 10% / + if ( bsdVersion == "darwin" && $(NF - 4) ~ /[0-9]+%/ ) { + print $NF "," $(NF - 7) "," $(NF - 6) "," $(NF - 4) ",main," fileSystem "," devBase + } + else { + print $NF "," $(NF - 4) "," $(NF - 3) "," $(NF - 1) ",main," fileSystem "," devBase + } } # skip all these, including the first, header line. Use the --exclude-type # to handle new filesystems types we do not want listed here @@ -6661,7 +8211,11 @@ get_partition_data() # this is to avoid file systems with spaces in their names, that will make # the test show the wrong data in each of the fields, if no x%, then do not use # using 3 cases, first default, standard, 2nd, 3rd, handles one and two spaces in name - if ( $(NF - 1) ~ /[0-9]+%/ ) { + if ( bsdVersion == "darwin" && $(NF - 4) ~ /[0-9]+%/ ) { + fileSystem="" + print $NF "," $(NF - 7) "," $(NF - 6) "," $(NF - 4) ",main," fileSystem "," devBase + } + else if ( $(NF - 1) ~ /[0-9]+%/ ) { # note, older df in bsd do not have file system column if ( NF == "7" ) { fileSystem=$(NF - 5) @@ -6693,7 +8247,6 @@ get_partition_data() print $(NF - 2) " " $(NF - 1) " " $NF "," $(NF - 6) "," $(NF - 5) "," $(NF - 3) ",secondary," fileSystem "," devBase } }' ) - # now add the swap partition data, don't want to show swap files, just partitions, # though this can include /dev/ramzswap0. Note: you can also use /proc/swaps for this # data, it's the same exact output as swapon -s @@ -6721,9 +8274,9 @@ get_partition_data() }' ) ) IFS="$ORIGINAL_IFS" - temp_array=${A_PARTITION_DATA[@]} - # echo $temp_array - log_function_data "1: A_PARTITION_DATA:\n$temp_array" + a_temp=${A_PARTITION_DATA[@]} + # echo $a_temp + log_function_data "1: A_PARTITION_DATA:\n$a_temp" # we'll use this for older systems where no filesystem type is shown in df if [[ $BSD_TYPE == 'bsd' ]];then @@ -6741,19 +8294,31 @@ get_partition_data() dev_item=${a_partition_working[6]} # reset each loop fs_type=${a_partition_working[5]} # older bsds have df minus -T so can't get fs type easily, try using mount instead - if [[ $BSD_TYPE == 'bsd' && -z $fs_type && -n $dev_item ]];then + if [[ $BSD_TYPE == 'bsd' ]] && [[ -z $fs_type && -n $dev_item ]];then dev_bsd_item=$( sed -e 's/non-dev-//' -e 's|/|\\/|g' <<< "$dev_item" ) - fs_type=$( gawk -F '(' ' + fs_type=$( gawk -v bsdVersion="$BSD_VERSION" -F '(' ' + BEGIN { + IGNORECASE=1 + fileSystem="" + } /'$dev_bsd_item'/ { - # slice out everything after / plus the first comma - sub( /,.*/, "", $2 ) - print $2 + if ( bsdVersion != "openbsd" ) { + # slice out everything after / plus the first comma + sub( /,.*/, "", $2 ) + fileSystem=$2 + } + else { + # for openbsd: /dev/wd0f on /usr type ffs (local, nodev) + gsub(/^.*type[[:space:]]+|[[:space:]]*$/, "", $1 ) + fileSystem=$1 + } + print fileSystem exit }' <<< "$mount_data" ) fi # note: for swap this will already be set if [[ -n $( grep -E '(by-uuid|by-label)' <<< $dev_item ) ]];then - dev_working_item=$( basename $dev_item ) + dev_working_item=${dev_item##*/} if [[ -n $DEV_DISK_UUID ]];then dev_item=$( echo "$DEV_DISK_UUID" | gawk ' $0 ~ /[ /t]'$dev_working_item'[ /t]/ { @@ -6783,9 +8348,9 @@ get_partition_data() IFS="$ORIGINAL_IFS" fi done - temp_array=${A_PARTITION_DATA[@]} - # echo $temp_array - log_function_data "2: A_PARTITION_DATA:\n$temp_array" + a_temp=${A_PARTITION_DATA[@]} + # echo $a_temp;exit + log_function_data "2: A_PARTITION_DATA:\n$a_temp" if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then get_partition_data_advanced fi @@ -6797,7 +8362,7 @@ get_partition_data_advanced() { eval $LOGFS local a_partition_working='' dev_partition_data='' - local dev_item='' dev_label='' dev_uuid='' temp_array='' + local dev_item='' dev_label='' dev_uuid='' a_temp='' local mount_point='' # set dev disk label/mapper/uuid data globals get_partition_dev_data 'label' @@ -6823,7 +8388,7 @@ get_partition_data_advanced() partTemp = "" } # trying to handle space in name -# gsub( /\\040/, " ", $0 ) +# gsub(/\\040/, " ", $0 ) /[ \t]'$mount_point'[ \t]/ && $1 != "rootfs" { # initialize the variables label = "" @@ -6846,7 +8411,7 @@ get_partition_data_advanced() # if this works, great, otherwise, just set this to null values partTemp="'$( readlink /dev/root 2>/dev/null )'" if ( partTemp != "" ) { - if ( partTemp ~ /[hsv]d[a-z][0-9]{1,2}/ ) { + if ( partTemp ~ /[hsv]d[a-z]+[0-9]{1,2}/ ) { partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, partTemp ) } else if ( partTemp ~ /by-uuid/ ) { @@ -6881,7 +8446,7 @@ get_partition_data_advanced() dev_item=$( get_dev_processed_item "${a_partition_working[6]}" ) # make sure not to slice off rest if it's a network mounted file system if [[ -n $dev_item && -z $( grep -E '(^//|:/)' <<< $dev_item ) ]];then - dev_item=$( basename $dev_item ) ## needed to avoid error in case name still has / in it + dev_item=${dev_item##*/} ## needed to avoid error in case name still has / in it fi dev_label=${a_partition_working[7]} dev_uuid=${a_partition_working[8]} @@ -6900,7 +8465,7 @@ get_partition_data_advanced() elif [[ -n $DEV_DISK_LABEL && -n $dev_label ]];then dev_item=$( echo "$DEV_DISK_LABEL" | gawk ' # first we need to change space x20 in by-label back to a real space - #gsub( /x20/, " ", $0 ) + #gsub(/x20/, " ", $0 ) # then we can see if the string is there $0 ~ /[ \t]'$dev_label'[ \t]/ { item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF ) @@ -6939,9 +8504,9 @@ get_partition_data_advanced() get_partition_data_advanced_bsd fi fi - temp_array=${A_PARTITION_DATA[@]} - # echo $temp_array - log_function_data "3-advanced: A_PARTITION_DATA:\n$temp_array" + a_temp=${A_PARTITION_DATA[@]} + # echo $a_temp + log_function_data "3-advanced: A_PARTITION_DATA:\n$a_temp" eval $LOGFE } @@ -6958,7 +8523,7 @@ get_partition_data_advanced_bsd() a_partition_working=( ${A_PARTITION_DATA[i]} ) IFS="$ORIGINAL_IFS" # no need to use the rest of the name if it's not a straight /dev/item - dev_item=$( basename ${a_partition_working[6]} ) + dev_item=${a_partition_working[6]##*/} label_uuid=$( gawk -F ':' ' BEGIN { @@ -7055,7 +8620,7 @@ get_dev_processed_item() if [[ -n $DEV_DISK_MAPPER && -n $( grep -is 'mapper/' <<< $dev_item ) ]];then dev_return=$( echo "$DEV_DISK_MAPPER" | gawk ' - $( NF - 2 ) ~ /^'$( basename $dev_item )'$/ { + $( NF - 2 ) ~ /^'${dev_item##*/}'$/ { item=gensub( /..\/(.+)/, "\\1", 1, $NF ) print item }' ) @@ -7087,7 +8652,7 @@ get_pciconf_data() { eval $LOGFS - local pciconf_data='' temp_array='' + local pciconf_data='' a_temp='' if [[ $B_PCICONF == 'true' ]];then pciconf_data="$( pciconf -lv 2>/dev/null )" @@ -7138,13 +8703,13 @@ EOF" sub(/:$/, "", pciId) itemData=$4 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 ) - if ( $2 == "class=020000" ) { + if ( $2 ~ /class=020000/ ) { class="network" } else if ( $2 == "class=030000" ) { class="display" } - else if ( $2 == "class=040300" ) { + else if ( $2 ~ /class=040300|class=040100/ ) { class="audio" } @@ -7165,10 +8730,8 @@ EOF" if ( device == "" ) { device=vendor } - fullLine=class "," device "," vendor "," driver "," pciId "," chipId print fullLine - }' <<< "$pciconf_data" )) IFS="$ORIGINAL_IFS" fi @@ -7176,8 +8739,8 @@ EOF" A_PCICONF_DATA='pciconf-not-installed' fi B_PCICONF_SET='true' - temp_array=${A_PCICONF_DATA[@]} - log_function_data "$temp_array" + a_temp=${A_PCICONF_DATA[@]} + log_function_data "$a_temp" log_function_data "$pciconf_data" eval $LOGFE } @@ -7289,7 +8852,7 @@ get_ps_tcm_data() esac # throttle potential irc abuse - if [[ $B_RUNNING_IN_SHELL != 'true' && $PS_COUNT -gt 5 ]];then + if [[ $B_IRC == 'true' && $PS_COUNT -gt 5 ]];then PS_THROTTLED=$PS_COUNT PS_COUNT=5 fi @@ -7421,7 +8984,7 @@ get_raid_data() uData = "" while ( !/^[[:space:]]*$/ ) { - gsub(/,/, " ", $0 ) + gsub(/'"$BAN_LIST_ARRAY"'/, " ", $0 ) gsub(/[[:space:]]+/, " ", $0 ) if ( $0 ~ /^md/ ) { device = gensub(/(md.*)[[:space:]]?:/, "\\1", "1", $1 ) @@ -7497,9 +9060,9 @@ get_raid_data() fi fi B_RAID_SET='true' - temp_array=${A_RAID_DATA[@]} - log_function_data "A_RAID_DATA: $temp_array" -# echo -e "A_RAID_DATA:\n${temp_array}" + a_temp=${A_RAID_DATA[@]} + log_function_data "A_RAID_DATA: $a_temp" +# echo -e "A_RAID_DATA:\n${a_temp}" eval $LOGFE } @@ -7508,18 +9071,26 @@ get_raid_data_bsd() { eval $LOGFS local zpool_path=$( type -p zpool 2>/dev/null ) - local zpool_data='' + local zpool_data='' zpool_arg='v' if [[ -n $zpool_path ]];then B_BSD_RAID='true' # bsd sed does not support inserting a true \n so use this trick - zpool_data="$( $zpool_path list -v | sed $SED_RX 's/^([^[:space:]])/\ + # some zfs does not have -v + if $zpool_path list -v &>/dev/null;then + zpool_data="$( $zpool_path list -v 2>/dev/null | sed $SED_RX 's/^([^[:space:]])/\ +\1/' )" + else + zpool_data="$( $zpool_path list 2>/dev/null | sed $SED_RX 's/^([^[:space:]])/\ \1/' )" + zpool_arg='no-v' + fi # echo "$zpool_data" IFS=$'\n' A_RAID_DATA=( $( gawk ' BEGIN { + IGNORECASE=1 raidString="" separator="" components="" @@ -7530,6 +9101,7 @@ get_raid_data_bsd() /SIZE.*ALLOC/ { sub(/.*ALLOC.*/,"", $0) } + # gptid/d874c7e7-3f6d-11e4-b7dc-080027ea466c /^[^[:space:]]/ { components="" separator="" @@ -7540,18 +9112,30 @@ get_raid_data_bsd() blocksAvailable=$4 chunkRaidAllocated=$3 - # go to the next line now, this will probably need fixing later with weird data sets getline + # raid level is the second item in the output, unless it is not, sometimes it is absent if ( $1 != "" ) { - raidLevel="zfs " $1 + if ( $1 ~ /raid|mirror/ ) { + raidLevel="zfs " $1 + } + else { + raidLevel="zfs-no-raid" + components = $1 + separator=" " + } } while ( getline && $1 !~ /^$/ ) { + # https://blogs.oracle.com/eschrock/entry/zfs_hot_spares + if ($1 ~ /spares/) { + getline + } # print $1 components = components separator $1 separator=" " } - + # some issues if we use ~ here + gsub(/\//,"%",components) # print $1 raidString = device "," deviceState "," raidLevel "," components "," reportSize "," uData raidString = raidString "," blocksAvailable "," superBlock "," algorithm "," chunkRaidAllocated @@ -7562,12 +9146,14 @@ get_raid_data_bsd() print raidString }' <<< "$zpool_data" ) ) IFS="$ORIGINAL_IFS" - get_raid_component_data_bsd + # pass the zpool type, so we know how to get the components + get_raid_component_data_bsd "$zpool_arg" fi eval $LOGFE } # note, we've already tested for zpool so no further tests required +# args: $1 - zpool type, v will have a single row output, no-v has stacked for components get_raid_component_data_bsd() { eval $LOGFS @@ -7587,24 +9173,68 @@ get_raid_component_data_bsd() zpool_status="$( zpool status $device )" # we will remove ONLINE for status and only use OFFLINE/DEGRADED as tests # for print output display of issues with components - for component in ${a_raid_data[3]} - do - component_status=$( gawk ' + # note: different zfs outputs vary, some have the components listed by line + if [[ $1 == 'v' ]];then + for component in ${a_raid_data[3]} + do + component_status=$( gawk ' + BEGIN { + IGNORECASE=1 + separator="" + } + { + gsub(/\//,"%",$1) + } + $1 ~ /^'$component'$/ { + sub( /ONLINE/, "", $2 ) + print "'$component'" $2 + exit + }' <<< "$zpool_status" ) + component_string="$component_string$separator$component_status" + separator=' ' + done + array_string="$device,${a_raid_data[1]},${a_raid_data[2]},${component_string//%/\/},${a_raid_data[4]}" + array_string="$array_string,${a_raid_data[5]},${a_raid_data[6]},${a_raid_data[7]},${a_raid_data[8]}" + array_string="$array_string,${a_raid_data[9]},${a_raid_data[10]},${a_raid_data[11]},${a_raid_data[12]}," + array_string="$array_string${a_raid_data[13]},${a_raid_data[14]},${a_raid_data[15]}" + else + component_string=$( gawk ' BEGIN { IGNORECASE=1 - } - $1 ~ /^'$component'$/ { - sub( /ONLINE/, "", $2 ) - print "'$component'" $2 - exit + separator="" + components="" + raidLevel="" + } + $1 ~ /^'$device'$/ { + while ( getline && !/^$/ ) { + # raid level is the second item in the output, unless it is not, sometimes it is absent + if ( $1 != "" ) { + if ( raidLevel == "" ) { + if ( $1 ~ /raid|mirror/ ) { + raidLevel="zfs " $1 + getline + } + else { + raidLevel="zfs-no-raid" + } + } + } + # https://blogs.oracle.com/eschrock/entry/zfs_hot_spares + if ($1 ~ /spares/) { + getline + } + sub( /ONLINE/, "", $2 ) + components=components separator $1 separator $2 + separator=" " + } + print raidLevel "," components }' <<< "$zpool_status" ) - component_string="$component_string$separator$component_status" - separator=' ' - done - array_string="$device,${a_raid_data[1]},${a_raid_data[2]},$component_string,${a_raid_data[4]}" - array_string="$array_string,${a_raid_data[5]},${a_raid_data[6]},${a_raid_data[7]},${a_raid_data[8]}" - array_string="$array_string,${a_raid_data[9]},${a_raid_data[10]},${a_raid_data[11]},${a_raid_data[12]}," - array_string="$array_string${a_raid_data[13]},${a_raid_data[14]},${a_raid_data[15]}" + # note: component_string is raid type AND components + array_string="$device,${a_raid_data[1]},$component_string,${a_raid_data[4]}" + array_string="$array_string,${a_raid_data[5]},${a_raid_data[6]},${a_raid_data[7]},${a_raid_data[8]}" + array_string="$array_string,${a_raid_data[9]},${a_raid_data[10]},${a_raid_data[11]},${a_raid_data[12]}," + array_string="$array_string${a_raid_data[13]},${a_raid_data[14]},${a_raid_data[15]}" + fi IFS="," A_RAID_DATA[i]=$array_string IFS="$ORIGINAL_IFS" @@ -7614,11 +9244,540 @@ get_raid_component_data_bsd() } # get_raid_data_bsd;exit +get_ram_data() +{ + eval $LOGFS + + local a_temp='' array_string='' + + get_dmidecode_data + + if [[ -n $DMIDECODE_DATA ]];then + if [[ $DMIDECODE_DATA == 'dmidecode-error-'* ]];then + A_MEMORY_DATA[0]=$DMIDECODE_DATA + # please note: only dmidecode version 2.11 or newer supports consistently the -s flag + else + IFS=$'\n' + A_MEMORY_DATA=( $( + gawk -F ':' ' + BEGIN { + IGNORECASE=1 + arrayHandle="" + bankLocator="" + clockSpeed="" + configuredClockSpeed="" + dataWidth="" + deviceManufacturer="" + devicePartNumber="" + deviceSerialNumber="" + deviceSpeed="" + deviceType="" + deviceTypeDetail="" + deviceSize="" + errorCorrection="" + formFactor="" + handle="" + location="" + locator="" + aArrayData[0,"maxCapacity5"]=0 + aArrayData[0,"maxCapacity16"]=0 + aArrayData[0,"usedCapacity"]=0 + aArrayData[0,"maxModuleSize"]=0 + aArrayData[0,"derivedModuleSize"]=0 + aArrayData[0,"deviceCount5"]=0 + aArrayData[0,"deviceCount16"]=0 + aArrayData[0,"deviceCountFound"]=0 + aArrayData[0,"moduleVoltage5"]="" + moduleVoltage="" + numberOfDevices="" + primaryType="" + totalWidth="" + use="" + i=0 + j=0 + k=0 + bDebugger1="false" + dDebugger2="false" + bType5="false" + } + function calculateSize(data,size) { + if ( data ~ /^[0-9]+[[:space:]]*[GMTP]B/) { + if ( data ~ /GB/ ) { + data=gensub(/([0-9]+)[[:space:]]*GB/,"\\1",1,data) * 1024 + } + else if ( data ~ /MB/ ) { + data=gensub(/([0-9]+)[[:space:]]*MB/,"\\1",1,data) + } + else if ( data ~ /TB/ ) { + data=gensub(/([0-9]+)[[:space:]]*TB/,"\\1",1,data) * 1024 * 1000 + } + else if ( data ~ /PB/ ) { + data=gensub(/([0-9]+)[[:space:]]*TB/,"\\1",1,data) * 1024 * 1000 * 1000 + } + if (data ~ /^[0-9][0-9]+$/ && data > size ) { + size=data + } + } + return size + } + /^Table[[:space:]]+at[[:space:]]/ { + bType5="false" + # we need to start count here because for testing > 1 array, and we want always to have + # the actual module data assigned to the right primary array, even when it is out of + # position in dmidecode output + i=0 + j=0 + k++ + } + # {print k ":k:" $0} + /^Handle .* DMI[[:space:]]+type[[:space:]]+5(,|[[:space:]])/ { + while ( getline && !/^$/ ) { + if ( $1 == "Maximum Memory Module Size" ) { + aArrayData[k,"maxModuleSize"]=calculateSize($2,aArrayData[k,"maxModuleSize"]) + # print "mms:" aArrayData[k,"maxModuleSize"] ":" $2 + } + if ($1 == "Maximum Total Memory Size") { + aArrayData[k,"maxCapacity5"]=calculateSize($2,aArrayData[k,"maxCapacity5"]) + } + if ( $1 == "Memory Module Voltage" ) { + aArrayData[k,"moduleVoltage5"]=$2 + } + } + aArrayData[k,"data-type"]="memory-array" + # print k ":data5:"aArrayData[k,"data-type"] + bType5="true" + } + /^Handle .* DMI[[:space:]]+type[[:space:]]+6(,|[[:space:]])/ { + while ( getline && !/^$/ ) { + if ( $1 == "Installed Size" ) { + # get module size + aMemory[k,j,18]=calculateSize($2,0) + # get data after module size + sub(/ Connection/,"",$2) + sub(/^[0-9]+[[:space:]]*[MGTP]B[[:space:]]*/,"",$2) + aMemory[k,j,16]=$2 + } + if ( $1 == "Current Speed" ) { + aMemory[k,j,17]=$2 + } + } + j++ + } + + /^Handle .* DMI[[:space:]]+type[[:space:]]+16/ { + arrayHandle=gensub(/Handle[[:space:]]([0-9a-zA-Z]+)([[:space:]]|,).*/,"\\1",$0) + while ( getline && !/^$/ ) { + # print $0 + if ( $1 == "Maximum Capacity") { + aArrayData[k,"maxCapacity16"]=calculateSize($2,aArrayData[k,"maxCapacity16"]) + #print "mc:" aArrayData[k,"maxCapacity16"] ":" $2 + } + # note: these 3 have cleaned data in get_dmidecode_data, so replace stuff manually + if ( $1 == "Location") { + sub(/[[:space:]]Or[[:space:]]Motherboard/,"",$2) + location=$2 + if ( location == "" ){ + location="System Board" + } + } + if ( $1 == "Use") { + use=$2 + if ( use == "" ){ + use="System Memory" + } + } + if ( $1 == "Error Correction Type") { + errorCorrection=$2 + if ( errorCorrection == "" ){ + errorCorrection="None" + } + } + if ( $1 == "Number of Devices") { + numberOfDevices=$2 + } + } + aArrayData[k,"data-type"]="memory-array" + # print k ":data16:"aArrayData[k,"data-type"] + aArrayData[k,"handle"]=arrayHandle + aArrayData[k,"location"]=location + aArrayData[k,"deviceCount16"]=numberOfDevices + aArrayData[k,"use"]=use + aArrayData[k,"errorCorrection"]=errorCorrection + + # reset + primaryType="" + arrayHandle="" + location="" + numberOfDevices="" + use="" + errorCorrection="" + moduleVoltage="" + + aDerivedModuleSize[k+1]=0 + aArrayData[k+1,"deviceCountFound"]=0 + aArrayData[k+1,"maxCapacity5"]=0 + aArrayData[k+1,"maxCapacity16"]=0 + aArrayData[k+1,"maxModuleSize"]=0 + } + /^Handle .* DMI[[:space:]]+type[[:space:]]+17/ { + while ( getline && !/^$/ ) { + if ( $1 == "Array Handle") { + arrayHandle=$2 + } + if ( $1 == "Data Width") { + dataWidth=$2 + } + if ( $1 == "Total Width") { + totalWidth=$2 + } + if ( $1 == "Size") { + # do not try to guess from installed modules, only use this to correct type 5 data + aArrayData[k,"derivedModuleSize"]=calculateSize($2,aArrayData[k,"derivedModuleSize"]) + workingSize=calculateSize($2,0) + if ( workingSize ~ /^[0-9][0-9]+$/ ){ + aArrayData[k,"deviceCountFound"]++ + # build up actual capacity found for override tests + aArrayData[k,"usedCapacity"]=workingSize + aArrayData[k,"usedCapacity"] + } + # print aArrayData[k,"derivedModuleSize"] " dm:" k ":mm " aMaxModuleSize[k] " uc:" aArrayData[k,"usedCapacity"] + # we want any non real size data to be preserved + if ( $2 ~ /^[0-9]+[[:space:]]*[MTPG]B/ ) { + deviceSize=workingSize + } + else { + deviceSize=$2 + } + } + if ( $1 == "Locator") { + # sub(/.*_/,"",$2) + #sub(/RAM slot #|^DIMM/, "Slot",$2) + sub(/RAM slot #/, "Slot",$2) + + #locator=toupper($2) + locator=$2 + } + if ( $1 == "Bank Locator") { + #sub(/_.*/,"",$2) + #sub(/RAM slot #|Channel|Chan/,"bank",$2) + #sub(/RAM slot #|Channel|Chan/,"bank",$2) + #bankLocator=toupper($2) + bankLocator=$2 + } + if ( $1 == "Form Factor") { + formFactor=$2 + } + if ( $1 == "Type") { + deviceType=$2 + } + if ( $1 == "Type Detail") { + deviceTypeDetail=$2 + } + if ( $1 == "Speed") { + deviceSpeed=$2 + } + if ( $1 == "Configured Clock Speed") { + configuredClockSpeed=$2 + } + if ( $1 == "Manufacturer") { + gsub(/(^[0]+$|Undefined.*|.*Manufacturer.*)/,"",$2) + deviceManufacturer=$2 + } + if ( $1 == "Part Number") { + sub(/(^[0]+$||.*Module.*|Undefined.*)/,"",$2) + devicePartNumber=$2 + } + if ( $1 == "Serial Number") { + gsub(/(^[0]+$|Undefined.*)/,"",$2) + deviceSerialNumber=$2 + } + } + # because of the wide range of bank/slot type data, we will just use + # the one that seems most likely to be right. Some have: Bank: SO DIMM 0 slot: J6A + # so we dump the useless data and use the one most likely to be visibly correct + if ( bankLocator ~ /DIMM/ ) { + mainLocator=bankLocator + } + else { + mainLocator=locator + } + # sometimes the data is just wrong, they reverse total/data. data I believe is + # used for the actual memory bus width, total is some synthetic thing, sometimes missing. + # note that we do not want a regular string comparison, because 128 bit memory buses are + # in our future, and 128 bits < 64 bits with string compare + intData=gensub(/(^[0-9]+).*/,"\\1",1,dataWidth) + intTotal=gensub(/(^[0-9]+).*/,"\\1",1,totalWidth) + if (intData != "" && intTotal != "" && intData > intTotal ) { + tempWidth=dataWidth + dataWidth=totalWidth + totalWidth=tempWidth + } + + aMemory[k,i,0]="memory-device" + aMemory[k,i,1]=arrayHandle + aMemory[k,i,2]=deviceSize + aMemory[k,i,3]=bankLocator + aMemory[k,i,4]=locator + aMemory[k,i,5]=formFactor + aMemory[k,i,6]=deviceType + aMemory[k,i,7]=deviceTypeDetail + aMemory[k,i,8]=deviceSpeed + aMemory[k,i,9]=configuredClockSpeed + aMemory[k,i,10]=dataWidth + aMemory[k,i,11]=totalWidth + aMemory[k,i,12]=deviceManufacturer + aMemory[k,i,13]=devicePartNumber + aMemory[k,i,14]=deviceSerialNumber + aMemory[k,i,15]=mainLocator + + primaryType="" + arrayHandle="" + deviceSize="" + bankLocator="" + locator="" + mainLocator="" + mainLocator="" + formFactor="" + deviceType="" + deviceTypeDetail="" + deviceSpeed="" + configuredClockSpeed="" + dataWidth="" + totalWidth="" + deviceManufacturer="" + devicePartNumber="" + deviceSerialNumber="" + i++ + } + END { + ## CRITICAL: gawk keeps changing integers to strings, so be explicit with int() in math + # print primaryType "," arrayHandle "," location "," maxCapacity "," numberOfDevices "," use "," errorCorrection "," maxModuleSize "," moduleVoltage + + # print primaryType "," arrayHandle "," deviceSize "," bankLocator "," locator "," formFactor "," deviceType "," deviceTypeDetail "," deviceSpeed "," configuredClockSpeed "," dataWidth "," totalWidth "," deviceManufacturer "," devicePartNumber "," deviceSerialNumber "," mainLocator + + for ( m=1;m<=k;m++ ) { + estCap="" + estMod="" + unit="" + altCap=0 + workingMaxCap=int(aArrayData[m,"maxCapacity16"]) + + if ( bDebugger1 == "true" ){ + print "" + print "count: " m + print "1: mmods: " aArrayData[m,"maxModuleSize"] " :dmmods: " aArrayData[m,"derivedModuleSize"] " :mcap: " workingMaxCap " :ucap: " aArrayData[m,"usedCapacity"] + } + # 1: if max cap 1 is null, and max cap 2 not null, use 2 + if ( workingMaxCap == 0 ) { + if ( aArrayData[m,"maxCapacity5"] != 0 ) { + workingMaxCap=aArrayData[m,"maxCapacity5"] + } + } + if ( aArrayData[m,"deviceCount16"] == "" ) { + aArrayData[m,"deviceCount16"] = 0 + } + if ( bDebugger1 == "true" ){ + print "2: mmods: " aArrayData[m,"maxModuleSize"] " :dmmods: " aArrayData[m,"derivedModuleSize"] " :mcap: " workingMaxCap " :ucap: " aArrayData[m,"usedCapacity"] + } + # 2: now check to see if actually found module sizes are > than listed max module, replace if > + if (aArrayData[m,"maxModuleSize"] != 0 && aArrayData[m,"derivedModuleSize"] != 0 && int(aArrayData[m,"derivedModuleSize"]) > int(aArrayData[m,"maxModuleSize"]) ) { + aArrayData[m,"maxModuleSize"]=aArrayData[m,"derivedModuleSize"] + estMod=" (est)" + } + aArrayData[m,"maxModuleSize"]=int(aArrayData[m,"maxModuleSize"]) + aArrayData[m,"derivedModuleSize"]=int(aArrayData[m,"derivedModuleSize"]) + aArrayData[m,"usedCapacity"]=int(aArrayData[m,"usedCapacity"]) + workingMaxCap=int(workingMaxCap) + + # note: some cases memory capacity == max module size, so one stick will fill it + # but I think only with cases of 2 slots does this happen, so if > 2, use the count of slots. + if ( bDebugger1 == "true" ){ + print "3: fmod: " aArrayData[m,"deviceCountFound"] " :modc: " aArrayData[m,"deviceCount16"] " :maxc1: " aArrayData[m,"maxCapacity5"] " :maxc2: " aArrayData[m,"maxCapacity16"] + } + if (workingMaxCap != 0 && ( aArrayData[m,"deviceCountFound"] != 0 || aArrayData[m,"deviceCount16"] != 0 ) ) { + aArrayData[m,"deviceCount16"]=int(aArrayData[m,"deviceCount16"]) + ## first check that actual memory found is not greater than listed max cap, or + ## checking to see module count * max mod size is not > used capacity + if ( aArrayData[m,"usedCapacity"] != 0 && aArrayData[m,"maxCapacity16"] != 0 ) { + if ( aArrayData[m,"usedCapacity"] > workingMaxCap ) { + if ( aArrayData[m,"maxModuleSize"] != 0 && + aArrayData[m,"usedCapacity"] < aArrayData[m,"deviceCount16"] * aArrayData[m,"maxModuleSize"] ) { + workingMaxCap=aArrayData[m,"deviceCount16"] * aArrayData[m,"maxModuleSize"] + estCap=" (est)" + if ( bDebugger1 == "true" ){ + print "A" + } + } + else if ( aArrayData[m,"derivedModuleSize"] != 0 && + aArrayData[m,"usedCapacity"] < aArrayData[m,"deviceCount16"] * aArrayData[m,"derivedModuleSize"] ) { + workingMaxCap=aArrayData[m,"deviceCount16"] * aArrayData[m,"derivedModuleSize"] + estCap=" (est)" + if ( bDebugger1 == "true" ){ + print "B" + } + } + else { + workingMaxCap=aArrayData[m,"usedCapacity"] + estCap=" (est)" + if ( bDebugger1 == "true" ){ + print "C" + } + } + } + } + # note that second case will never really activate except on virtual machines and maybe + # mobile devices + if ( estCap == "" ) { + # do not do this for only single modules found, max mod size can be equal to the array size + if ( ( aArrayData[m,"deviceCount16"] > 1 && aArrayData[m,"deviceCountFound"] > 1 ) && + ( workingMaxCap < aArrayData[m,"derivedModuleSize"] * aArrayData[m,"deviceCount16"] ) ) { + workingMaxCap = aArrayData[m,"derivedModuleSize"] * aArrayData[m,"deviceCount16"] + estCap=" (est)" + if ( bDebugger1 == "true" ){ + print "D" + } + } + else if ( ( aArrayData[m,"deviceCountFound"] > 0 ) && + ( workingMaxCap < aArrayData[m,"derivedModuleSize"] * aArrayData[m,"deviceCountFound"] ) ) { + workingMaxCap = aArrayData[m,"derivedModuleSize"] * aArrayData[m,"deviceCountFound"] + estCap=" (est)" + if ( bDebugger1 == "true" ){ + print "E" + } + } + ## handle cases where we have type 5 data: mms x device count equals type 5 max cap + # however do not use it if cap / devices equals the derived module size + else if ( aArrayData[m,"maxModuleSize"] > 0 && + ( aArrayData[m,"maxModuleSize"] * aArrayData[m,"deviceCount16"] == aArrayData[m,"maxCapacity5"] ) && + aArrayData[m,"maxCapacity5"] != aArrayData[m,"maxCapacity16"] && + aArrayData[m,"maxCapacity16"] / aArrayData[m,"deviceCount16"] != aArrayData[m,"derivedModuleSize"] ) { + workingMaxCap = aArrayData[m,"maxCapacity5"] + altCap=aArrayData[m,"maxCapacity5"] # not used + estCap=" (check)" + if ( bDebugger1 == "true" ){ + print "F" + } + } + } + } + altCap=int(altCap) + workingMaxCap=int(workingMaxCap) + if ( bDebugger1 == "true" ){ + print "4: mmods: " aArrayData[m,"maxModuleSize"] " :dmmods: " aArrayData[m,"derivedModuleSize"] " :mcap: " workingMaxCap " :ucap: " aArrayData[m,"usedCapacity"] + } + # some cases of type 5 have too big module max size, just dump the data then since + # we cannot know if it is valid or not, and a guess can be wrong easily + if ( aArrayData[m,"maxModuleSize"] != 0 && workingMaxCap != "" && + ( aArrayData[m,"maxModuleSize"] > workingMaxCap ) ){ + aArrayData[m,"maxModuleSize"] = 0 + # print "yes" + } + if ( bDebugger1 == "true" ){ + print "5: dms: " aArrayData[m,"derivedModuleSize"] " :dc: " aArrayData[m,"deviceCount16"] " :wmc: " workingMaxCap + } + ## prep for output ## + if (aArrayData[m,"maxModuleSize"] == 0 ){ + aArrayData[m,"maxModuleSize"]="" + # ie: 2x4gB + if ( estCap == "" && int(aArrayData[m,"derivedModuleSize"]) > 0 && + workingMaxCap > ( int(aArrayData[m,"derivedModuleSize"]) * int(aArrayData[m,"deviceCount16"]) * 4 ) ) { + estCap=" (check)" + if ( bDebugger1 == "true" ){ + print "G" + } + } + } + else { + # case where listed max cap is too big for actual slots x max cap, eg: + # listed max cap, 8gb, max mod 2gb, slots 2 + if ( estCap == "" && aArrayData[m,"maxModuleSize"] > 0 ) { + if ( int(workingMaxCap) > int(aArrayData[m,"maxModuleSize"]) * aArrayData[m,"deviceCount16"] ) { + estCap=" (check)" + if ( bDebugger1 == "true" ){ + print "H" + } + } + } + if (aArrayData[m,"maxModuleSize"] > 1023 ) { + aArrayData[m,"maxModuleSize"]=aArrayData[m,"maxModuleSize"] / 1024 " GB" + } + else { + aArrayData[m,"maxModuleSize"]=aArrayData[m,"maxModuleSize"] " MB" + } + } + if ( aArrayData[m,"deviceCount16"] == 0 ) { + aArrayData[m,"deviceCount16"] = "" + } + if (workingMaxCap != 0 ) { + if ( workingMaxCap < 1024 ) { + workingMaxCap = workingMaxCap + unit=" MB" + } + else if ( workingMaxCap < 1024000 ) { + workingMaxCap = workingMaxCap / 1024 + unit=" GB" + } + else if ( workingMaxCap < 1024000000 ) { + workingMaxCap = workingMaxCap / 1024000 + unit=" TB" + } + # we only want a max 2 decimal places, this trick gives 0 to 2 + workingMaxCap=gensub(/([0-9]+\.[0-9][0-9]).*/,"\\1",1,workingMaxCap) + workingMaxCap = workingMaxCap unit estCap + + } + else { + workingMaxCap == "" + } + + print aArrayData[m,"data-type"] "," aArrayData[m,"handle"] "," aArrayData[m,"location"] "," workingMaxCap "," aArrayData[m,"deviceCount16"] "," aArrayData[m,"use"] "," aArrayData[m,"errorCorrection"] "," aArrayData[m,"maxModuleSize"] estMod "," aArrayData[m,"voltage5"] + # print device rows next + for ( j=0;j<=100;j++ ) { + if (aMemory[m,j,0] != "" ) { + unit="" + workingSize=aMemory[m,j,2] + if ( workingSize ~ /^[0-9]+$/ ) { + workingSize=int(workingSize) + if ( workingSize < 1024 ) { + workingSize = workingSize + unit=" MB" + } + else if ( workingSize < 1024000 ) { + workingSize = workingSize / 1024 + unit=" GB" + } + else if ( workingSize < 1024000000 ) { + workingSize = workingSize / 1024000 + unit=" TB" + } + # we only want a max 2 decimal places, this trick gives 0 to 2 + workingSize=gensub(/([0-9]+\.[0-9][0-9]).*/,"\\1",1,workingSize) + workingSize = workingSize unit + } + print aMemory[m,j,0] "," aMemory[m,j,1] "," workingSize "," aMemory[m,j,3] "," aMemory[m,j,4] "," aMemory[m,j,5] "," aMemory[m,j,6] "," aMemory[m,j,7] "," aMemory[m,j,8] "," aMemory[m,j,9] "," aMemory[m,j,10] "," aMemory[m,j,11] "," aMemory[m,j,12] "," aMemory[m,j,13] "," aMemory[m,j,14] "," aMemory[m,j,15] "," aMemory[m,j,16] "," aMemory[m,j,17] + } + else { + break + } + } + } + }' <<< "$DMIDECODE_DATA" ) ) + fi + fi + IFS="$ORIGINAL_IFS" + a_temp=${A_MEMORY_DATA[@]} + + # echo "${a_temp[@]}" + log_function_data "A_MEMORY_DATA: $a_temp" + + eval $LOGFE +} + # Repos will be added as we get distro package manager data to create the repo data. # This method will output the file name also, which is useful to create output that's # neat and readable. Each line of the total number contains the following sections, # separated by a : for splitting in the print function # part one, repo type/string : part two, file name, if present, of info : part 3, repo data +# args: $1 - [file location of debug data file - optional, only for debugging data collection] get_repo_data() { eval $LOGFS @@ -7626,11 +9785,28 @@ get_repo_data() local repo_name='' local apt_file='/etc/apt/sources.list' yum_repo_dir='/etc/yum.repos.d/' yum_conf='/etc/yum.conf' local pacman_conf='/etc/pacman.conf' pacman_repo_dir='/etc/pacman.d/' pisi_dir='/etc/pisi/' - local zypp_repo_dir='/etc/zypp/repos.d/' freebsd_conf='/etc/portsnap.conf' + local zypp_repo_dir='/etc/zypp/repos.d/' ports_conf='/etc/portsnap.conf' openbsd_conf='/etc/pkg.conf' + local bsd_pkg_dir='/usr/local/etc/pkg/repos/' slackpkg_file='/etc/slackpkg/mirrors' + local netbsd_file='/usr/pkg/etc/pkgin/repositories.conf' freebsd_file='/etc/freebsd-update.conf' + local freebsd_pkg_file='/etc/pkg/FreeBSD.conf' slackpkg_plus_file='/etc/slackpkg/slackpkgplus.conf' + local portage_repo_dir='/etc/portage/repos.conf/' # apt - debian, buntus, also sometimes some yum/rpm repos may create apt repos here as well if [[ -f $apt_file || -d $apt_file.d ]];then - REPO_DATA="$( grep -Esv '(^[[:space:]]*$|^[[:space:]]*#)' $apt_file $apt_file.d/*.list | sed $SED_RX 's/^(.*)/apt sources:\1/' )" + repo_files=$(ls /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null) + log_function_data "apt repo files: $repo_files" + for repo_file in $repo_files + do + if [[ -n $1 ]];then + cat $repo_file &> $1/repo-data_${repo_file//\//-}.txt + fi + repo_data_working="$( gawk -v repoFile="$repo_file" ' + !/^[[:space:]]*$|^[[:space:]]*#/ { + print "apt sources^" repoFile "^" $0 + }' $repo_file )" + get_repo_builder "$repo_data_working" + done + repo_data_working='' fi # yum - fedora, redhat, centos, etc. Note that rpmforge also may create apt sources # in /etc/apt/sources.list.d/. Therefore rather than trying to assume what package manager is @@ -7642,17 +9818,22 @@ get_repo_data() # older redhats put their yum data in /etc/yum.conf repo_files=$( ls $yum_repo_dir*.repo $yum_conf 2>/dev/null ) repo_name='yum' + log_function_data "yum repo files: $repo_files" elif [[ -d $zypp_repo_dir ]];then repo_files=$( ls $zypp_repo_dir*.repo 2>/dev/null ) repo_name='zypp' + log_function_data "zypp repo files: $repo_files" fi if [[ -n $repo_files ]];then for repo_file in $repo_files do - repo_data_working="$( gawk -v repoFile=$repo_file ' + if [[ -n $1 ]];then + cat $repo_file &> $1/repo-data_${repo_file//\//-}.txt + fi + repo_data_working="$( gawk -v repoFile="$repo_file" ' # construct the string for the print function to work with, file name: data function print_line( fileName, repoId, repoUrl ){ - print "'$repo_name' sources:" fileName ":" repoId repoUrl + print "'$repo_name' sources^" fileName "^" repoId repoUrl } BEGIN { FS="\n" @@ -7673,7 +9854,7 @@ get_repo_data() urlData="" repoTitle="" } - gsub( /\[|\]/, "", $1 ) # strip out the brackets + gsub(/\[|\]/, "", $1 ) # strip out the brackets repoTitle = $1 " ~ " } /^(mirrorlist|baseurl)/ { @@ -7703,19 +9884,11 @@ get_repo_data() } } ' $repo_file )" - # then load the global for each file as it gets filled - if [[ -n $repo_data_working ]];then - if [[ -z $REPO_DATA ]];then - REPO_DATA="$repo_data_working" - else - REPO_DATA="$REPO_DATA -$repo_data_working" - fi - repo_data_working='' - fi + get_repo_builder "$repo_data_working" done fi + repo_data_working='' # pacman - archlinux, going to assume that pisi and arch/pacman, etc don't have the above issue with apt/yum elif [[ -f $pacman_conf ]];then # get list of mirror include files, trim white space off ends @@ -7734,6 +9907,9 @@ $repo_data_working" repo_data_working="$repo_data_working $pacman_conf" for repo_file in $repo_data_working do + if [[ -n $1 ]];then + cat $repo_file &> $1/repo-data_${repo_file//\//-}.txt + fi if [[ -f $repo_file ]];then # inserting a new line after each found / processed match repo_data_working2="$repo_data_working2$( gawk -v repoFile=$repo_file ' @@ -7743,7 +9919,7 @@ $repo_data_working" } /^[[:space:]]*Server/ { sub(/^[[:space:]]+|[[:space:]]+$/,"",$2) - print "pacman repo servers:" repoFile ":" $2 "\\n" + print "pacman repo servers^" repoFile "^" $2 "\\n" } ' $repo_file )" else @@ -7752,9 +9928,126 @@ $repo_data_working" done # execute line breaks REPO_DATA="$( echo -e $repo_data_working2 )" + repo_data_working='' # pisi - pardus + elif [[ -f $slackpkg_file || -f $slackpkg_plus_file ]];then + # note, only one file, but loop it in case more are added in future + if [[ -f $slackpkg_file ]];then + if [[ -n $1 ]];then + cat $slackpkg_file &> $1/repo-data_${slackpkg_file//\//-}.txt + fi + repo_data_working="$( gawk -v repoFile="$slackpkg_file" ' + !/^[[:space:]]*$|^[[:space:]]*#/ { + print "slackpkg sources^" repoFile "^" $0 + }' $slackpkg_file )" + get_repo_builder "$repo_data_working" + fi + if [[ -f $slackpkg_plus_file ]];then + if [[ -n $1 ]];then + cat $slackpkg_plus_file &> $1/repo-data_${slackpkg_plus_file//\//-}.txt + fi + # see sample for syntax + repo_data_working="$( gawk -F '=' -v repoFile="$slackpkg_plus_file" ' + BEGIN { + activeRepos="" + } + # stop if set to off + /^SLACKPKGPLUS/ { + if ( $2 == "off" ){ + exit + } + } + # get list of current active repos + /^REPOPLUS/ { + activeRepos=$2 + } + # print out repo line if found + /^MIRRORPLUS/ { + if ( activeRepos != "" ) { + gsub(/MIRRORPLUS\['\''|'\''\]/,"",$1) + if ( match( activeRepos, $1 ) ){ + print "slackpkg+ sources^" repoFile "^" $1 " ~ " $2 + } + } + }' $slackpkg_plus_file )" + get_repo_builder "$repo_data_working" + fi + repo_data_working='' + elif [[ -d $portage_repo_dir && -n $( type -p emerge ) ]];then + repo_files=$( ls $portage_repo_dir*.conf 2>/dev/null ) + repo_name='portage' + log_function_data "portage repo files: $repo_files" + if [[ -n $repo_files ]];then + for repo_file in $repo_files + do + if [[ -n $1 ]];then + cat $repo_file &> $1/repo-data_${repo_file//\//-}.txt + fi + repo_data_working="$( gawk -v repoFile="$repo_file" ' + # construct the string for the print function to work with, file name: data + function print_line( fileName, repoId, repoUrl ){ + print "'$repo_name' sources^" fileName "^" repoId repoUrl + } + BEGIN { + FS="\n" + IGNORECASE=1 + enabledStatus="" + repoTitle="" + urlData="" + } + # this is a hack, assuming that each item has these fields listed, we collect the 3 + # items one by one, then when the url/enabled fields are set, we print it out and + # reset the data. Not elegant but it works. Note that if enabled was not present + # we assume it is enabled then, and print the line, reset the variables. This will + # miss the last item, so it is printed if found in END + /^\[.+\]/ { + if ( urlData != "" && repoTitle != "" ){ + print_line( repoFile, repoTitle, urlData ) + enabledStatus="" + urlData="" + repoTitle="" + } + gsub(/\[|\]/, "", $1 ) # strip out the brackets + repoTitle = $1 " ~ " + } + /^(sync-uri)/ { + sub( /sync-uri[[:space:]]*=[[:space:]]*/, "", $1 ) # strip out the field starter + urlData = $1 + } + # note: enabled = 1. enabled = 0 means disabled + /^auto-sync[[:space:]]*=/ { + sub( /auto-sync[[:space:]]*=[[:space:]]*/, "", $1 ) # strip out the field starter + enabledStatus = $1 + } + # print out the line if all 3 values are found, otherwise if a new + # repoTitle is hit above, it will print out the line there instead + { + if ( urlData != "" && enabledStatus != "" && repoTitle != "" ){ + if ( enabledStatus !~ /enabled[[:space:]]*=[[:space:]]*0/ ){ + print_line( repoFile, repoTitle, urlData ) + } + enabledStatus="" + urlData="" + repoTitle="" + } + } + END { + # print the last one if there is data for it + if ( urlData != "" && repoTitle != "" ){ + print_line( repoFile, repoTitle, urlData ) + } + } + ' $repo_file )" + # then load the global for each file as it gets filled + get_repo_builder "$repo_data_working" + done + fi elif [[ -d $pisi_dir && -n $( type -p pisi ) ]];then REPO_DATA="$( pisi list-repo )" + if [[ -n $1 ]];then + echo "$REPO_DATA" &> $1/repo-data_pisi-list-repo.txt + fi + log_function_data "pisi-list-repo: $REPO_DATA" # now we need to create the structure: repo info: repo path # we do that by looping through the lines of the output and then # putting it back into the : format print repos expects to see @@ -7775,16 +10068,20 @@ $repo_data_working" print $0 }' <<< $repo_line ) if [[ -n $( grep '://' <<< $repo_line ) ]];then - repo_data_working="$repo_data_working:$repo_line\n" + repo_data_working="$repo_data_working^$repo_line\n" else - repo_data_working="${repo_data_working}pisi repo:$repo_line" + repo_data_working="${repo_data_working}pisi repo^$repo_line" fi done <<< "$REPO_DATA" # echo and execute the line breaks inserted REPO_DATA="$( echo -e $repo_data_working )" + repo_data_working='' # Mandriva/Mageia using: urpmq - elif [[ -n $( type -p urpmq ) ]];then + elif type -p urpmq &>/dev/null;then REPO_DATA="$( urpmq --list-media active --list-url )" + if [[ -n $1 ]];then + echo "$REPO_DATA" &> $1/repo-data_urpmq-list-media-active.txt + fi # now we need to create the structure: repo info: repo path # we do that by looping through the lines of the output and then # putting it back into the : format print repos expects to see @@ -7812,31 +10109,150 @@ $repo_data_working" repo_data_working2=$( grep -Eo '([^[:space:]]+://|[[:space:]]/).*' <<< $repo_line ) # then get the repo name string by slicing out the url string repo_name=$( sed "s|[[:space:]]*$repo_data_working2||" <<< $repo_line ) - repo_data_working="${repo_data_working}urpmq repo:$repo_name:$repo_data_working2\n" + repo_data_working="${repo_data_working}urpmq repo^$repo_name^$repo_data_working2\n" fi done <<< "$REPO_DATA" # echo and execute the line breaks inserted REPO_DATA="$( echo -e $repo_data_working )" - elif [[ -f $freebsd_conf ]];then - REPO_DATA="$( gawk -F '=' -v repoFile=$freebsd_conf ' + elif [[ -f $ports_conf || -f $freebsd_file || -d $bsd_pkg_dir ]];then + if [[ -f $ports_conf ]];then + if [[ -n $1 ]];then + cat $ports_conf &> $1/repo-data_${ports_conf//\//-}.txt + fi + repo_data_working="$( gawk -F '=' -v repoFile=$ports_conf ' + BEGIN { + IGNORECASE=1 + } + /^SERVERNAME/ { + print "BSD ports server^" repoFile "^" $2 + exit + } + ' $ports_conf )" + get_repo_builder "$repo_data_working" + fi + if [[ -f $freebsd_file ]];then + if [[ -n $1 ]];then + cat $freebsd_file &> $1/repo-data_${freebsd_file//\//-}.txt + fi + repo_data_working="$( gawk -v repoFile=$freebsd_file ' + BEGIN { + IGNORECASE=1 + } + /^ServerName/ { + print "FreeBSD update server^" repoFile "^" $2 + exit + } + ' $freebsd_file )" + get_repo_builder "$repo_data_working" + fi + if [[ -f $freebsd_pkg_file ]];then + if [[ -n $1 ]];then + cat $freebsd_pkg_file &> $1/repo-data_${freebsd_pkg_file//\//-}.txt + fi + repo_data_working="$( gawk -F ': ' -v repoFile=$freebsd_pkg_file ' + BEGIN { + IGNORECASE=1 + } + $1 ~ /^[[:space:]]*url/ { + gsub(/\"|pkg\+|,/,"",$2) + print "FreeBSD default pkg server^" repoFile "^" $2 + exit + } + ' $freebsd_pkg_file )" + get_repo_builder "$repo_data_working" + fi + + if [[ -d $bsd_pkg_dir ]];then + repo_files=$(ls ${bsd_pkg_dir}*.conf 2>/dev/null ) + for repo_file in $repo_files + do + if [[ -n $1 ]];then + cat $repo_file &> $1/repo-data_${repo_file//\//-}.txt + fi + repo_data_working="$( gawk -v repoFile=$repo_file ' + BEGIN { + FS=":" + IGNORECASE=1 + repoName="" + repoUrl="" + enabled="" + } + { + gsub(/{|}|^#.*/,"",$0) + } + /^[^[:space:]]/ { + repoName=$1 + repoUrl="" + enabled="" + while ( getline && $0 !~ /^[[:space:]]*$/ ) { + gsub(/'"$BAN_LIST_ARRAY"'/,"",$0) + gsub(/({|}|^[[:space:]]+|[[:space:]]+$)/,"",$1) + gsub(/({|}|^[[:space:]]+|[[:space:]]+$)/,"",$2) + if ( $1 == "url" ) { + repoUrl=$2$3 + } + if ( $1 == "enabled" ) { + if ( $2 == "yes" ) { + print "BSD pkg server^" repoFile "^" repoName " ~ " repoUrl + } + } + } + } + ' $repo_file )" + get_repo_builder "$repo_data_working" + done + fi + repo_data_working='' + elif [[ -f $openbsd_conf ]];then + if [[ -n $1 ]];then + cat $openbsd_conf &> $1/repo-data_${openbsd_conf//\//-}.txt + fi + REPO_DATA="$( gawk -F '=' -v repoFile=$openbsd_conf ' BEGIN { IGNORECASE=1 } - /^SERVERNAME/ { - print "BSD ports servers:" repoFile ":" $2 + /^installpath/ { + print "OpenBSD pkg mirror^" repoFile "^" $2 } - ' $freebsd_conf )" + ' $openbsd_conf )" + elif [[ -f $netbsd_file ]];then + # note, only one file, but loop it in case more are added in future + for repo_file in $netbsd_file + do + if [[ -n $1 ]];then + cat $repo_file &> $1/repo-data_${repo_file//\//-}.txt + fi + repo_data_working="$( gawk -v repoFile="$repo_file" ' + !/^[[:space:]]*$|^[[:space:]]*#/ { + print "NetBSD pkg servers^" repoFile "^" $0 + }' $repo_file )" + get_repo_builder "$repo_data_working" + done + repo_data_working='' fi eval $LOGFE } +# build the total REPO_DATA global here +# args: $1 - the repo line/s +get_repo_builder() +{ + if [[ -n $1 ]];then + if [[ -z $REPO_DATA ]];then + REPO_DATA="$1" + else + REPO_DATA="$REPO_DATA +$1" + fi + fi +} get_runlevel_data() { eval $LOGFS local runlvl='' - local runlevel_path=$( type -p runlevel ) - if [[ -n $runlevel_path ]];then - runlvl="$( $runlevel_path | gawk '{ print $2 }' )" + + if type -p runlevel &>/dev/null;then + runlvl="$( runlevel | gawk '{ print $2 }' )" fi echo $runlvl eval $LOGFE @@ -7857,7 +10273,7 @@ get_runlevel_default() if [[ -L $systemd_default ]];then default_runlvl=$( readlink $systemd_default ) if [[ -n $default_runlvl ]];then - default_runlvl=$( basename $default_runlvl ) + default_runlvl=${default_runlvl##*/} fi # http://askubuntu.com/questions/86483/how-can-i-see-or-change-default-run-level # note that technically default can be changed at boot but for inxi purposes that does @@ -7885,7 +10301,7 @@ get_sensors_data() eval $LOGFS - local temp_array='' + local a_temp='' IFS=$'\n' if [[ -n $Sensors_Data ]];then @@ -7895,7 +10311,8 @@ get_sensors_data() gawk -F ':' -v userCpuNo="$SENSORS_CPU_NO" ' BEGIN { IGNORECASE=1 - core0Temp="" # only if all else fails... + core0Temp="" # these only if all else fails... + cpuPeciTemp="" # use if temps are missing or wrong cpuTemp="" cpuTempReal="" fanWorking="" @@ -7910,6 +10327,8 @@ get_sensors_data() sysFanString="" temp1="" temp2="" + temp3="" + tempDiff=20 # for C, handled for F after that is determined tempFanType="" # set to 1 or 2 tempUnit="" tempWorking="" @@ -7938,6 +10357,8 @@ get_sensors_data() tempUnit=tempWorkingUnit } } + # issue 58 msi/asus show wrong for CPUTIN so overwrite it if PECI 0 is present + # http://www.spinics.net/lists/lm-sensors/msg37308.html /^CPU(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ { cpuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 ) tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 ) @@ -7945,6 +10366,13 @@ get_sensors_data() tempUnit=tempWorkingUnit } } + /^PECI[[:space:]]Agent[[:space:]]0(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ { + cpuPeciTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 ) + tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 ) + if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){ + tempUnit=tempWorkingUnit + } + } /^(P\/S|Power)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ { psuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 ) tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 ) @@ -7952,9 +10380,10 @@ get_sensors_data() tempUnit=tempWorkingUnit } } + # for temp1/2 only use temp1/2 if they are null or greater than the last ones $1 ~ /^temp1$/ && $2 ~ /^[ \t]*\+([0-9]+)/ { tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 ) - if ( temp1 == "" || tempWorking > 0 ) { + if ( temp1 == "" || ( tempWorking != "" && tempWorking > 0 ) ) { temp1=tempWorking } tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 ) @@ -7964,7 +10393,7 @@ get_sensors_data() } $1 ~ /^temp2$/ && $2 ~ /^[ \t]*\+([0-9]+)/ { tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 ) - if ( temp2 == "" || tempWorking > 0 ) { + if ( temp2 == "" || ( tempWorking != "" && tempWorking > 0 ) ) { temp2=tempWorking } tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 ) @@ -7972,12 +10401,22 @@ get_sensors_data() tempUnit=tempWorkingUnit } } - + # temp3 is only used as an absolute override for systems with all 3 present + $1 ~ /^temp3$/ && $2 ~ /^[ \t]*\+([0-9]+)/ { + tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 ) + if ( temp3 == "" || ( tempWorking != "" && tempWorking > 0 ) ) { + temp3=tempWorking + } + tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 ) + if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){ + tempUnit=tempWorkingUnit + } + } # final fallback if all else fails, funtoo user showed sensors putting # temp on wrapped second line, not handled - /^(core0|core 0)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ { + /^(core0|core 0|Physical id 0)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ { tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 ) - if ( core0Temp == "" || tempWorking > 0 ) { + if ( tempWorking != "" && core0Temp == "" && tempWorking > 0 ) { core0Temp=tempWorking } tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 ) @@ -7985,7 +10424,6 @@ get_sensors_data() tempUnit=tempWorkingUnit } } - # note: can be cpu fan:, cpu fan speed:, etc. Some cases have no space before # $2 starts (like so :1234 RPM), so skip that space test in regex /^CPU(.*)[ \t]*([0-9]+)[ \t]RPM/ { @@ -8043,17 +10481,18 @@ get_sensors_data() } } } - END { # first we need to handle the case where we have to determine which temp/fan to use for cpu and mobo: # note, for rare cases of weird cool cpus, user can override in their prefs and force the assignment + # this is wrong for systems with > 2 tempX readings, but the logic is too complex with 3 variables + # so have to accept that it will be wrong in some cases, particularly for motherboard temp readings. if ( temp1 != "" && temp2 != "" ){ if ( userCpuNo != "" && userCpuNo ~ /(1|2)/ ) { tempFanType=userCpuNo } else { # first some fringe cases with cooler cpu than mobo: assume which is cpu temp based on fan speed - # but only if other fan speed is 0 + # but only if other fan speed is 0. if ( temp1 >= temp2 && 1 in aFanDefault && 2 in aFanDefault && aFanDefault[1] == 0 && aFanDefault[2] > 0 ) { tempFanType=2 } @@ -8081,38 +10520,91 @@ get_sensors_data() tempFanType=1 } } - - # then get the real cpu temp, best guess is hottest is real - if ( cpuTemp != "" ){ - cpuTempReal=cpuTemp + # convert the diff number for F, it needs to be bigger that is + if ( tempUnit == "F" ) { + tempDiff = tempDiff * 1.8 } - else if ( tempFanType != "" ){ - if ( tempFanType == 1 ){ - cpuTempReal=temp1 + if ( cpuTemp != "" ) { + # specific hack to handle broken CPUTIN temps with PECI + if ( cpuPeciTemp != "" && ( cpuTemp - cpuPeciTemp ) > tempDiff ){ + cpuTempReal=cpuPeciTemp } + # then get the real cpu temp, best guess is hottest is real else { - cpuTempReal=temp2 + cpuTempReal=cpuTemp } } else { - cpuTempReal=temp1 + if ( tempFanType != "" ){ + # there are some weird scenarios + if ( tempFanType == 1 ){ + if ( temp1 != "" && temp2 != "" && temp2 > temp1 ) { + cpuTempReal=temp2 + } + else { + cpuTempReal=temp1 + } + } + else { + if ( temp1 != "" && temp2 != "" && temp1 > temp2 ) { + cpuTempReal=temp1 + } + else { + cpuTempReal=temp2 + } + } + } + else { + cpuTempReal=temp1 # can be null, that is ok + } + if ( cpuTempReal != "" ) { + # using temp3 is just not reliable enough, more errors caused than fixed imo + #if ( temp3 != "" && temp3 > cpuTempReal ) { + # cpuTempReal=temp3 + #} + # there are some absurdly wrong temp1: acpitz-virtual-0 temp1: +13.8°C + if ( core0Temp != "" && (core0Temp - cpuTempReal) > tempDiff ) { + cpuTempReal=core0Temp + } + } } - # if all else fails, use core0 temp if it is present and cpu is null - if ( cpuTempReal == "" && core0Temp != "" ) { - cpuTempReal=core0Temp + # if all else fails, use core0/peci temp if present and cpu is null + if ( cpuTempReal == "" ) { + if ( core0Temp != "" ) { + cpuTempReal=core0Temp + } + # note that peci temp is known to be colder than the actual system + # sometimes so it is the last fallback we want to use even though in theory + # it is more accurate, but fact suggests theory wrong. + else if ( cpuPeciTemp != "" ) { + cpuTempReal=cpuPeciTemp + } } - # then the real mobo temp if ( moboTemp != "" ){ moboTempReal=moboTemp } else if ( tempFanType != "" ){ if ( tempFanType == 1 ) { - moboTempReal=temp2 + if ( temp1 != "" && temp2 != "" && temp2 > temp1 ) { + moboTempReal=temp1 + } + else { + moboTempReal=temp2 + } } else { - moboTempReal=temp1 + if ( temp1 != "" && temp2 != "" && temp1 > temp2 ) { + moboTempReal=temp2 + } + else { + moboTempReal=temp1 + } } + ## NOTE: not safe to assume temp3 is the mobo temp, sad to say + #if ( temp1 != "" && temp2 != "" && temp3 != "" && temp3 < moboTempReal ) { + # moboTempReal= temp3 + #} } else { moboTempReal=temp2 @@ -8130,7 +10622,6 @@ get_sensors_data() aFanDefault[2]="" } } - # then we need to get the actual numeric max array count for both fan arrays for (i = 0; i <= 29; i++) { if ( i in aFanMain && i > indexCountaFanMain ) { @@ -8142,7 +10633,6 @@ get_sensors_data() indexCountaFanDefault=i } } - # clear out any duplicates. Primary fan real trumps fan working always if same speed for (i = 1; i <= indexCountaFanMain; i++) { if ( i in aFanMain && aFanMain[i] != "" && aFanMain[i] != 0 ) { @@ -8153,7 +10643,6 @@ get_sensors_data() } } } - # now see if you can find the fast little mobo fan, > 5000 rpm and put it as mobo # note that gawk is returning true for some test cases when aFanDefault[j] < 5000 # which has to be a gawk bug, unless there is something really weird with arrays @@ -8172,7 +10661,6 @@ get_sensors_data() } } } - # then construct the sys_fan string for echo, note that iteration 1 # makes: fanDefaultString separator null, ie, no space or , for (j = 1; j <= indexCountaFanDefault; j++) { @@ -8193,7 +10681,6 @@ get_sensors_data() if ( cpuTempReal != "" ) { cpuTempReal = cpuTempReal tempUnit } - # if they are ALL null, print error message. psFan is not used in output currently if ( cpuTempReal == "" && moboTempReal == "" && aFanMain[1] == "" && aFanMain[2] == "" && aFanMain[3] == "" && fanDefaultString == "" ) { print "No active sensors found. Have you configured your sensors yet?" @@ -8212,18 +10699,18 @@ get_sensors_data() fi IFS="$ORIGINAL_IFS" - temp_array=${A_SENSORS_DATA[@]} - log_function_data "A_SENSORS_DATA: $temp_array" + a_temp=${A_SENSORS_DATA[@]} + log_function_data "A_SENSORS_DATA: $a_temp" # echo "A_SENSORS_DATA: ${A_SENSORS_DATA[@]}" eval $LOGFE } get_sensors_output() { - local sensors_path=$( type -p sensors ) sensors_data='' + local sensors_data='' - if [[ -n $sensors_path ]];then - sensors_data="$( $sensors_path 2>/dev/null )" + if type -p sensors &>/dev/null;then + sensors_data="$( sensors 2>/dev/null )" if [[ -n "$sensors_data" ]];then # make sure the file ends in newlines then characters, the newlines are lost in the echo unless # the data ends in some characters @@ -8243,24 +10730,24 @@ get_shell_data() if [[ $B_EXTRA_DATA == 'true' && -n $shell_type ]];then case $shell_type in bash) - shell_version=$( get_de_app_version "$shell_type" "^GNU[[:space:]]bash,[[:space:]]version" "4" | \ + shell_version=$( get_program_version "$shell_type" "^GNU[[:space:]]bash,[[:space:]]version" "4" | \ sed $SED_RX 's/(\(.*|-release|-version)//' ) ;; # csh/dash use dpkg package version data, debian/buntu only csh) - shell_version=$( get_de_app_version "$shell_type" "^tcsh" "2" ) + shell_version=$( get_program_version "$shell_type" "^tcsh" "2" ) ;; dash) - shell_version=$( get_de_app_version "$shell_type" "$shell_type" "3" ) + shell_version=$( get_program_version "$shell_type" "$shell_type" "3" ) ;; ksh) - shell_version=$( get_de_app_version "$shell_type" "version" "5" ) + shell_version=$( get_program_version "$shell_type" "version" "5" ) ;; tcsh) - shell_version=$( get_de_app_version "$shell_type" "^tcsh" "2" ) + shell_version=$( get_program_version "$shell_type" "^tcsh" "2" ) ;; zsh) - shell_version=$( get_de_app_version "$shell_type" "^zsh" "2" ) + shell_version=$( get_program_version "$shell_type" "^zsh" "2" ) ;; esac fi @@ -8268,8 +10755,8 @@ get_shell_data() shell_type="$shell_type $shell_version" fi echo $shell_type - - eval $LOGFS + log_function_data "shell type: $shell_type" + eval $LOGFE } get_shell_parent() @@ -8301,10 +10788,16 @@ get_sysctl_data() local sysctl_data='' if [[ $B_SYSCTL ]];then - sysctl_data="$( sysctl -$1 )" + # darwin sysctl has BOTH = and : separators, and repeats data. Why? No bsd discipline, that's for sure + if [[ $BSD_VERSION == 'darwin' ]];then + sysctl_data="$( sysctl -$1 | sed 's/[[:space:]]*=[[:space:]]*/: /' )" + else + sysctl_data="$( sysctl -$1 )" + fi fi # log_function_data "sysctl_data: $sysctl_data" echo "$sysctl_data" + eval $LOGFE } @@ -8312,14 +10805,14 @@ get_tty_console_irc() { eval $LOGFS local tty_number='' - if [[ -n ${IRC_CLIENT} ]];then + if [[ -n $IRC_CLIENT ]];then tty_number=$( gawk ' BEGIN { IGNORECASE=1 } # if multiple irc clients open, can give wrong results # so make sure to also use the PPID number to get the right tty - /.*'$PPID'.*'${IRC_CLIENT}'/ { + /.*'$PPID'.*'$IRC_CLIENT'/ { gsub(/[^0-9]/, "", $7) print $7 exit @@ -8334,9 +10827,9 @@ get_tty_number() { eval $LOGFS - local tty_number=$( basename "$( tty 2>/dev/null )" | sed 's/[^0-9]*//g' ) - - echo $tty_number + local tty_number=$( tty 2>/dev/null | sed 's/[^0-9]*//g' ) + tty_number=${tty_number##*/} + echo ${tty_number##*/} eval $LOGFE } @@ -8457,11 +10950,14 @@ get_unmounted_partition_filesystem() get_uptime() { eval $LOGFS + local uptime_value='' ## note: removing gsub(/ /,"",a); to get get space back in there, goes right before print a - local uptime_value="$( uptime | gawk '{ - a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0) - print a - }' )" + if type -p uptime &>/dev/null;then + uptime_value="$( uptime | gawk '{ + a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0) + print a + }' )" + fi echo "$uptime_value" log_function_data "uptime_value: $uptime_value" eval $LOGFE @@ -8474,12 +10970,12 @@ get_weather_data() local location_site='http://geoip.ubuntu.com/lookup' local weather_feed='http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=' local weather_spider='http://wunderground.com/' - local data_grab_error='' wget_error=0 + local data_grab_error='' downloader_error=0 local b_test_loc=false b_test_weather=false b_debug=false local test_dir="$HOME/bin/scripts/inxi/data/weather/" local test_location='location2.xml' test_weather='weather-feed.xml' local location_data='' location='' weather_data='' location_array_value='' a_location='' - local weather_array_value='' site_elevation='' temp_array='' + local weather_array_value='' site_elevation='' a_temp='' # first we get the location data, once that is parsed and handled, we move to getting the # actual weather data, assuming no errors @@ -8489,12 +10985,33 @@ get_weather_data() # echo $ALTERNATE_WEATHER_LOCATION;exit else if [[ $b_test_loc != 'true' ]];then - location_data=$( wget -q -t 1 -T $WGET_TIMEOUT -O- $location_site || wget_error=$? ) + case $DOWNLOADER in + curl) + location_data="$( curl -y $DL_TIMEOUT -s $location_site )" || downloader_error=$? + ;; + fetch) + location_data="$( fetch -T $DL_TIMEOUT -q -o - $location_site )" || downloader_error=$? + ;; + ftp) + location_data="$( ftp -o - $location_site 2>/dev/null )" || downloader_error=$? + ;; + wget) + location_data="$( wget -t 1 -T $DL_TIMEOUT -q -O - $location_site )" || downloader_error=$? + ;; + no-downloader) + downloader_error=100 + ;; + esac log_function_data "$location_data" - if [[ $wget_error -ne 0 ]];then - data_grab_error="Error: location server up but download error - wget: $wget_error" + + if [[ $downloader_error -ne 0 ]];then + if [[ $downloader_error -eq 100 ]];then + data_grab_error="Error: No downloader tool available. Install wget, curl, or fetch." + else + data_grab_error="Error: location server up but download error - $DOWNLOADER: $downloader_error" + fi fi - wget_error=0 + downloader_error=0 else if [[ -f $test_dir$test_location ]];then location_data="$( cat $test_dir$test_location )" @@ -8605,9 +11122,29 @@ get_weather_data() # now either dump process or go on to get weather data if [[ -z $data_grab_error ]];then if [[ $b_test_weather != 'true' ]];then - weather_data="$( wget -q -t 1 -T $WGET_TIMEOUT -O- $weather_feed"$location" || wget_error=$? )" - if [[ $wget_error -ne 0 ]];then - data_grab_error="Error: weather server up but download error - wget: $wget_error" + case $DOWNLOADER in + curl) + weather_data="$( curl -y $DL_TIMEOUT -s $weather_feed"$location" )" || downloader_error=$? + ;; + fetch) + weather_data="$( fetch -T $DL_TIMEOUT -q -o - $weather_feed"$location" )" || downloader_error=$? + ;; + ftp) + weather_data="$( ftp -o - $weather_feed"$location" 2>/dev/null )" || downloader_error=$? + ;; + wget) + weather_data="$( wget -t 1 -T $DL_TIMEOUT -q -O - $weather_feed"$location" )" || downloader_error=$? + ;; + no-downloader) + downloader_error=100 + ;; + esac + if [[ $downloader_error -ne 0 ]];then + if [[ $downloader_error -eq 100 ]];then + data_grab_error="Error: No downloader tool available. Install wget, curl, or fetch." + else + data_grab_error="Error: weather server up but download error - $DOWNLOADER: $downloader_error" + fi fi log_function_data "$weather_data" else @@ -8740,8 +11277,8 @@ get_weather_data() echo "site_elevation: $site_elevation" echo "${A_WEATHER_DATA[1]}" fi - temp_array=${A_WEATHER_DATA[@]} - log_function_data "A_WEATHER_DATA: $temp_array" + a_temp=${A_WEATHER_DATA[@]} + log_function_data "A_WEATHER_DATA: $a_temp" eval $LOGFE } @@ -8754,11 +11291,13 @@ get_weather_data() # args: $1 - string to strip color code characters out of # returns count of string length minus colors +# note; this cleanup may not be working on bsd sed calculate_line_length() { local string=$1 # ansi:  irc: \x0312 - 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 ) + # note: using special trick for bsd sed, tr - NOTE irc sed must use " double quote + string=$( sed -e 's/'$ESC'\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g' -e "s/\\\x0[0-9]\{1,3\}//g" <<< $string ) count=${#string} echo $count } @@ -8884,12 +11423,15 @@ print_it_out() if [[ $B_SHOW_MACHINE == 'true' ]];then print_machine_data fi - if [[ $B_SHOW_WEATHER == 'true' ]];then - print_weather_data + if [[ $B_SHOW_BATTERY == 'true' ]];then + print_battery_data fi if [[ $B_SHOW_BASIC_CPU == 'true' || $B_SHOW_CPU == 'true' ]];then print_cpu_data fi + if [[ $B_SHOW_MEMORY == 'true' ]];then + print_ram_data + fi if [[ $B_SHOW_GRAPHICS == 'true' ]];then print_graphics_data fi @@ -8920,10 +11462,18 @@ print_it_out() if [[ $B_SHOW_PS_CPU_DATA == 'true' || $B_SHOW_PS_MEM_DATA == 'true' ]];then print_ps_data fi + if [[ $B_SHOW_WEATHER == 'true' ]];then + print_weather_data + fi if [[ $B_SHOW_INFO == 'true' ]];then print_info_data fi fi + ## last steps, clear any lingering colors + if [[ $B_IRC == 'false' && $SCHEME -gt 0 ]];then + echo -n "" + fi + eval $LOGFE } @@ -8938,22 +11488,42 @@ print_short_data() local short_data='' i='' b_background_black='false' local memory=$( get_memory_data ) local up_time="$( get_uptime )" + if [[ -z $up_time ]];then + up_time='N/A - missing uptime?' + fi # set A_CPU_CORE_DATA get_cpu_core_count - local cpc_plural='' cpu_count_print='' model_plural='' + local cpc_plural='' cpu_count_print='' model_plural='' current_max_clock='' local cpu_physical_count=${A_CPU_CORE_DATA[0]} local cpu_core_count=${A_CPU_CORE_DATA[3]} local cpu_core_alpha=${A_CPU_CORE_DATA[1]} local cpu_type=${A_CPU_CORE_DATA[2]} + local kernel_os='' speed_starter='speed' + local cpu_data_string='' + + if [[ -z $BSD_TYPE || -n $cpu_type ]];then + cpu_type=" ($cpu_type)" + fi + + if [[ $BSD_TYPE == 'bsd' ]];then + kernel_os="${C1}OS${C2}$SEP1$( uname -rsp )" + else + kernel_os="${C1}Kernel${C2}$SEP1$current_kernel" + fi if [[ $cpu_physical_count -gt 1 ]];then cpc_plural='(s)' model_plural='s' cpu_count_print="$cpu_physical_count " + # for multicpu systems, divide total cores by cpu count to get per cpu cores + $cpu_core_count=$(($cpu_core_count/$cpu_physical_count)) + fi + if [[ -z $BSD_TYPE ]];then + cpu_data_string="$cpu_count_print$cpu_core_alpha core" + else + cpu_data_string="$cpu_count_print$cpu_core_count core" fi - - local cpu_data_string="${cpu_count_print}${cpu_core_alpha} core" # local cpu_core_count=${A_CPU_CORE_DATA[0]} # load A_HDD_DATA @@ -8972,24 +11542,40 @@ print_short_data() IFS="," local a_cpu_working=(${A_CPU_DATA[0]}) + # this gets that weird min/max final array item, which almost never contains any data of use + local current_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 )) + local a_cpu_speeds=(${A_CPU_DATA[$current_max_clock_nu]}) IFS="$ORIGINAL_IFS" local cpu_model="${a_cpu_working[0]}" ## assemble data for output local cpu_clock="${a_cpu_working[1]}" # old CPU3 - # this gets that weird min/max final array item, which almost never contains any data of use - local min_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 )) - local min_max_clock=${A_CPU_DATA[$min_max_clock_nu]} + # echo $cpu_clock + # if [[ -z ${a_cpu_working[1]} || ${a_cpu_working[1]} < 50 ]];then + # a_cpu_working[1]=$(get_cpu_speed_hack) + # fi + # this handles the case of for example ARM cpus, which will not have data for # min/max, since they don't have speed. Since that sets a flag, not found, just # look for that and use the speed from the first array array, same where we got # model from - if [[ "$min_max_clock" == 'N/A' && ${a_cpu_working[1]} != '' ]];then - min_max_clock="${a_cpu_working[1]} MHz" + # index: 0 speed ; 1 min ; 2 max + # this handles bsd types which always should show N/A unless we get a way to get min / max data + if [[ "${a_cpu_speeds[0]}" == 'N/A' && ${a_cpu_working[1]} != '' ]];then + current_max_clock="${a_cpu_working[1]} MHz" + else + if [[ ${a_cpu_speeds[2]} != 0 ]];then + if [[ ${a_cpu_speeds[0]} == ${a_cpu_speeds[2]} ]];then + current_max_clock="${a_cpu_speeds[0]} MHz (max)" + else + current_max_clock="${a_cpu_speeds[0]}/${a_cpu_speeds[2]} MHz" + speed_starter='speed/max' + fi + fi fi local patch_version_number=$( get_patch_version_string ) #set_color_scheme 12 - if [[ $B_RUNNING_IN_SHELL == 'false' ]];then + if [[ $B_IRC == 'true' ]];then for i in $C1 $C2 $CN do case "$i" in @@ -9011,14 +11597,14 @@ print_short_data() #C1="${C1},1"; C2="${C2},1"; CN="${CN},1" fi fi - 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}" + short_data="${C1}CPU$cpc_plural${C2}$SEP1$cpu_data_string $cpu_model$model_plural$cpu_type ${C1}$speed_starter${C2}$SEP1$current_max_clock$SEP2$kernel_os$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" if [[ $SHOW_IRC -gt 0 ]];then - short_data="${short_data}${C1}Client${C2}${SEP1}${IRC_CLIENT}${IRC_CLIENT_VERSION}${SEP2}" + short_data="$short_data${C1}Client${C2}$SEP1$IRC_CLIENT$IRC_CLIENT_VERSION$SEP2" fi - short_data="${short_data}${C1}$SCRIPT_NAME${C2}${SEP1}$SCRIPT_VERSION_NUMBER$patch_version_number${SEP2}${CN}" + short_data="$short_data${C1}$SCRIPT_NAME${C2}$SEP1$SCRIPT_VERSION_NUMBER$patch_version_number$SEP2${CN}" if [[ $SCHEME -gt 0 ]];then - short_data="${short_data} $NORMAL" + short_data="$short_data $NORMAL" fi print_screen_output "$short_data" eval $LOGFE @@ -9036,10 +11622,14 @@ print_audio_data() local driver='' # set A_AUDIO_DATA and get alsa data if [[ $BSD_TYPE == 'bsd' ]];then - if [[ $B_PCICONF_SET == 'false' ]];then - get_pciconf_data + if [[ $B_PCICONF == 'true' ]];then + if [[ $B_PCICONF_SET == 'false' ]];then + get_pciconf_data + fi + get_pciconf_card_data 'audio' + elif [[ $B_LSPCI == 'true' ]];then + get_audio_data fi - get_pciconf_card_data 'audio' else get_audio_data fi @@ -9058,7 +11648,7 @@ print_audio_data() else alsa_version='N/A' fi - alsa_data="${C1}Sound:${C2} $alsa ${C1}ver$SEP3${C2} $alsa_version" + alsa_data="${C1}Sound$SEP3${C2} $alsa ${C1}v$SEP3${C2} $alsa_version" IFS="$ORIGINAL_IFS" fi # note, error handling is done in the get function, so this will never be null, but @@ -9079,7 +11669,6 @@ print_audio_data() bus_usb_text='' bus_usb_id='' print_data='' - card_id='' chip_id='' if [[ ${#A_AUDIO_DATA[@]} -gt 1 ]];then @@ -9100,7 +11689,7 @@ print_audio_data() else driver=${a_audio_working[1]} fi - audio_driver="${C1}driver$SEP3${C2} ${driver} " + audio_driver="${C1}driver$SEP3${C2} $driver " fi if [[ -n ${a_audio_working[2]} && $B_EXTRA_DATA == 'true' ]];then if [[ $( wc -w <<< ${a_audio_working[2]} ) -gt 1 ]];then @@ -9131,12 +11720,12 @@ print_audio_data() fi fi if [[ -n ${a_audio_working[0]} ]];then - card_string="${C1}Card$card_id:${C2} ${a_audio_working[0]} " + card_string="${C1}Card$card_id$EP3${C2} ${a_audio_working[0]} " audio_data="$audio_driver$port_data$pci_bus_id$chip_id" fi # only print alsa on last line if short enough, otherwise print on its own line if [[ $i -eq 0 ]];then - if [[ -n $alsa_data && $( calculate_line_length "$card_string${audio_data}$alsa_data" ) -lt $COLS_INNER ]];then + if [[ -n $alsa_data && $( calculate_line_length "$card_string$audio_data$alsa_data" ) -lt $COLS_INNER ]];then audio_data="$audio_data$alsa_data" alsa_data='' fi @@ -9148,15 +11737,15 @@ print_audio_data() # print the line else # keep the driver on the same line no matter what, looks weird alone on its own line - if [[ $B_EXTRA_DATA != 'true' ]];then - print_data=$( create_print_line "$line_starter" "$card_string$audio_data" ) - print_screen_output "$print_data" - else + if [[ $( calculate_line_length "$card_string$audio_data" ) -gt $COLS_INNER ]];then print_data=$( create_print_line "$line_starter" "$card_string" ) print_screen_output "$print_data" line_starter=' ' print_data=$( create_print_line "$line_starter" "$audio_data" ) print_screen_output "$print_data" + else + print_data=$( create_print_line "$line_starter" "$card_string$audio_data" ) + print_screen_output "$print_data" fi fi line_starter=' ' @@ -9164,22 +11753,209 @@ print_audio_data() done fi if [[ -n $alsa_data ]];then - alsa_data=$( sed 's/ALSA/Advanced Linux Sound Architecture/' <<< $alsa_data ) + if [[ $( calculate_line_length "${alsa_data/ALSA/Advanced Linux Sound Architecture}" ) -lt $COLS_INNER ]];then + # alsa_data=$( sed 's/ALSA/Advanced Linux Sound Architecture/' <<< $alsa_data ) + alsa_data=${alsa_data/ALSA/Advanced Linux Sound Architecture} + fi alsa_data=$( create_print_line "$line_starter" "$alsa_data" ) print_screen_output "$alsa_data" fi eval $LOGFE } +print_battery_data() +{ + eval $LOGFS + local line_starter='Battery' print_data='' + get_battery_data + if [[ -n ${A_BATTERY_DATA[@]} ]];then + local battery_data='' battery_string='' + local present='' chemistry='' cycles='' voltage_min_design='' voltage_now='' + local power_now='' charge_full_design='' charge_full='' charge_now='' capacity='' + local capacity_level='' model='' company='' serial='' of_orig='' model='' condition='' + local power='' + + # echo ${A_BATTERY_DATA[@]} + for (( i=0; i< ${#A_BATTERY_DATA[@]}; i++ )) + do + battery_data='' + print_data='' + battery_string='' + charge='' + model='' + condition='' + voltage='' + + name='' + status='' + present='' + chemistry='' + cycles='' + voltage_min_design='' + voltage_now='' + power_now='' + charge_full_design='' + charge_full='' + charge_now='' + capacity='' + capacity_level='' + of_orig='' + model='' + company='' + serial='' + location='' # dmidecode only + IFS="," + a_battery_working=( ${A_BATTERY_DATA[i]} ) + IFS="$ORIGINAL_IFS" + bat_id="$(( $i + 1 ))" + + if [[ -n ${a_battery_working[10]} ]];then + charge="${a_battery_working[10]} Wh " + fi + if [[ -n ${a_battery_working[11]} ]];then + charge="$charge${a_battery_working[11]} " + fi + if [[ $charge == '' ]];then + charge='N/A ' + fi + charge="${C1}charge$SEP3${C2} $charge" + if [[ -n ${a_battery_working[9]} ]];then + condition="${a_battery_working[9]}" + else + condition='NA' + fi + if [[ -n ${a_battery_working[8]} ]];then + condition="$condition/${a_battery_working[8]} Wh " + else + condition="$condition/NA Wh " + fi + if [[ -n ${a_battery_working[13]} ]];then + condition="$condition(${a_battery_working[13]}) " + fi + if [[ $condition == '' ]];then + condition='N/A ' + fi + condition="${C1}condition$SEP3${C2} $condition" + if [[ $B_EXTRA_DATA == 'true' ]];then + if [[ -n ${a_battery_working[15]} ]];then + model="${a_battery_working[15]} " + fi + if [[ -n ${a_battery_working[14]} ]];then + model="$model${a_battery_working[14]} " + fi + if [[ $model == '' ]];then + model='N/A ' + fi + model="${C1}model$SEP3${C2} $model" + + if [[ -n ${a_battery_working[1]} ]];then + status="${a_battery_working[1]} " + else + status="N/A " + fi + status="${C1}status$SEP3${C2} $status" + fi + if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then + if [[ -n ${a_battery_working[16]} ]];then + serial="${a_battery_working[16]} " + else + serial='N/A ' + fi + serial="${C1}serial$SEP3${C2} $serial" + if [[ -n ${a_battery_working[6]} ]];then + voltage="${a_battery_working[6]}" + fi + if [[ -n ${a_battery_working[5]} ]];then + if [[ $voltage == '' ]];then + voltage='NA' + fi + voltage="$voltage/${a_battery_working[5]} " + fi + if [[ $voltage == '' ]];then + voltage='NA ' + fi + voltage="${C1}volts$SEP3${C2} $voltage" + fi + if [[ $B_EXTRA_EXTRA_EXTRA_DATA == 'true' ]];then + if [[ -n ${a_battery_working[3]} ]];then + chemistry="${a_battery_working[3]} " + fi + if [[ -n ${a_battery_working[4]} ]];then + cycles="${C1}cycles$SEP3${C2} ${a_battery_working[4]} " + fi + # location is dmidecode only + if [[ -n ${a_battery_working[17]} ]];then + location="${C1}loc$SEP3${C2} ${a_battery_working[17]} " + fi + fi + if [[ -n ${a_battery_working[15]} ]];then + battery_string="${C1}${a_battery_working[0]}$SEP3${C2} $charge$condition" + battery_data="$model$chemistry$serial$status$cycles$location" + fi + + if [[ ${A_BATTERY_DATA[0]} == 'dmidecode-error-'* ]];then + error_string=$( print_dmidecode_error 'bat' "${A_BATTERY_DATA[0]}" ) + battery_string=${C2}$error_string + battery_data='' + voltage='' + fi + + if [[ -n $battery_string ]];then + if [[ $( calculate_line_length "$battery_string$voltage$battery_data" ) -lt $COLS_INNER ]];then + #echo one + print_data=$( create_print_line "$line_starter" "$battery_string$voltage$battery_data" ) + print_screen_output "$print_data" + # print the line + else + # keep the driver on the same line no matter what, looks weird alone on its own line + if [[ $( calculate_line_length "$battery_string$voltage$battery_data" ) -gt $COLS_INNER ]];then + if [[ $( calculate_line_length "$battery_string$voltage" ) -gt $COLS_INNER ]];then + print_data=$( create_print_line "$line_starter" "$battery_string" ) + print_screen_output "$print_data" + line_starter=' ' + battery_string='' + print_data=$( create_print_line "$line_starter" "$voltage" ) + print_screen_output "$print_data" + voltage='' + else + print_data=$( create_print_line "$line_starter" "$battery_string$voltage" ) + print_screen_output "$print_data" + line_starter=' ' + voltage='' + battery_string='' + fi + #echo two + if [[ $battery_data != '' ]];then + print_data=$( create_print_line "$line_starter" "$battery_data" ) + print_screen_output "$print_data" + fi + else + #echo three + print_data=$( create_print_line "$line_starter" "$battery_string$voltage$battery_data" ) + print_screen_output "$print_data" + fi + fi + line_starter=' ' + fi + done + elif [[ $B_SHOW_BATTERY_FORCED == 'true' ]];then + print_data=$( create_print_line "$line_starter" "No battery data found in /sys or dmidecode. Is one present?" ) + print_screen_output "$print_data" + fi + eval $LOGFE +} + print_cpu_data() { eval $LOGFS - local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data='' + local cpu_data='' i='' cpu_clock_speed='' cpu_multi_clock_data='' a_cpu_speeds='' local bmip_data='' cpu_cache='' cpu_vendor='' cpu_flags='' flag_feature='flags' - local a_cpu_working='' cpu_model='' cpu_clock='' cpu_null_error='' + local a_cpu_working='' cpu_model='' cpu_clock='' cpu_null_error='' max_speed='' local cpc_plural='' cpu_count_print='' model_plural='' cpu_data_string='' local cpu_physical_count='' cpu_core_count='' cpu_core_alpha='' cpu_type='' - local cpu_2_data='' line_starter='' + local cpu_2_data='' working_cpu='' temp1='' per_cpu_cores='' current_max_clock_nu='' + local line_starter="CPU:" multi_cpu_starter="${C1}clock speeds$SEP3${C2} " + local speed_starter='speed' ##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\"" # Array A_CPU_DATA always has one extra element: max clockfreq found. @@ -9189,6 +11965,8 @@ print_cpu_data() IFS="," a_cpu_working=(${A_CPU_DATA[0]}) + current_max_clock_nu=$(( ${#A_CPU_DATA[@]} - 1 )) + a_cpu_speeds=(${A_CPU_DATA[$current_max_clock_nu]}) IFS="$ORIGINAL_IFS" # Strange (and also some expected) behavior encountered. If print_screen_output() uses $1 @@ -9203,9 +11981,7 @@ print_cpu_data() cpu_model="${a_cpu_working[0]}" ## assemble data for output cpu_clock="${a_cpu_working[1]}" - cpu_vendor=${a_cpu_working[5]} - # set A_CPU_CORE_DATA get_cpu_core_count cpu_physical_count=${A_CPU_CORE_DATA[0]} @@ -9219,8 +11995,21 @@ print_cpu_data() model_plural='s' fi line_starter="CPU$cpc_plural:" - cpu_data_string="${cpu_count_print}${cpu_core_alpha} core" - cpu_data="${C1}${cpu_data_string}${C2} ${a_cpu_working[0]}$model_plural (${cpu_type})" + if [[ -z $BSD_TYPE ]];then + cpu_data_string="$cpu_count_print$cpu_core_alpha core" + cpu_data="${C1}$cpu_data_string${C2} ${a_cpu_working[0]}$model_plural ($cpu_type)" + else + if [[ $cpu_physical_count -gt 1 ]];then + per_cpu_cores=$(($cpu_core_count/$cpu_physical_count)) + cpu_data_string="${C1}Cores$SEP3${C2} $cpu_core_count ($cpu_physical_count $per_cpu_cores core cpus) " + else + cpu_data_string="${C1}Cores$SEP3${C2} $cpu_core_count " + fi + if [[ -n $cpu_type ]];then + cpu_type=" ($cpu_type)" + fi + cpu_data="$cpu_data_string${C1}model$SEP3${C2} ${a_cpu_working[0]}$cpu_type" + fi if [[ $B_SHOW_CPU == 'true' ]];then # update for multicore, bogomips x core count. if [[ $B_EXTRA_DATA == 'true' ]];then @@ -9228,14 +12017,17 @@ print_cpu_data() # ARM may use the faked 1 cpucorecount to make this work # echo $cpu_core_count $cpu_physical_count if [[ -n ${a_cpu_working[4]} ]];then - bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$(( $cpu_core_count * $cpu_physical_count ))" ) + # new arm shows bad bogomip value, so don't use it + if [[ ${a_cpu_working[4]%.*} -gt 50 ]];then + bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$(( $cpu_core_count * $cpu_physical_count ))" ) + fi bmip_data=${bmip_data%.*} fi # else # bmip_data="${a_cpu_working[4]}" # fi # bogomips are a linux thing, but my guess is over time bsds will use them somewhere anyway - if [[ $BSD_TYPE == 'bsd' && -z $bmip_data ]];then + if [[ -n $BSD_TYPE && -z $bmip_data ]];then bmip_data='' else bmip_data="${C1}bmips$SEP3${C2} $bmip_data " @@ -9244,10 +12036,14 @@ print_cpu_data() ## note: this handles how intel reports L2, total instead of per core like AMD does # note that we need to multiply by number of actual cpus here to get true cache size if [[ -n ${a_cpu_working[2]} ]];then - if [[ $cpu_vendor != 'intel' ]];then - cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$(( $cpu_core_count * $cpu_physical_count ))" ) + if [[ -z $BSD_TYPE ]];then + if [[ $cpu_vendor != 'intel' ]];then + cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$(( $cpu_core_count * $cpu_physical_count ))" ) + else + cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$cpu_physical_count" ) + fi else - cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$cpu_physical_count" ) + cpu_cache=${a_cpu_working[2]} fi else cpu_cache='N/A' @@ -9261,23 +12057,45 @@ print_cpu_data() if [[ ${a_cpu_working[6]} == 'true' ]];then flag_feature='features' fi - cpu_flags="${C1}$flag_feature$SEP3${C2} $cpu_flags " fi fi # arm cpus do not have flags or cache if [[ ${a_cpu_working[6]} != 'true' ]];then - cpu_data="$cpu_data${C2} ${C1}cache$SEP3${C2} $cpu_cache${CN}" - cpu_2_data="$cpu_flags$bmip_data${CN}" + cpu_data="$cpu_data${C2} ${C1}cache$SEP3${C2} $cpu_cache" + cpu_2_data="$cpu_flags$bmip_data" else - cpu_data="$cpu_data${C2} (ARM)$bmip_data${CN}" + cpu_data="$cpu_data${C2} (ARM)$bmip_data" fi fi # we don't this printing out extra line unless > 1 cpu core if [[ ${#A_CPU_DATA[@]} -gt 2 && $B_SHOW_CPU == 'true' ]];then cpu_clock_speed='' # null < verbosity level 5 else - cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]%.*} MHz${CN}" + if [[ -z ${a_cpu_working[1]} ]];then + if [[ -z ${cpu_data/*ARM*/} ]];then + temp1=' (ARM)' + fi + a_cpu_working[1]="N/A$temp1" + else + a_cpu_working[1]="${a_cpu_working[1]%.*} MHz" + fi + # this handles bsd case unless we get a way to get max/min cpu speeds + if [[ ${a_cpu_speeds[0]} != 'N/A' && ${a_cpu_speeds[2]} != 0 ]];then + if [[ $B_EXTRA_EXTRA_DATA == 'true' && ${#A_CPU_DATA[@]} -eq 2 && + $B_SHOW_CPU == 'true' && ${a_cpu_speeds[1]} != 0 ]];then + a_cpu_working[1]="${a_cpu_speeds[0]}/${a_cpu_speeds[1]}/${a_cpu_speeds[2]} MHz" + speed_starter='speed/min/max' + else + if [[ ${a_cpu_speeds[0]} == ${a_cpu_speeds[2]} ]];then + a_cpu_working[1]="${a_cpu_speeds[0]} MHz (max)" + else + a_cpu_working[1]="${a_cpu_speeds[0]}/${a_cpu_speeds[2]} MHz" + speed_starter='speed/max' + fi + fi + fi + cpu_clock_speed="${C1}$speed_starter$SEP3${C2} ${a_cpu_working[1]}" fi cpu_2_data="$cpu_2_data$cpu_clock_speed" else @@ -9288,40 +12106,59 @@ print_cpu_data() fi # echo $cpu_data $cpu_2_data # echo ln: $( calculate_line_length "$cpu_data $cpu_2_data" ) -# echo cpl: $( create_print_line "$line_starter" "${cpu_2_data}" ): +# echo cpl: $( create_print_line "$line_starter" "$cpu_2_data" ): # echo icols: $COLS_INNER # echo tc: $TERM_COLUMNS # echo :${cpu_2_data}: if [[ -n $cpu_2_data && $( calculate_line_length "$cpu_data $cpu_2_data" ) -gt $COLS_INNER ]];then - cpu_data=$( create_print_line "$line_starter" "${cpu_data}" ) - line_starter='' + cpu_data=$( create_print_line "$line_starter" "$cpu_data" ) + line_starter=' ' print_screen_output "$cpu_data" - cpu_data=$( create_print_line " " "${cpu_2_data}" ) + cpu_data=$( create_print_line " " "$cpu_2_data" ) print_screen_output "$cpu_data" else - cpu_data=$( create_print_line "$line_starter" "${cpu_data}" ) - print_screen_output "$cpu_data ${cpu_2_data}" + cpu_data=$( create_print_line "$line_starter" "$cpu_data" ) + print_screen_output "$cpu_data $cpu_2_data" fi - # we don't this printing out extra line unless > 1 cpu core + # we don't do this printing out extra line unless > 1 cpu core # note the numbering, the last array item is the min/max/not found for cpu speeds if [[ ${#A_CPU_DATA[@]} -gt 2 && $B_SHOW_CPU == 'true' ]];then + if [[ ${a_cpu_speeds[2]} != 0 ]];then + if [[ $B_EXTRA_EXTRA_DATA == 'true' && ${a_cpu_speeds[1]} != 0 ]];then + max_speed="${C1}min/max$SEP3${C2} ${a_cpu_speeds[1]}/${a_cpu_speeds[2]} MHz " + else + max_speed="${C1}max$SEP3${C2} ${a_cpu_speeds[2]} MHz " + fi + fi for (( i=0; i < ${#A_CPU_DATA[@]}-1; i++ )) do IFS="," a_cpu_working=(${A_CPU_DATA[i]}) IFS="$ORIGINAL_IFS" # note: the first iteration will create a first space, for color code separation below - cpu_multi_clock_data="$cpu_multi_clock_data ${C1}$(( i + 1 )):${C2} ${a_cpu_working[1]%.*} MHz${CN}" # someone actually appeared with a 16 core system, so going to stop the cpu core throttle # if this had some other purpose which we can't remember we'll add it back in #if [[ $i -gt 10 ]];then # break #fi + # echo $(calculate_line_length "$multi_cpu_starter$SEP3 $cpu_multi_clock_data" ) + working_cpu="$max_speed${C1}$(( i + 1 ))$SEP3${C2} ${a_cpu_working[1]%.*} MHz " + max_speed='' + if [[ -n $cpu_multi_clock_data && \ + $( calculate_line_length "$multi_cpu_starter$cpu_multi_clock_data$working_cpu" ) -gt $COLS_INNER ]];then + cpu_multi_clock_data=$( create_print_line " " "$multi_cpu_starter$cpu_multi_clock_data" ) + print_screen_output "$cpu_multi_clock_data" + multi_cpu_starter='' + cpu_multi_clock_data="$working_cpu" + else + cpu_multi_clock_data="$cpu_multi_clock_data$working_cpu" + fi done - if [[ -n $cpu_multi_clock_data ]];then - cpu_multi_clock_data=$( create_print_line " " "${C1}Clock Speeds:${C2}$cpu_multi_clock_data" ) - print_screen_output "$cpu_multi_clock_data" - fi + fi + # print the last line if it exists after loop + if [[ -n $cpu_multi_clock_data ]];then + cpu_multi_clock_data=$( create_print_line " " "$multi_cpu_starter$cpu_multi_clock_data" ) + print_screen_output "$cpu_multi_clock_data" fi if [[ $B_CPU_FLAGS_FULL == 'true' ]];then print_cpu_flags_full "${a_cpu_working[3]}" "${a_cpu_working[6]}" @@ -9337,7 +12174,7 @@ print_cpu_flags_full() # note: sort only sorts lines, not words in a string, so convert to lines local cpu_flags_full="$( echo $1 | tr " " "\n" | sort )" local a_cpu_flags='' line_starter='' temp_string='' - local i=0 counter=0 starter_length=15 flag='' flag_data='' + local i=0 counter=0 starter_length=0 flag='' flag_data='' local line_length='' flag_feature='Flags' spacer='' flag_string='' if [[ $2 == 'true' ]];then @@ -9362,11 +12199,13 @@ print_cpu_flags_full() a_cpu_flags[$counter]=$flag_string flag_string=$flag (( counter++ )) - fi + fi temp_string='' done if [[ -n $flag_string ]];then a_cpu_flags[$counter]=$flag_string + else + a_cpu_flags[$counter]='No CPU flag data found.' fi # then print it out for (( i=0; i < ${#a_cpu_flags[@]};i++ )) @@ -9380,6 +12219,40 @@ print_cpu_flags_full() eval $LOGFE } +# args: $1 - type [sys/bat/default]; $2 - get_dmidecode_data error return +print_dmidecode_error() +{ + eval $LOGFS + local error_message='Unknown dmidecode error.' + local sysDmiError='Using ' + + if [[ $1 == 'sys' || $1 == 'bat' ]];then + if [[ $B_FORCE_DMIDECODE == 'true' ]];then + sysDmiError='Forcing ' + # dragonfly has /sys, but it's empty + elif [[ $1 == 'sys' ]] && [[ $BSD_TYPE == '' || -d /sys/devices ]];then + sysDmiError='No /sys/class/dmi; using ' + #elif [[ $1 == 'bat' ]] && [[ $BSD_TYPE == '' || -d /sys/devices ]];then + # sysDmiError='No /sys/ battery; using ' + else + sysDmiError='Using ' + fi + fi + if [[ $2 == 'dmidecode-error-requires-root' ]];then + error_message="${sysDmiError}dmidecode: you must be root to run dmidecode" + elif [[ $2 == 'dmidecode-error-not-installed' ]];then + error_message="${sysDmiError}dmidecode: dmidecode is not installed." + elif [[ $2 == 'dmidecode-error-no-smbios-dmi-data' ]];then + error_message="${sysDmiError}dmidecode: no smbios data available. Old system?" + elif [[ $2 == 'dmidecode-error-no-battery-data' ]];then + error_message="${sysDmiError}dmidecode: no battery data available." + elif [[ $2 == 'dmidecode-error-unknown-error' ]];then + error_message="${sysDmiError}dmidecode: unknown error occured" + fi + echo $error_message + eval $LOGFE +} + print_graphics_data() { eval $LOGFS @@ -9389,7 +12262,7 @@ print_graphics_data() local spacer='' driver='' driver_string='' driver_plural='' direct_render_string='' local separator_loaded='' separator_unloaded='' separator_failed='' local loaded='' unloaded='' failed='' display_server_string='' - local line_starter='Graphics:' + local line_starter='Graphics:' part_1_data='' part_2_data='' local screen_resolution="$( get_graphics_res_data )" # set A_DISPLAY_SERVER_DATA @@ -9403,13 +12276,17 @@ print_graphics_data() # this can contain a long No case debugging message, so it's being sliced off # note: using grep -ioE '(No|Yes)' <<< ${A_GLX_DATA[2]} did not work in Arch, no idea why local glx_direct_render=$( gawk '{print $1}' <<< "${A_GLX_DATA[2]}" ) - + # set A_GRAPHICS_CARD_DATA if [[ $BSD_TYPE == 'bsd' ]];then - if [[ $B_PCICONF_SET == 'false' ]];then - get_pciconf_data + if [[ $B_PCICONF == 'true' ]];then + if [[ $B_PCICONF_SET == 'false' ]];then + get_pciconf_data + fi + get_pciconf_card_data 'display' + elif [[ $B_LSPCI == 'true' ]];then + get_graphics_card_data fi - get_pciconf_card_data 'display' else get_graphics_card_data fi @@ -9441,38 +12318,37 @@ print_graphics_data() done fi if [[ -n $loaded ]];then - driver="${driver} $loaded" + driver="$driver $loaded" fi if [[ -n $unloaded ]];then - driver="${driver} (unloaded: $unloaded)" + driver="$driver (unloaded: $unloaded)" fi if [[ -n $failed ]];then - driver="${driver} ${RED}FAILED:${C2} $failed" + driver="$driver ${RED}FAILED$SEP3${C2} $failed" fi # sometimes for some reason there is no driver found but the array is started if [[ -z $driver ]];then driver=' N/A' fi - if [[ ${#A_GRAPHIC_DRIVERS[@]} -gt 1 ]];then driver_plural='s' fi - driver_string="${C1}driver$driver_plural$SEP3${C2}$driver " - # some basic error handling: if [[ -z $screen_resolution ]];then screen_resolution='N/A' fi + # note: fix this, we may find a display server that has no version if [[ -z $display_vendor || -z $display_version ]];then display_vendor_string="N/A" else display_vendor_string="$display_vendor $display_version" fi display_server_string="${C1}Display Server${SEP3}${C2} $display_vendor_string " + driver_string="${C1}driver$driver_plural$SEP3${C2}$driver " if [[ $B_ROOT == 'true' ]];then root_x_string='for root ' - if [[ $B_RUNNING_IN_SHELL == 'true' || $B_CONSOLE_IRC == 'true' ]];then + if [[ $B_IRC == 'false' || $B_CONSOLE_IRC == 'true' ]];then res_tty='tty size' fi fi @@ -9482,12 +12358,10 @@ print_graphics_data() fi if [[ -n $root_x_string ]];then - root_x_string="${C1}Advanced Data:${C2} N/A $root_x_string" + root_x_string="${C1}Advanced Data$SEP3${C2} N/A $root_x_string" fi - - display_full_string="$display_server_string$driver_string${C1}${res_tty}$SEP3${C2} ${screen_resolution} $root_x_string" - - if [[ ${#A_GRAPHICS_CARD_DATA[@]} -gt 0 ]];then + # note, this comes out with a count of 1 sometimes for null data + if [[ ${A_GRAPHICS_CARD_DATA[0]} != '' ]];then for (( i=0; i < ${#A_GRAPHICS_CARD_DATA[@]}; i++ )) do IFS="," @@ -9497,7 +12371,7 @@ print_graphics_data() card_data=${a_graphics_working[0]} if [[ $B_EXTRA_DATA == 'true' ]];then if [[ -n ${a_graphics_working[1]} ]];then - card_bus_id=" ${C1}bus-ID$SEP3${C2} ${a_graphics_working[1]}" + card_bus_id="${a_graphics_working[1]}" if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then if [[ $BSD_TYPE != 'bsd' ]];then chip_id=$( get_lspci_chip_id "${a_graphics_working[1]}" ) @@ -9506,40 +12380,74 @@ print_graphics_data() fi fi else - card_bus_id=" ${C1}bus-ID$SEP3${C2} N/A" + card_bus_id='N/A' fi fi + if [[ -n $card_bus_id ]];then + card_bus_id="${C1}bus-ID$SEP3${C2} $card_bus_id " + fi if [[ -n $chip_id ]];then - chip_id=" ${C1}chip-ID$SEP3${C2} $chip_id" + chip_id="${C1}chip-ID$SEP3${C2} $chip_id" fi if [[ ${#A_GRAPHICS_CARD_DATA[@]} -gt 1 ]];then - card_id="Card-$(($i+1)):" - else - card_id='Card:' + card_id="-$(($i+1))" fi - graphics_data="${C1}$card_id${C2} $card_data$card_bus_id$chip_id " + + part_1_data="${C1}Card$card_id$SEP3${C2} $card_data " + part_2_data="$card_bus_id$chip_id" + if [[ ${#A_GRAPHICS_CARD_DATA[@]} -gt 1 ]];then - graphics_data=$( create_print_line "$line_starter" "${graphics_data}" ) - print_screen_output "$graphics_data" + if [[ $( calculate_line_length "$part_1_data$part_2_data" ) -gt $COLS_INNER ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data" ) + print_screen_output "$graphics_data" + part_1_data='' + line_starter=' ' + fi + if [[ -n $( grep -vE '^[[:space:]]*$' <<< $part_1_data$part_2_data ) ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data$part_2_data" ) + print_screen_output "$graphics_data" + fi + part_1_data='' + part_2_data='' line_starter=' ' graphics_data='' fi done # handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes.. else - graphics_data="${C1}Card:${C2} Failed to Detect Video Card! " + part_1_data="${C1}Card$SEP3${C2} Failed to Detect Video Card! " fi - if [[ -n $graphics_data && $( calculate_line_length "${graphics_data}$display_full_string" ) -lt $COLS_INNER ]];then - graphics_data=$( create_print_line "$line_starter" "${graphics_data}$display_full_string" ) - else - if [[ -n $graphics_data ]];then - graphics_data=$( create_print_line "$line_starter" "$graphics_data" ) + # Print cards if not dual card system + if [[ -n $part_1_data$part_2_data ]];then + if [[ $( calculate_line_length "$part_1_data$part_2_data" ) -gt $COLS_INNER ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data" ) print_screen_output "$graphics_data" + part_1_data='' line_starter=' ' fi - graphics_data=$( create_print_line "$line_starter" "$display_full_string" ) + if [[ -n $( grep -vE '^[[:space:]]*$' <<< $part_1_data$part_2_data ) ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data$part_2_data" ) + print_screen_output "$graphics_data" + fi + fi + line_starter=' ' + graphics_data='' + + part_1_data="$display_server_string$driver_string" + part_2_data="${C1}$res_tty$SEP3${C2} $screen_resolution $root_x_string" + if [[ -n $( grep -vE '^[[:space:]]*$' <<< $part_1_data$part_2_data ) && \ + $( calculate_line_length "$part_1_data $part_2_data" ) -gt $COLS_INNER ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data" ) + print_screen_output "$graphics_data" + line_starter=' ' + part_1_data='' + graphics_data=$part_2_data + fi + if [[ -n $( grep -vE '^[[:space:]]*$' <<< $part_1_data$part_2_data ) ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data$part_2_data" ) + print_screen_output "$graphics_data" + line_starter=' ' fi - print_screen_output "$graphics_data" # if [[ -z $glx_renderer || -z $glx_version ]];then # b_is_mesa='true' # fi @@ -9557,12 +12465,21 @@ print_graphics_data() glx_direct_render='N/A' fi if [[ $B_HANDLE_CORRUPT_DATA == 'true' || $B_EXTRA_DATA == 'true' ]];then - direct_render_string=" ${C1}Direct Rendering$SEP3${C2} ${glx_direct_render}${CN}" + direct_render_string=" ${C1}Direct Rendering$SEP3${C2} $glx_direct_render" + fi + part_1_data="${C1}GLX Renderer$SEP3${C2} $glx_renderer " + part_2_data="${C1}GLX Version$SEP3${C2} $glx_version$direct_render_string" + # echo $line_starter + if [[ $( calculate_line_length "$part_1_data$part_2_data" ) -gt $COLS_INNER ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data" ) + print_screen_output "$graphics_data" + part_1_data='' + line_starter=' ' + fi + if [[ -n $part_1_data$part_2_data ]];then + graphics_data=$( create_print_line "$line_starter" "$part_1_data$part_2_data" ) + print_screen_output "$graphics_data" fi - graphics_data="${C1}GLX Renderer$SEP3${C2} ${glx_renderer} ${C1}GLX Version$SEP3${C2} ${glx_version}${CN}$direct_render_string" - graphics_data=$( create_print_line " " "$graphics_data" ) - - print_screen_output "$graphics_data" fi eval $LOGFE } @@ -9571,11 +12488,10 @@ print_hard_disk_data() { eval $LOGFS local hdd_data='' hdd_data_2='' a_hdd_working='' hdd_temp_data='' hdd_string='' - local hdd_serial='' - local dev_data='' size_data='' hdd_model='' usb_data='' hdd_name='' divisor=5 + local hdd_serial='' dev_string='/dev/' + local dev_data='' size_data='' hdd_model='' usb_data='' hdd_name='' local Line_Starter='Drives:' # inherited by print_optical_drives - - # load A_HDD_DATA + # load A_HDD_DATA - this will also populate the full bsd disk data array values get_hdd_data_basic ## note: if hdd_model is declared prior to use, whatever string you want inserted will ## be inserted first. In this case, it's desirable to print out (x) before each disk found. @@ -9585,102 +12501,122 @@ print_hard_disk_data() IFS="$ORIGINAL_IFS" local hdd_capacity="${a_hdd_basic_working[0]}" local hdd_used=${a_hdd_basic_working[1]} - local bsd_unsupported='Hard drive data not yet supported for BSD systems.' - local hdd_name_temp='' + local bsd_error="No HDD Info. $FILE_DMESG_BOOT not readable?" + local hdd_name_temp='' part_1_data='' part_2_data='' + local row_starter="${C1}HDD Total Size$SEP3${C2} $hdd_capacity ($hdd_used) " + # in bsd, /dev/wd0c is disk id + if [[ -n $BSD_TYPE ]];then + dev_string='' + fi if [[ $B_SHOW_BASIC_DISK == 'true' || $B_SHOW_DISK == 'true' ]];then - ## note: the output part of this should be in the print hdd data function, not here + ## note: the output part of this should be in the print hdd data function, not here get_hard_drive_data_advanced - for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ )) - do - # this adds the (x) numbering in front of each disk found, and creates the full disk string - IFS="," - a_hdd_working=( ${A_HDD_DATA[i]} ) - IFS="$ORIGINAL_IFS" - if [[ $B_SHOW_DISK == 'true' ]];then - if [[ -n ${a_hdd_working[3]} ]];then - usb_data="${a_hdd_working[3]} " - else - usb_data='' - fi - dev_data="/dev/${a_hdd_working[0]} " - size_data=" ${C1}size$SEP3${C2} ${a_hdd_working[1]}" - if [[ $B_EXTRA_DATA == 'true' && -n $dev_data ]];then - hdd_temp_data=$( get_hdd_temp_data "$dev_data" ) - # error handling is done in get data function - if [[ -n $hdd_temp_data ]];then - hdd_temp_data=" ${C1}temp$SEP3${C2} ${hdd_temp_data}C" + + # temporary message to indicate not yet supported + if [[ $BSD_TYPE == 'bsd' && -z $Dmesg_Boot_Data ]];then + hdd_data=$bsd_error + hdd_data=$( create_print_line "$Line_Starter" "$hdd_data" ) + print_screen_output "$hdd_data" + Line_Starter=' ' + else + for (( i=0; i < ${#A_HDD_DATA[@]} - 1; i++ )) + do + # this adds the (x) numbering in front of each disk found, and creates the full disk string + IFS="," + a_hdd_working=( ${A_HDD_DATA[i]} ) + IFS="$ORIGINAL_IFS" + if [[ $B_SHOW_DISK == 'true' ]];then + if [[ -n ${a_hdd_working[3]} ]];then + usb_data="${a_hdd_working[3]} " else - hdd_temp_data='' + usb_data='' fi - fi - if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then - hdd_serial=$( get_hdd_serial_number "${a_hdd_working[0]}" ) - if [[ -z $hdd_serial ]];then - hdd_serial='N/A' + size_data=" ${C1}size$SEP3${C2} ${a_hdd_working[1]}" + if [[ $B_EXTRA_DATA == 'true' ]];then + hdd_temp_data=${a_hdd_working[5]} + # error handling is done in get data function + if [[ -n $hdd_temp_data ]];then + hdd_temp_data=" ${C1}temp$SEP3${C2} ${hdd_temp_data}C" + else + hdd_temp_data='' + fi + fi + if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then + hdd_serial=${a_hdd_working[4]} + if [[ -z $hdd_serial ]];then + hdd_serial='N/A' + fi + hdd_serial=" ${C1}serial$SEP3${C2} $hdd_serial" fi - hdd_serial=" ${C1}serial$SEP3${C2} $hdd_serial" - divisor=1 # print every line + dev_data="$dev_string${a_hdd_working[0]} " + fi + if [[ -n ${a_hdd_working[2]} ]];then + hdd_name_temp=${a_hdd_working[2]} else - divisor=2 # for modulus line print out, either 2 items for full, or default for short + hdd_name_temp='N/A' fi - dev_data="${C1}id$SEP3${C2} /dev/${a_hdd_working[0]} " - fi - if [[ -n ${a_hdd_working[2]} ]];then - hdd_name_temp=${a_hdd_working[2]} - else - hdd_name_temp='N/A' - fi - hdd_name="${C1}model$SEP3${C2} $hdd_name_temp" - hdd_string="$usb_data$dev_data$hdd_name$size_data$hdd_serial$hdd_temp_data" - hdd_model="${hdd_model}${C1}$(($i+1)):${C2} $hdd_string " - # printing line one, then new lines according to $divisor setting, and after, if leftovers, print that line. - case $i in - 0) - if [[ $divisor -eq 1 ]];then - hdd_data=$( create_print_line "$Line_Starter" "${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used})" ) + # echo "loop: $i" + hdd_name="${C1}model$SEP3${C2} $hdd_name_temp" + hdd_string="${C1}ID-$((i+1))$SEP3${C2} $usb_data$dev_data$hdd_name$size_data$hdd_serial$hdd_temp_data" + part_1_data="$hdd_model$hdd_string " + + if [[ $i -eq 0 ]];then + if [[ $( calculate_line_length "$row_starter$part_1_data" ) -gt $COLS_INNER ]];then + hdd_data=$( create_print_line "$Line_Starter" "$row_starter" ) print_screen_output "$hdd_data" + #echo 0 Line_Starter=' ' - hdd_data=$( create_print_line "$Line_Starter" "${hdd_model}" ) + row_starter='' + hdd_data=$( create_print_line "$Line_Starter" "$part_1_data" ) print_screen_output "$hdd_data" - hdd_model='' + part_1_data='' + #echo 1 else - hdd_data=$( create_print_line "$Line_Starter" "${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used}) ${hdd_model}" ) + hdd_data=$( create_print_line "$Line_Starter" "$row_starter$part_1_data" ) print_screen_output "$hdd_data" - hdd_model='' Line_Starter=' ' + row_starter='' + part_1_data='' + #echo 2 fi - ;; - *) - # using modulus here, if divisible by $divisor, print line, otherwise skip - if [[ $(( $i % $divisor )) -eq 0 ]];then - hdd_data=$( create_print_line "$Line_Starter" "${hdd_model}${CN}" ) + fi + if [[ $( calculate_line_length "$row_starter$part_2_data$part_1_data" ) -gt $COLS_INNER ]];then + if [[ -n $( grep -vE '^[[:space:]]*$' <<< $part_2_data ) ]];then + hdd_data=$( create_print_line "$Line_Starter" "$row_starter$part_2_data" ) print_screen_output "$hdd_data" - hdd_model='' + #echo 3 Line_Starter=' ' + row_starter='' + part_2_data='' fi - ;; - esac - done - # then print any leftover items - if [[ -n $hdd_model ]];then - hdd_data=$( create_print_line "$Line_Starter" "${hdd_model}${CN}" ) - print_screen_output "$hdd_data" - fi - # temporary message to indicate not yet supported - if [[ $BSD_TYPE == 'bsd' ]];then - hdd_data=$bsd_unsupported - hdd_data=$( create_print_line "$Line_Starter" "$hdd_data${CN}" ) - print_screen_output "$hdd_data" - Line_Starter=' ' + hdd_data=$( create_print_line "$Line_Starter" "$row_starter$part_1_data" ) + print_screen_output "$hdd_data" + part_1_data='' + #echo 4 + elif [[ -n $part_2_data && \ + $( calculate_line_length "$row_starter$part_2_data$part_1_data" ) -le $COLS_INNER ]];then + hdd_data=$( create_print_line "$Line_Starter" "$row_starter$part_2_data$part_1_data" ) + print_screen_output "$hdd_data" + #echo 3 + Line_Starter=' ' + row_starter='' + part_1_data='' + part_2_data='' + else + part_2_data=$part_1_data + fi + done + # then print any leftover items + if [[ -n $part_2_data ]];then + hdd_data=$( create_print_line "$Line_Starter" "$part_2_data" ) + print_screen_output "$hdd_data" + #echo 5 + fi fi else - # temporary message to indicate not yet supported - hdd_data="${C1}HDD Total Size:${C2} ${hdd_capacity} (${hdd_used})" - if [[ $BSD_TYPE == 'bsd' ]];then - hdd_data=$bsd_unsupported - fi - hdd_data=$( create_print_line "$Line_Starter" "$hdd_data${CN}" ) + hdd_data="$row_starter" + hdd_data=$( create_print_line "$Line_Starter" "$hdd_data" ) print_screen_output "$hdd_data" Line_Starter=' ' fi @@ -9701,8 +12637,11 @@ print_info_data() local memory="$( get_memory_data )" local processes=$(( $( wc -l <<< "$Ps_aux_Data" ) - 1 )) local up_time="$( get_uptime )" + if [[ -z $up_time ]];then + up_time='N/A - missing uptime?' + fi local patch_version_number=$( get_patch_version_string ) - local gcc_string='' gcc_installed='' gcc_others='' closing_data='' + local gcc_installed='' gcc_others='' closing_data='' if [[ -z $memory ]];then memory='N/A' @@ -9717,12 +12656,13 @@ print_info_data() gcc_installed='N/A' fi if [[ $B_EXTRA_EXTRA_DATA == 'true' && -n ${A_GCC_VERSIONS[1]} ]];then - gcc_others=" ${C1}alt$SEP3${C2} $( tr ',' '/' <<< ${A_GCC_VERSIONS[1]} )" + # gcc_others=" ${C1}alt$SEP3${C2} $( tr ',' '/' <<< ${A_GCC_VERSIONS[1]} )" + gcc_others=" ${C1}alt$SEP3${C2} ${A_GCC_VERSIONS[1]//,//}" fi gcc_installed="${C1}Gcc sys$SEP3${C2} $gcc_installed$gcc_others " fi fi - if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ $B_IRC == 'false' ]];then shell_data=$( get_shell_data ) if [[ -n $shell_data ]];then # note, if you start this in tty, it will give 'login' as the parent, which we don't want. @@ -9736,7 +12676,7 @@ print_info_data() if [[ $shell_parent == 'login' ]];then shell_parent='' elif [[ -n $shell_parent ]];then - shell_parent=" running in $shell_parent" + shell_parent=" running in ${shell_parent##*/}" fi fi IRC_CLIENT="$IRC_CLIENT ($shell_data$shell_parent)" @@ -9744,8 +12684,8 @@ print_info_data() fi # Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch! - # long_last=$( echo -ne "${C1}Processes$SEP3${C2} ${processes}${CN} | ${C1}Uptime$SEP3${C2} ${up_time}${CN} | ${C1}Memory$SEP3${C2} ${MEM}${CN}" ) - info_data="${C1}Processes$SEP3${C2} ${processes} ${C1}Uptime$SEP3${C2} ${up_time} ${C1}Memory$SEP3${C2} ${memory}${CN} " + # long_last=$( echo -ne "${C1}Processes$SEP3${C2} $processes${CN} | ${C1}Uptime$SEP3${C2} $up_time${CN} | ${C1}Memory$SEP3${C2} $MEM${CN}" ) + info_data="${C1}Processes$SEP3${C2} $processes ${C1}Uptime$SEP3${C2} $up_time ${C1}Memory$SEP3${C2} $memory " # this only triggers if no X data is present or if extra data switch is on if [[ $B_SHOW_DISPLAY_DATA != 'true' || $B_EXTRA_DATA == 'true' ]];then @@ -9757,7 +12697,6 @@ print_info_data() if [[ -z $init_type ]];then init_type='N/A' fi - if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then init_version=${A_INIT_DATA[1]} if [[ -z $init_version ]];then @@ -9766,18 +12705,16 @@ print_info_data() init_version=" ${C1}v$SEP3${C2} $init_version" rc_version=${A_INIT_DATA[3]} if [[ -n $rc_version ]];then - rc_version=" ${C1}v$SEP3${C2} $rc_version" + rc_version="${C1}v$SEP3${C2} $rc_version " fi - runlvl_default=${A_INIT_DATA[5]} fi # currently only using openrc here, otherwise show nothing rc_type=${A_INIT_DATA[2]} if [[ -n $rc_type ]];then - rc_type=" ${C1}rc$SEP3${C2} $rc_type$rc_version" + rc_type="${C1}rc$SEP3${C2} $rc_type $rc_version" fi init_type="${C1}Init$SEP3${C2} $init_type$init_version " - runlvl=${A_INIT_DATA[4]} if [[ -n $runlvl ]];then runlvl="${C1}$runlvl_title$SEP3${C2} $runlvl " @@ -9788,63 +12725,64 @@ print_info_data() init_data="$init_type$rc_type$runlvl$runlvl_default" fi if [[ $SHOW_IRC -gt 0 ]];then - client_data="${C1}Client$SEP3${C2} ${IRC_CLIENT}${IRC_CLIENT_VERSION} " + client_data="${C1}Client$SEP3${C2} $IRC_CLIENT$IRC_CLIENT_VERSION " fi - info_data="${info_data}" - closing_data="$client_data${C1}$SCRIPT_NAME$SEP3${C2} $SCRIPT_VERSION_NUMBER$patch_version_number${CN}" - + # info_data="$info_data" + closing_data="$client_data${C1}$SCRIPT_NAME$SEP3${C2} $SCRIPT_VERSION_NUMBER$patch_version_number" # sometimes gcc is very long, and default runlevel can be long with systemd, so create a gcc-less line first - if [[ $( calculate_line_length "${info_data}${init_data}${gcc_installed}${closing_data}" ) -gt $COLS_INNER ]];then - info_data=${info_data}${init_data} + if [[ $( calculate_line_length "$info_data$init_data$gcc_installed" ) -gt $COLS_INNER ]];then + # info_data=$info_data info_data=$( create_print_line "$line_starter" "$info_data" ) print_screen_output "$info_data" - init_data='' info_data='' # closing_data='' line_starter=' ' #echo 1 fi - if [[ $( calculate_line_length "${info_data}${init_data}${gcc_installed}${closing_data}" ) -gt $COLS_INNER ]];then - info_data=${info_data}${init_data}${gcc_installed} + if [[ $( calculate_line_length "$init_data$gcc_installed" ) -gt $COLS_INNER ]];then + info_data=$init_data info_data=$( create_print_line "$line_starter" "$info_data" ) print_screen_output "$info_data" info_data='' - gcc_installed='' init_data='' line_starter=' ' #echo 2 fi - info_data="${info_data}${init_data}${gcc_installed}${closing_data}" + if [[ $( calculate_line_length "$info_data$init_data$gcc_installed$closing_data" ) -gt $COLS_INNER ]];then + info_data=$info_data$init_data$gcc_installed + info_data=$( create_print_line "$line_starter" "$info_data" ) + print_screen_output "$info_data" + info_data='' + gcc_installed='' + init_data='' + line_starter=' ' + #echo 3 + fi + info_data="$info_data$init_data$gcc_installed$closing_data" info_data=$( create_print_line "$line_starter" "$info_data" ) if [[ $SCHEME -gt 0 ]];then - info_data="${info_data} ${NORMAL}" + info_data="$info_data ${NORMAL}" fi print_screen_output "$info_data" eval $LOGFE } - +#print_info_data;exit print_machine_data() { eval $LOGFS local system_line='' mobo_line='' bios_line='' chassis_line='' local mobo_vendor='' mobo_model='' mobo_version='' mobo_serial='' - local bios_vendor='' bios_version='' bios_date='' bios_rom='' + local bios_vendor='' bios_version='' bios_date='' bios_rom='' error_string='' local system_vendor='' product_name='' product_version='' product_serial='' product_uuid='' local chassis_vendor='' chassis_type='' chassis_version='' chassis_serial='' local b_skip_system='false' b_skip_chassis='false' - local sysDmiError='No /sys/class/dmi, using ' local sysDmiNull='No /sys/class/dmi machine data: try newer kernel, or install dmidecode' # set A_MACHINE_DATA get_machine_data - if [[ -n $BSD_TYPE ]];then - sysDmiError='' - sysDmiNull='No machine data available. Is dmidecode installed?' - fi - IFS=',' ## keys for machine data are: # 0-sys_vendor 1-product_name 2-product_version 3-product_serial 4-product_uuid @@ -9852,8 +12790,8 @@ print_machine_data() # 9-bios_vendor 10-bios_version 11-bios_date ## with extra data: # 12-chassis_vendor 13-chassis_type 14-chassis_version 15-chassis_serial - - if [[ ${#A_MACHINE_DATA[@]} -gt 0 ]];then + # a null array always has a count of 1 + if [[ ${#A_MACHINE_DATA[@]} -gt 1 ]];then # note: in some case a mobo/version will match a product name/version, do not print those # but for laptops, or even falsely id'ed desktops with batteries, let's print it all if it matches # there can be false id laptops if battery appears so need to make sure system is filled @@ -9886,7 +12824,7 @@ print_machine_data() chassis_type=" ${C1}type$SEP3${C2} ${A_MACHINE_DATA[13]}" fi if [[ -n ${A_MACHINE_DATA[14]} ]];then - chassis_version=" ${C1}version$SEP3${C2} ${A_MACHINE_DATA[14]}" + chassis_version=" ${C1}v$SEP3${C2} ${A_MACHINE_DATA[14]}" fi if [[ -n ${A_MACHINE_DATA[15]} && $B_OUTPUT_FILTER != 'true' ]];then chassis_serial=" ${C1}serial$SEP3${C2} ${A_MACHINE_DATA[15]}" @@ -9907,7 +12845,7 @@ print_machine_data() mobo_model='N/A' fi if [[ -n ${A_MACHINE_DATA[7]} ]];then - mobo_version=" ${C1}version$SEP3${C2} ${A_MACHINE_DATA[7]}" + mobo_version=" ${C1}v$SEP3${C2} ${A_MACHINE_DATA[7]}" fi if [[ -n ${A_MACHINE_DATA[8]} && $B_OUTPUT_FILTER != 'true' ]];then mobo_serial=" ${C1}serial$SEP3${C2} ${A_MACHINE_DATA[8]}" @@ -9934,7 +12872,7 @@ print_machine_data() bios_rom=" ${C1}rom size$SEP3${C2} ${A_MACHINE_DATA[17]}" fi mobo_line="${C1}Mobo$SEP3${C2} $mobo_vendor ${C1}model$SEP3${C2} $mobo_model$mobo_version$mobo_serial" - bios_line="${C1}Bios$SEP3${C2} $bios_vendor ${C1}version$SEP3${C2} $bios_version ${C1}date$SEP3${C2} $bios_date$bios_rom" + bios_line="${C1}Bios$SEP3${C2} $bios_vendor ${C1}v$SEP3${C2} $bios_version ${C1}date$SEP3${C2} $bios_date$bios_rom" if [[ $( calculate_line_length "$mobo_line$bios_line" ) -lt $COLS_INNER ]];then mobo_line="$mobo_line $bios_line" bios_line='' @@ -9954,7 +12892,7 @@ print_machine_data() product_name='N/A' fi if [[ -n ${A_MACHINE_DATA[2]} ]];then - product_version=" ${C1}version$SEP3${C2} ${A_MACHINE_DATA[2]}" + product_version=" ${C1}v$SEP3${C2} ${A_MACHINE_DATA[2]}" fi if [[ -n ${A_MACHINE_DATA[3]} && $B_OUTPUT_FILTER != 'true' ]];then product_serial=" ${C1}serial$SEP3${C2} ${A_MACHINE_DATA[3]} " @@ -9965,17 +12903,14 @@ print_machine_data() chassis_line='' fi fi - IFS="$ORIGINAL_IFS" else - system_line="${C2}$sysDmiNull${CN}" + system_line="${C2}$sysDmiNull" fi - # patch to dump all of above if dmidecode was data source and non root user - if [[ ${A_MACHINE_DATA[0]} == 'dmidecode-non-root-user' || ${A_MACHINE_DATA[0]} == 'dmidecode-no-smbios-dmi-data' ]];then - if [[ ${A_MACHINE_DATA[0]} == 'dmidecode-non-root-user' ]];then - system_line="${C2}${sysDmiError}dmidecode: you must be root to run dmidecode${CN}" - elif [[ ${A_MACHINE_DATA[0]} == 'dmidecode-no-smbios-dmi-data' ]];then - system_line="${C2}${sysDmiError}dmidecode: no machine data available${CN}" - fi + IFS="$ORIGINAL_IFS" + # patch to dump all of above if dmidecode was data source and a dmidecode error is present + if [[ ${A_MACHINE_DATA[0]} == 'dmidecode-error-'* ]];then + error_string=$( print_dmidecode_error 'sys' "${A_MACHINE_DATA[0]}" ) + system_line=${C2}$error_string mobo_line='' bios_line='' chassis_line='' @@ -10009,8 +12944,8 @@ print_module_version() if [[ -z $( grep -E '^snd' <<< $modules ) ]];then prefix='snd_' # sound modules start with snd_ fi - modules=$( tr '[A-Z]' '[a-z]' <<< $modules ) - modules=$( tr '-' '_' <<< $modules ) + modules=$( tr '[A-Z]' '[a-z]' <<< "$modules" ) + modules=${modules//-/_} # special intel processing, generally no version info though if [[ $modules == 'hda intel' ]];then modules='hda_intel' @@ -10028,7 +12963,7 @@ print_module_version() done if [[ -n $module_versions ]];then - echo " ${C1}ver$SEP3${C2}$module_versions" + echo " ${C1}v$SEP3${C2}$module_versions" fi eval $LOGFE } @@ -10039,13 +12974,18 @@ print_networking_data() local i='' card_id='' network_data='' a_network_working='' port_data='' driver_data='' local card_string='' port_plural='' module_version='' pci_bus_id='' bus_usb_text='' local bus_usb_id='' line_starter='Network:' card_string='' card_data='' chip_id='' - local driver='' + local driver='' part_2_data='' + # set A_NETWORK_DATA if [[ $BSD_TYPE == 'bsd' ]];then - if [[ $B_PCICONF_SET == 'false' ]];then - get_pciconf_data + if [[ $B_PCICONF == 'true' ]];then + if [[ $B_PCICONF_SET == 'false' ]];then + get_pciconf_data + fi + get_pciconf_card_data 'network' + elif [[ $B_LSPCI == 'true' ]];then + get_networking_data fi - get_pciconf_card_data 'network' else get_networking_data fi @@ -10068,11 +13008,11 @@ print_networking_data() pci_bus_id='' port_data='' port_plural='' - card_id='' chip_id='' + part_2_data='' if [[ ${#A_NETWORK_DATA[@]} -gt 1 ]];then - chip_id="-$(( $i + 1 ))" + card_id="-$(( $i + 1 ))" fi if [[ -n ${a_network_working[1]} && $B_EXTRA_DATA == 'true' && $BSD_TYPE != 'bsd' ]];then module_version=$( print_module_version "${a_network_working[1]}" ) @@ -10084,7 +13024,7 @@ print_networking_data() else driver=${a_network_working[1]} fi - driver_data="${C1}driver$SEP3${C2} ${driver}$module_version " + driver_data="${C1}driver$SEP3${C2} $driver$module_version " fi if [[ -n ${a_network_working[2]} && $B_EXTRA_DATA == 'true' ]];then if [[ $( wc -w <<< ${a_network_working[2]} ) -gt 1 ]];then @@ -10115,23 +13055,37 @@ print_networking_data() chip_id=" ${C1}chip-ID$SEP3${C2} $chip_id" fi fi - card_string="${C1}Card$card_id:${C2} ${a_network_working[0]} " - card_data="$driver_data$port_data$pci_bus_id$chip_id" - if [[ $( calculate_line_length "$card_string$card_data" ) -gt $COLS_INNER ]];then + card_string="${C1}Card$card_id$SEP3${C2} ${a_network_working[0]} " + card_data="$driver_data$port_data" + part_2_data="$pci_bus_id$chip_id" + if [[ $( calculate_line_length "$card_string$card_data$part_2_data" ) -gt $COLS_INNER ]];then network_data=$( create_print_line "$line_starter" "$card_string" ) line_starter=' ' card_string='' print_screen_output "$network_data" fi - network_data=$( create_print_line "$line_starter" "$card_string$card_data" ) - line_starter=' ' - print_screen_output "$network_data" + if [[ $( calculate_line_length "$card_string$card_data$part_2_data" ) -gt $COLS_INNER ]];then + network_data=$( create_print_line "$line_starter" "$card_string$card_data" ) + print_screen_output "$network_data" + line_starter=' ' + card_data='' + card_string='' + + fi + if [[ -n $card_string$card_data$part_2_data ]];then + network_data=$( create_print_line "$line_starter" "$card_string$card_data$part_2_data" ) + print_screen_output "$network_data" + line_starter=' ' + card_data='' + card_string='' + part_2_data='' + fi if [[ $B_SHOW_ADVANCED_NETWORK == 'true' ]];then print_network_advanced_data fi done else - network_data="${C1}Card:${C2} Failed to Detect Network Card! " + network_data="${C1}Card$SEP3${C2} Failed to Detect Network Card! " network_data=$( create_print_line "$line_starter" "$network_data" ) print_screen_output "$network_data" fi @@ -10145,7 +13099,7 @@ print_network_advanced_data() { eval $LOGFS local network_data='' if_id='N/A' duplex='N/A' mac_id='N/A' speed='N/A' oper_state='N/A' - local b_is_wifi='false' speed_string='' duplex_string='' + local b_is_wifi='false' speed_string='' duplex_string='' part_2_data='' # first check if it's a known wifi id'ed card, if so, no print of duplex/speed if [[ -n $( grep -Esi '(wireless|wifi|wi-fi|wlan|802\.11|centrino)' <<< ${a_network_working[0]} ) ]];then @@ -10182,9 +13136,18 @@ print_network_advanced_data() mac_id=${a_network_working[9]} fi fi - network_data="${C1}IF:${C2} $if_id ${C1}state$SEP3${C2} $oper_state $speed_string$duplex_string${C1}mac$SEP3${C2} $mac_id" - network_data=$( create_print_line " " "$network_data" ) - print_screen_output "$network_data" + network_data="${C1}IF$SEP3${C2} $if_id ${C1}state$SEP3${C2} $oper_state $speed_string$duplex_string" + part_2_data="${C1}mac$SEP3${C2} $mac_id" + if [[ $( calculate_line_length "$network_data$part_2_data" ) -gt $COLS_INNER ]];then + network_data=$( create_print_line " " "$network_data" ) + print_screen_output "$network_data" + network_data='' + fi + if [[ -n $network_data$part_2_data ]];then + network_data=$( create_print_line " " "$network_data$part_2_data" ) + print_screen_output "$network_data" + network_data='' + fi eval $LOGFE } @@ -10193,10 +13156,9 @@ print_networking_ip_data() { eval $LOGFS local ip=$( get_networking_wan_ip_data ) - local wan_ip_data='' a_interfaces_working='' interfaces='' i='' + local wan_ip_data='' a_interfaces_working='' interfaces='' i=0 local if_id='' if_ip='' if_ipv6='' if_ipv6_string='' full_string='' if_string='' - local if_id_string='' if_ip_string='' - local line_max=$(( $COLS_INNER - 40 )) + local if_id_string='' if_ip_string='' if_string_holding='' # set A_INTERFACES_DATA get_networking_local_ip_data @@ -10208,7 +13170,7 @@ print_networking_ip_data() ip=$FILTER_STRING fi fi - wan_ip_data="${C1}WAN IP:${C2} $ip " + wan_ip_data="${C1}WAN IP$SEP3${C2} $ip " # then create the list of local interface/ip i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1 while [[ -n ${A_INTERFACES_DATA[i]} ]] @@ -10228,7 +13190,7 @@ print_networking_ip_data() if_ip=${a_interfaces_working[1]} fi fi - if_ip_string=" ${C1}ip$SEP3${C2} $if_ip" + if_ip_string=" ${C1}ip-v4$SEP3${C2} $if_ip" if [[ $B_EXTRA_DATA == 'true' ]];then if [[ -n ${a_interfaces_working[3]} ]];then if [[ $B_OUTPUT_FILTER == 'true' ]];then @@ -10243,19 +13205,39 @@ print_networking_ip_data() if [[ -n ${a_interfaces_working[0]} ]];then if_id=${a_interfaces_working[0]} fi - if_string="$wan_ip_data$if_string${C1}IF:${C2} $if_id$if_ip_string$if_ipv6_string " - wan_ip_data='' - if [[ $( calculate_line_length "$if_string" ) -gt $line_max ]];then - full_string=$( create_print_line " " "$if_string" ) - print_screen_output "$full_string" - if_string='' + if_string="${C1}IF$SEP3${C2} $if_id$if_ip_string$if_ipv6_string " + # first line, print wan on its own line if too long + if [[ $i -eq 0 ]];then + if [[ $( calculate_line_length "$wan_ip_data$if_string" ) -gt $COLS_INNER ]];then + full_string=$( create_print_line " " "$wan_ip_data" ) + print_screen_output "$full_string" + wan_ip_data='' + full_string=$( create_print_line " " "$if_string" ) + print_screen_output "$full_string" + if_string='' + else + full_string=$( create_print_line " " "$wan_ip_data$if_string" ) + print_screen_output "$full_string" + wan_ip_data='' + if_string='' + fi + else + if [[ $( calculate_line_length "$if_string_holding$if_string" ) -gt $COLS_INNER ]];then + if [[ -n $if_string_holding ]];then + full_string=$( create_print_line " " "$if_string_holding" ) + print_screen_output "$full_string" + fi + if_string_holding="$if_string" + else + if_string_holding="$if_string_holding$if_string" + fi fi ((i++)) done # then print out anything not printed already - if [[ -n $if_string ]];then - full_string=$( create_print_line " " "$if_string" ) + if [[ -n $if_string_holding ]];then + full_string=$( create_print_line " " "$if_string_holding" ) print_screen_output "$full_string" fi eval $LOGFE @@ -10264,10 +13246,16 @@ print_networking_ip_data() print_optical_drive_data() { eval $LOGFS - local a_drives='' drive_data='' counter='' + local a_drives='' drive_data='' counter='' dev_string='/dev/' speed_string='x' local drive_id='' drive_links='' vendor='' speed='' multisession='' mcn='' audio='' - local dvd='' state='' rw_support='' rev='' separator='' drive_string='' - get_optical_drive_data + local dvd='' state='' rw_support='' rev='' separator='' drive_string='' part_2_data='' + if [[ -z $BSD_TYPE ]];then + get_optical_drive_data + else + get_optical_drive_data_bsd + dev_string='' + speed_string='' + fi # 0 - true dev path, ie, sr0, hdc # 1 - dev links to true path # 2 - device vendor - for hdx drives, vendor model are one string from proc @@ -10302,7 +13290,7 @@ print_optical_drive_data() if [[ -z ${a_drives[0]} ]];then drive_id='N/A' else - drive_id="/dev/${a_drives[0]}" + drive_id="$dev_string${a_drives[0]}" fi drive_links=$( sed 's/~/,/g' <<< ${a_drives[1]} ) if [[ -z $drive_links ]];then @@ -10327,14 +13315,43 @@ print_optical_drive_data() else rev='N/A' fi - rev=" ${C1}rev$SEP3${C2} $rev" + rev="${C1}rev$SEP3${C2} $rev " fi - drive_string="$drive_id ${C1}model$SEP3${C2} $vendor$rev ${C1}dev-links$SEP3${C2} $drive_links" + drive_string="$drive_id ${C1}model$SEP3${C2} $vendor " + part_2_data="$rev${C1}dev-links$SEP3${C2} $drive_links" fi - drive_data="${C1}Optical${counter}:${C2} $drive_string" - drive_data=$( create_print_line "$Line_Starter" "$drive_data" ) - print_screen_output "$drive_data" - Line_Starter=' ' + drive_data="${C1}Optical${counter}$SEP3${C2} $drive_string" + if [[ $( calculate_line_length "$drive_data$part_2_data" ) -lt $COLS_INNER ]];then + drive_data=$( create_print_line "$Line_Starter" "$drive_data$part_2_data" ) + print_screen_output "$drive_data" + Line_Starter=' ' + drive_data='' + part_2_data='' + else + if [[ $( calculate_line_length "$drive_data" ) -gt $COLS_INNER ]];then + drive_data=$( create_print_line "$Line_Starter" "$drive_data" ) + print_screen_output "$drive_data" + Line_Starter=' ' + drive_data='' + fi + if [[ $( calculate_line_length "$drive_data$part_2_data" ) -lt $COLS_INNER ]];then + drive_data=$( create_print_line "$Line_Starter" "$drive_data$part_2_data" ) + print_screen_output "$drive_data" + Line_Starter=' ' + part_2_data='' + drive_data='' + else + drive_data=$( create_print_line "$Line_Starter" "$drive_data" ) + print_screen_output "$drive_data" + drive_data='' + Line_Starter=' ' + drive_data=$( create_print_line "$Line_Starter" "$part_2_data" ) + print_screen_output "$drive_data" + Line_Starter=' ' + part_2_data='' + fi + fi + # 5 - speed # 6 - multisession support # 7 - MCN support @@ -10349,7 +13366,7 @@ print_optical_drive_data() if [[ -z ${a_drives[5]} ]];then speed='N/A' else - speed="${a_drives[5]}x" + speed="${a_drives[5]}$speed_string" fi if [[ -z ${a_drives[8]} ]];then audio='N/A' @@ -10358,7 +13375,7 @@ print_optical_drive_data() else audio='no' fi - audio=" ${C1}audio$SEP3${C2} $audio" + audio="${C1}audio$SEP3${C2} $audio " if [[ -z ${a_drives[6]} ]];then multisession='N/A' elif [[ ${a_drives[6]} == 1 ]];then @@ -10366,7 +13383,7 @@ print_optical_drive_data() else multisession='no' fi - multisession=" ${C1}multisession$SEP3${C2} $multisession" + multisession="${C1}multisession$SEP3${C2} $multisession " if [[ -z ${a_drives[11]} ]];then dvd='N/A' elif [[ ${a_drives[11]} == 1 ]];then @@ -10380,31 +13397,40 @@ print_optical_drive_data() else state="${a_drives[14]}" fi - state=" ${C1}state$SEP3${C2} $state" + state="${C1}state$SEP3${C2} $state " fi if [[ -n ${a_drives[9]} && ${a_drives[9]} == 1 ]];then rw_support='cd-r' separator=',' fi if [[ -n ${a_drives[10]} && ${a_drives[10]} == 1 ]];then - rw_support="${rw_support}${separator}cd-rw" + rw_support="$rw_support${separator}cd-rw" separator=',' fi if [[ -n ${a_drives[12]} && ${a_drives[12]} == 1 ]];then - rw_support="${rw_support}${separator}dvd-r" + rw_support="$rw_support${separator}dvd-r" separator=',' fi if [[ -n ${a_drives[13]} && ${a_drives[13]} == 1 ]];then - rw_support="${rw_support}${separator}dvd-ram" + rw_support="$rw_support${separator}dvd-ram" separator=',' fi if [[ -z $rw_support ]];then rw_support='none' fi - - drive_data="${C1}Features: speed$SEP3${C2} $speed$multisession$audio ${C1}dvd$SEP3${C2} $dvd ${C1}rw$SEP3${C2} $rw_support$state" - drive_data=$( create_print_line "$Line_Starter" "$drive_data" ) - print_screen_output "$drive_data" + drive_data="${C1}Features: speed$SEP3${C2} $speed $multisession" + part_2_data="$audio${C1}dvd$SEP3${C2} $dvd ${C1}rw$SEP3${C2} $rw_support $state" + if [[ $( calculate_line_length "$drive_data$part_2_data" ) -lt $COLS_INNER ]];then + drive_data=$( create_print_line "$Line_Starter" "$drive_data$part_2_data" ) + print_screen_output "$drive_data" + Line_Starter=' ' + else + drive_data=$( create_print_line "$Line_Starter" "$drive_data" ) + print_screen_output "$drive_data" + drive_data=$( create_print_line "$Line_Starter" "$part_2_data" ) + print_screen_output "$drive_data" + Line_Starter=' ' + fi fi done else @@ -10417,9 +13443,9 @@ print_partition_data() { eval $LOGFS local a_partition_working='' partition_used='' partition_data='' - local counter=0 i=0 a_partition_data='' line_starter='' line_max=$(( $COLS_INNER - 25 )) + local counter=0 i=0 part_id=0 a_partition_data='' line_starter='' local partitionIdClean='' part_dev='' full_dev='' part_label='' full_label='' - local part_uuid='' full_uuid='' dev_remote='' full_fs='' line_max_label_uuid=$COLS_INNER + local part_uuid='' full_uuid='' dev_remote='' full_fs='' local b_non_dev='false' holder='' # set A_PARTITION_DATA @@ -10445,25 +13471,24 @@ print_partition_data() full_fs='N/A' # reset partition fs type fi full_fs="${C1}fs$SEP3${C2} $full_fs " - - if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then - if [[ -n ${a_partition_working[6]} ]];then - if [[ -z $( grep -E '(^//|:/|non-dev)' <<< ${a_partition_working[6]} ) ]];then - part_dev="/dev/${a_partition_working[6]}" - dev_remote='dev' - elif [[ -n $( grep '^non-dev' <<< ${a_partition_working[6]} ) ]];then - holder=$( sed 's/non-dev-//' <<< ${a_partition_working[6]} ) - part_dev="$holder" - dev_remote='raid' - else - part_dev="${a_partition_working[6]}" - dev_remote='remote' - fi - else + if [[ -n ${a_partition_working[6]} ]];then + if [[ -z $( grep -E '(^//|:/|non-dev)' <<< ${a_partition_working[6]} ) ]];then + part_dev="/dev/${a_partition_working[6]}" dev_remote='dev' - part_dev='N/A' + elif [[ -n $( grep '^non-dev' <<< ${a_partition_working[6]} ) ]];then + holder=$( sed 's/non-dev-//' <<< ${a_partition_working[6]} ) + part_dev="$holder" + dev_remote='raid' + else + part_dev="${a_partition_working[6]}" + dev_remote='remote' fi - full_dev="${C1}$dev_remote$SEP3${C2} $part_dev " + else + dev_remote='dev' + part_dev='N/A' + fi + full_dev="${C1}$dev_remote$SEP3${C2} $part_dev " + if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then if [[ $B_SHOW_LABELS == 'true' && $dev_remote != 'remote' ]];then if [[ -n ${a_partition_working[7]} ]];then part_label="${a_partition_working[7]}" @@ -10487,20 +13512,25 @@ print_partition_data() else partitionIdClean=${a_partition_working[0]} fi - id_size_fs="${C1}ID:${C2} $partitionIdClean ${C1}size$SEP3${C2} ${a_partition_working[1]} $partition_used$full_fs$full_dev" + id_size_fs="${C1}ID-$((part_id+1))$SEP3${C2} $partitionIdClean ${C1}size$SEP3${C2} ${a_partition_working[1]} $partition_used$full_fs$full_dev" label_uuid="$full_label$full_uuid" # label/uuid always print one per line, so only wrap if it's very long - if [[ $B_SHOW_UUIDS == 'true' && $B_SHOW_LABELS == 'true' && $( calculate_line_length "$id_size_fs$label_uuid" ) -gt $line_max_label_uuid ]];then + if [[ $B_SHOW_UUIDS == 'true' || $B_SHOW_LABELS == 'true' ]] && \ + [[ $( calculate_line_length "${a_partition_data[$counter]}$id_size_fs$label_uuid" ) -gt $COLS_INNER ]];then a_partition_data[$counter]="$id_size_fs" ((counter++)) a_partition_data[$counter]="$label_uuid" else - a_partition_data[$counter]="${a_partition_data[$counter]}$id_size_fs$label_uuid" - fi - # because these lines can vary widely, using dynamic length handling here - if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]] || [[ $( calculate_line_length "${a_partition_data[$counter]}" ) -gt $line_max ]];then - ((counter++)) + if [[ $( calculate_line_length "${a_partition_data[$counter]}$id_size_fs$label_uuid" ) -gt $COLS_INNER ]];then + a_partition_data[$counter]="${a_partition_data[$counter]}" + ((counter++)) + a_partition_data[$counter]="$id_size_fs$label_uuid" + else + a_partition_data[$counter]="${a_partition_data[$counter]}$id_size_fs$label_uuid" + fi fi + ((counter++)) + ((part_id++)) fi done # print out all lines, line starter on first line @@ -10511,13 +13541,15 @@ print_partition_data() else line_starter=' ' fi - partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}" ) - print_screen_output "$partition_data" + if [[ -n ${a_partition_data[$i]} ]];then + partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}" ) + print_screen_output "$partition_data" + fi done eval $LOGFE } - +# legacy not used print_program_version() { local patch_version_number=$( get_patch_version_string ) @@ -10528,7 +13560,7 @@ print_program_version() # center pad: sed -e :a -e 's/^.\{1,80\}$/ & /;ta' #local line_max=$COLS_INNER #program_version="$( sed -e :a -e "s/^.\{1,$line_max\}$/ &/;ta" <<< $program_version )" # use to create padding if needed - # program_version=$( create_print_line "Version:" "$program_version" ) + # program_version=$( create_print_line "Version:" "$program_version${CN}" ) print_screen_output "$program_version" } @@ -10557,17 +13589,30 @@ print_ps_item() eval $LOGFS local a_ps_data='' ps_data='' line_starter='' line_start_data='' full_line='' local app_name='' app_pid='' app_cpu='' app_mem='' throttled='' app_daemon='' - local b_print_first=$2 line_counter=0 i=0 count_nu='' extra_data='' + local b_print_first=$2 line_counter=0 i=0 count_nu='' extra_data='' memory='' extra_text='' if [[ -n $PS_THROTTLED ]];then throttled=" ${C1} - throttled from${C2} $PS_THROTTLED" fi + # important: ${C2} $PS_COUNT must have space after ${C2} for irc output or the number vanishes case $1 in cpu) - line_start_data="${C1}CPU - % used - top ${C2} $PS_COUNT ${C1}active$throttled " + if [[ $B_EXTRA_DATA == 'true' ]];then + extra_text=" ${C1}- Memory$SEP3 MB / % used" + if [[ $B_SHOW_INFO == 'false' && $B_SHOW_PS_MEM_DATA == 'false' ]];then + memory=" - ${C1}Used/Total$SEP3${C2} $( get_memory_data )" + fi + fi + line_start_data="${C1}CPU$SEP3 % used$extra_text$memory${C1} - top${C2} $PS_COUNT ${C1}active$throttled" ;; mem) - line_start_data="${C1}Memory - MB / % used - top ${C2} $PS_COUNT ${C1}active$throttled" + if [[ $B_EXTRA_DATA == 'true' ]];then + extra_text=" ${C1}- CPU$SEP3 % used" + fi + if [[ $B_SHOW_INFO == 'false' ]];then + memory=" - ${C1}Used/Total$SEP3${C2} $( get_memory_data )" + fi + line_start_data="${C1}Memory$SEP3 MB / % used$memory$extra_text${C1} - top${C2} $PS_COUNT ${C1}active$throttled" ;; esac @@ -10599,7 +13644,7 @@ print_ps_item() app_name="$app_name ${C1}(started by$SEP3${C2} ${a_ps_data[2]}${C1})${C2}" fi app_pid=" ${C1}pid$SEP3${C2} ${a_ps_data[6]}" - # ${C1}user:${C2} ${a_ps_data[8]} + # ${C1}user$SEP3${C2} ${a_ps_data[8]} case $1 in cpu) app_cpu=" ${C1}cpu$SEP3${C2} ${a_ps_data[4]}%" @@ -10615,7 +13660,7 @@ print_ps_item() ;; esac (( line_counter++ )) - count_nu="${C1}$line_counter:${C2}" + count_nu="${C1}$line_counter$SEP3${C2}" full_line="$count_nu$app_cpu$app_mem$app_name$app_pid$extra_data" ps_data=$( create_print_line " " "$full_line" ) print_screen_output "$ps_data" @@ -10639,14 +13684,14 @@ print_raid_data() local empty_raid_data='' report_size='report' blocks_avail='blocks' chunk_raid_usage='chunk size' if [[ -n $BSD_TYPE ]];then - no_raid_detected='No zfs software RAID detected - other types not yet supported.' - empty_raid_data='No zfs RAID data available - other types not yet supported.' - report_size='full size' - blocks_avail='available size' - chunk_raid_usage='raid allocated' + no_raid_detected='No zfs software RAID detected-other types not yet supported.' + empty_raid_data='No zfs RAID data available-other types not yet supported.' + report_size='size' + blocks_avail='available' + chunk_raid_usage='allocated' else - no_raid_detected="No RAID data available - $FILE_MDSTAT is missing - is md_mod kernel module loaded?" - empty_raid_data="No RAID devices detected - $FILE_MDSTAT and md_mod kernel raid module present" + no_raid_detected="No RAID data: $FILE_MDSTAT missing-is md_mod kernel module loaded?" + empty_raid_data="No RAID devices: $FILE_MDSTAT, md_mod kernel module present" fi if [[ $BSD_TYPE == 'bsd' ]];then @@ -10694,7 +13739,7 @@ print_raid_data() if [[ ${a_raid_working[1]} == 'inactive' ]];then inactive=" - ${a_raid_working[1]}" fi - basic_raid="$basic_raid$basic_raid_separator${C1}$basic_counter${SEP3}${C2} $dev_string${a_raid_working[0]}$inactive" + basic_raid="$basic_raid$basic_raid_separator${C1}$basic_counter$SEP3${C2} $dev_string${a_raid_working[0]}$inactive" basic_raid_separator=' ' (( basic_counter++ )) else @@ -10715,7 +13760,7 @@ print_raid_data() if [[ ${a_raid_working[2]} == '' && ${a_raid_working[1]} == 'inactive' ]];then raid_level='' else - raid_level=" ${C1}raid${SEP3}${C2} $raid_level" + raid_level=" ${C1}raid$SEP3${C2} $raid_level" fi if [[ ${a_raid_working[4]} != '' ]];then device_report="${a_raid_working[4]}" @@ -10728,17 +13773,17 @@ print_raid_data() else blocks='N/A' fi - blocks=" ${C1}$blocks_avail${SEP3}${C2} $blocks" + blocks=" ${C1}$blocks_avail$SEP3${C2} $blocks" if [[ ${a_raid_working[9]} != '' ]];then chunk_size=${a_raid_working[9]} else chunk_size='N/A' fi - chunk_size=" ${C1}$chunk_raid_usage${SEP3}${C2} $chunk_size" + chunk_size=" ${C1}$chunk_raid_usage$SEP3${C2} $chunk_size" if [[ ${a_raid_working[10]} != '' ]];then bitmap_value='true' - bitmap_value=" ${C1}bitmap${SEP3}${C2} $bitmap_value" + bitmap_value=" ${C1}bitmap$SEP3${C2} $bitmap_value" fi fi if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then @@ -10746,15 +13791,15 @@ print_raid_data() u_data=" ${a_raid_working[5]}" fi if [[ ${a_raid_working[7]} != '' ]];then - super_blocks=" ${C1}super blocks${SEP3}${C2} ${a_raid_working[7]}" + super_blocks=" ${C1}super blocks$SEP3${C2} ${a_raid_working[7]}" fi if [[ ${a_raid_working[8]} != '' ]];then - algorithm=" ${C1}algorithm${SEP3}${C2} ${a_raid_working[8]}" + algorithm=" ${C1}algorithm$SEP3${C2} ${a_raid_working[8]}" fi fi if [[ ${a_raid_working[3]} == '' ]];then if [[ ${a_raid_working[1]} != 'inactive' ]];then - device_components='N/A' + device_components=" ${C1}components$SEP3${C2} N/A" fi else for component in ${a_raid_working[3]} @@ -10776,14 +13821,12 @@ print_raid_data() component_separator=' ' fi done - if [[ $failed != '' ]];then - failed=" ${C1}FAILED${SEP3}${C2}$failed${C2}" + failed=" ${C1}FAILED$SEP3${C2}$failed${C2}" fi if [[ $spare != '' ]];then - spare=" ${C1}spare${SEP3}${C2}$spare${C2}" + spare=" ${C1}spare$SEP3${C2}$spare${C2}" fi - if [[ -n $device_components || -n $spare || -n $failed ]];then if [[ $B_EXTRA_DATA != 'true' && -z $BSD_TYPE ]];then if [[ $device_report != 'N/A' && -n $device_components ]];then @@ -10793,20 +13836,20 @@ print_raid_data() if [[ $device_components == '' ]];then device_components='none' fi - device_components="${C1}online${SEP3}${C2} $device_components" - device_components=" ${C1}components${SEP3}${C2} $device_components$failed$spare" + device_components="${C1}online$SEP3${C2} $device_components" + device_components=" ${C1}components$SEP3${C2} $device_components$failed$spare" fi fi - a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components" + a_raid_data[$raid_counter]="${C1}Device$device_id$SEP3${C2} $device$device_state$raid_level$device_components" if [[ $B_EXTRA_DATA == 'true' && ${a_raid_working[1]} != 'inactive' ]];then - a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$device_components" + a_raid_data[$raid_counter]="${C1}Device$device_id$SEP3${C2} $device$device_state$device_components" (( raid_counter++ )) - print_string="${C1}Info${SEP3}${C2}$raid_level ${C1}$report_size${SEP3}${C2} $device_report$u_data" + print_string="${C1}Info$SEP3${C2}$raid_level ${C1}$report_size$SEP3${C2} $device_report$u_data" print_string="$print_string$blocks$chunk_size$bitmap_value$super_blocks$algorithm" a_raid_data[$raid_counter]="$print_string" else - a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components" + a_raid_data[$raid_counter]="${C1}Device$device_id$SEP3${C2} $device$device_state$raid_level$device_components" fi (( raid_counter++ )) @@ -10818,10 +13861,10 @@ print_raid_data() else finish_time='N/A' fi - finish_time=" ${C1}time remaining${SEP3}${C2} $finish_time" + finish_time=" ${C1}time remaining$SEP3${C2} $finish_time" if [[ $B_EXTRA_DATA == 'true' ]];then if [[ ${a_raid_working[13]} != '' ]];then - recovered_sectors=" ${C1}sectors${SEP3}${C2} ${a_raid_working[13]}" + recovered_sectors=" ${C1}sectors$SEP3${C2} ${a_raid_working[13]}" fi fi if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then @@ -10829,11 +13872,10 @@ print_raid_data() recovery_progress_bar=" ${a_raid_working[11]}" fi if [[ ${a_raid_working[15]} != '' ]];then - recovery_speed=" ${C1}speed${SEP3}${C2} ${a_raid_working[15]}" + recovery_speed=" ${C1}speed$SEP3${C2} ${a_raid_working[15]}" fi fi - - a_raid_data[$raid_counter]="${C1}Recovering${SEP3}${C2} $recovery_percent$recovery_progress_bar$recovered_sectors$finish_time$recovery_speed" + a_raid_data[$raid_counter]="${C1}Recovering$SEP3${C2} $recovery_percent$recovery_progress_bar$recovered_sectors$finish_time$recovery_speed" (( raid_counter++ )) fi fi @@ -10843,11 +13885,11 @@ print_raid_data() else kernel_support=${a_raid_working[1]} fi - kernel_support=" ${C1}supported${SEP3}${C2} $kernel_support" + kernel_support=" ${C1}supported$SEP3${C2} $kernel_support" elif [[ ${a_raid_working[0]} == 'ReadAhead' ]];then if [[ ${a_raid_working[1]} != '' ]];then read_ahead=${a_raid_working[1]} - read_ahead=" ${C1}read ahead${SEP3}${C2} $read_ahead" + read_ahead=" ${C1}read ahead$SEP3${C2} $read_ahead" fi elif [[ ${a_raid_working[0]} == 'UnusedDevices' ]];then if [[ ${a_raid_working[1]} == '' ]];then @@ -10855,17 +13897,17 @@ print_raid_data() else unused_devices=${a_raid_working[1]} fi - unused_devices="${C1}Unused Devices${SEP3}${C2} $unused_devices" + unused_devices="${C1}Unused Devices$SEP3${C2} $unused_devices" elif [[ ${a_raid_working[0]} == 'raidEvent' ]];then if [[ ${a_raid_working[1]} != '' ]];then raid_event=${a_raid_working[1]} - raid_event=" ${C1}Raid Event${SEP3}${C2} ${a_raid_working[1]}" + raid_event=" ${C1}Raid Event$SEP3${C2} ${a_raid_working[1]}" fi fi done if [[ $B_SHOW_BASIC_RAID == 'true' && $basic_raid != '' ]];then - a_raid_data[0]="${C1}Device$basic_raid_plural${SEP3}${C2} $basic_raid" + a_raid_data[0]="${C1}Device$basic_raid_plural$SEP3${C2} $basic_raid" fi # note bsd temp test hack to make it run if [[ $B_MDSTAT_FILE != 'true' && -z $BSD_TYPE ]] || \ @@ -10886,7 +13928,7 @@ print_raid_data() # now let's add on the system line and the unused device line. Only print on -xx if [[ $kernel_support$read_ahead$raid_event != '' ]];then array_count=${#a_raid_data[@]} - a_raid_data[array_count]="${C1}System${SEP3}${C2}$kernel_support$read_ahead$raid_event" + a_raid_data[array_count]="${C1}System$SEP3${C2}$kernel_support$read_ahead$raid_event" loop_limit=1 fi if [[ $unused_devices != '' ]];then @@ -10927,6 +13969,240 @@ print_raid_data() eval $LOGFE } +print_ram_data() +{ + eval $LOGFS + local memory_line='' line_2='' line_3='' b_module_present='true' + local error_string='' a_memory_item='' line_starter='Memory:' array_counter=1 device_counter=1 + local dmidecodeNull='No dmidecode memory data: try newer kernel.' + + local manufacturer='' part_nu='' serial_nu='' device_speed='' configured_speed='' bus_width= + local data_width='' total_width='' device_type='' device_type_detail='' bank='' slot='' form_factor='' + local device_size='' array_use='' location='' error_correction='' max_capacity='' nu_of_devices='' + local max_module_size='' module_voltage='' bank_connection='' + + get_ram_data + #echo ${#A_MEMORY_DATA[@]} + #echo ${A_MEMORY_DATA[0]} + if [[ ${#A_MEMORY_DATA[@]} -gt 0 ]];then + if [[ ${A_MEMORY_DATA[0]} == 'dmidecode-error-'* ]];then + error_string=$( print_dmidecode_error 'default' "${A_MEMORY_DATA[0]}" ) + memory_line="${C2}$error_string" + else + for (( i=0;i<${#A_MEMORY_DATA[@]};i++ )) + do + IFS=',' + a_memory_item=(${A_MEMORY_DATA[i]}) + IFS="$ORIGINAL_IFS" + memory_line='' + line_2='' + line_3='' + bus_width='' + data_width= + total_width= + part_nu='' + serial_nu='' + manufacturer='' + max_module_size='' + module_voltage='' + bank_connection='' + # memory-array,0x0012,System Board,8 GB,4,System Memory,None,max size,moudule voltage + if [[ ${a_memory_item[0]} == 'memory-array' ]];then + if [[ -n ${a_memory_item[4]} ]];then + nu_of_devices=${a_memory_item[4]} + else + nu_of_devices='N/A' + fi + if [[ -n ${a_memory_item[3]} ]];then + max_capacity=${a_memory_item[3]} + else + max_capacity='N/A' + fi + if [[ -n ${a_memory_item[6]} ]];then + error_correction=${a_memory_item[6]} + else + error_correction='N/A' + fi + if [[ $B_EXTRA_DATA == 'true' ]];then + if [[ -n ${a_memory_item[7]} ]];then + max_module_size="${C1}max module size${SEP3}${C2} ${a_memory_item[7]} " + fi + fi + if [[ $B_EXTRA_EXTRA_EXTRA_DATA == 'true' ]];then + if [[ -n ${a_memory_item[8]} ]];then + module_voltage="${C1}module voltage$SEP3${C2} ${a_memory_item[8]}" + fi + fi + memory_line="${C1}Array-$array_counter capacity$SEP3${C2} $max_capacity ${C1}devices$SEP3${C2} $nu_of_devices ${C1}EC$SEP3${C2} $error_correction " + line_2="$max_module_size$module_voltage" + if [[ -n $line_2 && $( calculate_line_length "$memory_line$line_2" ) -gt $COLS_INNER ]];then + memory_line=$( create_print_line "$line_starter" "$memory_line" ) + print_screen_output "$memory_line" + memory_line="$line_2" + line_starter=' ' + line_2='' + else + memory_line="$memory_line$line_2" + line_2='' + fi + (( array_counter++ )) + device_counter=1 # reset so device matches device count per array + else + # not used for now +# if [[ -n ${a_memory_item[3333]} ]];then +# if [[ -z ${a_memory_item[3]/BANK*/} ]];then +# #bank=${a_memory_item[3]#BANK} +# bank=${a_memory_item[3]} +# bank=${bank## } +# else +# bank=${a_memory_item[3]} +# fi +# else +# bank='N/A' +# fi +# # not used for now +# if [[ -n ${a_memory_item[44444]} ]];then +# if [[ -z ${a_memory_item[4]/SLOT*/} ]];then +# #slot=${a_memory_item[4]#SLOT} +# slot=${a_memory_item[4]} +# slot=${slot## } +# else +# slot=${a_memory_item[4]} +# fi +# else +# slot='N/A' +# fi + if [[ -n ${a_memory_item[15]} ]];then + locator=${a_memory_item[15]} + locator=${locator## } + else + locator='N/A' + fi + if [[ -n ${a_memory_item[2]} ]];then + device_size=${a_memory_item[2]} + if [[ $device_size == 'No Module Installed' ]];then + b_module_present='false' + else + b_module_present='true' + fi + else + device_size='N/A' + fi + if [[ -n ${a_memory_item[6]} ]];then + device_type=${a_memory_item[6]} + if [[ $B_EXTRA_EXTRA_EXTRA_DATA == 'true' && -n ${a_memory_item[7]} \ + && ${a_memory_item[7]} != 'Other' ]];then + device_type="$device_type (${a_memory_item[7]})" + fi + else + device_type='N/A' + fi + device_type="${C1}type$SEP3${C2} $device_type " + if [[ -n ${a_memory_item[8]} ]];then + if [[ -n ${a_memory_item[9]} ]];then + device_speed=${a_memory_item[9]} + else + device_speed=${a_memory_item[8]} + fi + else + device_speed='N/A' + fi + if [[ $b_module_present == 'true' ]];then + device_speed="${C1}speed$SEP3${C2} $device_speed " + else + device_speed='' + fi + # memory-device,0x002C,8192 MB,ChannelD,ChannelD_Dimm2,DIMM,DDR3,Synchronous,2400 MHz,2400 MHz,64 bits,64 bits,Undefined,F3-19200C10-8GBZH,00000000 + if [[ $b_module_present == 'true' ]];then + if [[ $B_EXTRA_DATA == 'true' ]];then + if [[ -n ${a_memory_item[13]} ]];then + part_nu=${a_memory_item[13]} + else + part_nu='N/A' + fi + part_nu="${C1}part$SEP3${C2} $part_nu " + fi + if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then + if [[ -n ${a_memory_item[12]} ]];then + manufacturer=${a_memory_item[12]} + else + manufacturer='N/A' + fi + manufacturer="${C1}manufacturer$SEP3${C2} $manufacturer " + if [[ -n ${a_memory_item[14]} ]];then + serial_nu=${a_memory_item[14]} + else + serial_nu='N/A' + fi + serial_nu="${C1}serial$SEP3${C2} $serial_nu " + + if [[ $device_size != 'N/A' && -n ${a_memory_item[16]} ]];then + bank_connection=" ${a_memory_item[16]}" + fi + fi + fi + if [[ $B_EXTRA_EXTRA_EXTRA_DATA == 'true' ]];then + if [[ $b_module_present == 'true' ]] || \ + [[ -n ${a_memory_item[11]} || -n ${a_memory_item[10]} ]];then + # only create this if the total exists and is > data width + if [[ -n ${a_memory_item[10]/ bits/} && -n ${a_memory_item[11]/ bits} && \ + ${a_memory_item[11]/ bits/} -gt ${a_memory_item[10]/ bits/} ]];then + total_width=" (total$SEP3 ${a_memory_item[11]})" + fi + if [[ -n ${a_memory_item[10]} ]];then + data_width=${a_memory_item[10]} + else + data_width='N/A' + fi + bus_width="${C1}bus width$SEP3${C2} $data_width$total_width " + fi + fi + memory_line="${C1}Device-$device_counter$SEP3${C2} $locator ${C1}size$SEP3${C2} $device_size$bank_connection $device_speed" + if [[ $( calculate_line_length "$memory_line$device_type" ) -le $COLS_INNER ]];then + memory_line="$memory_line$device_type" + device_type='' + fi + line_3="$manufacturer$part_nu$serial_nu" + line_2="$device_type$bus_width" + # echo $( calculate_line_length "$memory_line" ) + # echo $( calculate_line_length "$memory_line$line_2" ) + if [[ $( calculate_line_length "$memory_line$line_2$line_3" ) -gt $COLS_INNER ]];then + memory_line=$( create_print_line "$line_starter" "$memory_line" ) + print_screen_output "$memory_line" + memory_line="$line_2" + line_starter=' ' + if [[ -n $memory_line && -n $line_3 && $( calculate_line_length "$memory_line$line_3" ) -gt $COLS_INNER ]];then + memory_line=$( create_print_line "$line_starter" "$memory_line" ) + print_screen_output "$memory_line" + memory_line="$line_3" + else + memory_line="$memory_line$line_3" + fi + else + memory_line="$memory_line$line_2$line_3" + fi + (( device_counter++ )) + fi + memory_line=$( create_print_line "$line_starter" "$memory_line" ) + print_screen_output "$memory_line" + line_starter=' ' + done + memory_line=' ' + fi + else + memory_line="${C2}$dmidecodeNull" + fi + IFS="$ORIGINAL_IFS" + memory_line=${memory_line## } + if [[ -n $memory_line ]];then + memory_line=$( create_print_line "$line_starter" "$memory_line" ) + print_screen_output "$memory_line" + fi + + eval $LOGFE +} + + # currently only apt using distros support this feature, but over time we can add others print_repo_data() { @@ -10941,14 +14217,14 @@ print_repo_data() while read repo_line do (( repo_count++ )) - repo_type=$( cut -d ':' -f 1 <<< $repo_line ) - file_name=$( cut -d ':' -f 2 <<< $repo_line ) - file_content=$( cut -d ':' -f 3-7 <<< $repo_line ) + repo_type=$( cut -d '^' -f 1 <<< $repo_line ) + file_name=$( cut -d '^' -f 2 <<< $repo_line ) + file_content=$( cut -d '^' -f 3-7 <<< $repo_line ) # this will dump unwanted white space line starters. Some irc channels # use bots that show page title for urls, so need to break the url by adding # a white space. - if [[ $B_RUNNING_IN_SHELL != 'true' ]];then - file_content=$( echo $file_content | sed 's|://|: //|' ) + if [[ $B_IRC == 'true' ]];then + file_content=$( echo ${file_content/:\/\//: \/\/} ) else file_content=$( echo $file_content ) fi @@ -10956,14 +14232,14 @@ print_repo_data() # check file name, if different, update the holder for print out if [[ $file_name != $file_name_holder ]];then if [[ $repo_type == 'pisi repo' || $repo_type == 'urpmq repo' ]];then - repo_full="${C1}$repo_type:${C2} $file_name" + repo_full="${C1}$repo_type$SEP3${C2} $file_name" else - repo_full="${C1}Active $repo_type in file:${C2} $file_name" + repo_full="${C1}Active $repo_type in file$SEP3${C2} $file_name" fi file_name_holder=$file_name b_print_next_line='true' else - repo_full=$file_content + repo_full="${C2}$file_content" fi # first line print Repos: if [[ $repo_count -eq 1 ]];then @@ -10980,7 +14256,12 @@ print_repo_data() fi done <<< "$REPO_DATA" else - repo_full=$( create_print_line "Repos:" "${C1}Error:${C2} $SCRIPT_NAME does not support this feature for your distro yet." ) + if [[ $BSD_TYPE == 'bsd' ]];then + repo_type='OS type' + else + repo_type="package manager" + fi + repo_full=$( create_print_line "Repos:" "${C1}Error$SEP3${C2} No repo data detected. Does $SCRIPT_NAME support your $repo_type?" ) print_screen_output "$repo_full" fi eval $LOGFE @@ -11041,7 +14322,7 @@ print_sensors_data() gpu_temp=${gpu_temp#*:} fi if [[ -n $gpu_temp ]];then - gpu_temp="${C1}gpu$SEP3${C2} ${gpu_temp} " + gpu_temp="${C1}gpu$SEP3${C2} $gpu_temp " fi ;; # then the fan data from main fan array @@ -11135,11 +14416,16 @@ print_system_data() { eval $LOGFS local system_data='' bits='' desktop_environment='' dm_data='' de_extra_data='' - local host_kernel_string='' de_distro_string='' host_string='' desktop_type='Desktop' + local de_string='' distro_string='' line_starter='System:' + local host_kernel_string='' host_string='' desktop_type='Desktop' local host_name=$HOSTNAME local current_kernel=$( get_kernel_version ) local distro="$( get_distro_data )" - local tty_session='' + local tty_session='' compiler_string='' distro_os='Distro' + + if [[ -n $BSD_TYPE ]];then + distro_os='OS' + fi # I think these will work, maybe, if logged in as root and in X if [[ $B_RUNNING_IN_DISPLAY == 'true' ]];then @@ -11179,12 +14465,10 @@ print_system_data() dm_data=" ${C1}dm$SEP3${C2} $dm_data" fi fi - - de_distro_string="${C1}$desktop_type$SEP3${C2} $desktop_environment$de_extra_data$dm_data ${C1}Distro$SEP3${C2} $distro" if [[ $B_EXTRA_DATA == 'true' ]];then - gcc_string=$( get_gcc_kernel_version ) - if [[ -n $gcc_string ]];then - gcc_string=", ${C1}gcc$SEP3${C2} $gcc_string" + compiler_string=$( get_kernel_compiler_version ) + if [[ -n $compiler_string ]];then + compiler_string=" ${C1}${compiler_string%^*}$SEP3${C2} ${compiler_string#*^}" fi fi # check for 64 bit first @@ -11193,7 +14477,7 @@ print_system_data() else bits="32" fi - bits=" (${bits} bit${gcc_string})" + bits=" ($bits bit$compiler_string)" if [[ $B_SHOW_HOST == 'true' ]];then if [[ -z $HOSTNAME ]];then if [[ -n $( type p hostname ) ]];then @@ -11204,18 +14488,31 @@ print_system_data() fi fi host_string="${C1}Host$SEP3${C2} $host_name " - system_data=$( create_print_line "System:" "$host_string$host_name ${C1}Kernel$SEP3${C2}" ) fi host_kernel_string="$host_string${C1}Kernel$SEP3${C2} $current_kernel$bits " - if [[ $( calculate_line_length "$host_kernel_string$de_distro_string" ) -lt $COLS_INNER ]];then - system_data="$host_kernel_string$de_distro_string" - system_data=$( create_print_line "System:" "$system_data" ) - else - system_data=$( create_print_line "System:" "$host_kernel_string" ) + de_string="${C1}$desktop_type$SEP3${C2} $desktop_environment$de_extra_data$dm_data " + distro_string="${C1}$distro_os$SEP3${C2} $distro " + + if [[ $( calculate_line_length "$host_kernel_string$de_string" ) -gt $COLS_INNER ]];then + system_data=$( create_print_line "$line_starter" "$host_kernel_string" ) + print_screen_output "$system_data" + host_kernel_string='' + line_starter=' ' + fi + if [[ $( calculate_line_length "$host_kernel_string$de_string$distro_string" ) -gt $COLS_INNER ]];then + system_data=$( create_print_line "$line_starter" "$host_kernel_string$de_string" ) + print_screen_output "$system_data" + host_kernel_string='' + de_string='' + line_starter=' ' + fi + system_data="$host_kernel_string$de_string$distro_string" + if [[ -n $system_data ]];then + system_data="$host_kernel_string$de_string$distro_string" + system_data=$( create_print_line "$line_starter" "$system_data" ) print_screen_output "$system_data" - system_data=$( create_print_line " " "$de_distro_string" ) fi - print_screen_output "$system_data" + eval $LOGFE } @@ -11225,15 +14522,17 @@ print_unmounted_partition_data() local a_unmounted_data='' line_starter='' unmounted_data='' full_fs='' local full_dev='' full_size='' full_label='' full_uuid='' full_string='' local bsd_unsupported='This feature is not yet supported for BSD systems.' + local line_starter='Unmounted:' part_2_data='' if [[ -z ${A_PARTITION_DATA} ]];then get_partition_data fi get_unmounted_partition_data - if [[ ${#A_UNMOUNTED_PARTITION_DATA[@]} -ge 1 ]];then for (( i=0; i < ${#A_UNMOUNTED_PARTITION_DATA[@]}; i++ )) do + full_string='' + part_2_data='' IFS="," a_unmounted_data=(${A_UNMOUNTED_PARTITION_DATA[i]}) IFS="$ORIGINAL_IFS" @@ -11242,45 +14541,51 @@ print_unmounted_partition_data() else full_dev="/dev/${a_unmounted_data[0]}" fi - full_dev="${C1}ID:${C2} $full_dev" + full_dev="${C1}ID-$((i+1))$SEP3${C2} $full_dev " if [[ -z ${a_unmounted_data[1]} ]];then full_size='N/A' else full_size=${a_unmounted_data[1]} fi - full_size="${C1}size$SEP3${C2} $full_size" + full_size="${C1}size$SEP3${C2} $full_size " if [[ -z ${a_unmounted_data[2]} ]];then full_label='N/A' else full_label=${a_unmounted_data[2]} fi - full_label="${C1}label$SEP3${C2} $full_label" + full_label="${C1}label$SEP3${C2} $full_label " if [[ -z ${a_unmounted_data[3]} ]];then full_uuid='N/A' else full_uuid=${a_unmounted_data[3]} fi - full_uuid="${C1}uuid$SEP3${C2} $full_uuid" + full_uuid="${C1}uuid$SEP3${C2} $full_uuid " if [[ -z ${a_unmounted_data[4]} ]];then full_fs='' else - full_fs="${C1}fs$SEP3${C2} ${a_unmounted_data[4]}" - fi - full_string="$full_dev $full_size $full_label $full_uuid $full_fs" - if [[ $i -eq 0 ]];then - line_starter='Unmounted:' - else - line_starter=' ' + full_fs="${C1}fs$SEP3${C2} ${a_unmounted_data[4]} " fi # temporary message to indicate not yet supported if [[ $BSD_TYPE == 'bsd' ]];then full_string=$bsd_unsupported + else + full_string="$full_dev$full_size" + part_2_data="$full_fs$full_label$full_uuid" + fi + if [[ $( calculate_line_length "$full_string$part_2_data" ) -gt $COLS_INNER ]];then + unmounted_data=$( create_print_line "$line_starter" "$full_string" ) + print_screen_output "$unmounted_data" + line_starter=' ' + unmounted_data=$( create_print_line "$line_starter" "$part_2_data" ) + print_screen_output "$unmounted_data" + else + unmounted_data=$( create_print_line "$line_starter" "$full_string$part_2_data" ) + print_screen_output "$unmounted_data" + line_starter=' ' fi - unmounted_data=$( create_print_line "$line_starter" "$full_string" ) - print_screen_output "$unmounted_data" done else - unmounted_data=$( create_print_line "Unmounted:" "No unmounted partitions detected" ) + unmounted_data=$( create_print_line "$line_starter" "No unmounted partitions detected" ) print_screen_output "$unmounted_data" fi @@ -11294,10 +14599,10 @@ print_weather_data() local weather_data='' location_string='' local_time='' time_string='' pressure='' local a_location='' a_weather='' weather_string='' weather='' temp='' winds='' humidity='' local time_zone='' observation_time='' city='' state='' country='' altitude='' - local heat_index="" wind_chill='' dewpoint='' xxx_humidity='' + local heat_index='' wind_chill='' dewpoint='' xxx_humidity='' local openP='(' closeP=')' - if [[ $B_RUNNING_IN_SHELL == 'false' ]];then + if [[ $B_IRC == 'true' ]];then openP='' closeP='' fi @@ -11417,9 +14722,9 @@ print_weather_data() fi fi else - weather_data=$( create_print_line "Weather:" "Weather data failure: $(date)" ) + weather_data=$( create_print_line "Weather:" "${C2}Weather data failure: $(date)" ) print_screen_output "$weather_data" - weather_data=$( create_print_line " " "${A_WEATHER_DATA}" ) + weather_data=$( create_print_line " " "${C2}${A_WEATHER_DATA}" ) print_screen_output "$weather_data" fi eval $LOGFE -- 2.20.1