#!/bin/bash

DESTDIR=./dist
VERSION=$(git describe --tag | sed 's/^v//')
ITERATION=3
NAME=scw-cap
#DOCKER_IMAGE=registry.scw.systems/debian-build:latest
DOCKER_IMAGE=debian-build:1.17-buster

rm -rf $DESTDIR
install -d $DESTDIR/{usr/bin,etc/systemd/system,etc/$NAME,usr/share/$NAME}
make all-debian

install -m 755 munchclient $DESTDIR/usr/bin/$NAME
install -m 644 munchclient.toml $DESTDIR/etc/$NAME/$NAME.toml
install -m 644 munchclient.toml $DESTDIR/usr/share/$NAME/$NAME.toml
# install -m 644 munchclient.service $DESTDIR/etc/systemd/system/$NAME.service
# install -m 644 ca-chain.cert.pem $DESTDIR/usr/share/$NAME/

docker run -i -t --rm -v $PWD:/go/src/git.scraperwall.com/scw/munchclient -w /go/src/git.scraperwall.com/scw/munchclient $DOCKER_IMAGE \
fpm -s dir -t deb -C $DESTDIR --name $NAME \
  --version $VERSION \
  --iteration $ITERATION \
  --deb-systemd $NAME.service \
  --description "ScraperWall Packet Capture" \
  --config-files /etc/$NAME/$NAME.toml \
  -p ./debian

rm -rf $DESTDIR

