]> git.ipfire.org Git - location/libloc.git/blob - debian/build.sh
debian: Add script to build package for various arches
[location/libloc.git] / debian / build.sh
1 #!/bin/bash
2
3 set -x
4
5 ARCHITECTURES=( amd64 arm64 i386 armhf riscv64 )
6 RELEASES=( buster )
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 local package="${1}"
17 local sources="${2}"
18
19 # Create some temporary directory
20 local tmp="$(mktemp -d)"
21
22 # Extract the sources into it
23 tar xvfa "${sources}" -C "${tmp}"
24
25 # Copy the tarball under the correct Debian name
26 cp -vf "${sources}" "${tmp}/${package//-/_}.orig.tar.xz"
27
28 # Change into source directory
29 pushd "${tmp}/${package}"
30
31 # Prepare the build environment
32 #if ! debuild -us -uc; then
33 # echo "Could not prepare build environment" >&2
34 # return 1
35 #fi
36
37 # Build the package for each release
38 local release
39 for release in ${RELEASES[@]}; do
40 # And for each architecture we want to support
41 local arch
42 for arch in ${ARCHITECTURES[@]}; do
43 local chroot="${release}-${arch}-sbuild"
44
45 # Create a chroot environment
46 if [ ! -d "/etc/sbuild/chroot/${chroot}" ]; then
47 if ! sbuild-createchroot --arch="${arch}" "${release}" \
48 "${CHROOT_PATH}/${chroot}"; then
49 echo "Could not create chroot for ${release} on ${arch}" >&2
50 return 1
51 fi
52 fi
53
54 # Run the build process
55 if ! sbuild --dist="${release}" --host="${arch}"; then
56 echo "Could not build package for ${release} on ${arch}" >&2
57 return 1
58 fi
59 done
60 done
61
62 popd
63
64 # Cleanup
65 rm -rf "${tmp}"
66 }
67
68 main "$@" || exit $?