<commit_before>#!/bin/bash
# -*- mode: shell-script; fill-column: 80; -*-
#
# Copyright (c) 2013 Joyent Inc., All rights reserved.
#

export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
set -o errexit

PATH=/opt/smartdc/sdc/bin:/opt/smartdc/sdc/build/node/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin
SAPIADM=/opt/smartdc/config-agent/bin/sapiadm

metadata_path=/var/tmp/metadata.json
sdc-sapi /configs/$(zonename) | json -H metadata > $metadata_path
admin_uuid=$(json -f ${metadata_path} ufds_admin_uuid)
datacenter_name=$(json -f ${metadata_path} datacenter_name)


# Add a '$dcname sdc key' ssh key on the 'admin' user and to ~/.ssh in *every
# SDC core zone* (by adding for manifest on the 'sdc' *application* in SAPI).
# This will be used for ssh'ing to each sdc zone (e.g. by the 'sdc-req' tool)
# and for uploading rotated log files to Manta.
key_name="$datacenter_name sdc key"
key=$(sdc-useradm key $admin_uuid "$key_name" || true)
if [[ -n "$key" ]]; then
    echo "Already have '$key_name' key on admin user"
elif [[ "$(sdc-useradm ping --master)" != "pong" ]]; then
    echo "Skip '$key_name' setup because cannot reach UFDS master"
else
    echo "Create '$key_name' key for admin user and add to the 'sdc' SAPI app"
    key_file=/var/tmp/sdc.id_rsa
    rm -f $key_file $key_file.pub
    ssh-keygen -t rsa -C "$key_name" -f "$key_file" -N ""
    key_fingerprint=$(ssh-keygen -l -f "$key_file" | awk '{print $2}')

    # Add the keys to the sdc service metadata, which will be used by the
    # actual manifests that write the keys to each 'sdc' zone.
    sdc_app_uuid=$(sdc-sapi /applications?name=sdc | json -H 0.uuid)
    node -e "
        var fs = require('fs');
        var d = {
            metadata: {
                SDC_PRIVATE_KEY: fs.readFileSync('$key_file', 'ascii'),
                SDC_PUBLIC_KEY: fs.readFileSync('$key_file.pub', 'ascii'),
                SDC_KEY_ID: '$key_fingerprint'<commit_msg>TOOLS-345: 'sdc' zone configure (mdata:execute) failed on reboot of COAL<commit_after>#!/bin/bash
# -*- mode: shell-script; fill-column: 80; -*-
#
# Copyright (c) 2013 Joyent Inc., All rights reserved.
#

export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
set -o errexit

PATH=/opt/smartdc/sdc/bin:/opt/smartdc/sdc/build/node/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin
SAPIADM=/opt/smartdc/config-agent/bin/sapiadm

function fatal
{
    echo "$0: fatal error: $*"
    exit 1
}


config_path=/opt/smartdc/sdc/etc/config.json
admin_uuid=$(json -f ${config_path} ufds_admin_uuid)
[[ -z "$admin_uuid" ]] && fatal "could not determine admin_uuid"
datacenter_name=$(json -f ${config_path} datacenter_name)
[[ -z "$datacenter_name" ]] && fatal "could not determine datacenter_name"


# Add a '$dcname sdc key' ssh key on the 'admin' user and to ~/.ssh in *every
# SDC core zone* (by adding for manifest on the 'sdc' *application* in SAPI).
# This will be used for ssh'ing to each sdc zone (e.g. by the 'sdc-req' tool)
# and for uploading rotated log files to Manta.
key_name="$datacenter_name sdc key"
key=$(sdc-useradm key $admin_uuid "$key_name" || true)
if [[ -n "$key" ]]; then
    echo "Already have '$key_name' key on admin user"
elif [[ "$(sdc-useradm ping --master)" != "pong" ]]; then
    echo "Skip '$key_name' setup because cannot reach UFDS master"
else
    echo "Create '$key_name' key for admin user and add to the 'sdc' SAPI app"
    key_file=/var/tmp/sdc.id_rsa
    rm -f $key_file $key_file.pub
    ssh-keygen -t rsa -C "$key_name" -f "$key_file" -N ""
    key_fingerprint=$(ssh-keygen -l -f "$key_file" | awk '{print $2}')

    # Add the keys to the sdc service metadata, which will be used by the
    # actual manifests that write the keys to each 'sdc' zone.
    sdc_app_uuid=$(sdc-sapi /applications?name=sdc | json -H 0.uuid)
    node -e "
        var fs = require('fs');
        var d = {
            metadata: {
                SDC_PRIVATE_KEY: fs.readFileSync('$key_file', 'ascii'),
                SDC_PUBLIC_KEY: fs.readFileSync('$key_file.pub', 'ascii'),
                SDC_KEY_ID: '$key_fingerprint'
{'fraction_non_alphanumeric': 0.15602496399423907, 'fraction_numerical': 0.006481036965914546, 'mean_word_length': 3.461456102783726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3258311', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1509, 'n_words': 440}