(Change Version)

A series of bug and potential bug fixes:
1. In get distro data, improved handling of unfound distros significanly, handling
lsb-release testing as a fall back in 2 cases.

2. Created a new get_distro_lsb_data function to handle that processing

3. Added a last test for lsb-release presence.

4. Fixed a small bug that made ubuntu live cd hard disk size display fail.
This commit is contained in:
inxi-svn 2008-11-11 02:31:29 +00:00
parent fd1da2523a
commit 3b1e36a1ee

79
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 0.5.3 #### version: 0.5.5
#### Date: November 10 2008 #### Date: November 10 2008
######################################################################## ########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif #### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -999,13 +999,13 @@ get_cpu_data()
IFS="$ORIGINAL_IFS" IFS="$ORIGINAL_IFS"
} }
# for more on distro id, please reference this python thread: http://bugs.python.org/issue1322
## return distro name/id if found ## return distro name/id if found
get_distro_data() get_distro_data()
{ {
local i='' distro='' distro_file='' a_distro_glob='' local i='' distro='' distro_file='' a_distro_glob=''
# get the wild carded array of release/version /etc files if present
# please reference this python thread: http://bugs.python.org/issue1322
shopt -s nullglob shopt -s nullglob
cd /etc cd /etc
a_distro_glob=(*[-_]{release,version}) a_distro_glob=(*[-_]{release,version})
@ -1014,29 +1014,33 @@ get_distro_data()
if [[ ${#a_distro_glob[@]} -eq 1 ]];then if [[ ${#a_distro_glob[@]} -eq 1 ]];then
distro_file="${a_distro_glob}" distro_file="${a_distro_glob}"
# use the file if it's in the known good lists
elif [[ ${#a_distro_glob[@]} -gt 1 ]];then elif [[ ${#a_distro_glob[@]} -gt 1 ]];then
for i in $DISTROS_DERIVED $DISTROS_PRIMARY for i in $DISTROS_DERIVED $DISTROS_PRIMARY
do do
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger() # Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
# This is a known bug, search for the word "strange" inside comments # This is a known bug, search for the word "strange" inside comments
# echo "i='$i' a_distro_glob[@]='${a_distro_glob[@]}'" # echo "i='$i' a_distro_glob[@]='${a_distro_glob[@]}'"
## note: this method only works with [[ brackets, not [. It's very hard to actually
## use this, it should probably be made more explicit.
if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then
distro_file="${i}" distro_file="${i}"
break break
fi fi
done done
fi fi
if [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
distro=$( remove_erroneous_chars "/etc/$distro_file" ) # first test for the legacy antiX distro id file
# this is necessary because antiX doesn't use version/release in its distro id file name if [[ -e /etc/antiX ]];then
# so the glob tests fail. I expect those tests will need to be redone at some point to avoid this
elif [[ -e /etc/antiX ]];then
distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )" distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )"
else # this handles case where only one release/version file was found, and it's lsb-release. This would
# Debian pure should fall through here # never apply for ubuntu or debian, which will filter down to the following conditions. In general
distro_file="issue" # if there's a specific distro release file available, that's to be preferred, but this is a good backup.
elif [[ $distro_file == 'lsb-release' ]];then
distro=$( get_distro_lsb_data )
# then if the distro id file was found and it's not in the exluded primary distro file list, read it
elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
distro=$( remove_erroneous_chars "/etc/$distro_file" )
# otherwise try the default debian/ubuntu /etc/issue file
elif [[ -f /etc/issue ]];then
distro=$( gawk ' distro=$( gawk '
BEGIN { RS="" } { BEGIN { RS="" } {
gsub(/\\[a-z]/, "") gsub(/\\[a-z]/, "")
@ -1044,7 +1048,7 @@ get_distro_data()
gsub(/^ +| +$/, "") gsub(/^ +| +$/, "")
gsub(/ [ \t]+/, " ") gsub(/ [ \t]+/, " ")
print print
}' "/etc/${distro_file}" ) }' /etc/issue )
fi fi
if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then
@ -1052,9 +1056,31 @@ get_distro_data()
fi fi
## note: would like to actually understand the method even if it's not used ## note: would like to actually understand the method even if it's not used
# : ${distro:=Unknown distro o_O} # : ${distro:=Unknown distro o_O}
## test for /etc/lsb-release as a backup in case of failure ## 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 && -f /etc/lsb-release ]];then if [[ -z $distro && -f /etc/lsb-release ]];then
distro=$( get_distro_lsb_data )
fi
## finally, if all else has failed, give up
if [[ -z $distro ]];then
distro='Unknown distro o_O'
fi
# this handles an arch bug where /etc/arch-release is empty and /etc/issue is corrupted
if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
distro='Arch Linux'
fi
echo "$distro"
}
get_distro_lsb_data()
{
local distro=''
if [[ -f /etc/lsb-release ]];then
distro=$( gawk -F '=' ' distro=$( gawk -F '=' '
{ IGNORECASE=1 } { IGNORECASE=1 }
/^DISTRIB_ID/ { /^DISTRIB_ID/ {
gsub(/^ +| +$/, "", $NF) gsub(/^ +| +$/, "", $NF)
@ -1091,16 +1117,8 @@ get_distro_data()
# print distroId " " distroRelease " (" distroCodename ")" # print distroId " " distroRelease " (" distroCodename ")"
# }' ) # }' )
fi fi
if [[ -z $distro ]];then
distro='Unknown distro o_O'
fi
# this handles an arch bug where /etc/arch-release is empty and /etc/issue is corrupted echo $distro
if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
distro='Arch Linux'
fi
echo "$distro"
} }
## create array of gfx cards installed on system ## create array of gfx cards installed on system
@ -1275,6 +1293,10 @@ get_hdd_data_basic()
print c print c
}' ) }' )
if [[ -z $hdd_used ]];then
hdd_used='na'
fi
# create the initial array strings: # create the initial array strings:
# disk-dev, capacity, name, usb or not # disk-dev, capacity, name, usb or not
# final item is the total of the disk # final item is the total of the disk
@ -1293,11 +1315,16 @@ get_hdd_data_basic()
END { END {
size = size*1024/1000**3 # calculate size in GB size size = size*1024/1000**3 # calculate size in GB size
workingUsed = hddused*1024/1000**3 # calculate workingUsed in GB used workingUsed = hddused*1024/1000**3 # calculate workingUsed in GB used
if ( size > 0 && workingUsed > 0 ){ # this handles a special case with livecds where no hdd_used is detected
if ( size > 0 && hddused == "na" ) {
size = sprintf( "%.1f", size )
print size "GB,-"
}
else if ( size > 0 && workingUsed > 0 ) {
diskUsed = workingUsed*100/size # calculate used percentage diskUsed = workingUsed*100/size # calculate used percentage
diskUsed = sprintf( "%.1f", diskUsed ) diskUsed = sprintf( "%.1f", diskUsed )
size = sprintf( "%.1f", size ) size = sprintf( "%.1f", size )
print size"GB,"diskUsed"% used" print size "GB," diskUsed "% used"
} }
else { else {
print "NA,-" # print an empty array, this will be further handled in the print out function print "NA,-" # print an empty array, this will be further handled in the print out function