#!/bin/bash

cd $(dirname $0)

chmod a+x rpi/*.sh

# build and cleanup rpi-server
cd rpi-server
yarn install
yarn build
rm -rf node_modules
yarn install --production --frozen-lockfile

# build and cleanup webapp
cd ../webapp
yarn install
yarn build
rm -rf node_modules
yarn install --production --frozen-lockfile

# delete all prebuilds for other architectures (otherwise error by dh_strip)
cd ../
find . -name "*.node" | grep -E '^.+((linux|darwin|windows)-(x64|ia32|arm(64-musl|\/))|darwin-arm64).+\.node$' | xargs rm

# build deb
dpkg-buildpackage