| #!/bin/sh | 
 |  | 
 | set -e | 
 |  | 
 | # Prepare RHEL image for bootstrap on VSPHERE | 
 |  | 
 | : "${DOWNLOAD_INSTALL:="true"}" | 
 |  | 
 | yum -y install open-vm-tools cloud-init | 
 |  | 
 | # The script to lookup the path to the cloud-init's datasource directory, "sources". | 
 | PY_SCRIPT='import os; from cloudinit import sources; print(os.path.dirname(sources.__file__));' | 
 |  | 
 | # Get the path to the cloud-init installation's datasource directory. | 
 | CLOUD_INIT_SOURCES=$(python -c ''"${PY_SCRIPT}"'' 2>/dev/null || \ | 
 |   python3 -c ''"${PY_SCRIPT}"'' 2>/dev/null) || | 
 |   { exit_code="${?}"; echo "failed to find python runtime" 1>&2; exit "${exit_code}"; } | 
 |  | 
 | # If no "sources" directory was located then it's likely cloud-init is not installed. | 
 | [ -z "${CLOUD_INIT_SOURCES}" ] && echo "cloud-init not found" 1>&2 && exit 1 | 
 |  | 
 | if [ "${DOWNLOAD_INSTALL}" = "true" ]; then | 
 |     REPO_URL="${REPO_URL:-https://gerrit.mcp.mirantis.com/plugins/gitiles/kubernetes/vmware-guestinfo/+/refs/heads}" | 
 |  | 
 |     # The git reference to use. This can be a branch or tag name as well as a commit ID. | 
 |     GIT_REF="${GIT_REF:-mcp}" | 
 |  | 
 |     # Download the cloud init datasource into the cloud-init's "sources" directory. | 
 |     curl "${REPO_URL}/${GIT_REF}/DataSourceVMwareGuestInfo.py?format=TEXT" | base64 -d \ | 
 |       > "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" | 
 |  | 
 |     # Add the configuration file that tells cloud-init what datasource to use. | 
 |     mkdir -p /etc/cloud/cloud.cfg.d | 
 |     curl "${REPO_URL}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg?format=TEXT" | base64 -d \ | 
 |       > /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg | 
 | else | 
 |     BASEDIR=$(dirname "$0") | 
 |     cp "${BASEDIR}/DataSourceVMwareGuestInfo.py" "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" | 
 |     mkdir -p /etc/cloud/cloud.cfg.d | 
 |     cp "${BASEDIR}/99-DataSourceVMwareGuestInfo.cfg" /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg | 
 | fi |