diff --git a/inxi b/inxi index 0adb98a..10e7ca7 100755 --- a/inxi +++ b/inxi @@ -1,8 +1,8 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 1.0.13-b2 -#### Date: 28 May 2009 +#### version: 1.0.16-b1 +#### Date: 6 June 2009 ######################################################################## #### SPECIAL THANKS ######################################################################## @@ -119,6 +119,10 @@ #### -! 13 - triggers an update from svn branch three - if present, of course #### -! 14 - triggers an update from svn branch four - if present, of course #### -! - Triggers an update from whatever server you list. +#### LOG FLAGS (logs to $HOME/.inxi/inxi.log with rotate 3 total) +#### -@ 8 - Basic data logging of generated data / array values +#### -@ 9 - Full logging of all data used, including cat of files and system data +#### -@ 10 - Basic data logging plus color code logging ######################################################################## #### VARIABLES ######################################################################## @@ -161,6 +165,7 @@ B_EXTRA_DATA='false' # override certain errors due to currupted data B_HANDLE_CORRUPT_DATA='false' B_LOG_COLORS='false' +B_LOG_FULL_DATA='false' B_ROOT='false' # Running in a shell? Defaults to false, and is determined later. B_RUNNING_IN_SHELL='false' @@ -222,7 +227,7 @@ DIR_IFCONFIG='/sbin/ifconfig' ### Variable initializations: constants DCOPOBJ="default" -DEBUG=0 # Set debug levels from 1-10 +DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels) # Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up' DEBUG_BUFFER_INDEX=0 ## note: the debugger rerouting to /dev/null has been moved to the end of the get_parameters function @@ -234,7 +239,7 @@ DEFAULT_SCHEME=2 # Default indentation level INDENT=10 -# logging eval variables, start and end function: Insert to LOGFS LOGFE when debug level == 10 +# logging eval variables, start and end function: Insert to LOGFS LOGFE when debug level >= 8 LOGFS_STRING='log_function_data fs $FUNCNAME "$( echo $@ )"' LOGFE_STRING='log_function_data fe $FUNCNAME' LOGFS='' @@ -341,17 +346,19 @@ BAN_LIST_CPU='' main() { eval $LOGFS - # first init function must be set first for colors etc. Remember, no debugger - # stuff works on this function unless you set the debugging flag manually. - # Debugging flag -@ [number] will not work until get_parameters runs. - # This function just initializes variables - initialize_script_data + # Check for dependencies BEFORE running ANYTHING else except above functions # Not all distro's have these depends installed by default check_script_depends check_script_suggested_apps + # first init function must be set first for colors etc. Remember, no debugger + # stuff works on this function unless you set the debugging flag manually. + # Debugging flag -@ [number] will not work until get_parameters runs. + # This function just initializes variables + initialize_script_data + ### Only continue if depends ok SCRIPT_PATH=$( dirname $0 ) SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' ) @@ -753,11 +760,11 @@ script_debugger() # NOTE: no logging available until get_parameters is run, since that's what sets logging # in order to trigger earlier logging manually set B_USE_LOGGING to true in top variables. # $1 alone: logs data; $2 with or without $3 logs func start/end. -# $1 type (fs/fe) or logged data; [$2 is $FUNCNAME; [$3 - function args]] +# $1 type (fs/fe/cat/raw) or logged data; [$2 is $FUNCNAME; [$3 - function args]] log_function_data() { if [ "$B_USE_LOGGING" == 'true' ];then - local logged_data='' spacer=" " + local logged_data='' spacer=' ' line='----------------------------------------' case $1 in fs) logged_data="Function: $2 - Primary: Start" @@ -770,16 +777,30 @@ log_function_data() logged_data="Function: $2 - Primary: End" spacer='' ;; + cat) + if [[ $B_LOG_FULL_DATA == 'true' ]];then + logged_data="\n$line\nFull file data: cat $2\n\n$( cat $2 )\n$line\n" + spacer='' + fi + ;; + raw) + if [[ $B_LOG_FULL_DATA == 'true' ]];then + logged_data="\n$line\nRaw system data:\n\n$2\n$line\n" + spacer='' + fi + ;; *) logged_data="$1" ;; esac # Create any required line breaks and strip out escape color code, either ansi (case 1)or irc (case 2). # This pattern doesn't work for irc colors, if we need that someone can figure it out - if [[ $B_LOG_COLORS != 'true' ]];then - echo -e "${spacer}$logged_data" | sed 's/\x1b\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g' >> $LOG_FILE - else - echo -e "${spacer}$logged_data" >> $LOG_FILE + if [[ -n $logged_data ]];then + if [[ $B_LOG_COLORS != 'true' ]];then + echo -e "${spacer}$logged_data" | sed -r 's/\x1b\[[0-9]{1,2}(;[0-9]{1,2}){0,2}m//g' >> $LOG_FILE + else + echo -e "${spacer}$logged_data" >> $LOG_FILE + fi fi fi } @@ -1033,10 +1054,12 @@ get_parameters() @) if [[ -n $( egrep "^([1-9]|10)$" <<< $OPTARG ) ]];then DEBUG=$OPTARG exec 2>&1 - # switch on logging only for -@ 10 - if [[ $OPTARG -ge 9 ]];then + # switch on logging only for -@ 8-10 + if [[ $OPTARG -ge 8 ]];then if [[ $OPTARG -eq 10 ]];then B_LOG_COLORS='true' + elif [[ $OPTARG -eq 9 ]];then + B_LOG_FULL_DATA='true' fi B_USE_LOGGING='true' # pack the logging data for evals function start/end @@ -1151,7 +1174,8 @@ show_options() fi print_screen_output "-V $SCRIPT_NAME version information. Prints information then exits." print_screen_output "-% Overrides defective or corrupted data." - print_screen_output "-@ Triggers debugger output. Requires debugging level 1-10." + print_screen_output "-@ Triggers debugger output. Requires debugging level 1-10 (8-10 - logging)." + print_screen_output " 8 - basic logging; 9 - full file/sys info logging; 10 - color logging." if [[ $1 == 'full' ]];then print_screen_output "" print_screen_output "Developer and Testing Options (Advanced):" @@ -1234,6 +1258,46 @@ get_start_client() # replacing loose detection with tight detection, bugs will be handled with app names # as they appear. case $app_working_name in + # check for shell first + bash|dash|sh) + unset IRC_CLIENT_VERSION + IRC_CLIENT="Shell wrapper" + ;; + # now start on irc clients, alphabetically + bitchx) + IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk ' + /Version/ { + a=tolower($2) + gsub(/[()]|bitchx-/,"",a) + print a + exit + } + $2 == "version" { + a=tolower($3) + sub(/bitchx-/,"",a) + print a + exit + }' )" + IRC_CLIENT="BitchX" + ;; + finch) + IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { + print $2 + }' )" + IRC_CLIENT="Finch" + ;; + gaim) + IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { + print $2 + }' )" + IRC_CLIENT="Gaim" + ;; + ircii) + IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { + print $3 + }' )" + IRC_CLIENT="ircII" + ;; irssi-text|irssi) IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { print $2 @@ -1286,45 +1350,27 @@ get_start_client() fi IRC_CLIENT="Konversation" ;; - xchat-gnome) - IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { + kopete) + IRC_CLIENT_VERSION=" $( kopete -v | gawk ' + /Kopete:/ { print $2 - }' )" - IRC_CLIENT="X-Chat-Gnome" - ;; - xchat) - IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { - print $2 - }' )" - IRC_CLIENT="X-Chat" - ;; - bitchx) - IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk ' - /Version/ { - a=tolower($2) - gsub(/[()]|bitchx-/,"",a) - print a - exit - } - $2 == "version" { - a=tolower($3) - sub(/bitchx-/,"",a) - print a exit }' )" - IRC_CLIENT="BitchX" + IRC_CLIENT="Kopete" ;; - ircii) - IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { - print $3 - }' )" - IRC_CLIENT="ircII" - ;; - gaim) - IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { - print $2 - }' )" - IRC_CLIENT="Gaim" + kvirc) + IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>&1 | gawk '{ + for ( i=2; i<=NF; i++) { + if ( i == NF ) { + print $i + } + else { + printf $i" " + } + } + exit + }' )" + IRC_CLIENT="KVIrc" ;; pidgin) IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { @@ -1371,28 +1417,19 @@ get_start_client() IRC_CLIENT_VERSION=" $( $irc_client_path -v ) " IRC_CLIENT="Weechat" ;; - kvirc) - IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>&1 | gawk '{ - for ( i=2; i<=NF; i++) { - if ( i == NF ) { - print $i - } - else { - printf $i" " - } - } - exit - }' )" - IRC_CLIENT="KVIrc" - ;; - kopete) - IRC_CLIENT_VERSION=" $( kopete -v | gawk ' - /Kopete:/ { + xchat-gnome) + IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { print $2 - exit }' )" - IRC_CLIENT="Kopete" + IRC_CLIENT="X-Chat-Gnome" ;; + xchat) + IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 { + print $2 + }' )" + IRC_CLIENT="X-Chat" + ;; + # then do some perl type searches, do this last since it's a wildcard search perl*|ksirc|dsirc) unset IRC_CLIENT_VERSION # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client @@ -1423,10 +1460,7 @@ get_start_client() IRC_CLIENT="Unknown Perl client" fi ;; - bash|dash|sh) - unset IRC_CLIENT_VERSION - IRC_CLIENT="Shell wrapper" - ;; + # then unset, set unknown data *) IRC_CLIENT="Unknown : ${irc_client_path##*/}" unset IRC_CLIENT_VERSION @@ -1502,6 +1536,7 @@ get_audio_data() print driver } }' $DIR_ASOUND_DEVICE ) + log_function_data 'cat' "$DIR_ASOUND_DEVICE" fi # this is to safeguard against line breaks from results > 1, which if inserted into following @@ -1605,6 +1640,7 @@ get_audio_data() # corresponding line. Finally, strip out commas as they will change the driver :) usb_id=$( cat $usb_proc_file/usbid ) usb_data=$( lsusb -v 2>/dev/null | grep "$usb_id" ) + log_function_data 'raw' "usb_data:\n$usb_data" usb_data=$( gawk '{ gsub( /,/, " ", $0 ) for( i=7; i <= NF; i++ ) { @@ -1652,6 +1688,7 @@ get_audio_alsa_data() print $0 } }' $DIR_ASOUND_VERSION ) + log_function_data 'cat' "$DIR_ASOUND_VERSION" fi echo "$alsa_data" log_function_data "alsa_data: $alsa_data" @@ -1773,6 +1810,7 @@ get_cpu_data() printf("%s %s\n", max, "Mhz") } }' $DIR_CPUINFO ) ) + log_function_data 'cat' "$DIR_CPUINFO" fi IFS="$ORIGINAL_IFS" @@ -1863,8 +1901,7 @@ get_cpu_ht_multicore_smp_data() } print type " " physical_cpu_count " " core_count } - ' $DIR_CPUINFO - ) ) + ' $DIR_CPUINFO ) ) fi log_function_data "A_CPU_TYPE_PCNT_CCNT: ${A_CPU_TYPE_PCNT_CCNT[@]}" eval $LOGFE @@ -1909,14 +1946,14 @@ get_distro_data() fi done fi - + log_function_data "distro_file: $distro_file" # first test for the legacy antiX distro id file if [[ -e /etc/antiX ]];then distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )" # this handles case where only one release/version file was found, and it's lsb-release. This would # never apply for ubuntu or debian, which will filter down to the following conditions. In general # if there's a specific distro release file available, that's to be preferred, but this is a good backup. - elif [[ -n $distro_file && -f /etc/lsb_release && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then + elif [[ -n $distro_file && -f $DIR_LSB_RELEASE && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then distro=$( get_distro_lsb_data ) elif [[ $distro_file == 'lsb-release' ]];then distro=$( get_distro_lsb_data ) @@ -2006,6 +2043,7 @@ get_distro_lsb_data() END { print distroId distroRelease distroCodename }' $DIR_LSB_RELEASE ) + log_function_data 'cat' "$DIR_LSB_RELEASE" fi # this is HORRIBLY slow, but I don't know why, it runs fast in shell # if [[ -n $( which lsb_release ) && $1 == 'app' ]];then @@ -2131,7 +2169,7 @@ get_graphics_glx_data() get_graphics_res_data() { eval $LOGFS - local screen_resolution='' + local screen_resolution='' if [[ $B_X_RUNNING == 'true' && $B_ROOT != 'true' ]];then # Added the two ?'s , because the resolution is now reported without spaces around the 'x', as in @@ -2172,12 +2210,13 @@ get_graphics_agp_data() eval $LOGFS local agp_module='' - if [[ B_MODULES_DIR == 'true' ]];then + if [[ $B_MODULES_DIR == 'true' ]];then ## not used currently agp_module=$( gawk ' /agp/ && !/agpgart/ && $3 > 0 { print(gensub(/(.*)_agp.*/,"\\1","g",$1)) }' $DIR_MODULES ) + log_function_data 'cat' "$DIR_MODULES" fi log_function_data "agp_module: $agp_module" eval $LOGFE @@ -2236,8 +2275,10 @@ get_hdd_data_basic() { eval $LOGFS local hdd_used='' - - hdd_used=$( df --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk ' + local hdd_data="$( df --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 )" + log_function_data 'raw' "hdd_data:\n$hdd_data" + + hdd_used=$( echo "$hdd_data" | gawk ' # also handles odd dm-1 type, from lvm /^\/dev\/(mapper\/|[hs]d[a-z][0-9]+|dm[-]?[0-9]+)/ { # this handles the case where the first item is too long @@ -2310,8 +2351,8 @@ get_hdd_data_basic() else { print "NA,-" # print an empty array, this will be further handled in the print out function } - }' $DIR_PARTITIONS - ) ) + }' $DIR_PARTITIONS ) ) + log_function_data 'cat' "$DIR_PARTITIONS" fi IFS="$ORIGINAL_IFS" log_function_data "A_HDD_DATA: ${A_HDD_DATA[@]}" @@ -2383,6 +2424,7 @@ get_hard_drive_data_advanced() } } }' $DIR_SCSI ) ) + log_function_data 'cat' "$DIR_SCSI" fi IFS="$ORIGINAL_IFS" @@ -2445,7 +2487,7 @@ get_lspci_data() }' )" echo "$lspci_data" - log_function_data "lspci_data: $lspci_data" + log_function_data 'raw' "lspci_data:\n$lspci_data" eval $LOGFE } @@ -2454,19 +2496,20 @@ get_memory_data() { eval $LOGFS local memory='' - - memory=$( gawk ' - /^MemTotal:/ { - tot = $2 - } - /^(MemFree|Buffers|Cached):/ { - notused+=$2 - } - END { - used = tot-notused - printf("%.1f/%.1fMB\n", used/1024, tot/1024) - }' $DIR_MEMINFO ) - + if [[ $B_MEMINFO == 'true' ]];then + memory=$( gawk ' + /^MemTotal:/ { + tot = $2 + } + /^(MemFree|Buffers|Cached):/ { + notused+=$2 + } + END { + used = tot-notused + printf("%.1f/%.1fMB\n", used/1024, tot/1024) + }' $DIR_MEMINFO ) + log_function_data 'cat' "$DIR_MEMINFO" + fi echo "$memory" log_function_data "memory: $memory" eval $LOGFE @@ -2643,13 +2686,16 @@ get_partition_data() eval $LOGFS #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 - + local main_partition_data="$( df -h -T --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 )" + local swap_data="$( swapon -s )" + log_function_data 'raw' "main_partition_data:\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=( $( df -h -T --exclude-type=aufs --exclude-type=tmpfs --exclude-type=iso9660 | gawk ' + A_PARTITION_DATA=( $( echo "$main_partition_data" | gawk ' BEGIN { IGNORECASE=1 } @@ -2691,7 +2737,7 @@ get_partition_data() # 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 - $( swapon -s | gawk ' + $( echo "$swap_data" | gawk ' BEGIN { swapCounter = 1 } @@ -2726,6 +2772,7 @@ get_partition_data_advanced() if [[ -d /dev/disk/by-uuid ]];then dev_disk_uuid="$( ls -l /dev/disk/by-uuid )" fi + log_function_data 'raw' "dev_disk_label:\n$dev_disk_label\n\ndev_disk_uuid:\n$dev_disk_uuid" if [[ $B_MOUNTS_DIR == 'true' ]];then for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ )) @@ -2841,6 +2888,7 @@ get_partition_data_advanced() A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","$dev_item","$dev_label","$dev_uuid IFS="$ORIGINAL_IFS" done + log_function_data 'cat' "$DIR_MOUNTS" fi log_function_data "A_PARTITION_DATA: ${A_PARTITION_DATA[@]}" eval $LOGFE