#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Portainer
# Runs portainer
# ==============================================================================
declare -a options
export AGENT_SECRET

bashio::log.info 'Starting Portainer...'

options+=(--data /data)
options+=(--bind 0.0.0.0:8099)
options+=(--host unix:///var/run/docker.sock)

# Export agent secret, if defined
if bashio::config.has_value 'agent_secret' ; then
    AGENT_SECRET=$(bashio::config 'agent_secret')
fi

# Run Portainer
exec /opt/portainer/portainer "${options[@]}"
