<commit_before>#!/usr/bin/env bash

set -e

function msg() {
	logger -st cluster-init-out "$@"
}
function err() {
	logger -st cluster-init-err "$@"
}

exec 1> >(msg)
exec 2> >(err)

function init() {
        ips=('192.168.200.200'
             '192.168.200.201'
             '192.168.200.202'
        )
        quuids=('e30aa502-e48b-2a4e-8116-d4b09c0b89b3'
                '21c1c14f-ca81-2e4f-96cc-0ba6aa404a94'
                '11e48c3f-b13a-5e4a-b20e-b5b3ae6fd060'
        )

        # handle uuid endiannes changes in qemu/smbios/dmidecode, see
        # https://bugzilla.redhat.com/show_bug.cgi?id=1152922
        # and the fix
        # https://lists.gnu.org/archive/html/qemu-devel/2014-10/msg03640.html
        #
        # which also affects the systemd-networkd generated mac for br0
        if [[ $(hostname) != ${quuids[0]} ]]; then
                uuids=('02a50ae3-8be4-4e2a-8116-d4b09c0b89b3'
                       '4fc1c121-81ca-4f2e-96cc-0ba6aa404a94'
                       '3f8ce411-3ab1-4a5e-b20e-b5b3ae6fd060'
                )
                macs=('DE:AD:BE:EF:7F:20'
                      'A6:59:45:B2:57:12'
                      '6A:B1:9E:0F:F0:56'
                )
        else
                echo "SMBIOS version is older than v2.6"
                uuids=(${quuids[*]})
                macs=('DE:AD:BE:EF:7F:20'
                      'FA:86:83:AA:58:6B'
                      'C6:85:44:7D:FA:88'
                )
        fi
}
init

function do_until() {
	local t=$1
	local cmd=$2
	shift 2
	local i=0
	until $cmd "$@"; do
		sleep $t
		msg "$((++i * $t))s elapsed"
	done
}

ip=${ips[0]}
nm=24
gw=192.168.200.1

echo "$LINENO: stopping nconfigd to avoid races"
systemctl stop nconfigd
echo "$LINENO: done"

echo "$LINENO: setting up etcd keys"
etcdctl set /lochness/hypervisors/${uuids[0]}/config/dhcpd true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/dns true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/cbootstrapd true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/etcd true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/tftpd true

etcdctl set /lochness/hypervisors/${uuids[1]}/config/dns true
etcdctl set /lochness/hypervisors/${uuids[1]}/config/etcd true
etcdctl set /lochness/hypervisors/${uuids[2]}/config/dns true
etcdctl set /lochness/hypervisors/${uuids[2]}/config/etcd true
echo "$LINENO: done"

echo "$LINENO: setting up network"
rm -f /etc/systemd/network/*
cat > /etc/systemd/network/br0.netdev <<EOF
[NetDev]<commit_msg>cluster-init: rename logging function msg -> out<commit_after>#!/usr/bin/env bash

set -e

function out() {
	logger -st cluster-init-out "$@"
}
function err() {
	logger -st cluster-init-err "$@"
}

exec 1> >(out)
exec 2> >(err)

function init() {
        ips=('192.168.200.200'
             '192.168.200.201'
             '192.168.200.202'
        )
        quuids=('e30aa502-e48b-2a4e-8116-d4b09c0b89b3'
                '21c1c14f-ca81-2e4f-96cc-0ba6aa404a94'
                '11e48c3f-b13a-5e4a-b20e-b5b3ae6fd060'
        )

        # handle uuid endiannes changes in qemu/smbios/dmidecode, see
        # https://bugzilla.redhat.com/show_bug.cgi?id=1152922
        # and the fix
        # https://lists.gnu.org/archive/html/qemu-devel/2014-10/msg03640.html
        #
        # which also affects the systemd-networkd generated mac for br0
        if [[ $(hostname) != ${quuids[0]} ]]; then
                uuids=('02a50ae3-8be4-4e2a-8116-d4b09c0b89b3'
                       '4fc1c121-81ca-4f2e-96cc-0ba6aa404a94'
                       '3f8ce411-3ab1-4a5e-b20e-b5b3ae6fd060'
                )
                macs=('DE:AD:BE:EF:7F:20'
                      'A6:59:45:B2:57:12'
                      '6A:B1:9E:0F:F0:56'
                )
        else
                echo "SMBIOS version is older than v2.6"
                uuids=(${quuids[*]})
                macs=('DE:AD:BE:EF:7F:20'
                      'FA:86:83:AA:58:6B'
                      'C6:85:44:7D:FA:88'
                )
        fi
}
init

function do_until() {
	local t=$1
	local cmd=$2
	shift 2
	local i=0
	until $cmd "$@"; do
		sleep $t
		echo "$((++i * $t))s elapsed"
	done
}

ip=${ips[0]}
nm=24
gw=192.168.200.1

echo "$LINENO: stopping nconfigd to avoid races"
systemctl stop nconfigd
echo "$LINENO: done"

echo "$LINENO: setting up etcd keys"
etcdctl set /lochness/hypervisors/${uuids[0]}/config/dhcpd true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/dns true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/cbootstrapd true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/etcd true
etcdctl set /lochness/hypervisors/${uuids[0]}/config/tftpd true

etcdctl set /lochness/hypervisors/${uuids[1]}/config/dns true
etcdctl set /lochness/hypervisors/${uuids[1]}/config/etcd true
etcdctl set /lochness/hypervisors/${uuids[2]}/config/dns true
etcdctl set /lochness/hypervisors/${uuids[2]}/config/etcd true
echo "$LINENO: done"

echo "$LINENO: setting up network"
rm -f /etc/systemd/network/*
cat > /etc/systemd/network/br0.netdev <<EOF
[NetDev]
{'fraction_non_alphanumeric': 0.14962196577795464, 'fraction_numerical': 0.09351372861122165, 'mean_word_length': 2.279191128506197, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2267696', 'n_tokens_mistral': 2268, 'n_tokens_neox': 2016, 'n_words': 336}