diff --git a/inxi b/inxi index 2485151..1021ef0 100755 --- a/inxi +++ b/inxi @@ -1,8 +1,8 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 0.10.0-b1-t6 -#### Date: 4 February 2009 +#### version: 0.10.2-b1-t1 +#### Date: 5 February 2009 ######################################################################## #### SPECIAL THANKS ######################################################################## @@ -63,6 +63,8 @@ #### Do not use `....`, those are totally non-reabable, use $(....) #### Do not use one liner flow controls. The ONLY time you should use ; is in #### this single case: if [[ condition ]];then (ie, never: [[ condition ]] && statement) +#### Note: [[ -n $something ]] - double brackets do not require quotes: "$something" for variables +#### 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 @@ -288,7 +290,7 @@ DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release" # user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v # 00000000 01 01 6f 6e 65 20 74 77 6f 0a |..one two.| A_NORMAL_BANS=( corporation communications gmbh technologies technology group $'\2'"\" ltd. $'\2'"\" inc. $'\2'\ co. "(tm)" "(r)" $'\2'"\(rev ..\)" ) -A_CPU_BANS=( @ cpu deca 'dual core' 'tri core' 'quad core' ennea genuine hepta hexa multi octa penta 'processor' processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" ) +A_CPU_BANS=( @ cpu deca 'dual core' dual-core 'tri core' tri-core 'quad core' quad-core ennea genuine hepta hexa multi octa penta 'processor' processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" ) # after processing, the ban arrays will be put into these: BAN_LIST_NORMAL='' BAN_LIST_CPU='' @@ -421,27 +423,27 @@ initialize_script_data() error_handler 6 fi - if [[ -e "$DIR_CPUINFO" ]]; then + if [[ -e $DIR_CPUINFO ]]; then B_CPUINFO='true' fi - if [[ -e "$DIR_MEMINFO" ]];then + if [[ -e $DIR_MEMINFO ]];then B_MEMINFO='true' fi - if [[ -e "$DIR_ASOUND_DEVICE" ]];then + if [[ -e $DIR_ASOUND_DEVICE ]];then B_ASOUND_CARDS='true' fi - if [[ -e "$DIR_ASOUND_VERSION" ]];then + if [[ -e $DIR_ASOUND_VERSION ]];then B_ASOUND_VERSION='true' fi - if [[ -f "$DIR_LSB_RELEASE" ]];then + if [[ -f $DIR_LSB_RELEASE ]];then B_LSB_DIR='true' fi - if [[ -e "$DIR_SCSI" ]];then + if [[ -e $DIR_SCSI ]];then B_SCSI_DIR='true' fi @@ -449,7 +451,7 @@ initialize_script_data() if [[ -x ifconfig ]]; then B_IFCONFIG='true' DIR_IFCONFIG='ifconfig' # change from full path to use $PATH - elif [[ -x "$DIR_IFCONFIG" ]];then + elif [[ -x $DIR_IFCONFIG ]];then B_IFCONFIG='true' else A_INTERFACES_DATA=( "Interfaces tool requires missing app: $DIR_IFCONFIG" ) @@ -459,15 +461,15 @@ initialize_script_data() B_X_RUNNING='true' fi - if [[ -e "$DIR_MODULES" ]];then + if [[ -e $DIR_MODULES ]];then B_MODULES_DIR='true' fi - if [[ -e "$DIR_MOUNTS" ]];then + if [[ -e $DIR_MOUNTS ]];then B_MOUNTS_DIR='true' fi - if [[ -e "$DIR_PARTITIONS" ]];then + if [[ -e $DIR_PARTITIONS ]];then B_PARTITIONS_DIR='true' fi } @@ -1241,7 +1243,7 @@ get_cmdline() ##print_screen_output "\$ppid='$ppid' -=- $(< /proc/$ppid/cmdline)" unset A_CMDL ## note: need to figure this one out, and ideally clean it up and make it readable - while read -d $'\0' L && [ "$i" -lt 32 ] + while read -d $'\0' L && [[ $i -lt 32 ]] do A_CMDL[i++]="$L" ## note: make sure this is valid - What does L mean? ## done < /proc/$ppid/cmdline @@ -2348,7 +2350,7 @@ get_partition_data() }' ) ) IFS="$ORIGINAL_IFS" - if [[ "$B_SHOW_LABELS" == 'true' || "$B_SHOW_UUIDS" == 'true' ]];then + if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then get_partition_data_advanced fi } @@ -2358,6 +2360,7 @@ get_partition_data_advanced() { local a_partition_working='' dev_partition_data='' local dev_disk_label='' dev_disk_uuid='' dev_item='' dev_label='' dev_uuid='' + local mount_point='' if [[ -d /dev/disk/by-label ]];then dev_disk_label="$( ls -l /dev/disk/by-label )" @@ -2366,14 +2369,14 @@ get_partition_data_advanced() dev_disk_uuid="$( ls -l /dev/disk/by-uuid )" fi - if [[ "$B_MOUNTS_DIR" == 'true' ]];then + if [[ $B_MOUNTS_DIR == 'true' ]];then for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ )) do IFS="," a_partition_working=( ${A_PARTITION_DATA[i]} ) IFS="$ORIGINAL_IFS" # note: for swap this will already be set - if [[ -z "${a_partition_working[5]}" ]];then + if [[ -z ${a_partition_working[5]} ]];then mount_point=$( sed 's|/|\\/|g' <<< ${a_partition_working[0]} ) #echo mount_point $mount_point dev_partition_data=$( gawk ' @@ -2404,10 +2407,10 @@ 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 ~ /^[hs]d[a-z][0-9]+$/ ) { + if ( partTemp ~ /[hs]d[a-z][0-9]/ ) { partition=gensub( /^(\/dev\/)(.+)$/, "\\2", 1, partTemp ) } - else if ( partTemp ~ /by-uuid\/[a-z0-9]+-[a-z0-9]+-[a-z0-9]+/ ) { + else if ( partTemp ~ /by-uuid/ ) { uuid=gensub( /^(\/dev\/disk\/by-uuid\/)(.+)$/, "\\2", 1, partTemp ) } else if ( partTemp ~ /by-label/ ) { @@ -2438,13 +2441,14 @@ get_partition_data_advanced() dev_label=${a_partition_working[6]} dev_uuid=${a_partition_working[7]} - if [[ -n "$dev_disk_label" ]];then - if [[ -n "$dev_item" && -z "$dev_label" ]];then + # first if the dev data/label data is incomplete, try to get missing piece + if [[ -n $dev_disk_label ]];then + if [[ -n $dev_item && -z $dev_label ]];then dev_label=$( echo "$dev_disk_label" | gawk ' /'$dev_item'$/ { print $(NF - 2) }' ) - elif [[ -z "$dev_item" && -n "$dev_label" ]];then + elif [[ -z $dev_item && -n $dev_label ]];then dev_item=$( echo "$dev_disk_label" | gawk ' /'$dev_label'/ { item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF ) @@ -2452,13 +2456,14 @@ get_partition_data_advanced() }' ) fi fi - if [[ -n "$dev_disk_uuid" ]];then - if [[ -n "$dev_item" && -z "$dev_uuid" ]];then + # then if dev data/uuid is incomplete, try to get missing piece + if [[ -n $dev_disk_uuid ]];then + if [[ -n $dev_item && -z $dev_uuid ]];then dev_uuid=$( echo "$dev_disk_uuid" | gawk ' /'$dev_item'$/ { print $(NF - 2) }' ) - elif [[ -z "$dev_item" && -n "$dev_uuid" ]];then + elif [[ -z $dev_item && -n $dev_uuid ]];then dev_item=$( echo "$dev_disk_uuid" | gawk ' /'$dev_uuid'/ { item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF ) @@ -2472,7 +2477,6 @@ get_partition_data_advanced() IFS="$ORIGINAL_IFS" done fi -# echo 'A_PARTITION_DATA: ' "${A_PARTITION_DATA[@]}" } ## return uptime string @@ -2480,9 +2484,9 @@ get_uptime() { ## note: removing gsub(/ /,"",a); to get get space back in there, goes right before print a echo $( uptime | gawk '{ - a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0) - print a - }' ) + a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0) + print a + }' ) } #### ------------------------------------------------------------------- @@ -2629,7 +2633,7 @@ print_short_data() local cpu_core_alpha=${A_CPU_CORE_DATA[1]} local cpu_type=${A_CPU_CORE_DATA[2]} - if [[ "$cpu_physical_count" -gt 1 ]];then + if [[ $cpu_physical_count -gt 1 ]];then cpc_plural='(s)' model_plural='s' cpu_count_print="$cpu_physical_count " @@ -2676,7 +2680,7 @@ print_short_data() for i in C1 C2 CN do ## these need to be in quotes, don't know why - if [[ "${!i}" == "$NORMAL" ]];then + if [[ ${!i} == $NORMAL ]];then declare $i="${!i}15,1" else declare $i="${!i},1" @@ -2804,7 +2808,7 @@ print_cpu_data() local cpu_core_alpha=${A_CPU_CORE_DATA[1]} local cpu_type=${A_CPU_CORE_DATA[2]} - if [[ "$cpu_physical_count" -gt 1 ]];then + if [[ $cpu_physical_count -gt 1 ]];then cpc_plural='(s)' cpu_count_print="$cpu_physical_count " model_plural='s' @@ -3177,7 +3181,8 @@ print_partition_data() { local a_partition_working='' partition_used='' swap='' partition_data='' local counter=0 line_max=160 i=0 a_partition_data='' line_starter='' - local partitionIdClean='' part_dev='' full_dev='' part_label='' full_label='' part_uuid='' full_uuid='' + local partitionIdClean='' part_dev='' full_dev='' part_label='' full_label='' + local part_uuid='' full_uuid='' dev_remote='' # this handles the different, shorter, irc colors strings embedded in variable data if [[ $B_RUNNING_IN_SHELL != 'true' ]];then @@ -3187,7 +3192,7 @@ print_partition_data() if [[ $SCHEME -eq 0 ]];then line_max=75 fi - if [[ "$B_SHOW_LABELS" == 'true' || "$B_SHOW_UUIDS" == 'true' ]];then + if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then line_max=20 fi @@ -3201,34 +3206,40 @@ print_partition_data() IFS="$ORIGINAL_IFS" if [[ $B_SHOW_PARTITIONS_FULL == 'true' ]] || [[ ${a_partition_working[4]} == 'swap' || ${a_partition_working[4]} == 'main' ]];then - if [[ -n "${a_partition_working[2]}" ]];then + if [[ -n ${a_partition_working[2]} ]];then partition_used=" ${C1}used:${C2} ${a_partition_working[2]} (${a_partition_working[3]})" else partition_used='' # reset partition used to null fi - if [[ "${a_partition_working[4]}" == 'swap' ]];then + if [[ ${a_partition_working[4]} == 'swap' ]];then swap=" ${C1}swap:${C2}" else swap='' fi # don't show user names in output - if [[ "$B_SHOW_LABELS" == 'true' || "$B_SHOW_UUIDS" == 'true' ]];then - if [[ -n "${a_partition_working[5]}" ]];then - part_dev="/dev/${a_partition_working[5]}" + if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then + if [[ -n ${a_partition_working[5]} ]];then + if [[ -z $( grep '^//' <<< ${a_partition_working[5]} ) ]];then + part_dev="/dev/${a_partition_working[5]}" + dev_remote='dev' + else + part_dev="${a_partition_working[5]}" + dev_remote='remote' + fi else part_dev='N/A' fi - full_dev=" ${C1}dev:${C2} $part_dev" - if [[ "$B_SHOW_LABELS" == 'true' ]];then - if [[ -n "${a_partition_working[6]}" ]];then + full_dev=" ${C1}$dev_remote:${C2} $part_dev" + if [[ $B_SHOW_LABELS == 'true' ]];then + if [[ -n ${a_partition_working[6]} ]];then part_label="${a_partition_working[6]}" else part_label='N/A' fi full_label=" ${C1}label:${C2} $part_label" fi - if [[ "$B_SHOW_UUIDS" == 'true' ]];then - if [[ -n "${a_partition_working[7]}" ]];then + if [[ $B_SHOW_UUIDS == 'true' ]];then + if [[ -n ${a_partition_working[7]} ]];then part_uuid="${a_partition_working[7]}" else part_uuid='N/A' @@ -3265,7 +3276,7 @@ print_system_data() local current_kernel=$( uname -rm ) # | gawk '{print $1,$3,$(NF-1)}' ) local distro="$( get_distro_data )" # check for 64 bit first - if [[ -n "$( uname -m | grep -o 'x86_64' )" ]];then + if [[ -n $( uname -m | grep -o 'x86_64' ) ]];then bits="(64 bit)" else bits="(32 bit)"