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 | |
Ivan Berezovskiy | 9bc7485 | 2023-01-23 19:51:07 +0500 | [diff] [blame] | 5 | # Prepare VM image for bootstrap on VSPHERE |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 6 | |
| 7 | : "${DOWNLOAD_INSTALL:="true"}" |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 8 | |
Ivan Berezovskiy | 9bc7485 | 2023-01-23 19:51:07 +0500 | [diff] [blame] | 9 | PACKAGE_LIST="open-vm-tools net-tools perl cloud-init coreutils vim rsync" |
| 10 | |
| 11 | # If Debian: |
| 12 | if [ ! -e /etc/system-release ]; then |
| 13 | apt-get update |
| 14 | apt-get install ${PACKAGE_LIST} -y |
| 15 | |
| 16 | # No need to patch cloud-init datasource, just enable it. |
| 17 | mkdir -p /etc/cloud/cloud.cfg.d |
| 18 | cat << EOF >> /etc/cloud/cloud.cfg.d/99_mcc.cfg |
| 19 | datasource_list: [ VMware ] |
| 20 | package_update: false |
| 21 | package_upgrade: false |
| 22 | apt: |
| 23 | preserve_sources_list: true |
| 24 | EOF |
| 25 | |
| 26 | exit 0 |
| 27 | fi |
| 28 | |
| 29 | # If RHEL/Centos: |
| 30 | yum -y install ${PACKAGE_LIST} |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 31 | |
| 32 | # The script to lookup the path to the cloud-init's datasource directory, "sources". |
| 33 | PY_SCRIPT='import os; from cloudinit import sources; print(os.path.dirname(sources.__file__));' |
| 34 | |
| 35 | # Get the path to the cloud-init installation's datasource directory. |
| 36 | CLOUD_INIT_SOURCES=$(python -c ''"${PY_SCRIPT}"'' 2>/dev/null || \ |
| 37 | python3 -c ''"${PY_SCRIPT}"'' 2>/dev/null) || |
| 38 | { exit_code="${?}"; echo "failed to find python runtime" 1>&2; exit "${exit_code}"; } |
| 39 | |
| 40 | # If no "sources" directory was located then it's likely cloud-init is not installed. |
| 41 | [ -z "${CLOUD_INIT_SOURCES}" ] && echo "cloud-init not found" 1>&2 && exit 1 |
| 42 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 43 | if [ "${DOWNLOAD_INSTALL}" = "true" ]; then |
| 44 | 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] | 45 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 46 | # The git reference to use. This can be a branch or tag name as well as a commit ID. |
| 47 | GIT_REF="${GIT_REF:-mcp}" |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 48 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 49 | # Download the cloud init datasource into the cloud-init's "sources" directory. |
| 50 | curl "${REPO_URL}/${GIT_REF}/DataSourceVMwareGuestInfo.py?format=TEXT" | base64 -d \ |
| 51 | > "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 52 | |
Ivan Berezovskiy | 6627997 | 2020-10-26 16:48:53 +0400 | [diff] [blame] | 53 | # Add the configuration file that tells cloud-init what datasource to use. |
| 54 | mkdir -p /etc/cloud/cloud.cfg.d |
| 55 | curl "${REPO_URL}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg?format=TEXT" | base64 -d \ |
| 56 | > /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg |
| 57 | else |
| 58 | BASEDIR=$(dirname "$0") |
| 59 | cp "${BASEDIR}/DataSourceVMwareGuestInfo.py" "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" |
| 60 | mkdir -p /etc/cloud/cloud.cfg.d |
| 61 | cp "${BASEDIR}/99-DataSourceVMwareGuestInfo.cfg" /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg |
| 62 | fi |