#!/bin/bash

# docker exec -it postgres psql -U postgres
# create role homeautomation nosuperuser nocreatedb nocreaterole password 'badPassword';
# create database homeautomation owner homeautomation;

# --device /dev/ttyACM0:/dev/ttyACM0
# --device /dev/rtc1:/dev/rtc1
# -v /sys/class:/sys/class

ARCH=`arch`
if [ $ARCH == "aarch64" ]
then
    REPO="homeassistant/raspberrypi3-64-homeassistant"
else
    REPO="homeassistant/raspberrypi3-homeassistant"
fi

docker pull ${REPO}

touch /var/home-assistant/known_devices.yaml

docker container stop home-assistant
docker container rm home-assistant

docker run -it --name home-assistant \
    --restart unless-stopped \
    --network docker-private \
    --device /dev/ttyACM0:/dev/ttyACM0 \
    -e DEBUG=1 \
    -l traefik.frontend.rule=Host:home-automation.domain.tld \
    -l traefik.frontend.passHostHeader=true \
    -l traefik.port=8123 \
    -v /sys/class:/sys/class \
    -v /etc/localtime:/etc/localtime:ro \
    -v /var/home-assistant:/config \
    ${REPO}:latest
