blob: e226b9fc9d2b1936e67d219978ee8ab33b8a0d60 [file] [log] [blame]
akutz9efe9a22019-05-22 13:46:51 -05001#!/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#
akutzd1f67642019-05-30 12:33:50 -050016# This file should be installed to /usr/bin/dscheck_VMwareGuestInfo
akutz9efe9a22019-05-22 13:46:51 -050017# 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
akutzcb9e8e42019-10-23 21:28:16 -050036if [ -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
42fi
43
yvespp8d58dfd2019-10-29 20:42:09 +010044if ! command -v vmware-rpctool >/dev/null 2>&1; then
akutz9efe9a22019-05-22 13:46:51 -050045 exit 1
46fi
47
yvespp8d58dfd2019-10-29 20:42:09 +010048if { 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
akutz9efe9a22019-05-22 13:46:51 -050051 exit 0
52fi
53
54exit 1