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