Skip to content

Commit

Permalink
moved out base system scripts from main repository to always-required…
Browse files Browse the repository at this point in the history
… extension
  • Loading branch information
tomaszklim committed Nov 20, 2017
0 parents commit e12225c
Show file tree
Hide file tree
Showing 6 changed files with 569 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2008-2017 Tomasz Klim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sf-system extension base system detection and configuration scripts
(to make merging of the main repository easier).
67 changes: 67 additions & 0 deletions detect-hardware-type.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

if [ -f /proc/1/environ ] && [ "`cat /proc/1/environ |grep lxc`" != "" ]; then
echo "lxc"
elif [ -f /run/systemd/container ] && [ "`cat /run/systemd/container |grep lxc`" != "" ]; then
echo "lxc"

elif [ -f /run/systemd/container ] && [ "`cat /run/systemd/container |grep systemd-nspawn`" != "" ]; then
echo "container" # nspawn
elif [ -d /proc/vz ] && [ ! -f /proc/vz/version ]; then
echo "container" # openvz
elif [ -f /proc/self/status ] && [ "`cat /proc/self/status |grep -i vxid`" != "" ]; then
echo "container" # linux-vserver

elif [ -f /sys/devices/virtual/dmi/id/product_name ] && [ "`cat /sys/devices/virtual/dmi/id/product_name |grep VirtualBox`" != "" ]; then
echo "guest" # virtualbox
elif [ -d /sys/class/dmi/id ] && [ "`cat /sys/class/dmi/id/*_vendor |grep innotek`" != "" ]; then
echo "guest" # virtualbox
elif [ -f /proc/scsi/scsi ] && [ "`cat /proc/scsi/scsi |grep -i \"VBOX HARDDISK\"`" != "" ]; then
echo "guest" # virtualbox

elif [ -f /proc/scsi/scsi ] && [ "`cat /proc/scsi/scsi |grep -i vmware`" != "" ]; then
echo "guest" # vmware
elif [ -d /sys/class/dmi/id ] && [ "`cat /sys/class/dmi/id/*_vendor |egrep \"(VMware|VMW)\"`" != "" ]; then
echo "guest" # vmware

elif [ -x /usr/bin/lspci ] && [ "`/usr/bin/lspci |grep Hyper-V`" != "" ]; then
echo "guest" # ms hyper-v
elif [ -d /sys/class/dmi/id ] && [ "`cat /sys/class/dmi/id/*_vendor |grep \"Microsoft Corporation\"`" != "" ]; then
echo "guest" # ms virtualpc or hyper-v

elif [ -f /proc/cpuinfo ] && [ "`cat /proc/cpuinfo |grep \"QEMU Virtual CPU\"`" != "" ]; then
echo "guest" # kvm/qemu
elif [ -f /proc/scsi/scsi ] && [ "`cat /proc/scsi/scsi |grep -i QEMU`" != "" ]; then
echo "guest" # kvm/qemu
elif [ -d /sys/class/dmi/id ] && [ "`cat /sys/class/dmi/id/*_vendor |grep QEMU`" != "" ]; then
echo "guest" # kvm/qemu
elif [ -d /sys/class/dmi/id ] && [ "`cat /sys/class/dmi/id/*_vendor |grep Google`" != "" ]; then
echo "guest" # kvm/qemu
elif [ -d /dev/disk/by-id ] && [ "`ls /dev/disk/by-id/ata-* 2>/dev/null |grep QEMU_HARDDISK`" != "" ]; then
echo "guest" # kvm/qemu

elif [ -d /sys/class/dmi/id ] && [ "`cat /sys/class/dmi/id/*_vendor |grep Xen`" != "" ]; then
echo "guest" # xen
elif [ -f /proc/xen/capabilities ]; then
echo "guest" # xen
elif [ -f /sys/hypervisor/type ] && [ "`cat /sys/hypervisor/type |grep -i xen`" != "" ]; then
echo "guest" # xen

elif [ -d /sys/class/dmi/id ] && [ "`cat /sys/class/dmi/id/*_vendor |grep Bochs`" != "" ]; then
echo "guest" # bochs
elif [ -f /proc/cpuinfo ] && [ "`cat /proc/cpuinfo |grep \"User Mode Linux\"`" != "" ]; then
echo "guest" # uml

elif [ "`dmesg |grep VirtualBox`" != "" ]; then
echo "guest" # virtualbox
elif [ "`dmesg |grep VBOX`" != "" ]; then
echo "guest" # virtualbox
elif [ "`dmesg |grep VMware`" != "" ]; then
echo "guest" # vmware
elif [ "`dmesg |grep Hyper-V`" != "" ]; then
echo "guest" # ms hyper-v
elif [ "`dmesg |grep QEMU`" != "" ]; then
echo "guest" # kvm/qemu
else
echo "physical"
fi
235 changes: 235 additions & 0 deletions detect-system-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
#!/bin/sh

detect_os_type()
{
if [ -f /etc/debian_version ] || [ -f /etc/devuan_version ]; then
echo "debian"
elif [ -f /etc/redhat-release ]; then
echo "redhat"
elif [ -f /etc/SuSE-release ]; then
echo "suse"
elif [ -f /etc/freebsd-update.conf ]; then
echo "freebsd"
elif [ -x /netbsd ]; then
echo "netbsd"
elif [ -f /bsd ] && [ -f /bsd.rd ]; then
echo "openbsd"
else
echo "generic"
fi
}

