#! /bin/bash # common modules for pbuilder. # pbuilder -- personal Debian package builder # Copyright (C) 2001,2002 Junichi Uekawa # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA function showhelp () { cat < unmounting /proc filesystem" if ! umount "$BUILDPLACE/proc"; then echo "W: Retrying to unmount proc" sleep 5s while ! umount "$BUILDPLACE/proc"; do sleep 5s cat < unmounting /dev/pts filesystem" umount "$BUILDPLACE/dev/pts" || true fi if [ "$USEDEVFS" = "yes" ]; then echo " -> unmounting /dev filesystem" umount "$BUILDPLACE/dev" || true fi } function mountproc () { if [ "$USEPROC" = "yes" ]; then echo " -> mounting /proc filesystem" mkdir -p $BUILDPLACE/proc mount -t proc /proc "$BUILDPLACE/proc" fi if [ "$USEDEVPTS" = "yes" ]; then echo " -> mounting /dev/pts filesystem" mkdir -p $BUILDPLACE/dev/pts || true mount -t devpts /dev/pts "$BUILDPLACE/dev/pts" fi if [ "$USEDEVFS" = "yes" ]; then echo " -> mounting /dev filesystem" mkdir -p $BUILDPLACE/dev || true mount -t devfs /dev "$BUILDPLACE/dev" fi } function cleanbuildplace () { if [ "$?" -ne 0 ]; then echo " -> Aborting with an error"; fi if [ -d "$BUILDPLACE" ]; then echo " -> cleaning the build env " rm -rf "$BUILDPLACE" fi; } function umountproc_cleanbuildplace () { # rolling back to abort. if [ "$?" -ne 0 ]; then echo " -> Aborting with an error"; fi umountproc cleanbuildplace } function installaptlines (){ echo " -> Installing apt-lines" rm -f "$BUILDPLACE"/etc/apt/sources.list if [ -z "$DISTRIBUTION" ]; then echo "Distribution not specified, please specify" >&2 exit 1 fi if [ -n "$OTHERMIRROR" ]; then echo "$OTHERMIRROR" | tr "|" "\n" >> "$BUILDPLACE"/etc/apt/sources.list fi if [ -n "$MIRRORSITE" ] ; then cat >> "$BUILDPLACE"/etc/apt/sources.list << EOF deb $MIRRORSITE $DISTRIBUTION main contrib non-free #deb-src $MIRRORSITE $DISTRIBUTION main contrib non-free EOF fi if [ -n "$NONUSMIRRORSITE" ]; then cat >> "$BUILDPLACE"/etc/apt/sources.list << EOF deb $NONUSMIRRORSITE $DISTRIBUTION/non-US main contrib non-free #deb-src $NONUSMIRRORSITE $DISTRIBUTION/non-US main contrib non-free EOF fi if [ -n "$APTCONFDIR" ]; then echo " -> Copy " "$APTCONFDIR"/* " to chroot" cp -a "$APTCONFDIR/"* "$BUILDPLACE"/etc/apt fi } function extractbuildplace () { # after calling this function, umountproc, and cleanbuildplace # needs to be called. Please trap it. cleanbuildplace echo "Building the build Environment" echo " -> extracting base.tgz" if ! mkdir -p "$BUILDPLACE"; then echo "E: failed to build the directory to chroot" exit 1 fi if [ ! -f "$BASETGZ" ]; then echo "E: failed to find $BASETGZ, have you done to create your base tarball yet?" exit 1 fi if ! (cd "$BUILDPLACE" && tar xfzp "$BASETGZ"); then echo "E: failed to extract $BASETGZ to $BUILDPLACE" exit 1 fi mountproc mkdir -p "$BUILDPLACE/tmp/buildd" echo " -> copying/creating local configuration" for a in hosts hostname resolv.conf; do cp $( readlink -f /etc/$a ) "$BUILDPLACE/etc/$a"; done hostname -f > "$BUILDPLACE/etc/mailname" if [ -n "$DISTRIBUTION" ]; then installaptlines fi } function recover_aptcache() { # recover the aptcache archive if [ -n "$APTCACHE" ]; then echo "Obtaining the cached apt archive contents" if ls "$APTCACHE"/*.deb > /dev/null 2> /dev/null ; then if [ "$APTCACHEHARDLINK" = "yes" ]; then ln "$APTCACHE"/*.deb "$BUILDPLACE/var/cache/apt/archives/" || true else cp "$APTCACHE"/*.deb "$BUILDPLACE/var/cache/apt/archives/" || true fi else echo "W: No cache contents yet." fi fi } function save_aptcache() { # save the current aptcache archive if [ -n "$APTCACHE" ]; then echo "Copying back the cached apt archive contents" mkdir -p "$APTCACHE" ; for A in "$BUILDPLACE/var/cache/apt/archives/"*.deb; do if [ ! -f "$APTCACHE/"$(basename "$A") -a -f "$A" ]; then echo " -> new cache content "$(basename "$A")" added" if [ "$APTCACHEHARDLINK" = "yes" ]; then ln "$A" "$APTCACHE/" || true else cp "$A" "$APTCACHE/" || true fi fi done fi } #required for some packages to install... export LANG=C export LC_ALL=C