| 1 | #!/bin/sh |
| 2 | |
| 3 | fail() { |
| 4 | echo "FAILED:" "$@" 1>&2 |
| 5 | exit 1 |
| 6 | } |
| 7 | |
| 8 | PYTHON="${PYTHON:-python3}" |
| 9 | if [ ! $(which ${PYTHON}) ]; then |
| 10 | echo "Please install python first." |
| 11 | exit 1 |
| 12 | fi |
| 13 | py_prefix=$(${PYTHON} -c 'import sys; print("py%d%d" % (sys.version_info.major, sys.version_info.minor))') |
| 14 | |
| 15 | # Check dependencies: |
| 16 | depschecked=/tmp/c-i.dependencieschecked |
| 17 | pkgs=" |
| 18 | bash |
| 19 | dmidecode |
| 20 | ${py_prefix}-configobj |
| 21 | ${py_prefix}-jinja2 |
| 22 | ${py_prefix}-oauthlib |
| 23 | ${py_prefix}-requests |
| 24 | ${py_prefix}-setuptools |
| 25 | ${py_prefix}-yaml |
| 26 | ${py_prefix}-jsonschema |
| 27 | sudo |
| 28 | " |
| 29 | [ -f "$depschecked" ] || pkg_add ${pkgs} || fail "install packages" |
| 30 | |
| 31 | touch $depschecked |
| 32 | |
| 33 | # Build the code and install in /usr/pkg/: |
| 34 | ${PYTHON} setup.py build |
| 35 | ${PYTHON} setup.py install -O1 --distro netbsd --skip-build --init-system sysvinit_netbsd |
| 36 | mv -v /usr/local/etc/rc.d/cloud* /etc/rc.d |
| 37 | |
| 38 | # Enable cloud-init in /etc/rc.conf: |
| 39 | sed -i.bak -e "/^cloud.*=.*/d" /etc/rc.conf |
| 40 | echo ' |
| 41 | # You can safely remove the following lines starting with "cloud" |
| 42 | cloudinitlocal="YES" |
| 43 | cloudinit="YES" |
| 44 | cloudconfig="YES" |
| 45 | cloudfinal="YES"' >> /etc/rc.conf |
| 46 | |
| 47 | echo "Installation completed." |