]> git.ipfire.org Git - location/libloc.git/blob - debian/build.sh
importer: Fix potential SQL command injection
[location/libloc.git] / debian / build.sh
1 #!/bin/bash
2
3 ARCHITECTURES=( amd64 arm64 i386 armhf )
4 RELEASES=( buster bullseye bookworm sid )
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 if [ "${release}" = "buster" ]; then
42 local buster_backport=( --extra-repository "deb http://deb.debian.org/debian buster-backports main" --build-dep-resolver=aspcud )
43 fi
44
45 mkdir -p "${release}"
46 pushd "${release}"
47
48 # Create a chroot environment
49 if [ ! -d "/etc/sbuild/chroot/${chroot}" ]; then
50 if ! sbuild-createchroot --arch="${host_arch}" "${release}" \
51 "${CHROOT_PATH}/${chroot}"; then
52 echo "Could not create chroot for ${release} on ${host_arch}" >&2
53 rm -rf "${tmp}"
54 return 1
55 fi
56 fi
57
58 # And for each architecture we want to support
59 local arch
60 for arch in ${ARCHITECTURES[@]}; do
61 mkdir -p "${arch}"
62 pushd "${arch}"
63
64 # Copy sources
65 cp -r "${tmp}/sources" .
66
67 # Run the build process
68 if ! sbuild --dist="${release}" --host="${arch}" --source "${buster_backport[@]}" "sources/${package}"; then
69 echo "Could not build package for ${release} on ${arch}" >&2
70 rm -rf "${tmp}"
71 return 1
72 fi
73
74 # Remove the sources
75 rm -rf "sources/${package}"
76 popd
77 done
78 popd
79 done
80
81 # Remove sources
82 rm -rf "${tmp}/sources"
83 popd
84
85 # Done!
86 echo "SUCCESS!"
87 echo " You can find your Debian packages in ${tmp}"
88 return 0
89 }
90
91 main "$@" || exit $?