diff --git a/inxi b/inxi index 3fd1676..3c82186 100644 --- a/inxi +++ b/inxi @@ -1,7 +1,7 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 0.8.13.b2.3 +#### version: 0.8.13.b2.4 #### Date: December 22 2008 ######################################################################## #### inxi is a fork of infobash 3.02, the original bash sys info script by locsmif @@ -150,11 +150,8 @@ B_TESTING_1='false' B_TESTING_2='false' # Test for X running B_X_RUNNING='false' -if [[ -n $DISPLAY ]];then - B_X_RUNNING='true' -fi -### Directory/file exist flags +### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]] B_PROC='false' B_CPUINFO='false' B_MEMINFO='false' @@ -381,14 +378,17 @@ init() fi if [[ -e "$SCSI_DIR" ]];then - B_SCSI_DIR='false' + B_SCSI_DIR='true' fi # lack of ifconfig will throw an error only upon it's usage if [[ -x ifconfig ]];then B_IFCONFIG='true' fi - + + if [[ -n $DISPLAY ]];then + B_X_RUNNING='true' + fi } check_script_suggested_apps() @@ -495,7 +495,7 @@ error_handler() # args: $1 - $@ debugging string text script_debugger() { - if [[ $B_SCRIPT_UP == 'true' ]];then + if [[ $(B_SCRIPT_UP) ]];then # only return if debugger is off and no pre start up errors have occured if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then return 0 @@ -1202,7 +1202,7 @@ get_audio_data() IFS=$'\n' # this first step handles the drivers for cases where the second step fails to find one device_count=$( egrep -ic '(multimedia audio controller|audio device)' <<< "$lspci_data" ) - if [[ $device_count -eq 1 && -f $ASOUND_DEVICE ]];then + if [[ $device_count -eq 1 ]] && [[ $B_ASOUND_CARDS == 'true' ]];then alsa_driver=$( gawk -F ']: ' ' { IGNORECASE=1 } # filtering out modems and usb devices like webcams, this might get a @@ -1289,7 +1289,7 @@ get_audio_data() }') ) # in case of failure of first check do this instead - if [[ ${#A_AUDIO_DATA[@]} -eq 0 && -f $ASOUND_DEVICE ]];then + if [[ ${#A_AUDIO_DATA[@]} -eq 0 ]] && [[ $B_ASOUND_CARDS ]];then A_AUDIO_DATA=( $( gawk -F ']: ' ' { IGNORECASE=1 } $1 !~ /modem/ && $2 !~ /modem/ { @@ -1313,7 +1313,7 @@ get_audio_alsa_data() local alsa_data='' # now we'll get the alsa data if the file exists - if [[ $B_ASOUND_VERSION ]];then + if [[ $B_ASOUND_VERSION == 'true' ]];then alsa_data=$( gawk ' { IGNORECASE=1 } # some alsa strings have the build date in (...) @@ -1335,17 +1335,19 @@ get_audio_alsa_data() ## return value cpu core count string, this helps resolve the multi redundant lines of old style output get_cpu_core_count() { - ## 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 - local cpu_core_count=$(grep -ic "cpu cores" $CPUINFO| cut -d':' -f2) + if [[ $B_CPUINFO == 'true' ]]; then + ## 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 + local cpu_core_count=$(grep -ic "cpu cores" $CPUINFO| cut -d':' -f2) - if [[ $cpu_core_count -eq 0 ]];then - cpu_core_count=$(grep -ic "^processor" $CPUINFO| cut -d':' -f2) - fi - local cpu_alpha_count='' + if [[ $cpu_core_count -eq 0 ]];then + cpu_core_count=$(grep -ic "^processor" $CPUINFO| cut -d':' -f2) + fi + local cpu_alpha_count='' - if [[ $cpu_core_count -lt 2 ]]; then - cpu_core_count=1 + if [[ $cpu_core_count -lt 2 ]]; then + cpu_core_count=1 + fi fi # match the numberic value to an alpha value @@ -1371,67 +1373,69 @@ get_cpu_data() { local i='' j='' cpu_array_nu='' a_cpu_working='' multi_cpu='' bits='' - IFS=$'\n' - A_CPU_DATA=($(gawk -F': ' ' - { IGNORECASE=1 } - # TAKE NOTE: \t+ will work for $CPUINFO, but SOME ARBITRARY FILE used for TESTING might contain SPACES! - # Therefore PATCH to use [ \t]+ when TESTING! - /^processor\t+:/ { nr = $NF } + if [[ $B_CPUINFO == 'true' ]];then + IFS=$'\n' + A_CPU_DATA=($(gawk -F': ' ' + { IGNORECASE=1 } + # TAKE NOTE: \t+ will work for $CPUINFO, but SOME ARBITRARY FILE used for TESTING might contain SPACES! + # Therefore PATCH to use [ \t]+ when TESTING! + /^processor\t+:/ { nr = $NF } - /^model name|^cpu\t+:/ { - gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF ) - gsub(/'"$BAN_LIST_CPU"'/, "", $NF ) - gsub(/,/, " ", $NF) - gsub(/^ +| +$/, "", $NF) - gsub(/ [ \t]+/, " ", $NF) - cpu[nr, "model"] = $NF - } - - /^cpu MHz|^clock\t+:/ { - if (!min) { - min = $NF + /^model name|^cpu\t+:/ { + gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF ) + gsub(/'"$BAN_LIST_CPU"'/, "", $NF ) + gsub(/,/, " ", $NF) + gsub(/^ +| +$/, "", $NF) + gsub(/ [ \t]+/, " ", $NF) + cpu[nr, "model"] = $NF } - else { - if ($NF < min) { + + /^cpu MHz|^clock\t+:/ { + if (!min) { min = $NF } + else { + if ($NF < min) { + min = $NF + } + } + + if ($NF > max) { + max = $NF + } + gsub(/MHZ/,"",$NF) ## clears out for cell cpu + gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros + cpu[nr, "speed"] = $NF } - if ($NF > max) { - max = $NF - } - gsub(/MHZ/,"",$NF) ## clears out for cell cpu - gsub(/.00[0]+$/,".00",$NF) ## clears out excessive zeros - cpu[nr, "speed"] = $NF - } + /^cache size/ { cpu[nr, "cache"] = $NF } - /^cache size/ { cpu[nr, "cache"] = $NF } + /^flags/ { cpu[nr, "flags"] = $NF } - /^flags/ { cpu[nr, "flags"] = $NF } + /^bogomips/ { cpu[nr, "bogomips"] = $NF } - /^bogomips/ { cpu[nr, "bogomips"] = $NF } + /vendor_id/ { + gsub(/genuine|authentic/,"",$NF) + cpu[nr, "vendor"] = tolower( $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++ ) { - print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] "," cpu[nr, "vendor"] - } - if (!min) { - print "not found" - exit - } - if (min != max) { - printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz") - } - else { - printf("%s %s\n", max, "Mhz") - } - }' $CPUINFO)) + END { + #if (!nr) { print ",,,"; exit } # <- should this be necessary or should bash handle that + for ( i = 0; i <= nr; i++ ) { + print cpu[i, "model"] "," cpu[i, "speed"] "," cpu[i, "cache"] "," cpu[i, "flags"] "," cpu[i, "bogomips"] "," cpu[nr, "vendor"] + } + if (!min) { + print "not found" + exit + } + if (min != max) { + printf("Min:%s%s Max:%s%s\n", min, "Mhz", max, "Mhz") + } + else { + printf("%s %s\n", max, "Mhz") + } + }' $CPUINFO)) + fi IFS="$ORIGINAL_IFS" } @@ -1465,7 +1469,7 @@ 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_DIR" ]];then + if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_DIR == 'true' ]];then distro_file='lsb-release' else distro_file="${i}" @@ -1489,8 +1493,8 @@ get_distro_data() # 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 - # something here allows puppy linux into the mint section - if [[ $B_LSB_DIR ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then + # some bashism, boolean must be in parenthesis to work correctly, ie [[ $(boolean) ]] not [[ $boolean ]] + if [[ $B_LSB_DIR == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then distro=$( get_distro_lsb_data ) else distro=$( gawk ' @@ -1504,14 +1508,14 @@ get_distro_data() fi fi - if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then + if [[ ${#distro} -gt 80 ]] && [[ $B_HANDLE_CORRUPT_DATA != 'true' ]];then distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}" 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_DIR" ]];then + if [[ -z $distro ]] && [[ $B_LSB_DIR == 'true' ]];then distro=$( get_distro_lsb_data ) fi ## finally, if all else has failed, give up @@ -1532,7 +1536,7 @@ get_distro_lsb_data() { local distro='' - if [[ "$B_LSB_DIR" && $1 != 'app' ]];then + if [[ $B_LSB_DIR == 'true' ]] && [[ $1 != 'app' ]];then distro=$( gawk -F '=' ' { IGNORECASE=1 } @@ -1837,7 +1841,7 @@ get_hard_drive_data_advanced() ## then handle libata names # first get the ata device names, put them into an array IFS=$'\n' - if [[ $B_SCSI_DIR ]]; then + if [[ $B_SCSI_DIR == 'true' ]]; then a_temp_scsi=( $( gawk ' BEGIN { IGNORECASE=1 } /host/ { @@ -2045,7 +2049,7 @@ get_networking_wan_ip_data() get_networking_local_ip_data() { - if [[ $B_IFCONFIG ]];then + if [[ $B_IFCONFIG == 'true' ]];then IFS=$'\n' A_INTERFACES_DATA=( $( ifconfig | gawk ' BEGIN { IGNORECASE=1 } @@ -2091,6 +2095,7 @@ get_networking_local_ip_data() get_partition_data() { #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 IFS=$'\n' # sample line: /dev/sda2 ext3 15G 8.9G 4.9G 65% /home @@ -2573,7 +2578,7 @@ print_gfx_data() fi ## note: if glx render or version have no content, then mesa is true - if [[ $B_X_RUNNING == 'true' && $b_is_mesa != 'true' ]];then + if [[ $B_X_RUNNING == 'true' ]] && [[ $b_is_mesa != 'true' ]];then gfx_data=$( create_print_line " " "${C1}GLX Renderer${C2} ${glx_renderer} ${C1}GLX Version${C2} ${glx_version}${CN}" ) if [[ $B_HANDLE_CORRUPT_DATA == 'true' ]];then gfx_data="${gfx_data} ${C1}Direct rendering${C2} ${glx_direct_render}${CN}" @@ -2598,7 +2603,7 @@ print_hard_disk_data() local hdd_capacity=${a_hdd_basic_working[0]} local hdd_used=${a_hdd_basic_working[1]} - if [[ $VERBOSITY_LEVEL -ge 3 || $B_SHOW_DISK == 'true' ]];then + if [[ $VERBOSITY_LEVEL -ge 3 ]] || [[ $B_SHOW_DISK == 'true' ]];then ## 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++ ))