#!/bin/sh

config=/home/hass/ha_config

image=ghcr.io/home-assistant/home-assistant:stable
name=homeassistant

start() {
  docker run \
    --detach \
    --name ${name} \
    --restart=unless-stopped \
    --privileged \
    --cap-add=NET_ADMIN \
    --cap-add=NET_RAW \
    --dns 192.168.100.1 \
    --dns 8.8.8.8 \
    --dns 8.8.4.4 \
    --env TZ=`cat /etc/timezone` \
    --volume ${config}:/config \
    --volume /share:/share \
    --volume /run/dbus:/run/dbus:ro \
    --network=host \
    ${image}
}

stop() {
  docker stop ${name}
  docker rm ${name}
}

restart() {
  stop
  start
}

update() {
  docker pull ${image}
}

upgrade() {
  restart
  docker image prune -f
}

case "${1}" in
  start|stop|restart|update|upgrade)
    ${1}
    ;;
  *)
    echo "Usage: ${0} start|stop|restart|update|upgrade"
    ;;
esac
