xref: /freebsd/contrib/ntp/sntp/scripts/cvo.sh (revision f5f40dd63bc7acbb5312b26ac1ea1103c12352a6)
12b15cb3dSCy Schubert#! /bin/sh
22b15cb3dSCy Schubert
32b15cb3dSCy Schubert# Copyright 2002, 2009, 2010 Harlan Stenn.  Used by NTP with permission.
42b15cb3dSCy Schubert# Author: Harlan Stenn <harlan+cvo@pfcs.com>
52b15cb3dSCy Schubert
62b15cb3dSCy Schubert# Possible output formats:
72b15cb3dSCy Schubert#
82b15cb3dSCy Schubert# CVO=...		Shell variable
92b15cb3dSCy Schubert# CVO=... ; export CVO	Old-style exported envariable
102b15cb3dSCy Schubert# export CVO=...	New-style exported envariable
112b15cb3dSCy Schubert# setenv CVO ...	csh-style exported envariable
122b15cb3dSCy Schubert
132b15cb3dSCy SchubertTS="$*"
142b15cb3dSCy Schubert
152b15cb3dSCy SchubertCVO_raw=`config.guess`
162b15cb3dSCy SchubertCVO=$CVO_raw
172b15cb3dSCy Schubert
182b15cb3dSCy Schubertset 1 `echo $CVO | tr '-' ' '`
192b15cb3dSCy Schubertshift
202b15cb3dSCy Schubert
212b15cb3dSCy Schubertcase "$#" in
222b15cb3dSCy Schubert 4) # eg: i686-pc-linux-gnu
232b15cb3dSCy Schubert    CVO_CPU=$1
242b15cb3dSCy Schubert    CVO_VENDOR=$2
252b15cb3dSCy Schubert    cvo_KERN=$3			# Note the capitalization...
262b15cb3dSCy Schubert    CVO_OS=$4
272b15cb3dSCy Schubert    case "$cvo_KERN" in
282b15cb3dSCy Schubert     linux)			# Braindamage.  We want OS, not kernel info
29*f5f40dd6SCy Schubert	if test -f /etc/os-release
30*f5f40dd6SCy Schubert	then
31*f5f40dd6SCy Schubert	    . /etc/os-release
32*f5f40dd6SCy Schubert	    ID=`echo $ID | tr '-' '_'`
33*f5f40dd6SCy Schubert	    CVO_OS="${ID}${VERSION_ID}"
34*f5f40dd6SCy Schubert	    CVO_KOSVER=`uname -r`
35*f5f40dd6SCy Schubert	elif lsb_release > /dev/null 2>&1
362b15cb3dSCy Schubert	then
372b15cb3dSCy Schubert	    CVO_OS=`lsb_release --id --short | tr '[:upper:]' '[:lower:]'`
382b15cb3dSCy Schubert	    CVO_OS="$CVO_OS`lsb_release --release --short`"
392b15cb3dSCy Schubert	elif test -f /etc/debian_version
402b15cb3dSCy Schubert	then
412b15cb3dSCy Schubert	    set `cat /etc/debian_version`
422b15cb3dSCy Schubert	    CVO_OS=debian$1
432b15cb3dSCy Schubert	    CVO_KOSVER=`uname -r`
442b15cb3dSCy Schubert	elif test -f /etc/mandrake-release
452b15cb3dSCy Schubert	then
462b15cb3dSCy Schubert	    set `cat /etc/mandrake-release`
472b15cb3dSCy Schubert	    CVO_OS=mandrake$4
482b15cb3dSCy Schubert	    CVO_KOSVER=`uname -r`
492b15cb3dSCy Schubert	elif test -f /etc/redhat-release
502b15cb3dSCy Schubert	then
512b15cb3dSCy Schubert	    set `cat /etc/redhat-release`
522b15cb3dSCy Schubert	    case "$1" in
532b15cb3dSCy Schubert	     CentOS)
542b15cb3dSCy Schubert		case "$2" in
552b15cb3dSCy Schubert		 Linux)
562b15cb3dSCy Schubert		    CVO_OS=centos$4
572b15cb3dSCy Schubert		    ;;
582b15cb3dSCy Schubert		 *) CVO_OS=centos$3
592b15cb3dSCy Schubert		    ;;
602b15cb3dSCy Schubert		esac
612b15cb3dSCy Schubert	        ;;
622b15cb3dSCy Schubert	     Fedora)
632b15cb3dSCy Schubert	        CVO_OS=fedora$3
642b15cb3dSCy Schubert	        ;;
652b15cb3dSCy Schubert	    *)
662b15cb3dSCy Schubert		case "$3" in
672b15cb3dSCy Schubert		 Enterprise)
682b15cb3dSCy Schubert		    CVO_OS=redhat$7.E
692b15cb3dSCy Schubert		    ;;
702b15cb3dSCy Schubert		 Linux)
712b15cb3dSCy Schubert		    CVO_OS=redhat$5
722b15cb3dSCy Schubert		    ;;
732b15cb3dSCy Schubert		esac
742b15cb3dSCy Schubert		;;
752b15cb3dSCy Schubert	    esac
762b15cb3dSCy Schubert	    CVO_KOSVER=`uname -r`
772b15cb3dSCy Schubert	elif test -f /etc/slackware-version
782b15cb3dSCy Schubert	then
792b15cb3dSCy Schubert	    set `cat /etc/slackware-version`
802b15cb3dSCy Schubert	    CVO_OS=slackware$2
812b15cb3dSCy Schubert	    CVO_KOSVER=`uname -r`
822b15cb3dSCy Schubert	elif test -f /etc/SuSE-release
832b15cb3dSCy Schubert	then
842b15cb3dSCy Schubert	    set `cat /etc/SuSE-release`
852b15cb3dSCy Schubert	    CVO_OS=suse$9
862b15cb3dSCy Schubert	    CVO_KOSVER=`uname -r`
872b15cb3dSCy Schubert	else
882b15cb3dSCy Schubert	    CVO_OS=$cvo_KERN`uname -r`
892b15cb3dSCy Schubert
902b15cb3dSCy Schubert	fi
912b15cb3dSCy Schubert	;;
922b15cb3dSCy Schubert     nto)	# QNX
932b15cb3dSCy Schubert	CVO_KOSVER=`uname -r`
942b15cb3dSCy Schubert	;;
952b15cb3dSCy Schubert     *)
962b15cb3dSCy Schubert	echo "gronk - I don't understand <$CVO>!"
972b15cb3dSCy Schubert	exit 1
982b15cb3dSCy Schubert	;;
992b15cb3dSCy Schubert    esac
1002b15cb3dSCy Schubert    ;;
1012b15cb3dSCy Schubert 3) CVO_CPU=$1
1022b15cb3dSCy Schubert    CVO_VENDOR=$2
1032b15cb3dSCy Schubert    CVO_OS=$3
1042b15cb3dSCy Schubert    ;;
1052b15cb3dSCy Schubert *) echo "gronk - config.guess returned $# pieces, not 3 pieces!"
1062b15cb3dSCy Schubert    exit 1
1072b15cb3dSCy Schubert    ;;
1082b15cb3dSCy Schubertesac
1092b15cb3dSCy Schubert
1102b15cb3dSCy Schubertcase "$CVO_OS" in
1112b15cb3dSCy Schubert cygwin)
1122b15cb3dSCy Schubert    # Decisions, decisions.
1132b15cb3dSCy Schubert    # uname -r is the cygwin version #, eg: 1.3.3(0.46/3/2)
1142b15cb3dSCy Schubert    # uname -s returns something like CYGWIN_NT-5.0
1152b15cb3dSCy Schubert    CVO_OS="$CVO_OS`uname -r | sed 's/(.*//'`"
1162b15cb3dSCy Schubert    ;;
1172b15cb3dSCy Schubertesac
1182b15cb3dSCy Schubertset `echo $CVO_OS | sed 's/\([0-9]\)/ \1/'`
1192b15cb3dSCy Schubert
1202b15cb3dSCy Schubertcase "$#" in
1212b15cb3dSCy Schubert 2) ;;
1222b15cb3dSCy Schubert *) echo "gronk - <$CVO_OS> expanded to $#, not 2 pieces!"
1232b15cb3dSCy Schubert    exit 1
1242b15cb3dSCy Schubert    ;;
1252b15cb3dSCy Schubertesac
1262b15cb3dSCy Schubert
1272b15cb3dSCy SchubertCVO_OSNAME=$1
1282b15cb3dSCy SchubertCVO_OSVER=$2
1292b15cb3dSCy Schubert
1302b15cb3dSCy Schubertcase "$CVO_OSNAME" in
1312b15cb3dSCy Schubert solaris)
1322b15cb3dSCy Schubert    CVO_KOSVER=`uname -v`
1332b15cb3dSCy Schubert    ;;
1342b15cb3dSCy Schubertesac
1352b15cb3dSCy Schubert
1362b15cb3dSCy SchubertCVO=$CVO_CPU-$CVO_VENDOR-$CVO_OS
1372b15cb3dSCy Schubert
1382b15cb3dSCy Schubertcase "$TS" in
1392b15cb3dSCy Schubert '')
1402b15cb3dSCy Schubert    set | grep CVO
1412b15cb3dSCy Schubert    ;;
1422b15cb3dSCy Schubert *)
1432b15cb3dSCy Schubert    # keys['cvo'] = "cvo.CVO['CVO']"
1442b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@cvo@/$CVO/g`
1452b15cb3dSCy Schubert    # keys['cpu'] = "cvo.CVO['CVO_CPU']"
1462b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@cpu@/$CVO_CPU/g`
1472b15cb3dSCy Schubert    # keys['kosver'] = "cvo.CVO['CVO_KOSVER']"
1482b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@kosver@/$CVO_KOSVER/g`
1492b15cb3dSCy Schubert    # keys['os'] = "cvo.CVO['CVO_OS']"
1502b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@os@/$CVO_OS/g`
1512b15cb3dSCy Schubert    # keys['osname'] = "cvo.CVO['CVO_OSNAME']"
1522b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@osname@/$CVO_OSNAME/g`
1532b15cb3dSCy Schubert    # keys['osver'] = "cvo.CVO['CVO_OSVER']"
1542b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@osver@/$CVO_OSVER/g`
1552b15cb3dSCy Schubert    # keys['vendor'] = "cvo.CVO['CVO_VENDOR']"
1562b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@vendor@/$CVO_VENDOR/g`
1572b15cb3dSCy Schubert    # keys['raw'] = "cvo.CVO['CVO_raw']"
1582b15cb3dSCy Schubert    TS=`echo $TS | sed -e s/@raw@/$CVO_raw/g`
1592b15cb3dSCy Schubert
1602b15cb3dSCy Schubert    echo $TS
1612b15cb3dSCy Schubert    ;;
1622b15cb3dSCy Schubertesac
163