Blame SOURCES/dist.sh

7b79ae
#!/bin/bash
7b79ae
# dist.sh
7b79ae
# Author: Tom "spot" Callaway <tcallawa@redhat.com>
7b79ae
# License: GPL
7b79ae
# This is a script to output the value for the %{dist}
7b79ae
# tag. The dist tag takes the following format: .$type$num
7b79ae
# Where $type is one of: el, fc, rh
7b79ae
# (for RHEL, Fedora Core, and RHL, respectively)
7b79ae
# And $num is the version number of the distribution.
7b79ae
# NOTE: We can't detect Rawhide or Fedora Test builds properly.
7b79ae
# If we successfully detect the version number, we output the
7b79ae
# dist tag. Otherwise, we exit with no output.
7b79ae
7b79ae
RELEASEFILE=/etc/redhat-release
7b79ae
7b79ae
function check_num {
7b79ae
    MAINVER=`cut -d "(" -f 1 < $RELEASEFILE | \
7b79ae
	sed -e "s/[^0-9.]//g" -e "s/$//g" | cut -d "." -f 1`
7b79ae
7b79ae
    echo $MAINVER | grep -q '[0-9]' && echo $MAINVER
7b79ae
}
7b79ae
7b79ae
function check_rhl {
7b79ae
    grep -q "Red Hat Linux" $RELEASEFILE && ! grep -q "Advanced" $RELEASEFILE && echo $DISTNUM
7b79ae
}
7b79ae
7b79ae
function check_rhel {
f3792f
    egrep -q "(Enterprise|Advanced|CentOS)" $RELEASEFILE && echo $DISTNUM
7b79ae
}
7b79ae
7b79ae
function check_fedora {
7b79ae
    grep -q Fedora $RELEASEFILE && echo $DISTNUM
7b79ae
}
7b79ae
7b79ae
DISTNUM=`check_num`
7b79ae
DISTFC=`check_fedora`
7b79ae
DISTRHL=`check_rhl`
7b79ae
DISTRHEL=`check_rhel`
7b79ae
if [ -n "$DISTNUM" ]; then
7b79ae
    if [ -n "$DISTFC" ]; then
7b79ae
	DISTTYPE=fc
7b79ae
    elif [ -n "$DISTRHEL" ]; then
7b79ae
	DISTTYPE=el
7b79ae
    elif [ -n "$DISTRHL" ]; then
7b79ae
	DISTTYPE=rhl
7b79ae
    fi
7b79ae
fi
7b79ae
[ -n "$DISTTYPE" -a -n "$DISTNUM" ] && DISTTAG=".${DISTTYPE}${DISTNUM}"
7b79ae
7b79ae
case "$1" in
7b79ae
    --el) echo -n "$DISTRHEL" ;;
7b79ae
    --fc) echo -n "$DISTFC" ;;
7b79ae
    --rhl) echo -n "$DISTRHL" ;;
7b79ae
    --distnum) echo -n "$DISTNUM" ;;
7b79ae
    --disttype) echo -n "$DISTTYPE" ;;
7b79ae
    --help)
7b79ae
	printf "Usage: $0 [OPTIONS]\n"
7b79ae
	printf " Default mode is --dist. Possible options:\n"
7b79ae
	printf " --el\t\tfor RHEL version (if RHEL)\n"
7b79ae
	printf " --fc\t\tfor Fedora version (if Fedora)\n"
7b79ae
	printf " --rhl\t\tfor RHL version (if RHL)\n"
7b79ae
	printf " --dist\t\tfor distribution tag\n"
7b79ae
	printf " --distnum\tfor distribution number (major)\n"
7b79ae
	printf " --disttype\tfor distribution type\n" ;;
7b79ae
    *) echo -n "$DISTTAG" ;;
7b79ae
esac