xref: /freebsd/contrib/ntp/sntp/scripts/cvo.sh (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
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 test -f /etc/os-release
30	then
31	    . /etc/os-release
32	    ID=`echo $ID | tr '-' '_'`
33	    CVO_OS="${ID}${VERSION_ID}"
34	    CVO_KOSVER=`uname -r`
35	elif lsb_release > /dev/null 2>&1
36	then
37	    CVO_OS=`lsb_release --id --short | tr '[:upper:]' '[:lower:]'`
38	    CVO_OS="$CVO_OS`lsb_release --release --short`"
39	elif test -f /etc/debian_version
40	then
41	    set `cat /etc/debian_version`
42	    CVO_OS=debian$1
43	    CVO_KOSVER=`uname -r`
44	elif test -f /etc/mandrake-release
45	then
46	    set `cat /etc/mandrake-release`
47	    CVO_OS=mandrake$4
48	    CVO_KOSVER=`uname -r`
49	elif test -f /etc/redhat-release
50	then
51	    set `cat /etc/redhat-release`
52	    case "$1" in
53	     CentOS)
54		case "$2" in
55		 Linux)
56		    CVO_OS=centos$4
57		    ;;
58		 *) CVO_OS=centos$3
59		    ;;
60		esac
61	        ;;
62	     Fedora)
63	        CVO_OS=fedora$3
64	        ;;
65	    *)
66		case "$3" in
67		 Enterprise)
68		    CVO_OS=redhat$7.E
69		    ;;
70		 Linux)
71		    CVO_OS=redhat$5
72		    ;;
73		esac
74		;;
75	    esac
76	    CVO_KOSVER=`uname -r`
77	elif test -f /etc/slackware-version
78	then
79	    set `cat /etc/slackware-version`
80	    CVO_OS=slackware$2
81	    CVO_KOSVER=`uname -r`
82	elif test -f /etc/SuSE-release
83	then
84	    set `cat /etc/SuSE-release`
85	    CVO_OS=suse$9
86	    CVO_KOSVER=`uname -r`
87	else
88	    CVO_OS=$cvo_KERN`uname -r`
89
90	fi
91	;;
92     nto)	# QNX
93	CVO_KOSVER=`uname -r`
94	;;
95     *)
96	echo "gronk - I don't understand <$CVO>!"
97	exit 1
98	;;
99    esac
100    ;;
101 3) CVO_CPU=$1
102    CVO_VENDOR=$2
103    CVO_OS=$3
104    ;;
105 *) echo "gronk - config.guess returned $# pieces, not 3 pieces!"
106    exit 1
107    ;;
108esac
109
110case "$CVO_OS" in
111 cygwin)
112    # Decisions, decisions.
113    # uname -r is the cygwin version #, eg: 1.3.3(0.46/3/2)
114    # uname -s returns something like CYGWIN_NT-5.0
115    CVO_OS="$CVO_OS`uname -r | sed 's/(.*//'`"
116    ;;
117esac
118set `echo $CVO_OS | sed 's/\([0-9]\)/ \1/'`
119
120case "$#" in
121 2) ;;
122 *) echo "gronk - <$CVO_OS> expanded to $#, not 2 pieces!"
123    exit 1
124    ;;
125esac
126
127CVO_OSNAME=$1
128CVO_OSVER=$2
129
130case "$CVO_OSNAME" in
131 solaris)
132    CVO_KOSVER=`uname -v`
133    ;;
134esac
135
136CVO=$CVO_CPU-$CVO_VENDOR-$CVO_OS
137
138case "$TS" in
139 '')
140    set | grep CVO
141    ;;
142 *)
143    # keys['cvo'] = "cvo.CVO['CVO']"
144    TS=`echo $TS | sed -e s/@cvo@/$CVO/g`
145    # keys['cpu'] = "cvo.CVO['CVO_CPU']"
146    TS=`echo $TS | sed -e s/@cpu@/$CVO_CPU/g`
147    # keys['kosver'] = "cvo.CVO['CVO_KOSVER']"
148    TS=`echo $TS | sed -e s/@kosver@/$CVO_KOSVER/g`
149    # keys['os'] = "cvo.CVO['CVO_OS']"
150    TS=`echo $TS | sed -e s/@os@/$CVO_OS/g`
151    # keys['osname'] = "cvo.CVO['CVO_OSNAME']"
152    TS=`echo $TS | sed -e s/@osname@/$CVO_OSNAME/g`
153    # keys['osver'] = "cvo.CVO['CVO_OSVER']"
154    TS=`echo $TS | sed -e s/@osver@/$CVO_OSVER/g`
155    # keys['vendor'] = "cvo.CVO['CVO_VENDOR']"
156    TS=`echo $TS | sed -e s/@vendor@/$CVO_VENDOR/g`
157    # keys['raw'] = "cvo.CVO['CVO_raw']"
158    TS=`echo $TS | sed -e s/@raw@/$CVO_raw/g`
159
160    echo $TS
161    ;;
162esac
163