]> git.proxmox.com Git - debcargo-conf.git/blame - build.sh
Update termcolor, wincolor, TODO
[debcargo-conf.git] / build.sh
CommitLineData
1057693c
XL
1#!/bin/sh
2set -e
3
4abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
5
6if [ "$(basename "$PWD")" != "build" ]; then
7 abort 1 "This script is only meant to be run from the build/ directory."
8fi
9
10if [ -n "$DEBCARGO" ]; then
11 true
12elif which debcargo >/dev/null; then
13 DEBCARGO=$(which debcargo)
14elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
15 DEBCARGO="$HOME/.cargo/bin/debcargo"
16else
17 abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
18fi
19
20CRATE="$1"
21VER="$2"
22DISTRIBUTION="${DISTRIBUTION:-unstable}"
23
24PKGNAME=$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")
25DEBVER=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SVersion)
26DEBSRC=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SSource)
27DEBDIST=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SDistribution)
28DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH)
29if [ -z "$CHROOT" ] && schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then
30 CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
31fi
32
33shouldbuild() {
34 local dst="$1"
35 local src="$2"
36 test ! -e "$dst" -o "$src" -nt "$dst"
37}
38
39if shouldbuild ${DEBSRC}_${DEBVER}.dsc "$PKGNAME/debian/changelog" ]; then
40 ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign )
41 # sign if not UNRELEASED
42 if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
43 debsign ${DEBSRC}_${DEBVER}_source.changes
44 fi
45fi
46
47check_build_deps() {
48 mkdir -p dpkg-dummy
49 if shouldbuild dpkg-dummy/status /var/cache/apt/pkgcache.bin; then
50 # pretend dpkg status file that marks all packages as installed
51 # this is because dpkg-checkbuilddeps only works on installed pkgs
52 apt-cache dumpavail | \
53 sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status
54 fi
c7386c93 55 ( cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy )
1057693c
XL
56}
57
58if ! check_build_deps; then
59 abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
60fi
61
62if [ "$SOURCEONLY" = 1 ]; then
63 exit
64fi
65
66sbuild --no-source --arch-any --arch-all ${CHROOT:+-c $CHROOT }${DISTRIBUTION:+-d $DISTRIBUTION }${DEBSRC}_${DEBVER}.dsc
67changestool ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes adddsc ${DEBSRC}_${DEBVER}.dsc
68
69# sign if not UNRELEASED
70if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
71 debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes
72fi