]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
cloud-init: Add function to detect if we are running on Azure
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Jun 2019 15:31:35 +0000 (15:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 1 Jul 2019 06:53:58 +0000 (07:53 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/initscripts/system/cloud-init

index 7448ff3b0ce0976b6aa4538d5392270ba4d43bc9..4bd474b0baba785dd26d2c8cac0ae1ab40de519d 100644 (file)
@@ -28,6 +28,22 @@ running_on_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
+}
+
 case "${1}" in
        start)
                # Do nothing if we are not running on AWS EC2
@@ -68,11 +84,19 @@ case "${1}" in
                ;;
 
        status)
+               # Check Amazon
                if running_on_ec2; then
                        echo "This system is running on AWS EC2"
                        exit 0
+
+               # Check Microsoft
+               elif running_on_azure; then
+                       echo "This system is running on Microsoft Azure"
+                       exit 0
+
+               # The rest
                else
-                       echo "This system is NOT running on AWS EC2"
+                       echo "This system is NOT running in the cloud"
                        exit 1
                fi
                ;;