(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

47
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 0.5.2
#### version: 0.5.3
#### Date: November 10 2008
########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -1004,6 +1004,8 @@ get_distro_data()
{
local i='' distro='' distro_file='' a_distro_glob=''
# please reference this python thread: http://bugs.python.org/issue1322
shopt -s nullglob
cd /etc
a_distro_glob=(*[-_]{release,version})
@ -1044,11 +1046,51 @@ get_distro_data()
print
}' "/etc/${distro_file}" )
fi
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
## 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
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
distro='Unknown distro o_O'
fi
@ -1057,6 +1099,7 @@ get_distro_data()
if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
distro='Arch Linux'
fi
echo "$distro"
}