]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blobdiff - src/initscripts/system/functions
Merge branch 'master' into next
[people/mfischer/ipfire-2.x.git] / src / initscripts / system / functions
index c00f65922c97450e74aae3cc3f0c28f9c36f2251..6f53a941badaac4c656e7240f9088023f9a261a9 100644 (file)
@@ -1,17 +1,23 @@
 #!/bin/sh
-########################################################################
-# Begin $rc_base/init.d/functions
-#
-# Description : Run Level Control Functions
-#
-# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
-#
-# Version     : 00.00
-#
-# Notes       : With code based on Matthias Benkmann's simpleinit-msb
-#              http://winterdrache.de/linux/newboot/index.html
-#
-########################################################################
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007-2022  IPFire Team  <info@ipfire.org>                     #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 ## Environmental setup
 # Setup default values for environment
@@ -153,7 +159,7 @@ print_error_msg()
        boot_mesg -n "If you're able to track this"
        boot_mesg -n " error down to a bug in one of the files provided by"
        boot_mesg -n " ipfire, please be so kind to inform us at"
-       boot_mesg " info@ipfire.org.\n"
+       boot_mesg " https://bugzilla.ipfire.org.\n"
        boot_mesg_flush
        boot_mesg -n "Press Enter to continue or wait a minute..." ${INFO}
        boot_mesg "" ${NORMAL}
@@ -436,6 +442,7 @@ getpids()
 #*******************************************************************************
 loadproc()
 {
+       local background=""
        local pidfile=""
        local forcestart=""
        local nicelevel=""
@@ -448,6 +455,10 @@ loadproc()
   while true
        do
                case "${1}" in
+                       -b)
+                               background="1"
+                               shift 1
+                               ;;
                        -f)
                                forcestart="1"
                                shift 1
@@ -506,8 +517,16 @@ loadproc()
                cmd="nice -n "${nicelevel}" ${cmd}"
        fi
 
-       ${cmd}
-       evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
+       if [ -n "${background}" ]; then
+               (
+                       ${cmd} &>/dev/null
+               ) &
+               evaluate_retval
+       else
+               ${cmd}
+               evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
+       fi
+
        return 0
 }
 
@@ -784,4 +803,75 @@ umount_ramdisk() {
        rm -rf "${path_tmpfs}"
 }
 
-# End $rc_base/init.d/functions
+# Returns true when this system running in a virtual environment
+running_on_hypervisor() {
+       grep -qE "^flags\s+:.*hypervisor" /proc/cpuinfo
+}
+
+# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
+running_on_ec2() {
+       local uuid
+
+       # Check if the DMI product UUID starts with EC2
+       if [ -r "/sys/devices/virtual/dmi/id/product_uuid" ]; then
+               uuid=$(</sys/devices/virtual/dmi/id/product_uuid)
+
+               # Convert the UUID as uppercase
+               uuid="${uuid^^}"
+
+               [ "${uuid:0:3}" = "EC2" ] && return 0
+       fi
+
+       # We are not running on AWS EC2
+       return 1
+}
+
+running_on_azure() {
+       # Check if the vendor is Microsoft
+       if [ -r "/sys/devices/virtual/dmi/id/sys_vendor" ] && \
+                       [ "$(</sys/devices/virtual/dmi/id/sys_vendor)" = "Microsoft Corporation" ]; then
+               # Check if this product is a "Virtual Machine"
+               if [ -r "/sys/devices/virtual/dmi/id/product_name" ] && \
+                               [ "$(</sys/devices/virtual/dmi/id/product_name)" = "Virtual Machine" ]; then
+                       # Yes, we are running on Azure
+                       return 0
+               fi
+       fi
+
+       # We are not running on Azure
+       return 1
+}
+
+running_on_exoscale() {
+       if [ -r "/sys/devices/virtual/dmi/id/sys_vendor" ]; then
+               local sys_vendor="$(</sys/devices/virtual/dmi/id/sys_vendor)"
+
+               [ "${sys_vendor}" = "Exoscale" ] && return 0
+       fi
+
+       # We are not running on Exoscale
+       return 1
+}
+
+running_on_gcp() {
+       # Check if the BIOS vendor is "Google"
+       if [ -r "/sys/devices/virtual/dmi/id/bios_vendor" ]; then
+               local bios_vendor="$(</sys/devices/virtual/dmi/id/bios_vendor)"
+
+               [ "${bios_vendor}" = "Google" ] && return 0
+       fi
+
+       # We are not running on GCP
+       return 1
+}
+
+running_on_oci() {
+       if [ -r "/sys/devices/virtual/dmi/id/chassis_asset_tag" ]; then
+               local asset_tag="$(</sys/devices/virtual/dmi/id/chassis_asset_tag)"
+
+               [ "${asset_tag}" = "OracleCloud.com" ] && return 0
+       fi
+
+       # We are not running on OCI
+       return 1
+}