#!/bin/bash # # Build a Debian .deb package. set -euo pipefail cleanup() { rm -rf "$tmpdir" } # Get location where resulting files should be copied. if [ "$#" != 1 ] then echo "ERROR: must give location where build package should be copied as argument" 1>&2 exit 1 fi target="$(cd "$1"; pwd)" # Create a temporary directory and arrange for it to be deleted at the # end. tmpdir="$(mktemp -d)" echo "$tmpdir" trap cleanup EXIT # Get name and version of source package. name="$(dpkg-parsechangelog -SSource)" version="$(dpkg-parsechangelog -SVersion)" # Get upstream version: everythin before the last dash. uv="$(echo "$version" | sed 's/-[^-]*$//')" orig="${name}_${uv}.orig.tar.xz" # Build the package in a temporary diretory. git archive HEAD | xz > "$tmpdir/$orig" cd "$tmpdir" mkdir src tar -C src -xf "$orig" cd src dpkg-buildpackage -us -uc # Copy the results to the desired location. cp ../*_* "$target"