#!/usr/bin/env fish

# This script is meant to be executed inside the repo root.

set_color --bold yellow
echo "###########"
echo "## Build ##"
echo "###########"
set_color normal

./meta/build-typst-plugin
or return 1

./meta/build-thermal-printer-ui
or return 1

cross build --release \
    --package showbits-thermal-printer \
    --target aarch64-unknown-linux-gnu
or return 1

echo

set_color --bold yellow
echo "############"
echo "## Upload ##"
echo "############"
set_color normal

rsync -vP \
    meta/spinch/showbits-thermal-printer.service \
    meta/spinch/showbits-thermal-printer-tunnel.service \
    target/aarch64-unknown-linux-gnu/release/showbits-thermal-printer \
    bondrucker@spinch:
or return 1

echo

set_color --bold yellow
echo "#############"
echo "## Restart ##"
echo "#############"
set_color normal

ssh root@spinch "\
systemctl daemon-reload \
&& systemctl restart showbits-thermal-printer.service \
&& systemctl restart showbits-thermal-printer-tunnel.service \
"
