#!/bin/bash

# skip strongbash header
[[ "$-" == *x* ]] && _trace="-x"
[ "${__DEBUG:-}" = TRUE ] && set +x
set -eu
___CLASS="$1"
___CMD="$2"
___NAME="$3"
export PATH="/opt/fox_$___CLASS/:$PATH"
. /opt/fox_conf/cloud/*/cloud.conf
. /opt/fox_utils/fox_const
___DIR="/opt/fox_conf/$___CLASS/$___NAME"
eval "${___CLASS^^}_DIR=$___DIR"
___CONF="$___DIR/${___CLASS}.conf"

if [ "$___CMD" = "exists" ]; then
	[ ! -d "$___DIR" ] && exit 255
	exit 0
elif [ "$___CMD" = "get" ]; then
	if [ -f "$___CONF" ]; then
		for ___tmp_conf in $___DIR/${___CLASS}_*.conf; do
			[ -s "$___tmp_conf" ] && . "$___tmp_conf" || continue
		done
		. "$___CONF"
	else
		echo "$___CLASS $___NAME not exists"
		exit 255
	fi
else
	echo "LOG_ERROR CMD=${___CMD} not exists"
	exit 255
fi
[ -n "${_trace:-}" ] && { _trace=""; set -x; }

true
