From d48147d79d8a8f42dba0262c465223bfd08115ea Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Sat, 9 Jan 2010 04:49:55 +0000 Subject: [PATCH] some code cleanup and variable naming fixes --- inxi | 126 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/inxi b/inxi index 0665cc3..62115dd 100755 --- a/inxi +++ b/inxi @@ -236,11 +236,11 @@ B_ASOUND_CARDS='false' B_ASOUND_VERSION='false' B_BASH_ARRAY='false' B_IFCONFIG='false' -B_LSB_DIR='false' -B_SCSI_DIR='false' -B_MODULES_DIR='false' # -B_MOUNTS_DIR='false' -B_PARTITIONS_DIR='false' # +B_LSB_FILE='false' +B_SCSI_FILE='false' +B_MODULES_FILE='false' # +B_MOUNTS_FILE='false' +B_PARTITIONS_FILE='false' # ### File's used when present FILE_CPUINFO='/proc/cpuinfo' @@ -543,11 +543,11 @@ initialize_script_data() fi if [[ -f $FILE_LSB_RELEASE ]];then - B_LSB_DIR='true' + B_LSB_FILE='true' fi if [[ -e $FILE_SCSI ]];then - B_SCSI_DIR='true' + B_SCSI_FILE='true' fi # lack of ifconfig will throw an error only upon it's usage @@ -566,15 +566,15 @@ initialize_script_data() fi if [[ -e $FILE_MODULES ]];then - B_MODULES_DIR='true' + B_MODULES_FILE='true' fi if [[ -e $FILE_MOUNTS ]];then - B_MOUNTS_DIR='true' + B_MOUNTS_FILE='true' fi if [[ -e $FILE_PARTITIONS ]];then - B_PARTITIONS_DIR='true' + B_PARTITIONS_FILE='true' fi # gfx output will require this flag if [[ $( whoami ) == 'root' ]];then @@ -2070,7 +2070,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 == 'true' ]];then + if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_FILE == 'true' ]];then distro_file='lsb-release' else distro_file="${i}" @@ -2097,7 +2097,7 @@ get_distro_data() elif [[ -f /etc/issue ]];then # 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_DIR == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then + if [[ $B_LSB_FILE == 'true' ]] && [[ -z $( grep -i 'mint' /etc/issue ) ]];then distro=$( get_distro_lsb_data ) else distro=$( gawk ' @@ -2121,7 +2121,7 @@ get_distro_data() # : ${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 == 'true' ]];then + if [[ -z $distro ]] && [[ $B_LSB_FILE == 'true' ]];then distro=$( get_distro_lsb_data ) fi ## finally, if all else has failed, give up @@ -2145,7 +2145,7 @@ get_distro_lsb_data() eval $LOGFS local distro='' - if [[ $B_LSB_DIR == 'true' ]] && [[ $1 != 'app' ]];then + if [[ $B_LSB_FILE == 'true' ]] && [[ $1 != 'app' ]];then distro=$( gawk -F '=' ' BEGIN { IGNORECASE=1 @@ -2406,7 +2406,7 @@ get_graphics_agp_data() eval $LOGFS local agp_module='' - if [[ $B_MODULES_DIR == 'true' ]];then + if [[ $B_MODULES_FILE == 'true' ]];then ## not used currently agp_module=$( gawk ' /agp/ && !/agpgart/ && $3 > 0 { @@ -2513,7 +2513,7 @@ get_hdd_data_basic() # final item is the total of the disk IFS=$'\n' - if [[ $B_PARTITIONS_DIR == 'true' ]];then + if [[ $B_PARTITIONS_FILE == 'true' ]];then A_HDD_DATA=( $( gawk -v hddused="$hdd_used" ' /[hs]d[a-z]$/ { @@ -2593,7 +2593,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 == 'true' ]]; then + if [[ $B_SCSI_FILE == 'true' ]]; then a_temp_scsi=( $( gawk ' BEGIN { IGNORECASE=1 @@ -3001,7 +3001,7 @@ get_partition_data_advanced() 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 + if [[ $B_MOUNTS_FILE == 'true' ]];then for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ )) do IFS="," @@ -3546,52 +3546,54 @@ get_unmounted_partition_data() local a_unmounted_working='' a_unmounted_temp='' mounted_partitions='' separator='' local dev_disk_label='' dev_disk_uuid='' dev_working='' uuid_working='' label_working='' - 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 - - # create list for slicing out the mounted partitions - for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ )) - do - IFS="," - a_unmounted_working=( ${A_PARTITION_DATA[i]} ) - IFS="$ORIGINAL_IFS" - if [[ -n ${a_unmounted_working[6]} ]];then - mounted_partitions="$mounted_partitions$separator${a_unmounted_working[6]}" - separator='|' + 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 - done - - A_UNMOUNTED_PARTITION_DATA=( $( cat /proc/partitions | grep -Ev '('$mounted_partitions')' | gawk ' - BEGIN { - IGNORECASE=1 - } - # note that size 1 means it is a logical extended partition container - /[a-z][0-9]+$/ && $3 != 1 { - 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 '{ - print $(NF - 2) - }' ) - uuid_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$dev_disk_uuid" | gawk '{ - print $(NF - 2) - }' ) - - IFS="," - A_UNMOUNTED_PARTITION_DATA[i]=${a_unmounted_working[0]}","${a_unmounted_working[1]}","$label_working","$uuid_working - IFS="$ORIGINAL_IFS" - done + # create list for slicing out the mounted partitions + for (( i=0; i < ${#A_PARTITION_DATA[@]}; i++ )) + do + IFS="," + a_unmounted_working=( ${A_PARTITION_DATA[i]} ) + IFS="$ORIGINAL_IFS" + if [[ -n ${a_unmounted_working[6]} ]];then + mounted_partitions="$mounted_partitions$separator${a_unmounted_working[6]}" + separator='|' + fi + done + + A_UNMOUNTED_PARTITION_DATA=( $( grep -Ev '('$mounted_partitions')' $FILE_PARTITIONS | gawk ' + BEGIN { + IGNORECASE=1 + } + # note that size 1 means it is a logical extended partition container + /[a-z][0-9]+$/ && $3 != 1 { + 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 '{ + print $(NF - 2) + }' ) + uuid_working=$( grep -E "${a_unmounted_working[0]}$" <<< "$dev_disk_uuid" | gawk '{ + print $(NF - 2) + }' ) + + IFS="," + A_UNMOUNTED_PARTITION_DATA[i]=${a_unmounted_working[0]}","${a_unmounted_working[1]}","$label_working","$uuid_working + IFS="$ORIGINAL_IFS" + done + fi # echo "${A_UNMOUNTED_PARTITION_DATA[@]}" eval $LOGFE