]> git.ipfire.org Git - fireperf.git/commitdiff
debian: Add tooling to build packages for various releases and architectures
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Feb 2021 22:45:59 +0000 (22:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Feb 2021 22:45:59 +0000 (22:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
debian/build.sh [new file with mode: 0644]

index c3096781fa87320486b3ca40e2ca755288156913..bafa5356c6fcdf398ecf4148392232dddea5e737 100644 (file)
@@ -126,3 +126,15 @@ man/%.html: man/%.txt man/asciidoc.conf
 .PHONY: upload-man
 upload-man: $(MANPAGES_HTML)
        rsync -avHz --delete --progress $(MANPAGES_HTML) ms@fs01.haj.ipfire.org:/pub/man-pages/$(PACKAGE_NAME)/
+
+EXTRA_DIST += \
+       debian/build.sh \
+       debian/changelog \
+       debian/compat \
+       debian/control \
+       debian/copyright \
+       debian/rules
+
+.PHONY: debian
+debian: dist
+       $(SHELL) debian/build.sh $(PACKAGE_NAME)-$(PACKAGE_VERSION) $(distdir).tar.xz
diff --git a/debian/build.sh b/debian/build.sh
new file mode 100644 (file)
index 0000000..4385455
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+ARCHITECTURES=( amd64 arm64 i386 armhf )
+RELEASES=( buster bullseye sid )
+
+CHROOT_PATH="/var/tmp"
+
+main() {
+    if [ $# -lt 2 ]; then
+        echo "Not enough arguments" >&2
+        return 2
+    fi
+
+    # Get host architecture
+    local host_arch="$(dpkg --print-architecture)"
+    if [ -z "${host_arch}" ]; then
+        echo "Could not discover host architecture" >&2
+        return 1
+    fi
+
+    local package="${1}"
+    local sources="${2}"
+
+    # Create some temporary directory
+    local tmp="$(mktemp -d)"
+
+    # Extract the sources into it
+    mkdir -p "${tmp}/sources"
+    tar xvfa "${sources}" -C "${tmp}/sources"
+
+    # Copy the tarball under the correct Debian name
+    cp -vf "${sources}" "${tmp}/sources/${package//-/_}.orig.tar.xz"
+
+    # Change into temporary directory
+    pushd "${tmp}"
+
+    # Build the package for each release
+    local release
+    for release in ${RELEASES[@]}; do
+        local chroot="${release}-${host_arch}-sbuild"
+
+        mkdir -p "${release}"
+        pushd "${release}"
+
+        # Create a chroot environment
+        if [ ! -d "/etc/sbuild/chroot/${chroot}" ]; then
+            if ! sbuild-createchroot --arch="${host_arch}" "${release}" \
+                    "${CHROOT_PATH}/${chroot}"; then
+                echo "Could not create chroot for ${release} on ${host_arch}" >&2
+                rm -rf "${tmp}"
+                return 1
+            fi
+        fi
+
+        # And for each architecture we want to support
+        local arch
+        for arch in ${ARCHITECTURES[@]}; do
+            mkdir -p "${arch}"
+            pushd "${arch}"
+
+            # Copy sources
+            cp -r "${tmp}/sources" .
+
+            # Run the build process
+            if ! sbuild --dist="${release}" --host="${arch}" --source "sources/${package}"; then
+                echo "Could not build package for ${release} on ${arch}" >&2
+                rm -rf "${tmp}"
+                return 1
+            fi
+
+            # Remove the sources
+            rm -rf "sources/${package}"
+            popd
+        done
+        popd
+    done
+
+    # Remove sources
+    rm -rf "${tmp}/sources"
+    popd
+
+    # Done!
+    echo "SUCCESS!"
+    echo "  You can find your Debian packages in ${tmp}"
+    return 0
+}
+
+main "$@" || exit $?