| 1 |
#! /bin/bash |
| 2 |
# pbuilder -- personal Debian package builder |
| 3 |
# Copyright © 2001-2007 Junichi Uekawa <[email protected]> |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 2 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
############################################################################### |
| 19 |
|
| 20 |
# The original pbuilder-satisfydepends code, which is now called 'classic' |
| 21 |
|
| 22 |
set -e |
| 23 |
|
| 24 |
export PBUILDER_PKGLIBDIR="${PBUILDER_PKGLIBDIR:-$PBUILDER_ROOT/usr/lib/pbuilder}" |
| 25 |
|
| 26 |
. "$PBUILDER_PKGLIBDIR"/pbuilder-satisfydepends-funcs |
| 27 |
|
| 28 |
# splits lines of deps (possibly with alternates) separated by commas into one |
| 29 |
# dep (possibly with alternates) per line; also changes all spaces to slashes |
| 30 |
# first as to iterate on deps with "for"; e.g. "foo, bar | baz", "foobar (>= |
| 31 |
# 2)" becomes "foo", "bar/|/baz", "foobar/(>=/2)" |
| 32 |
split_deps() { |
| 33 |
sed 's#, *#\n#g; s# #/#g' |
| 34 |
} |
| 35 |
# and build-conflicts |
| 36 |
|
| 37 |
# splits build-dep with alternates into one alternate per line; e.g. "foo|bar" |
| 38 |
# becomes "foo", "bar" |
| 39 |
split_alternates() { |
| 40 |
echo "$*" | sed 's/ *| */\n/g' |
| 41 |
} |
| 42 |
|
| 43 |
# filters package name out of a "/" escaped simple build-dep, possibly with |
| 44 |
# architecture or version specifier; e.g. "/foo/(>=/2)/[i386/amd64]" becomes |
| 45 |
# "foo" |
| 46 |
get_pkg_name() { |
| 47 |
echo "$*" | sed 's#^/*##; s#[[/(<].*##' |
| 48 |
} |
| 49 |
|
| 50 |
# filter operator and version of a "/" escaped versioned build-dep; e.g. |
| 51 |
# "foo/(>=/2)" becomes ">= 2" |
| 52 |
get_dep_op_and_ver() { |
| 53 |
echo "$*" | sed -n 's#/# #g; s/.*( *\(<<\|<=\|>=\|=\|<\|>>\|>\) *\([^ )]*\) *).*/\1 \2/p' |
| 54 |
} |
| 55 |
|
| 56 |
# call apt-get in chroot in simulate mode |
| 57 |
apt_sim() { |
| 58 |
$CHROOTEXEC apt-get -s install "$@" |
| 59 |
} |
| 60 |
|
| 61 |
# Use this function to fulfill the dependency (almost) |
| 62 |
checkbuilddep_internal() { |
| 63 |
local ARCH=$($CHROOTEXEC dpkg-architecture -qDEB_HOST_ARCH) |
| 64 |
local INSTALLPKG |
| 65 |
local INSTALLPKGLIST |
| 66 |
local INSTALLPKGMULTI |
| 67 |
local CURRENTREALPKGNAME |
| 68 |
local SATISFIED |
| 69 |
local APTFLAG="-o APT::Install-Recommends=false" |
| 70 |
echo " -> Attempting to parse the build-deps " |
| 71 |
for INSTALLPKGMULTI in $(get_build_deps | split_deps); do |
| 72 |
echo " -> Considering build-dep $(echo "$INSTALLPKGMULTI" | tr "/" " ")" |
| 73 |
SATISFIED="no" |
| 74 |
for INSTALLPKG in $(split_alternates "$INSTALLPKGMULTI"); do |
| 75 |
CURRENTREALPKGNAME=$(get_pkg_name "$INSTALLPKG") |
| 76 |
if echo "$INSTALLPKG" | grep -q '\['; then |
| 77 |
if checkbuilddep_archdeps "$INSTALLPKG" "$ARCH"; then |
| 78 |
SATISFIED="yes" |
| 79 |
echo " -> This package is not for this architecture" |
| 80 |
continue |
| 81 |
fi |
| 82 |
fi |
| 83 |
if echo "$INSTALLPKG" | grep -q '<'; then |
| 84 |
if checkbuilddep_restrictiondeps "$INSTALLPKG" "$DEB_BUILD_PROFILES"; then |
| 85 |
SATISFIED="yes" |
| 86 |
echo " -> This package is not for the current build profiles" |
| 87 |
continue |
| 88 |
fi |
| 89 |
fi |
| 90 |
if echo "$INSTALLPKG" | grep -q '('; then |
| 91 |
#echo "Debug: $INSTALLPKG" |
| 92 |
if ! checkbuilddep_versiondeps "$CURRENTREALPKGNAME" $(get_dep_op_and_ver "$INSTALLPKG"); then |
| 93 |
echo " -> Does not satisfy version, not trying" |
| 94 |
continue |
| 95 |
fi |
| 96 |
fi |
| 97 |
echo " -> Trying $CURRENTREALPKGNAME" |
| 98 |
|
| 99 |
if apt_sim $APTFLAG $INSTALLPKGLIST $CURRENTREALPKGNAME >& /dev/null; then |
| 100 |
SATISFIED="yes" |
| 101 |
INSTALLPKGLIST="$INSTALLPKGLIST $CURRENTREALPKGNAME" |
| 102 |
else |
| 103 |
echo " -> Cannot install $CURRENTREALPKGNAME; apt errors follow:" |
| 104 |
if apt_sim $APTFLAG $INSTALLPKGLIST "$CURRENTREALPKGNAME"; then |
| 105 |
: |
| 106 |
fi |
| 107 |
# package could not be found. -- looking for alternative. |
| 108 |
PROVIDED="" |
| 109 |
checkbuilddep_provides "$CURRENTREALPKGNAME" |
| 110 |
if [ -n "$PROVIDED" ]; then |
| 111 |
# something provides this package |
| 112 |
echo " -> Considering $PROVIDED to satisfy the dependency " |
| 113 |
if apt_sim $APTFLAG $INSTALLPKGLIST $PROVIDED >& /dev/null; then |
| 114 |
SATISFIED="yes"; |
| 115 |
INSTALLPKGLIST="$INSTALLPKGLIST $PROVIDED" |
| 116 |
else |
| 117 |
# show the error for diagnostic purposes |
| 118 |
echo " -> Cannot install $PROVIDED; apt errors follow:" |
| 119 |
apt_sim $APTFLAG $INSTALLPKGLIST $PROVIDED || true |
| 120 |
fi |
| 121 |
fi |
| 122 |
fi |
| 123 |
if [ "$SATISFIED" = "yes" ]; then |
| 124 |
break; |
| 125 |
fi |
| 126 |
done; |
| 127 |
if [ "$SATISFIED" = "no" ]; then |
| 128 |
echo "E: Could not satisfy build-dependency." >&2 |
| 129 |
if [ "$CONTINUE_FAIL" != "yes" ]; then |
| 130 |
exit 2 |
| 131 |
fi |
| 132 |
fi |
| 133 |
done; |
| 134 |
|
| 135 |
# now actually install the packages |
| 136 |
echo " -> Installing $INSTALLPKGLIST" |
| 137 |
if ! $CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" install $APTFLAG $INSTALLPKGLIST; then |
| 138 |
echo " -> Trying to fix apt error" |
| 139 |
# Work around an apt bug which causes configure to fail. |
| 140 |
if $CHROOTEXEC dpkg --configure --pending && $CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" install $APTFLAG $INSTALLPKGLIST; then |
| 141 |
echo " -> Apt bug workaround succeeded" |
| 142 |
elif [ "$CONTINUE_FAIL" != "yes" ]; then |
| 143 |
echo "E: Unrecoverable error installing build-dependencies." >&2 |
| 144 |
exit 1 |
| 145 |
fi |
| 146 |
fi |
| 147 |
|
| 148 |
# start processing build-conflicts. |
| 149 |
for INSTALLPKG in $(get_build_conflicts | split_deps); do |
| 150 |
CURRENTREALPKGNAME=$(get_pkg_name "$INSTALLPKG") |
| 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" $(get_dep_op_and_ver "$INSTALLPKG"); then |
| 170 |
echo "I: Satisfies version, not trying" |
| 171 |
continue |
| 172 |
fi |
| 173 |
fi |
| 174 |
|
| 175 |
# if package exists, remove it. |
| 176 |
if $CHROOTEXEC dpkg -s "$CURRENTREALPKGNAME" 2>&1 | grep -q ^Package:; then |
| 177 |
if ! $CHROOTEXEC apt-get -q -y remove "$CURRENTREALPKGNAME" ; then |
| 178 |
echo "E: Could not satisfy build-conflicts" >&2 |
| 179 |
exit 1 |
| 180 |
fi |
| 181 |
else |
| 182 |
echo "I: $CURRENTREALPKGNAME package is not installed, no need to remove" |
| 183 |
fi |
| 184 |
done |
| 185 |
echo " -> Finished parsing the build-deps" |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
print_help() { |
| 190 |
# print out help message |
| 191 |
cat <<EOF |
| 192 |
pbuilder-satisfydepends -- satisfy dependencies |
| 193 |
Copyright 2002-2007 Junichi Uekawa <[email protected]> |
| 194 |
|
| 195 |
--help: give help |
| 196 |
--control: specify control file (debian/control, *.dsc) |
| 197 |
--chroot: operate inside chroot |
| 198 |
--binary-all: include binary-all |
| 199 |
--binary-arch: include binary-arch only |
| 200 |
--echo: echo mode, do nothing. (--force-version required for most operation) |
| 201 |
--force-version: skip version check. |
| 202 |
--continue-fail: continue even when failed. |
| 203 |
|
| 204 |
EOF |
| 205 |
} |
| 206 |
|
| 207 |
. "$PBUILDER_PKGLIBDIR"/pbuilder-satisfydepends-checkparams |
| 208 |
|