]> git.ipfire.org Git - people/ms/libloc.git/blob - debian/build.sh
debian: build.sh: Stop printing every command that is executed
[people/ms/libloc.git] / debian / build.sh
1 #!/bin/bash
2
3 ARCHITECTURES=( amd64 arm64 i386 armhf )
4 RELEASES=( buster bullseye )
5
6 CHROOT_PATH="/var/tmp"
7
8 main() {
9 if [ $# -lt 2 ]; then
10 echo "Not enough arguments" >&2
11 return 2
12 fi
13
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
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
28 mkdir -p "${tmp}/sources"
29 tar xvfa "${sources}" -C "${tmp}/sources"
30
31 # Copy the tarball under the correct Debian name
32 cp -vf "${sources}" "${tmp}/sources/${package//-/_}.orig.tar.xz"
33
34 # Change into temporary directory
35 pushd "${tmp}"
36
37 # Build the package for each release
38 local release
39 for release in ${RELEASES[@]}; do
40 local chroot="${release}-${host_arch}-sbuild"
41
42 mkdir -p "${release}"
43 pushd "${release}"
44
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
50 rm -rf "${tmp}"
51 return 1
52 fi
53 fi
54
55 # And for each architecture we want to support
56 local arch
57 for arch in ${ARCHITECTURES[@]}; do
58 mkdir -p "${arch}"
59 pushd "${arch}"
60
61 # Copy sources
62 cp -r "${tmp}/sources" .
63
64 # Run the build process
65 if ! sbuild --dist="${release}" --host="${arch}" --source "sources/${package}"; then
66 echo "Could not build package for ${release} on ${arch}" >&2
67 rm -rf "${tmp}"
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 # Done!
83 echo "SUCCESS!"
84 echo " You can find your Debian packages in ${tmp}"
85 return 0
86 }
87
88 main "$@" || exit $?