#!/bin/sh

# This is a launch script that takes the identifier from a systemd template unit 
# file and locates the corresponding configuration file in /etc/nebula
#
# This bodge is nesseary because YAML files can have multiple extentions


set -e

if [ "$1" = "" ]; then
	printf "USAGE: nebula-systemd-launcher [conifg]\n";
	exit 1
fi

CONFIG_DIR=/etc/nebula
CONFIG_PATH="${CONFIG_DIR}/$1"

if [ -f "${CONFIG_PATH}.yml" ]; then
	CONFIG_PATH="${CONFIG_PATH}.yml"
elif [ -f "${CONFIG_PATH}.yaml" ]; then
	CONFIG_PATH="${CONFIG_PATH}.yaml"
else
	printf "Cannot find configuration file $CONFIG_PATH.yml or $CONFIG_PATH.yaml\n" >&2
	exit 1
fi

/usr/bin/nebula -config $CONFIG_PATH
