From a2ccd182787a307792cfa4549d97d5c6da5bf9e1 Mon Sep 17 00:00:00 2001 From: cyeoh <> Date: Sep 29 2000 04:09:32 +0000 Subject: Merge in changes from mdomi@users.sourceforge.net --- diff --git a/lsb_release/src/lsb_release b/lsb_release/src/lsb_release index fde2e94..78368da 100755 --- a/lsb_release/src/lsb_release +++ b/lsb_release/src/lsb_release @@ -1,14 +1,22 @@ #!/bin/sh # About: This shell script is the lsb_release implementation, # Version: see SCRIPTVERSION (in the Declarations section) -# Licence: GPL (latest version) +# Licence: GPL (latest version), Free Software Group, Inc # Author: Dominique MASSONIE -# Date: August 7th, 2000 +# Date: September 27th, 2000 +# +# * Changes in 1.1 +# - removed some bash-ism and typos (me) +# Notice: script remains broken with ash because of awk issues +# - changed licence to FSG - "Free Software Group, Inc" (me) +# - fixed problem with --short single arg call (me) +# - changed Debian specifics, codename anticipates release num (me) # -# Required information in /etc/lsb-release -# LSB_VERSION -# Optional information in /etc/lsb-release -# DISTRIB_ID, DISTRIB_RELEASE, DISTRIB_CODENAME, DISTRIB_DESCRIPTION +# Description: +# Collect informations from sourceable /etc/lsb-release file (present on +# LSB-compliant systems) : LSB_VERSION (required) and (optional) +# DISTRIB_ID, DISTRIB_RELEASE, DISTRIB_CODENAME, DISTRIB_DESCRIPTION. +# Then (if needed) find and parse the /etc/[distro]-release file. ############################################################################### @@ -16,7 +24,7 @@ ############################################################################### # This script version -SCRIPTVERSION="1.0" +SCRIPTVERSION="1.1" # Defines the data files INFO_ROOT="/etc" # directory of config files @@ -54,25 +62,13 @@ DESCSTR_DELI="release" # FUNCTIONS ############################################################################### -function Version() { # Notice: not used, but for man page generation - echo "GNU ${0##*/} $SCRIPTVERSION" - echo - echo "Copyright (C) 2000 Free Software Foundation, Inc." - echo "This is free software; see the source for copying conditions. There\ - is NO" - echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR\ - PURPOSE." - echo - echo "Written by Dominique MASSONIE." -} - # defines the Usage for lsb_release -function Usage() { - echo "GNU \`${0##*/} $SCRIPTVERSION' print certain LSB (Linux Standard\ - Base) and" +Usage() { + echo "LSB `basename $0` $SCRIPTVERSION print certain LSB (Linux\ + Standard Base) and" echo "Distribution information." echo - echo "Usage: ${0##*/} [OPTION]..." + echo "Usage: `basename $0` [OPTION]..." echo "With no OPTION, same as -v." echo echo "Options:" @@ -97,7 +93,7 @@ function Usage() { } # Handles the enhanced args (i.e. --something) -function EnhancedGetopt() { +EnhancedGetopt() { getopt -T >/dev/null 2>&1 # is getopt the enhanced one ? if [ $? = 4 ] then # Yes, advanced args ALLOWED @@ -135,23 +131,23 @@ function EnhancedGetopt() { } # Get/Init LSB infos (maybe Distrib infos too) -function GetLSBInfo() { +GetLSBInfo() { if [ -f "$INFO_ROOT/$INFO_LSB_FILE" ] then - # should init at least LSB_VERSION - source "$INFO_ROOT/$INFO_LSB_FILE" - [ -z "$LSB_VERSION" ] && echo "$MSG_LSBBADFILE" \ - && exit $ERROR_LSBBADFILE + # should init at least LSB_VERSION + source "$INFO_ROOT/$INFO_LSB_FILE" + [ -z "$LSB_VERSION" ] && echo "$MSG_LSBBADFILE" \ + && exit $ERROR_LSBBADFILE else - LSB_VERSION=$MSG_NA # Exit code remains Ok (not ERROR_NOANSWER) + LSB_VERSION=$MSG_NA # Exit code remains Ok (not ERROR_NOANSWER) fi } # Get the whole distrib information string (from ARG $1 file) -function InitDistribInfo() { +InitDistribInfo() { ## Notice: Debian has a debian_version file ## (at least) Mandrake has two files, a mandrake and a redhat one - local FILENAME=$1 # CHECKFIRST or find result in GetDistribInfo() or "" + local FILENAME=$1 # CHECKFIRST or finds' result in GetDistribInfo() or "" if [ -z "$FILENAME" ] then @@ -163,57 +159,57 @@ function InitDistribInfo() { [ -z "$DISTRIB_CODENAME" ] && [ "$DISTRIB_RELEASE" = "2.1" ] \ && DISTRIB_CODENAME="Slink" [ -z "$DISTRIB_CODENAME" ] && [ "$DISTRIB_RELEASE" = "2.2" ] \ - && DISTRIB_CODENAME="Potato" - [ -z "$DISTRIB_CODENAME" ] && [ "$DISTRIB_RELEASE" = "2.3" ] \ - && DISTRIB_CODENAME="Woody" - [ -z "$DISTRIB_CODENAME" ] && DISTRIB_CODENAME=$MSG_NA \ - && EXIT_STATUS=$ERROR_NOANSWER + && DISTRIB_CODENAME="Potato" +# [ -z "$DISTRIB_CODENAME" ] && [ "$DISTRIB_RELEASE" = "2.3" ] \ +# && DISTRIB_CODENAME="Woody" + [ -z "$DISTRIB_CODENAME" ] && DISTRIB_CODENAME=$DISTRIB_RELEASE # build the DISTRIB_DESCRIPTION string (never need to be parsed) - [ -z "$DISTRIB_DESCRIPTION" ] \ + [ -z "$DISTRIB_DESCRIPTION" ] \ && DISTRIB_DESCRIPTION="$DISTRIB_ID $DESCSTR_DELI \ $DISTRIB_RELEASE ($DISTRIB_CODENAME)" else # Only for nothing known compliant distrib :( [ -z "$DISTRIB_ID" ] && DISTRIB_ID=$MSG_NA [ -z "$DISTRIB_RELEASE" ] && DISTRIB_RELEASE=$MSG_NA [ -z "$DISTRIB_CODENAME" ] && DISTRIB_CODENAME=$MSG_NA - [ -z "$DISTRIB_DESCRIPTION" ] && DISTRIB_DESCRIPTION=$MSG_NONE + [ -z "$DISTRIB_DESCRIPTION" ] && DISTRIB_DESCRIPTION=$MSG_NONE EXIT_STATUS=$ERROR_NOANSWER fi else local NO="" # is Description string syntax correct ? - if [ -z "$DISTRIB_DESCRIPTION" ] \ - || [ "${DISTRIB_DESCRIPTION/$DESCSTR_DELI/}" = "$DISTRIB_DESCRIPTION" ] - then - TMP_DISTRIB_DESC=$(head -1 $FILENAME 2>/dev/null) - [ -z "$DISTRIB_DESCRIPTION" ] \ - && DISTRIB_DESCRIPTION=$TMP_DISTRIB_DESC - else - TMP_DISTRIB_DESC=$DISTRIB_DESCRIPTION - fi + if [ -z "$DISTRIB_DESCRIPTION" ] \ + || [ -n "$(echo $DISTRIB_DESCRIPTION | \ + sed -e "s/.*$DESCSTR_DELI.*//")" ] + then + TMP_DISTRIB_DESC=$(head -1 $FILENAME 2>/dev/null) + [ -z "$DISTRIB_DESCRIPTION" ] \ + && DISTRIB_DESCRIPTION=$TMP_DISTRIB_DESC + else + TMP_DISTRIB_DESC=$DISTRIB_DESCRIPTION + fi if [ -z "$TMP_DISTRIB_DESC" ] # head or lsb-release init - then # file contains no data - DISTRIB_DESCRIPTION=$MSG_NONE - NO="y" - else # Do simple check - [ "${TMP_DISTRIB_DESC/$DESCSTR_DELI/}" = "$TMP_DISTRIB_DESC" ] \ - && NO="y" - fi - - if [ -n "$NO" ] - then # does not contain "release" delimiter - [ -z "$DISTRIB_ID" ] && DISTRIB_ID=$MSG_NA - [ -z "$DISTRIB_RELEASE" ] && DISTRIB_RELEASE=$MSG_NA - [ -z "$DISTRIB_CODENAME" ] && DISTRIB_CODENAME=$MSG_NA - fi + then # file contains no data + DISTRIB_DESCRIPTION=$MSG_NONE + NO="y" + else # Do simple check + [ -n "$(echo $TMP_DISTRIB_DESC | \ + sed -e "s/.*$DESCSTR_DELI.*//")" ] \ + && NO="y" + fi + + if [ -n "$NO" ] + then # does not contain "release" delimiter + [ -z "$DISTRIB_ID" ] && DISTRIB_ID=$MSG_NA + [ -z "$DISTRIB_RELEASE" ] && DISTRIB_RELEASE=$MSG_NA + [ -z "$DISTRIB_CODENAME" ] && DISTRIB_CODENAME=$MSG_NA + fi fi } # Check missing and requested infos, then find the file and get infos -function GetDistribInfo() { - local NO="" - # check if info set in the LSB file are enough to reply what is requested? +GetDistribInfo() { + local NO="" # /etc/lsb-release data are enough to reply what is requested? [ -n "$ARG_D" ] && [ -z "$DISTRIB_DESCRIPTION" ] && NO="y" [ -z "$NO" ] && [ -n "$ARG_I" ] && [ -z "$DISTRIB_ID" ] && NO="y" [ -z "$NO" ] && [ -n "$ARG_R" ] && [ -z "$DISTRIB_RELEASE" ] && NO="y" @@ -221,40 +217,40 @@ function GetDistribInfo() { if [ -n "$NO" ] then - if [ ! -f "$CHECKFIRST" ] - then - CHECKFIRST=$(find $INFO_ROOT/ -maxdepth 1 \ - -name \*$INFO_DISTRIB_SUFFIX \ - -and ! -name $INFO_LSB_FILE \ - -and -type f \ - 2>/dev/null \ + if [ ! -f "$CHECKFIRST" ] + then + CHECKFIRST=$(find $INFO_ROOT/ -maxdepth 1 \ + -name \*$INFO_DISTRIB_SUFFIX \ + -and ! -name $INFO_LSB_FILE \ + -and -type f \ + 2>/dev/null \ | awk 'END { print $1 ;}') # multi file pb: keep the last # -and ! -perm +0111 seems broken on Mandrake 7.0 - fi - InitDistribInfo $CHECKFIRST + fi + InitDistribInfo $CHECKFIRST fi } # Display version of LSB against which distribution is compliant -function DisplayVersion() { +DisplayVersion() { if [ -z "$ARG_S" ] then - echo -e "$MSG_LSBVER$LSB_VERSION" # at least "n/a" + echo -e "$MSG_LSBVER$LSB_VERSION" # at least "n/a" else - MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$LSB_VERSION" + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$LSB_VERSION" fi } # Display string id of distributor ( i.e. a single word! ) -function DisplayID() { +DisplayID() { if [ -z "$DISTRIB_ID" ] then ## Linux could be part of the distro name (i.e. Turbolinux) or a separate word ## set before, after... -## also expect "release" as delimiter (else stop when NumberOfField reached) - DISTRIB_ID=$(echo $TMP_DISTRIB_DESC \ +## also expect "release" as delimiter (else stop when NumberofField reached) + DISTRIB_ID=$(echo "$TMP_DISTRIB_DESC" \ | awk --assign delimiter="$DESCSTR_DELI" --assign na="$MSG_NA" \ - 'BEGIN { \ + 'BEGIN { \ i = 1 ; res = "" \ } \ { \ @@ -265,22 +261,22 @@ function DisplayID() { } \ } \ END { \ - if (i == NF || res == "" ) \ - print na ; \ - else \ - print res ; \ + if ( i == NF || res == "" ) \ + print na ; \ + else \ + print res ; \ }') fi if [ -z "$ARG_S" ] then - echo -e "$MSG_DISTID$DISTRIB_ID" + echo -e "$MSG_DISTID$DISTRIB_ID" else - MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$DISTRIB_ID" + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$DISTRIB_ID" fi } # Diplay single line text description of distribution -function DisplayDescription() { +DisplayDescription() { if [ -z "$DISTRIB_DESCRIPTION" ] then # should not be empty since GetDistribInfo called on Initialization ! @@ -288,45 +284,47 @@ function DisplayDescription() { fi if [ -z "$ARG_S" ] then - echo -e "$MSG_DISTDESC$DISTRIB_DESCRIPTION" + echo -e "$MSG_DISTDESC$DISTRIB_DESCRIPTION" else - MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }\"$DISTRIB_DESCRIPTION\"" + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }\"$DISTRIB_DESCRIPTION\"" fi } # Display release number of distribution. -function DisplayRelease() { +DisplayRelease() { if [ -z "$DISTRIB_RELEASE" ] then # parse the "$DISTRIB_DESCRIPTION" string DISTRIB_RELEASE=$(echo "$TMP_DISTRIB_DESC" | \ sed -e "s/.*$DESCSTR_DELI[[:blank:]]*\([[:digit:]][[:graph:]]*\).*/\1/" ) - [ "$DISTRIB_RELEASE" = "$TMP_DISTRIB_DESC" ] \ - || [ -z "$DISTRIB_RELEASE" ] \ - && DISTRIB_RELEASE=$MSG_NA + [ "$DISTRIB_RELEASE" = "$TMP_DISTRIB_DESC" ] \ + || [ -z "$DISTRIB_RELEASE" ] \ + && DISTRIB_RELEASE=$MSG_NA fi if [ -z "$ARG_S" ] then - echo -e "$MSG_DISTREL$DISTRIB_RELEASE" + echo -e "$MSG_DISTREL$DISTRIB_RELEASE" else - MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$DISTRIB_RELEASE" + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$DISTRIB_RELEASE" fi } # Display codename according to distribution version. -function DisplayCodename() { +DisplayCodename() { if [ -z "$DISTRIB_CODENAME" ] then # parse the "$DISTRIB_DESCRIPTION" string DISTRIB_CODENAME=$(echo "$TMP_DISTRIB_DESC" | \ - sed -e "s/.*$DESCSTR_DELI.*(\(.*\)).*/\1/") - [ "$DISTRIB_CODENAME" = "$TMP_DISTRIB_DESC" ] \ - || [ -z "$DISTRIB_CODENAME" ] \ - && DISTRIB_CODENAME=$MSG_NA + sed -e "s/.*$DESCSTR_DELI.*(\(.*\)).*/\1/") + [ "$DISTRIB_CODENAME" = "$TMP_DISTRIB_DESC" ] \ + || [ -z "$DISTRIB_CODENAME" ] \ + && DISTRIB_CODENAME=$MSG_NA fi if [ -z "$ARG_S" ] then - echo -e "$MSG_DISTCODE${DISTRIB_CODENAME// /}" # Remove blanks + echo -e "$MSG_DISTCODE$(echo "$DISTRIB_CODENAME" | \ + tr -d "[:blank:]")" # Remove blanks else - MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }${DISTRIB_CODENAME// /}" + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$(echo "$DISTRIB_CODENAME" | \ + tr -d "[:blank:]")" fi } @@ -338,9 +336,13 @@ function DisplayCodename() { # Check if any prog argument if [ -z "$1" ] then - ARG_V="y" # default set to Display LSB Version (not Usage) + ARG_V="y" # default set to Display LSB Version (not Usage) else - EnhancedGetopt "$@" # Parse program args + EnhancedGetopt "$@" # Parse program args + if [ -n "$ARG_S" ] && [ "$#" = "1" ] + then + ARG_V="y" # set also default for --short when single arg + fi fi # Update args to All if requested