blob: f1c088fa2b9dbd8510d93de795ee2acfb6ca9988 [file] [log] [blame]
Andrew Kutz4f66b8b2018-09-16 18:28:59 -05001#!/bin/sh
2
3#
4# usage: install.sh
5# curl -sSL https://raw.githubusercontent.com/akutz/cloud-init-vmware-guestinfo/master/install.sh | sh -
6#
7
8# The script to lookup the path to the cloud-init's datasource directory, "sources".
9PY_SCRIPT='import os; from cloudinit import sources; print(os.path.dirname(sources.__file__));'
10
11# Get the path to the cloud-init installation's datasource directory.
12CLOUD_INIT_SOURCES=$(python -c ''"${PY_SCRIPT}"'' 2>/dev/null || \
13 python3 -c ''"${PY_SCRIPT}"'' 2>/dev/null) ||
14 { exit_code="${?}"; echo "failed to find python runtime" 1>&2; exit "${exit_code}"; }
15
16# If no "sources" directory was located then it's likely cloud-init is not installed.
17[ -z "${CLOUD_INIT_SOURCES}" ] && echo "cloud-init not found" 1>&2 && exit 1
18
19# The repository from which to fetch the cloud-init datasource and config files.
20REPO_SLUG="${REPO_SLUG:-https://raw.githubusercontent.com/akutz/cloud-init-vmware-guestinfo}"
21
22# The git reference to use. This can be a branch or tag name as well as a commit ID.
23GIT_REF="${GIT_REF:-master}"
24
25# Download the cloud init datasource into the cloud-init's "sources" directory.
26curl -sSL -o "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" \
27 "${REPO_SLUG}/${GIT_REF}/DataSourceVMwareGuestInfo.py"
28
29# Add the configuration file that tells cloud-init what datasource to use.
akutzf808b452018-10-10 14:16:47 -050030mkdir -p /etc/cloud/cloud.cfg.d
31curl -sSL -o /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg \
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050032 "${REPO_SLUG}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg"
33
34echo "So long, and thanks for all the fish."