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.64 2024/03/19 16:03:23 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` 45# and even `uname -m` outputting usless info 46# fortunately not both together 47case "$MACHINE" in 48*[!A-Za-z0-9_-]*) MACHINE="$MACHINE_ARCH";; 49esac 50case "$MACHINE_ARCH" in 51unknown|*[!A-Za-z0-9_-]*) MACHINE_ARCH="$MACHINE";; 52esac 53 54# we need this here, and it is not always available... 55Which() { 56 case "$1" in 57 -*) t=$1; shift;; 58 *) t=-x;; 59 esac 60 case "$1" in 61 /*) test $t $1 && echo $1;; 62 *) 63 # some shells cannot correctly handle `IFS` 64 # in conjunction with the for loop. 65 _dirs=`IFS=:; echo ${2:-$PATH}` 66 for d in $_dirs 67 do 68 test $t $d/$1 && { echo $d/$1; break; } 69 done 70 ;; 71 esac 72} 73 74# tr is insanely non-portable wrt char classes, so we need to 75# spell out the alphabet. sed y/// would work too. 76toUpper() { 77 ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 78} 79 80toLower() { 81 ${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 82} 83 84K= 85case "$OS" in 86AIX) # everyone loves to be different... 87 OSMAJOR=`uname -v` 88 OSMINOR=`uname -r` 89 OSREL="$OSMAJOR.$OSMINOR" 90 LOCAL_FS=jfs 91 PS_AXC=-e 92 SHARE_ARCH=$OS/$OSMAJOR.X 93 ;; 94CYGWIN*) # uname -s not very useful 95 # uname -o produces just Cygwin which is better 96 OS=Cygwin 97 ;; 98Darwin) # this is more explicit (arm64 vs arm) 99 HOST_ARCH=$MACHINE 100 ;; 101SunOS) 102 CHOWN=`Which chown /usr/etc:/usr/bin` 103 export CHOWN 104 105 # Great! Solaris keeps moving arch(1) 106 # should just bite the bullet and use uname -p 107 arch=`Which arch /usr/bin:/usr/ucb` 108 109 MAILER=/usr/ucb/Mail 110 LOCAL_FS=4.2 111 112 case "$OSREL" in 113 4.0*) 114 # uname -m just says sun which could be anything 115 # so use arch(1). 116 MACHINE_ARCH=`arch` 117 MACHINE=$MACHINE_ARCH 118 ;; 119 4*) 120 MACHINE_ARCH=`arch` 121 ;; 122 5*) 123 K=-k 124 LOCAL_FS=ufs 125 MAILER=mailx 126 PS_AXC=-e 127 # can you believe that ln on Solaris defaults to 128 # overwriting an existing file!!!!! We want one that works! 129 test -x /usr/xpg4/bin/ln && LN=${LN:-/usr/xpg4/bin/ln} 130 # wonderful, 5.8's tr again require's []'s 131 # but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set! 132 # use toUpper/toLower instead. 133 ;; 134 esac 135 case "$OS/$MACHINE_ARCH" in 136 *sun386) SHARE_ARCH=$MACHINE_ARCH;; 137 esac 138 ;; 139*BSD) 140 K=-k 141 MAILER=/usr/bin/Mail 142 LOCAL_FS=local 143 : $-,$ENV 144 case "$-,$ENV" in 145 *i*,*) ;; 146 *,|*ENVFILE*) ;; 147 *) ENV=;; 148 esac 149 # NetBSD at least has good backward compatibility 150 # so NetBSD/i386 is good enough 151 # recent NetBSD uses x86_64 for MACHINE_ARCH 152 case $OS in 153 NetBSD) 154 LOCALBASE=/usr/pkg 155 SHARE_ARCH=$OS/$HOST_ARCH 156 ;; 157 OpenBSD) 158 arch=`Which arch /usr/bin:/usr/ucb:$PATH` 159 MACHINE_ARCH=`$arch -s` 160 ;; 161 esac 162 NAWK=awk 163 export NAWK 164 ;; 165HP-UX) 166 TMP_DIRS="/tmp /usr/tmp" 167 LOCAL_FS=hfs 168 MAILER=mailx 169 # don't rely on /bin/sh, its broken 170 _shell=/bin/ksh; ENV= 171 # also, no one would be interested in OSMAJOR=A 172 case "$OSREL" in 173 ?.09*) OSMAJOR=9; PS_AXC=-e;; 174 ?.10*) OSMAJOR=10; PS_AXC=-e;; 175 esac 176 ;; 177IRIX) 178 LOCAL_FS=efs 179 ;; 180Interix) 181 MACHINE=i386 182 MACHINE_ARCH=i386 183 ;; 184UnixWare|SCO_SV) 185 OSREL=`uname -v` 186 OSMAJOR=`IFS=.; set $OSREL; echo $1` 187 MACHINE_ARCH=`uname -m` 188 ;; 189Linux) 190 # Not really any such thing as Linux, but 191 # this covers red-hat and hopefully others. 192 case $MACHINE in 193 i?86) MACHINE_ARCH=i386;; # we don't care about i686 vs i586 194 esac 195 LOCAL_FS=ext2 196 PS_AXC=axc 197 [ -x /usr/bin/md5sum ] && { MD5=/usr/bin/md5sum; export MD5; } 198 ;; 199QNX) 200 case $MACHINE in 201 x86pc) MACHINE_ARCH=i386;; 202 esac 203 ;; 204Haiku) 205 case $MACHINE in 206 BeBox) MACHINE_ARCH=powerpc;; 207 BeMac) MACHINE_ARCH=powerpc;; 208 BePC) MACHINE_ARCH=i386;; 209 esac 210 ;; 211esac 212LOCALBASE=${LOCALBASE:-/usr/local} 213 214HOSTNAME=${HOSTNAME:-`( hostname ) 2>/dev/null`} 215HOSTNAME=${HOSTNAME:-`( uname -n ) 2>/dev/null`} 216case "$HOSTNAME" in 217*.*) HOST=`IFS=.; set -- $HOSTNAME; echo $1`;; 218*) HOST=$HOSTNAME;; 219esac 220 221TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"} 222MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE} 223HOST_ARCH=${HOST_ARCH:-$MACHINE_ARCH} 224case "$HOST_ARCH" in 225x86*64|amd64) MACHINE32_ARCH=i386;; 226*64) MACHINE32_ARCH=`echo $MACHINE_ARCH | sed 's,64,32,'`;; 227*) MACHINE32_ARCH=$MACHINE_ARCH;; 228esac 229HOST_ARCH32=${HOST_ARCH32:-$MACHINE32_ARCH} 230# we mount server:/share/arch/$SHARE_ARCH as /usr/local 231SHARE_ARCH_DEFAULT=$OS/$OSMAJOR.X/$HOST_ARCH 232SHARE_ARCH=${SHARE_ARCH:-$SHARE_ARCH_DEFAULT} 233LN=${LN:-ln} 234TR=${TR:-tr} 235 236# Some people like have /share/$HOST_TARGET/bin etc. 237HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower` 238HOST_TARGET32=`echo ${OS}${OSMAJOR}-$HOST_ARCH32 | tr -d / | toLower` 239export HOST_TARGET HOST_TARGET32 240 241case `echo -n .` in -n*) echo_n=; echo_c="\c";; *) echo_n=-n; echo_c=;; esac 242 243Echo() { 244 case "$1" in 245 -n) shift; echo $echo_n "$@$echo_c";; 246 *) echo "$@";; 247 esac 248} 249 250# for systems that deprecate egrep 251case "`echo egrep | egrep 'e|g' 2>&1`" in 252egrep) ;; 253*) egrep() { grep -E "$@"; };; 254esac 255 256export HOSTNAME HOST 257export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC 258export LN SHARE_ARCH TR 259export LOCALBASE 260 261case /$0 in 262*/os.sh) 263 for v in $* 264 do 265 eval vv=\$$v 266 echo "$v='$vv'" 267 done 268 ;; 269*/host_target32) echo $HOST_TARGET32;; 270*/host_target) echo $HOST_TARGET;; 271esac 272 273