#!/bin/sh

# This script identifies the operating system's distribution and kernel
#
# It is designed so as to be sourced from other scripts or
# invoked as a standalone utility.
#
# Written by Marc Boucher <marc@mbsi.ca>
# 
# Copyright (c) 2001 Conexant Systems, Inc.
# 
# 1.   Permitted use. Redistribution and use in source and binary forms,
# with or without modification, are permitted under the terms set forth
# herein.
# 
# 2.   Disclaimer of Warranties. CONEXANT AND OTHER CONTRIBUTORS MAKE NO
# REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.
# IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTIES OF ANY KIND.
# CONEXANT AND OTHER CONTRIBUTORS DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE, GOOD TITLE AND AGAINST INFRINGEMENT.
# 
# This software has not been formally tested, and there is no guarantee that
# it is free of errors including, but not limited to, bugs, defects,
# interrupted operation, or unexpected results. Any use of this software is
# at user's own risk.
# 
# 3.   No Liability.
# 
# (a) Conexant or contributors shall not be responsible for any loss or
# damage to Company, its customers, or any third parties for any reason
# whatsoever, and CONEXANT OR CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY
# ACTUAL, DIRECT, INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL, OR CONSEQUENTIAL
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED, WHETHER IN CONTRACT, STRICT OR OTHER LEGAL THEORY OF
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# 
# (b) User agrees to hold Conexant and contributors harmless from any
# liability, loss, cost, damage or expense, including attorney's fees,
# as a result of any claims which may be made by any person, including
# but not limited to User, its agents and employees, its customers, or
# any third parties that arise out of or result from the manufacture,
# delivery, actual or alleged ownership, performance, use, operation
# or possession of the software furnished hereunder, whether such claims
# are based on negligence, breach of contract, absolute liability or any
# other legal theory.
# 
# 4.   Notices. User hereby agrees not to remove, alter or destroy any
# copyright, trademark, credits, other proprietary notices or confidential
# legends placed upon, contained within or associated with the Software,
# and shall include all such unaltered copyright, trademark, credits,
# other proprietary notices or confidential legends on or in every copy of
# the Software.
#

OSDISTNAME=unknown
OSDISTVERS=unknown

if [ -f /etc/debian_version ]; then
	OSDISTNAME=Debian
	read OSDISTVERS < /etc/debian_version
elif [ -f /etc/slackware-version ]; then
	OSDISTNAME=Slackware
	OSDISTVERS="`awk '{print $1; exit}' /etc/slackware-version`"
elif [ -f /etc/conectiva-release ]; then
	OSDISTNAME=Conectiva
elif [ -f /etc/SuSE-release ]; then
	OSDISTNAME=SuSE
	OSDISTVERS="`sed -n '/^VERSION/s/^.*=[ 	]*//p' < /etc/SuSE-release`"
elif [ -f /etc/mandrake-release ]; then
	OSDISTNAME=Mandrake
#it would be better to use rpm instead of sed but it doesn't work when
#recursively (due to database locking) when this script is called when the
#package is being installed
#	OSDISTVERS="`rpm -q --queryformat '%{VERSION}\n' mandrake-release | sort -r | head -1`"
	OSDISTVERS="`sed -n '/release /{s/^.*release  *\([^ ]*\)/\1/;s/ .*//;p;q;}' < /etc/mandrake-release`"
#elif [ -f /etc/yellowdog-release ]; then
#	OSDISTNAME=YellowDog
elif [ -f /etc/redhat-release ]; then
	OSDISTNAME=RedHat
	OSDISTVERS="`sed -n '/release /{s/^.*release  *\([^ ]*\)/\1/;s/ .*//;p;q;}' < /etc/redhat-release`"
elif [ -d /var/lib/LST ]; then
	OSDISTNAME=Caldera
fi

OSKERNNAME="`uname -s`"
OSKERNARCH="`uname -m`"
OSKERNVERS="`uname -r`"

if uname -v | grep -q SMP; then
	OSKERNSMP="-SMP"
else
	OSKERNSMP=""
fi

if [ -r /proc/ksyms -a `grep -c '_R[a-f0-9]*$' /proc/ksyms` -gt 100 ]; then
	OSKERNMODV="-MODVERS"
else
	OSKERNMODV=""
fi

echo $OSKERNNAME-$OSKERNARCH-$OSKERNVERS$OSKERNSMP$OSKERNMODV $OSDISTNAME-$OSDISTVERS 
