#!/bin/sh # # whatami # Prints a string describing the system type. # # $Id: # # "whatami" is part of Msys, the MCS Systems Administration Toolkit. # For more information, see http://www.mcs.anl.gov/systems/software/ . # # Copyright (c) University of Chicago 1999. # See the COPYRIGHT file in the distribution for details on the copyright. # # =========================================================================== # # Description: # # Try to figure out what type of machine we're running on. # # The string returned is one that is useful to distinguish between # system architectures, where we think of machines with the same architectures # as machines that should be using the same set of compiled software. # # One would think that you could already get such a string from an existing # UNIX utility. But, no, this appears not to be the case. "uname" and # "arch" come close, but are inconsistent. Thus this script is basically # a wrapper around those. # # Several other programs in the Msys distribution (and innumerable scripts # around MCS) call this program. # # =========================================================================== # TODO: # # Authors: # # Remy Evard # - Version 1.0 and 2.0: # 2003.03.12 Brian Elliott Finley # - added get_linux_type function to provide a three part type: # Ie: linux-debian_unstable-ia32, or linux-sles8-ia64 # - added -o (option_test) # 2003.10.16 Larry A. Diegel # - patch for aix-5 # 2004.01.17 Brian Elliott Finley # - modified --help output # - accept --long-options as well as -s (short options) # 2004.02.04 Brian Elliott Finley # - identify macosx on ppc and ppc64 # - identify linux on Opteron (x86_64) # 2004.02.26 Brian Elliott Finley # - add redhat AS # - add mandrake 9.1 # - add redhat 9 # - add redhat 8 # 2005.01.19 Susan Coghlan # - add sles8 PPC64 # 2005.02.01 Susan Coghlan # - add sles9 # 2005.03.07 Brian Elliott Finley # - add rhel, and deal w/different versions, sub-distros (AS|EL|WS) # 2005.04.21 Peter Couvares # - add tao linux 1.0, cygwin # 2005.04.22 Ti Leggett # - add Gentoo # 2006.03.14 JP Navarro # - more precise AIX type, aix-{version}.{release} # - add Cray Rocks 1.3 # - add CentOS 4.0 # - add SGI ProPack 3 -> rhel3 # - add SGI ProPack 4 -> sles9 # - add SuSE 9.1 # 2006.03.21 JP Navarro # - add Fedora Core # - drop RHEL sub-distros # - ClassAd output support # - XML output support # 2006.03.30 Ti Leggett # - Fixed CentOS to recognize 4.x instead of only 4.0 # 2006.10.17 JP Navarro # - Add SuSE 10.1 # 2007.01.02 JP Navarro # - Add SuSE 10.2 # 2007.02.06 Ti Leggett # - Add MacOS on Intel support # 2008.10.14 Brian Finley # - Add generic lsb_release support # - includes CentOS 5.x # 2008.10.30 Ethan Mallove # - Support two different SuSE 10 lsb-release file formats # 2008.10.30 Brian Finley # - Turn Ethan's code and concept into a subroutine. # # Authors -- Be sure to increment the version number appropriately! # # =========================================================================== # # Exit codes: # # 0 on success # 1 on failure to grok arguments or figure out architecture details # # =========================================================================== # # Machine type strings: # # sun4 # irix-5 # irix-6 # solaris # freebsd # aix-{version}.{release} # aux # hpux # mips # osf # digital # next # linux-{distro_and_version}-{architecture} # solaris86 # solarishp # nt # ntalpha # # =========================================================================== program=`echo $0 | sed 's:.*/::'` version="2008.10.31" ################################################################################ # # Subroutines # get_lsb_info_if_available() { if [ -f /etc/lsb-release ]; then # # 1) Example contents of /etc/lsb-release from Ubuntu Hardy: # DISTRIB_ID=Ubuntu # DISTRIB_RELEASE=8.04 # DISTRIB_CODENAME=hardy # DISTRIB_DESCRIPTION="Ubuntu hardy (development branch)" # 2) Example contents of /etc/lsb-release from SLES 9: # LSB_VERSION="core-2.0-noarch:core-3.0-noarch:core-2.0-x86_64:core-3.0-x86_64" . /etc/lsb-release elif [ -x /usr/bin/lsb_release ]; then DISTRIB_ID=$(/usr/bin/lsb_release -i | sed -e 's/^Distributor ID:[[:space:]]//') DISTRIB_RELEASE=$(/usr/bin/lsb_release -r | sed -e 's/^Release:[[:space:]]//') fi } get_linux_type() { ############################################################################ # # Step 1) Determine $hardware string (in Linux terms, based on architecture # names used by the Linux kernel. See /usr/src/linux/hardware/ for # details). # case $uhardware in alpha) hardware=alpha ;; i386|i486|i586|i686) hardware=ia32 ;; ppc64) hardware=ppc64 ;; ia64) hardware=ia64 ;; x86_64) hardware=x86_64 ;; *) hardware=unknown_hardware_please_send_us_a_patch ;; esac # ############################################################################ ############################################################################ # # Step 2) Determine $distro (distribution) string # # NOTES: Put newer tests higher up, as they'll most # likely get hit first. -BEF- # NOTES: But, make sure that newer programatic tests don't override # older tests with different results. -BEF- # # # If lsb-release contains the DISTRIB* variables we need - use # them, otherwise, defer to tests later down the line. # get_lsb_info_if_available if [ "${DISTRIB_ID}" != "" -a "${DISTRIB_RELEASE}" != "" ]; then distro=${DISTRIB_ID}_${DISTRIB_RELEASE} elif [ -f /etc/issue ]; then if [ -e /etc/debian_version ]; then distro_brand=debian distro_version=`cat /etc/debian_version | sed 's#testing/##'` distro=${distro_brand}_${distro_version} elif [ -e /etc/gentoo-release ]; then distro_brand=gentoo # If you think there should be a version, # uncomment out the following #gentoo_profile=`readlink /etc/make.profile` #distro_version=`basename ${gentoo_profile}` #distro=${distro_brand}_${distro_version} distro=${distro_brand} elif [ -n "`egrep 'Scientific Linux SL release [0-9\.]+' /etc/issue`" ]; then distro_ver="`grep 'Scientific Linux' /etc/issue | sed -e 's/.*release \([0-9]*\.[0-9]*\).*/\1/'`" distro=scientificlinux_$distro_ver elif [ -n "`egrep 'Red Hat Enterprise Linux ([a-zA-Z]+) release [0-9]*' /etc/issue`" ]; then distro_brand=rhel #sub_distro=` grep 'Red Hat' /etc/issue | sed -e 's/Red Hat Enterprise Linux \([A-Z][A-Z]\) release \([0-9]*\).*/\1/' ` distro_version=`grep 'Red Hat' /etc/issue | sed -e 's/Red Hat Enterprise Linux \([a-zA-Z]*\) release \([0-9]*\).*/\2/' ` #distro=${distro_brand}${distro_version}_${sub_distro} distro=${distro_brand}${distro_version} elif [ -n "`egrep 'Cray Rocks Linux release 1.3' /etc/issue`" ]; then distro=rh73 elif [ -n "`egrep 'SGI ProPack 3' /etc/issue`" ]; then distro=rhel3 elif [ -n "`egrep 'CentOS release 4.[0-9]' /etc/issue`" ]; then distro=rhel4 elif [ -n "`egrep 'SuSE SLES 8' /etc/issue`" ]; then distro=sles8 elif [ -n "`egrep 'Red Hat Linux Advanced Server release 2.1AS ' /etc/issue`" ]; then distro=redhat_2.1AS elif [ -n "`egrep 'Red Hat Linux release 9 ' /etc/issue`" ]; then distro=redhat_9 elif [ -n "`egrep 'Red Hat Linux release 8.0 ' /etc/issue`" ]; then distro=redhat_8.0 elif [ -n "`egrep 'Mandrake Linux release 9.1 ' /etc/issue`" ]; then distro=mandrake_9.1 elif [ -n "`egrep 'SGI ProPack 4' /etc/issue`" ]; then distro=sles9 elif [ -n "`egrep 'SUSE LINUX Enterprise Server 9' /etc/issue`" ]; then distro=sles9 elif [ -n "`egrep 'SUSE Linux Enterprise Server 10' /etc/issue`" ]; then distro=sles10 elif [ -n "`egrep 'SuSE SLES 8' /etc/issue`" ]; then distro=sles8 elif [ -n "`egrep 'UnitedLinux 1.0' /etc/issue`" ]; then distro=sles8 # Welcome to SuSE Linux 9.0 (x86-64) - Kernel \r (\l) elif [ -n "`egrep 'SuSE Linux 9\.0' /etc/issue`" ]; then distro=suse_9.0 elif [ -n "`egrep 'SuSE Linux 9\.1' /etc/issue`" ]; then distro=suse_9.1 elif [ -n "`egrep 'SuSE Linux 9\.2' /etc/issue`" ]; then distro=suse_9.2 elif [ -n "`egrep 'SuSE Linux 9\.3' /etc/issue`" ]; then distro=suse_9.3 # Welcome to SUSE LINUX 10.1 (i586) - Kernel \r (\l). elif [ -n "`egrep 'SUSE LINUX 10\.1' /etc/issue`" ]; then distro=suse_10.1 # Welcome to openSUSE 10.2 (i586) - Kernel \r (\l). elif [ -n "`egrep 'SUSE 10\.2' /etc/issue`" ]; then distro=suse_10.2 elif [ -n "`egrep 'SUSE 10\.3' /etc/issue`" ]; then distro=suse_10.3 elif [ -n "`egrep 'Tao Linux release 1 ' /etc/issue`" ]; then distro=tao_1.0 elif [ -n "`egrep 'Fedora Core ' /etc/issue`" ]; then distro_brand=fc distro_version=`grep 'Fedora Core ' /etc/issue | sed -e 's/Fedora Core release \([0-9]*\).*/\1/' ` distro=${distro_brand}${distro_version} elif [ -n "`egrep 'White Box Enterprise Linux release 3.0' /etc/issue`" ]; then distro=white_box_enterprise_linux_3.0 else distro=unknown_linux_type_please_send_us_a_patch fi fi # ############################################################################ ############################################################################ # # Step 3) Put it all together as $type # type=linux-${distro}-${hardware} # ############################################################################ os=$uos release=$urelease } get_darwin_info() { ############################################################################ # # step 1) determine $hardware (architecture) string # (Should be one of ppc, ppc64. Why these strings? Well, we are # taking them from the arches directory names in the linux kernel # source.) -BEF- # if [ -n "`system_profiler SPHardwareDataType|egrep '(CPU Type|Processor Name): PowerPC G4 '`" ]; then hardware=ppc elif [ -n "`system_profiler SPHardwareDataType|egrep '(CPU Type|Processor Name): PowerPC (970|G5) '`" ]; then hardware=ppc64 elif [ -n "`system_profiler SPHardwareDataType|egrep 'Processor Name: Intel Core Duo'`" ]; then hardware=ia32 elif [ -n "`system_profiler SPHardwareDataType|egrep 'Processor Name: (Dual-Core Intel Xeon|Intel Core 2 Duo)'`" ]; then hardware=x86_64 else hardware=unknown_darwin_hardware_please_send_us_a_patch fi # ############################################################################ ############################################################################ # # step 2) determine $distro (distribution) string # # Thanks to JP Navarro for the get distro version string command # below. -BEF- # distro_brand=macosx distro_version=`sw_vers -productVersion|sed -e 's/\([0-9]\{1,2\}\.[0-9]\{1,2\}\).*/\1/'` distro=${distro_brand}_${distro_version} if [ -z "$distro" ]; then distro=unknown_darwin_version_please_send_us_a_patch fi # ############################################################################ ############################################################################ # # Step 3) Put it all together as $type # type=darwin-${distro}-${hardware} # ############################################################################ os=$uos release=$urelease } # ################################################################################ # # Check the number of arguments and set the mode. # mode=type format=default if [ $# = 1 ]; then case "$1" in --c*|-c* ) format=classad ;; --x*|-x* ) format=xml ;; --t*|-t* ) mode=type ;; --n*|-n* ) mode=os ;; --r*|-r* ) mode=release ;; --m*|-m* ) mode=hardware ;; --a*|-a* ) mode=all ;; --list-all* ) mode=list_all ;; --l*|-l* ) mode=list ;; --v*|-v* ) mode=version ;; --h*|-h* ) mode=usage ;; --o*|-o* ) mode=option_test # Cycles through and tries each of the other options, for testing purposes. ;; esac fi if [ "$mode" = "unknown" -o "$mode" = "usage" ]; then echo "$program $version" echo echo "Usage: $program [OPTION]" echo cat <. EOF if [ "$mode" = "usage" ]; then exit 0 else exit 1 fi fi # =========================================================================== # Okay, now we know what we should do... if the mode is list or the version # that's easy to get out of the way. # # Be sure to add to this list whenever a new architecture is figured out. # =========================================================================== if [ "$mode" = "list" ]; then cat </dev/null` || uos=unknown urelease=`($UNAME -r) 2>/dev/null` || urelease=unknown uhardware=`($UNAME -m) 2>/dev/null` || uhardware=unknown type=unknown os=unknown release=unknown hardware=unknown case "${uos}:${urelease}:${uhardware}" in AIX:*:*) release=`$UNAME -v 2>/dev/null` || release=unknown # case $release in # 3) # type=aix-3 # ;; # 4) # type=aix-4 # ;; # 5) # type=aix-5 # ;; # esac type=aix-$release.$urelease os=$uos hardware=$uhardware ;; A/UX:*:*) type=aux os=$uos release=$urelease hardware=$uhardware ;; CYGWIN_NT-5.1:*:*) type=cygwin-5.1 os=$uos release=$urelease hardware=$uhardware ;; Darwin:*:*) get_darwin_info ;; FreeBSD:*:*) type=freebsd os=$uos release=$urelease hardware=$uhardware ;; HP-UX:*:*) type=hpux os=$uos release=$urelease hardware=$uhardware ;; IRIX:5*:*) type=irix-5 os=$uos release=$urelease hardware=`$UNAME -p 2>/dev/null` || hardware=unknown ;; # On alaska, uname->IRIX64, but IRIX everywhere else. IRIX*:6*:*) type=irix-6 os=$uos release=$urelease hardware=`$UNAME -p 2>/dev/null` || hardware=unknown ;; Linux:*:*) os=$uos release=$urelease hardware=$uhardware case $uhardware in alpha) # legacy definition type=linux-alpha ;; *) # legacy definitions if [ -f /etc/issue ]; then if [ -n "`cat /etc/issue | grep "Mandrake release 7.2"`" ]; then type=linux-2 elif [ -n "`cat /etc/issue | grep "Red Hat Linux release 7.1"`" ]; then type=linux-rh71 elif [ -n "`cat /etc/issue | grep "Red Hat Linux release 7.2"`" ]; then type=linux-rh72 elif [ -n "`cat /etc/issue | grep "Red Hat Linux release 7.3"`" ]; then type=linux-rh73 else get_linux_type fi else type=linux fi ;; esac ;; SunOS:4*:*) type=sun4 os=$uos release=$urelease hardware=`/bin/arch -k` || hardware=unknown ;; SunOS:5*:*) solaris_version=`uname -r | sed 's/^5\.//'` type=solaris-${solaris_version} os=$uos release=$urelease hardware=`/bin/arch -k` || hardware=unknown ;; OSF1:*:*) type=osf os=$uos release=$urelease hardware=$uhardware ;; ULTRIX:*:*) type=ultrix os=$uos release=$urelease hardware=$uhardware ;; esac exit_code=0 grid="" # =========================================================================== # Got all the info, now just print the right stuff based on mode. # =========================================================================== case $format in classad) echo ${grid}whatami_type = \"$type\" echo ${grid}whatami_os = \"$os\" echo ${grid}whatami_release = \"$release\" echo ${grid}whatami_hardware = \"$hardware\" if [ $os = "Linux" ]; then echo ${grid}whatami_distro = \"$distro\" fi exit ;; xml) echo "<${grid}whatami>" echo " $type" echo " $os" echo " $release" echo " $hardware" if [ $os = "Linux" ]; then echo " $distro" fi echo "" exit ;; esac case $mode in type) if [ $type = "unknown" ]; then exit_code=1 fi echo $type ;; os) if [ $os = "unknown" ]; then exit_code=1 fi echo $os ;; release) if [ $os = "unknown" -o $release = "unknown" ]; then exit_code=1 fi echo "$os $release" ;; hardware) if [ $hardware = "unknown" ]; then exit_code=1 fi echo $hardware ;; all) if [ $hardware = "unknown" \ -o $os = "unknown" \ -o $release = "unknown" ]; then exit_code=1 fi echo "$type $hardware $os $release" ;; esac exit $exit_code