# platform_detection.sh ############ # This section makes platform detection compatible with omnitruck on the system # it runs. # # Outputs: # $platform: Name of the platform. # $platform_version: Version of the platform. # $machine: System's architecture. ############ # # Platform and Platform Version detection # # NOTE: This should now match ohai platform and platform_version matching. # do not invented new platform and platform_version schemas, just make this behave # like what ohai returns as platform and platform_version for the server. # # ALSO NOTE: Do not mangle platform or platform_version here. It is less error # prone and more future-proof to do that in the server, and then all omnitruck clients # will 'inherit' the changes (install.sh is not the only client of the omnitruck # endpoint out there). # machine=`uname -m` os=`uname -s` if test -f "/etc/lsb-release" && grep -q DISTRIB_ID /etc/lsb-release && ! grep -q wrlinux /etc/lsb-release; then platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'` platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2` elif test -f "/etc/debian_version"; then platform="debian" platform_version=`cat /etc/debian_version` elif test -f "/etc/redhat-release"; then platform=`sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]'` platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release` # If /etc/redhat-release exists, we act like RHEL by default if test "$platform" = "fedora"; then # FIXME: stop remapping fedora to el # FIXME: remove client side platform_version mangling and hard coded yolo # Change platform version for use below. platform_version="6.0" fi if test "$platform" = "xenserver"; then # Current XenServer 6.2 is based on CentOS 5, platform is not reset to "el" server should hanlde response platform="xenserver" else # FIXME: use "redhat" platform="el" fi elif test -f "/etc/system-release"; then platform=`sed 's/^\(.\+\) release.\+/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'` platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'` # amazon is built off of fedora, so act like RHEL if test "$platform" = "amazon linux ami"; then # FIXME: remove client side platform_version mangling and hard coded yolo, and remapping to deprecated "el" platform="el" platform_version="6.0" fi # Apple OS X elif test -f "/usr/bin/sw_vers"; then platform="mac_os_x" # Matching the tab-space with sed is error-prone platform_version=`sw_vers | awk '/^ProductVersion:/ { print $2 }' | cut -d. -f1,2` # x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63) x86_64=`sysctl -n hw.optional.x86_64` if test $x86_64 -eq 1; then machine="x86_64" fi elif test -f "/etc/release"; then machine=`/usr/bin/uname -p` if grep -q SmartOS /etc/release; then platform="smartos" platform_version=`grep ^Image /etc/product | awk '{ print $3 }'` else platform="solaris2" platform_version=`/usr/bin/uname -r` fi elif test -f "/etc/SuSE-release"; then if grep -q 'Enterprise' /etc/SuSE-release; then platform="sles" platform_version=`awk '/^VERSION/ {V = $3}; /^PATCHLEVEL/ {P = $3}; END {print V "." P}' /etc/SuSE-release` else platform="suse" platform_version=`awk '/^VERSION =/ { print $3 }' /etc/SuSE-release` fi elif test "x$os" = "xFreeBSD"; then platform="freebsd" platform_version=`uname -r | sed 's/-.*//'` elif test "x$os" = "xAIX"; then platform="aix" platform_version="`uname -v`.`uname -r`" machine="powerpc" elif test -f "/etc/os-release"; then . /etc/os-release if test "x$CISCO_RELEASE_INFO" != "x"; then . $CISCO_RELEASE_INFO fi platform=$ID platform_version=$VERSION fi if test "x$platform" = "x"; then echo "Unable to determine platform version!" report_bug exit 1 fi # # NOTE: platform manging in the install.sh is DEPRECATED # # - install.sh should be true to ohai and should not remap # platform or platform versions. # # - remapping platform and mangling platform version numbers is # now the complete responsibility of the server-side endpoints # major_version=`echo $platform_version | cut -d. -f1` case $platform in # FIXME: should remove this case statement completely "el") # FIXME: "el" is deprecated, should use "redhat" platform_version=$major_version ;; "debian") # FIXME: remove client-side yolo here case $major_version in "5") platform_version="6";; # FIXME: need to port this "reverse-yolo" into platform.rb "6") platform_version="6";; "7") platform_version="6";; esac ;; "freebsd") platform_version=$major_version ;; "sles") platform_version=$major_version ;; "suse") platform_version=$major_version ;; esac if test "x$platform_version" = "x"; then echo "Unable to determine platform version!" report_bug exit 1 fi if test "x$platform" = "xsolaris2"; then # hack up the path on Solaris to find wget, pkgadd PATH=/usr/sfw/bin:/usr/sbin:$PATH export PATH fi echo "$platform $platform_version $machine" ############ # end of platform_detection.sh ############