| 1 |
#! /bin/bash |
| 2 |
# pbuilder -- personal Debian package builder |
| 3 |
# Copyright © 2001-2007 Junichi Uekawa <[email protected]> |
| 4 |
# 2006-2007 Loïc Minier <[email protected]> |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
############################################################################### |
| 20 |
|
| 21 |
# module to satisfy build dependencies; experimental flavor |
| 22 |
|
| 23 |
# can test this with: |
| 24 |
# testsuite/random-manual-test-material/build-depends-on-experimental: |
| 25 |
# sudo pbuilder --build --configfile config bde_0.1.dsc |
| 26 |
|
| 27 |
set -e |
| 28 |
|
| 29 |
. "${BASH_SOURCE%/*}/pbuilder-satisfydepends-funcs" |
| 30 |
|
| 31 |
# Use this function to fulfill the dependency (almost) |
| 32 |
function checkbuilddep_internal () { |
| 33 |
local ARCH=$($CHROOTEXEC dpkg-architecture -qDEB_HOST_ARCH) |
| 34 |
local INSTALLPKG |
| 35 |
local INSTALLPKGLIST |
| 36 |
local INSTALLPKGMULTI |
| 37 |
local CURRENTREALPKGNAME |
| 38 |
local SATISFIED |
| 39 |
local PACKAGEVERSIONS |
| 40 |
local CANDIDATE_VERSION |
| 41 |
local APTFLAG="-o APT::Install-Recommends=false" |
| 42 |
echo " -> Attempting to parse the build-deps" |
| 43 |
for INSTALLPKGMULTI in $(get_build_deps | |
| 44 |
tr " " "/" | \ |
| 45 |
awk 'BEGIN{RS=","} {print}'); do |
| 46 |
echo " -> Considering build-dep$(echo "$INSTALLPKGMULTI" | tr "/" " " )" |
| 47 |
SATISFIED="no" |
| 48 |
for INSTALLPKG in $(echo "$INSTALLPKGMULTI" | \ |
| 49 |
awk 'BEGIN{RS="|"} {print}'); do |
| 50 |
CURRENTREALPKGNAME=$(echo "$INSTALLPKG" | sed -e 's#^/*##' -e 's#[[/(].*##') |
| 51 |
if echo "$INSTALLPKG" | grep -q '\['; then |
| 52 |
if checkbuilddep_archdeps "$INSTALLPKG" "$ARCH"; then |
| 53 |
SATISFIED="yes" |
| 54 |
echo " -> This package is not for this architecture" |
| 55 |
continue |
| 56 |
fi |
| 57 |
fi |
| 58 |
if echo "$INSTALLPKG" | grep -q '<'; then |
| 59 |
if checkbuilddep_restrictiondeps "$INSTALLPKG" "$DEB_BUILD_PROFILES"; then |
| 60 |
SATISFIED="yes" |
| 61 |
echo " -> This package is not for the current build profiles" |
| 62 |
continue |
| 63 |
fi |
| 64 |
fi |
| 65 |
|
| 66 |
CURRENT_APT_COMMAND="$(versioneddep_to_aptcmd "$INSTALLPKG")" |
| 67 |
|
| 68 |
while [ "$SATISFIED" = "no" ]; do |
| 69 |
echo " -> Trying to add $CURRENT_APT_COMMAND" |
| 70 |
if APT_OUTPUT="$( exec 2>&1; LC_ALL=C $CHROOTEXEC apt-get -s install $APTFLAG $INSTALLPKGLIST $CURRENT_APT_COMMAND )"; then |
| 71 |
# success, we're done |
| 72 |
SATISFIED="yes" |
| 73 |
INSTALLPKGLIST="$INSTALLPKGLIST $CURRENT_APT_COMMAND" |
| 74 |
break |
| 75 |
fi |
| 76 |
# try to parse APT's output to recognize lines such as: |
| 77 |
# libfoo-dev: Depends: bar (>= xyz) but www is to be installed |
| 78 |
DEP_INSTALLPKG="$(echo "$APT_OUTPUT" | \ |
| 79 |
sed -n \ |
| 80 |
-e "s/^ *.*: *Depends: *\(.*\) but.*is to be installed\$/\\1/p" \ |
| 81 |
-e "s/^ *.*: *Depends: *\(.*\) but it is not going to be installed\$/\\1/p" \ |
| 82 |
-e "s/^ *.*: *Depends: *\(.*\)\$/\\1/p" | \ |
| 83 |
head -1 | \ |
| 84 |
tr " " "/")" |
| 85 |
APT_ADD_COMMAND="$(versioneddep_to_aptcmd "$DEP_INSTALLPKG")" |
| 86 |
if echo "$CURRENT_APT_COMMAND" | grep -q "$APT_ADD_COMMAND"; then |
| 87 |
# loop detected, give up with real packages |
| 88 |
echo " -> Loop detected, last APT error was: ======" |
| 89 |
echo "$APT_OUTPUT" |
| 90 |
echo " -> =========================================" |
| 91 |
echo " -> (not adding $APT_ADD_COMMAND to $CURRENT_APT_COMMAND)" |
| 92 |
break |
| 93 |
fi |
| 94 |
CURRENT_APT_COMMAND="$CURRENT_APT_COMMAND $APT_ADD_COMMAND" |
| 95 |
done |
| 96 |
if [ "$SATISFIED" = "yes" ]; then |
| 97 |
break; |
| 98 |
fi |
| 99 |
|
| 100 |
echo " -> Cannot install $CURRENT_APT_COMMAND; apt errors follow:" |
| 101 |
if $CHROOTEXEC apt-get -s install $APTFLAG $INSTALLPKGLIST "$CURRENT_APT_COMMAND"; then |
| 102 |
: |
| 103 |
fi |
| 104 |
# package could not be found. -- looking for alternative. |
| 105 |
PROVIDED="" |
| 106 |
checkbuilddep_provides "$CURRENTREALPKGNAME" |
| 107 |
if [ -n "$PROVIDED" ]; then |
| 108 |
# something provides this package |
| 109 |
echo " -> Considering $PROVIDED to satisfy the dependency " |
| 110 |
if $CHROOTEXEC apt-get -s install $APTFLAG $INSTALLPKGLIST $PROVIDED >& /dev/null; then |
| 111 |
SATISFIED="yes"; |
| 112 |
INSTALLPKGLIST="$INSTALLPKGLIST $PROVIDED" |
| 113 |
else |
| 114 |
# show the error for diagnostic purposes |
| 115 |
echo " -> Cannot install $PROVIDED; apt errors follow:" |
| 116 |
if $CHROOTEXEC apt-get -s install $APTFLAG $INSTALLPKGLIST $PROVIDED; then |
| 117 |
: |
| 118 |
fi |
| 119 |
fi |
| 120 |
fi |
| 121 |
if [ "$SATISFIED" = "yes" ]; then |
| 122 |
break; |
| 123 |
fi |
| 124 |
done; |
| 125 |
if [ "$SATISFIED" = "no" ]; then |
| 126 |
echo "E: Could not satisfy build-dependency." >&2 |
| 127 |
if [ "$CONTINUE_FAIL" != "yes" ]; then |
| 128 |
exit 2 |
| 129 |
fi |
| 130 |
fi |
| 131 |
done; |
| 132 |
|
| 133 |
# now actually install the packages |
| 134 |
echo " -> Installing $INSTALLPKGLIST" |
| 135 |
if ! $CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" $APTFLAG install $INSTALLPKGLIST; then |
| 136 |
echo " -> Trying to fix apt error" |
| 137 |
# Work around an apt bug which causes configure to fail. |
| 138 |
if $CHROOTEXEC dpkg --configure --pending && $CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" $APTFLAG install $INSTALLPKGLIST; then |
| 139 |
echo " -> Apt bug workaround succeeded" |
| 140 |
elif [ "$CONTINUE_FAIL" != "yes" ]; then |
| 141 |
echo "E: Unrecoverable error installing build-dependencies." >&2 |
| 142 |
exit 1 |
| 143 |
fi |
| 144 |
fi |
| 145 |
|
| 146 |
# start processing build-conflicts. |
| 147 |
for INSTALLPKG in $(get_build_conflicts | |
| 148 |
tr " " "/" | \ |
| 149 |
awk 'BEGIN{RS=","} {print}'); do |
| 150 |
CURRENTREALPKGNAME=$(echo "$INSTALLPKG" | sed -e 's#^/*##' -e 's#[[/(].*##') |
| 151 |
echo " -> Considering $CURRENTREALPKGNAME" |
| 152 |
|
| 153 |
if echo "$INSTALLPKG" | grep -q '\['; then |
| 154 |
# this package has arch-conflicts. |
| 155 |
if checkbuilddep_archdeps "$INSTALLPKG" "$ARCH"; then |
| 156 |
echo "I: Ignoring other-arch" |
| 157 |
continue |
| 158 |
fi |
| 159 |
fi |
| 160 |
if echo "$INSTALLPKG" | grep -q '<'; then |
| 161 |
# this package has build-profiles-conflicts. |
| 162 |
if checkbuilddep_restrictiondeps "$INSTALLPKG" "$DEB_BUILD_PROFILES"; then |
| 163 |
echo "I: Ignoring other-buildprofiles" |
| 164 |
continue |
| 165 |
fi |
| 166 |
fi |
| 167 |
if echo "$INSTALLPKG" | grep -q '('; then |
| 168 |
# this package has version-conflicts |
| 169 |
if ! checkbuilddep_versiondeps $CURRENTREALPKGNAME \ |
| 170 |
$(echo "$INSTALLPKG" | tr "/" " " | sed 's/^.*( *\(<<\|<=\|>=\|=\|<\|>>\|>\) *\(.*\)).*$/\1/') \ |
| 171 |
$(echo "$INSTALLPKG" | tr "/" " " | sed 's/^.*( *\(<<\|<=\|>=\|=\|<\|>>\|>\) *\(.*\)).*$/\2/'); then |
| 172 |
echo "I: Satisfies version, not trying" |
| 173 |
continue |
| 174 |
fi |
| 175 |
fi |
| 176 |
|
| 177 |
# if package exists, remove it. |
| 178 |
if $CHROOTEXEC dpkg -s $(echo "$INSTALLPKG" | tr "/" " " | awk '{print $1}') 2>&1 | grep -q ^Package:; then |
| 179 |
if ! $CHROOTEXEC apt-get -q -y remove $CURRENTREALPKGNAME ; then |
| 180 |
echo "E: Could not satisfy build-conflicts" >&2 |
| 181 |
exit 1 |
| 182 |
fi |
| 183 |
else |
| 184 |
echo "I: $CURRENTREALPKGNAME package is not installed, no need to remove" |
| 185 |
fi |
| 186 |
done |
| 187 |
echo " -> Finished parsing the build-deps" |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
function print_help () { |
| 192 |
# print out help message |
| 193 |
cat <<EOF |
| 194 |
pbuilder-satisfydepends -- satisfy dependencies |
| 195 |
Copyright 2002-2007 Junichi Uekawa <[email protected]> |
| 196 |
|
| 197 |
--help: give help |
| 198 |
--control: specify control file (debian/control, *.dsc) |
| 199 |
--chroot: operate inside chroot |
| 200 |
--binary-all: include binary-all |
| 201 |
--binary-arch: include binary-arch only |
| 202 |
--echo: echo mode, do nothing. (--force-version required for most operation) |
| 203 |
--force-version: skip version check. |
| 204 |
--continue-fail: continue even when failed. |
| 205 |
|
| 206 |
EOF |
| 207 |
} |
| 208 |
|
| 209 |
. "${BASH_SOURCE%/*}/pbuilder-satisfydepends-checkparams" |
| 210 |
|