| 1 | #!/bin/bash |
|---|
| 2 | set -e |
|---|
| 3 | # empdebuild : emdebian version of pdebuild. |
|---|
| 4 | # |
|---|
| 5 | # Emdebian chroot builder - initially supporting the creation of a |
|---|
| 6 | # chroot capable of running emdebian-tools to reduce the number of |
|---|
| 7 | # cross dependencies that need to be installed on the build system. |
|---|
| 8 | # |
|---|
| 9 | # Copyright (C) 2006-2008 Neil Williams <codehelp@debian.org> |
|---|
| 10 | # |
|---|
| 11 | # This package is free software; you can redistribute it and/or modify |
|---|
| 12 | # it under the terms of the GNU General Public License as published by |
|---|
| 13 | # the Free Software Foundation; either version 3 of the License, or |
|---|
| 14 | # (at your option) any later version. |
|---|
| 15 | # |
|---|
| 16 | # This program is distributed in the hope that it will be useful, |
|---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | # GNU General Public License for more details. |
|---|
| 20 | # |
|---|
| 21 | # You should have received a copy of the GNU General Public License |
|---|
| 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 23 | # |
|---|
| 24 | # Note 1: Most configuration values are calculated, not taken from the command line |
|---|
| 25 | # or an rc file. |
|---|
| 26 | # Note 2: emdebuild creates a build log for us - just the output of dpkg-buildpackage, |
|---|
| 27 | # not the rest of the chroot operations. |
|---|
| 28 | |
|---|
| 29 | . /usr/lib/emdebian-tools/empbuilderlib |
|---|
| 30 | |
|---|
| 31 | SUITE=unstable |
|---|
| 32 | |
|---|
| 33 | function usagehelp () { |
|---|
| 34 | # print out help message |
|---|
| 35 | cat <<EOF |
|---|
| 36 | empdebuild - cross-building chroot Emdebian package builder |
|---|
| 37 | version $OURVERSION |
|---|
| 38 | |
|---|
| 39 | Syntax: sudo empdebuild [OPTIONS] [COMMAND] |
|---|
| 40 | Only one command can be actioned at any one time. |
|---|
| 41 | Options must precede the command to take effect. |
|---|
| 42 | |
|---|
| 43 | Commands: |
|---|
| 44 | -?|-h|--help|-version: print this help message and exit |
|---|
| 45 | --create|create: create a cross-building base .tgz for unstable |
|---|
| 46 | --update|update: update the base .tgz and save changes |
|---|
| 47 | --build|build: build the current package in the chroot |
|---|
| 48 | (needs to be run in the top source directory) |
|---|
| 49 | --autobuild|autobuild PACKAGE: build the specified package in the chroot |
|---|
| 50 | (used by the autobuilder) |
|---|
| 51 | --login|login: Login to the chroot to run tests or fix problems. |
|---|
| 52 | --clean|clean: Clean up all build sub directories. |
|---|
| 53 | |
|---|
| 54 | Options: |
|---|
| 55 | --arch: Override the default cross-build architecture (from dpkg-cross). |
|---|
| 56 | --testing: Override the default suite (unstable) to use testing |
|---|
| 57 | instead. This is a fallback option for use during |
|---|
| 58 | toolchain transitions in unstable. |
|---|
| 59 | --save-after-login: Allow changes made within the chroot login to persist. |
|---|
| 60 | --login-after-fail: In case of error, try to log in to the new chroot. |
|---|
| 61 | -- OPTIONS dpkg-buildpackage options |
|---|
| 62 | (except: -uc -us [default] -a [ignored]) |
|---|
| 63 | |
|---|
| 64 | Although based on pbuilder, empdebuild cannot support the full range of |
|---|
| 65 | pbuilder commands or options. In addition, creating a cross-building chroot for |
|---|
| 66 | testing involves a variety of changes to the creation of a similar chroot for |
|---|
| 67 | unstable so testing is only supported as an override, rather than using the |
|---|
| 68 | pbuilder method of a --distribution option. |
|---|
| 69 | |
|---|
| 70 | When testing local changes made with emdebuild, use 'empdebuild --build' which |
|---|
| 71 | will use the .diff.gz from the current working directory. |
|---|
| 72 | |
|---|
| 73 | Once the local changes are complete and are committed to Emdebian SVN, you |
|---|
| 74 | can use 'empdebuild --autobuild PACKAGE' to ensure that the patches are |
|---|
| 75 | usable for the autobuilder. |
|---|
| 76 | |
|---|
| 77 | Options to dpkg-buildpackage can be specified after the -- option. |
|---|
| 78 | Note that '-uc' and '-us' are set by default and '-a' will be ignored |
|---|
| 79 | (because arch is controlled separately). Options are passed down to |
|---|
| 80 | emdebuild unchanged. |
|---|
| 81 | |
|---|
| 82 | EOF |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | function get_cross_depends () |
|---|
| 86 | { |
|---|
| 87 | # derived from checkbuilddep_internal |
|---|
| 88 | # Use this function to fulfill the cross-dependencies |
|---|
| 89 | DEBIAN_XCONTROL=debian/xcontrol |
|---|
| 90 | BD_REGEXP="build-depends" |
|---|
| 91 | |
|---|
| 92 | local INSTALLPKG |
|---|
| 93 | local INSTALLPKGLIST |
|---|
| 94 | local INSTALLPKGMULTI |
|---|
| 95 | local CURRENTREALPKGNAME |
|---|
| 96 | if [ ! -f ${DEBIAN_XCONTROL} ]; then |
|---|
| 97 | return |
|---|
| 98 | fi |
|---|
| 99 | echo " -> updating apt-cross cache" |
|---|
| 100 | chroot $BUILDPLACE /usr/bin/apt-cross -a $ARCH -S $SUITE -u |
|---|
| 101 | echo " -> Attempting to parse the cross-build dependencies" |
|---|
| 102 | # read debian/xcontrol |
|---|
| 103 | for INSTALLPKGMULTI in $(cat ${DEBIAN_XCONTROL} | \ |
|---|
| 104 | awk ' |
|---|
| 105 | BEGIN{source=1} |
|---|
| 106 | /^$/ {source=0} |
|---|
| 107 | /^Source:/ {source=1} |
|---|
| 108 | /^[^ ]*:/ {p=0} |
|---|
| 109 | tolower($0) ~ /^'"${BD_REGEXP}"':/ {p=1} |
|---|
| 110 | {if(p && source) {print $0}}' | \ |
|---|
| 111 | sed 's/^[^: ]*://' | \ |
|---|
| 112 | tr " " "/" | \ |
|---|
| 113 | awk 'BEGIN{RS=","} {print}'); do |
|---|
| 114 | echo " -> Considering cross-build-dep$(echo "$INSTALLPKGMULTI" | tr "/" " " )" |
|---|
| 115 | # parse the list - removing commas etc. |
|---|
| 116 | for INSTALLPKG in $(echo "$INSTALLPKGMULTI" | \ |
|---|
| 117 | awk 'BEGIN{RS="|"} {print}'); do |
|---|
| 118 | CURRENTREALPKGNAME=$(echo "$INSTALLPKG" | sed -e 's/^[/]*//' -e 's/[[/(].*//') #)# syntax hack |
|---|
| 119 | INSTALLPKGLIST="${INSTALLPKGLIST} ${CURRENTREALPKGNAME}" |
|---|
| 120 | done; # end parse list |
|---|
| 121 | done; # end parse debian/xcontrol |
|---|
| 122 | if [ -n "${INSTALLPKGLIST}" ]; then |
|---|
| 123 | echo " -> Installing ${INSTALLPKGLIST}" |
|---|
| 124 | chroot $BUILDPLACE /usr/bin/apt-cross -q -k -a $ARCH --install ${INSTALLPKGLIST} |
|---|
| 125 | save_aptcrosscache |
|---|
| 126 | fi |
|---|
| 127 | echo " -> Finished parsing the cross build-deps" |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | function update_emchroot () |
|---|
| 131 | { |
|---|
| 132 | if [ $SUITE == testing ]; then |
|---|
| 133 | BASETGZ="${WORKDIR}/emdebian-testing.tgz" |
|---|
| 134 | SUITE=testing |
|---|
| 135 | echo "Updating the embootstrap testing chroot" |
|---|
| 136 | else |
|---|
| 137 | BASETGZ="$WORKDIR/emdebian.tgz" |
|---|
| 138 | fi |
|---|
| 139 | extractembuildplace |
|---|
| 140 | echo "File extracted to: $BUILDPLACE" |
|---|
| 141 | echo "" |
|---|
| 142 | echo " -> upgrading packages" |
|---|
| 143 | disable_apt_recommends |
|---|
| 144 | # force the sources list - a bit of a hack really. |
|---|
| 145 | # TODO this should be configurable - emdebian-tools will add a primary later. |
|---|
| 146 | cp /usr/share/emdebian-tools/emsources.$SUITE $BUILDPLACE/etc/apt/sources.list |
|---|
| 147 | if echo "/usr/bin/apt-get update" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 148 | : |
|---|
| 149 | else |
|---|
| 150 | # if apt failed (maybe update needs to be run), save so far and exit cleanly |
|---|
| 151 | save_aptcache |
|---|
| 152 | # copy out the failed build here first. |
|---|
| 153 | umountproc |
|---|
| 154 | cleanbuildplace |
|---|
| 155 | exit 1; |
|---|
| 156 | fi |
|---|
| 157 | echo " -> updating apt-cross cache for $SUITE" |
|---|
| 158 | if echo "/usr/bin/apt-cross -a $ARCH -S $SUITE -u" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 159 | : |
|---|
| 160 | else |
|---|
| 161 | # if apt failed (maybe update needs to be run), save so far and exit cleanly |
|---|
| 162 | save_aptcache |
|---|
| 163 | umountproc |
|---|
| 164 | cleanbuildplace |
|---|
| 165 | exit 1; |
|---|
| 166 | fi |
|---|
| 167 | recover_aptcache |
|---|
| 168 | # TODO persistent problems with the toolchains mean this needs to be optional. |
|---|
| 169 | if echo "DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get $OPTIONS -y --force-yes upgrade" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 170 | : |
|---|
| 171 | else |
|---|
| 172 | # if apt failed (maybe update needs to be run), save so far and exit cleanly |
|---|
| 173 | save_aptcache |
|---|
| 174 | umountproc |
|---|
| 175 | cleanbuildplace |
|---|
| 176 | exit 1; |
|---|
| 177 | fi |
|---|
| 178 | if echo "DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get $OPTIONS -y --force-yes dist-upgrade" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 179 | : |
|---|
| 180 | else |
|---|
| 181 | # if apt failed (maybe update needs to be run), save so far and exit cleanly |
|---|
| 182 | save_aptcache |
|---|
| 183 | umountproc |
|---|
| 184 | cleanbuildplace |
|---|
| 185 | exit 1; |
|---|
| 186 | fi |
|---|
| 187 | chroot $BUILDPLACE /usr/bin/apt-get $OPTIONS -y --force-yes install emdebian-tools || true |
|---|
| 188 | chroot $BUILDPLACE /usr/bin/apt-get $OPTIONS --purge -y --force-yes autoremove || true |
|---|
| 189 | autoclean_aptcache |
|---|
| 190 | save_aptcache |
|---|
| 191 | echo " -> updating devscripts configuration" |
|---|
| 192 | if [ -f /home/$SUDO_USER/.devscripts ]; then |
|---|
| 193 | cp /home/$SUDO_USER/.devscripts $BUILDPLACE/home/$SUDO_USER/.devscripts |
|---|
| 194 | fi |
|---|
| 195 | VAL=`chroot $BUILDPLACE hostname -f 2>&1` |
|---|
| 196 | if [ "$VAL" != "" ]; then |
|---|
| 197 | echo " -> updating /etc/hosts" |
|---|
| 198 | cp /etc/hosts $BUILDPLACE/etc/hosts |
|---|
| 199 | fi |
|---|
| 200 | # sometimes this returns non-zero |
|---|
| 201 | if echo "$COLOUR ARCH=$ARCH /usr/bin/emsetup --arch $ARCH --yes" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 202 | : |
|---|
| 203 | fi |
|---|
| 204 | umountproc || true |
|---|
| 205 | chroot $BUILDPLACE /usr/bin/apt-get clean || true |
|---|
| 206 | create_emdebiantgz |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | # very similar to emchrootbuild but calls emsource inside the |
|---|
| 210 | # chroot instead of copying the source in from outside. |
|---|
| 211 | # i.e. autobuilder mode (so it tries to be quiet). |
|---|
| 212 | function empautobuild() |
|---|
| 213 | { |
|---|
| 214 | if [ $SUITE == testing ]; then |
|---|
| 215 | BASETGZ="${WORKDIR}/emdebian-testing.tgz" |
|---|
| 216 | SUITE=testing |
|---|
| 217 | echo "Building in the embootstrap testing chroot" |
|---|
| 218 | else |
|---|
| 219 | BASETGZ="$WORKDIR/emdebian.tgz" |
|---|
| 220 | fi |
|---|
| 221 | . /usr/lib/pbuilder/pbuilder-buildpackage-funcs |
|---|
| 222 | PACKAGE=$1 |
|---|
| 223 | BUILDRESULTUID="${BUILDRESULTUID:-${SUDO_UID:-0}}" |
|---|
| 224 | BUILDRESULTGID="${BUILDRESULTGID:-${SUDO_GID:-0}}" |
|---|
| 225 | INITIAL=`echo $PACKAGE | cut -b1` |
|---|
| 226 | TRUNK="$INITIAL/${PACKAGE}/trunk" |
|---|
| 227 | |
|---|
| 228 | echobacktime |
|---|
| 229 | extractembuildplace |
|---|
| 230 | echo "File extracted to: $BUILDPLACE" |
|---|
| 231 | echo "" |
|---|
| 232 | recover_aptcache |
|---|
| 233 | createbuilduser |
|---|
| 234 | if [ -f "/etc/devscripts.conf" ]; then |
|---|
| 235 | cp /etc/devscripts.conf $BUILDPLACE/etc/devscripts.conf |
|---|
| 236 | fi |
|---|
| 237 | if [ -f "/home/$SUDO_USER/.devscripts" ]; then |
|---|
| 238 | mkdir -p $BUILDPLACE/home/$SUDO_USER/ |
|---|
| 239 | cp /home/$SUDO_USER/.devscripts $BUILDPLACE/home/$SUDO_USER/.devscripts |
|---|
| 240 | fi |
|---|
| 241 | |
|---|
| 242 | COLOUR= |
|---|
| 243 | if [ $ANSI_COLORS_DISABLED ]; then |
|---|
| 244 | COLOUR=ANSI_COLORS_DISABLED=1 |
|---|
| 245 | fi |
|---|
| 246 | echo "Checking the Emdebian toolchain" |
|---|
| 247 | # fails with non-zero if no toolchain is found |
|---|
| 248 | if echo "$COLOUR /usr/bin/emsetup -q --arch $ARCH --report" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 249 | : |
|---|
| 250 | else |
|---|
| 251 | umountproc |
|---|
| 252 | cleanbuildplace |
|---|
| 253 | exit 1; |
|---|
| 254 | fi |
|---|
| 255 | if echo "$COLOUR ARCH=$ARCH emsource -q -a $ARCH -b --build-dep $PACKAGE $EM_DPKG_OPTS" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 256 | : |
|---|
| 257 | else |
|---|
| 258 | echo " -> emsource -b failed" |
|---|
| 259 | if [ "${LOGIN_AFTER_FAIL}" = "yes" ]; then |
|---|
| 260 | echo " -> Logging into the chroot" |
|---|
| 261 | echobacktime |
|---|
| 262 | chroot $BUILDPLACE /bin/sh |
|---|
| 263 | save_aptcache |
|---|
| 264 | umountproc |
|---|
| 265 | cleanbuildplace |
|---|
| 266 | exit 1; |
|---|
| 267 | fi |
|---|
| 268 | save_aptcache |
|---|
| 269 | umountproc |
|---|
| 270 | cleanbuildplace |
|---|
| 271 | exit 1; |
|---|
| 272 | fi |
|---|
| 273 | if [ $? -ne 0 ]; then |
|---|
| 274 | echo " -> emsource -b failed" |
|---|
| 275 | if [ "${LOGIN_AFTER_FAIL}" = "yes" ]; then |
|---|
| 276 | echo " -> Logging into the chroot" |
|---|
| 277 | echobacktime |
|---|
| 278 | chroot $BUILDPLACE /bin/sh |
|---|
| 279 | save_aptcache |
|---|
| 280 | umountproc |
|---|
| 281 | cleanbuildplace |
|---|
| 282 | exit 1; |
|---|
| 283 | fi |
|---|
| 284 | fi |
|---|
| 285 | FULLPATH="$BUILDPLACE/trunk/$TRUNK/" |
|---|
| 286 | FULLPATH=`echo $FULLPATH | tr -s \/` |
|---|
| 287 | PKGRESULT="${BUILDRESULT}${INITIAL}/${PACKAGE}/trunk" |
|---|
| 288 | echo "Copying build results to ${PKGRESULT}" |
|---|
| 289 | mkdir -p "$PKGRESULT" |
|---|
| 290 | if [ -d "${PKGRESULT}" ]; then |
|---|
| 291 | chown -R "${BUILDRESULTUID}:${BUILDRESULTGID}" "${BUILDRESULT}/"* |
|---|
| 292 | cp -p "${FULLPATH}"/* "${PKGRESULT}" 2>/dev/null || true |
|---|
| 293 | chown -R "${BUILDRESULTUID}:${BUILDRESULTGID}" "${BUILDRESULT}/"* |
|---|
| 294 | else |
|---|
| 295 | echo "E: BUILDRESULT=[$BUILDRESULT] is not a directory." >&2 |
|---|
| 296 | fi |
|---|
| 297 | save_aptcache |
|---|
| 298 | umountproc |
|---|
| 299 | cleanbuildplace |
|---|
| 300 | echobacktime |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | function emchrootbuild() |
|---|
| 304 | { |
|---|
| 305 | if [ $SUITE == testing ]; then |
|---|
| 306 | BASETGZ="${WORKDIR}/emdebian-testing.tgz" |
|---|
| 307 | SUITE=testing |
|---|
| 308 | echo "Building in the embootstrap testing chroot" |
|---|
| 309 | else |
|---|
| 310 | BASETGZ="$WORKDIR/emdebian.tgz" |
|---|
| 311 | fi |
|---|
| 312 | . /usr/lib/pbuilder/pbuilder-buildpackage-funcs |
|---|
| 313 | |
|---|
| 314 | BUILDRESULTUID="${BUILDRESULTUID:-${SUDO_UID:-0}}" |
|---|
| 315 | BUILDRESULTGID="${BUILDRESULTGID:-${SUDO_GID:-0}}" |
|---|
| 316 | |
|---|
| 317 | while ! test -d ./debian -o "$(pwd)" = "$WORKDIR" ; do |
|---|
| 318 | cd ..; |
|---|
| 319 | done |
|---|
| 320 | if test ! -d ./debian; then |
|---|
| 321 | echo "Cannot find ./debian dir" |
|---|
| 322 | cleanbuildplace |
|---|
| 323 | exit 1 |
|---|
| 324 | fi; |
|---|
| 325 | |
|---|
| 326 | PKG_SOURCENAME=`dpkg-parsechangelog|sed -n 's/^Source: //p'` |
|---|
| 327 | PKG_VERSION=`dpkg-parsechangelog|sed -n 's/^Version: \(.*:\|\)//p'` |
|---|
| 328 | HOST_ARCH=`dpkg-architecture -qDEB_HOST_ARCH` |
|---|
| 329 | |
|---|
| 330 | echo "Building ${PKG_SOURCENAME} ${PKG_VERSION} on ${HOST_ARCH} for $ARCH" |
|---|
| 331 | INITIAL=`echo $PKG_SOURCENAME | cut -b1` |
|---|
| 332 | PKG=`basename \$PWD`; |
|---|
| 333 | TRUNK="$INITIAL/${PKG_SOURCENAME}/trunk" |
|---|
| 334 | SVN="$TRUNK/${PKG}" |
|---|
| 335 | if [ "$LOGIN_AFTER_FAIL" == "yes" ]; then |
|---|
| 336 | echo " -> will attempt to login after build failure" |
|---|
| 337 | fi |
|---|
| 338 | echo " -> source location: trunk/$SVN" |
|---|
| 339 | # get the Debian .dsc |
|---|
| 340 | DEB_VER=`echo $PKG_VERSION | sed -n 's/em[0-9]*$//p'` |
|---|
| 341 | if [ "$DEB_VER" == "" ]; then |
|---|
| 342 | echo "$PKG_VERSION is not an Emdebian version string." |
|---|
| 343 | cleanbuildplace |
|---|
| 344 | exit 1; |
|---|
| 345 | fi |
|---|
| 346 | DSC="${PKG_SOURCENAME}_${DEB_VER}.dsc" |
|---|
| 347 | if [ ! -f "../$DSC" ]; then |
|---|
| 348 | echo "Cannot find ../$DSC" |
|---|
| 349 | cleanbuildplace |
|---|
| 350 | exit 1; |
|---|
| 351 | fi |
|---|
| 352 | echo " -> using $DSC" |
|---|
| 353 | |
|---|
| 354 | # don't duplicate the downloads made by emsource |
|---|
| 355 | DIFFS=`find ../ -name emdebian-*\.patch` |
|---|
| 356 | DEBDIFFS=`find ../ -maxdepth 1 -name debian-patch*` |
|---|
| 357 | OLDSRC="$PKG_SOURCENAME.old" |
|---|
| 358 | echobacktime |
|---|
| 359 | extractembuildplace |
|---|
| 360 | echo "File extracted to: $BUILDPLACE" |
|---|
| 361 | echo "" |
|---|
| 362 | recover_aptcache |
|---|
| 363 | createbuilduser |
|---|
| 364 | |
|---|
| 365 | if [ -f "/etc/devscripts.conf" ]; then |
|---|
| 366 | cp /etc/devscripts.conf $BUILDPLACE/etc/devscripts.conf |
|---|
| 367 | fi |
|---|
| 368 | if [ -f "/home/$SUDO_USER/.devscripts" ]; then |
|---|
| 369 | mkdir -p $BUILDPLACE/home/$SUDO_USER/ |
|---|
| 370 | cp /home/$SUDO_USER/.devscripts $BUILDPLACE/home/$SUDO_USER/.devscripts |
|---|
| 371 | fi |
|---|
| 372 | |
|---|
| 373 | COLOUR= |
|---|
| 374 | if [ $ANSI_COLORS_DISABLED ]; then |
|---|
| 375 | COLOUR=ANSI_COLORS_DISABLED=1 |
|---|
| 376 | fi |
|---|
| 377 | echo "Checking the Emdebian toolchain" |
|---|
| 378 | # fails with non-zero if no toolchain is found |
|---|
| 379 | if echo "$COLOUR /usr/bin/emsetup --arch $ARCH --report" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 380 | : |
|---|
| 381 | else |
|---|
| 382 | umountproc |
|---|
| 383 | cleanbuildplace |
|---|
| 384 | exit 1; |
|---|
| 385 | fi |
|---|
| 386 | echo "Copying Debian source" |
|---|
| 387 | chroot $BUILDPLACE mkdir -p trunk/$TRUNK |
|---|
| 388 | copydsc "../$DSC" "$BUILDPLACE/trunk/${TRUNK}/" |
|---|
| 389 | chroot $BUILDPLACE /usr/bin/dpkg-source -x trunk/${TRUNK}/$DSC trunk/$SVN |
|---|
| 390 | |
|---|
| 391 | echo "Applying Emdebian changes" |
|---|
| 392 | for PATCH in $DEBDIFFS |
|---|
| 393 | do |
|---|
| 394 | if [ ! -d /trunk/$SVN/debian/patches/ ]; then |
|---|
| 395 | echo "Creating debian/patches directory" |
|---|
| 396 | mkdir -p $BUILDPLACE/trunk/$SVN/debian/patches/ |
|---|
| 397 | fi |
|---|
| 398 | NAME=`echo $PATCH | sed -e 's/..\/debian-patch-//'` |
|---|
| 399 | echo "Copying $PATCH to /trunk/$SVN/debian/patches/$NAME" |
|---|
| 400 | cp "$PATCH" "$BUILDPLACE/trunk/$SVN/debian/patches/$NAME" |
|---|
| 401 | done |
|---|
| 402 | for PATCH in $DIFFS |
|---|
| 403 | do |
|---|
| 404 | cp "$PATCH" "$BUILDPLACE/trunk/$TRUNK" |
|---|
| 405 | if echo "cd /trunk/$SVN; patch -p1 < $PATCH" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 406 | : |
|---|
| 407 | else |
|---|
| 408 | umountproc |
|---|
| 409 | cleanbuildplace |
|---|
| 410 | exit 1; |
|---|
| 411 | fi |
|---|
| 412 | done |
|---|
| 413 | |
|---|
| 414 | # only check for dependencies AFTER debian/control has been patched for Emdebian. |
|---|
| 415 | echo " -> installing build dependencies for $PKG_SOURCENAME" |
|---|
| 416 | checkembuilddep |
|---|
| 417 | # new function to parse and install cross-depends. |
|---|
| 418 | # read debian/xcontrol, pass Build-Cross-Depends to apt-cross -i |
|---|
| 419 | get_cross_depends |
|---|
| 420 | save_aptcache |
|---|
| 421 | echo " -> copying ../$OLDSRC" |
|---|
| 422 | cp -r "../$OLDSRC" "$BUILDPLACE/trunk/$TRUNK" |
|---|
| 423 | echo "Running emdebuild -a $ARCH $EM_DPKG_OPTS " |
|---|
| 424 | COLOUR= |
|---|
| 425 | if [ $ANSI_COLORS_DISABLED ]; then |
|---|
| 426 | COLOUR=ANSI_COLORS_DISABLED=1 |
|---|
| 427 | fi |
|---|
| 428 | if echo "cd /trunk/$SVN; $COLOUR ARCH=$ARCH emdebuild -a $ARCH $EM_DPKG_OPTS" | chroot $BUILDPLACE /bin/sh; then |
|---|
| 429 | : |
|---|
| 430 | else |
|---|
| 431 | echo " -> emdebuild failed" |
|---|
| 432 | if [ "${LOGIN_AFTER_FAIL}" = "yes" ]; then |
|---|
| 433 | echo " -> Logging into the chroot" |
|---|
| 434 | echo " -> Build directory: /trunk/$SVN" |
|---|
| 435 | echobacktime |
|---|
| 436 | chroot $BUILDPLACE /bin/sh |
|---|
| 437 | save_aptcache |
|---|
| 438 | umountproc |
|---|
| 439 | cleanbuildplace |
|---|
| 440 | exit 1; |
|---|
| 441 | fi |
|---|
| 442 | save_aptcache |
|---|
| 443 | umountproc |
|---|
| 444 | cleanbuildplace |
|---|
| 445 | exit 1; |
|---|
| 446 | fi |
|---|
| 447 | if [ $? -ne 0 ]; then |
|---|
| 448 | echo " -> emdebuild failed" |
|---|
| 449 | if [ "${LOGIN_AFTER_FAIL}" = "yes" ]; then |
|---|
| 450 | echo " -> Logging into the chroot" |
|---|
| 451 | echo " -> Build directory: /trunk/$SVN" |
|---|
| 452 | echobacktime |
|---|
| 453 | chroot $BUILDPLACE /bin/sh |
|---|
| 454 | save_aptcache |
|---|
| 455 | umountproc |
|---|
| 456 | cleanbuildplace |
|---|
| 457 | exit 1; |
|---|
| 458 | fi |
|---|
| 459 | fi |
|---|
| 460 | FULLPATH="$BUILDPLACE/trunk/$TRUNK/" |
|---|
| 461 | FULLPATH=`echo $FULLPATH | tr -s \/` |
|---|
| 462 | PKGRESULT="${BUILDRESULT}${INITIAL}/${PKG_SOURCENAME}/trunk" |
|---|
| 463 | echo "Copying build results to ${PKGRESULT}" |
|---|
| 464 | mkdir -p "$PKGRESULT" |
|---|
| 465 | if [ -d "${PKGRESULT}" ]; then |
|---|
| 466 | chown -R "${BUILDRESULTUID}:${BUILDRESULTGID}" "${BUILDRESULT}/"* |
|---|
| 467 | cp -p "${FULLPATH}"/* "${PKGRESULT}" 2>/dev/null || true |
|---|
| 468 | chown -R "${BUILDRESULTUID}:${BUILDRESULTGID}" "${BUILDRESULT}/"* |
|---|
| 469 | else |
|---|
| 470 | echo "E: BUILDRESULT=[$BUILDRESULT] is not a directory." >&2 |
|---|
| 471 | fi |
|---|
| 472 | CHANGES=`find $PKGRESULT -name \*${PKG_VERSION}_${ARCH}.changes` |
|---|
| 473 | echo " -> .changes file : ${CHANGES}" |
|---|
| 474 | EMDSC=`find $PKGRESULT -name \*${PKG_VERSION}.dsc` |
|---|
| 475 | echo " -> .dsc file : ${EMDSC}" |
|---|
| 476 | EMDEBS=`find $PKGRESULT -name \*${PKG_VERSION}*deb | grep -c deb` |
|---|
| 477 | echo " -> ${EMDEBS} packages built." |
|---|
| 478 | save_aptcache |
|---|
| 479 | umountproc |
|---|
| 480 | cleanbuildplace |
|---|
| 481 | echobacktime |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | function emlogin() |
|---|
| 485 | { |
|---|
| 486 | if [ $SUITE == testing ]; then |
|---|
| 487 | BASETGZ="${WORKDIR}/emdebian-testing.tgz" |
|---|
| 488 | echo "Logging into the embootstrap testing chroot" |
|---|
| 489 | else |
|---|
| 490 | BASETGZ="$WORKDIR/emdebian.tgz" |
|---|
| 491 | fi |
|---|
| 492 | extractembuildplace |
|---|
| 493 | recover_aptcache |
|---|
| 494 | echo " -> entering the shell" |
|---|
| 495 | echo "File extracted to: $BUILDPLACE" |
|---|
| 496 | # login should be as close to failsafe as possible so do v.little else. |
|---|
| 497 | chroot $BUILDPLACE /bin/sh || true |
|---|
| 498 | save_aptcache |
|---|
| 499 | umountproc |
|---|
| 500 | # saving the buildplace afterwards |
|---|
| 501 | if [ "${SAVE_AFTER_LOGIN}" = "yes" ]; then |
|---|
| 502 | echo " -> Saving the results, modifications to this session will persist" |
|---|
| 503 | chroot $BUILDPLACE /usr/bin/apt-get clean || true |
|---|
| 504 | create_emdebiantgz |
|---|
| 505 | fi |
|---|
| 506 | cleanbuildplace |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | # test for sudo - normally empdebuild is installed in /usr/sbin so this |
|---|
| 510 | # test is really only for SVN users. |
|---|
| 511 | # make sure sudo is in use. |
|---|
| 512 | # bash cannot seem to do this when set -e is enabled |
|---|
| 513 | # because grep returns non-zero on a non-match |
|---|
| 514 | # so I use perl. :-) |
|---|
| 515 | ISSUDOSET=`perl -e '$e=\`printenv\`; ($e =~ /SUDO_USER/) ? print "yes" : print "no";'` |
|---|
| 516 | if [ $ISSUDOSET == "no" ] ; then |
|---|
| 517 | AREWEROOT=`perl -e '$e=\`printenv\`; ($e =~ /LOGNAME=root/) ? print "yes" : print "no";'` |
|---|
| 518 | if [ $AREWEROOT == "no" ]; then |
|---|
| 519 | echo "empdebuild needs to be run under sudo or as root." |
|---|
| 520 | exit 2 |
|---|
| 521 | fi |
|---|
| 522 | fi |
|---|
| 523 | |
|---|
| 524 | if [ ! $1 ];then |
|---|
| 525 | usagehelp |
|---|
| 526 | exit; |
|---|
| 527 | fi |
|---|
| 528 | |
|---|
| 529 | USEDEVPTS="yes" |
|---|
| 530 | USEPROC="yes" |
|---|
| 531 | |
|---|
| 532 | while [ -n "$1" ]; do |
|---|
| 533 | case "$1" in |
|---|
| 534 | --help|-h|-?|--version) |
|---|
| 535 | usagehelp |
|---|
| 536 | exit; |
|---|
| 537 | ;; |
|---|
| 538 | -a|--arch) |
|---|
| 539 | shift |
|---|
| 540 | ARCH=$1 |
|---|
| 541 | # chomp the argument to --arch |
|---|
| 542 | shift |
|---|
| 543 | ;; |
|---|
| 544 | --testing) |
|---|
| 545 | shift |
|---|
| 546 | SUITE=testing |
|---|
| 547 | ;; |
|---|
| 548 | --create|create) |
|---|
| 549 | shift; |
|---|
| 550 | checkarch |
|---|
| 551 | createemchroot |
|---|
| 552 | exit; |
|---|
| 553 | ;; |
|---|
| 554 | --update|update) |
|---|
| 555 | shift; |
|---|
| 556 | checkarch |
|---|
| 557 | update_emchroot |
|---|
| 558 | exit; |
|---|
| 559 | ;; |
|---|
| 560 | --build|build) |
|---|
| 561 | shift; |
|---|
| 562 | checkarch |
|---|
| 563 | emchrootbuild |
|---|
| 564 | exit; |
|---|
| 565 | ;; |
|---|
| 566 | --autobuild|autobuild) |
|---|
| 567 | shift; |
|---|
| 568 | PACKAGE=$1 |
|---|
| 569 | shift; |
|---|
| 570 | checkarch |
|---|
| 571 | empautobuild $PACKAGE |
|---|
| 572 | exit; |
|---|
| 573 | ;; |
|---|
| 574 | --save-after-login) |
|---|
| 575 | shift |
|---|
| 576 | SAVE_AFTER_LOGIN="yes" |
|---|
| 577 | ;; |
|---|
| 578 | --login-after-fail) |
|---|
| 579 | shift |
|---|
| 580 | LOGIN_AFTER_FAIL="yes" |
|---|
| 581 | ;; |
|---|
| 582 | --login|login) |
|---|
| 583 | shift |
|---|
| 584 | checkarch |
|---|
| 585 | emlogin |
|---|
| 586 | exit; |
|---|
| 587 | ;; |
|---|
| 588 | --clean|clean) |
|---|
| 589 | shift |
|---|
| 590 | echo "Trying to ensure crashed chroots are unmounted" |
|---|
| 591 | CRASH=`mount | grep "$WORKDIR" | cut -d' ' -f3` |
|---|
| 592 | if [ "$CRASH" ]; then |
|---|
| 593 | echo "Trying to ensure crashed chroots are unmounted" |
|---|
| 594 | mount | grep "$WORKDIR" | cut -d' ' -f3 | xargs umount || true |
|---|
| 595 | fi |
|---|
| 596 | echo "Cleaning $BASEBUILDPLACE" |
|---|
| 597 | clean_subdirectories $BASEBUILDPLACE |
|---|
| 598 | # if debootstrap fails, we start again so remove the stamp. |
|---|
| 599 | if [ -f $WORKDIR/stamp-debootstrap ]; then |
|---|
| 600 | rm $WORKDIR/stamp-debootstrap |
|---|
| 601 | fi |
|---|
| 602 | exit; |
|---|
| 603 | ;; |
|---|
| 604 | --) |
|---|
| 605 | while [ -n "$1" ] |
|---|
| 606 | do |
|---|
| 607 | EM_DPKG_OPTS+="$1 " |
|---|
| 608 | shift |
|---|
| 609 | done |
|---|
| 610 | break |
|---|
| 611 | ;; |
|---|
| 612 | *) |
|---|
| 613 | echo "Unrecognised option: $1" |
|---|
| 614 | echo |
|---|
| 615 | usagehelp |
|---|
| 616 | exit; |
|---|
| 617 | ;; |
|---|
| 618 | esac |
|---|
| 619 | done |
|---|