(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

133
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 0.5.3
#### version: 0.5.5
#### Date: November 10 2008
########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -999,62 +999,88 @@ get_cpu_data()
IFS="$ORIGINAL_IFS"
}
# for more on distro id, please reference this python thread: http://bugs.python.org/issue1322
## return distro name/id if found
get_distro_data()
{
local i='' distro='' distro_file='' a_distro_glob=''
# get the wild carded array of release/version /etc files if present
shopt -s nullglob
cd /etc
a_distro_glob=(*[-_]{release,version})
cd "$OLDPWD"
shopt -u nullglob
# please reference this python thread: http://bugs.python.org/issue1322
shopt -s nullglob
cd /etc
a_distro_glob=(*[-_]{release,version})
cd "$OLDPWD"
shopt -u nullglob
if [[ ${#a_distro_glob[@]} -eq 1 ]];then
distro_file="${a_distro_glob}"
# use the file if it's in the known good lists
elif [[ ${#a_distro_glob[@]} -gt 1 ]];then
for i in $DISTROS_DERIVED $DISTROS_PRIMARY
do
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
# This is a known bug, search for the word "strange" inside comments
# echo "i='$i' a_distro_glob[@]='${a_distro_glob[@]}'"
if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then
distro_file="${i}"
break
fi
done
fi
if [[ ${#a_distro_glob[@]} -eq 1 ]];then
distro_file="${a_distro_glob}"
elif [[ ${#a_distro_glob[@]} -gt 1 ]];then
for i in $DISTROS_DERIVED $DISTROS_PRIMARY
do
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
# This is a known bug, search for the word "strange" inside comments
# 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
distro_file="${i}"
break
fi
done
fi
if [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
distro=$( remove_erroneous_chars "/etc/$distro_file" )
# this is necessary because antiX doesn't use version/release in its distro id file name
# 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//' )"
else
# Debian pure should fall through here
distro_file="issue"
distro=$( gawk '
BEGIN { RS="" } {
gsub(/\\[a-z]/, "")
gsub(/,/, " ")
gsub(/^ +| +$/, "")
gsub(/ [ \t]+/, " ")
print
}' "/etc/${distro_file}" )
fi
# first test for the legacy antiX distro id file
if [[ -e /etc/antiX ]];then
distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )"
# this handles case where only one release/version file was found, and it's lsb-release. This would
# never apply for ubuntu or debian, which will filter down to the following conditions. In general
# 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 '
BEGIN { RS="" } {
gsub(/\\[a-z]/, "")
gsub(/,/, " ")
gsub(/^ +| +$/, "")
gsub(/ [ \t]+/, " ")
print
}' /etc/issue )
fi
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
## 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
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 '=' '
{ IGNORECASE=1 }
/^DISTRIB_ID/ {
gsub(/^ +| +$/, "", $NF)
@ -1091,16 +1117,8 @@ get_distro_data()
# print distroId " " distroRelease " (" distroCodename ")"
# }' )
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
if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
distro='Arch Linux'
fi
echo "$distro"
echo $distro
}
## create array of gfx cards installed on system
@ -1275,6 +1293,10 @@ get_hdd_data_basic()
print c
}' )
if [[ -z $hdd_used ]];then
hdd_used='na'
fi
# create the initial array strings:
# disk-dev, capacity, name, usb or not
# final item is the total of the disk
@ -1293,11 +1315,16 @@ get_hdd_data_basic()
END {
size = size*1024/1000**3 # calculate size in GB size
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 = sprintf( "%.1f", diskUsed )
size = sprintf( "%.1f", size )
print size"GB,"diskUsed"% used"
print size "GB," diskUsed "% used"
}
else {
print "NA,-" # print an empty array, this will be further handled in the print out function