blob: 933e6802b25ddddebc91b78ccbf6339b0595406c [file] [log] [blame]
Andrew Kutz4f66b8b2018-09-16 18:28:59 -05001#!/bin/sh
2
Ivan Berezovskiy66279972020-10-26 16:48:53 +04003set -e
4
Ivan Berezovskiy9bc74852023-01-23 19:51:07 +05005# Prepare VM image for bootstrap on VSPHERE
Ivan Berezovskiy66279972020-10-26 16:48:53 +04006
7: "${DOWNLOAD_INSTALL:="true"}"
Ivan Berezovskiy66279972020-10-26 16:48:53 +04008
Ivan Berezovskiy9bc74852023-01-23 19:51:07 +05009PACKAGE_LIST="open-vm-tools net-tools perl cloud-init coreutils vim rsync"
10
11# If Debian:
12if [ ! -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
19datasource_list: [ VMware ]
20package_update: false
21package_upgrade: false
22apt:
23 preserve_sources_list: true
24EOF
25
26 exit 0
27fi
28
29# If RHEL/Centos:
30yum -y install ${PACKAGE_LIST}
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050031
32# The script to lookup the path to the cloud-init's datasource directory, "sources".
33PY_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.
36CLOUD_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 Berezovskiy66279972020-10-26 16:48:53 +040043if [ "${DOWNLOAD_INSTALL}" = "true" ]; then
44 REPO_URL="${REPO_URL:-https://gerrit.mcp.mirantis.com/plugins/gitiles/kubernetes/vmware-guestinfo/+/refs/heads}"
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050045
Ivan Berezovskiy66279972020-10-26 16:48:53 +040046 # 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 Kutz4f66b8b2018-09-16 18:28:59 -050048
Ivan Berezovskiy66279972020-10-26 16:48:53 +040049 # 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 Kutz4f66b8b2018-09-16 18:28:59 -050052
Ivan Berezovskiy66279972020-10-26 16:48:53 +040053 # 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
57else
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
62fi