3 # $NetBSD: pkg_comp.sh,v 1.40 2012/02/27 22:42:27 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 GENERATE_PKG_SUMMARY"
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:=}
129 : ${GENERATE_PKG_SUMMARY:=yes}
131 if [ -n "${MAKE_PACKAGES}" ]; then
132 warn
"MAKE_PACKAGES is deprecated; use {AUTO,BUILD}_PACKAGES instead."
133 : ${AUTO_PACKAGES:=${MAKE_PACKAGES}}
134 : ${BUILD_PACKAGES:=${MAKE_PACKAGES}}
137 if [ -n "${MOUNT_SCRIPT}" ]; then
138 warn
"MOUNT_SCRIPT is deprecated; use MOUNT_HOOKS instead."
139 : ${MOUNT_HOOKS:=${MOUNT_SCRIPT}}
142 if [ -n "${UMOUNT_SCRIPT}" ]; then
143 warn
"UMOUNT_SCRIPT is deprecated; use UMOUNT_HOOKS instead."
144 : ${UMOUNT_HOOKS:=${UMOUNT_SCRIPT}}
148 # ----------------------------------------------------------------------
150 # ----------------------------------------------------------------------
154 # Shows the given error message and exit.
158 echo "$ProgName: $1" 1>&2
164 # Shows the given warning message.
168 echo "$ProgName: $1" 1>&2
173 # Shows an usage message and exits.
177 echo "usage: $ProgName [-(c|C) conf_file] [-Nn] target [pkg_names]" 1>&2
181 # copy_vulnerabilities
183 # If USE_AUDIT_PACKAGES is set to 'yes', this function copies the
184 # system-wide pkg-vulnerabilities file inside the sandbox.
186 copy_vulnerabilities
()
188 if [ "$USE_AUDIT_PACKAGES" = "yes" ]; then
189 echo "PKG_COMP ==> Installing new \`pkg-vulnerabilities' file"
190 if [ ! -f "$REAL_PKGVULNDIR/pkg-vulnerabilities" ]; then
191 echo "$REAL_PKGVULNDIR/pkg-vulnerabilities not found."
193 mkdir
-p $DESTDIR/$PKGVULNDIR
194 cp $REAL_PKGVULNDIR/pkg-vulnerabilities
$DESTDIR/$PKGVULNDIR
199 # init_script filename
201 # Create a script that will be used within the sandbox and write some
202 # common content to it.
209 # Generated by pkg_comp on `date`
211 if [ -f ${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so ]; then
212 LD_PRELOAD=${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so; export LD_PRELOAD
218 # ----------------------------------------------------------------------
219 # Filesystem functions
220 # ----------------------------------------------------------------------
224 # Mounts all sandboxed filesystems, if they are not mounted yet.
228 echo "PKG_COMP ==> Mounting sandboxed filesystems"
229 if [ -f $fsstate ]; then
231 count
=$
(($count + 1))
232 echo "$count" > $fsstate
233 echo "Already mounted (maybe by another pkg_comp process?)"
239 if [ -n "$REAL_SRC" ]; then
240 if [ ! -d "$REAL_SRC" ]; then
243 err
"REAL_SRC $REAL_SRC disappeared"
245 mount
$REAL_SRC_OPTS $REAL_SRC $DESTDIR/usr
/src
248 if [ -n "$REAL_PKGSRC" ]; then
249 if [ ! -d "$REAL_PKGSRC" ]; then
252 err
"REAL_PKGSRC $REAL_PKGSRC disappeared"
254 mount
$REAL_PKGSRC_OPTS $REAL_PKGSRC $DESTDIR/usr
/pkgsrc
257 if [ -n "$REAL_DISTFILES" ]; then
258 if [ ! -d "$REAL_DISTFILES" ]; then
261 err
"REAL_DISTFILES $REAL_DISTFILES disappeared"
263 mount
$REAL_DISTFILES_OPTS $REAL_DISTFILES $DESTDIR/pkg_comp
/distfiles
266 if [ -n "$REAL_PACKAGES" ]; then
267 if [ ! -d "$REAL_PACKAGES" ]; then
270 err
"REAL_PACKAGES $REAL_PACKAGES disappeared"
272 mount
$REAL_PACKAGES_OPTS $REAL_PACKAGES $DESTDIR/pkg_comp
/packages
275 if [ -n "${REAL_CCACHE}" ]; then
276 if [ ! -d "${REAL_CCACHE}" ]; then
279 err
"REAL_CCACHE ${REAL_CCACHE} disappeared"
281 mount
-t null
-o rw
${REAL_CCACHE} ${DESTDIR}/pkg_comp
/ccache
286 if [ -n "${MOUNT_HOOKS}" ]; then
287 echo "Executing mount hooks."
288 for h
in ${MOUNT_HOOKS}; do
289 ${h} ${DESTDIR} mount
296 # Unmounts all sandboxed filesystems, if they are not in use any more.
300 echo "PKG_COMP ==> Unmounting sandboxed filesystems"
302 if [ ! -f $fsstate ]; then
308 if [ $count -gt 1 ]; then
309 count
=$
(($count - 1))
310 echo "$count" > $fsstate
311 echo "Still in use (maybe by another pkg_comp process?)"
315 if [ -n "${UMOUNT_HOOKS}" ]; then
316 echo "Executing umount hooks."
317 for h
in ${UMOUNT_HOOKS}; do
318 ${h} ${DESTDIR} umount
324 if [ -n "$REAL_SRC" -a -d "$REAL_SRC" ]; then
325 umount
$DESTDIR/usr
/src || fsfailed
=yes
328 if [ -n "$REAL_PKGSRC" -a -d "$REAL_PKGSRC" ]; then
329 umount
$DESTDIR/usr
/pkgsrc || fsfailed
=yes
332 if [ -n "$REAL_DISTFILES" -a -d "$REAL_DISTFILES" ]; then
333 umount
$DESTDIR/pkg_comp
/distfiles || fsfailed
=yes
336 if [ -n "$REAL_PACKAGES" -a -d "$REAL_PACKAGES" ]; then
337 umount
$DESTDIR/pkg_comp
/packages || fsfailed
=yes
340 if [ -n "${REAL_CCACHE}" -a -d "${REAL_CCACHE}" ]; then
341 umount
${DESTDIR}/pkg_comp
/ccache || fsfailed
=yes
344 if [ "$SYNC_UMOUNT" != "no" ]; then
354 if [ "$fsfailed" = "yes" ]; then
355 err
"FATAL: failed to umount all filesystems"
361 # ----------------------------------------------------------------------
362 # maketemplate target
363 # ----------------------------------------------------------------------
367 # Generates a sample configuration file based on the list of variables
368 # given in TEMPLATE_VARS and MKCONF_VARS.
372 if [ -f "$conffile" ]; then
373 err
"$conffile already exists"
377 cat > $conffile <<EOF
380 # pkg_comp - configuration file
381 # See pkg_comp(8) for a detailed description of each variable.
386 echo "# Variables used internally by pkg_comp." >> $conffile
387 for var
in `echo $TEMPLATE_VARS | tr ' ' '\n' | sort`; do
388 eval val
=\""\$$var"\"
389 echo "$var=\"$val\"" >> $conffile
393 echo "# Default variables written to the generated mk.conf." >> $conffile
394 for var
in `echo $MKCONF_VARS | tr ' ' '\n' | sort`; do
395 eval val
=\""\$$var"\"
396 echo "$var=\"$val\"" >> $conffile
399 echo "pkg_comp: $conffile created. Edit the file by hand now."
402 # ----------------------------------------------------------------------
404 # ----------------------------------------------------------------------
408 # The 'makeroot' target. This creates a new sandbox and then issues
409 # some stuff to be called only when using this specific target.
415 [ "$nflag" = "no" -a -n "$INSTALL_PACKAGES" ] &&
416 pkg_install
$INSTALL_PACKAGES
418 if [ "$nflag" = "no" -a -n "$BUILD_PACKAGES" ]; then
419 for pkg
in $BUILD_PACKAGES; do
420 build_and_install
$pkg
427 # Creates a new sandbox. This is independent from 'makeroot' and
432 # Check for directories that will be null mounted.
433 if [ -n "$REAL_SRC" -a ! -d "$REAL_SRC" ]; then
434 err
"REAL_SRC $REAL_SRC does not exist"
437 if [ -n "$REAL_PKGSRC" -a ! -d "$REAL_PKGSRC" ]; then
438 err
"REAL_PKGSRC $REAL_PKGSRC does not exist"
441 if [ -n "$REAL_DISTFILES" -a ! -d "$REAL_DISTFILES" ]; then
442 err
"REAL_DISTFILES $REAL_DISTFILES does not exist"
445 if [ -n "$REAL_PACKAGES" -a ! -d "$REAL_PACKAGES" ]; then
446 err
"REAL_PACKAGES $REAL_PACKAGES does not exist"
449 if echo ${PKGSRC_COMPILER} |
grep ccache
>/dev
/null
2>&1 && \
450 [ -z "${REAL_CCACHE}" ]; then
451 warn
"PKGSRC_COMPILER contains 'ccache' but REAL_CCACHE is unset"
452 elif [ -n "${REAL_CCACHE}" -a ! -d "${REAL_CCACHE}" ]; then
453 err
"REAL_CCACHE ${REAL_CCACHE} does not exist"
456 # Check for required directories.
457 if [ ! -d $DISTRIBDIR ]; then
458 err
"DISTRIBDIR $DISTRIBDIR does not exist"
461 if [ -d $DESTDIR ]; then
462 err
"DESTDIR $DESTDIR already exists"
465 if [ "$SETS_X11" = "no" ]; then
468 allsets
="$SETS $SETS_X11"
471 for s
in $allsets; do
472 if [ ! -f $DISTRIBDIR/binary
/sets
/$s ]; then
473 err
"$DISTRIBDIR/binary/sets/$s does not exist"
477 echo "PKG_COMP ==> Creating sandbox \`${DESTDIR}'"
482 for s
in $allsets; do
483 echo "Extracting $s..."
484 tar xzpf
$DISTRIBDIR/binary
/sets
/$s
487 [ -f ${DESTDIR}/netbsd
] ||
touch ${DESTDIR}/netbsd
489 echo "Making device nodes..."
494 echo "Setting root's environment..."
495 chroot
$DESTDIR chpass
-s $ROOTSHELL
496 if [ "$COPYROOTCFG" = "yes" ]; then
497 cp /root
/.
* $DESTDIR/root
>/dev
/null
2>&1
499 if [ -n "${REAL_CCACHE}" ]; then
500 # This is a workaround for older versions of ccache.mk that do not
501 # pass the CCACHE_DIR variable down to ccache.
502 ( cd ${DESTDIR}/root
&& ln -fs ..
/pkg_comp
/ccache .ccache
)
505 echo "Setting up initial configuration..."
507 mkdir
-p $DESTDIR/usr
/src
508 mkdir
-p $DESTDIR/usr
/pkgsrc
509 mkdir
-p $DESTDIR/pkg_comp
/distfiles
510 mkdir
-p $DESTDIR/pkg_comp
/packages
511 mkdir
-p $DESTDIR/pkg_comp
/tmp
512 mkdir
-p $DESTDIR/pkg_comp
/obj
/pkgsrc
513 [ -n "${REAL_CCACHE}" ] && mkdir
-p ${DESTDIR}/pkg_comp
/ccache
514 ( cd $DESTDIR && ln -s pkg_comp p
)
516 # Set sh configuration
517 echo "umask 022" >> $DESTDIR/etc
/profile
518 echo "ENV=/etc/shrc" >> $DESTDIR/etc
/profile
519 echo "export PS1=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc
/shrc
520 echo "set -o emacs" >> $DESTDIR/etc
/shrc
521 echo "export PKG_DBDIR=\"${PKG_DBDIR}\"" >> ${DESTDIR}/etc
/shrc
523 # Set csh configuration
524 echo "umask 022" >> $DESTDIR/etc
/csh.login
525 echo "set prompt=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc
/csh.login
526 echo "set prompt=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc
/csh.cshrc
527 echo "setenv PKG_DBDIR \"${PKG_DBDIR}\"" >> ${DESTDIR}/etc
/csh.cshrc
529 cp /etc
/resolv.conf
$DESTDIR/etc
/resolv.conf
533 echo "PKG_DBDIR=${PKG_DBDIR}" >> ${DESTDIR}/etc
/pkg_install.conf
535 # From now on, filesystems may be mounted, so we need to trap
536 # signals to umount them.
537 trap "echo \"*** Process aborted ***\" ; fsumount ; exit 1" INT QUIT
541 if [ "$USE_GCC3" = "yes" -a "$Nflag" = "no" ]; then
542 if [ -z "`echo $BUILD_PACKAGES $INSTALL_PACKAGES | grep gcc3`" ]; then
543 AVOID_GCC3
=yes build_and_install lang
/gcc3
549 if [ -n "${MAKEROOT_HOOKS}" ]; then
550 echo "Executing makeroot hooks."
551 for h
in ${MAKEROOT_HOOKS}; do
552 ${h} ${DESTDIR} makeroot
559 # Generates a mk.conf file inside the sandbox, based on the content
560 # of MKCONF_VARS and EXTRAMK. Also handles some special stuff.
564 file="$DESTDIR/etc/mk.conf"
569 # File automatically generated by pkg_comp on `date`
575 for var
in $MKCONF_VARS; do
576 eval val
=\""\$$var"\"
577 echo "$var ?= $val" >> $file
580 if [ -n "$EXTRAMK" ]; then
581 for mkfile
in $EXTRAMK; do
582 if [ ! -f "$mkfile" ]; then
583 err
"Cannot find $mkfile"
590 if [ "$USE_AUDIT_PACKAGES" != "yes" ]; then
591 echo "ALLOW_VULNERABLE_PACKAGES ?= YES" >> $file
594 if [ "$USE_GCC3" = "yes" ]; then
596 .if !defined(AVOID_GCC3) && exists(/usr/pkg/share/examples/gcc-3.3/mk.conf)
599 CPPFLAGS += $CPPFLAGS
600 CXXFLAGS += $CXXFLAGS
601 .include "/usr/pkg/share/examples/gcc-3.3/mk.conf"
607 CPPFLAGS += $CPPFLAGS
608 CXXFLAGS += $CXXFLAGS
617 # If NETBSD_RELEASE is set to a version string, installs libkver
618 # inside the sandbox and configures it.
622 local prefix
script statfile
624 if [ "$NETBSD_RELEASE" != "no" ]; then
625 _BUILD_TARGET
="$BUILD_TARGET"
626 BUILD_TARGET
="standalone-install"
627 build_and_install pkgtools
/libkver
628 BUILD_TARGET
="$_BUILD_TARGET"
629 echo "LD_PRELOAD=${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so; export LD_PRELOAD" >> $DESTDIR/etc
/shrc
630 echo "setenv LD_PRELOAD ${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so" >> $DESTDIR/etc
/csh.login
631 echo "setenv LD_PRELOAD ${LIBKVER_STANDALONE_PREFIX}/lib/libkver.so" >> $DESTDIR/etc
/csh.cshrc
632 ln -s "$NETBSD_RELEASE" $DESTDIR/libkver_osrelease
638 # If X11 is enabled, installs x11-links inside the sandbox.
639 # If USE_XPKGWEDGE is yes, configures xpkgwedge too (but does not
640 # install it; pkgsrc will take care of that when needed).
644 if [ "$SETS_X11" != "no" ]; then
645 if [ "$USE_XPKGWEDGE" = "yes" ]; then
646 echo "export XAPPLRESDIR=${LOCALBASE}/lib/X11/app-defaults" >> $DESTDIR/etc
/profile
647 echo "setenv XAPPLRESDIR ${LOCALBASE}/lib/X11/app-defaults" >> $DESTDIR/etc
/csh.login
649 [ "$Nflag" = "no" ] && build_and_install pkgtools
/x11-links
653 # ----------------------------------------------------------------------
655 # ----------------------------------------------------------------------
663 local pkgs rfile target
665 pkgs
="${*:-${AUTO_PACKAGES}}"
666 rfile
=${DESTDIR}/pkg_comp
/tmp
/auto.list
667 target
="${AUTO_TARGET}"
669 [ -z "${REAL_PACKAGES}" ] && err
"this is useless without REAL_PACKAGES"
671 err
"this is useless without AUTO_PACKAGES nor package names"
673 if [ "$1" = resume
]; then
674 [ -f ${rfile} ] || err
"there is no auto build to resume"
676 elif [ -f ${rfile} ]; then
677 err
"there is an stopped auto build; removeroot first or resume it"
681 [ "$nflag" = "no" -a -n "$INSTALL_PACKAGES" ] &&
682 pkg_install
$INSTALL_PACKAGES
684 echo ${pkgs} |
tr ' ' '\n' > ${rfile}
688 _BUILD_RESUME
=${rfile} BUILD_TARGET=${target} pkg_build ${pkgs}
692 # generate_pkg_summary directory
694 # Generates a pkg_summary.gz file in the specified directory.
695 generate_pkg_summary
()
697 local directory
="${1}"; shift
699 echo "PKG_COMP ==> Generating pkg_summary.tgz"
700 for pkg
in "${directory}"/*.tgz
; do pkg_info
-X "${pkg}"; done \
701 |
gzip -c >"${directory}"/pkg_summary.gz
704 # ----------------------------------------------------------------------
706 # ----------------------------------------------------------------------
710 # The build target. Also used as a helper function within this script
711 # to build several packages when needed.
715 local failed invalid p pkgs
script statfile
719 for pkg
in "${@}"; do
720 local match
="$(find_pkg "${pkg}")"
721 if [ -z "${match}" ]; then
722 invalid
="${invalid} ${pkg}"
724 pkgs
="${pkgs} ${match}"
727 if [ -n "$invalid" ]; then
728 err
"invalid packages:$invalid"
736 echo "PKG_COMP ==> Building and installing $p"
737 prefix
=$
(mktemp
$DESTDIR/pkg_comp
/tmp
/pkg_comp-XXXXXX
)
740 statfile
="$prefix.stat"
745 if [ \$? != 0 ]; then
746 touch /pkg_comp/tmp/`basename $statfile`
751 chroot
$DESTDIR /pkg_comp
/tmp
/`basename $script`
753 if [ -f $statfile ]; then
756 elif [ -n "${_BUILD_RESUME}" ]; then
757 grep -v "^${p}\$" < ${_BUILD_RESUME} > ${_BUILD_RESUME}.new
758 mv ${_BUILD_RESUME}.new ${_BUILD_RESUME}
762 if [ -n "$failed" ]; then
763 echo "PKG_COMP
==> Build error summary
"
764 echo "Build failed
for:"
769 if [ "${GENERATE_PKG_SUMMARY}" = yes ]; then
770 generate_pkg_summary "${REAL_PACKAGES}/All
"
776 # Checks if the given package exists and outputs its path within pkgsrc.
777 # Outputs nothing if the package is not found.
784 if [ -d "${REAL_PKGSRC}/${name}" ]; then
787 : # Not found; output nothing.
791 local match="$
(cd "${REAL_PKGSRC}" && echo */"${name}")"
792 if [ -d "${REAL_PKGSRC}/${match}" ]; then
795 : # Not found; output nothing.
800 # build_and_install pkg
802 # Builds a package and ensures it gets installed. The use of destdir to
803 # build packages may cause a package to get built but not installed,
804 # which is not OK for this script. This is for internal usage only.
810 if pkg_build ${pkg}; then
811 script=$(mktemp ${DESTDIR}/pkg_comp/tmp/pkg_comp-XXXXXX).sh
812 init_script ${script}
813 cat >>${script} <<EOF
814 cd /usr/pkgsrc/${pkg}
815 pkgname=\$(make show-var VARNAME=PKGNAME)
816 if pkg_info -E \${pkgname} 2>/dev/null; then
819 echo "PKG_COMP
==> Forcing installation of \
${pkgname}"
820 cd /pkg_comp/packages/All
825 chroot ${DESTDIR} /pkg_comp/tmp/$(basename ${script})
831 # ----------------------------------------------------------------------
833 # ----------------------------------------------------------------------
837 # The install target. Also used as a helper function within this
838 # script to install several packages when needed.
842 local failed pkgs stat
846 [ -z "$REAL_PACKAGES" ] && err "REAL_PACKAGES is not
set"
852 for p in $(cd ${REAL_PACKAGES}/All && echo ${pkgs}); do
853 echo "PKG_COMP
==> Installing binary package
: $p"
854 stat=$DESTDIR/pkg_comp/tmp/install.sh
857 cd /pkg_comp/packages/All
861 chroot $DESTDIR /pkg_comp/tmp/install.sh || failed="$failed $p"
865 [ -n "$failed" ] && echo "Installation failed
for:$failed"
868 # ----------------------------------------------------------------------
870 # ----------------------------------------------------------------------
874 # The 'chroot' target.
878 local prefix script exitstatus
880 [ -d $DESTDIR ] || err "$DESTDIR does not exist
"
885 echo "PKG_COMP
==> Entering sandbox \
`$DESTDIR'"
886 prefix=$(mktemp $DESTDIR/pkg_comp/tmp/pkg_comp-XXXXXX)
890 if [ $# -eq 0 ]; then
892 ENV=/etc/shrc $ROOTSHELL
900 ENV=/etc/shrc chroot $DESTDIR /pkg_comp/tmp/`basename $script`
908 # ----------------------------------------------------------------------
910 # ----------------------------------------------------------------------
914 # The 'removeroot' target.
918 [ -f $fsstate ] && err "filesystems may still be mounted; cannot remove"
919 echo "PKG_COMP ==> Removing sandbox \`${DESTDIR}'"
923 # ----------------------------------------------------------------------
925 # ----------------------------------------------------------------------
927 confdir="$HOME/pkg_comp"
930 args=`getopt c:C:nN $*`
938 while [ $# -gt 0 ]; do
941 [ -n "$conffile" ] && usage
942 conffile="$confdir/$2.conf"
946 [ -n "$conffile" ] && usage
964 if [ $# -lt 1 ]; then
968 if [ -z "$conffile" ]; then
969 conffile="$confdir/default.conf"
985 # Reads the configuration file and ensures that the environment is in
986 # a consistent state.
990 if [ -f $conffile ]; then
991 [ `id -u` -ne 0 ] && err "must be run as root"
996 err "$conffile does not exist"
999 fsstate="$DESTDIR/pkg_comp/tmp/mount.stat"
1004 # Checks that the sandbox is initialized, that it's a valid directory
1005 # and configures a signal trap for SIGINT and SIGQUIT.
1009 if [ ! -d "$DESTDIR" ]; then
1010 err
"sandbox not initialized; use makeroot first."
1012 if [ "$DESTDIR" = "/" ]; then
1013 err
"DESTDIR cannot be /"
1016 # From now on, filesystems may be mounted, so we need to trap
1017 # signals to umount them.
1018 trap "echo \"*** Process aborted ***\" ; fsumount ; exit 1" INT QUIT
1061 err
"unknown target \`$target'"
1067 # vim: expandtab:softtabstop=4:shiftwidth=4