(Change Version)

Added fall through /etc/lsb-release test to update distro data tests.

This adds one more failsafe test to future proof the stuff against
id failures. 

I tried to also use the standard lsb_release function but for some reason
when it's run inside inxi and sent to awk it gets incredibly slowed down.
This is odd, since that command usually runs quite fast in shell.

But it's too slow as is for now to use, it makes everything hang.

Maybe later I'll add an option to trigger it or something.
This commit is contained in:
inxi-svn 2008-11-11 01:05:55 +00:00
parent c8464427bd
commit f298a77680

125
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 0.5.2 #### version: 0.5.3
#### 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
@ -1004,51 +1004,93 @@ get_distro_data()
{ {
local i='' distro='' distro_file='' a_distro_glob='' local i='' distro='' distro_file='' a_distro_glob=''
shopt -s nullglob
cd /etc
a_distro_glob=(*[-_]{release,version})
cd "$OLDPWD"
shopt -u nullglob
if [[ ${#a_distro_glob[@]} -eq 1 ]];then # please reference this python thread: http://bugs.python.org/issue1322
distro_file="${a_distro_glob}" shopt -s nullglob
elif [[ ${#a_distro_glob[@]} -gt 1 ]];then cd /etc
for i in $DISTROS_DERIVED $DISTROS_PRIMARY a_distro_glob=(*[-_]{release,version})
do cd "$OLDPWD"
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger() shopt -u nullglob
# 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[@]} -eq 1 ]];then
## note: this method only works with [[ brackets, not [. It's very hard to actually distro_file="${a_distro_glob}"
## use this, it should probably be made more explicit. elif [[ ${#a_distro_glob[@]} -gt 1 ]];then
if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then for i in $DISTROS_DERIVED $DISTROS_PRIMARY
distro_file="${i}" do
break # Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
fi # This is a known bug, search for the word "strange" inside comments
done # echo "i='$i' a_distro_glob[@]='${a_distro_glob[@]}'"
fi ## note: this method only works with [[ brackets, not [. It's very hard to actually
if [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then ## use this, it should probably be made more explicit.
distro=$( remove_erroneous_chars "/etc/$distro_file" ) if [[ " ${a_distro_glob[@]} " == *" $i "* ]];then
# this is necessary because antiX doesn't use version/release in its distro id file name distro_file="${i}"
# so the glob tests fail. I expect those tests will need to be redone at some point to avoid this break
elif [[ -e /etc/antiX ]];then fi
distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )" done
else fi
# Debian pure should fall through here if [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
distro_file="issue" distro=$( remove_erroneous_chars "/etc/$distro_file" )
distro=$( gawk ' # this is necessary because antiX doesn't use version/release in its distro id file name
BEGIN { RS="" } { # so the glob tests fail. I expect those tests will need to be redone at some point to avoid this
gsub(/\\[a-z]/, "") elif [[ -e /etc/antiX ]];then
gsub(/,/, " ") distro="$( egrep -oi 'antix.*\.iso' <<< $( remove_erroneous_chars '/etc/antiX' ) | sed 's/\.iso//' )"
gsub(/^ +| +$/, "") else
gsub(/ [ \t]+/, " ") # Debian pure should fall through here
print distro_file="issue"
}' "/etc/${distro_file}" ) distro=$( gawk '
fi BEGIN { RS="" } {
gsub(/\\[a-z]/, "")
gsub(/,/, " ")
gsub(/^ +| +$/, "")
gsub(/ [ \t]+/, " ")
print
}' "/etc/${distro_file}" )
fi
if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then
distro="${RED}/etc/${distro_file} corrupted, use -C to override${NORMAL}" distro="${RED}/etc/${distro_file} corrupted, use -% to override${NORMAL}"
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
if [[ -f /etc/lsb-release && -z $distro ]];then
distro=$( gawk -F '=' '
{ IGNORECASE=1 }
/^DISTRIB_ID/ {
gsub(/^ +| +$/, "", $NF)
distroId = $NF
}
/^DISTRIB_RELEASE/ {
gsub(/^ +| +$/, "", $NF)
distroRelease = $NF
}
/^DISTRIB_CODENAME/ {
gsub(/^ +| +$/, "", $NF)
distroCodename = $NF
}
END {
print distroId " " distroRelease " (" distroCodename ")"
}' /etc/lsb-release )
# this is HORRIBLY slow, but I don't know why, it runs fast in shell
# elif [[ -n $( which lsb_release ) ]];then
# distro=$( echo "$( lsb_release -irc )" | gawk '
# { IGNORECASE=1 }
# /^Distributor ID/ {
# gsub(/^ +| +$/, "", $NF)
# distroId = $NF
# }
# /^Release/ {
# gsub(/^ +| +$/, "", $NF)
# distroRelease = $NF
# }
# /^Codename/ {
# gsub(/^ +| +$/, "", $NF)
# distroCodename = $NF
# }
# END {
# print distroId " " distroRelease " (" distroCodename ")"
# }' )
fi
if [[ -z $distro ]];then if [[ -z $distro ]];then
distro='Unknown distro o_O' distro='Unknown distro o_O'
fi fi
@ -1057,6 +1099,7 @@ get_distro_data()
if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
distro='Arch Linux' distro='Arch Linux'
fi fi
echo "$distro" echo "$distro"
} }