#!/usr/bin/env bash

VERSION=$1

mkdir -p deb-package
cd deb-package

mkdir -p "jilo-web-$VERSION/DEBIAN"
cp ../deb-control "jilo-web-$VERSION/DEBIAN/control"
cp ../deb-postinst "jilo-web-$VERSION/DEBIAN/postinst"
cp ../deb-postrm "jilo-web-$VERSION/DEBIAN/postrm"
cp ../deb-templates "jilo-web-$VERSION/DEBIAN/templates"

mkdir -p "jilo-web-$VERSION/etc/jilo-web"
cp ../../jilo-web.conf.php "jilo-web-$VERSION/etc/jilo-web/jilo-web.conf.php"
cp ../../jilo-web.schema "jilo-web-$VERSION/etc/jilo-web/jilo-web.schema"

mkdir -p "jilo-web-$VERSION/usr/share/jilo-web"
cp -r ../../public_html/* "jilo-web-$VERSION/usr/share/jilo-web"

mkdir -p "jilo-web-$VERSION/usr/share/doc/jilo-web"
cp ../deb-README.debian "jilo-web-$VERSION/usr/share/doc/jilo-web/"
cp ../../CHANGELOG.md "jilo-web-$VERSION/usr/share/doc/jilo-web/"
cp ../../LICENSE "jilo-web-$VERSION/usr/share/doc/jilo-web/"
cp ../../README.md "jilo-web-$VERSION/usr/share/doc/jilo-web/"
cp ../../TODO.md "jilo-web-$VERSION/usr/share/doc/jilo-web/"
cp ../../config.apache "jilo-web-$VERSION/usr/share/doc/jilo-web/"
cp ../../config.nginx "jilo-web-$VERSION/usr/share/doc/jilo-web/"

mkdir -p "jilo-web-$VERSION/usr/share/man/man8"
cp ../man-jilo-web.8 "jilo-web-$VERSION/usr/share/man/man8/jilo-web.8"

dpkg-deb --build "jilo-web-$VERSION"

rm -rf "jilo-web-$VERSION/"