#!/usr/bin/env bash

set -e

if ! snapctl is-connected docker-executables; then
    echo "the docker-executables content interface must be connected first!"
    echo "please run \"snap connect $SNAP_NAME:docker-executables docker:docker-executables\""
    exit 1
fi

if ! snapctl is-connected docker; then
    echo "the docker socket interface must be connected first!"
    echo "please run \"snap connect $SNAP_NAME:docker docker:docker-daemon\""
    exit 1
fi

COMPOSE_FILE="${SNAP}/services/ozwdaemon/docker-compose.yml"

USB_PATH=$(snapctl get usb-path)
MQTT_SERVER=$(snapctl get mqtt.server)
MQTT_PORT=$(snapctl get mqtt.port)
MQTT_USERNAME=$(snapctl get mqtt.username)
MQTT_PASSWORD=$(snapctl get mqtt.password)
MQTT_TLS=$(snapctl get mqtt.tls)
MQTT_CONNECT_TIMEOUT=$(snapctl get mqtt.connect-timeout)
STOP_ON_FAILURE=$(snapctl get stop-on-failure)
OZW_NETWORK_KEY=$(snapctl get ozw.network_key)
OZW_INSTANCE=$(snapctl get ozw.instance)

#$SNAP/docker-snap/bin/docker-compose -f $COMPOSE_FILE up -d

# ALL IN ONE
# $SNAP/docker-snap/bin/docker run -it \
#     --security-opt seccomp=unconfined \
#     --device=/dev/ttyUSB0 \
#     -v $PWD/ozw:/opt/ozw/config \
#     -e MQTT_SERVER="10.100.200.102" \
#     -e USB_PATH=/dev/ttyUSB0 \
#     -p 1983:1983 \
#     -p 5901:5901 \
#     -p 7800:7800 \
#     openzwave/ozwdaemon:allinone-latest

$SNAP/docker-snap/bin/docker "$@"