diff options
author | jmmv <jmmv@pkgsrc.org> | 2004-01-23 09:48:53 +0000 |
---|---|---|
committer | jmmv <jmmv@pkgsrc.org> | 2004-01-23 09:48:53 +0000 |
commit | 1955870fa2cf21b7e8072185c9eded18ba0685e7 (patch) | |
tree | 49bc8cb8f661a7f9c9add8e823aafcc90260dfdb /pkgtools/pkg_comp | |
parent | 3767c8300ffe16e20dc42e833060b3704d9b3a64 (diff) | |
download | pkgsrc-1955870fa2cf21b7e8072185c9eded18ba0685e7.tar.gz |
Update to 1.15:
- Automatic builds can now be interrupted at any time with CTRL+C and then
resumed! (with 'auto resume' from the command line).
- MAKE_PACKAGES has been deprecated in favour of two new variables:
BUILD_PACKAGES, which tells which packages to build after a 'makeroot'
and AUTO_PACKAGES, used during the 'auto' target.
- MOUNT_SCRIPT and UMOUNT_SCRIPT have been deprecated in favour of MOUNT_HOOKS
and UMOUNT_HOOKS, which take a list of shell functions or external commands
to be executed.
- /pkg_comp is now symlinked to /p inside the chroot, to make paths simpler
when working inside it (i.e., with the 'chroot' target).
- security/audit-packages is not installed any more inside the chroot by
default. This is not needed to get pkgsrc security checks working.
The user can add it to BUILD_PACKAGES for a regular build.
- pkgtools/xpkgwedge is not installed any more during a 'makeroot'. pkgsrc
handles this automatically when needed, so we let it install the package
for us.
- Ensure that libkver's library is preloaded when doing builds inside the
chroot, so that packages get the right version number in them.
- When creating a template file, sort all variables alphabetically.
- Several miscellaneous changes in the code: simplification of syntax,
addition of comments to functions, cleanup of messages...
Diffstat (limited to 'pkgtools/pkg_comp')
-rw-r--r-- | pkgtools/pkg_comp/DESCR | 1 | ||||
-rw-r--r-- | pkgtools/pkg_comp/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkg_comp/files/pkg_comp.8 | 77 | ||||
-rw-r--r-- | pkgtools/pkg_comp/files/pkg_comp.sh | 398 |
4 files changed, 323 insertions, 157 deletions
diff --git a/pkgtools/pkg_comp/DESCR b/pkgtools/pkg_comp/DESCR index de1311fd876..4f84886d3e9 100644 --- a/pkgtools/pkg_comp/DESCR +++ b/pkgtools/pkg_comp/DESCR @@ -11,3 +11,4 @@ Some ideas about what to use it for (taken from manpage): work properly. * Avoid autoconf's side effects by keeping a separate chroot for each project, like one for GNOME2 and another one for KDE3. +* Schedule builds of package sets for several different machines. diff --git a/pkgtools/pkg_comp/Makefile b/pkgtools/pkg_comp/Makefile index 2be50e18da0..135600e2bb4 100644 --- a/pkgtools/pkg_comp/Makefile +++ b/pkgtools/pkg_comp/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.20 2004/01/20 12:23:57 agc Exp $ +# $NetBSD: Makefile,v 1.21 2004/01/23 09:48:53 jmmv Exp $ -DISTNAME= pkg_comp-1.14 +DISTNAME= pkg_comp-1.15 CATEGORIES= pkgtools MASTER_SITES= # empty DISTFILES= # empty diff --git a/pkgtools/pkg_comp/files/pkg_comp.8 b/pkgtools/pkg_comp/files/pkg_comp.8 index afbdeef09f4..9f090cf86b4 100644 --- a/pkgtools/pkg_comp/files/pkg_comp.8 +++ b/pkgtools/pkg_comp/files/pkg_comp.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_comp.8,v 1.18 2004/01/18 20:45:42 zuntum Exp $ +.\" $NetBSD: pkg_comp.8,v 1.19 2004/01/23 09:48:53 jmmv Exp $ .\" .\" pkg_comp - Build packages inside a clean chroot environment .\" Copyright (c) 2002, 2003, 2004 Julio M. Merino Vidal <jmmv@NetBSD.org> @@ -27,12 +27,12 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 8, 2004 +.Dd January 23, 2004 .Dt PKG_COMP 8 .Os .Sh NAME .Nm pkg_comp -.Nd build packages inside a chroot +.Nd build packages inside a sandbox .Sh SYNOPSIS .Nm .Oo Fl Po @@ -44,9 +44,12 @@ .Ar target .Op Ar pkg_name ... .Sh DESCRIPTION -.Nm +.Nm , +or +.Em Package Compiler +in its full name, is a tool that makes easy the compilation of packages inside a clean -chroot environment. +sandbox. This allows an easy tracking of exact dependencies and the correct behavior of a package in a fresh system installation. .Pp @@ -73,7 +76,7 @@ as configuration file (only base name expected). Avoid installation of .Va INSTALL_PACKAGES and -.Va MAKE_PACKAGES +.Va BUILD_PACKAGES during the creation of the chroot. .El .Ss What to use it for? @@ -100,6 +103,8 @@ properly. .It Avoid autoconf's side effects by keeping a separate chroot for each project, like one for GNOME2 and another one for KDE3. +.It +Schedule builds of package sets for several different machines. .El .Sh CONTROL DIRECTORY .Nm @@ -107,8 +112,11 @@ needs to store several information when it is running. Instead of using normal system trees, it uses a special directory inside the chroot to avoid polluting the system. It stores there scripts, object files, built packages, etc. -This directory is located by default in -.Pa $DESTDIR/pkg_comp . +This directory is +.Pa $DESTDIR/pkg_comp ; +the symbolic link +.Pa $DESTDIR/p +is automatically created to ease pathnames when working inside the chroot. .Sh CONFIGURATION With .Nm @@ -133,6 +141,12 @@ variables. The default values shown here are those written in the template when issuing a maketemplate. .Bl -tag -width indent +.It AUTO_PACKAGES +A list of packages to automatically build during the +.Sy auto +target. +A package is in the form section/name, like misc/colorls. +Defaults to nothing. .It AUTO_TARGET The pkgsrc target to use when building packages in an automated fashion (using the @@ -145,6 +159,12 @@ or as other values are useless. Defaults to .Ql package . +.It BUILD_PACKAGES +A list of packages to automatically build after the +.Sy makeroot +target. +A package is in the form section/name, like misc/colorls. +Defaults to nothing. .It BUILD_TARGET The pkgsrc target to use when building packages. It can contain any target supported by the pkgsrc system, but @@ -186,7 +206,7 @@ Defaults to nothing. A list of packages to automatically install after the .Sy makeroot and after installing -.Sy MAKE_PACKAGES . +.Sy BUILD_PACKAGES . Each name must be the full package name, including the tgz suffix. Packages are searched inside .Pa $REAL_PACKAGES/All . @@ -195,12 +215,6 @@ Defaults to nothing. Where binary packages get installed. Defaults to .Pa /usr/pkg . -.It MAKE_PACKAGES -A list of packages to automatically build after the -.Sy makeroot -target. -A package is in the form section/name, like misc/colorls. -Defaults to nothing. .It MKCONF_VARS A list of variable names that will be appended to the generated .Pa /etc/mk.conf @@ -269,9 +283,7 @@ Defaults to .It USE_AUDIT_PACKAGES If set to .Ql yes , -install the -.Pa security/audit-packages -package inside the chroot and let +let .Nm handle the .Pa vulnerabilities @@ -369,20 +381,22 @@ Defaults to Mount options. Defaults to .Sy -t null -o ro . -.It MOUNT_SCRIPT -Pathname to a script to run after the file systems are mounted. -Two arguments are given to it: +.It MOUNT_HOOKS +A whitespace separated list of functions or external scripts to be executed +after file systems are mounted. +Two arguments are given to each of them: .Ar $DESTDIR , and the word .Ar mount . -Defaults to the empty value i.e. no script is to be run. -.It UMOUNT_SCRIPT -Pathname to a script to run before the file systems are unmounted. -Two arguments are given to it: +Defaults to nothing. +.It UMOUNT_HOOKS +A whitespace separated list of functions or external scripts to be executed +before file systems are unmounted. +Two arguments are given to each of them: .Ar $DESTDIR , and the word .Ar umount . -Defaults to the empty value i.e. no script is to be run. +Defaults to nothing. .El .Sh TARGETS A target specifies what @@ -428,8 +442,14 @@ dependencies automatically. For this to be useful, you need to set .Sy REAL_PACKAGES and use -.Sy MAKE_PACKAGES +.Sy AUTO_PACKAGES or pass package names through the command line. +.Pp +If the magic work +.Ql resume +is passed as the unique argument to this target, +.Nm +will attempt to resume a previous automatic build for the given configuration. .El .Sh NOTES This program uses nullfs to create virtual copies of real trees inside the @@ -437,7 +457,8 @@ chroot environment. .Pp You need to install the .Pa security/audit-packages -package in the host system if you want security checks to work inside the +package in the host system (and have an up to date vulnerabilities database) +if you want security checks to work inside the chroot environment. .Sh SEE ALSO .Xr pkg_delete 1 , diff --git a/pkgtools/pkg_comp/files/pkg_comp.sh b/pkgtools/pkg_comp/files/pkg_comp.sh index 162fd58fbea..cebea5aa106 100644 --- a/pkgtools/pkg_comp/files/pkg_comp.sh +++ b/pkgtools/pkg_comp/files/pkg_comp.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: pkg_comp.sh,v 1.15 2004/01/08 14:06:15 jmmv Exp $ +# $NetBSD: pkg_comp.sh,v 1.16 2004/01/23 09:48:53 jmmv Exp $ # # pkg_comp - Build packages inside a clean chroot environment # Copyright (c) 2002, 2003, 2004 Julio M. Merino Vidal <jmmv@NetBSD.org> @@ -41,15 +41,23 @@ ProgName="`basename $0`" # as they require special handling. _MKCONF_VARS="OBJMACHINE MKOBJDIRS BSDSRCDIR WRKOBJDIR DISTDIR PACKAGES \ PKG_DEVELOPER CLEANDEPENDS LOCALBASE PKG_SYSCONFBASE \ - CFLAGS CPPFLAGS CXXFLAGS USE_AUDIT_PACKAGES PKGVULNDIR" + CFLAGS CPPFLAGS CXXFLAGS USE_AUDIT_PACKAGES PKGVULNDIR \ + USE_XPKGWEDGE" _TEMPLATE_VARS="DESTDIR ROOTSHELL COPYROOTCFG BUILD_TARGET DISTRIBDIR SETS \ - SETS_X11 USE_XPKGWEDGE REAL_SRC REAL_SRC_OPTS REAL_PKGSRC \ + SETS_X11 REAL_SRC REAL_SRC_OPTS REAL_PKGSRC \ REAL_PKGSRC_OPTS REAL_DISTFILES REAL_DISTFILES_OPTS \ REAL_PACKAGES REAL_PACKAGES_OPTS REAL_PKGVULNDIR \ - NETBSD_RELEASE MOUNT_SCRIPT UMOUNT_SCRIPT SYNC_UMOUNT \ - AUTO_TARGET" + NETBSD_RELEASE MOUNT_HOOKS UMOUNT_HOOKS SYNC_UMOUNT \ + AUTO_TARGET AUTO_PACKAGES BUILD_PACKAGES" +_BUILD_RESUME= + +# env_clean +# +# Sets all variables that may appear in the config file to the null +# string, so that we know the environment is in a consistent state. +# env_clean() { MKCONF_VARS="" @@ -59,6 +67,12 @@ env_clean() done } +# env_setdefaults +# +# Sets several reasonable defaults for many variables we will use. +# Also checks for deprecated variables and warns the user about them. +# To be called after reading the configuration file. +# env_setdefaults() { MKCONF_VARS="$MKCONF_VARS ${_MKCONF_VARS}" @@ -81,6 +95,7 @@ env_setdefaults() : ${USE_GCC3:=no} : ${USE_AUDIT_PACKAGES:=yes} : ${PKGVULNDIR:=/usr/pkg/share} + : ${USE_XPKGWEDGE:=yes} # Default values for global variables used in the script. : ${DESTDIR:=/var/chroot/pkg_comp/default} @@ -91,7 +106,6 @@ env_setdefaults() : ${DISTRIBDIR:=/var/pub/NetBSD} : ${SETS:=base.tgz comp.tgz etc.tgz text.tgz} : ${SETS_X11:=xbase.tgz xcomp.tgz xcontrib.tgz xfont.tgz xmisc.tgz xserver.tgz} - : ${USE_XPKGWEDGE:=yes} : ${REAL_SRC:=/usr/src} : ${REAL_SRC_OPTS:=-t null -o ro} : ${REAL_PKGSRC:=/usr/pkgsrc} @@ -102,27 +116,65 @@ env_setdefaults() : ${REAL_PACKAGES_OPTS:=-t null -o rw} : ${REAL_PKGVULNDIR:=/usr/pkgsrc/distfiles} : ${NETBSD_RELEASE:=no} - : ${MOUNT_SCRIPT:=} - : ${UMOUNT_SCRIPT:=} + : ${MOUNT_HOOKS:=} + : ${UMOUNT_HOOKS:=} : ${SYNC_UMOUNT:=no} + + if [ -n "${MAKE_PACKAGES}" ]; then + warn "MAKE_PACKAGES is deprecated; use {AUTO,BUILD}_PACKAGES instead." + : ${AUTO_PACKAGES:=${MAKE_PACKAGES}} + : ${BUILD_PACKAGES:=${MAKE_PACKAGES}} + fi + + if [ -n "${MOUNT_SCRIPT}" ]; then + warn "MOUNT_SCRIPT is deprecated; use MOUNT_HOOKS instead." + : ${MOUNT_HOOKS:=${MOUNT_SCRIPT}} + fi + + if [ -n "${UMOUNT_SCRIPT}" ]; then + warn "UMOUNT_SCRIPT is deprecated; use UMOUNT_HOOKS instead." + : ${UMOUNT_HOOKS:=${UMOUNT_SCRIPT}} + fi } # ---------------------------------------------------------------------- # Misc functions # ---------------------------------------------------------------------- +# err msg +# +# Shows the given error message and exit. +# err() { - echo "$ProgName: $1" + echo "$ProgName: $1" 1>&2 exit 1 } +# warn msg +# +# Shows the given warning message. +# +warn() +{ + echo "$ProgName: $1" 1>&2 +} + +# usage +# +# Shows an usage message and exits. +# usage() { - echo "usage: $ProgName [-(c|C) conf_file] [-n] target [pkg_names]" + echo "usage: $ProgName [-(c|C) conf_file] [-n] target [pkg_names]" 1>&2 exit 1 } +# copy_vulnerabilities +# +# If USE_AUDIT_PACKAGES is set to 'yes', this function copies the +# system-wide pkg-vulnerabilities file inside the sandbox. +# copy_vulnerabilities() { if [ "$USE_AUDIT_PACKAGES" = "yes" ]; then @@ -136,18 +188,41 @@ copy_vulnerabilities() fi } +# init_script filename +# +# Create a script that will be used within the sandbox and write some +# common content to it. +# +init_script() +{ + rm -f $1 + cat >$1 <<EOF +#!/bin/sh +# Generated by pkg_comp on `date` + +if [ -f ${LOCALBASE}/lib/libkver.so ]; then + LD_PRELOAD=${LOCALBASE}/lib/libkver.so; export LD_PRELOAD +fi + +EOF +} + # ---------------------------------------------------------------------- # Filesystem functions # ---------------------------------------------------------------------- +# fsmount +# +# Mounts all sandboxed filesystems, if they are not mounted yet. +# fsmount() { - printf "PKG_COMP ==> Mounting chroot filesystems:" + echo "PKG_COMP ==> Mounting sandboxed filesystems" if [ -f $fsstate ]; then count=`cat $fsstate` count=$(($count + 1)) echo "$count" > $fsstate - echo " already mounted." + echo "Already mounted by another pkg_comp process." return else echo "1" > $fsstate @@ -190,20 +265,22 @@ fsmount() fi touch $fsstate - echo " done." - if [ -n "$MOUNT_SCRIPT" -a -x "$MOUNT_SCRIPT" ]; then - echo "PKG_COMP ==> Executing mount script." - $MOUNT_SCRIPT $DESTDIR mount - fi + for h in ${MOUNT_HOOKS}; do + ${h} ${DESTDIR} mount + done } +# fsumount +# +# Unmounts all sandboxed filesystems, if they are not in use any more. +# fsumount() { - msg="PKG_COMP ==> Unmounting chroot filesystems:" + echo "PKG_COMP ==> Unmounting sandboxed filesystems" if [ ! -f $fsstate ]; then - echo "$msg none mounted." + echo "None mounted." return fi @@ -211,41 +288,32 @@ fsumount() if [ $count -gt 1 ]; then count=$(($count - 1)) echo "$count" > $fsstate - echo "$msg still in use." + echo "Still in use by another pkg_comp process." return fi - if [ -n "$UMOUNT_SCRIPT" -a -x "$UMOUNT_SCRIPT" ]; then - echo "PKG_COMP ==> Executing umount script." - $UMOUNT_SCRIPT $DESTDIR umount - fi - - printf "$msg" + for h in ${UMOUNT_HOOKS}; do + ${h} ${DESTDIR} umount + done fsfailed=no if [ -n "$REAL_SRC" -a -d "$REAL_SRC" ]; then - umount $DESTDIR/usr/src - if [ $? != 0 ]; then fsfailed=yes; fi + umount $DESTDIR/usr/src || fsfailed=yes fi if [ -n "$REAL_PKGSRC" -a -d "$REAL_PKGSRC" ]; then - umount $DESTDIR/usr/pkgsrc - if [ $? != 0 ]; then fsfailed=yes; fi + umount $DESTDIR/usr/pkgsrc || fsfailed=yes fi if [ -n "$REAL_DISTFILES" -a -d "$REAL_DISTFILES" ]; then - umount $DESTDIR/pkg_comp/distfiles - if [ $? != 0 ]; then fsfailed=yes; fi + umount $DESTDIR/pkg_comp/distfiles || fsfailed=yes fi if [ -n "$REAL_PACKAGES" -a -d "$REAL_PACKAGES" ]; then - umount $DESTDIR/pkg_comp/packages - if [ $? != 0 ]; then fsfailed=yes; fi + umount $DESTDIR/pkg_comp/packages || fsfailed=yes fi - echo " done." - if [ "$SYNC_UMOUNT" != "no" ]; then printf "Syncing: 1" sync ; sleep 1 @@ -267,6 +335,11 @@ fsumount() # maketemplate target # ---------------------------------------------------------------------- +# pkg_maketemplate +# +# Generates a sample configuration file based on the list of variables +# given in TEMPLATE_VARS and MKCONF_VARS. +# pkg_maketemplate() { if [ -f "$conffile" ]; then @@ -284,14 +357,14 @@ pkg_maketemplate() EOF echo "# Variables used internally by pkg_comp." >> $conffile - for var in $TEMPLATE_VARS; do + for var in `echo $TEMPLATE_VARS | tr ' ' '\n' | sort`; do eval val=\""\$$var"\" echo "$var=\"$val\"" >> $conffile done echo >> $conffile echo "# Default variables written to the generated mk.conf." >> $conffile - for var in $MKCONF_VARS; do + for var in `echo $MKCONF_VARS | tr ' ' '\n' | sort`; do eval val=\""\$$var"\" echo "$var=\"$val\"" >> $conffile done @@ -303,8 +376,29 @@ EOF # makeroot target # ---------------------------------------------------------------------- +# pkg_makeroot +# +# The 'makeroot' target. This creates a new sandbox and then issues +# some stuff to be called only when using this specific target. +# pkg_makeroot() { + makeroot + + [ "$nflag" = "no" -a -n "$INSTALL_PACKAGES" ] && + pkg_install $INSTALL_PACKAGES + + [ "$nflag" = "no" -a -n "$BUILD_PACKAGES" ] && + pkg_build $BUILD_PACKAGES +} + +# makeroot +# +# Creates a new sandbox. This is independant from 'makeroot' and +# 'auto' targets. +# +makeroot() +{ # Check for directories that will be null mounted. if [ -n "$REAL_SRC" -a ! -d "$REAL_SRC" ]; then err "REAL_SRC $REAL_SRC does not exist" @@ -343,30 +437,28 @@ pkg_makeroot() fi done + echo "PKG_COMP ==> Creating sandbox \`${DESTDIR}'" + mkdir -p $DESTDIR cd $DESTDIR - printf "Unpacking sets:" for s in $allsets; do - printf " $s" + echo "Extracting $s..." tar xzpf $DISTRIBDIR/binary/sets/$s done - echo - printf "Making device nodes:" + echo "Making device nodes..." cd $DESTDIR/dev ./MAKEDEV all cd $DESTDIR - echo " done." - printf "Setting root's environment:" + echo "Setting root's environment..." chroot $DESTDIR chpass -s $ROOTSHELL if [ "$COPYROOTCFG" = "yes" ]; then cp /root/.* $DESTDIR/root 2>&1 | > /dev/null fi - echo " done." - printf "Setting up initial configuration:" + echo "Setting up initial configuration..." mkdir -p $DESTDIR/usr/src mkdir -p $DESTDIR/usr/pkgsrc @@ -374,6 +466,7 @@ pkg_makeroot() mkdir -p $DESTDIR/pkg_comp/packages mkdir -p $DESTDIR/pkg_comp/tmp mkdir -p $DESTDIR/pkg_comp/obj/pkgsrc + ( cd $DESTDIR && ln -s pkg_comp p ) # Set sh configuration echo "umask 022" >> $DESTDIR/etc/profile @@ -390,46 +483,26 @@ pkg_makeroot() makeroot_mkconf - echo " done." - # From now on, filesystems may be mounted, so we need to trap # signals to umount them. trap "echo \"*** Process aborted ***\" ; fsumount ; exit 1" INT QUIT - check_pkg_install - - if [ "$USE_AUDIT_PACKAGES" = "yes" ]; then - pkg_build security/audit-packages - fi - - if [ "$NETBSD_RELEASE" != "no" ]; then - pkg_build pkgtools/libkver - echo "LD_PRELOAD=${LOCALBASE}/lib/libkver.so; export LD_PRELOAD" >> $DESTDIR/etc/shrc - echo "setenv LD_PRELOAD ${LOCALBASE}/lib/libkver.so" >> $DESTDIR/etc/csh.login - echo "setenv LD_PRELOAD ${LOCALBASE}/lib/libkver.so" >> $DESTDIR/etc/csh.cshrc - ln -s "$NETBSD_RELEASE" $DESTDIR/libkver_osrelease - fi + makeroot_libkver if [ "$USE_GCC3" = "yes" ]; then - if [ -z "`echo $MAKE_PACKAGES $INSTALL_PACKAGES | grep gcc3`" ]; then + if [ -z "`echo $BUILD_PACKAGES $INSTALL_PACKAGES | grep gcc3`" ]; then AVOID_GCC3=yes pkg_build lang/gcc3 fi fi - if [ "$SETS_X11" != "no" ]; then - makeroot_xpkgwedge - pkg_build pkgtools/x11-links - fi - - if [ "$nflag" = "no" -a -n "$INSTALL_PACKAGES" ]; then - pkg_install $INSTALL_PACKAGES - fi - - if [ "$nflag" = "no" -a -n "$MAKE_PACKAGES" ]; then - pkg_build $MAKE_PACKAGES - fi + makeroot_x11 } +# makeroot_mkconf +# +# Generates a mk.conf file inside the sandbox, based on the content +# of MKCONF_VARS and EXTRAMK. Also handles some special stuff. +# makeroot_mkconf() { file="$DESTDIR/etc/mk.conf" @@ -483,23 +556,87 @@ EOF fi } -makeroot_xpkgwedge() +# makeroot_libkver +# +# If NETBSD_RELEASE is set to a version string, installs libkver +# inside the sandbox and configures it. +# +makeroot_libkver() +{ + if [ "$NETBSD_RELEASE" != "no" ]; then + pkg_build pkgtools/libkver + echo "LD_PRELOAD=${LOCALBASE}/lib/libkver.so; export LD_PRELOAD" >> $DESTDIR/etc/shrc + echo "setenv LD_PRELOAD ${LOCALBASE}/lib/libkver.so" >> $DESTDIR/etc/csh.login + echo "setenv LD_PRELOAD ${LOCALBASE}/lib/libkver.so" >> $DESTDIR/etc/csh.cshrc + ln -s "$NETBSD_RELEASE" $DESTDIR/libkver_osrelease + fi +} + +# makeroot_x11 +# +# If X11 is enabled, installs x11-links inside the sandbox. +# If USE_XPKGWEDGE is yes, configures xpkgwedge too (but does not +# install it; pkgsrc will take care of that when needed). +# +makeroot_x11() { - if [ -n "$SETS_X11" ]; then - if [ $USE_XPKGWEDGE = "yes" ]; then - pkg_build "pkgtools/xpkgwedge" + if [ "$SETS_X11" != "no" ]; then + if [ "$USE_XPKGWEDGE" = "yes" ]; then echo "export XAPPLRESDIR=${LOCALBASE}/lib/X11/app-defaults" >> $DESTDIR/etc/profile echo "setenv XAPPLRESDIR ${LOCALBASE}/lib/X11/app-defaults" >> $DESTDIR/etc/csh.login fi + pkg_build pkgtools/x11-links + fi +} + +# ---------------------------------------------------------------------- +# auto target +# ---------------------------------------------------------------------- + +# pkg_auto pkgs +# +# The 'auto' target. +# +pkg_auto() +{ + local pkgs rfile target + + pkgs="${*:-${AUTO_PACKAGES}}" + rfile=${DESTDIR}/pkg_comp/tmp/auto.list + target="${AUTO_TARGET}" + + [ -z "${REAL_PACKAGES}" ] && err "this is useless without REAL_PACKAGES" + [ -z "${pkgs}" ] && + err "this is useless without AUTO_PACKAGES nor package names" + + if [ "$1" = resume ]; then + [ -f ${rfile} ] || err "there is no auto build to resume" + pkgs=`cat ${rfile}` + elif [ -f ${rfile} ]; then + err "there is an stopped auto build; removeroot first or resume it" + else + makeroot + echo ${pkgs} | tr ' ' '\n' > ${rfile} fi + + checkroot + _BUILD_RESUME=${rfile} BUILD_TARGET=${target} pkg_build ${pkgs} + pkg_removeroot } # ---------------------------------------------------------------------- # build target # ---------------------------------------------------------------------- +# pkg_build pkgs +# +# The build target. Also used as a helper function within this script +# to build several packages when needed. +# pkg_build() { + local failed invalid p pkgs script statfile + pkgs="$*" # Check if all packages exist @@ -513,10 +650,9 @@ pkg_build() err "invalid packages:$invalid" fi - check_pkg_install # executes copy_vulnerabilities too - # Build them fsmount + check_pkg_install # executes copy_vulnerabilities too failed="" for p in $pkgs; do echo "PKG_COMP ==> Building and installing $p" @@ -524,8 +660,8 @@ pkg_build() rm $prefix script="$prefix.sh" statfile="$prefix.stat" - cat > $script <<EOF -#!/bin/sh + init_script $script + cat >> $script <<EOF cd /usr/pkgsrc/$p make $BUILD_TARGET if [ \$? != 0 ]; then @@ -539,6 +675,9 @@ EOF if [ -f $statfile ]; then failed="$failed $p" rm $statfile + elif [ -n "${_BUILD_RESUME}" ]; then + grep -v "^${p}\$" < ${_BUILD_RESUME} > ${_BUILD_RESUME}.new + mv ${_BUILD_RESUME}.new ${_BUILD_RESUME} fi done fsumount @@ -551,15 +690,23 @@ EOF fi } +# check_pkg_install +# +# Ensure that the version of pkg_install inside the sandbox is new +# enough to work with pkgsrc. If not, rebuild it. +# check_pkg_install() { + local script + copy_vulnerabilities - echo "PKG_COMP ==> Checking that pkg_install is up to date" - fsmount + # We assume filesystems are mounted! + + echo "PKG_COMP ==> Checking if pkg_install is up to date" script=`mktemp $DESTDIR/pkg_comp/tmp/pkg_comp-XXXX`.sh - cat > $script <<EOF -#!/bin/sh + init_script $script + cat >> $script <<EOF cd /usr/pkgsrc/pkgtools/pkg_comp fail=\$(make show-var VARNAME=PKG_FAIL_REASON) if echo \$fail | grep "package tools installed on this system are out of date" >/dev/null; then @@ -571,20 +718,24 @@ EOF chmod +x $script chroot $DESTDIR /pkg_comp/tmp/`basename $script` rm $script - fsumount } # ---------------------------------------------------------------------- # install target # ---------------------------------------------------------------------- +# pkg_install pkgs +# +# The install target. Also used as a helper function within this +# script to install several packages when needed. +# pkg_install() { + local failed pkgs stat + pkgs="$*" - if [ -z "$REAL_PACKAGES" ]; then - err "REAL_PACKAGES is not set" - fi + [ -z "$REAL_PACKAGES" ] && err "REAL_PACKAGES is not set" copy_vulnerabilities @@ -594,8 +745,8 @@ pkg_install() if [ -f $DESTDIR/pkg_comp/packages/All/$p ]; then echo "PKG_COMP ==> Installing binary package: $p" stat=$DESTDIR/pkg_comp/tmp/install.sh + init_script $stat cat >> $stat <<EOF -#!/bin/sh cd /pkg_comp/packages/All pkg_add $p EOF @@ -607,25 +758,25 @@ EOF fi done fsumount - if [ -n "$failed" ]; then - echo "Installation failed for:$failed" - fi + [ -n "$failed" ] && echo "Installation failed for:$failed" } # ---------------------------------------------------------------------- # chroot target # ---------------------------------------------------------------------- +# pkg_chroot cmd +# +# The 'chroot' target. +# pkg_chroot() { - if [ ! -d $DESTDIR ]; then - err "$DESTDIR does not exist" - fi + [ -d $DESTDIR ] || err "$DESTDIR does not exist" copy_vulnerabilities fsmount - echo "PKG_COMP ==> Entering chroot: $DESTDIR" + echo "PKG_COMP ==> Entering sandbox \`$DESTDIR'" if [ $# -eq 0 ]; then ENV=/etc/shrc chroot $DESTDIR $ROOTSHELL else @@ -639,14 +790,15 @@ pkg_chroot() # removeroot target # ---------------------------------------------------------------------- +# pkg_removeroot +# +# The 'removeroot' target. +# pkg_removeroot() { - if [ -f $fsstate ]; then - err "filesystems may still be mounted; cannot remove" - fi - printf "PKG_COMP ==> Removing chroot:" + [ -f $fsstate ] && err "filesystems may still be mounted; cannot remove" + echo "PKG_COMP ==> Removing sandbox \`${DESTDIR}'" rm -rf $DESTDIR - echo " done." } # ---------------------------------------------------------------------- @@ -666,16 +818,12 @@ nflag=no while [ $# -gt 0 ]; do case "$1" in -c) - if [ -n "$conffile" ]; then - usage - fi + [ -n "$conffile" ] && usage conffile="$confdir/$2.conf" shift ;; -C) - if [ -n "$conffile" ]; then - usage - fi + [ -n "$conffile" ] && usage conffile="$2" shift ;; @@ -701,13 +849,15 @@ target="$1" shift args="$*" +# readconf +# +# Reads the configuration file and ensures that the environment is in +# a consistent state. +# readconf() { if [ -f $conffile ]; then - if [ `id -u` -ne 0 ]; then - err "must be run as root" - fi - echo "Reading config file: $conffile" + [ `id -u` -ne 0 ] && err "must be run as root" env_clean . $conffile env_setdefaults @@ -718,10 +868,15 @@ readconf() fsstate="$DESTDIR/pkg_comp/tmp/mount.stat" } +# checkroot +# +# Checks that the sandbox is initialized, that it's a valid directory +# and configures a signal trap for SIGINT and SIGQUIT. +# checkroot() { if [ ! -d "$DESTDIR" ]; then - err "chroot not initialized; use makeroot first." + err "sandbox not initialized; use makeroot first." fi if [ "$DESTDIR" = "/" ]; then err "DESTDIR cannot be /" @@ -769,19 +924,7 @@ case "$target" in ;; auto) readconf - BUILD_TARGET="${AUTO_TARGET}" - if [ -z "$REAL_PACKAGES" ]; then - err "this is useless without REAL_PACKAGES" - fi - if [ -z "$MAKE_PACKAGES" -a -z "$args" ]; then - err "this is useless without MAKE_PACKAGES nor package names" - fi - pkg_makeroot - checkroot - if [ -n "$args" ]; then - pkg_build $args - fi - pkg_removeroot + pkg_auto $args ;; *) err "unknown target \`$target'" @@ -790,3 +933,4 @@ esac exit 0 +# vim: expandtab:softtabstop=4:shiftwidth=4 |