xref: /freebsd/contrib/ntp/sntp/scripts/cvo.sh (revision 2abb9b42a53c39a8b781e25a05de1de9e98b8b9a)
1#! /bin/sh
2
3# Copyright 2002, 2009, 2010 Harlan Stenn.  Used by NTP with permission.
4# Author: Harlan Stenn <harlan+cvo@pfcs.com>
5
6# Possible output formats:
7#
8# CVO=...		Shell variable
9# CVO=... ; export CVO	Old-style exported envariable
10# export CVO=...	New-style exported envariable
11# setenv CVO ...	csh-style exported envariable
12
13TS="$*"
14
15CVO_raw=`config.guess`
16CVO=$CVO_raw
17
18set 1 `echo $CVO | tr '-' ' '`
19shift
20
21case "$#" in
22 4) # eg: i686-pc-linux-gnu
23    CVO_CPU=$1
24    CVO_VENDOR=$2
25    cvo_KERN=$3			# Note the capitalization...
26    CVO_OS=$4
27    case "$cvo_KERN" in
28     linux)			# Braindamage.  We want OS, not kernel info
29	if lsb_release > /dev/null 2>&1
30	then
31	    CVO_OS=`lsb_release --id --short | tr '[:upper:]' '[:lower:]'`
32	    CVO_OS="$CVO_OS`lsb_release --release --short`"
33	elif test -f /etc/debian_version
34	then
35	    set `cat /etc/debian_version`
36	    CVO_OS=debian$1
37	    CVO_KOSVER=`uname -r`
38	elif test -f /etc/mandrake-release
39	then
40	    set `cat /etc/mandrake-release`
41	    CVO_OS=mandrake$4
42	    CVO_KOSVER=`uname -r`
43	elif test -f /etc/redhat-release
44	then
45	    set `cat /etc/redhat-release`
46	    case "$1" in
47	     CentOS)
48		case "$2" in
49		 Linux)
50		    CVO_OS=centos$4
51		    ;;
52		 *) CVO_OS=centos$3
53		    ;;
54		esac
55	        ;;
56	     Fedora)
57	        CVO_OS=fedora$3
58	        ;;
59	    *)
60		case "$3" in
61		 Enterprise)
62		    CVO_OS=redhat$7.E
63		    ;;
64		 Linux)
65		    CVO_OS=redhat$5
66		    ;;
67		esac
68		;;
69	    esac
70	    CVO_KOSVER=`uname -r`
71	elif test -f /etc/slackware-version
72	then
73	    set `cat /etc/slackware-version`
74	    CVO_OS=slackware$2
75	    CVO_KOSVER=`uname -r`
76	elif test -f /etc/SuSE-release
77	then
78	    set `cat /etc/SuSE-release`
79	    CVO_OS=suse$9
80	    CVO_KOSVER=`uname -r`
81	else
82	    CVO_OS=$cvo_KERN`uname -r`
83
84	fi
85	;;
86     nto)	# QNX
87	CVO_KOSVER=`uname -r`
88	;;
89     *)
90	echo "gronk - I don't understand <$CVO>!"
91	exit 1
92	;;
93    esac
94    ;;
95 3) CVO_CPU=$1
96    CVO_VENDOR=$2
97    CVO_OS=$3
98    ;;
99 *) echo "gronk - config.guess returned $# pieces, not 3 pieces!"
100    exit 1
101    ;;
102esac
103
104case "$CVO_OS" in
105 cygwin)
106    # Decisions, decisions.
107    # uname -r is the cygwin version #, eg: 1.3.3(0.46/3/2)
108    # uname -s returns something like CYGWIN_NT-5.0
109    CVO_OS="$CVO_OS`uname -r | sed 's/(.*//'`"
110    ;;
111esac
112set `echo $CVO_OS | sed 's/\([0-9]\)/ \1/'`
113
114case "$#" in
115 2) ;;
116 *) echo "gronk - <$CVO_OS> expanded to $#, not 2 pieces!"
117    exit 1
118    ;;
119esac
120
121CVO_OSNAME=$1
122CVO_OSVER=$2
123
124case "$CVO_OSNAME" in
125 solaris)
126    CVO_KOSVER=`uname -v`
127    ;;
128esac
129
130CVO=$CVO_CPU-$CVO_VENDOR-$CVO_OS
131
132case "$TS" in
133 '')
134    set | grep CVO
135    ;;
136 *)
137    # keys['cvo'] = "cvo.CVO['CVO']"
138    TS=`echo $TS | sed -e s/@cvo@/$CVO/g`
139    # keys['cpu'] = "cvo.CVO['CVO_CPU']"
140    TS=`echo $TS | sed -e s/@cpu@/$CVO_CPU/g`
141    # keys['kosver'] = "cvo.CVO['CVO_KOSVER']"
142    TS=`echo $TS | sed -e s/@kosver@/$CVO_KOSVER/g`
143    # keys['os'] = "cvo.CVO['CVO_OS']"
144    TS=`echo $TS | sed -e s/@os@/$CVO_OS/g`
145    # keys['osname'] = "cvo.CVO['CVO_OSNAME']"
146    TS=`echo $TS | sed -e s/@osname@/$CVO_OSNAME/g`
147    # keys['osver'] = "cvo.CVO['CVO_OSVER']"
148    TS=`echo $TS | sed -e s/@osver@/$CVO_OSVER/g`
149    # keys['vendor'] = "cvo.CVO['CVO_VENDOR']"
150    TS=`echo $TS | sed -e s/@vendor@/$CVO_VENDOR/g`
151    # keys['raw'] = "cvo.CVO['CVO_raw']"
152    TS=`echo $TS | sed -e s/@raw@/$CVO_raw/g`
153
154    echo $TS
155    ;;
156esac
157