From 6750924de4dc76c426e1c139b773a3939bed3131 Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Thu, 16 Sep 2010 21:10:33 +0000 Subject: [PATCH] fixed a weird arch kernel issue where df -hT reports first column /dev/disk/by-uuid no matter how disk is mounted in reality. --- inxi | 128 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 98 insertions(+), 30 deletions(-) diff --git a/inxi b/inxi index a39bb17..c699060 100755 --- a/inxi +++ b/inxi @@ -1,8 +1,8 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 1.4.14 -#### Date: August 24 2010 +#### version: 1.4.15 +#### Date: September 16 2010 ######################################################################## #### SPECIAL THANKS ######################################################################## @@ -170,6 +170,8 @@ COLOR_SCHEME='' COLOR_SCHEME_SET='' # override in user config if desired, seems like less than .3 doesn't work as reliably CPU_SLEEP='0.3' +DEV_DISK_LABEL='' +DEV_DISK_UUID='' IRC_CLIENT='' IRC_CLIENT_VERSION='' PS_COUNT=5 @@ -211,6 +213,7 @@ B_DEBUG_FLOOD='false' B_EXTRA_DATA='false' # override certain errors due to currupted data B_HANDLE_CORRUPT_DATA='false' +B_LABEL_SET='false' B_LOG_COLORS='false' B_LOG_FULL_DATA='false' # kde qdbus @@ -250,6 +253,7 @@ B_TESTING_1='false' B_TESTING_2='false' # set to true here for debug logging from script start B_USE_LOGGING='false' +B_UUID_SET='false' # Test for X running B_X_RUNNING='false' @@ -3059,10 +3063,16 @@ get_networking_local_ip_data() get_partition_data() { eval $LOGFS + + local a_partition_working='' dev_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 local main_partition_data="$( df -h -T --exclude-type=aufs --exclude-type=squashfs --exclude-type=unionfs --exclude-type=devtmpfs --exclude-type=tmpfs --exclude-type=iso9660 )" local swap_data="$( swapon -s )" + # set dev disk label/uuid data globals + get_partition_uuid_label_data 'label' + get_partition_uuid_label_data 'uuid' + log_function_data 'raw' "main_partition_data:\n$main_partition_data\n\nswap_data:\n$swap_data" IFS=$'\n' @@ -3113,6 +3123,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 @@ -3129,6 +3140,39 @@ get_partition_data() swapCounter = ++swapCounter }' ) ) IFS="$ORIGINAL_IFS" + + # now we'll handle some fringe cases where irregular df -hT output shows /dev/disk/.. instead of + # /dev/h|s/dxy type data for column 1, . A_PARTITION_DATA[6] + 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 [[ -n $( grep -E '(by-uuid|by-label)' <<< ${a_partition_working[6]} ) ]];then + if [[ -n $DEV_DISK_UUID ]];then + dev_item=$( echo "$DEV_DISK_UUID" | gawk ' + /'$( basename ${a_partition_working[6]} )'/ { + item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF ) + print item + }' ) + fi + # if we didn't find anything for uuid try label + if [[ -z $dev_item && -n $DEV_DISK_LABEL ]];then + dev_item=$( echo "$DEV_DISK_LABEL" | gawk ' + /'$( basename ${a_partition_working[6]} )'/ { + item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF ) + print item + }' ) + fi + if [[ -n $dev_item ]];then + # assemble everything we could get for dev/h/dx, label, and uuid + IFS="," + A_PARTITION_DATA[i]=${a_partition_working[0]}","${a_partition_working[1]}","${a_partition_working[2]}","${a_partition_working[3]}","${a_partition_working[4]}","${a_partition_working[5]}","$dev_item + IFS="$ORIGINAL_IFS" + fi + fi + done if [[ $B_SHOW_LABELS == 'true' || $B_SHOW_UUIDS == 'true' ]];then get_partition_data_advanced @@ -3142,16 +3186,11 @@ get_partition_data_advanced() { eval $LOGFS local a_partition_working='' dev_partition_data='' - local dev_disk_label='' dev_disk_uuid='' dev_item='' dev_label='' dev_uuid='' + local 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 )" - fi - 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" + # set dev disk label/uuid data globals + get_partition_uuid_label_data 'label' + get_partition_uuid_label_data 'uuid' if [[ $B_MOUNTS_FILE == 'true' ]];then for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ )) @@ -3233,14 +3272,14 @@ get_partition_data_advanced() # it's more likely we'll get a uuid than a label. But this should get the # dev item set no matter what, so then we can get the rest of any missing data # first we'll get the dev_item if it's missing - if [[ -n $dev_disk_uuid ]] && [[ -z $dev_item && -n $dev_uuid ]];then - dev_item=$( echo "$dev_disk_uuid" | gawk ' + if [[ -n $DEV_DISK_UUID ]] && [[ -z $dev_item && -n $dev_uuid ]];then + dev_item=$( echo "$DEV_DISK_UUID" | gawk ' /'$dev_uuid'/ { item=gensub( /..\/..\/(.+)/, "\\1", 1, $NF ) print item }' ) - elif [[ -n $dev_disk_label ]] && [[ -z $dev_item && -n $dev_label ]];then - dev_item=$( echo "$dev_disk_label" | gawk ' + elif [[ -n $DEV_DISK_LABEL ]] && [[ -z $dev_item && -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 ) # then we can see if the string is there @@ -3249,14 +3288,14 @@ get_partition_data_advanced() print item }' ) fi - if [[ -n $dev_disk_uuid ]] && [[ -n $dev_item && -z $dev_uuid ]];then - dev_uuid=$( echo "$dev_disk_uuid" | gawk ' + if [[ -n $DEV_DISK_UUID ]] && [[ -n $dev_item && -z $dev_uuid ]];then + dev_uuid=$( echo "$DEV_DISK_UUID" | gawk ' /'$dev_item'$/ { print $(NF - 2) }' ) fi - if [[ -n $dev_disk_label ]] && [[ -n $dev_item && -z $dev_label ]];then - dev_label=$( echo "$dev_disk_label" | gawk ' + if [[ -n $DEV_DISK_LABEL ]] && [[ -n $dev_item && -z $dev_label ]];then + dev_label=$( echo "$DEV_DISK_LABEL" | gawk ' /'$dev_item'/ { print $(NF - 2) }' ) @@ -3273,6 +3312,38 @@ get_partition_data_advanced() eval $LOGFE } + +# args: $1 - uuid/label +get_partition_uuid_label_data() +{ + eval $LOGFS + + # only run these tests once per directory to avoid excessive queries to fs + case $1 in + label) + if [[ -d /dev/disk/by-label && $B_LABEL_SET != 'true' ]];then + DEV_DISK_LABEL="$( ls -l /dev/disk/by-label )" + B_LABEL_SET='true' + fi + ;; + uuid) + if [[ -d /dev/disk/by-uuid && $B_UUID_SET != 'true' ]];then + DEV_DISK_UUID="$( ls -l /dev/disk/by-uuid )" + B_UUID_SET='true' + fi + ;; + esac + log_function_data 'raw' "DEV_DISK_LABEL:\n$DEV_DISK_LABEL\n\nDEV_DISK_UUID:\n$DEV_DISK_UUID" + # debugging section, uncomment to insert user data +# DEV_DISK_LABEL=' +# +# ' +# DEV_DISK_UUID=' +# +# ' + eval $LOGFE +} + # args: $1 - type cpu/mem get_ps_data() { @@ -3856,15 +3927,12 @@ get_unmounted_partition_data() { eval $LOGFS local a_unmounted_working='' mounted_partitions='' separator='' unmounted_fs='' - local dev_disk_label='' dev_disk_uuid='' dev_working='' uuid_working='' label_working='' + local dev_working='' uuid_working='' label_working='' if [[ $B_PARTITIONS_FILE == 'true' ]];then - if [[ -d /dev/disk/by-label ]];then - dev_disk_label="$( ls -l /dev/disk/by-label )" - fi - if [[ -d /dev/disk/by-uuid ]];then - dev_disk_uuid="$( ls -l /dev/disk/by-uuid )" - fi + # set dev disk label/uuid data globals + get_partition_uuid_label_data 'label' + get_partition_uuid_label_data 'uuid' # create list for slicing out the mounted partitions for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ )) @@ -3889,17 +3957,17 @@ get_unmounted_partition_data() size = sprintf( "%.2f", $3*1024/1000**3 ) print $4 "," size "G" }' ) ) - + for (( i=0; i < ${#A_UNMOUNTED_PARTITION_DATA[@]}; i++ )) do IFS="," a_unmounted_working=( ${A_UNMOUNTED_PARTITION_DATA[i]} ) IFS="$ORIGINAL_IFS" - label_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$dev_disk_label" | gawk '{ + label_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$DEV_DISK_LABEL" | gawk '{ print $(NF - 2) }' ) - uuid_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$dev_disk_uuid" | gawk '{ + uuid_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$DEV_DISK_UUID" | gawk '{ print $(NF - 2) }' ) unmounted_fs=$( get_unmounted_partition_filesystem "/dev/${a_unmounted_working[0]}" ) @@ -3909,7 +3977,7 @@ get_unmounted_partition_data() IFS="$ORIGINAL_IFS" done fi - +# echo "${A_PARTITION_DATA[@]}" # echo "${A_UNMOUNTED_PARTITION_DATA[@]}" eval $LOGFE }