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