From 8fc7daeddfd5a44fed622e1a739d066934fe6d82 Mon Sep 17 00:00:00 2001 From: cyeoh <> Date: Sep 28 2000 09:38:43 +0000 Subject: Initial revision --- diff --git a/lsb_release/src/README b/lsb_release/src/README new file mode 100644 index 0000000..78934f7 --- /dev/null +++ b/lsb_release/src/README @@ -0,0 +1,41 @@ +This dir contains le lsb_release script and the required +ones to build the associated Man pages. + +lsb_release : version 1.0 +help2man : the GNU script to build Man from --help output +lsb_release.examples : the Man style add-on for the pages +doman : the small script to automate creation +readme : this file +lsb_release.spec: The RPM spec file + +Notice: the doman script is required to modify the --version +behavior of the lsb_release script to match help2man needs. + +Regards, + +-- Dominique + +To build and package lsb_release: + +1) Extract lsb_release from CVS: + +cvs -d :pserver:anonymous@cvs.lsb.sourceforge.net:/cvsroot/lsb checkout src + +2) Create a tar(1) ball. + +cd src/bin +mv lsb_release lsb_release-1.0 +tar czvf /usr/src/redhat/SOURCES/lsb_release-1.0.tgz lsb_release-1.0 + +3) RPM build the package + +cp lsb_release-1.0/lsb_release.spec /usr/src/redhat/SPECS +cd /usr/src/redhat/SPECS +rpm -ba lsb_release.spec + +4) Install the RPM + +rpm -i /usr/src/redhat/RPMS/i386/lsb_release-1.0-1.i386.rpm + +George (gk4) + diff --git a/lsb_release/src/doman b/lsb_release/src/doman new file mode 100755 index 0000000..2a3c03c --- /dev/null +++ b/lsb_release/src/doman @@ -0,0 +1,27 @@ +#!/bin/sh + +if [ ! -f "./lsb_release.ori" ] +then # do a backup of lsb_release + cp -p lsb_release lsb_release.ori +fi +mv -f lsb_release lsb_release.tmp # lsb_release need to be parsed for + # the help2man perl script +cat lsb_release.tmp | sed -e "s/\[ -n \"\$ARG_V\" \] \&\& DisplayVersion/\[ -n \"\$ARG_V\" \] \&\& Version/" >./lsb_release + +chmod a+x ./lsb_release + +rm -f lsb_release.1 lsb_release.1.bz2 # remove old man pages + +# build man page +./help2man -N --include ./lsb_release.examples ./lsb_release >lsb_release.1 + +bzip2 lsb_release.1 # do the needed compression + +# restore former lsb_release script +cat lsb_release | sed -e "s/\[ -n \"\$ARG_V\" \] \&\& Version/\[ -n \"\$ARG_V\" \] \&\& DisplayVersion/" >./lsb_release.tmp +mv -f lsb_release.tmp lsb_release +chmod a+x ./lsb_release + +cp lsb_release.1.bz2 /usr/man/man1/ # install place + +man lsb_release # view the result diff --git a/lsb_release/src/help2man b/lsb_release/src/help2man new file mode 100755 index 0000000..0d06fe8 --- /dev/null +++ b/lsb_release/src/help2man @@ -0,0 +1,513 @@ +#!/usr/bin/perl -w + +# Generate a short man page from --help and --version output. +# Copyright � 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Written by Brendan O'Dea +# Available from ftp://ftp.gnu.org/gnu/help2man/ + +use 5.004; +use strict; +use Getopt::Long; +use Text::Tabs qw(expand); +use POSIX qw(strftime setlocale LC_TIME); + +my $this_program = 'help2man'; +my $this_version = '1.022'; +my $version_info = < +EOT + +my $help_info = <. +EOT + +my $section = 1; +my ($opt_name, @opt_include, $opt_output, $opt_no_info); + +# Parse options. +Getopt::Long::config('bundling'); +GetOptions ( + 'n|name=s' => \$opt_name, + 's|section=s' => \$section, + 'i|include=s' => sub { push @opt_include, [ pop, 1 ] }, + 'I|opt-include=s' => sub { push @opt_include, [ pop, 0 ] }, + 'o|output=s' => \$opt_output, + 'N|no-info' => \$opt_no_info, + help => sub { print $help_info; exit }, + version => sub { print $version_info; exit }, +) or die $help_info; + +die $help_info unless @ARGV == 1; + +my %include = (); +my %append = (); +my @include = (); # retain order given in include file + +# Provide replacement `quote-regex' operator for pre-5.005. +BEGIN { eval q(sub qr { '' =~ $_[0]; $_[0] }) if $] < 5.005 } + +# Process include file (if given). Format is: +# +# [section name] +# verbatim text +# +# or +# +# /pattern/ +# verbatim text +# + +for (@opt_include) +{ + my ($inc, $required) = @$_; + + next unless -f $inc or $required; + die "$this_program: can't open `$inc' ($!)\n" + unless open INC, $inc; + + my $key; + my $hash = \%include; + + while () + { + # [section] + if (/^\[([^]]+)\]/) + { + $key = uc $1; + $key =~ s/^\s+//; + $key =~ s/\s+$//; + $hash = \%include; + push @include, $key unless $include{$key}; + next; + } + + # /pattern/ + if (m!^/(.*)/([ims]*)!) + { + my $pat = $2 ? "(?$2)$1" : $1; + + # Check pattern. + eval { $key = qr($pat) }; + if ($@) + { + $@ =~ s/ at .*? line \d.*//; + die "$inc:$.:$@"; + } + + $hash = \%append; + next; + } + + # Silently ignore anything before the first + # section--allows for comments and revision info. + next unless $key; + + $hash->{$key} ||= ''; + $hash->{$key} .= $_; + } + + close INC; + + die "$this_program: no valid information found in `$inc'\n" + unless $key; +} + +# Compress trailing blank lines. +for my $hash (\(%include, %append)) +{ + for (keys %$hash) { $hash->{$_} =~ s/\n+$/\n/ } +} + +# Turn off localisation of executable's ouput. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# Turn off localisation of date (for strftime). +setlocale LC_TIME, 'C'; + +# Grab help and version info from executable. +my ($help_text, $version_text) = map { + join '', map { s/ +$//; expand $_ } `$ARGV[0] --$_ 2>/dev/null` + or die "$this_program: can't get `--$_' info from $ARGV[0]\n" +} qw(help version); + +my $date = strftime "%B %Y", localtime; +(my $program = $ARGV[0]) =~ s!.*/!!; +my $package = $program; +my $version; + +if ($opt_output) +{ + unlink $opt_output + or die "$this_program: can't unlink $opt_output ($!)\n" + if -e $opt_output; + + open STDOUT, ">$opt_output" + or die "$this_program: can't create $opt_output ($!)\n"; +} + +# The first line of the --version information is assumed to be in one +# of the following formats: +# +# +# +# {GNU,Free} +# ({GNU,Free} ) +# - {GNU,Free} +# +# and seperated from any copyright/author details by a blank line. + +($_, $version_text) = split /\n+/, $version_text, 2; + +if (/^(\S+) +\(((?:GNU|Free) +[^)]+)\) +(.*)/ or + /^(\S+) +- *((?:GNU|Free) +\S+) +(.*)/) +{ + $program = $1; + $package = $2; + $version = $3; +} +elsif (/^((?:GNU|Free) +)?(\S+) +(.*)/) +{ + $program = $2; + $package = $1 ? "$1$2" : $2; + $version = $3; +} +else +{ + $version = $_; +} + +$program =~ s!.*/!!; + +# No info for `info' itself. +$opt_no_info = 1 if $program eq 'info'; + +# --name overrides --include contents. +$include{NAME} = "$program \\- $opt_name\n" if $opt_name; + +# Default (useless) NAME paragraph. +$include{NAME} ||= "$program \\- manual page for $program $version\n"; + +# Man pages traditionally have the page title in caps. +my $PROGRAM = uc $program; + +# Extract usage clause(s) [if any] for SYNOPSIS. +if ($help_text =~ s/^Usage:( +(\S+))(.*)((?:\n(?: {6}\1| *or: +\S).*)*)//m) +{ + my @syn = $2 . $3; + + if ($_ = $4) + { + s/^\n//; + for (split /\n/) { s/^ *(or: +)?//; push @syn, $_ } + } + + my $synopsis = ''; + for (@syn) + { + $synopsis .= ".br\n" if $synopsis; + s!^\S*/!!; + s/^(\S+) *//; + $synopsis .= ".B $1\n"; + s/\s+$//; + s/(([][]|\.\.+)+)/\\fR$1\\fI/g; + s/^/\\fI/ unless s/^\\fR//; + $_ .= '\fR'; + s/(\\fI)( *)/$2$1/g; + s/\\fI\\fR//g; + s/^\\fR//; + s/\\fI$//; + s/^\./\\&./; + + $synopsis .= "$_\n"; + } + + $include{SYNOPSIS} ||= $synopsis; +} + +# Process text, initial section is DESCRIPTION. +my $sect = 'DESCRIPTION'; +$_ = "$help_text\n\n$version_text"; + +# Normalise paragraph breaks. +s/^\n+//; +s/\n*$/\n/; +s/\n\n+/\n\n/g; + +# Temporarily exchange leading dots and backslashes for tokens. +s/^\./\x80/mg; +s/\\/\x81/g; + +# Start a new paragraph (if required) for these. +s/([^\n])\n(Report +bugs|Email +bug +reports +to|Written +by)/$1\n\n$2/g; + +sub convert_option; + +while (length) +{ + # Convert some standard paragraph names. + if (s/^(Options|Examples): *\n//) + { + $sect = uc $1; + next; + } + + # Copyright section + if (/^Copyright +[(\xa9]/) + { + $sect = 'COPYRIGHT'; + $include{$sect} ||= ''; + $include{$sect} .= ".PP\n" if $include{$sect}; + + my $copy; + ($copy, $_) = split /\n\n/, $_, 2; + + for ($copy) + { + # Add back newline + s/\n*$/\n/; + + # Convert iso9959-1 copyright symbol or (c) to nroff + # character. + s/^Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/mg; + + # Insert line breaks before additional copyright messages + # and the disclaimer. + s/(.)\n(Copyright |This +is +free +software)/$1\n.br\n$2/g; + + # Join hyphenated lines. + s/([A-Za-z])-\n */$1/g; + } + + $include{$sect} .= $copy; + $_ ||= ''; + next; + } + + # Catch bug report text. + if (/^(Report +bugs|Email +bug +reports +to) /) + { + $sect = 'REPORTING BUGS'; + } + + # Author section. + elsif (/^Written +by/) + { + $sect = 'AUTHOR'; + } + + # Examples, indicated by an indented leading $, % or > are + # rendered in a constant width font. + if (/^( +)([\$\%>] )\S/) + { + my $indent = $1; + my $prefix = $2; + my $break = '.IP'; + $include{$sect} ||= ''; + while (s/^$indent\Q$prefix\E(\S.*)\n*//) + { + $include{$sect} .= "$break\n\\f(CW$prefix$1\\fR\n"; + $break = '.br'; + } + + next; + } + + my $matched = ''; + $include{$sect} ||= ''; + + # Sub-sections have a trailing colon and the second line indented. + if (s/^(\S.*:) *\n / /) + { + $matched .= $& if %append; + $include{$sect} .= qq(.SS "$1"\n); + } + + my $indent = 0; + my $content = ''; + + # Option with description. + if (s/^( {1,10}([+-]\S.*?))(?:( +)|\n( {20,}))(\S.*)\n//) + { + $matched .= $& if %append; + $indent = length ($4 || "$1$3"); + $content = ".TP\n\x82$2\n\x82$5\n"; + unless ($4) + { + # Indent may be different on second line. + $indent = length $& if /^ {20,}/; + } + } + + # Option without description. + elsif (s/^ {1,10}([+-]\S.*)\n//) + { + $matched .= $& if %append; + $content = ".HP\n\x82$1\n"; + $indent = 80; # not continued + } + + # Indented paragraph with tag. + elsif (s/^( +(\S.*?) +)(\S.*)\n//) + { + $matched .= $& if %append; + $indent = length $1; + $content = ".TP\n\x82$2\n\x82$3\n"; + } + + # Indented paragraph. + elsif (s/^( +)(\S.*)\n//) + { + $matched .= $& if %append; + $indent = length $1; + $content = ".IP\n\x82$2\n"; + } + + # Left justified paragraph. + else + { + s/(.*)\n//; + $matched .= $& if %append; + $content = ".PP\n" if $include{$sect}; + $content .= "$1\n"; + } + + # Append continuations. + while (s/^ {$indent}(\S.*)\n//) + { + $matched .= $& if %append; + $content .= "\x82$1\n" + } + + # Move to next paragraph. + s/^\n+//; + + for ($content) + { + # Leading dot protection. + s/\x82\./\x80/g; + s/\x82//g; + + # Convert options. + s/(^| )(-[][\w=-]+)/$1 . convert_option $2/mge; + } + + # Check if matched paragraph contains /pat/. + if (%append) + { + for my $pat (keys %append) + { + if ($matched =~ $pat) + { + $content .= ".PP\n" unless $append{$pat} =~ /^\./; + $content .= $append{$pat}; + } + } + } + + $include{$sect} .= $content; +} + +# Refer to the real documentation. +unless ($opt_no_info) +{ + $sect = 'SEE ALSO'; + $include{$sect} ||= ''; + $include{$sect} .= ".PP\n" if $include{$sect}; + $include{$sect} .= < +# Date: August 7th, 2000 +# +# Required information in /etc/lsb-release +# LSB_VERSION +# Optional information in /etc/lsb-release +# DISTRIB_ID, DISTRIB_RELEASE, DISTRIB_CODENAME, DISTRIB_DESCRIPTION + + +############################################################################### +# DECLARATIONS +############################################################################### + +# This script version +SCRIPTVERSION="1.0" + +# Defines the data files +INFO_ROOT="/etc" # directory of config files +INFO_LSB_FILE="lsb-release" # where to get LSB version +INFO_DISTRIB_SUFFIX="release" # - +ALTERNATE_DISTRIB_FILE="/etc/debian_version" # for Debian +ALTERNATE_DISTRIB_NAME="Debian" # " +CHECKFIRST="/etc/redhat-release" # check it before file search + +# Defines our exit codes +EXIT_STATUS="0" # default = Ok :) +ERROR_UNKNOWN="10" # unknown error +ERROR_USER="1" # program misuse +ERROR_PROGRAM="2" # internal error +ERROR_NOANSWER="3" # all required info not available + # typically non LSB compliant distro! +ERROR_LSBBADFILE="4" # bad "lsb-release" content + +# Defines our messages +MSG_LSBBADFILE="Bad $INFO_ROOT/$INFO_LSB_FILE file, field LSB_VERSION missing." +MSG_LSBVER="LSB Version:\t" +MSG_DISTID="Distributor ID:\t" +MSG_DISTDESC="Description:\t" +MSG_DISTREL="Release:\t" +MSG_DISTCODE="Codename:\t" +MSG_NA="n/a" +MSG_NONE="(none)" +MSG_RESULT="" # contains the result in case short output selected + +# Description string delimiter +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" + echo "Distribution information." + echo + echo "Usage: ${0##*/} [OPTION]..." + echo "With no OPTION, same as -v." + echo + echo "Options:" + echo " -v, --version" + echo " Display version of LSB against which distribution is compliant." + echo " -i, --id" + echo " Display string id of distributor." + echo " -d, --description" + echo " Display single line text description of distribution." + echo " -r, --release" + echo " Display release number of distribution." + echo " -c, --codename" + echo " Display codename according to distribution release." + echo " -a, --all" + echo " Display all of the above information." + echo " -s, --short" + echo " Display all of the above information in short output format." + echo " -h, --help" + echo " Display this message." + + exit $EXIT_STATUS +} + +# Handles the enhanced args (i.e. --something) +function EnhancedGetopt() { + getopt -T >/dev/null 2>&1 # is getopt the enhanced one ? + if [ $? = 4 ] + then # Yes, advanced args ALLOWED + OPT=$(getopt -o acdhirsv \ + --long all,codename,description,help,id,release,short,version \ + -n 'lsb_release' \ + -- "$@") + else # No, advanced args NOT allowed + # convert (if needed) the enhanced options into basic ones + MYARGS=$(echo "$@" | sed -e "/--/s/-\(-[[:alnum:]]\)[[:alnum:]]*/\1/g") + OPT=$(getopt -o acdhirsv \ + -n 'lsb_release' \ + -- "$MYARGS") + fi + if [ $? != 0 ] + then + exit $ERROR_PROGRAM + fi + eval set -- "$OPT" + while true ; do + case "$1" in + -a|--all) ARG_A="y"; shift;; + -c|--codename) ARG_C="y"; shift;; + -d|--description) ARG_D="y"; shift;; + -i|--id) ARG_I="y"; shift;; + -r|--release) ARG_R="y"; shift;; + -s|--short) ARG_S="y"; shift;; + -v|--version) ARG_V="y"; shift;; + -h|--help) Usage;; + --) shift; break;; + *) EXIT_STATUS=$ERROR_USER + Usage;; + esac + done +} + +# Get/Init LSB infos (maybe Distrib infos too) +function 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 + else + LSB_VERSION=$MSG_NA # Exit code remains Ok (not ERROR_NOANSWER) + fi +} + +# Get the whole distrib information string (from ARG $1 file) +function 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 "" + + if [ -z "$FILENAME" ] + then + if [ -f "$ALTERNATE_DISTRIB_FILE" ] + then # For Debian only + [ -z "$DISTRIB_ID" ] && DISTRIB_ID="$ALTERNATE_DISTRIB_NAME" + [ -z "$DISTRIB_RELEASE" ] \ + && DISTRIB_RELEASE=$(cat $ALTERNATE_DISTRIB_FILE) + [ -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 + # build the DISTRIB_DESCRIPTION string (never need to be parsed) + [ -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 + + 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 "$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 + 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? + [ -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" + [ -z "$NO" ] && [ -n "$ARG_C" ] && [ -z "$DISTRIB_CODENAME" ] && NO="y" + + 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 \ + | awk 'END { print $1 ;}') # multi file pb: keep the last + # -and ! -perm +0111 seems broken on Mandrake 7.0 + fi + InitDistribInfo $CHECKFIRST + fi +} + +# Display version of LSB against which distribution is compliant +function DisplayVersion() { + if [ -z "$ARG_S" ] + then + echo -e "$MSG_LSBVER$LSB_VERSION" # at least "n/a" + else + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$LSB_VERSION" + fi +} + +# Display string id of distributor ( i.e. a single word! ) +function 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 \ + | awk --assign delimiter="$DESCSTR_DELI" --assign na="$MSG_NA" \ + 'BEGIN { \ + i = 1 ; res = "" \ + } \ + { \ + while ( i < NF && $i != delimiter ) { \ + if (tolower($i) != "linux") \ + res=res$i ; \ + i++ \ + } \ + } \ + END { \ + if (i == NF || res == "" ) \ + print na ; \ + else \ + print res ; \ + }') + fi + if [ -z "$ARG_S" ] + then + echo -e "$MSG_DISTID$DISTRIB_ID" + else + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$DISTRIB_ID" + fi +} + +# Diplay single line text description of distribution +function DisplayDescription() { + if [ -z "$DISTRIB_DESCRIPTION" ] + then + # should not be empty since GetDistribInfo called on Initialization ! + EXIT_STATUS=$ERROR_PROGRAM + fi + if [ -z "$ARG_S" ] + then + echo -e "$MSG_DISTDESC$DISTRIB_DESCRIPTION" + else + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }\"$DISTRIB_DESCRIPTION\"" + fi +} + +# Display release number of distribution. +function 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 + fi + if [ -z "$ARG_S" ] + then + echo -e "$MSG_DISTREL$DISTRIB_RELEASE" + else + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }$DISTRIB_RELEASE" + fi +} + +# Display codename according to distribution version. +function 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 + fi + if [ -z "$ARG_S" ] + then + echo -e "$MSG_DISTCODE${DISTRIB_CODENAME// /}" # Remove blanks + else + MSG_RESULT="$MSG_RESULT${MSG_RESULT:+ }${DISTRIB_CODENAME// /}" + fi +} + + +############################################################################### +# MAIN +############################################################################### + +# Check if any prog argument +if [ -z "$1" ] +then + ARG_V="y" # default set to Display LSB Version (not Usage) +else + EnhancedGetopt "$@" # Parse program args +fi + +# Update args to All if requested +if [ -n "$ARG_A" ] +then + [ -z "$ARG_C" ] && ARG_C="y" + [ -z "$ARG_D" ] && ARG_D="y" + [ -z "$ARG_I" ] && ARG_I="y" + [ -z "$ARG_R" ] && ARG_R="y" + [ -z "$ARG_V" ] && ARG_V="y" +fi + +# Initialization +GetLSBInfo +GetDistribInfo + +# Display requested infos (order as follow) +[ -n "$ARG_V" ] && DisplayVersion +[ -n "$ARG_I" ] && DisplayID +[ -n "$ARG_D" ] && DisplayDescription +[ -n "$ARG_R" ] && DisplayRelease +[ -n "$ARG_C" ] && DisplayCodename + +[ -n "$ARG_S" ] && echo "$MSG_RESULT" + +exit $EXIT_STATUS diff --git a/lsb_release/src/lsb_release.examples b/lsb_release/src/lsb_release.examples new file mode 100644 index 0000000..d2ca52e --- /dev/null +++ b/lsb_release/src/lsb_release.examples @@ -0,0 +1,68 @@ +[FILES] +The \fB"/etc/lsb-release"\fR file should contain the following fields: + +\fBLSB_VERSION="1.0"\fR (REQUIRED) + +And some optional fields like +\fBDISTRIB_ID\fR, \fBDISTRIB_RELEASE\fR, \fBDISTRIB_CODENAME\fR, \fBDISTRIB_DESCRIPTION\fR +to overwrite content parsed from next file. + +The \fB"/etc/[distrib]-release"\fR file contains a description line parsed to get information (especially on non-LSB compliant system). + +The required line style is: +.br +"\fIDistributor\fR \fBrelease\fR \fIx.x\fR \fB(\fR\fICodename\fR\fB)\fR" + +Where \fIDistributor\fR can be a couple of words, but then concatenated (i.e. Linux Foo BarLinux Linux -> FooBarLinux), +.br +\fIx.x\fR starts with a digit followed by any non-blank characters, +\fICodename\fR will also be concatenated (blanks cleanup only). + +And \fBrelease\fR is a keyword not to be used in \fBDISTRIB_DESCRIPTION\fR if you don't want to overwrite "/etc/[distrib]-release" data. + +\fBNotice:\fR To support the \fBDebian\fR distributions' lak of information (see "/etc/debian_version" file) some have been directly added into the \fBlsb_release\fR script. + +[EXAMPLES] +.B The "/etc/lsb-release" file contains: + +LSB_VERSION="1.0" +.br +DISTRIB_DESCRIPTION="I enjoy using my distrib" + +.B And the "/etc/foobar-release" file contains: + +My Linux Distrib release 1.0RC4 (TryIt) + +.B $ ./lsb_release --all +.br +LSB Version: 1.0 +.br +Distributor ID: MyDistrib +.br +Description: I enjoy using my distrib +.br +Release: 1.0RC4 +.br +Codename: TryIt + +.B $ ./lsb_release -a -s +.br +1.0 MyDistrib "I enjoy using my distrib" 1.0RC4 TryIt + +Then simply without the "/etc/lsb-release" file, that means result on a \fBnon-LSB\fR compliant distrib: +.br +.B $ ./lsb_release -a +.br +LSB Version: n/a +.br +Distributor ID: MyDistrib +.br +Description: My Linux Distrib release 1.0RC4 (TryIt) +.br +Release: 1.0RC4 +.br +Codename: TryIt + +[REPORTING BUGS] +Report bugs to . +Include a complete, selfcontained example that will allow the bug to be reproduced, and say which version of lsb_release you are using. diff --git a/lsb_release/src/lsb_release.spec b/lsb_release/src/lsb_release.spec new file mode 100644 index 0000000..bdf9858 --- /dev/null +++ b/lsb_release/src/lsb_release.spec @@ -0,0 +1,70 @@ +# +# Copyright 1999, International Business Machines, Inc. +# George Kraft IV (gk4@us.ibm.com) +# +# Red Hat Package Manager (RPM) file for LSB +# +Summary: Linux Standard Base tools +Name: lsb_release +Version: 1.0 +Release: 1 +Prefix: /opt +Copyright: GPL +Source: lsb_release-1.0.tgz +Group: System/Tools +URL: http://www.linuxbase.org/ +Vendor: Linux Standard Base +Packager: George Kraft IV + +%description +Linux Standard Base (LSB) tools. + +%prep +echo No speacial preparations are to be made. + +%setup + +%build +if [ ! -f "./lsb_release.ori" ]; then + # do a backup of lsb_release + cp -p lsb_release lsb_release.ori +fi +mv -f lsb_release lsb_release.tmp # lsb_release need to be parsed for + # the help2man perl script +cat lsb_release.tmp | sed -e "s/\[ -n \"\$ARG_V\" \] \&\& DisplayVersion/\[ -n \"\$ARG_V\" \] \&\& Version/" >./lsb_release + +chmod a+x ./lsb_release + +rm -f lsb_release.1 lsb_release.1.bz2 # remove old man pages + +# build man page +./help2man -N --include ./lsb_release.examples ./lsb_release >lsb_release.1 + +bzip2 lsb_release.1 # do the needed compression + +# restore former lsb_release script +cat lsb_release | sed -e "s/\[ -n \"\$ARG_V\" \] \&\& Version/\[ -n \"\$ARG_V\" \] \&\& DisplayVersion/" >./lsb_release.tmp +mv -f lsb_release.tmp lsb_release +chmod a+x ./lsb_release + +cp lsb_release.1.bz2 /usr/man/man1/ # install place +cp lsb_release.1.bz2 /opt/lsb/man/man1/ # install place +ln -fs /opt/lsb/man/man1/lsb_release.1.bz2 /opt/man/man1 # install place + +man -w lsb_release # view the result + +%install +echo We assume a previous imake install on this system has occurred. + +%files +/opt/lsb/bin/lsb_release +/opt/lsb/man/man1/lsb_release.1.bz2 + +%post +P=$RPM_INSTALL_PREFIX +mkdir $P/bin/ > /dev/null 2>&1 +ln -fs $P/lsb/bin/lsb_release $P/bin/ +mkdir $P/man/man1/ > /dev/null 2>&1 +ln -fs $P/lsb/man/man1/lsb_release.1.bz2 $P/man/man1/ + +#EOF