Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # |
| 4 | # usage: install.sh |
Ivan Mikushin | 6ba6bcb | 2019-05-23 19:43:55 -0700 | [diff] [blame] | 5 | # curl -sSL https://raw.githubusercontent.com/vmware/cloud-init-vmware-guestinfo/master/install.sh | sh - |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 6 | # |
| 7 | |
akutz | 36a15f9 | 2019-05-21 08:30:18 -0500 | [diff] [blame] | 8 | if ! command -v curl >/dev/null 2>&1; then |
| 9 | echo "curl is required" 1>&2 |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 13 | # The script to lookup the path to the cloud-init's datasource directory, "sources". |
| 14 | PY_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. |
| 17 | CLOUD_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 Mikushin | 6ba6bcb | 2019-05-23 19:43:55 -0700 | [diff] [blame] | 25 | REPO_SLUG="${REPO_SLUG:-https://raw.githubusercontent.com/vmware/cloud-init-vmware-guestinfo}" |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 26 | |
| 27 | # The git reference to use. This can be a branch or tag name as well as a commit ID. |
| 28 | GIT_REF="${GIT_REF:-master}" |
| 29 | |
| 30 | # Download the cloud init datasource into the cloud-init's "sources" directory. |
| 31 | curl -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. |
akutz | f808b45 | 2018-10-10 14:16:47 -0500 | [diff] [blame] | 35 | mkdir -p /etc/cloud/cloud.cfg.d |
| 36 | curl -sSL -o /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg \ |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 37 | "${REPO_SLUG}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg" |
| 38 | |
akutz | 9efe9a2 | 2019-05-22 13:46:51 -0500 | [diff] [blame] | 39 | # Download program used by ds-identify to determine wheether or not the |
| 40 | # VMwareGuestInfo datasource is useable. |
| 41 | curl -sSL -o "/usr/local/bin/dscheck_VMwareGuestInfo" \ |
| 42 | "${REPO_SLUG}/${GIT_REF}/dscheck_VMwareGuestInfo.sh" |
| 43 | chmod 0755 "/usr/local/bin/dscheck_VMwareGuestInfo" |
| 44 | |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 45 | echo "So long, and thanks for all the fish." |