mirror of
https://github.com/smxi/inxi.git
synced 2024-11-17 00:31:19 +00:00
added in fallback mode /etc/os-release for all distros, and as preferred mode for Arch, which
is I believe the only one that actually uses this at this point. Preferred is lsb-release, because that tends to be more accurate. Note, this may trigger arch derived distro errors, sigh...
This commit is contained in:
parent
bfce0a8fd7
commit
b9fdb8b36a
231
inxi
231
inxi
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Script Name: inxi
|
#### Script Name: inxi
|
||||||
#### version: 1.8.18
|
#### version: 1.8.19
|
||||||
#### Date: October 3 2012
|
#### Date: October 3 2012
|
||||||
#### Patch Number: 00
|
#### Patch Number: 00
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -315,7 +315,7 @@ B_MDSTAT_FILE='false'
|
||||||
B_MEMINFO_FILE='false'
|
B_MEMINFO_FILE='false'
|
||||||
B_MODULES_FILE='false' #
|
B_MODULES_FILE='false' #
|
||||||
B_MOUNTS_FILE='false'
|
B_MOUNTS_FILE='false'
|
||||||
B_OS_RELEASE='false' # new default distro id file? will this one work where lsb-release didn't?
|
B_OS_RELEASE_FILE='false' # new default distro id file? will this one work where lsb-release didn't?
|
||||||
B_PARTITIONS_FILE='false' #
|
B_PARTITIONS_FILE='false' #
|
||||||
B_PROC_DIR='false'
|
B_PROC_DIR='false'
|
||||||
B_SCSI_FILE='false'
|
B_SCSI_FILE='false'
|
||||||
|
@ -508,8 +508,10 @@ CN=''
|
||||||
DISTROS_DERIVED="antix-version aptosid-version kanotix-version knoppix-version mandrake-release pardus-release sabayon-release siduction-version sidux-version turbolinux-release zenwalk-version"
|
DISTROS_DERIVED="antix-version aptosid-version kanotix-version knoppix-version mandrake-release pardus-release sabayon-release siduction-version sidux-version turbolinux-release zenwalk-version"
|
||||||
# debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
|
# debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
|
||||||
DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
|
DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
|
||||||
DISTROS_PRIMARY="gentoo-release redhat-release slackware-version SuSE-release"
|
DISTROS_PRIMARY="arch-release gentoo-release redhat-release slackware-version SuSE-release"
|
||||||
DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
|
DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
|
||||||
|
# almost no distros are using this normally, and derived distros are not using it at all as far as I can see so far
|
||||||
|
DISTROS_OS_RELEASE_GOOD="arch-release"
|
||||||
## Distros with known problems
|
## Distros with known problems
|
||||||
# DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
|
# DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
|
||||||
# Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
|
# Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially
|
||||||
|
@ -726,7 +728,7 @@ initialize_script_data()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f $FILE_OS_RELEASE ]];then
|
if [[ -f $FILE_OS_RELEASE ]];then
|
||||||
B_OS_FILE='true'
|
B_OS_RELEASE_FILE='true'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -e $FILE_SCSI ]];then
|
if [[ -e $FILE_SCSI ]];then
|
||||||
|
@ -3593,6 +3595,8 @@ get_distro_data()
|
||||||
##
|
##
|
||||||
if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_FILE == 'true' ]];then
|
if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_FILE == 'true' ]];then
|
||||||
distro_file='lsb-release'
|
distro_file='lsb-release'
|
||||||
|
elif [[ " $DISTROS_OS_RELEASE_GOOD " == *" ${i} "* ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then
|
||||||
|
distro_file='os-release'
|
||||||
else
|
else
|
||||||
distro_file="${i}"
|
distro_file="${i}"
|
||||||
fi
|
fi
|
||||||
|
@ -3607,10 +3611,12 @@ get_distro_data()
|
||||||
# this handles case where only one release/version file was found, and it's lsb-release. This would
|
# 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
|
# 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.
|
# if there's a specific distro release file available, that's to be preferred, but this is a good backup.
|
||||||
elif [[ -n $distro_file && -f $FILE_LSB_RELEASE && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then
|
elif [[ -n $distro_file && $B_LSB_FILE == 'true' && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then
|
||||||
distro=$( get_distro_lsb_data )
|
distro=$( get_distro_lsb_osrelease_data 'lsb-file' )
|
||||||
elif [[ $distro_file == 'lsb-release' ]];then
|
elif [[ $distro_file == 'lsb-release' ]];then
|
||||||
distro=$( get_distro_lsb_data )
|
distro=$( get_distro_lsb_osrelease_data 'lsb-file' )
|
||||||
|
elif [[ $distro_file == 'os-release' ]];then
|
||||||
|
distro=$( get_distro_lsb_osrelease_data 'os-release-file' )
|
||||||
# then if the distro id file was found and it's not in the exluded primary distro file list, read it
|
# 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
|
elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then
|
||||||
distro=$( remove_erroneous_chars "/etc/$distro_file" )
|
distro=$( remove_erroneous_chars "/etc/$distro_file" )
|
||||||
|
@ -3619,7 +3625,7 @@ get_distro_data()
|
||||||
# lsb gives more manageable and accurate output than issue, but mint should use issue for now
|
# 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 ]]
|
# some bashism, boolean must be in parenthesis to work correctly, ie [[ $(boolean) ]] not [[ $boolean ]]
|
||||||
if [[ $B_LSB_FILE == '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 )
|
distro=$( get_distro_lsb_osrelease_data 'lsb-file' )
|
||||||
else
|
else
|
||||||
distro=$( gawk '
|
distro=$( gawk '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
|
@ -3632,10 +3638,17 @@ get_distro_data()
|
||||||
gsub(/ [ \t]+/, " ")
|
gsub(/ [ \t]+/, " ")
|
||||||
print
|
print
|
||||||
}' /etc/issue )
|
}' /etc/issue )
|
||||||
|
|
||||||
|
# this handles an arch bug where /etc/arch-release is empty and /etc/issue is corrupted
|
||||||
|
# only older arch installs that have not been updated should have this fallback required, new ones use
|
||||||
|
# os-release
|
||||||
|
if [[ -n $( grep -i 'arch linux' <<< $distro ) ]];then
|
||||||
|
distro='Arch Linux'
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
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 -% 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
|
||||||
|
@ -3643,7 +3656,10 @@ get_distro_data()
|
||||||
## test for /etc/lsb-release as a backup in case of failure, in cases where > one version/release file
|
## 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
|
## were found but the above resulted in null distro value
|
||||||
if [[ -z $distro ]] && [[ $B_LSB_FILE == 'true' ]];then
|
if [[ -z $distro ]] && [[ $B_LSB_FILE == 'true' ]];then
|
||||||
distro=$( get_distro_lsb_data )
|
distro=$( get_distro_lsb_osrelease_data 'lsb-file' )
|
||||||
|
fi
|
||||||
|
if [[ -z $distro ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then
|
||||||
|
distro=$( get_distro_lsb_osrelease_data 'os-release-file' )
|
||||||
fi
|
fi
|
||||||
# now some final null tries
|
# now some final null tries
|
||||||
if [[ -z $distro ]];then
|
if [[ -z $distro ]];then
|
||||||
|
@ -3658,94 +3674,131 @@ get_distro_data()
|
||||||
fi
|
fi
|
||||||
fi
|
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"
|
||||||
log_function_data "distro: $distro"
|
log_function_data "distro: $distro"
|
||||||
eval $LOGFE
|
eval $LOGFE
|
||||||
}
|
}
|
||||||
|
|
||||||
# args: $1 - optional, app, uses the app test, not being used now
|
# args: $1 - lsb-file/lsb-app/os-release-file
|
||||||
get_distro_lsb_data()
|
get_distro_lsb_osrelease_data()
|
||||||
{
|
{
|
||||||
eval $LOGFS
|
eval $LOGFS
|
||||||
local distro=''
|
local distro=''
|
||||||
|
|
||||||
if [[ $B_LSB_FILE == 'true' ]] && [[ $1 != 'app' ]];then
|
case $1 in
|
||||||
distro=$( gawk -F '=' '
|
lsb-file)
|
||||||
BEGIN {
|
if [[ $B_LSB_FILE == 'true' ]];then
|
||||||
IGNORECASE=1
|
distro=$( gawk -F '=' '
|
||||||
}
|
BEGIN {
|
||||||
# note: adding the spacing directly to variable to make sure distro output is null if not found
|
IGNORECASE=1
|
||||||
/^DISTRIB_ID/ {
|
}
|
||||||
gsub(/^ +| +$/, "", $NF)
|
# note: adding the spacing directly to variable to make sure distro output is null if not found
|
||||||
# this is needed because grep for "arch" is too loose to be safe
|
/^DISTRIB_ID/ {
|
||||||
if ( $NF == "arch" ) {
|
gsub(/^ +| +$/, "", $NF)
|
||||||
distroId = "Arch Linux"
|
# this is needed because grep for "arch" is too loose to be safe
|
||||||
}
|
if ( $NF == "arch" ) {
|
||||||
else if ( $NF != "n/a" ) {
|
distroId = "Arch Linux"
|
||||||
distroId = $NF " "
|
}
|
||||||
}
|
else if ( $NF != "n/a" ) {
|
||||||
}
|
distroId = $NF " "
|
||||||
/^DISTRIB_RELEASE/ {
|
}
|
||||||
gsub(/^ +| +$/, "", $NF)
|
}
|
||||||
if ( $NF != "n/a" ) {
|
/^DISTRIB_RELEASE/ {
|
||||||
distroRelease = $NF " "
|
gsub(/^ +| +$/, "", $NF)
|
||||||
}
|
if ( $NF != "n/a" ) {
|
||||||
}
|
distroRelease = $NF " "
|
||||||
/^DISTRIB_CODENAME/ {
|
}
|
||||||
gsub(/^ +| +$/, "", $NF)
|
}
|
||||||
if ( $NF != "n/a" ) {
|
/^DISTRIB_CODENAME/ {
|
||||||
distroCodename = $NF " "
|
gsub(/^ +| +$/, "", $NF)
|
||||||
}
|
if ( $NF != "n/a" ) {
|
||||||
}
|
distroCodename = $NF " "
|
||||||
# sometimes some distros cannot do their lsb-release files correctly, so here is
|
}
|
||||||
# one last chance to get it right.
|
}
|
||||||
/^DISTRIB_DESCRIPTION/ {
|
# sometimes some distros cannot do their lsb-release files correctly, so here is
|
||||||
gsub(/^ +| +$/, "", $0)
|
# one last chance to get it right.
|
||||||
if ( $NF != "n/a" ) {
|
/^DISTRIB_DESCRIPTION/ {
|
||||||
# slice out the part inside "", like: DISTRIB_DESCRIPTION="Arch Linux"
|
gsub(/^ +| +$/, "", $0)
|
||||||
gsub(/DISTRIB_DESCRIPTION=|"/,"",$0)
|
if ( $NF != "n/a" ) {
|
||||||
distroDescription = $0
|
# slice out the part inside "", like: DISTRIB_DESCRIPTION="Arch Linux"
|
||||||
}
|
gsub(/DISTRIB_DESCRIPTION=|"/,"",$0)
|
||||||
}
|
distroDescription = $0
|
||||||
END {
|
}
|
||||||
fullString=""
|
}
|
||||||
if ( distroId == "" && distroRelease == "" && distroCodename == "" && distroDescription != "" ){
|
END {
|
||||||
fullString = distroDescription
|
fullString=""
|
||||||
}
|
if ( distroId == "" && distroRelease == "" && distroCodename == "" && distroDescription != "" ){
|
||||||
else {
|
fullString = distroDescription
|
||||||
fullString = distroId distroRelease distroCodename
|
}
|
||||||
}
|
else {
|
||||||
print fullString
|
fullString = distroId distroRelease distroCodename
|
||||||
}
|
}
|
||||||
' $FILE_LSB_RELEASE )
|
print fullString
|
||||||
log_function_data 'cat' "$FILE_LSB_RELEASE"
|
}
|
||||||
fi
|
' $FILE_LSB_RELEASE )
|
||||||
# this is HORRIBLY slow, but I don't know why, it runs fast in shell
|
log_function_data 'cat' "$FILE_LSB_RELEASE"
|
||||||
# if [[ -n $( type -p lsb_release ) && $1 == 'app' ]];then
|
fi
|
||||||
# distro=$( echo "$( lsb_release -irc )" | gawk '
|
;;
|
||||||
# { IGNORECASE=1 }
|
lsb-app)
|
||||||
# /^Distributor ID/ {
|
# this is HORRIBLY slow, not using
|
||||||
# gsub(/^ +| +$/, "", $NF)
|
if [[ -n $( type -p lsb_release ) ]];then
|
||||||
# distroId = $NF
|
distro=$( echo "$( lsb_release -irc )" | gawk '
|
||||||
# }
|
BEGIN {
|
||||||
# /^Release/ {
|
IGNORECASE=1
|
||||||
# gsub(/^ +| +$/, "", $NF)
|
}
|
||||||
# distroRelease = $NF
|
/^Distributor ID/ {
|
||||||
# }
|
gsub(/^ +| +$/, "", $NF)
|
||||||
# /^Codename/ {
|
distroId = $NF
|
||||||
# gsub(/^ +| +$/, "", $NF)
|
}
|
||||||
# distroCodename = $NF
|
/^Release/ {
|
||||||
# }
|
gsub(/^ +| +$/, "", $NF)
|
||||||
# END {
|
distroRelease = $NF
|
||||||
# print distroId " " distroRelease " (" distroCodename ")"
|
}
|
||||||
# }' )
|
/^Codename/ {
|
||||||
# fi
|
gsub(/^ +| +$/, "", $NF)
|
||||||
|
distroCodename = $NF
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
print distroId " " distroRelease " (" distroCodename ")"
|
||||||
|
}' )
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
os-release-file)
|
||||||
|
if [[ $B_OS_RELEASE_FILE == 'true' ]];then
|
||||||
|
distro=$( gawk -F '=' '
|
||||||
|
BEGIN {
|
||||||
|
IGNORECASE=1
|
||||||
|
prettyName=""
|
||||||
|
regularName=""
|
||||||
|
distroName=""
|
||||||
|
}
|
||||||
|
# note: adding the spacing directly to variable to make sure distro output is null if not found
|
||||||
|
/^PRETTY_NAME/ {
|
||||||
|
gsub(/^ +| +$|\"/, "", $NF)
|
||||||
|
if ( $NF != "n/a" ) {
|
||||||
|
prettyName = $NF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/^NAME/ {
|
||||||
|
gsub(/^ +| +$|\"/, "", $NF)
|
||||||
|
if ( $NF != "n/a" ) {
|
||||||
|
regularName = $NF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
if ( prettyName != "" ){
|
||||||
|
distroName = prettyName
|
||||||
|
}
|
||||||
|
else if ( regularName != "" ){
|
||||||
|
distroName = regularName
|
||||||
|
}
|
||||||
|
print distroName
|
||||||
|
}
|
||||||
|
' $FILE_OS_RELEASE )
|
||||||
|
log_function_data 'cat' "$FILE_OS_RELEASE"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
echo $distro
|
echo $distro
|
||||||
log_function_data "distro: $distro"
|
log_function_data "distro: $distro"
|
||||||
eval $LOGFE
|
eval $LOGFE
|
||||||
|
|
Loading…
Reference in a new issue