#!/bin/bash

RECEIVER_FLAGS=()
RECEIVER_CONFIG="${RECEIVER_CONFIG:-/app/config/receiver-${RECEIVER_PROTOCOL}.yaml}"

[ -n "${RECEIVER_DEBUG}" ] && RECEIVER_FLAGS=("${RECEIVER_FLAGS[@]}" "--debug")
[ -n "${RECEIVER_TRACE}" ] && RECEIVER_FLAGS=("${RECEIVER_FLAGS[@]}" "--trace")

run() {
    case "${RECEIVER_PROTOCOL}" in
        "") exec "/app/hamview-receiver" help ;;
        *)  exec "/app/hamview-receiver" \
            "${RECEIVER_FLAGS[@]}" \
            --config "${RECEIVER_CONFIG}" \
            "${RECEIVER_PROTOCOL}" ;;
    esac
}

case "$@" in
    "")
        run
        ;;
    *)
        exec "/bin/sh" -c "$@"
        ;;
esac
