3 # $NetBSD: pkg_comp.sh,v 1.37 2010/04/15 09:42:45 jmmv Exp $
5 # pkg_comp - Build packages inside a clean chroot environment
6 # Copyright (c) 2002, 2003, 2004, 2005 Julio M. Merino Vidal <jmmv@NetBSD.org>
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
17 # 3. Neither the name of author nor the names of its contributors may
18 # be used to endorse or promote products derived from this software
19 # without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
34 ProgName="`basename $0`"
36 # ----------------------------------------------------------------------
37 # Default environment values and functions
38 # ----------------------------------------------------------------------
40 # USE_GCC3, CFLAGS, CPPFLAGS and CXXFLAGS are ommited from _MKCONF_VARS
41 # as they require special handling.
42 _MKCONF_VARS="WRKDIR_BASENAME MKOBJDIRS BSDSRCDIR WRKOBJDIR DISTDIR PACKAGES \
43 PKG_DEVELOPER CLEANDEPENDS LOCALBASE PKG_SYSCONFBASE \
44 CFLAGS CPPFLAGS CXXFLAGS USE_AUDIT_PACKAGES PKGVULNDIR \
45 USE_XPKGWEDGE PKGSRC_COMPILER \
46 LIBKVER_STANDALONE_PREFIX PKG_DBDIR"
48 _TEMPLATE_VARS="DESTDIR ROOTSHELL COPYROOTCFG BUILD_TARGET DISTRIBDIR SETS \
49 SETS_X11 REAL_SRC REAL_SRC_OPTS REAL_PKGSRC \
50 REAL_PKGSRC_OPTS REAL_DISTFILES REAL_DISTFILES_OPTS \
51 REAL_PACKAGES REAL_PACKAGES_OPTS REAL_PKGVULNDIR \
52 NETBSD_RELEASE MAKEROOT_HOOKS MOUNT_HOOKS UMOUNT_HOOKS \
53 SYNC_UMOUNT AUTO_TARGET AUTO_PACKAGES BUILD_PACKAGES \
54 REAL_CCACHE LIBKVER_STANDALONE_PREFIX"
60 # Sets all variables that may appear in the config file to the null
61 # string, so that we know the environment is in a consistent state.
67 for var in ${_MKCONF_VARS} ${_TEMPLATE_VARS}; do
74 # Sets several reasonable defaults for many variables we will use.
75 # Also checks for deprecated variables and warns the user about them.
76 # To be called after reading the configuration file.
80 MKCONF_VARS="$MKCONF_VARS ${_MKCONF_VARS}"
81 TEMPLATE_VARS="$TEMPLATE_VARS ${_TEMPLATE_VARS}"
83 # Default values for variables that will be written to mk.conf.
84 : ${WRKDIR_BASENAME:=default}
86 : ${BSDSRCDIR:=/usr/src}
87 : ${WRKOBJDIR:=/pkg_comp/obj/pkgsrc}
88 : ${DISTDIR:=/pkg_comp/distfiles}
89 : ${PACKAGES:=/pkg_comp/packages}
90 : ${PKG_DEVELOPER:=yes}
91 : ${CLEANDEPENDS:=yes}
92 : ${LOCALBASE:=/usr/pkg}
93 : ${PKG_SYSCONFBASE:=/usr/pkg/etc}
98 : ${USE_AUDIT_PACKAGES:=yes}
99 : ${PKGVULNDIR:=/usr/pkg/share}
100 : ${USE_XPKGWEDGE:=yes}
101 : ${PKGSRC_COMPILER:=gcc}
102 : ${PKG_DBDIR:=/var/db/pkg}
104 # Default values for global variables used in the script.
105 : ${DESTDIR:=/var/chroot/pkg_comp/default}
106 : ${ROOTSHELL:=/bin/ksh}
108 : ${AUTO_TARGET:=package}
109 : ${BUILD_TARGET:=package}
110 : ${DISTRIBDIR:=/var/pub/NetBSD}
111 : ${SETS:=base.tgz comp.tgz etc.tgz kern-GENERIC.tgz text.tgz}
112 : ${SETS_X11:=xbase.tgz xcomp.tgz xetc.tgz xfont.tgz xserver.tgz}
113 : ${REAL_SRC:=/usr/src}
114 : ${REAL_SRC_OPTS:=-t null -o ro}
115 : ${REAL_PKGSRC:=/usr/pkgsrc}
116 : ${REAL_PKGSRC_OPTS:=-t null -o ro}
117 : ${REAL_DISTFILES:=/usr/pkgsrc/distfiles}
118 : ${REAL_DISTFILES_OPTS:=-t null -o rw}
119 : ${REAL_PACKAGES:=/usr/pkgsrc/packages}
120 : ${REAL_PACKAGES_OPTS:=-t null -o rw}
121 : ${REAL_PKGVULNDIR:=/usr/pkgsrc/distfiles}
122 : ${NETBSD_RELEASE:=no}
123 : ${LIBKVER_STANDALONE_PREFIX:=/libkver}
124 : ${MAKEROOT_HOOKS:=}
130 if [ -n "${MAKE_PACKAGES}" ]; then
131 warn "MAKE_PACKAGES is deprecated; use {AUTO,BUILD}_PACKAGES instead."
132 : ${AUTO_PACKAGES:=${MAKE_PACKAGES}}
133 : ${BUILD_PACKAGES:=${MAKE_PACKAGES}}
136 if [ -n "${MOUNT_SCRIPT}" ]; then
137 warn "MOUNT_SCRIPT is deprecated; use MOUNT_HOOKS instead."
138 : ${MOUNT_HOOKS:=${MOUNT_SCRIPT}}
141 if [ -n "${UMOUNT_SCRIPT}" ]; then
142 warn "UMOUNT_SCRIPT is deprecated; use UMOUNT_HOOKS instead."
143 : ${UMOUNT_HOOKS:=${UMOUNT_SCRIPT}}
147 # ----------------------------------------------------------------------
149 # ----------------------------------------------------------------------
153 # Shows the given error message and exit.
157 echo "$ProgName: $1" 1>&2
163 # Shows the given warning message.
167 echo "$ProgName: $1" 1>&2
172 # Shows an usage message and exits.
176 echo "usage: $ProgName [-(c|C) conf_file] [-Nn] target [pkg_names]" 1>&2
180 # copy_vulnerabilities
182 # If USE_AUDIT_PACKAGES is set to 'yes', this function copies the
183 # system-wide pkg-vulnerabilities file inside the sandbox.
185 copy_vulnerabilities()
187 if [ "$USE_AUDIT_PACKAGES" = "yes" ]; then
188 echo "PKG_COMP ==> Installing new \`pkg-vulnerabilities' file"
189 if [ ! -f "$REAL_PKGVULNDIR/pkg-vulnerabilities" ]; then
190 echo "$REAL_PKGVULNDIR/pkg-vulnerabilities not found."
192 mkdir -p $DESTDIR/$PKGVULNDIR
193 cp $REAL_PKGVULNDIR/pkg-vulnerabilities $DESTDIR/$PKGVULNDIR
198 # init_script filename
200 # Create a script that will be used within the sandbox and write some
201 # common content to it.
208 # Generated by pkg_comp on `date`
210 if [ -f ${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so ]; then
211 LD_PRELOAD=${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so; export LD_PRELOAD
217 # ----------------------------------------------------------------------
218 # Filesystem functions
219 # ----------------------------------------------------------------------
223 # Mounts all sandboxed filesystems, if they are not mounted yet.
227 echo "PKG_COMP ==> Mounting sandboxed filesystems"
228 if [ -f $fsstate ]; then
230 count=$(($count + 1))
231 echo "$count" > $fsstate
232 echo "Already mounted (maybe by another pkg_comp process?)"
238 if [ -n "$REAL_SRC" ]; then
239 if [ ! -d "$REAL_SRC" ]; then
242 err "REAL_SRC $REAL_SRC disappeared"
244 mount $REAL_SRC_OPTS $REAL_SRC $DESTDIR/usr/src
247 if [ -n "$REAL_PKGSRC" ]; then
248 if [ ! -d "$REAL_PKGSRC" ]; then
251 err "REAL_PKGSRC $REAL_PKGSRC disappeared"
253 mount $REAL_PKGSRC_OPTS $REAL_PKGSRC $DESTDIR/usr/pkgsrc
256 if [ -n "$REAL_DISTFILES" ]; then
257 if [ ! -d "$REAL_DISTFILES" ]; then
260 err "REAL_DISTFILES $REAL_DISTFILES disappeared"
262 mount $REAL_DISTFILES_OPTS $REAL_DISTFILES $DESTDIR/pkg_comp/distfiles
265 if [ -n "$REAL_PACKAGES" ]; then
266 if [ ! -d "$REAL_PACKAGES" ]; then
269 err "REAL_PACKAGES $REAL_PACKAGES disappeared"
271 mount $REAL_PACKAGES_OPTS $REAL_PACKAGES $DESTDIR/pkg_comp/packages
274 if [ -n "${REAL_CCACHE}" ]; then
275 if [ ! -d "${REAL_CCACHE}" ]; then
278 err "REAL_CCACHE ${REAL_CCACHE} disappeared"
280 mount -t null -o rw ${REAL_CCACHE} ${DESTDIR}/pkg_comp/ccache
285 if [ -n "${MOUNT_HOOKS}" ]; then
286 echo "Executing mount hooks."
287 for h in ${MOUNT_HOOKS}; do
288 ${h} ${DESTDIR} mount
295 # Unmounts all sandboxed filesystems, if they are not in use any more.
299 echo "PKG_COMP ==> Unmounting sandboxed filesystems"
301 if [ ! -f $fsstate ]; then
307 if [ $count -gt 1 ]; then
308 count=$(($count - 1))
309 echo "$count" > $fsstate
310 echo "Still in use (maybe by another pkg_comp process?)"
314 if [ -n "${UMOUNT_HOOKS}" ]; then
315 echo "Executing umount hooks."
316 for h in ${UMOUNT_HOOKS}; do
317 ${h} ${DESTDIR} umount
323 if [ -n "$REAL_SRC" -a -d "$REAL_SRC" ]; then
324 umount $DESTDIR/usr/src || fsfailed=yes
327 if [ -n "$REAL_PKGSRC" -a -d "$REAL_PKGSRC" ]; then
328 umount $DESTDIR/usr/pkgsrc || fsfailed=yes
331 if [ -n "$REAL_DISTFILES" -a -d "$REAL_DISTFILES" ]; then
332 umount $DESTDIR/pkg_comp/distfiles || fsfailed=yes
335 if [ -n "$REAL_PACKAGES" -a -d "$REAL_PACKAGES" ]; then
336 umount $DESTDIR/pkg_comp/packages || fsfailed=yes
339 if [ -n "${REAL_CCACHE}" -a -d "${REAL_CCACHE}" ]; then
340 umount ${DESTDIR}/pkg_comp/ccache || fsfailed=yes
343 if [ "$SYNC_UMOUNT" != "no" ]; then
353 if [ "$fsfailed" = "yes" ]; then
354 err "FATAL: failed to umount all filesystems"
360 # ----------------------------------------------------------------------
361 # maketemplate target
362 # ----------------------------------------------------------------------
366 # Generates a sample configuration file based on the list of variables
367 # given in TEMPLATE_VARS and MKCONF_VARS.
371 if [ -f "$conffile" ]; then
372 err "$conffile already exists"
376 cat > $conffile <<EOF
379 # pkg_comp - configuration file
380 # See pkg_comp(8) for a detailed description of each variable.
385 echo "# Variables used internally by pkg_comp." >> $conffile
386 for var in `echo $TEMPLATE_VARS | tr ' ' '\n' | sort`; do
387 eval val=\""\$$var"\"
388 echo "$var=\"$val\"" >> $conffile
392 echo "# Default variables written to the generated mk.conf." >> $conffile
393 for var in `echo $MKCONF_VARS | tr ' ' '\n' | sort`; do
394 eval val=\""\$$var"\"
395 echo "$var=\"$val\"" >> $conffile
398 echo "pkg_comp: $conffile created. Edit the file by hand now."
401 # ----------------------------------------------------------------------
403 # ----------------------------------------------------------------------
407 # The 'makeroot' target. This creates a new sandbox and then issues
408 # some stuff to be called only when using this specific target.
414 [ "$nflag" = "no" -a -n "$INSTALL_PACKAGES" ] &&
415 pkg_install $INSTALL_PACKAGES
417 [ "$nflag" = "no" -a -n "$BUILD_PACKAGES" ] &&
418 build_and_install $BUILD_PACKAGES
423 # Creates a new sandbox. This is independent from 'makeroot' and
428 # Check for directories that will be null mounted.
429 if [ -n "$REAL_SRC" -a ! -d "$REAL_SRC" ]; then
430 err "REAL_SRC $REAL_SRC does not exist"
433 if [ -n "$REAL_PKGSRC" -a ! -d "$REAL_PKGSRC" ]; then
434 err "REAL_PKGSRC $REAL_PKGSRC does not exist"
437 if [ -n "$REAL_DISTFILES" -a ! -d "$REAL_DISTFILES" ]; then
438 err "REAL_DISTFILES $REAL_DISTFILES does not exist"
441 if [ -n "$REAL_PACKAGES" -a ! -d "$REAL_PACKAGES" ]; then
442 err "REAL_PACKAGES $REAL_PACKAGES does not exist"
445 if echo ${PKGSRC_COMPILER} | grep ccache >/dev/null 2>&1 && \
446 [ -z "${REAL_CCACHE}" ]; then
447 warn "PKGSRC_COMPILER contains 'ccache' but REAL_CCACHE is unset"
448 elif [ -n "${REAL_CCACHE}" -a ! -d "${REAL_CCACHE}" ]; then
449 err "REAL_CCACHE ${REAL_CCACHE} does not exist"
452 # Check for required directories.
453 if [ ! -d $DISTRIBDIR ]; then
454 err "DISTRIBDIR $DISTRIBDIR does not exist"
457 if [ -d $DESTDIR ]; then
458 err "DESTDIR $DESTDIR already exists"
461 if [ "$SETS_X11" = "no" ]; then
464 allsets="$SETS $SETS_X11"
467 for s in $allsets; do
468 if [ ! -f $DISTRIBDIR/binary/sets/$s ]; then
469 err "$DISTRIBDIR/binary/sets/$s does not exist"
473 echo "PKG_COMP ==> Creating sandbox \`${DESTDIR}'"
478 for s in $allsets; do
479 echo "Extracting $s..."
480 tar xzpf $DISTRIBDIR/binary/sets/$s
483 [ -f ${DESTDIR}/netbsd ] || touch ${DESTDIR}/netbsd
485 echo "Making device nodes..."
490 echo "Setting root's environment..."
491 chroot $DESTDIR chpass -s $ROOTSHELL
492 if [ "$COPYROOTCFG" = "yes" ]; then
493 cp /root/.* $DESTDIR/root >/dev/null 2>&1
495 if [ -n "${REAL_CCACHE}" ]; then
496 # This is a workaround for older versions of ccache.mk that do not
497 # pass the CCACHE_DIR variable down to ccache.
498 ( cd ${DESTDIR}/root && ln -fs ../pkg_comp/ccache .ccache )
501 echo "Setting up initial configuration..."
503 mkdir -p $DESTDIR/usr/src
504 mkdir -p $DESTDIR/usr/pkgsrc
505 mkdir -p $DESTDIR/pkg_comp/distfiles
506 mkdir -p $DESTDIR/pkg_comp/packages
507 mkdir -p $DESTDIR/pkg_comp/tmp
508 mkdir -p $DESTDIR/pkg_comp/obj/pkgsrc
509 [ -n "${REAL_CCACHE}" ] && mkdir -p ${DESTDIR}/pkg_comp/ccache
510 ( cd $DESTDIR && ln -s pkg_comp p )
512 # Set sh configuration
513 echo "umask 022" >> $DESTDIR/etc/profile
514 echo "ENV=/etc/shrc" >> $DESTDIR/etc/profile
515 echo "export PS1=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc/shrc
516 echo "set -o emacs" >> $DESTDIR/etc/shrc
517 echo "export PKG_DBDIR=\"${PKG_DBDIR}\"" >> ${DESTDIR}/etc/shrc
519 # Set csh configuration
520 echo "umask 022" >> $DESTDIR/etc/csh.login
521 echo "set prompt=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc/csh.login
522 echo "set prompt=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc/csh.cshrc
523 echo "setenv PKG_DBDIR \"${PKG_DBDIR}\"" >> ${DESTDIR}/etc/csh.cshrc
525 cp /etc/resolv.conf $DESTDIR/etc/resolv.conf
529 echo "PKG_DBDIR=${PKG_DBDIR}" >> ${DESTDIR}/etc/pkg_install.conf
531 # From now on, filesystems may be mounted, so we need to trap
532 # signals to umount them.
533 trap "echo \"*** Process aborted ***\" ; fsumount ; exit 1" INT QUIT
536 [ "$Nflag" = "no" ] && makeroot_digest
538 if [ "$USE_GCC3" = "yes" -a "$Nflag" = "no" ]; then
539 if [ -z "`echo $BUILD_PACKAGES $INSTALL_PACKAGES | grep gcc3`" ]; then
540 AVOID_GCC3=yes build_and_install lang/gcc3
546 if [ -n "${MAKEROOT_HOOKS}" ]; then
547 echo "Executing makeroot hooks."
548 for h in ${MAKEROOT_HOOKS}; do
549 ${h} ${DESTDIR} makeroot
556 # Generates a mk.conf file inside the sandbox, based on the content
557 # of MKCONF_VARS and EXTRAMK. Also handles some special stuff.
561 file="$DESTDIR/etc/mk.conf"
566 # File automatically generated by pkg_comp on `date`
572 for var in $MKCONF_VARS; do
573 eval val=\""\$$var"\"
574 echo "$var ?= $val" >> $file
577 if [ -n "$EXTRAMK" ]; then
578 for mkfile in $EXTRAMK; do
579 if [ ! -f "$mkfile" ]; then
580 err "Cannot find $mkfile"
587 if [ "$USE_AUDIT_PACKAGES" != "yes" ]; then
588 echo "ALLOW_VULNERABLE_PACKAGES ?= YES" >> $file
591 if [ "$USE_GCC3" = "yes" ]; then
593 .if !defined(AVOID_GCC3) && exists(/usr/pkg/share/examples/gcc-3.3/mk.conf)
596 CPPFLAGS += $CPPFLAGS
597 CXXFLAGS += $CXXFLAGS
598 .include "/usr/pkg/share/examples/gcc-3.3/mk.conf"
604 CPPFLAGS += $CPPFLAGS
605 CXXFLAGS += $CXXFLAGS
614 # Ensure digest is always installed, specially because PKGSRC_COMPILER
615 # may contain 'ccache' or 'distcc'.
619 ( PKGSRC_COMPILER=gcc; export PKGSRC_COMPILER; \
620 build_and_install pkgtools/digest )
625 # If NETBSD_RELEASE is set to a version string, installs libkver
626 # inside the sandbox and configures it.
630 local prefix script statfile
632 if [ "$NETBSD_RELEASE" != "no" ]; then
633 _BUILD_TARGET="$BUILD_TARGET"
634 BUILD_TARGET="standalone-install"
635 build_and_install pkgtools/libkver
636 BUILD_TARGET="$_BUILD_TARGET"
637 echo "LD_PRELOAD=${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so; export LD_PRELOAD" >> $DESTDIR/etc/shrc
638 echo "setenv LD_PRELOAD ${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so" >> $DESTDIR/etc/csh.login
639 echo "setenv LD_PRELOAD ${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so" >> $DESTDIR/etc/csh.cshrc
640 ln -s "$NETBSD_RELEASE" $DESTDIR/libkver_osrelease
646 # If X11 is enabled, installs x11-links inside the sandbox.
647 # If USE_XPKGWEDGE is yes, configures xpkgwedge too (but does not
648 # install it; pkgsrc will take care of that when needed).
652 if [ "$SETS_X11" != "no" ]; then
653 if [ "$USE_XPKGWEDGE" = "yes" ]; then
654 echo "export XAPPLRESDIR=${LOCALBASE}/lib/X11/app-defaults" >> $DESTDIR/etc/profile
655 echo "setenv XAPPLRESDIR ${LOCALBASE}/lib/X11/app-defaults" >> $DESTDIR/etc/csh.login
657 [ "$Nflag" = "no" ] && build_and_install pkgtools/x11-links
661 # ----------------------------------------------------------------------
663 # ----------------------------------------------------------------------
671 local pkgs rfile target
673 pkgs="${*:-${AUTO_PACKAGES}}"
674 rfile=${DESTDIR}/pkg_comp/tmp/auto.list
675 target="${AUTO_TARGET}"
677 [ -z "${REAL_PACKAGES}" ] && err "this is useless without REAL_PACKAGES"
679 err "this is useless without AUTO_PACKAGES nor package names"
681 if [ "$1" = resume ]; then
682 [ -f ${rfile} ] || err "there is no auto build to resume"
684 elif [ -f ${rfile} ]; then
685 err "there is an stopped auto build; removeroot first or resume it"
689 [ "$nflag" = "no" -a -n "$INSTALL_PACKAGES" ] &&
690 pkg_install $INSTALL_PACKAGES
692 echo ${pkgs} | tr ' ' '\n' > ${rfile}
696 _BUILD_RESUME=${rfile} BUILD_TARGET=${target} pkg_build ${pkgs}
700 # ----------------------------------------------------------------------
702 # ----------------------------------------------------------------------
706 # The build target. Also used as a helper function within this script
707 # to build several packages when needed.
711 local failed invalid p pkgs script statfile
715 # Check if all packages exist
718 if [ ! -d $REAL_PKGSRC/$p ]; then
719 invalid="$invalid $p"
722 if [ -n "$invalid" ]; then
723 err "invalid packages:$invalid"
728 check_pkg_install # executes copy_vulnerabilities too
731 echo "PKG_COMP ==> Building and installing $p"
732 prefix=$(mktemp $DESTDIR/pkg_comp/tmp/pkg_comp-XXXXXX)
735 statfile="$prefix.stat"
740 if [ \$? != 0 ]; then
741 touch /pkg_comp/tmp/`basename $statfile`
746 chroot $DESTDIR /pkg_comp/tmp/`basename $script`
748 if [ -f $statfile ]; then
751 elif [ -n "${_BUILD_RESUME}" ]; then
752 grep -v "^${p}\$" < ${_BUILD_RESUME} > ${_BUILD_RESUME}.new
753 mv ${_BUILD_RESUME}.new ${_BUILD_RESUME}
757 if [ -n "$failed" ]; then
758 echo "PKG_COMP ==> Build error summary"
759 echo "Build failed for:"
768 # Ensure that the version of pkg_install inside the sandbox is new
769 # enough to work with pkgsrc. If not, rebuild it.
777 # We assume filesystems are mounted!
779 echo "PKG_COMP ==> Checking if pkg_install is up to date"
780 script=$(mktemp $DESTDIR/pkg_comp/tmp/pkg_comp-XXXXXX).sh
783 cd /usr/pkgsrc/pkgtools/pkg_comp
784 fail=\$(make show-var VARNAME=PKG_FAIL_REASON)
785 if echo \$fail | grep "package tools installed on this system are out of date" >/dev/null; then
786 echo "PKG_COMP ==> pkg_install is out of date; rebuilding"
787 cd /usr/pkgsrc/pkgtools/pkg_install
788 make && make install && make clean
792 chroot $DESTDIR /pkg_comp/tmp/`basename $script`
796 # build_and_install pkg
798 # Builds a package and ensures it gets installed. The use of destdir to
799 # build packages may cause a package to get built but not installed,
800 # which is not OK for this script. This is for internal usage only.
806 if pkg_build ${pkg}; then
807 script=$(mktemp ${DESTDIR}/pkg_comp/tmp/pkg_comp-XXXXXX).sh
808 init_script ${script}
809 cat >>${script} <<EOF
810 cd /usr/pkgsrc/${pkg}
811 pkgname=\$(make show-var VARNAME=PKGNAME)
812 if pkg_info -E \${pkgname} 2>/dev/null; then
815 echo "PKG_COMP ==> Forcing installation of \${pkgname}"
816 cd /pkg_comp/packages/All
821 chroot ${DESTDIR} /pkg_comp/tmp/$(basename ${script})
827 # ----------------------------------------------------------------------
829 # ----------------------------------------------------------------------
833 # The install target. Also used as a helper function within this
834 # script to install several packages when needed.
838 local failed pkgs stat
842 [ -z "$REAL_PACKAGES" ] && err "REAL_PACKAGES is not set"
848 for p in $(cd ${REAL_PACKAGES}/All && echo ${pkgs}); do
849 echo "PKG_COMP ==> Installing binary package: $p"
850 stat=$DESTDIR/pkg_comp/tmp/install.sh
853 cd /pkg_comp/packages/All
857 chroot $DESTDIR /pkg_comp/tmp/install.sh || failed="$failed $p"
861 [ -n "$failed" ] && echo "Installation failed for:$failed"
864 # ----------------------------------------------------------------------
866 # ----------------------------------------------------------------------
870 # The 'chroot' target.
874 local prefix script exitstatus
876 [ -d $DESTDIR ] || err "$DESTDIR does not exist"
881 echo "PKG_COMP ==> Entering sandbox \`$DESTDIR'"
882 prefix=$(mktemp $DESTDIR/pkg_comp/tmp/pkg_comp-XXXXXX)
886 if [ $# -eq 0 ]; then
888 ENV=/etc/shrc $ROOTSHELL
896 ENV=/etc/shrc chroot $DESTDIR /pkg_comp/tmp/`basename $script`
904 # ----------------------------------------------------------------------
906 # ----------------------------------------------------------------------
910 # The 'removeroot' target.
914 [ -f $fsstate ] && err "filesystems may still be mounted; cannot remove"
915 echo "PKG_COMP ==> Removing sandbox \`${DESTDIR}'"
919 # ----------------------------------------------------------------------
921 # ----------------------------------------------------------------------
923 confdir="$HOME/pkg_comp"
926 args=`getopt c:C:nN $*`
934 while [ $# -gt 0 ]; do
937 [ -n "$conffile" ] && usage
938 conffile="$confdir/$2.conf"
942 [ -n "$conffile" ] && usage
960 if [ $# -lt 1 ]; then
964 if [ -z "$conffile" ]; then
965 conffile="$confdir/default.conf"
981 # Reads the configuration file and ensures that the environment is in
982 # a consistent state.
986 if [ -f $conffile ]; then
987 [ `id -u` -ne 0 ] && err "must be run as root"
992 err "$conffile does not exist"
995 fsstate="$DESTDIR/pkg_comp/tmp/mount.stat"
1000 # Checks that the sandbox is initialized, that it's a valid directory
1001 # and configures a signal trap for SIGINT and SIGQUIT.
1005 if [ ! -d "$DESTDIR" ]; then
1006 err "sandbox not initialized; use makeroot first."
1008 if [ "$DESTDIR" = "/" ]; then
1009 err "DESTDIR cannot be /"
1012 # From now on, filesystems may be mounted, so we need to trap
1013 # signals to umount them.
1014 trap "echo \"*** Process aborted ***\" ; fsumount ; exit 1" INT QUIT
1057 err "unknown target \`$target'"
1063 # vim: expandtab:softtabstop=4:shiftwidth=4