This repository has been archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
find-systype.sh
121 lines (117 loc) · 2.96 KB
/
find-systype.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# oper-:arch-:syst-:chip-:kern-
# oper = operating system type; e.g., sunos-4.1.4
# arch = machine language; e.g., sparc
# syst = which binaries can run; e.g., sun4
# chip = chip model; e.g., micro-2-80
# kern = kernel version; e.g., sun4m
# dependence: arch --- chip
# \ \
# oper --- syst --- kern
# so, for example, syst is interpreted in light of oper, but chip is not.
# anyway, no slashes, no extra colons, no uppercase letters.
# the point of the extra -'s is to ease parsing: can add hierarchies later.
# e.g., *:i386-*:*:pentium-*:* would handle pentium-100 as well as pentium,
# and i386-486 (486s do have more instructions, you know) as well as i386.
# the idea here is to include ALL useful available information.
exec 2>/dev/null
sys="`uname -s | tr '/:[A-Z]' '..[a-z]'`"
if [ x"$sys" != x ]
then
unamer="`uname -r | tr /: ..`"
unamem="`uname -m | tr /: ..`"
unamev="`uname -v | tr /: ..`"
case "$sys" in
bsd.os)
# in bsd 4.4, uname -v does not have useful info.
# in bsd 4.4, uname -m is arch, not chip.
oper="$sys-$unamer"
arch="$unamem"
syst=""
chip="`sysctl -n hw.model`"
kern=""
;;
freebsd)
# see above about bsd 4.4
oper="$sys-$unamer"
arch="$unamem"
syst=""
chip="`sysctl -n hw.model`" # hopefully
kern=""
;;
netbsd)
# see above about bsd 4.4
oper="$sys-$unamer"
arch="$unamem"
syst=""
chip="`sysctl -n hw.model`" # hopefully
kern=""
;;
linux)
# as in bsd 4.4, uname -v does not have useful info.
oper="$sys-$unamer"
arch="i386" # always correct for now
syst=""
chip="$unamem"
kern=""
;;
aix)
# naturally IBM has to get uname -r and uname -v backwards. dorks.
oper="$sys-$unamev-$unamer"
arch="`arch | tr /: ..`"
syst=""
chip="$unamem"
kern=""
;;
sunos)
oper="$sys-$unamer-$unamev"
arch="`(uname -p || mach) | tr /: ..`"
syst="`arch | tr /: ..`"
chip="$unamem" # this is wrong; is there any way to get the real info?
kern="`arch -k | tr /: ..`"
;;
unix_sv)
oper="$sys-$unamer-$unamev"
arch="`uname -m`"
syst=""
chip="$unamem"
kern=""
;;
*)
oper="$sys-$unamer-$unamev"
arch="`arch | tr /: ..`"
syst=""
chip="$unamem"
kern=""
;;
esac
else
$CC -c trycpp.c
$LD -o trycpp trycpp.o
case `./trycpp` in
nextstep)
oper="nextstep-`hostinfo | sed -n 's/^[ ]*NeXT Mach \([^:]*\):.*$/\1/p'`"
arch="`hostinfo | sed -n 's/^Processor type: \(.*\) (.*)$/\1/p' | tr /: ..`"
syst=""
chip="`hostinfo | sed -n 's/^Processor type: .* (\(.*\))$/\1/p' | tr ' /:' '...'`"
kern=""
;;
*)
oper="unknown"
arch=""
syst=""
chip=""
kern=""
;;
esac
fi
case "$chip" in
Intel.586)
# no, you nitwits, there is no such chip. (NeXTStep)
chip=pentium
;;
i586)
# no, you nitwits, there is no such chip. (Linux)
chip=pentium
;;
esac
echo "$oper-:$arch-:$syst-:$chip-:$kern-" | tr ' [A-Z]' '.[a-z]'