diff --git a/inxi b/inxi index 2bddde5..a15d0b2 100755 --- a/inxi +++ b/inxi @@ -1,7 +1,7 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 1.8.18 +#### version: 1.8.19 #### Date: October 3 2012 #### Patch Number: 00 ######################################################################## @@ -315,7 +315,7 @@ B_MDSTAT_FILE='false' B_MEMINFO_FILE='false' B_MODULES_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_PROC_DIR='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" # 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_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" +# 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 # 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 @@ -726,7 +728,7 @@ initialize_script_data() fi if [[ -f $FILE_OS_RELEASE ]];then - B_OS_FILE='true' + B_OS_RELEASE_FILE='true' fi if [[ -e $FILE_SCSI ]];then @@ -3588,11 +3590,13 @@ get_distro_data() # Now lets see if the distro file is in the known-good working-lsb-list # if so, use lsb-release, if not, then just use the found file # this is for only those distro's with self named release/version files - # because Mint does not use such, it must be done as below + # because Mint does not use such, it must be done as below ## this if statement requires the spaces and * as it is, else it won't work ## if [[ " $DISTROS_LSB_GOOD " == *" ${i} "* ]] && [[ $B_LSB_FILE == 'true' ]];then distro_file='lsb-release' + elif [[ " $DISTROS_OS_RELEASE_GOOD " == *" ${i} "* ]] && [[ $B_OS_RELEASE_FILE == 'true' ]];then + distro_file='os-release' else distro_file="${i}" 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 # 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 [[ -n $distro_file && -f $FILE_LSB_RELEASE && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then - distro=$( get_distro_lsb_data ) + elif [[ -n $distro_file && $B_LSB_FILE == 'true' && " $DISTROS_LSB_GOOD" == *" $distro_file "* ]];then + distro=$( get_distro_lsb_osrelease_data 'lsb-file' ) 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 elif [[ -n $distro_file && -s /etc/$distro_file && " $DISTROS_EXCLUDE_LIST " != *" $distro_file "* ]];then 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 # 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 - distro=$( get_distro_lsb_data ) + distro=$( get_distro_lsb_osrelease_data 'lsb-file' ) else distro=$( gawk ' BEGIN { @@ -3632,10 +3638,17 @@ get_distro_data() gsub(/ [ \t]+/, " ") print }' /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 - 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}" fi ## 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 ## were found but the above resulted in null distro value 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 # now some final null tries if [[ -z $distro ]];then @@ -3658,94 +3674,131 @@ get_distro_data() 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" log_function_data "distro: $distro" eval $LOGFE } -# args: $1 - optional, app, uses the app test, not being used now -get_distro_lsb_data() +# args: $1 - lsb-file/lsb-app/os-release-file +get_distro_lsb_osrelease_data() { eval $LOGFS local distro='' - - if [[ $B_LSB_FILE == 'true' ]] && [[ $1 != 'app' ]];then - distro=$( gawk -F '=' ' - BEGIN { - IGNORECASE=1 - } - # note: adding the spacing directly to variable to make sure distro output is null if not found - /^DISTRIB_ID/ { - gsub(/^ +| +$/, "", $NF) - # this is needed because grep for "arch" is too loose to be safe - if ( $NF == "arch" ) { - distroId = "Arch Linux" - } - else if ( $NF != "n/a" ) { - distroId = $NF " " - } - } - /^DISTRIB_RELEASE/ { - gsub(/^ +| +$/, "", $NF) - if ( $NF != "n/a" ) { - distroRelease = $NF " " - } - } - /^DISTRIB_CODENAME/ { - 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/ { - gsub(/^ +| +$/, "", $0) - if ( $NF != "n/a" ) { - # slice out the part inside "", like: DISTRIB_DESCRIPTION="Arch Linux" - gsub(/DISTRIB_DESCRIPTION=|"/,"",$0) - distroDescription = $0 - } - } - END { - fullString="" - if ( distroId == "" && distroRelease == "" && distroCodename == "" && distroDescription != "" ){ - fullString = distroDescription - } - else { - fullString = distroId distroRelease distroCodename - } - print fullString - } - ' $FILE_LSB_RELEASE ) - log_function_data 'cat' "$FILE_LSB_RELEASE" - fi - # this is HORRIBLY slow, but I don't know why, it runs fast in shell -# if [[ -n $( type -p lsb_release ) && $1 == 'app' ]];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 - + + case $1 in + lsb-file) + if [[ $B_LSB_FILE == 'true' ]];then + distro=$( gawk -F '=' ' + BEGIN { + IGNORECASE=1 + } + # note: adding the spacing directly to variable to make sure distro output is null if not found + /^DISTRIB_ID/ { + gsub(/^ +| +$/, "", $NF) + # this is needed because grep for "arch" is too loose to be safe + if ( $NF == "arch" ) { + distroId = "Arch Linux" + } + else if ( $NF != "n/a" ) { + distroId = $NF " " + } + } + /^DISTRIB_RELEASE/ { + gsub(/^ +| +$/, "", $NF) + if ( $NF != "n/a" ) { + distroRelease = $NF " " + } + } + /^DISTRIB_CODENAME/ { + 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/ { + gsub(/^ +| +$/, "", $0) + if ( $NF != "n/a" ) { + # slice out the part inside "", like: DISTRIB_DESCRIPTION="Arch Linux" + gsub(/DISTRIB_DESCRIPTION=|"/,"",$0) + distroDescription = $0 + } + } + END { + fullString="" + if ( distroId == "" && distroRelease == "" && distroCodename == "" && distroDescription != "" ){ + fullString = distroDescription + } + else { + fullString = distroId distroRelease distroCodename + } + print fullString + } + ' $FILE_LSB_RELEASE ) + log_function_data 'cat' "$FILE_LSB_RELEASE" + fi + ;; + lsb-app) + # this is HORRIBLY slow, not using + if [[ -n $( type -p lsb_release ) ]];then + distro=$( echo "$( lsb_release -irc )" | gawk ' + BEGIN { + IGNORECASE=1 + } + /^Distributor ID/ { + gsub(/^ +| +$/, "", $NF) + distroId = $NF + } + /^Release/ { + gsub(/^ +| +$/, "", $NF) + distroRelease = $NF + } + /^Codename/ { + 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 log_function_data "distro: $distro" eval $LOGFE