#!/bin/sh

set -e
set -x

usage () {
	echo "Usage: $0 --hostname <HOSTNAME> --root-password <ROOT_PASSWORD>"
	exit 1
}

for i in $@ ; do
	case "${1}" in
	"--hostname")
		MY_HOST=${2}
		shift
		shift
	;;
	"--root-password")
		ROOT_PASSWORD=${2}
		shift
		shift
	;;
	*)
	;;
	esac
done

if [ -z "${MY_HOST}" ] ; then
	usage
fi

if [ -z "${ROOT_PASSWORD}" ] ; then
	usage
fi

SHORT_HOSTNAME=$(echo ${MY_HOST} | cut -d. -f1)

vault kv put common/wallet/${SHORT_HOSTNAME} root=${ROOT_PASSWORD}