detect_debian_raw_version()
{
DATA=`cat /etc/debian_version`
case "$DATA" in
4.0)
echo "debian-etch"
;;
5.0 | 5.0.? | 5.0.10)
echo "debian-lenny"
;;
6.0 | 6.0.? | 6.0.10)
echo "debian-squeeze"
;;
7.?)
echo "debian-wheezy"
;;
8.?)
echo "debian-jessie"
;;
9.?)
echo "debian-stretch"
;;
*)
echo "debian-generic"
;;
esac
}

detect_debian_version()
{
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
if [ "$DISTRIB_ID" = "Ubuntu" ] && [ "$DISTRIB_CODENAME" != "" ]; then
if [ -f /var/lib/zentyal/latestversion ]; then
VER=`cat /var/lib/zentyal/latestversion |sed s/\\\.//g |cut -c1-2`
echo "ubuntu-$DISTRIB_CODENAME-zentyal$VER"
else
echo "ubuntu-$DISTRIB_CODENAME"
fi
fi

elif [ -f /etc/rpi-issue ]; then
DATA=`cat /etc/debian_version`
case "$DATA" in
8.?)
echo "raspbian-jessie"
;;
*)
;;
esac

elif [ -f /etc/devuan_version ]; then
DATA=`cat /etc/devuan_version`
case "$DATA" in
jessie)
echo "devuan-jessie"
;;
*)
;;
esac

elif [ -f /etc/pve/.version ]; then
echo "`detect_debian_raw_version`-pve"
elif [ -d /usr/local/directadmin ]; then
echo "`detect_debian_raw_version`-directadmin"
elif [ -f /etc/openattic/settings.py ]; then
echo "`detect_debian_raw_version`-openattic"
else
echo "`detect_debian_raw_version`"
fi
}

detect_redhat_version()
{
if [ -f /etc/oracle-release ]; then
DATA=`cat /etc/oracle-release`
case "$DATA" in
"Oracle Linux Server release 6.2" | "Oracle Linux Server release 6.3" | "Oracle Linux Server release 6.6")
echo "redhat-oracle6"
;;
"Oracle Linux Server release 7.1")
echo "redhat-oracle7"
;;
*)
;;
esac

elif [ -f /etc/elastix.conf ]; then
DATA=`cat /etc/redhat-release`
case "$DATA" in
"CentOS release 5.10 (Final)" | "CentOS release 5.11 (Final)")
echo "redhat-centos5-elastix"
;;
"CentOS release 6.4 (Final)")
echo "redhat-centos6-elastix"
;;
"CentOS Linux release 7.0.1406 (Core) " | "CentOS Linux release 7.1.1503 (Core) ")
echo "redhat-centos7-elastix"
;;
*)
;;
esac

elif [ -d /usr/local/cpanel ]; then
DATA=`cat /etc/redhat-release`
case "$DATA" in
"CentOS release 6.6 (Final)")
echo "redhat-centos6-cpanel"
;;
*)
;;
esac

else
DATA=`cat /etc/redhat-release`
case "$DATA" in
"CentOS release 5.11 (Final)")
echo "redhat-centos5"
;;
"CentOS release 6.6 (Final)")
echo "redhat-centos6"
;;
"CentOS Linux release 7.1.1503 (Core) ")
echo "redhat-centos7"
;;
"Red Hat Enterprise Linux Server release 5.5 (Tikanga)")
echo "redhat-rhel5"
;;
"Red Hat Enterprise Linux Server release 6.6 (Santiago)")
echo "redhat-rhel6"
;;
"Red Hat Enterprise Linux Server release 7.1 (Maipo)")
echo "redhat-rhel7"
;;
*)
;;
esac
fi
}

detect_suse_version()
{
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "suse-`echo $VERSION_ID |cut -d. -f 1`"
else
echo "suse-legacy"
fi
}

detect_netbsd_version()
{
DATA=`uname -r`
case "$DATA" in
"6.1.5")
echo "netbsd-6"
;;
*)
;;
esac
}

detect_openbsd_version()
{
VER=`uname -r |sed s/\\\.//g`
echo "openbsd-$VER"
}

detect_freebsd_version()
{
DATA=`uname -r`
case "$DATA" in
"9.3-RELEASE")
echo "freebsd-9"
;;
"10.1-RELEASE")
echo "freebsd-10"
;;
*)
;;
esac
}


TYPE="`detect_os_type`"

if [ "$1" = "-type" ]; then
echo $TYPE
else
case "$TYPE" in
debian)
echo "`detect_debian_version`"
;;
redhat)
echo "`detect_redhat_version`"
;;
suse)
echo "`detect_suse_version`"
;;
netbsd)
echo "`detect_netbsd_version`"
;;
openbsd)
echo "`detect_openbsd_version`"
;;
freebsd)
echo "`detect_freebsd_version`"
;;
*)
exit 1
;;
esac
fi

Loading

0 comments on commit e12225c

Please sign in to comment.