| #!/bin/sh |
| |
| set -e |
| |
| # Prepare VM image for bootstrap on VSPHERE |
| |
| : "${DOWNLOAD_INSTALL:="true"}" |
| |
| PACKAGE_LIST="open-vm-tools net-tools perl cloud-init coreutils vim rsync" |
| |
| # If Debian: |
| if [ ! -e /etc/system-release ]; then |
| apt-get update |
| apt-get install ${PACKAGE_LIST} -y |
| |
| # No need to patch cloud-init datasource, just enable it. |
| mkdir -p /etc/cloud/cloud.cfg.d |
| cat << EOF >> /etc/cloud/cloud.cfg.d/99_mcc.cfg |
| datasource_list: [ VMware ] |
| package_update: false |
| package_upgrade: false |
| apt: |
| preserve_sources_list: true |
| EOF |
| |
| exit 0 |
| fi |
| |
| # If RHEL/Centos: |
| yum -y install ${PACKAGE_LIST} |
| |
| # 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 |