109 lines
2.2 KiB
Bash
109 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
# Script to "probe" current machine for what linux distribution type it is running on
|
|
#
|
|
# Output possibilities:
|
|
#
|
|
# no args:
|
|
# Unknown
|
|
# el
|
|
# sles
|
|
#
|
|
# w/args
|
|
# Unknown
|
|
# el<ver>
|
|
# sles<ver>
|
|
|
|
# We prefer to use /etc/os-release if it is available
|
|
if test -f /etc/os-release; then
|
|
# read in the variables
|
|
. /etc/os-release
|
|
|
|
# Map ID to a normalized output
|
|
case ${ID} in
|
|
|
|
# RHEL distros
|
|
centos|rhel)
|
|
DISTRO=el
|
|
;;
|
|
|
|
# SLES distros
|
|
sles)
|
|
DISTRO=sles
|
|
;;
|
|
|
|
*)
|
|
DISTRO=unknown
|
|
;;
|
|
esac
|
|
|
|
# get the distro release
|
|
REL=${VERSION_ID}
|
|
|
|
else
|
|
# If /etc/os-release not found, use lsb_release if it is available
|
|
LSB_RELEASE=`which lsb_release 2>/dev/null`;
|
|
if [ $? -eq 0 ] ; then
|
|
if [ -e ${LSB_RELEASE} ] ; then
|
|
#
|
|
# extract the distro and the distro release
|
|
#
|
|
DISTRO=`lsb_release -i | sed -e "s/Distributor[ \t]*ID:[ \t]*//"`
|
|
REL=`lsb_release -r | sed -e "s/Release:[ \t]*//" -e "s/\..*$//"`
|
|
|
|
# Map raw data stream to a normalized output
|
|
case ${DISTRO} in
|
|
CentOS)
|
|
DISTRO=el
|
|
;;
|
|
RedHatEnterpriseServer)
|
|
DISTRO=el
|
|
;;
|
|
RHEL)
|
|
DISTRO=el
|
|
;;
|
|
'SUSE LINUX')
|
|
DISTRO=sles
|
|
;;
|
|
SLES)
|
|
DISTRO=sles
|
|
;;
|
|
SUSE)
|
|
DISTRO=sles
|
|
;;
|
|
Scientific)
|
|
DISTRO=el
|
|
;;
|
|
*)
|
|
DISTRO=unknown
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# If lsb_release is not found, look for a /etc/*-release file
|
|
elif test -f /etc/redhat-release; then
|
|
DISTRO=el
|
|
REL=`cat /etc/redhat-release | sed -e "s/^[^0-9]*//" -e "s/[^0-9].*$//"`
|
|
|
|
elif test -f /etc/SuSE-release; then
|
|
DISTRO=sles
|
|
REL=`grep SUSE /etc/SuSE-release | sed -e "s/^[^0-9]*//" -e "s/[^0-9].*$//"`
|
|
elif test -f /etc/lsb-release; then
|
|
DISTRO=`grep DISTRIB_ID /etc/lsb-release | sed "s/^DISTRIB_ID=//"`
|
|
REL=`grep DISTRIB_RELEASE /etc/lsb-release | sed -e "s/^DISTRIB_RELEASE=//" -e "s/[^0-9].*$//"`
|
|
|
|
# Otherwise it is unknown
|
|
else
|
|
DISTRO=unknown
|
|
fi
|
|
fi
|
|
|
|
#
|
|
# If an arg was given, then map to a common distro type and append the release
|
|
#
|
|
if [ -n "$1" ] ; then
|
|
echo ${DISTRO}${REL}
|
|
else
|
|
echo $DISTRO
|
|
fi
|