...
 
Commits (2)
......@@ -57,11 +57,9 @@ Notes:
* On FreeBSD and OpenBSD, where it is a generic install, the distro field is left blank and the distrover is populated with the kernel name.
* **x86_64** is normalised to **amd64**, **ix86** is normalised to **i386**.
* Values for **VIRT** and **CONT** use the naming convention from **[systemd-detect-virt](https://www.freedesktop.org/software/systemd/man/systemd-detect-virt.html "systemd-detect-virt")** with the exception of FreeBSD jails.
* Where we can identify the container, it is presented colon seperated (in the case of pipe), e.g **kvm:jail**.
* If the DMI strings or virtual cpu names have been changed, or running on a particularly old OS there is a likely chance that the detected virtualisation will be wrong.
* At present, the virt detection is pretty limited (for example under Linux, if the system doesn't not have systemd and it's running under KVM, it will still return QEMU)
Output:
* Default output is pipe deliminated: `OS|KERNEL|ARCH|DISTRO|VERSION|VIRT[:CONT]`
* Default output is pipe deliminated: `OS|KERNEL|ARCH|DISTRO|VERSION|VIRT|CONT`
* Possible output options are: *pipe*, *twopipe*, *ini*, *export*, *json*
* Set `$DISTROFORMAT` environment variable to change output. Example: `DISTROFORMAT=export ./distro`
......@@ -47,7 +47,7 @@
# URL: [https://gitlab.com/joewholden/distroscript]
# README: [https://gitlab.com/joewholden/distroscript/blob/master/README.md]
DISTROSCRIPT="1.3.1"
DISTROSCRIPT="1.3.2"
if [ -z ${DISTROFORMAT} ]; then
DISTROFORMAT="pipe"
......@@ -308,10 +308,10 @@ detectvirt() {
type=vmware
;;
HVM*domU*)
type=xen:hvm
type=xenhvm
;;
[Xx][Ee][Nn]*)
type=xen:pv
type=xenpv
;;
[Mm][Ii][Cc][Rr][Oo][Ss][Oo][Ff][Tt]|[Vv][Ii][Rr][Tt][Uu][Aa][Ll]*)
type=microsoft
......@@ -354,8 +354,20 @@ detectcont() {
getcont() {
CONT="none"
if [ "${OS}" = "Linux" ]; then
if [ -f /usr/bin/systemd-detect-virt ]; then
CONT=`/usr/bin/systemd-detect-virt -c`
if [ "${CONT}" = "none" ]; then
if [ -f /usr/bin/systemd-detect-virt ]; then
CONT=`/usr/bin/systemd-detect-virt -c`
fi
fi
if [ "${CONT}" = "none" ]; then
if [ -f /.dockerenv ]; then
CONT=docker
fi
fi
if [ "${CONT}" = "none" ]; then
if grep -qa docker /proc/1/cgroup; then
CONT=docker
fi
fi
elif [ "${OS}" = "FreeBSD" -o "${OS}" = "OpenBSD" -o "${OS}" = "NetBSD" ]; then
if [ "${OS}" = "FreeBSD" ]; then
......@@ -367,6 +379,9 @@ getcont() {
else
CONT=""
fi
if [ "${CONT}" = "none" ]; then
CONT=""
fi
export CONT
return 0
}
......@@ -428,6 +443,9 @@ getvirt() {
else
VIRT=""
fi
if [ "${VIRT}" = "none" ]; then
VIRT=""
fi
export VIRT
return 0
}
......@@ -445,11 +463,7 @@ if [ -z ${DISTROEXEC+x} ]; then
echo "<<<distro>>>"
fi
if [ "${DISTROFORMAT}" = "twopipe" ]; then
if [ "${CONT}" = "none" ]; then
echo "${OS}||${KERNEL}||${ARCH}||${DISTRO}||${VERSION}||${VIRT}"
else
echo "${OS}||${KERNEL}||${ARCH}||${DISTRO}||${VERSION}||${VIRT}:${CONT}"
fi
echo "${OS}||${KERNEL}||${ARCH}||${DISTRO}||${VERSION}||${VIRT}||${CONT}"
elif [ "${DISTROFORMAT}" = "ini" ]; then
echo "[distroscript]"
echo " OS = ${OS}"
......@@ -472,11 +486,7 @@ if [ -z ${DISTROEXEC+x} ]; then
elif [ "${DISTROFORMAT}" = "json" ]; then
echo "{\"os\":\"${OS}\",\"kernel\":\"${KERNEL}\",\"arch\":\"${ARCH}\",\"distro\":\"${DISTRO}\",\"version\":\"${VERSION}\",\"virt\":\"${VIRT}\",\"cont\":\"${CONT}\",\"scriptver\":\"${DISTROSCRIPT}\"}"
else
if [ "${CONT}" = "none" ]; then
echo "${OS}|${KERNEL}|${ARCH}|${DISTRO}|${VERSION}|${VIRT}"
else
echo "${OS}|${KERNEL}|${ARCH}|${DISTRO}|${VERSION}|${VIRT}:${CONT}"
fi
echo "${OS}|${KERNEL}|${ARCH}|${DISTRO}|${VERSION}|${VIRT}|${CONT}"
fi
exit 0
fi