]> git.ipfire.org Git - people/ms/libloc.git/blob - debian/build.sh
debian: unstable is called bullseye
[people/ms/libloc.git] / debian / build.sh
1 #!/bin/bash
2
3 set -x
4
5 ARCHITECTURES=( amd64 arm64 i386 armhf )
6 RELEASES=( buster bullseye )
7
8 CHROOT_PATH="/var/tmp"
9
10 main() {
11 if [ $# -lt 2 ]; then
12 echo "Not enough arguments" >&2
13 return 2
14 fi
15
16 # Get host architecture
17 local host_arch="$(dpkg --print-architecture)"
18 if [ -z "${host_arch}" ]; then
19 echo "Could not discover host architecture" >&2
20 return 1
21 fi
22
23 local package="${1}"
24 local sources="${2}"
25
26 # Create some temporary directory
27 local tmp="$(mktemp -d)"
28
29 # Extract the sources into it
30 mkdir -p "${tmp}/sources"
31 tar xvfa "${sources}" -C "${tmp}/sources"
32
33 # Copy the tarball under the correct Debian name
34 cp -vf "${sources}" "${tmp}/sources/${package//-/_}.orig.tar.xz"
35
36 # Change into temporary directory
37 pushd "${tmp}"
38
39 # Build the package for each release
40 local release
41 for release in ${RELEASES[@]}; do
42 local chroot="${release}-${host_arch}-sbuild"
43
44 mkdir -p "${release}"
45 pushd "${release}"
46
47 # Create a chroot environment
48 if [ ! -d "/etc/sbuild/chroot/${chroot}" ]; then
49 if ! sbuild-createchroot --arch="${host_arch}" "${release}" \
50 "${CHROOT_PATH}/${chroot}"; then
51 echo "Could not create chroot for ${release} on ${host_arch}" >&2
52 return 1
53 fi
54 fi
55
56 # And for each architecture we want to support
57 local arch
58 for arch in ${ARCHITECTURES[@]}; do
59 mkdir -p "${arch}"
60 pushd "${arch}"
61
62 # Copy sources
63 cp -r "${tmp}/sources" .
64
65 # Run the build process
66 if ! sbuild --dist="${release}" --host="${arch}" --source "sources/${package}"; then
67 echo "Could not build package for ${release} on ${arch}" >&2
68 return 1
69 fi
70
71 # Remove the sources
72 rm -rf "sources/${package}"
73 popd
74 done
75 popd
76 done
77
78 # Remove sources
79 rm -rf "${tmp}/sources"
80 popd
81
82 # Cleanup
83 rm -rf "${tmp}"
84 }
85
86 main "$@" || exit $?