1:
2# NAME:
3#	os.sh - operating system specifics
4#
5# DESCRIPTION:
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.
9#	
10#	It also sets variables such as MAILER, LOCAL_FS, PS_AXC to hide
11#	certain aspects of different UNIX flavours. 
12#
13# SEE ALSO:
14#	site.sh,funcs.sh
15#
16# AUTHOR:
17#	Simon J. Gerraty <sjg@crufty.net>
18
19# RCSid:
20#	$Id: os.sh,v 1.44 2010/06/29 15:37:21 sjg Exp $
21#
22#	@(#) Copyright (c) 1994 Simon J. Gerraty
23#
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
29#	left intact. 
30#      
31#	Please send copies of changes and bug-fixes to:
32#	sjg@crufty.net
33#
34
35# this lets us skip sourcing it again
36_OS_SH=:
37
38OS=`uname`
39OSREL=`uname -r`
40OSMAJOR=`IFS=.; set $OSREL; echo $1`
41MACHINE=`uname -m`
42MACHINE_ARCH=`uname -p 2>/dev/null || echo $MACHINE`
43
44# there is at least one case of `uname -p` outputting
45# a bunch of usless drivel
46case "$MACHINE_ARCH" in
47*[!A-Za-z0-9_-]*) MACHINE_ARCH="$MACHINE";;
48esac
49        
50# we need this here, and it is not always available...
51Which() {
52	case "$1" in
53	-*) t=$1; shift;;
54	*) t=-x;;
55	esac
56	case "$1" in
57	/*)	test $t $1 && echo $1;;
58	*)
59        	# some shells cannot correctly handle `IFS`
60        	# in conjunction with the for loop.
61        	_dirs=`IFS=:; echo ${2:-$PATH}`
62        	for d in $_dirs
63		do
64			test $t $d/$1 && { echo $d/$1; break; }
65		done
66		;;
67	esac
68}
69
70# tr is insanely non-portable wrt char classes, so we need to
71# spell out the alphabet. sed y/// would work too.
72toUpper() {
73        ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
74}
75
76toLower() {
77        ${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
78}
79
80K=
81case $OS in
82AIX)	# everyone loves to be different...
83	OSMAJOR=`uname -v`
84	OSREL="$OSMAJOR.`uname -r`"
85	LOCAL_FS=jfs
86	PS_AXC=-e
87	SHARE_ARCH=$OS/$OSMAJOR.X
88	;;
89SunOS)
90	CHOWN=`Which chown /usr/etc:/usr/bin`
91	export CHOWN
92	
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`
96	
97	MAILER=/usr/ucb/Mail
98	LOCAL_FS=4.2
99	
100	case "$OSREL" in
101	4.0*)
102		# uname -m just says sun which could be anything
103		# so use arch(1).
104		MACHINE_ARCH=`arch`
105		MACHINE=$MACHINE_ARCH
106		;;
107	4*)
108                MACHINE_ARCH=`arch`
109                ;;
110	5*)
111		K=-k
112		LOCAL_FS=ufs
113		MAILER=mailx
114		PS_AXC=-e
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.
121		;;
122	esac
123	case "$OS/$MACHINE_ARCH" in
124	*sun386)	SHARE_ARCH=$MACHINE_ARCH;;
125	esac
126	;;
127*BSD)
128	K=-k
129	MAILER=/usr/bin/Mail
130	LOCAL_FS=local
131	case "$-" in
132	*i*) ;;
133	*) ENV=;;
134	esac
135	# NetBSD at least has good backward compatability
136	# so NetBSD/i386 is good enough
137	case $OS in
138	NetBSD) SHARE_ARCH=$OS/${MACHINE_ARCH:-$MACHINE};;
139	OpenBSD)
140	        arch=`Which arch /usr/bin:/usr/ucb:$PATH`
141                MACHINE_ARCH=`$arch -s`
142                ;;
143	esac
144	NAWK=awk
145	export NAWK
146	;;
147HP-UX)
148	TMP_DIRS="/tmp /usr/tmp"
149	LOCAL_FS=hfs
150	MAILER=mailx
151	# don't rely on /bin/sh, its broken
152	_shell=/bin/ksh; ENV=
153	# also, no one would be interested in OSMAJOR=A
154	case "$OSREL" in
155	?.09*)	OSMAJOR=9; PS_AXC=-e;;
156	?.10*)	OSMAJOR=10; PS_AXC=-e;;
157	esac
158	;;
159IRIX)
160	LOCAL_FS=efs
161	;;
162Interix)
163	MACHINE=i386
164	MACHINE_ARCH=i386
165	;;
166UnixWare)
167	OSREL=`uname -v`
168	OSMAJOR=`IFS=.; set $OSREL; echo $1`
169	MACHINE_ARCH=`uname -m`
170	;;
171Linux)
172	# Not really any such thing as Linux, but
173	# this covers red-hat and hopefully others.
174	case $MACHINE in
175	i?86)	MACHINE_ARCH=i386;; # we don't care about i686 vs i586
176	esac
177	LOCAL_FS=ext2
178	PS_AXC=axc
179	[ -x /usr/bin/md5sum ] && { MD5=/usr/bin/md5sum; export MD5; }
180	;;
181QNX)
182	case $MACHINE in
183	x86pc)	MACHINE_ARCH=i386;;
184	esac
185	;;
186Haiku)
187	case $MACHINE in
188	BeBox)	MACHINE_ARCH=powerpc;;
189	BeMac)	MACHINE_ARCH=powerpc;;
190	BePC)	MACHINE_ARCH=i386;;
191	esac
192	;;
193esac
194
195HOSTNAME=${HOSTNAME:-`( hostname ) 2>/dev/null`}
196HOSTNAME=${HOSTNAME:-`( uname -n ) 2>/dev/null`}
197case "$HOSTNAME" in
198*.*)	HOST=`IFS=.; set -- $HOSTNAME; echo $1`;;
199*)	HOST=$HOSTNAME;;
200esac
201
202TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"}
203MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
204# we mount server:/share/arch/$SHARE_ARCH as /usr/local
205SHARE_ARCH=${SHARE_ARCH:-$OS/$OSMAJOR.X/$MACHINE_ARCH}
206LN=${LN:-ln}
207TR=${TR:-tr}
208
209# Some people like have /share/$HOST_TARGET/bin etc.
210HOST_TARGET=`echo ${OS}${OSMAJOR}-${MACHINE_ARCH} | toLower`
211export HOST_TARGET
212
213case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac
214
215export HOSTNAME HOST        
216export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC
217export LN SHARE_ARCH TR
218
219case /$0 in
220*/os.sh)
221        for v in $*
222	do
223                eval vv=\$$v
224                echo "$v='$vv'"
225	done
226        ;;
227esac
228
229