Files
bootstrap-build-environment/resolve-debbuilddeps.sh

79 lines
2.1 KiB
Bash
Raw Normal View History

2015-09-04 13:04:57 +00:00
#! /bin/bash -ex
## @id $Id$
## Resolve Debian Build Dependencies
## Installs all the required packages
2015-09-09 15:01:15 +00:00
## Call: ./resolve-debbuilddeps 'name of build schroot'
## e.g. call: ./resolve-debbuilddeps trusty_amd64
2015-09-04 13:04:57 +00:00
## 1 2 3 4 5 6 7 8
## 45678901234567890123456789012345678901234567890123456789012345678901234567890
SCHROOTNAME="$1"
2015-11-11 12:45:31 +00:00
if test -n "${SCHROOTNAME}"; then
DO="schroot -c "${SCHROOTNAME}" --"
SUDO="schroot -c "${SCHROOTNAME}" -u root -d / --"
else
DO=""
2016-11-25 17:28:07 +00:00
if grep -q '/docker' /proc/1/cgroup; then
2015-12-14 12:29:33 +00:00
SUDO=""
else
SUDO="sudo"
fi
2015-11-11 12:45:31 +00:00
fi
2015-09-04 13:04:57 +00:00
2015-11-03 15:06:39 +00:00
function install() {
2015-11-11 12:45:31 +00:00
if ${SUDO} apt-get -y install $*; then
return 0
2015-11-03 15:06:39 +00:00
else
2015-11-11 12:45:31 +00:00
return 1
2015-11-03 15:06:39 +00:00
fi
}
TO_INSTALL=
2017-02-06 22:55:20 +00:00
DEPS=
2015-11-03 15:06:39 +00:00
if test -e debian/control.in -a ! -e debian/control; then
2015-11-03 15:06:39 +00:00
for f in $(sed -n 's, *AX_DEB_DEPEND_IFEXISTS(\([^)]*\)).*,\1,p' configure.ac); do
2016-12-19 18:06:02 +00:00
if test -n "$(${DO} apt-cache policy -q ${f})" && ((! $(${DO} apt-cache policy ${f} 2>&1 | grep -q 'N: Unable to locate package')) && (! ${DO} dpkg -l "${f}")); then
2017-02-06 22:55:20 +00:00
DEPS+=" ${f}"
2015-11-03 15:06:39 +00:00
fi
done
2017-02-06 22:55:20 +00:00
for f in $(sed -n 's, *AX_DEB_BUILD_DEPEND(\([^)]*\)).*,\1,p' configure.ac); do
DEPS+=" ${f}"
done
trap "rm debian/control" INT TERM EXIT
2017-02-06 22:55:20 +00:00
sed 's,@\(DEB_DEPEND_IFEXISTS\|DEB_BUILD_DEPEND\|DEB_DEPEND\)@,,g' debian/control.in | \
2015-11-03 15:06:39 +00:00
sed 's,@[^@]*@, dummytext,g' > debian/control
fi
2015-09-04 13:04:57 +00:00
2015-11-11 12:45:31 +00:00
install dpkg-dev
2017-02-06 22:55:20 +00:00
DEPS+=" $(LANG= ${DO} dpkg-checkbuilddeps 2>&1 | sed -n '/Unmet build dependencies/ { s,.*Unmet build dependencies: ,,g; s, ([^)]*),,g; s, *| *,|,g; p}')"
2015-09-04 13:04:57 +00:00
for pa in ${DEPS}; do
if test ${pa//|/} = ${pa}; then
TO_INSTALL+=" ${pa}"
continue;
fi
2015-09-04 13:04:57 +00:00
success=0
for p in ${pa//|/ }; do
2015-11-03 15:06:39 +00:00
if install ${TO_INSTALL} ${p}; then
TO_INSTALL+=" ${p}"
success=1
break
2015-09-04 13:04:57 +00:00
fi
done
if test ${success} -eq 0; then
echo "**** Error: Installation Failed: ${pa}"
exit 1
2015-09-04 13:04:57 +00:00
fi
done
2015-11-03 15:06:39 +00:00
if test -n "${TO_INSTALL}" && ! install ${TO_INSTALL}; then
echo "**** Error: Installation Failed: ${TO_INSTALL}"
exit 1
fi
2015-09-04 13:04:57 +00:00
echo "**** Success: All Dependencies Resolved"