icinga-build-deb-binary 2.91 KB
Newer Older
Markus Frosch's avatar
Markus Frosch committed
1
2
3
#!/bin/bash

set -e
4
5
# shellcheck source=functions-debian.sh
. "$(dirname "$(readlink -f "$0")")"/functions-debian.sh
Markus Frosch's avatar
Markus Frosch committed
6
7

# enabling ccache
8
echo "[ enabling ccache ]"
Markus Frosch's avatar
Markus Frosch committed
9
10
PATH=/usr/lib/ccache:"$PATH"
export CCACHE_DIR="${WORKDIR}/ccache"
11
12
13
14
15
16
env | grep -E '^(PATH=|CCACHE)'

if [ -x /usr/sbin/update-ccache-symlinks ]; then
  echo "Running update-ccache-symlinks"
  sudo /usr/sbin/update-ccache-symlinks
fi
Markus Frosch's avatar
Markus Frosch committed
17

Markus Frosch's avatar
Markus Frosch committed
18
19
# reset ccache statistics
# so we now the statistics of the new build
20
21
22
if [ -d "${CCACHE_DIR}" ]; then
  ccache -z # (--zero-stats)
fi
Markus Frosch's avatar
Markus Frosch committed
23

24
25
# use eatmydata if present
eatmydata=
26
if command -v eatmydata >/dev/null; then
27
28
29
  eatmydata=eatmydata
fi

30
31
32
33
34
35
if [ -n "$ICINGA_BUILD_APTCACHER" ]; then
  echo "[ enable apt-cacher ]"
  echo "Acquire::http::Proxy \"${ICINGA_BUILD_APTCACHER}\";" | sudo tee /etc/apt/apt.conf.d/999cache
  echo
fi

Markus Frosch's avatar
Markus Frosch committed
36
echo "[ apt-get update ]"
37
38
39
# absolute apt-get path because of
# "eatmydata: unable to find 'apt-get' in PATH" on Ubuntu Hirsute
sudo $eatmydata /usr/bin/apt-get update
Markus Frosch's avatar
Markus Frosch committed
40
41
42
43
44

echo "[ Extracting source to build directory ]"
(
  set -ex
  cd "${BUILDDIR}/"
45
46
47
48
49
50
  set -e
  if [ -d "${ICINGA_BUILD_PROJECT}" ]; then
    set -x
    chmod -R u+w "${ICINGA_BUILD_PROJECT}"
  fi
  set -x
Markus Frosch's avatar
Markus Frosch committed
51
  rm -rf "${ICINGA_BUILD_PROJECT}"
52
  dpkg-source -x ./*.dsc "${ICINGA_BUILD_PROJECT}"
Markus Frosch's avatar
Markus Frosch committed
53
54
55
56
57
58
)

echo "[ Installing build dependencies ]"
(
  set -ex
  cd "${BUILDDIR}/${ICINGA_BUILD_PROJECT}"
59
60
61
62
63
  if [[ "$(uname -m)" = arm* ]]; then
    # avoid aptitude, since it crashed with qemu-arm-static for some reason...
    # qemu:handle_cpu_signal received signal outside vCPU context
    sudo DEBIAN_FRONTEND=noninteractive $eatmydata /usr/lib/pbuilder/pbuilder-satisfydepends-experimental
  elif command -v aptitude >/dev/null && [ -x /usr/lib/pbuilder/pbuilder-satisfydepends-aptitude ]; then
64
    sudo DEBIAN_FRONTEND=noninteractive $eatmydata /usr/lib/pbuilder/pbuilder-satisfydepends-aptitude
65
  else
66
    sudo DEBIAN_FRONTEND=noninteractive $eatmydata /usr/lib/pbuilder/pbuilder-satisfydepends
67
  fi
Markus Frosch's avatar
Markus Frosch committed
68
69
70
71
)

# Building the package
binopts=
72
if [ "${ICINGA_BUILD_ARCH}" != "${ICINGA_BUILD_DEB_DEFAULT_ARCH}" ]; then
Markus Frosch's avatar
Markus Frosch committed
73
74
75
76
77
78
79
80
81
  binopts="-B"
fi

echo "[ Building binary package ]"
(
  set -ex
  cd "${BUILDDIR}/${ICINGA_BUILD_PROJECT}"
  dpkg-buildpackage -rfakeroot -uc -us $binopts
)
82

83
84
85
86
87
88
89
90
91
92
93
if [ -d "${CCACHE_DIR}" ]; then
  cached_files="$(find "${CCACHE_DIR}" -type f ! -name ccache.conf ! -name stats | wc -l)"
  if [ "$cached_files" -eq 0 ]; then
    echo "Removing empty ccache dir: ${CCACHE_DIR}"
    rm -rf "${CCACHE_DIR}"
  else
    echo "[ ccache stats ]"
    ccache -s | tee build/ccache-stats.txt # (--show-stats)
    echo
  fi
fi
Markus Frosch's avatar
Markus Frosch committed
94

95
96
97
98
99
100
echo "[ Running Lintian ]"
(
  set -ex
  cd "${BUILDDIR}/${ICINGA_BUILD_PROJECT}/"
  lintian | tee ../lintian-binary.log
) || [ "${ICINGA_BUILD_IGNORE_LINT}" -eq 1 ]
101

102
103
104
105
if [ "${ICINGA_BUILD_CLEANUP:=1}" -gt 0 ]; then
  echo "[ Cleanup Build Directory ]"
  (
    set -ex
106
    chmod -R u+w "${BUILDDIR:?}/${ICINGA_BUILD_PROJECT}/"
107
108
109
    rm -rf "${BUILDDIR:?}/${ICINGA_BUILD_PROJECT}/"
  )
fi