Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 3 | set -e |
| 4 | |
| 5 | # Prepare RHEL image for bootstrap on VSPHERE |
| 6 | |
| 7 | : "${DOWNLOAD_INSTALL:="true"}" |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 8 | |
Ivan Berezovskiy | 23cb1e4 | 2021-05-19 14:01:16 +0400 | [diff] [blame^] | 9 | yum -y install open-vm-tools net-tools perl cloud-init |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 10 | |
| 11 | # The script to lookup the path to the cloud-init's datasource directory, "sources". |
| 12 | PY_SCRIPT='import os; from cloudinit import sources; print(os.path.dirname(sources.__file__));' |
| 13 | |
| 14 | # Get the path to the cloud-init installation's datasource directory. |
| 15 | CLOUD_INIT_SOURCES=$(python -c ''"${PY_SCRIPT}"'' 2>/dev/null || \ |
| 16 | python3 -c ''"${PY_SCRIPT}"'' 2>/dev/null) || |
| 17 | { exit_code="${?}"; echo "failed to find python runtime" 1>&2; exit "${exit_code}"; } |
| 18 | |
| 19 | # If no "sources" directory was located then it's likely cloud-init is not installed. |
| 20 | [ -z "${CLOUD_INIT_SOURCES}" ] && echo "cloud-init not found" 1>&2 && exit 1 |
| 21 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 22 | if [ "${DOWNLOAD_INSTALL}" = "true" ]; then |
| 23 | REPO_URL="${REPO_URL:-https://gerrit.mcp.mirantis.com/plugins/gitiles/kubernetes/vmware-guestinfo/+/refs/heads}" |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 24 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 25 | # The git reference to use. This can be a branch or tag name as well as a commit ID. |
| 26 | GIT_REF="${GIT_REF:-mcp}" |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 27 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 28 | # Download the cloud init datasource into the cloud-init's "sources" directory. |
| 29 | curl "${REPO_URL}/${GIT_REF}/DataSourceVMwareGuestInfo.py?format=TEXT" | base64 -d \ |
| 30 | > "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 31 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 32 | # Add the configuration file that tells cloud-init what datasource to use. |
| 33 | mkdir -p /etc/cloud/cloud.cfg.d |
| 34 | curl "${REPO_URL}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg?format=TEXT" | base64 -d \ |
| 35 | > /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg |
| 36 | else |
| 37 | BASEDIR=$(dirname "$0") |
| 38 | cp "${BASEDIR}/DataSourceVMwareGuestInfo.py" "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" |
| 39 | mkdir -p /etc/cloud/cloud.cfg.d |
| 40 | cp "${BASEDIR}/99-DataSourceVMwareGuestInfo.cfg" /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg |
| 41 | fi |