blob: 8252703d04a5cc611fd1a0bb830c3b702420ef7c [file] [log] [blame]
Andrew Kutz4f66b8b2018-09-16 18:28:59 -05001#!/bin/sh
2
3#
4# usage: install.sh
Ivan Mikushin6ba6bcb2019-05-23 19:43:55 -07005# curl -sSL https://raw.githubusercontent.com/vmware/cloud-init-vmware-guestinfo/master/install.sh | sh -
Andrew Kutz4f66b8b2018-09-16 18:28:59 -05006#
7
akutz36a15f92019-05-21 08:30:18 -05008if ! command -v curl >/dev/null 2>&1; then
9 echo "curl is required" 1>&2
10 exit 1
11fi
12
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050013# The script to lookup the path to the cloud-init's datasource directory, "sources".
14PY_SCRIPT='import os; from cloudinit import sources; print(os.path.dirname(sources.__file__));'
15
16# Get the path to the cloud-init installation's datasource directory.
17CLOUD_INIT_SOURCES=$(python -c ''"${PY_SCRIPT}"'' 2>/dev/null || \
18 python3 -c ''"${PY_SCRIPT}"'' 2>/dev/null) ||
19 { exit_code="${?}"; echo "failed to find python runtime" 1>&2; exit "${exit_code}"; }
20
21# If no "sources" directory was located then it's likely cloud-init is not installed.
22[ -z "${CLOUD_INIT_SOURCES}" ] && echo "cloud-init not found" 1>&2 && exit 1
23
24# The repository from which to fetch the cloud-init datasource and config files.
Ivan Mikushin6ba6bcb2019-05-23 19:43:55 -070025REPO_SLUG="${REPO_SLUG:-https://raw.githubusercontent.com/vmware/cloud-init-vmware-guestinfo}"
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050026
27# The git reference to use. This can be a branch or tag name as well as a commit ID.
28GIT_REF="${GIT_REF:-master}"
29
30# Download the cloud init datasource into the cloud-init's "sources" directory.
31curl -sSL -o "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py" \
32 "${REPO_SLUG}/${GIT_REF}/DataSourceVMwareGuestInfo.py"
33
34# Add the configuration file that tells cloud-init what datasource to use.
akutzf808b452018-10-10 14:16:47 -050035mkdir -p /etc/cloud/cloud.cfg.d
36curl -sSL -o /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg \
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050037 "${REPO_SLUG}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg"
38
akutz9efe9a22019-05-22 13:46:51 -050039# Download program used by ds-identify to determine wheether or not the
40# VMwareGuestInfo datasource is useable.
41curl -sSL -o "/usr/local/bin/dscheck_VMwareGuestInfo" \
42 "${REPO_SLUG}/${GIT_REF}/dscheck_VMwareGuestInfo.sh"
43chmod 0755 "/usr/local/bin/dscheck_VMwareGuestInfo"
44
Andrew Kutz4f66b8b2018-09-16 18:28:59 -050045echo "So long, and thanks for all the fish."