]> 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 2127a58995d576a33dd930b34ed595182f1a0d56..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
@@ -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,21 +803,22 @@ umount_ramdisk() {
        rm -rf "${path_tmpfs}"
 }
 
+# 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 hypervisor UUID starts with ec2
-       if [ -r "/sys/hypervisor/uuid" ]; then
-               uuid=$(</sys/hypervisor/uuid)
-
-               [ "${uuid:0:3}" = "ec2" ] && return 0
-       fi
-
        # 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
 
@@ -822,4 +842,36 @@ running_on_azure() {
        return 1
 }
 
-# End $rc_base/init.d/functions
+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
+}