#!/bin/bash

mkdir -p dbuild/usr/local/bin
mkdir -p dbuild/etc/
mkdir -p dbuild/etc/systemd/system/
mkdir -p dbuild/DEBIAN

cat <<EOF > dbuild/DEBIAN/control
Package: watcher
Version: 0.2
Maintainer: Charles
Architecture: all
Description: Watches cameras and temp sensors
EOF

cat <<EOF > dbuild/DEBIAN/postinst
#!/bin/bash

systemctl daemon-reload
# Make sure its enabled
systemctl enable --now watcher
# Restart it; it might have already been installed and running
systemctl restart watcher
EOF
chmod +x dbuild/DEBIAN/postinst

GOOS=linux GOARCH=arm64 go build -o dbuild/usr/local/bin/watcher ./cmd/watcher

cp ./rpi_camera.yaml dbuild/etc/watcher_config.yaml
cp ./watcher.systemd dbuild/etc/systemd/system/watcher.service
cp ./temperature.py dbuild/usr/local/bin/


dpkg-deb --build dbuild