blob: 1d1b53b097de3e7d1b612cb6fd761f760805517e [file] [log] [blame]
Andrew Kutz4f66b8b2018-09-16 18:28:59 -05001#!/bin/sh
2
Ivan Berezovskiy66279972020-10-26 16:48:53 +04003set -e
4
5# Prepare RHEL image for bootstrap on VSPHERE
6
7: "${DOWNLOAD_INSTALL:="true"}"
Ivan Berezovskiy66279972020-10-26 16:48:53 +04008
Ivan Berezovskiy23cb1e42021-05-19 14:01:16 +04009yum -y install open-vm-tools net-tools perl cloud-init
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050010
11# The script to lookup the path to the cloud-init's datasource directory, "sources".
12PY_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.
15CLOUD_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 Berezovskiy66279972020-10-26 16:48:53 +040022if [ "${DOWNLOAD_INSTALL}" = "true" ]; then
23 REPO_URL="${REPO_URL:-https://gerrit.mcp.mirantis.com/plugins/gitiles/kubernetes/vmware-guestinfo/+/refs/heads}"
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050024
Ivan Berezovskiy66279972020-10-26 16:48:53 +040025 # 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 Kutz4f66b8b2018-09-16 18:28:59 -050027
Ivan Berezovskiy66279972020-10-26 16:48:53 +040028 # 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 Kutz4f66b8b2018-09-16 18:28:59 -050031
Ivan Berezovskiy66279972020-10-26 16:48:53 +040032 # 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
36else
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
41fi