#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Vector
# Start Vector
# ==============================================================================

readonly CONFIG_PATH="/config/vector.yaml"
readonly DEFAULT_CONFIG="/vector.yaml"

bashio::log.info "Starting Vector..."

if ! bashio::fs.file_exists "$CONFIG_PATH"; then
    bashio::log.info "Copying default configuration from $DEFAULT_CONFIG"

    if cp "$DEFAULT_CONFIG" "$CONFIG_PATH"; then
        bashio::log.info "Default configuration copied successfully"
    else
        bashio::log.error "Failed to copy default configuration!"
        exit 1
    fi
else
    bashio::log.info "Using existing configuration at $CONFIG_PATH"
fi

exec /usr/local/bin/vector --config /config/vector.yaml
