forked from scotte/nicstat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnicstat.sh
More file actions
executable file
·165 lines (151 loc) · 4.1 KB
/
nicstat.sh
File metadata and controls
executable file
·165 lines (151 loc) · 4.1 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh
# nicstat.sh - Wrapper for multi-architecture nicstat install
#
# Tim Cook, 27 Aug 2012
# Let us see if we can figure out the OS & CPU architecture cheaply
ostype=unknown
osrel=unknown
cputype=unknown
OSTYPE_PATH=/proc/sys/kernel/ostype
if [ -f "/etc/release" ]; then
# Might be Solaris
read f1 f2 f3 rest < /etc/release
case " $f1 $f2 $f3 $rest" in
' Solaris '[0-9]*' '*' X86' )
ostype=Solaris ; osrel=$f2 ; cputype=i386 ;;
' Solaris '[0-9]*' '*' SPARC' )
ostype=Solaris ; osrel=$f2 ; cputype=sparc ;;
' '[A-Z]*' Solaris '[0-9]*' '*' X86' )
ostype=Solaris ; osrel=$f3 ; cputype=i386 ;;
' '[A-Z]*' Solaris '[0-9]*' '*' SPARC' )
ostype=Solaris ; osrel=$f3 ; cputype=sparc ;;
' '[A-Z]*' Solaris '[0-9]*.[0-9]*' X86' )
ostype=Solaris ; rel=$f3 ; cputype=i386 ;;
' '[A-Z]*' Solaris '[0-9]*.[0-9]*' SPARC' )
ostype=Solaris ; rel=$f3 ; cputype=sparc ;;
*' Solaris '* )
ostype=Solaris
cpu=`uname -p`
case "$cpu" in
'i386' | 'sparc' ) cputype=$cpu ;;
esac
rel=`uname -r`
;;
esac
case "$rel" in
5.8 ) osrel=8 ;;
5.9 ) osrel=9 ;;
5.10 ) osrel=10 ;;
# NOTE: Treat Solaris releases > 11 as if they were 11
5.1[1-9] | 1[1-9].* ) osrel=11 ;;
esac
elif [ -f "$OSTYPE_PATH" -a ! -s "$OSTYPE_PATH" ]; then
read f1 rest < "$OSTYPE_PATH"
case " $f1 " in
' Linux ' ) ostype=Linux ; osclass=Linux ;;
esac
# Let's see if we can refine that
# NOTE: I would want to bunch popular variants that are similar together
# (e.g. Ubuntu and Debian; RHEL & CentOS & OEL)
if [ -f /etc/redhat-release ]; then
ostype=RedHat
read f1 f2 f3 f4 f5 f6 f7 f8 f9 rest < /etc/redhat-release
if [ "$f6" = 'release' ]; then
osrel=$f7
elif [ "$f5" = 'release' ]; then
osrel=$f6
elif [ "$f7" = 'release' ]; then
osrel=$f7
elif [ -f /proc/sys/kernel/osrelease ]; then
read osrel < /proc/sys/kernel/osrelease
fi
case "$osrel" in
*'.'* )
osrel=${osrel%%.*} ;;
esac
elif [ -f /etc/SuSE-release ]; then
ostype=SuSE
while read f1 f2 f3 rest
do
if [ "$f1 $f2" = 'VERSION =' ]; then
osrel=$f3
fi
done < /etc/SuSE-release
elif [ -f /etc/lsb-release ]; then
save_IFS=$IFS
IFS='= '
while read name value
do
case "$name" in
'DISTRIB_ID' ) ostype=$value ;;
'DISTRIB_RELEASE' ) osrel=${value%%.*} ;;
esac
done < /etc/lsb-release
IFS=$save_IFS
fi
if [ -z "$ostype" -a -f "/etc/issue" ]; then
read f1 f2 f3 f4 f5 f6 rest < /etc/issue
case "$f1 $f2 $f3 $f4 $f5 $f6 $rest " in
'Ubuntu [1-9].'* ) ostype=Ubuntu ; osrel=${f2%%.*} ;;
'Ubuntu [1-9][0-9].'* ) ostype=Ubuntu ; osrel=${f2%%.*} ;;
'Red Hat Enterprise Server release '[1-9]* )
ostype=RedHat ; osrel=${f6%%.*} ;;
'Fedora release '[0-9]* ) ostype=Fedora ; osrel=${f3%%.*} ;;
'Fedora Core release '[0-9]* ) ostype=Fedora ; osrel=${f4%%.*} ;;
esac
fi
fi
if [ "X$ostype" = "Xunknown" ]; then
os=`uname -sr`
case "$os" in
'SunOS 5.'* ) ostype=Solaris ;;
'Linux '* ) ostype=Linux ; osclass=Linux ;;
esac
fi
if [ "X$cputype" = "Xunknown" ]; then
cpu=`uname -mp`
case "$cpu" in
'i'[3456]'86 '* ) cputype=i386 ;;
'i86pc '* ) cputype=i386 ;;
*' sparc' ) cputype=sparc ;;
'x86_64 '* ) cputype=i386 ;;
esac
fi
if [ "$ostype,$osrel,$kernrel" = "Linux,," ]; then
# Would be useful to at least get the Linux kernel release
rel=`uname -r`
case "$rel" in
2.4.* ) kernrel=2.4 ;;
2.6.* ) kernrel=2.6 ;;
esac
fi
#------------------------------------------------------------------------
# MAIN
# echo "os = [$ostype]"
# echo "cpu = [$cputype]"
# echo "release = [$osrel]"
# exit 0
SCRIPT_DIR=`dirname "$0"`
BIN_DIR=$SCRIPT_DIR
BIN_NAME=.nicstat
case "$#,$1" in
'1,--bin-name' )
echo "${BIN_NAME}.${ostype}_${osrel}_${cputype}"
exit 0
;;
esac
for s in "${ostype}_${osrel}_${cputype}" \
"${osclass}_${kernrel}_${cputype}" \
"${ostype}_${cputype}" \
"${osclass}_${cputype}"
do
if [ -x "$BIN_DIR/$BIN_NAME.$s" ]; then
BIN="$BIN_DIR/$BIN_NAME.$s"
break
fi
done
if [ "X$BIN" = "X" ]; then
echo "$0: can not find platform executable" >& 2
exit 1
fi
exec "$BIN" "$@"