<commit_before>#!/usr/bin/bash
#
# Copyright (c) 2010 Joyent Inc., All rights reserved.
#
# Exit codes:
#
# 0 - success
# 1 - error
# 2 - rebooting (don't bother doing anything)
#

#
# We set errexit (a.k.a. "set -e") to force an exit on error conditions, and
# pipefail to force any failures in a pipeline to force overall failure.  We
# also set xtrace to aid in debugging.
#
set -o errexit
set -o pipefail
set -o xtrace

function fatal
{
    echo "head-node configuration: fatal error: $*" >> /dev/console
    echo "head-node configuration: fatal error: $*"
    exit 1
}

function errexit
{
    [[ $1 -ne 0 ]] || exit 0
    fatal "error exit status $1"
}

function install_node_config
{
    dir=$1

    if [[ -n ${dir} ]] && [[ -d ${dir} ]]; then
        # pull out those config options we want to keep
        (
            . ${USB_COPY}/config

            # Options here should match key names from the headnode's config
            # that we want on compute nodes.
            for opt in \
                datacenter_name \
                root_authorized_keys_file \
                compute_node_initial_datasets \
                assets_admin_ip \
                ntp_conf_file \
                ntp_hosts \
                rabbitmq \
                root_shadow \
                ; do

                value=$(eval echo \${${opt}})
                if [[ -n ${value} ]]; then
                    echo "${opt}='${value}'"

                    if echo "${opt}" | grep "_file$" >/dev/null 2>&1 \
                        && [[ "${value}" != "node.config" ]]; then

                        [[ -f "${USB_COPY}/config.inc/${value}" ]] \
                            && cp "${USB_COPY}/config.inc/${value}" "${dir}/${value}"
                    fi
                fi

            done
        ) > ${dir}/node.config
    else
        echo "WARNING: Can't create node config in '${dir}'"
    fi
}

function install_config_file
{
    option=$1
    target=$2

    # pull out those config options we want to keep
    filename=$(
        . ${USB_COPY}/config
        eval echo "\${${option}}"
    )

    if [[ -n ${filename} ]] && [[ -f "${USB_COPY}/config.inc/${filename}" ]]; then
        cp "${USB_COPY}/config.inc/${filename}" "${target}"
    fi
}

trap 'errexit $?' EXIT

DEBUG="true"

USB_PATH=/mnt/`svcprop -p "joyentfs/usb_mountpoint" svc:/system/filesystem/smartdc:default`
USB_COPY=`svcprop -p "joyentfs/usb_copy_path" svc:/system/filesystem/smartdc:default`
<commit_msg>[HEAD-249] make list of templates come from build.spec instead of hardcoding (add back missing headnode.config)<commit_after>#!/usr/bin/bash
#
# Copyright (c) 2010 Joyent Inc., All rights reserved.
#
# Exit codes:
#
# 0 - success
# 1 - error
# 2 - rebooting (don't bother doing anything)
#

#
# We set errexit (a.k.a. "set -e") to force an exit on error conditions, and
# pipefail to force any failures in a pipeline to force overall failure.  We
# also set xtrace to aid in debugging.
#
set -o errexit
set -o pipefail
set -o xtrace

function fatal
{
    echo "head-node configuration: fatal error: $*" >> /dev/console
    echo "head-node configuration: fatal error: $*"
    exit 1
}

function errexit
{
    [[ $1 -ne 0 ]] || exit 0
    fatal "error exit status $1"
}

function install_node_config
{
    dir=$1

    if [[ -n ${dir} ]] && [[ -d ${dir} ]]; then
        # pull out those config options we want to keep
        (
            . ${USB_COPY}/config

            # Options here should match key names from the headnode's config
            # that we want on compute nodes.
            for opt in \
                datacenter_name \
                root_authorized_keys_file \
                compute_node_initial_datasets \
                assets_admin_ip \
                ntp_conf_file \
                ntp_hosts \
                rabbitmq \
                root_shadow \
                ; do

                value=$(eval echo \${${opt}})
                if [[ -n ${value} ]]; then
                    echo "${opt}='${value}'"

                    if echo "${opt}" | grep "_file$" >/dev/null 2>&1 \
                        && [[ "${value}" != "node.config" ]]; then

                        [[ -f "${USB_COPY}/config.inc/${value}" ]] \
                            && cp "${USB_COPY}/config.inc/${value}" "${dir}/${value}"
                    fi
                fi

            done
        ) > ${dir}/node.config
    else
        echo "WARNING: Can't create node config in '${dir}'"
    fi
}

function install_config_file
{
    option=$1
    target=$2

    # pull out those config options we want to keep
    filename=$(
        . ${USB_COPY}/config
        eval echo "\${${option}}"
    )

    if [[ -n ${filename} ]] && [[ -f "${USB_COPY}/config.inc/${filename}" ]]; then
        cp "${USB_COPY}/config.inc/${filename}" "${target}"
    fi
}

trap 'errexit $?' EXIT

DEBUG="true"

USB_PATH=/mnt/`svcprop -p "joyentfs/usb_mountpoint" svc:/system/filesystem/smartdc:default`
USB_COPY=`svcprop -p "joyentfs/usb_copy_path" svc:/system/filesystem/smartdc:default`

# Create a link to the config as /etc/headnode.config, so we can have a
# consistent location for it when we want to be able to umount the USB later
ln -s ${USB_COPY}/config /etc/headnode.config

{'fraction_non_alphanumeric': 0.13520213577421816, 'fraction_numerical': 0.007055682684973303, 'mean_word_length': 1.8459034183396636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '191270', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1576, 'n_words': 478}