#!/bin/sh

# Simple sh script that determines the Linux distribution and generates
# a release token to be used in the rpm %release tag
#
# Mihai Maties <mihai@xcyb.org>

# Samples :
#release="Fedora Core release 1 (Yarrow)"
#release="Mandrake Linux release 9.2 (FiveStar) for i586"
#release="Red Hat Linux release 9 (Shrike)"
#release="Yellow Dog Linux release 2.3 (Dayton)"
#release="UnitedLinux 1.0 (i386)"
#release="SuSE Linux 8.2 (i586)"
#release="Red Hat Enterprise Linux ES release 3 (Taroon)"

release=$(cat `echo /etc/*release|tr ' ' '\n'|grep -v lsb|head -1`)
dist=`echo $release|sed -re 's/(.*) (release|Linux).*/\1/;s/ *Linux.*//'`
version=`echo $release|sed -re 's/([a-zA-Z]| )*\ (([0-9]|\.)*) .*/\2/;s/\.//'`

case "$dist" in
    "Red Hat" ) dist=".rh";;
    "Fedora Core" ) dist=".fc";;
    "SuSE" ) dist=".suse";;
    "Mandrake" ) dist=".mdk";;
    "United" ) dist=".ul";;
    "Yellow Dog" ) dist=".yd";;
    "Red Hat Enterprise" ) dist=".rhel";;
esac
echo $dist$version
