1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
# 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 logic should match ohai platform and platform_version matching.
# do not invent new platform and platform_version schemas, just make this behave
# like what ohai returns as platform and platform_version for the system.
#
# 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 DISTRIB_ID /etc/lsb-release >/dev/null && ! grep wrlinux /etc/lsb-release >/dev/null; 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`
if test "$platform" = "\"cumulus linux\""; then
platform="cumulus_linux"
elif test "$platform" = "\"cumulus networks\""; then
platform="cumulus_networks"
fi
elif test -f "/etc/debian_version"; then
platform="debian"
platform_version=`cat /etc/debian_version`
elif test -f "/etc/Eos-release"; then
# EOS may also contain /etc/redhat-release so this check must come first.
platform=arista_eos
platform_version=`awk '{print $4}' /etc/Eos-release`
machine="i386"
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 test "$platform" = "xenserver"; then
# Current XenServer 6.2 is based on CentOS 5, platform is not reset to "el" server should handle 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]'`
case $platform in amazon*) # sh compat method of checking for a substring
platform="el"
. /etc/os-release
platform_version=$VERSION_ID
if test "$platform_version" = "2"; then
platform_version="7"
else
# VERSION_ID will match YYYY.MM for Amazon Linux AMIs
platform_version="6"
fi
esac
# Apple macOS
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`
elif test -f "/etc/release"; then
machine=`/usr/bin/uname -p`
if grep SmartOS /etc/release >/dev/null; 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 'Enterprise' /etc/SuSE-release >/dev/null;
then
platform="sles"
platform_version=`awk '/^VERSION/ {V = $3}; /^PATCHLEVEL/ {P = $3}; END {print V "." P}' /etc/SuSE-release`
else # opensuse 43 only. 15 ships with /etc/os-release only
platform="opensuseleap"
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
# VERSION_ID is always the preferred variable to use, but not
# every distro has it so fallback to VERSION
if test "x$VERSION_ID" != "x"; then
platform_version=$VERSION_ID
else
platform_version=$VERSION
fi
fi
if test "x$platform" = "x"; then
echo "Unable to determine platform version!"
report_bug
exit 1
fi
#
# NOTE: platform mangling 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")
if test "x$major_version" = "x5"; then
# This is here for potential back-compat.
# We do not have 5 in versions we publish for anymore but we
# might have it for earlier versions.
platform_version="6"
else
platform_version=$major_version
fi
;;
"freebsd")
platform_version=$major_version
;;
"sles")
platform_version=$major_version
;;
"opensuseleap")
platform_version=$major_version
;;
esac
# normalize the architecture we detected
case $machine in
"arm64"|"aarch64")
machine="aarch64"
;;
"x86_64"|"amd64"|"x64")
machine="x86_64"
;;
"i386"|"i86pc"|"x86"|"i686")
machine="i386"
;;
"sparc"|"sun4u"|"sun4v")
machine="sparc"
;;
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
############
|