summaryrefslogtreecommitdiff
path: root/tools/build-on-freebsd
blob: e2196b03d027310072afeb7929f03c64eb59daec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
# The official way to install cloud-init on FreeBSD is via the net/cloud-init
# port or the (appropriately py-flavoured) package.
# This script provides a communication medium between the cloud-init maintainers
# and the cloud-init port maintainers as to what dependencies have changed.
# It also provides a quick and dirty way of building and installing, and will
# optionally make a first run at the end.

set -eux

fail() { echo "FAILED:" "$@" 1>&2; exit 1; }

PYTHON="${PYTHON:-python3}"
if [ ! $(which ${PYTHON}) ]; then
    echo "Please install python first."
    exit 1
fi
py_prefix=$(${PYTHON} -c 'import sys; print("py%d%d" % (sys.version_info.major, sys.version_info.minor))')

# Check dependencies:
depschecked=/tmp/c-i.dependencieschecked
pkgs="
    bash
    e2fsprogs
    $py_prefix-Jinja2
    $py_prefix-configobj
    $py_prefix-jsonpatch
    $py_prefix-jsonpointer
    $py_prefix-jsonschema
    $py_prefix-oauthlib
    $py_prefix-requests
    $py_prefix-pyserial
    $py_prefix-yaml
    sudo
"
[ -f "$depschecked" ] || pkg install --yes ${pkgs} || fail "install packages"
touch $depschecked

# Build the code and install in /usr/local/:
${PYTHON} setup.py build
${PYTHON} setup.py install -O1 --skip-build --prefix /usr/local/ --init-system sysvinit_freebsd

# Enable cloud-init in /etc/rc.conf:
sed -i.bak -e "/cloudinit_enable=.*/d" /etc/rc.conf
echo 'cloudinit_enable="YES"' >> /etc/rc.conf

echo "Installation completed."

if [ "$#" -gt 1 ] && [ "$1" = "run" ]; then
    echo "Ok, now let's see if it works."

    # Backup SSH keys
    mv /etc/ssh/ssh_host_* /tmp/

    # Remove old metadata
    rm -rf /var/lib/cloud

    # Just log everything, quick&dirty
    rm /usr/local/etc/cloud/cloud.cfg.d/05_logging.cfg

    # Start:
    /usr/local/etc/rc.d/cloudinit start

    # Restore SSH keys
    mv /tmp/ssh_host_* /etc/ssh/
fi