-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdistro
425 lines (410 loc) · 13.9 KB
/
distro
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#!/bin/sh
#
# Observium License Version 1.0
#
# Copyright (c) 2013-2015 Joe Holden, (c) 2015 Mike Stupalov
#
# The intent of this license is to establish the freedom to use, share and contribute to
# the software regulated by this license.
#
# This license applies to any software containing a notice placed by the copyright holder
# saying that it may be distributed under the terms of this license. Such software is herein
# referred to as the Software. This license covers modification and distribution of the
# Software.
#
# Granted Rights
#
# 1. You are granted the non-exclusive rights set forth in this license provided you agree to
# and comply with any and all conditions in this license. Whole or partial distribution of the
# Software, or software items that link with the Software, in any form signifies acceptance of
# this license.
#
# 2. You may copy and distribute the Software in unmodified form provided that the entire package,
# including - but not restricted to - copyright, trademark notices and disclaimers, as released
# by the initial developer of the Software, is distributed.
#
# 3. You may make modifications to the Software and distribute your modifications, in a form that
# is separate from the Software, such as patches. The following restrictions apply to modifications:
#
# a. Modifications must not alter or remove any copyright notices in the Software.
# b. When modifications to the Software are released under this license, a non-exclusive royalty-free
# right is granted to the initial developer of the Software to distribute your modification in
# future versions of the Software provided such versions remain available under these terms in
# addition to any other license(s) of the initial developer.
#
# Limitations of Liability
#
# In no event shall the initial developers or copyright holders be liable for any damages whatsoever,
# including - but not restricted to - lost revenue or profits or other direct, indirect, special,
# incidental or consequential damages, even if they have been advised of the possibility of such damages,
# except to the extent invariable law, if any, provides otherwise.
#
# No Warranty
#
# The Software and this license document are provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# URL: [https://github.com/joeholden/distroscript]
# README: [https://github.com/joeholden/distroscript/blob/master/README.md]
DISTROSCRIPT="1.2"
if [ -z ${DISTROFORMAT} ]; then
DISTROFORMAT="pipe"
fi
if [ -n "${AGENT_LIBDIR}" -o -n "${MK_LIBDIR}" ]; then
DISTROFORMAT="export"
fi
getos() {
OS=`uname -s`
if [ "${OS}" = "SunOS" ]; then
OS="Solaris"
elif [ "${OS}" = "DragonFly" ]; then
OS="DragonFlyBSD"
fi
export OS
return 0
}
getkernel() {
if [ "${OS}" = "FreeBSD" -o "${OS}" = "DragonFlyBSD" ]; then
KERNEL=`uname -i`
elif [ "${OS}" = "OpenBSD" -o "${OS}" = "NetBSD" ]; then
KERNEL=`uname -v`
elif [ "${OS}" = "AIX" ]; then
KERNEL=`oslevel -s`
else
KERNEL=`uname -r`
fi
export KERNEL
return 0
}
getdistro() {
if [ "${OS}" = "Linux" ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=`echo ${NAME} | awk '{print $1}'`
elif [ -x /usr/bin/lsb_release ]; then
DISTRO=`/usr/bin/lsb_release -si 2>/dev/null`
elif [ -f /etc/redhat-release ]; then
DISTRO=`cat /etc/redhat-release | awk '{print $1}'`
elif [ -f /etc/fedora-release ]; then
DISTRO="Fedora"
elif [ -f /etc/debian_version ]; then
if [ -f /etc/mailcleaner/etc/mailcleaner/version.def ]; then
DISTRO="MailCleaner"
else
DISTRO="Debian"
fi
elif [ -f /etc/arch-release ]; then
DISTRO="ArchLinux"
elif [ -f /etc/gentoo-release ]; then
DISTRO="Gentoo"
elif [ -f /etc/SuSE-release -o -f /etc/novell-release -o -f /etc/sles-release ]; then
DISTRO="SuSE"
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "${NAME}" = "openSUSE" ]; then
DISTRO="openSUSE"
fi
fi
elif [ -f /etc/mandriva-release ]; then
DISTRO="Mandriva"
elif [ -f /etc/mandrake-release -o -f /etc/mandakelinux-release ]; then
DISTRO="Mandrake"
elif [ -f /etc/UnitedLinux-release ]; then
DISTRO="UnitedLinux"
elif [ -f /etc/openwrt_version ]; then
DISTRO="OpenWRT"
elif [ -f /etc/slackware-version -o -f /etc/slackware-release ]; then
DISTRO="Slackware"
elif [ -f /etc/annvix-release ]; then
DISTRO="Annvix"
elif [ -f /etc/arklinux-release ]; then
DISTRO="Arklinux"
elif [ -f /etc/aurox-release ]; then
DISTRO="Aurox Linux"
elif [ -f /etc/blackcat-release ]; then
DISTRO="BlackCat"
elif [ -f /etc/cobalt-release ]; then
DISTRO="Cobalt"
elif [ -f /etc/conectiva-release ]; then
DISTRO="Conectiva"
elif [ -f /etc/eos-version ]; then
DISTRO="FreeEOS"
elif [ -f /etc/hlfs-release -o -f /etc/hlfs_version ]; then
DISTRO="HLFS"
elif [ -f /etc/immunix-release ]; then
DISTRO="Immunix"
elif [ -f /knoppix_version ]; then
DISTRO="Knoppix"
elif [ -f /etc/lfs-release -o -f /etc/lfs_version ]; then
DISTRO="Linux-From-Scratch"
elif [ -f /etc/linuxppc-release ]; then
DISTRO="Linux-PPC"
elif [ -f /etc/mageia-release ]; then
DISTRO="Mageia"
elif [ -f /etc/mklinux-release ]; then
DISTRO="MkLinux"
elif [ -f /etc/nld-release ]; then
DISTRO="Novell Linux Desktop"
elif [ -f /etc/pld-release ]; then
DISTRO="PLD"
elif [ -f /etc/rubix-version ]; then
DISTRO="Rubix"
elif [ -f /etc/e-smith-release ]; then
DISTRO="SME Server"
elif [ -f /etc/synoinfo.conf ]; then
DISTRO="Synology"
elif [ -f /etc/tinysofa-release ]; then
DISTRO="Tiny Sofa"
elif [ -f /etc/trustix-release -o -f /etc/trustix-version ]; then
DISTRO="Trustix"
elif [ -f /etc/turbolinux-release ]; then
DISTRO="TurboLinux"
elif [ -f /etc/ultrapenguin-release ]; then
DISTRO="UltraPenguin"
elif [ -f /etc/va-release ]; then
DISTRO="VA-Linux"
elif [ -f /etc/yellowdog-release ]; then
DISTRO="Yellow Dog"
else
DISTRO=
fi
if [ "${DISTRO}" = "Debian GNU/Linux" ]; then
DISTRO="Debian"
elif [ "${DISTRO}" = "Red" -o "${DISTRO}" = "RedHatEnterpriseServer" ]; then
DISTRO="RedHat"
elif [ "${DISTRO}" = "Arch" ]; then
DISTRO="ArchLinux"
fi
elif [ "${OS}" = "FreeBSD" ]; then
if [ -f /etc/platform -a -f /etc/version ]; then
DISTRO="pfSense"
elif [ -f /etc/platform -a -f /etc/prd.name ]; then
DISTRO=`cat /etc/prd.name`
elif [ -f /usr/local/bin/pbreg ]; then
DISTRO="PC-BSD"
elif [ -f /tmp/freenas_config.md5 ]; then
DISTRO="FreeNAS"
else
DISTRO=
fi
elif [ "${OS}" = "Solaris" ]; then
DISTRO=`head -n 1 /etc/release | awk '{print $1}'`
if [ "${DISTRO}" = "Solaris" -o "${DISTRO}" = "Oracle" ]; then
DISTRO=
fi
elif [ "${OS}" = "Darwin" ]; then
case `uname -m` in
AppleTV*)
DISTRO="AppleTV"
;;
iPad*)
DISTRO="iPad"
;;
iPhone*)
DISTRO="iPhone"
;;
iPod*)
DISTRO="iPod"
;;
*)
DISTRO="macOS"
;;
esac
else
DISTRO=
fi
export DISTRO
return 0
}
getarch() {
if [ "${OS}" = "Solaris" ]; then
ARCH=`isainfo -k`
elif [ "${OS}" = "Darwin" ]; then
ARCH=`uname -m`
elif [ "${OS}" = "AIX" ]; then
ARCH=`uname -p`
else
ARCH=`uname -m`
fi
if [ "${ARCH}" = "x86_64" ]; then
ARCH="amd64"
elif [ "${ARCH}" = "i486" -o "${ARCH}" = "i586" -o "${ARCH}" = "i686" ]; then
ARCH="i386"
fi
export ARCH
return 0
}
getversion() {
if [ "${OS}" = "FreeBSD" -o "${OS}" = "DragonFlyBSD" ]; then
if [ "${DISTRO}" = "pfSense" ]; then
VERSION=`cat /etc/version`
elif [ "${DISTRO}" = "PC-BSD" ]; then
VERSION=`pbreg get /PC-BSD/Version`
elif [ -f /etc/prd.version ]; then
VERSION=`cat /etc/prd.version`
elif [ -f /bin/freebsd-version ]; then
VERSION=`/bin/freebsd-version -u`
else
VERSION=`uname -r`
fi
elif [ "${OS}" = "OpenBSD" -o "${OS}" = "NetBSD" ]; then
VERSION=`uname -r`
elif [ "${OS}" = "Linux" ]; then
if [ "${DISTRO}" = "Debian GNU/Linux" ]; then
DISTRO="Debian"
fi
if [ "${DISTRO}" = "OpenWRT" ]; then
VERSION=`cat /etc/openwrt_version`
elif [ "${DISTRO}" = "Slackware" ]; then
VERSION=`cat /etc/slackware-version | cut -d" " -f2`
elif [ -f /etc/os-release ]; then
if [ "${DISTRO}" = "Debian" ]; then
if [ -f /usr/bin/lsb_release ]; then
VERSION=`lsb_release -sr 2>/dev/null`
fi
else
. /etc/os-release
VERSION=${VERSION_ID}
fi
elif [ -f /etc/redhat-release ]; then
VERSION=`cat /etc/redhat-release | sed 's/.*release\ //' | sed 's/\ .*//'`
elif [ -x /usr/bin/lsb_release ]; then
VERSION=`lsb_release -sr 2>/dev/null`
elif [ -f /etc/os-release ]; then
. /etc/os-release
VERSION=${VERSION_ID}
else
VERSION=
fi
elif [ "${OS}" = "Darwin" ]; then
VERSION=`sw_vers -productVersion`
elif [ "${OS}" = "Solaris" ]; then
VERSION=`uname -v`
elif [ "${OS}" = "AIX" ]; then
# ie: 6.1.0.0
VERSION=`oslevel`
else
VERSION=
fi
export VERSION
return 0
}
detectvirt() {
local virt
local type
type=none
case $1 in
[Kk][Vv][Mm]|[Qq][Ee][Mm][Uu]*)
type=kvm
;;
[Vv][Mm][Ww][Aa][Rr][Ee]*)
type=vmware
;;
HVM*domU*)
type=xen:hvm
;;
[Xx][Ee][Nn]*)
type=xen:pv
;;
[Mm][Ii][Cc][Rr][Oo][Ss][Oo][Ff][Tt]|[Vv][Ii][Rr][Tt][Uu][Aa][Ll]*)
type=microsoft
;;
[Bb][Hh][Yy][Vv][Ee]*)
type=bhyve
;;
[Vv][Uu][Ll][Tt][Rr]|[Dd][Rr][Oo][Pp][Ll][Ee][Tt]*)
type=kvm:your-provider-is-a-moron
;;
Standard*PC*Q*ICH*)
type=kvm
;;
*)
type=none
;;
esac
echo $type
}
getvirt() {
if [ "${OS}" = "Linux" ]; then
if [ -f `which dmidecode` ]; then
tmp=`dmidecode -s system-product-name 2>/dev/null`
VIRT=`detectvirt "${tmp}"`
fi
if [ "${VIRT}" = "none" ]; then
if [ -f /usr/bin/systemd-detect-virt ]; then
VIRT=`/usr/bin/systemd-detect-virt`
fi
fi
elif [ "${OS}" = "FreeBSD" -o "${OS}" = "OpenBSD" -o "${OS}" = "NetBSD" ]; then
tmp=`sysctl -n hw.hv_vendor 2>/dev/null`
VIRT=`detectvirt "${tmp}"`
if [ "${VIRT}" = "none" ]; then
tmp=`sysctl -n hw.model 2>/dev/null`
VIRT=`detectvirt "${tmp}"`
fi
if [ "${VIRT}" = "none" ]; then
tmp=`sysctl -n hw.product 2>/dev/null`
VIRT=`detectvirt "${tmp}"`
fi
if [ "${VIRT}" = "none" ]; then
tmp=`sysctl -n hw.product 2>/dev/null`
VIRT=`detectvirt "${tmp}"`
fi
if [ "${VIRT}" = "none" ]; then
tmp=`sysctl -n machdep.dmi.system-vendor 2>/dev/null`
VIRT=`detectvirt "${tmp}"`
fi
if [ "${VIRT}" = "none" ]; then
tmp=`sysctl -n machdep.dmi.system-product 2>/dev/null`
VIRT=`detectvirt "${tmp}"`
fi
tmp=`sysctl -n security.jail.jailed 2>/dev/null`
if [ "${tmp}" = "1" ]; then
if [ "${VIRT}" = "none" ]; then
VIRT=jail
else
VIRT=${VIRT}:jail
fi
fi
else
VIRT=""
fi
export VIRT
return 0
}
getos
getkernel
getarch
getdistro
getversion
getvirt
if [ -z ${DISTROEXEC+x} ]; then
if [ "${AGENT_LIBDIR}" -o "${MK_LIBDIR}" ]; then
echo "<<<distro>>>"
fi
if [ "${DISTROFORMAT}" = "twopipe" ]; then
echo "${OS}||${KERNEL}||${ARCH}||${DISTRO}||${VERSION}||${VIRT}"
elif [ "${DISTROFORMAT}" = "ini" ]; then
echo "[distroscript]"
echo " OS = ${OS}"
echo " KERNEL = ${KERNEL}"
echo " ARCH = ${ARCH}"
echo " DISTRO = ${DISTRO}"
echo " VERSION = ${VERSION}"
echo " VIRT = ${VIRT}"
echo " SCRIPTVER = ${DISTROSCRIPT}"
elif [ "${DISTROFORMAT}" = "export" ]; then
echo "OS=${OS}"
echo "KERNEL=${KERNEL}"
echo "ARCH=${ARCH}"
echo "DISTRO=${DISTRO}"
echo "VERSION=${VERSION}"
echo "VIRT=${VIRT}"
echo "SCRIPTVER=${DISTROSCRIPT}"
elif [ "${DISTROFORMAT}" = "json" ]; then
echo "{\"os\":\"${OS}\",\"kernel\":\"${KERNEL}\",\"arch\":\"${ARCH}\",\"distro\":\"${DISTRO}\",\"version\":\"${VERSION}\",\"virt\":\"${VIRT}\",\"scriptver\":\"${DISTROSCRIPT}\"}"
else
echo "${OS}|${KERNEL}|${ARCH}|${DISTRO}|${VERSION}|${VIRT}"
fi
exit 0
fi