3 # os.sh - operating system specifics
6 # This file is included at the start of processing. Its role is
7 # to set the variables OS, OSREL, OSMAJOR, MACHINE and MACHINE_ARCH to
8 # reflect the current system.
10 # It also sets variables such as MAILER, LOCAL_FS, PS_AXC to hide
11 # certain aspects of different UNIX flavours.
17 # Simon J. Gerraty <sjg@crufty.net>
20 # $Id: os.sh,v 1.55 2017/12/11 20:31:41 sjg Exp $
22 # @(#) Copyright (c) 1994 Simon J. Gerraty
24 # This file is provided in the hope that it will
25 # be of use. There is absolutely NO WARRANTY.
26 # Permission to copy, redistribute or otherwise
27 # use this file is hereby granted provided that
28 # the above copyright notice and this notice are
31 # Please send copies of changes and bug-fixes to:
35 # this lets us skip sourcing it again
40 OSMAJOR=`IFS=.; set $OSREL; echo $1`
42 MACHINE_ARCH=`uname -p 2>/dev/null || echo $MACHINE`
44 # there is at least one case of `uname -p` outputting
45 # a bunch of usless drivel
46 case "$MACHINE_ARCH" in
47 unknown|*[!A-Za-z0-9_-]*) MACHINE_ARCH="$MACHINE";;
50 # we need this here, and it is not always available...
57 /*) test $t $1 && echo $1;;
59 # some shells cannot correctly handle `IFS`
60 # in conjunction with the for loop.
61 _dirs=`IFS=:; echo ${2:-$PATH}`
64 test $t $d/$1 && { echo $d/$1; break; }
70 # tr is insanely non-portable wrt char classes, so we need to
71 # spell out the alphabet. sed y/// would work too.
73 ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
77 ${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
82 AIX) # everyone loves to be different...
84 OSREL="$OSMAJOR.`uname -r`"
87 SHARE_ARCH=$OS/$OSMAJOR.X
90 CHOWN=`Which chown /usr/etc:/usr/bin`
93 # Great! Solaris keeps moving arch(1)
94 # should just bite the bullet and use uname -p
95 arch=`Which arch /usr/bin:/usr/ucb`
102 # uname -m just says sun which could be anything
105 MACHINE=$MACHINE_ARCH
115 # can you believe that ln on Solaris defaults to
116 # overwriting an existing file!!!!! We want one that works!
117 test -x /usr/xpg4/bin/ln && LN=${LN:-/usr/xpg4/bin/ln}
118 # wonderful, 5.8's tr again require's []'s
119 # but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set!
120 # use toUpper/toLower instead.
123 case "$OS/$MACHINE_ARCH" in
124 *sun386) SHARE_ARCH=$MACHINE_ARCH;;
137 # NetBSD at least has good backward compatibility
138 # so NetBSD/i386 is good enough
143 SHARE_ARCH=$OS/$HOST_ARCH
146 arch=`Which arch /usr/bin:/usr/ucb:$PATH`
147 MACHINE_ARCH=`$arch -s`
154 TMP_DIRS="/tmp /usr/tmp"
157 # don't rely on /bin/sh, its broken
158 _shell=/bin/ksh; ENV=
159 # also, no one would be interested in OSMAJOR=A
161 ?.09*) OSMAJOR=9; PS_AXC=-e;;
162 ?.10*) OSMAJOR=10; PS_AXC=-e;;
174 OSMAJOR=`IFS=.; set $OSREL; echo $1`
175 MACHINE_ARCH=`uname -m`
178 # Not really any such thing as Linux, but
179 # this covers red-hat and hopefully others.
181 i?86) MACHINE_ARCH=i386;; # we don't care about i686 vs i586
185 [ -x /usr/bin/md5sum ] && { MD5=/usr/bin/md5sum; export MD5; }
189 x86pc) MACHINE_ARCH=i386;;
194 BeBox) MACHINE_ARCH=powerpc;;
195 BeMac) MACHINE_ARCH=powerpc;;
196 BePC) MACHINE_ARCH=i386;;
200 LOCALBASE=${LOCALBASE:-/usr/local}
202 HOSTNAME=${HOSTNAME:-`( hostname ) 2>/dev/null`}
203 HOSTNAME=${HOSTNAME:-`( uname -n ) 2>/dev/null`}
205 *.*) HOST=`IFS=.; set -- $HOSTNAME; echo $1`;;
209 TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"}
210 MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
211 case "$MACHINE_ARCH" in
212 x86*64|amd64) MACHINE32_ARCH=i386;;
213 *64) MACHINE32_ARCH=`echo $MACHINE_ARCH | sed 's,64,32,'`;;
214 *) MACHINE32_ARCH=$MACHINE_ARCH;;
216 HOST_ARCH=${HOST_ARCH:-$MACHINE_ARCH}
217 HOST_ARCH32=${HOST_ARCH32:-$MACHINE32_ARCH}
218 # we mount server:/share/arch/$SHARE_ARCH as /usr/local
219 SHARE_ARCH_DEFAULT=$OS/$OSMAJOR.X/$HOST_ARCH
220 SHARE_ARCH=${SHARE_ARCH:-$SHARE_ARCH_DEFAULT}
224 # Some people like have /share/$HOST_TARGET/bin etc.
225 HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower`
226 HOST_TARGET32=`echo ${OS}${OSMAJOR}-$HOST_ARCH32 | tr -d / | toLower`
227 export HOST_TARGET HOST_TARGET32
229 case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac
233 -n) _n=$N _c=$C; shift;;
240 export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC
241 export LN SHARE_ARCH TR
252 */host_target32) echo $HOST_TARGET32;;
253 */host_target) echo $HOST_TARGET;;