osstuff.sh 2.74 KB
Newer Older
1
#!/bin/sh
Mike Hibler's avatar
Mike Hibler committed
2 3
#
# Copyright (c) 2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Mike Hibler's avatar
Mike Hibler committed
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

#
# Figure out which OS, distro. etc.
# Output: TAG=<string> OS=<string> DIST=<string> REL=<string>
#  where OS is 'FreeBSD', 'Linux', 'Cygwin', etc.
#        DIST for Linux only, is 'Redhat', 'Fedora', 'Ubuntu', etc.
#        REL is the release like '6.2', '9.0', '5.1', etc.
#        TAG is a unique combo of the above like 'freebsd6', 'fedora4', etc.
#

if [ $# -ne 1 ]; then
    arg="-a"
else
    arg=$1
fi

os=`uname -s`
tag=
dist=

case $os in
FreeBSD)
    dist="FreeBSD"
    rel=`uname -v | sed -e 's/FreeBSD \([0-9]\.[0-9][0-9]*\).*/\1/'`
    ;;
Linux)
    if [ -r /etc/lsb-release ]; then
        dist=`grep DISTRIB_ID /etc/lsb-release | awk -F = '{ print $2; }'`
        rel=`grep DISTRIB_RELEASE /etc/lsb-release | awk -F = '{ print $2; }'`
    fi
    if [ -z "$dist" -a -r /etc/redhat-release ]; then
55 56
        trel=`grep 'Red Hat' /etc/redhat-release | sed -e 's/Red Hat Linux release \([0-9]\(\.[0-9]\)\?\).*/\1/'`
	if [ -n "$trel" ]; then
57
            dist="Redhat"
58 59 60 61 62 63 64 65 66 67 68
	    rel=$trel
	fi
	trel=`grep 'Fedora' /etc/redhat-release | sed -e 's/Fedora .*release \([0-9.]\+\).*/\1/'`
	if [ -n "$trel" ]; then
	    dist="Fedora"
	    rel=$trel
	fi
	trel=`grep 'CentOS' /etc/redhat-release | sed -e 's/CentOS .*release \([0-9.]\+\).*/\1/'`
	if [ -n "$trel" ]; then
	    dist="CentOS"
	    rel=$trel
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	fi
    fi
    # XXX hack check for stargate
    if [ -z "$dist" -a `uname -m` = "armv5tel" ]; then
        dist="Stargate"
        rel=1.0  # XXX probably wrong
    fi
    ;;
CYGWIN_NT-5.1)	# aka Windows XP
    tag=$os	# XXX compat for tmcd makefile
    os="Cygwin"
    dist="NT"
    rel="5.1"
    ;;
*)
    dist="Unknown"
    rel="0.0"
    ;;
esac

if [ -z "$tag" ]; then
    p1=`echo $dist | tr '[A-Z]' '[a-z]'`
91
    p2=`echo $rel | sed -e 's/^\([0-9]*\).*/\1/'`
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    tag="${p1}${p2}"
fi

case $arg in
-a)
    echo "TAG=$tag OS=$os DIST=$dist REL=$rel"
    ;;
-t)
    echo "$tag"
    ;;
-o)
    echo "$os"
    ;;
-d)
    echo "$dist"
    ;;
-r)
    echo "$rel"
    ;;
esac
exit 0