Blame SOURCES/dist.sh

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