username="motion"
groupname="motion"

_setup_user_and_group() {
  getent group $groupname &>/dev/null || groupadd -r $groupname 1>/dev/null
  getent passwd $username &>/dev/null || useradd -r -g $groupname -s "/bin/bash" $username 1>/dev/null

  chown -R $username:$groupname "/etc/motioneye" 1>/dev/null
}

post_install() {
  cat <<INFO

If motion.service is installed, disable it:

  systemctl disable --now motion

Then reload systemd:

  systemctl daemon-reload

Finally enable motioneye:

  systemctl enable --now motioneye

Default web login:

  username: admin
  password: (empty)

INFO

  _setup_user_and_group
}

post_upgrade() {
  echo "Restart motioneye to apply changes:"
  echo "  systemctl restart motioneye"
  _setup_user_and_group
}