osstuff.sh 4.19 KB
Newer Older
1 2
#!/bin/sh
#
3
# Copyright (c) 2007-2018 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/>.
# 
# }}}
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#

#
# 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

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
# XXX cheezy hack for cross-building: if OSSTUFF env is set, use that info
if [ -n "$OSSTUFF" ]; then
    for _kv in $OSSTUFF; do
	_k=${_kv%%=*}
	_v=${_kv##*=}
	case $_k in
	TAG|OS|DIST|REL)
	    eval $_k=\"$_v\"
	    ;;
	esac
    done
    if [ -z "$OS" -o -z "$DIST" -o -z "$REL" ]; then
	echo "osstuff: malformed OSSTUFF environment var"
	exit 1
    fi
    if [ -z "$TAG" ]; then
	p1=`echo $DIST | tr '[A-Z]' '[a-z]'`
	p2=`echo $REL | sed -e 's/^\([0-9]*\).*/\1/'`
	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
fi

82 83 84 85 86 87 88
os=`uname -s`
tag=
dist=

case $os in
FreeBSD)
    dist="FreeBSD"
89
    rel=`uname -v | sed -e 's/FreeBSD \([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
90 91 92 93 94 95
    ;;
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
96 97 98 99 100 101 102
    if [ -z "$dist" -a -r /etc/os-release ]; then
	dist=`(. /etc/os-release ; echo $ID)`
	if [ "$dist" = "debian" ]; then
	    trel=`(. /etc/os-release ; echo $VERSION_ID)`
	    if [ -n "$trel" ]; then
		dist="Debian"
		rel=$trel
103 104 105 106 107 108
	    else
		grep PRETTY_NAME /etc/os-release | grep -q sid
		if [ $? -eq 0 ]; then
		    rel=S
		    tag=debianS
		fi
109 110 111
	    fi
	fi
    fi
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    if [ -z "$dist" -a -r /etc/redhat-release ]; then
        trel=`grep 'Red Hat' /etc/redhat-release | sed -e 's/Red Hat Linux release \([0-9]\(\.[0-9]\)\?\).*/\1/'`
	if [ -n "$trel" ]; then
            dist="Redhat"
	    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
	fi
    fi
129 130 131 132 133
    if [ -r /etc/centos-release ]; then
	trel=`grep 'CentOS' /etc/centos-release | sed -e 's/CentOS .*release \([0-9.]\+\).*/\1/'` 	
	dist="CentOS"
	rel=$trel
    fi
134 135 136 137 138
    # XXX hack check for stargate
    if [ -z "$dist" -a `uname -m` = "armv5tel" ]; then
        dist="Stargate"
        rel=1.0  # XXX probably wrong
    fi
139
    if [ "$dist" = "Ubuntu" -a `uname -m` = "aarch64" ]; then
140 141 142
	if [ "$rel" = "18.04" ]; then
	    tag=MoonshotUbuntu18
	elif [ "$rel" = "16.04" ]; then
143 144 145 146
	    tag=MoonshotUbuntu16
	else
	    tag=Moonshot
	fi
147
    fi
148
    ;;
149
CYGWIN_NT-*)	# aka Windows XP/7
150 151 152
    tag=$os	# XXX compat for tmcd makefile
    os="Cygwin"
    dist="NT"
153
    rel=`echo $tag | sed -e 's/^CYGWIN_NT-\(.*\)/\1/'`
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
    ;;
*)
    dist="Unknown"
    rel="0.0"
    ;;
esac

if [ -z "$tag" ]; then
    p1=`echo $dist | tr '[A-Z]' '[a-z]'`
    p2=`echo $rel | sed -e 's/^\([0-9]*\).*/\1/'`
    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