Probe used to dynamically set client groups based on OS/distro.
Note
Some parts of this script may depend on having lsb-release installed.
#!/bin/bash
OUTPUT=""
if [ -e /etc/release ]; then
# Solaris
OUTPUT="$OUTPUT\ngroup:solaris"
elif [ -e /etc/debian_version ]; then
# debian based
OUTPUT="$OUTPUT\ngroup:deb"
if [ -e /etc/lsb-release ]; then
# variant
. /etc/lsb-release
OS_GROUP=$DISTRIB_CODENAME
DEBIAN_VERSION=$(echo "$DISTRIB_ID" | tr '[A-Z]' '[a-z]')
case "$OS_GROUP" in
"lucid")
OUTPUT="$OUTPUT\ngroup:${DISTRIB_CODENAME}"
OUTPUT="$OUTPUT\ngroup:${DEBIAN_VERSION}"
;;
esac
else
# debian
OS_GROUP=`cat /etc/debian_version`
OUTPUT="$OUTPUT\ngroup:debian"
case "$OS_GROUP" in
5.*)
OUTPUT="$OUTPUT\ngroup:lenny"
;;
"sid")
OUTPUT="$OUTPUT\ngroup:sid"
;;
esac
fi
elif [ -e /etc/redhat-release ]; then
# redhat based
if [ -x /bin/rpm ]; then
OUTPUT="${OUTPUT}\ngroup:rpm"
OS_GROUP=`/bin/rpm -q --qf "%{NAME}" --whatprovides redhat-release | grep -vi 'freeing read locks for locker' | sed 's/-release.*//' | tr '[A-Z]' '[a-z]'`
REDHAT_VERSION=`/bin/rpm -q --qf "%{VERSION}" --whatprovides redhat-release`
case "$OS_GROUP" in
"centos" | "fedora" | "sl")
OUTPUT="${OUTPUT}\ngroup:${OS_GROUP}"
OUTPUT="${OUTPUT}\ngroup:${OS_GROUP}-${REDHAT_VERSION}"
;;
"redhat")
REDHAT_RELEASE=`/bin/rpm -q --qf "%{RELEASE}" --whatprovides redhat-release| cut -d. -f1`
OUTPUT="${OUTPUT}\ngroup:${OS_GROUP}"
OUTPUT="${OUTPUT}\ngroup:${OS_GROUP}-${REDHAT_VERSION}"
OUTPUT="${OUTPUT}\ngroup:${OS_GROUP}-${REDHAT_RELEASE}"
;;
esac
fi
elif [ -e /etc/gentoo-release ]; then
# gentoo
OUTPUT="$OUTPUT\ngroup:gentoo"
elif [ -x /usr/sbin/system_profiler ]; then
# os x
### NOTE: Think about using system_profiler SPSoftwareDataType here
OUTPUT="$OUTPUT\ngroup:osx"
OSX_VERSION=`sw_vers | grep 'ProductVersion:' | egrep -o '[0-9]+\.[0-9]+'`
if [ "$OSX_VERSION" == "10.6" ]; then
OUTPUT="$OUTPUT\ngroup:osx-snow"
elif [ "$OSX_VERSION" == "10.5" ]; then
OUTPUT="$OUTPUT\ngroup:osx-leo"
fi
echo $OUTPUT
else
exit 0
fi
# get the proper architecture
ARCH=`uname -m`
case "$ARCH" in
"x86_64")
if [ "$OS_GROUP" == 'centos' -o "$OS_GROUP" == 'sl' -o "$OS_GROUP" == 'redhat' ]; then
OUTPUT="$OUTPUT\ngroup:${ARCH}"
else
OUTPUT="$OUTPUT\ngroup:amd64"
fi
;;
"i386" | "i686")
OUTPUT="$OUTPUT\ngroup:i386"
;;
"sparc64")
OUTPUT="$OUTPUT\ngroup:sparc64"
;;
esac
# output the result of all the group probing
# (interpreting the backslashed newlines)
echo -e $OUTPUT