Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 1 | #!/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". |
| 9 | PY_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. |
| 12 | CLOUD_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. |
| 20 | REPO_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. |
| 23 | GIT_REF="${GIT_REF:-master}" |
| 24 | |
| 25 | # Download the cloud init datasource into the cloud-init's "sources" directory. |
| 26 | curl -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. |
akutz | f808b45 | 2018-10-10 14:16:47 -0500 | [diff] [blame] | 30 | mkdir -p /etc/cloud/cloud.cfg.d |
| 31 | curl -sSL -o /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg \ |
Andrew Kutz | 4f66b8b | 2018-09-16 18:28:59 -0500 | [diff] [blame] | 32 | "${REPO_SLUG}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg" |
| 33 | |
| 34 | echo "So long, and thanks for all the fish." |