#! /bin/bash -euv

# Convenience variables.
package=fmtools
home="`pwd`"
dest=debian/tmp
pkgdocdir=$dest/usr/doc/$package

# Make dir.
rm -rf $dest
install -d -m755 $dest

# Install binary.
install -d $dest/usr/bin
install -s fm $dest/usr/bin

# Install manpages.
install -d $dest/usr/man/man1
install -m644 fm.1 $dest/usr/man/man1
gzip -9v $dest/usr/man/man1/*

# Copy docs.
install -d -m755 $pkgdocdir
install -m644 README $pkgdocdir
install -m644 debian/changelog $pkgdocdir/changelog.Debian
gzip -9v $pkgdocdir/*

# Copy copyright.
install -m644 debian/copyright $pkgdocdir/copyright

# Dependencies.
install -d -m755 $dest/DEBIAN
dpkg-shlibdeps fm
dpkg-gencontrol

# Set group, owner, and permissions.
chown -R root.root $dest
chmod -R go=rX $dest

# Make the package.
dpkg --build $dest ..
