Blame SOURCES/dist.sh

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