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