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