#!/bin/bash

# Inform the enclosing instance (if any) of the URI's for this instance

if test $(flux getattr rank) -eq 0 \
	&& parent_uri=$(flux getattr parent-uri 2>/dev/null) \
	&& parent_ns=$(flux getattr parent-kvs-namespace 2>/dev/null); then
    key_prefix=flux
    local_uri=${FLUX_URI}
    remote_uri="ssh://$(hostname)/$(echo $local_uri|sed 's,^.*://,,')"

    FLUX_URI=${parent_uri} FLUX_KVS_NAMESPACE=${parent_ns} \
        flux kvs put ${key_prefix}.local_uri=${local_uri}
    FLUX_URI=${parent_uri} FLUX_KVS_NAMESPACE=${parent_ns} \
        flux kvs put ${key_prefix}.remote_uri=${remote_uri}
fi
