akutz | 9efe9a2 | 2019-05-22 13:46:51 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Cloud-Init Datasource for VMware Guestinfo |
| 4 | # |
| 5 | # Copyright (c) 2019 VMware, Inc. All Rights Reserved. |
| 6 | # |
| 7 | # This product is licensed to you under the Apache 2.0 license (the "License"). |
| 8 | # You may not use this product except in compliance with the Apache 2.0 License. |
| 9 | # |
| 10 | # This product may include a number of subcomponents with separate copyright |
| 11 | # notices and license terms. Your use of these subcomponents is subject to the |
| 12 | # terms and conditions of the subcomponent's license, as noted in the LICENSE |
| 13 | # file. |
| 14 | |
| 15 | # |
akutz | d1f6764 | 2019-05-30 12:33:50 -0500 | [diff] [blame] | 16 | # This file should be installed to /usr/bin/dscheck_VMwareGuestInfo |
akutz | 9efe9a2 | 2019-05-22 13:46:51 -0500 | [diff] [blame] | 17 | # without the ".sh" extension. The extension only exists to make it easier |
| 18 | # to identify the file during development. |
| 19 | # |
| 20 | # This file provides cloud-init's ds-identify program a shell type that |
| 21 | # can be resolved with "type dscheck_VMwareGuestInfo" and used to validate |
| 22 | # where a datasource is installed and useable. |
| 23 | # |
| 24 | # Cloud-init's ds-identify program in /usr/lib/cloud-init includes functions |
| 25 | # to determine whether or not datasources can be used. Because the program |
| 26 | # is a shell script and uses "type dscheck_DATASOURCE_NAME" to determine |
| 27 | # if there is a matching bash type that can answer for the datasource, |
| 28 | # it's possible to respond with an external script. While other datasources |
| 29 | # have functions in ds-identify, the "type" command looks up types both |
| 30 | # in Bash's function table as well as script in the PATH. Therefore the |
| 31 | # ds-identify program, when looking up whether or not the datasource |
| 32 | # VMwareGuestInfo can be used, will defer to this file when it is in the |
| 33 | # PATH and named dscheck_VMwareGuestInfo. |
| 34 | # |
| 35 | |
akutz | cb9e8e4 | 2019-10-23 21:28:16 -0500 | [diff] [blame] | 36 | if [ -n "${VMX_GUESTINFO}" ]; then |
| 37 | if [ -n "${VMX_GUESTINFO_METADATA}" ] || \ |
| 38 | [ -n "${VMX_GUESTINFO_USERDATA}" ] || \ |
| 39 | [ -n "${VMX_GUESTINFO_VENDORDATA}" ]; then |
| 40 | exit 0 |
| 41 | fi |
| 42 | fi |
| 43 | |
yvespp | 8d58dfd | 2019-10-29 20:42:09 +0100 | [diff] [blame] | 44 | if ! command -v vmware-rpctool >/dev/null 2>&1; then |
akutz | 9efe9a2 | 2019-05-22 13:46:51 -0500 | [diff] [blame] | 45 | exit 1 |
| 46 | fi |
| 47 | |
yvespp | 8d58dfd | 2019-10-29 20:42:09 +0100 | [diff] [blame] | 48 | if { vmware-rpctool "info-get guestinfo.metadata" || \ |
| 49 | vmware-rpctool "info-get guestinfo.userdata" || \ |
| 50 | vmware-rpctool "info-get guestinfo.vendordata"; } >/dev/null 2>&1; then |
akutz | 9efe9a2 | 2019-05-22 13:46:51 -0500 | [diff] [blame] | 51 | exit 0 |
| 52 | fi |
| 53 | |
| 54 | exit 1 |