Source

pbuilder / pbuilder

Full commit
#! /bin/bash
#   pbuilder -- personal Debian package builder
#   Copyright (C) 2001-2007 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

# pbuilder by Junichi Uekawa <dancer@debian.org> 2001 Aug 25

set -e 

# export this so that programs know which command line
# operation is currently done
export PBCURRENTCOMMANDLINEOPERATION="$1"
umask 0022

case "$1" in
    --create|create)
	shift;
	/usr/lib/pbuilder/pbuilder-createbuildenv "$@"
	;;
    --update|update)
	shift ;
	/usr/lib/pbuilder/pbuilder-updatebuildenv "$@"
	;;
    --build|build)
	shift ;
	/usr/lib/pbuilder/pbuilder-buildpackage "$@"
	;;
    --clean|clean)
	shift;
	. /usr/lib/pbuilder/pbuilder-checkparams
	if [ -n "$BASEBUILDPLACE" ]; then 
	    echo "Cleaning [$BASEBUILDPLACE]"
	    clean_subdirectories "$BASEBUILDPLACE" || true
	fi
	if [ -n "$APTCACHE" ]; then
	    echo "Cleaning [$APTCACHE]"
	    rm "$APTCACHE"/* || true
	fi
	;;
    --login|login)
	shift 
	. /usr/lib/pbuilder/pbuilder-checkparams
	. /usr/lib/pbuilder/pbuilder-runhooks
	extractbuildplace
	trap umountproc_cleanbuildplace_trap exit sighup
	loadhooks
	recover_aptcache
	trap saveaptcache_umountproc_cleanbuildplace_trap exit sighup

	if [ "${INTERNAL_BUILD_UML}" = "yes" ]; then
	    echo " -> entering the shell"
	else
	    echo " -> entering the shell
File extracted to: $BUILDPLACE
"
	fi
	executehooks "F"
	(${CHROOTEXEC} bin/bash -c 'exec -a -bash bin/bash')
	RET=$?

	save_aptcache

	trap umountproc_cleanbuildplace_trap exit sighup

	# saving the place afterwards
	if [ "${SAVE_AFTER_LOGIN}" = "yes" ]; then
	    if [ "${INTERNAL_BUILD_UML}" = "yes" ]; then
		echo "E: Invalid combination of internal-build-uml and save-after-login flags" >&2
		exit 1
	    else
		echo " -> Saving the results, modifications to this session will persist"
		unloadhooks
		umountproc
		trap cleanbuildplace_trap exit sighup
		${CHROOTEXEC} /usr/bin/apt-get clean || true
		create_basetgz
		cleanbuildplace
		trap - exit sighup
		exit $RET
	    fi
	fi
	umountproc_cleanbuildplace
	trap - exit sighup
	exit $RET
	;;
    --execute|execute)
	# try to execute arbitrary program.
	shift
	. /usr/lib/pbuilder/pbuilder-checkparams
	. /usr/lib/pbuilder/pbuilder-runhooks
	EXECPROGRAM="$1"
	shift
	if [ ! -f "${EXECPROGRAM}" ]; then
	    echo "Command line parameter [$EXECPROGRAM] does not exist" >&2
	    exit 1;
	fi;
	extractbuildplace

	trap umountproc_cleanbuildplace_trap exit sighup

	loadhooks
	recover_aptcache
	trap saveaptcache_umountproc_cleanbuildplace_trap exit sighup

	RUNNAME="$BUILDPLACE/run"
	cat "$EXECPROGRAM" > "$RUNNAME"
	chmod a+x "$RUNNAME"
	executehooks "F"
	( ${CHROOTEXEC} /run "$@" )
	RET=$?
	rm -f "$RUNNAME"

	save_aptcache
	trap umountproc_cleanbuildplace_trap exit sighup

	# saving the place afterwards
	if [ "${SAVE_AFTER_LOGIN}" = "yes" ]; then
	    if [ "${INTERNAL_BUILD_UML}" = "yes" ]; then
		echo "E: Invalid combination of internal-build-uml and save-after-login flags" >&2 
	    else
		echo " -> Saving the results, modifications to this session will persist"
		unloadhooks
		umountproc
		trap cleanbuildplace_trap exit sighup
		${CHROOTEXEC} /usr/bin/apt-get clean || true
		create_basetgz
		cleanbuildplace
		trap - exit sighup
		exit $RET
	    fi
	fi
	umountproc_cleanbuildplace
	trap - exit sighup
	exit $RET
	;;
    --dumpconfig|dumpconfig)
	shift
	. /usr/lib/pbuilder/pbuilder-checkparams
	. /usr/lib/pbuilder/pbuilder-runhooks
	extractbuildplace
	trap umountproc_cleanbuildplace_trap exit sighup
	loadhooks
	executehooks "F"
	echo " -> start dump config"
	echo "  -> set"
	set;
	echo "  -> env"
	env;
	echo " -> end dump config"
	;;
    --debuild|debuild)
	shift
	"$0" execute "$@" /usr/lib/pbuilder/pdebuild-internal
	;;
    *)
	. /usr/lib/pbuilder/pbuilder-modules
	showhelp
	;;
esac