summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrh <rh@pkgsrc.org>2002-09-07 00:08:35 +0000
committerrh <rh@pkgsrc.org>2002-09-07 00:08:35 +0000
commit2a5bf01b6aadf6fda1f665003a9ec8fa1c71599d (patch)
treec6f5e6a8bd8e3b7f6718e4b6559c95ceada38cae /pkgtools
parent4e00abac3b9520f9e9a355c4fb1e682d496406e4 (diff)
downloadpkgsrc-2a5bf01b6aadf6fda1f665003a9ec8fa1c71599d.tar.gz
Initial import of pkg_comp-1.0, a utility that allows retargetable package
building in chrooted environments. Provided in PR pkg/17986 by Julio Merino <jmmv@hispabsd.org>
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_comp/DESCR13
-rw-r--r--pkgtools/pkg_comp/Makefile24
-rw-r--r--pkgtools/pkg_comp/PLIST3
-rw-r--r--pkgtools/pkg_comp/files/pkg_comp.8296
-rw-r--r--pkgtools/pkg_comp/files/pkg_comp.sh578
5 files changed, 914 insertions, 0 deletions
diff --git a/pkgtools/pkg_comp/DESCR b/pkgtools/pkg_comp/DESCR
new file mode 100644
index 00000000000..de1311fd876
--- /dev/null
+++ b/pkgtools/pkg_comp/DESCR
@@ -0,0 +1,13 @@
+pkg_comp is a small utility designed to build packages inside a
+clean chroot tree.
+
+Some ideas about what to use it for (taken from manpage):
+* Build packages for other system versions. For example, build
+ packages for NetBSD 1.5 while you are running NetBSD current.
+* Build packages using different options than your current system
+ like changing the threading library, COPTS, placement of
+ configuration files, etc.
+* Debug the build process of a package, checking if buildlinks
+ work properly.
+* Avoid autoconf's side effects by keeping a separate chroot for
+ each project, like one for GNOME2 and another one for KDE3.
diff --git a/pkgtools/pkg_comp/Makefile b/pkgtools/pkg_comp/Makefile
new file mode 100644
index 00000000000..2ce05bee3b8
--- /dev/null
+++ b/pkgtools/pkg_comp/Makefile
@@ -0,0 +1,24 @@
+# $NetBSD: Makefile,v 1.1.1.1 2002/09/07 00:08:35 rh Exp $
+
+DISTNAME= pkg_comp-1.0
+CATEGORIES= pkgtools
+MASTER_SITES= # empty
+DISTFILES= # empty
+
+MAINTAINER= jmmv@hispabsd.org
+COMMENT= Build packages inside a chroot jail
+
+EXTRACT_ONLY= # empty
+NO_CHECKSUM= YES
+NO_PATCH= YES
+NO_CONFIGURE= YES
+NO_BUILD= YES
+WRKSRC= ${WRKDIR}
+
+.include "../../mk/bsd.prefs.mk"
+
+do-install:
+ ${INSTALL_SCRIPT} ${FILESDIR}/pkg_comp.sh ${PREFIX}/sbin/pkg_comp
+ ${INSTALL_MAN} ${FILESDIR}/pkg_comp.8 ${PREFIX}/man/man8/pkg_comp.8
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/pkgtools/pkg_comp/PLIST b/pkgtools/pkg_comp/PLIST
new file mode 100644
index 00000000000..339e766751d
--- /dev/null
+++ b/pkgtools/pkg_comp/PLIST
@@ -0,0 +1,3 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2002/09/07 00:08:35 rh Exp $
+sbin/pkg_comp
+man/man8/pkg_comp.8
diff --git a/pkgtools/pkg_comp/files/pkg_comp.8 b/pkgtools/pkg_comp/files/pkg_comp.8
new file mode 100644
index 00000000000..56c9656b036
--- /dev/null
+++ b/pkgtools/pkg_comp/files/pkg_comp.8
@@ -0,0 +1,296 @@
+.\" $NetBSD: pkg_comp.8,v 1.1.1.1 2002/09/07 00:08:50 rh Exp $
+.\"
+.\" pkg_comp - Build packages inside a clean chroot environment
+.\" Copyright (c) 2002, Julio Merino <jmmv@hispabsd.org>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\" 3. Neither the name of author nor the names of its contributors may
+.\" be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"/
+.Dd July 26, 2002
+.Dt PKG_COMP 8
+.Os
+.Sh NAME
+.Nm pkg_comp
+.Nd build packages inside a chroot
+.Sh SYNOPSIS
+.Nm
+.Op Ar -c conf_file
+.Ar target
+.Op Ar pkg_name ...
+.Sh DESCRIPTION
+.Nm
+is a tool that makes easy the compilation of packages inside a clean
+chroot environment. This allows an easy tracking of exact dependancies
+and the correct behaviour of a package in a fresh system installation.
+.Pp
+The behavior of
+.Nm
+is controlled trought a small configuration file and a target (keep
+reading to learn more). The configuration file tells
+.Nm
+how to configure the new chroot environment, and the target specifies
+which action to take.
+.Pp
+.Ss What to use it for?
+You can use
+.Nm
+to achieve many goals when buildling packages. Here are some ideas:
+.Bl -bullet -item
+.It
+Build packages for other system versions. For example, build packages for
+.Nx 1.5
+while you are running
+.Nx current .
+.It
+Build packages using different
+.Pa mk.conf
+options than your current system, like changing the threading library,
+.Sy COPTS ,
+placement of configuration files, etc.
+.It
+Debug the build process of a package, checking if buildlinks work
+properly.
+.It
+Avoid autoconf's side effects by keeping a separate chroot for each
+project, like one for GNOME2 and another one for KDE3.
+.El
+.Pp
+.Sh CONTROL DIRECTORY
+.Nm
+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 .
+.Pp
+.Sh CONFIGURATION
+With
+.Nm
+you can maintain several configuration files so you can work with
+different chroot jails easily. To make this easy, configuration files
+are stored inside
+.Pa $HOME/pkg_comp ,
+followed by the configuration file name and the .conf suffix. The default
+configuration file is
+.Pa $HOME/pkg_comp/default.conf ,
+and is always used if you do not specify another one.
+.Pp
+Configuration files are simple shell scripts that define
+variables. The default values shown here are those written in the
+template when issuing a maketemplate.
+.Bl -tag -width indent
+.It BUILD_TARGET
+The target to use when buildling packages. It can contain any target
+supported by the pkgsrc system, but reasonable values are:
+.Ql install
+and
+.Ql package .
+Defaults to
+.Ql package .
+.It COPYROOTCFG
+If set to
+.Ql yes ,
+all configuration files (not directories) that reside inside
+.Pa /root
+are copied to
+.Sy $DESTDIR/root .
+Defaults to
+.Ql no .
+.It DESTDIR
+The chroot jail directory. Defaults to
+.Pa /var/chroot/pkg_comp/default .
+.It DISTRIBDIR
+This is the directory which holds
+.Nb
+binary sets and X sets. Its structure is the same as official release
+distributions, that is, tgz files must reside inside
+.Pa $DISTRIBDIR/binary/sets .
+Defaults to
+.Pa /var/pub/NetBSD .
+.It INSTALL_PACKAGES
+A list of packages to automatically install after the
+.Sy makeroot
+and after installing
+.Sy MAKE_PACKAGES .
+Each name must be the full package name, including the tgz suffix. Packages
+are searched inside
+.Pa $REAL_PACKAGES/All .
+Defaults to nothing.
+.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 PTHREAD_TYPE
+The threading type to use when building packages. Defaults to
+.Ql pth .
+.It ROOTSHELL
+The shell of the root user. Defaults to
+.Pa /bin/sh .
+.It SETS
+A list of binary sets to be extracted inside
+.Sy DESTDIR .
+Defaults to
+.Ql base.tgz comp.tgz etc.tgz text.tgz .
+.It SETS_X11
+A list of binary sets of the X Window system. This has the same behavior
+as
+.Sy SETS .
+If this variable is empty, no X Window is configured inside the chroot
+jail and no other X variables take effect. Default to
+.Ql xbase.tgz xcomp.tgz xcontrib.tgz xfont.tgz xmisc.tgz xserver.tgz .
+.It USE_XF86_4
+If set to
+.Ql yes ,
+sets specified in SETS_X11 contain X Window version 4. Has no effect if
+X is unconfigured. Defaults to
+.Ql yes .
+.It USE_XPKGWEDGE
+If set to
+.Ql yes ,
+you want xpkgwedge to be compiled and installed automatically inside the
+chroot. This takes care of setting up
+.Pa /etc/profile
+and
+.Pa /etc/csh.login
+for xpkgwedge to work. Has no effect if X is unconfiguerd. Defaults to
+.Ql yes .
+.El
+.Ss Mounted filesystems
+In order to avoid duplicating huge system trees,
+.Nm
+takes advantadge of filesystem layers. By default, it uses
+.Xr mount_null 8 ,
+which duplicates a filesystem tree into another directory; although
+you may want to use
+.Xr mount_union 8 ,
+or even
+.Xr mount_overlay 8 .
+If the
+content of these variables is empty, that filesystem is not mounted.
+.Pp
+You can control which layer to use and which options you want with
+special configuration options, as explained below.
+.Pp
+These filesystems are mounted before entering the chroot and unmounted
+after exiting. In order to know if filesystems are mounted or not, the
+program uses a temporary file, called
+.Pa $DESTDIR/pkg_comp/tmp/mount.stat ,
+which controls the number of
+.Nm
+processes using the chroot environment. If some of them crashes
+unexpectedly and you notice it does not try to unmount the
+filesystems, this status file may get out of sync. Be sure to check if
+NO filesystems are mounted when issuing a
+.Sy removeroot .
+.Bl -tag -width indent
+.It REAL_DISTFILES
+Specifies where distfiles reside in the real system. Defaults to
+.Pa /usr/pkgsrc/distfiles .
+.It REAL_DISTFILES_OPTS
+Mount options. Defaults to
+.Sy -t null -o ro .
+.It REAL_PACKAGES
+Specifies where to build binary packages. This variable is specially useful.
+Defaults to
+.Pa /usr/pkgsrc/packages .
+.It REAL_PACKAGES_OPTS
+Mount options. Defaults to
+.Sy -t null -o ro .
+.It REAL_PKGSRC
+The pkgsrc tree. This can be useful if you want to use several pkgsrc trees
+independantly. Defaults to
+.Pa /usr/pkgsrc .
+.It REAL_PKGSRC_OPTS
+Mount options. Defaults to
+.Sy -t null -o rw .
+.It REAL_SRC
+The src system tree. Usually useless, but may be needed by some packages,
+like sysutils/aperture. Defaults to
+.Pa /usr/src .
+.It REAL_SRC_OPTS
+Mount options. Defaults to
+.Sy -t null -o rw .
+.El
+.Pp
+.Sh TARGETS
+A target specifies what
+.Nm
+should do (as in make). The following list describes all supported targets,
+in the logical order you should call them.
+.Bl -tag -width indent
+.It maketemplate
+Create a sample
+.Ar conf_file .
+You should edit it after the creation as you will probably want to change
+the default configuration, specially paths.
+.It makeroot
+Create the chroot environment, based on the specs of the configuration file.
+This step is required before trying any other, except maketemplate .
+.It build
+Builds the specified packages inside the chroot. You need to pass their
+names as relative paths inside pkgsrc, like
+.Pa pkgtools/pkg_comp .
+.It install
+Install the specified binary packages into the chroot. You must specify
+the full name of the package and they must be reside inside
+.Sy REAL_PACKAGES .
+.It chroot
+Enters the chroot environment.
+.It removepkgs
+Remove all the packages in the chroot environment. It starts deleting
+packages with
+.Xr pkg_delete 1
+and then cleans the package tree and the database. This will rebuild
+.Sy MAKE_PACKAGES ,
+reinstall
+.Sy INSTALL_PACKAGES
+and xpkgwedge if they are specified in the configuration file.
+.It removeroot
+Remove the entire chroot tree. You should do it with this target because it
+will take care to umount needed mount points.
+.It auto
+This executes several targets automatically, setting
+.Sy BUILD_TARGET
+to package. The order is: makeroot, build and removeroot. This is
+useful to create binary packages of several pkgsrc and their
+dependancies automatically. For this to be useful, you need to set
+.Sy REAL_PACKAGES
+and use
+.Sy MAKE_PACKAGES
+or pass package names trought the command line.
+.El
+.Pp
+.Sh NOTES
+This program uses nullfs to create virtual copies of real trees inside the
+chroot environment.
+.Pp
+.Sh AUTHORS
+Julio Merino <jmmv@hispabsd.org>
+.Sh SEE ALSO
+.Xr pkg_delete 1 ,
+.Xr packages 7 ,
+.Xr mount_null 8 .
+.Sh BUGS
+Probably many, specially error checking.
diff --git a/pkgtools/pkg_comp/files/pkg_comp.sh b/pkgtools/pkg_comp/files/pkg_comp.sh
new file mode 100644
index 00000000000..8649cc54ff7
--- /dev/null
+++ b/pkgtools/pkg_comp/files/pkg_comp.sh
@@ -0,0 +1,578 @@
+#!/bin/sh
+#
+# $NetBSD: pkg_comp.sh,v 1.1.1.1 2002/09/07 00:08:49 rh Exp $
+#
+# pkg_comp - Build packages inside a clean chroot environment
+# Copyright (c) 2002, Julio Merino <jmmv@hispabsd.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name of author nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# ----------------------------------------------------------------------
+# Misc functions
+# ----------------------------------------------------------------------
+err()
+{
+ echo "$progname: $1"
+ exit 1
+}
+
+usage()
+{
+ echo "usage: $progname [-c conf_file] target [pkg_names]"
+ exit 1
+}
+
+# ----------------------------------------------------------------------
+# Filesystem functions
+# ----------------------------------------------------------------------
+fsmount()
+{
+ echo -n "=> Mounting chroot filesystems:"
+ if [ -f $fsstate ]; then
+ count=`cat $fsstate`
+ count=$(($count + 1))
+ echo "$count" > $fsstate
+ echo " already mounted."
+ return
+ else
+ echo "1" > $fsstate
+ fi
+
+ if [ ! -z "$REAL_SRC" ]; then
+ mount $REAL_SRC_OPTS $REAL_SRC $DESTDIR/usr/src
+ fi
+
+ if [ ! -z "$REAL_PKGSRC" ]; then
+ mount $REAL_PKGSRC_OPTS $REAL_PKGSRC $DESTDIR/usr/pkgsrc
+ fi
+
+ if [ ! -z "$REAL_DISTFILES" ]; then
+ mount $REAL_DISTFILES_OPTS $REAL_DISTFILES $DESTDIR/pkg_comp/distfiles
+ fi
+
+ if [ ! -z "$REAL_PACKAGES" ]; then
+ mount $REAL_PACKAGES_OPTS $REAL_PACKAGES $DESTDIR/pkg_comp/packages
+ fi
+
+ touch $fsstate
+ echo " done."
+}
+
+fsumount()
+{
+ echo -n "=> Unmounting chroot filesystems:"
+ if [ ! -f $fsstate ]; then
+ echo " none mounted."
+ return
+ fi
+
+ count=`cat $fsstate`
+ if [ $count -gt 1 ]; then
+ count=$(($count - 1))
+ echo "$count" > $fsstate
+ echo " still in use."
+ return
+ fi
+
+ fsfailed=no
+
+ if [ ! -z "$REAL_SRC" ]; then
+ umount $DESTDIR/usr/src
+ if [ $? != 0 ]; then fsfailed=yes; fi
+ fi
+
+ if [ ! -z "$REAL_PKGSRC" ]; then
+ umount $DESTDIR/usr/pkgsrc
+ if [ $? != 0 ]; then fsfailed=yes; fi
+ fi
+
+ if [ ! -z "$REAL_DISTFILES" ]; then
+ umount $DESTDIR/pkg_comp/distfiles
+ if [ $? != 0 ]; then fsfailed=yes; fi
+ fi
+
+ if [ ! -z "$REAL_PACKAGES" ]; then
+ umount $DESTDIR/pkg_comp/packages
+ if [ $? != 0 ]; then fsfailed=yes; fi
+ fi
+
+ echo " done."
+
+ echo -n "Syncing: 1"
+ sync ; sleep 1
+ echo -n " 2"
+ sync ; sleep 1
+ echo -n " 3"
+ sync ; sleep 1
+ echo " done."
+ if [ "$fsfailed" = "yes" ]; then
+ err "FATAL: failed to umount all filesystems"
+ else
+ rm $fsstate
+ fi
+}
+
+# ----------------------------------------------------------------------
+# maketemplate target
+# ----------------------------------------------------------------------
+pkg_maketemplate()
+{
+ if [ -f "$conffile" ]; then
+ err "$conffile already exists"
+ fi
+
+ echo "Creating template: $conffile"
+ mkdir -p $confdir
+ cat > $conffile <<EOF
+# -*- sh -*-
+#
+# pkg_comp configuration file
+#
+
+DESTDIR="/var/chroot/pkg_comp/default"
+ROOTSHELL="/bin/sh"
+COPYROOTCFG="no"
+COPTS="-pipe"
+
+# Target used to build packages.
+BUILD_TARGET="package"
+
+# Binary sets (tgz) are found in \$DISTRIBDIR/binary/sets
+DISTRIBDIR="/var/pub/NetBSD"
+
+# These sets are unpacked to setup the initial chroot.
+SETS="base.tgz comp.tgz etc.tgz text.tgz"
+
+# X configuration. Leave SETS_X11 empty to disable X11.
+SETS_X11="xbase.tgz xcomp.tgz xcontrib.tgz xfont.tgz xmisc.tgz xserver.tgz"
+USE_XPKGWEDGE="yes"
+USE_XF86_4="yes"
+
+# Threading library to use.
+PTHREAD_TYPE="pth"
+
+# Special directories. They are mounted inside the chroot jail using
+# mount_null. Leave empty to avoid mounting.
+REAL_SRC="/usr/src"
+REAL_SRC_OPTS="-t null -o ro"
+REAL_PKGSRC="/usr/pkgsrc"
+REAL_PKGSRC_OPTS="-t null -o ro"
+REAL_DISTFILES="/usr/pkgsrc/distfiles"
+REAL_DISTFILES_OPTS="-t null -o rw"
+REAL_PACKAGES="/usr/pkgsrc/packages"
+REAL_PACKAGES_OPTS="-t null -o rw"
+
+# Specify which packages to build automatically after building the chroot.
+MAKE_PACKAGES=""
+
+# Install these packages after building the chroot. They must be present in
+# inside REAL_PACKAGES. You must specify the complete name.
+INSTALL_PACKAGES=""
+
+EOF
+}
+
+# ----------------------------------------------------------------------
+# makeroot target
+# ----------------------------------------------------------------------
+pkg_makeroot()
+{
+ if [ ! -d $DISTRIBDIR ]; then
+ err "DISTRIBDIR $DISTRIBDIR does not exist"
+ fi
+
+ if [ -d $DESTDIR ]; then
+ err "DESTDIR $DESTDIR already exists"
+ fi
+ mkdir -p $DESTDIR
+ cd $DESTDIR
+
+ echo -n "Unpacking sets:"
+ allsets="$SETS $SETS_X11"
+ for s in $allsets; do
+ echo -n " $s"
+ tar xzpf $DISTRIBDIR/binary/sets/$s
+ done
+ echo
+
+ echo -n "Making device nodes:"
+ cd $DESTDIR/dev
+ ./MAKEDEV all
+ cd $DESTDIR
+ echo " done."
+
+ echo -n "Setting root's environment:"
+ chroot $DESTDIR chpass -s $ROOTSHELL
+ if [ "$COPYROOTCFG" = "yes" ]; then
+ cp /root/.* $DESTDIR/root 2>&1 | > /dev/null
+ fi
+ echo " done."
+
+ echo -n "Setting up initial configuration:"
+
+ mkdir -p $DESTDIR/usr/src
+ mkdir -p $DESTDIR/usr/pkgsrc
+ mkdir -p $DESTDIR/pkg_comp/distfiles
+ mkdir -p $DESTDIR/pkg_comp/packages
+ mkdir -p $DESTDIR/pkg_comp/tmp
+ mkdir -p $DESTDIR/pkg_comp/obj/pkgsrc
+
+ # Set sh configuration
+ echo "umask 022" >> $DESTDIR/etc/profile
+ echo "ENV=/etc/shrc" >> $DESTDIR/etc/profile
+ echo "export PS1=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc/shrc
+
+ # Set csh configuration
+ echo "umask 022" >> $DESTDIR/etc/csh.login
+ echo "set prompt=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc/csh.login
+ echo "set prompt=\"pkg_comp:`basename $conffile`# \"" >> $DESTDIR/etc/csh.cshrc
+
+ cp /etc/resolv.conf $DESTDIR/etc/resolv.conf
+
+ makeroot_mkconf
+
+ echo " done."
+
+ makeroot_xpkgwedge
+
+ if [ ! -z "$MAKE_PACKAGES" ]; then
+ pkg_build $MAKE_PACKAGES
+ fi
+
+ if [ ! -z "$INSTALL_PACKAGES" ]; then
+ pkg_install $INSTALL_PACKAGES
+ fi
+}
+
+makeroot_mkconf()
+{
+ file="$DESTDIR/etc/mk.conf"
+
+ echo "OBJMACHINE=yes" >> $file
+ echo "MKOBJDIRS=yes" >> $file
+ echo "BSDSRCDIR=/usr/src" >> $file
+ echo "WRKOBJDIR=/pkg_comp/obj/pkgsrc" >> $file
+ echo "DISTDIR=/pkg_comp/distfiles" >> $file
+ echo "PACKAGES=/pkg_comp/packages" >> $file
+ echo "PKG_DEVELOPER?=yes" >> $file
+ echo "CLEANDEPENDS?=yes" >> $file
+
+ echo "COPTS=$COPTS" >> $file
+ echo "PTHREAD_TYPE=$PTHREAD_TYPE" >> $file
+ echo "USE_XF86_4=$USE_XF86_4" >> $file
+}
+
+makeroot_xpkgwedge()
+{
+ if [ ! -z "$SETS_X11" ]; then
+ if [ $USE_XPKGWEDGE = "yes" ]; then
+ pkg_build "pkgtools/xpkgwedge"
+ echo "export XAPPLRESDIR=/usr/pkg/lib/X11/app-defaults" >> $DESTDIR/etc/profile
+ echo "setenv XAPPLRESDIR /usr/pkg/lib/X11/app-defaults" >> $DESTDIR/etc/csh.login
+ fi
+ fi
+}
+
+# ----------------------------------------------------------------------
+# build target
+# ----------------------------------------------------------------------
+pkg_build()
+{
+ pkgs="$*"
+
+ # Check if all packages exist
+ invalid=""
+ for p in $pkgs; do
+ if [ ! -d $REAL_PKGSRC/$p ]; then
+ invalid="$invalid $p"
+ fi
+ done
+ if [ ! -z "$invalid" ]; then
+ err "invalid packages:$invalid"
+ fi
+
+ # Build them
+ fsmount
+ failed=""
+ for p in $pkgs; do
+ echo "=> Building and installing $p"
+ prefix=`mktemp $DESTDIR/pkg_comp/tmp/pkg_comp-XXXX`
+ rm $prefix
+ script="$prefix.sh"
+ statfile="$prefix.stat"
+ cat > $script <<EOF
+#!/bin/sh
+cd /usr/pkgsrc/$p
+make $BUILD_TARGET
+if [ $? != 0 ]; then
+ touch /pkg_comp/tmp/`basename $statfile`
+fi
+make clean
+EOF
+ chmod +x $script
+ chroot $DESTDIR /pkg_comp/tmp/`basename $script`
+ rm $script
+ if [ -f $statfile ]; then
+ failed="$failed $p"
+ rm $statfile
+ fi
+ done
+ fsumount
+ if [ ! -z "$failed" ]; then
+ echo "Build failed for:$failed"
+ fi
+}
+
+# ----------------------------------------------------------------------
+# install target
+# ----------------------------------------------------------------------
+pkg_install()
+{
+ pkgs="$*"
+
+ if [ -z "$REAL_PACKAGES" ]; then
+ err "REAL_PACKAGES is not set"
+ fi
+
+ fsmount
+ failed=""
+ for p in $pkgs; do
+ if [ -f $DESTDIR/pkg_comp/packages/All/$p ]; then
+ echo "=> Installing binary package: $p"
+ stat=$DESTDIR/pkg_comp/tmp/install.sh
+ cat >> $stat <<EOF
+#!/bin/sh
+cd /pkg_comp/packages/All
+pkg_add $p
+EOF
+ chmod +x $stat
+ chroot $DESTDIR /pkg_comp/tmp/install.sh
+ rm $stat
+ else
+ failed="$failed $p"
+ fi
+ done
+ fsumount
+ if [ ! -z "$failed" ]; then
+ echo "Installation failed for:$failed"
+ fi
+}
+
+# ----------------------------------------------------------------------
+# chroot target
+# ----------------------------------------------------------------------
+pkg_chroot()
+{
+ if [ ! -d $DESTDIR ]; then
+ err "$DESTDIR does not exist"
+ fi
+
+ fsmount
+ echo "=> Entering chroot: $DESTDIR"
+ chroot $DESTDIR $ROOTSHELL
+ echo
+ fsumount
+}
+
+# ----------------------------------------------------------------------
+# removeroot target
+# ----------------------------------------------------------------------
+pkg_removeroot()
+{
+ if [ -f $fsstate ]; then
+ err "filesystems may still be mounted; cannot remove"
+ fi
+ echo -n "=> Removing:"
+ rm -rf $DESTDIR
+ echo " done."
+}
+
+# ----------------------------------------------------------------------
+# removepkgs target
+# ----------------------------------------------------------------------
+pkg_removepkgs()
+{
+ echo "=> Removing packages"
+ cat > $DESTDIR/pkg_comp/tmp/removeall.sh <<EOF
+#!/bin/sh
+list="`pkg_info`"
+while [ ! -z "$list" ]; do
+ echo "Deleting all (non-recursive)"
+ pkg_delete "*"
+ list="`pkg_info`"
+done
+EOF
+ chmod +x $DESTDIR/pkg_comp/tmp/removeall.sh
+ chroot $DESTDIR /pkg_comp/tmp/removeall.sh
+ rm $DESTDIR/pkg_comp/tmp/removeall.sh
+
+ echo -n "Cleaning pkg tree:"
+ rm -rf $DESTDIR/usr/pkg
+ echo " done."
+
+ echo -n "Cleaning pkg database:"
+ rm -rf $DESTDIR/var/db/pkg
+ mkdir -p $DESTDIR/var/db/pkg
+ echo " done."
+ makeroot_xpkgwedge
+ if [ ! -z "$MAKE_PACKAGES" ]; then
+ pkg_build $MAKE_PACKAGES
+ fi
+ if [ ! -z "$INSTALL_PACKAGES" ]; then
+ pkg_install $INSTALL_PACKAGES
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Main program
+# ----------------------------------------------------------------------
+
+progname="`basename $0`"
+confdir="$HOME/pkg_comp"
+
+# Parse options
+args=`getopt c: $*`
+if [ $? != 0 ]; then
+ usage
+fi
+set -- $args
+conffile="$confdir/default.conf"
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -c)
+ conffile="$confdir/$2.conf"
+ shift
+ ;;
+ --)
+ shift; break
+ ;;
+ esac
+ shift
+done
+
+if [ $# -lt 1 ]; then
+ usage
+fi
+
+target="$1"
+shift
+pkgnames="$*"
+
+readconf()
+{
+ if [ -f $conffile ]; then
+ if [ `id -u` -ne 0 ]; then
+ err "must be run as root"
+ fi
+ echo "Reading config file: $conffile"
+ . $conffile
+ else
+ err "$conffile does not exist"
+ fi
+
+ fsstate="$DESTDIR/pkg_comp/tmp/mount.stat"
+
+ if [ ! -z "$SETS_X11" ]; then
+ MAKE_PACKAGES="$MAKE_PACKAGES pkgtools/x11-links"
+ fi
+}
+
+checkroot()
+{
+ if [ ! -d "$DESTDIR" ]; then
+ err "chroot not initialized; use makeroot first."
+ fi
+ if [ "$DESTDIR" = "/" ]; then
+ err "DESTDIR can't be /"
+ fi
+
+ # 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
+}
+
+case "$target" in
+ maketemplate)
+ pkg_maketemplate
+ exit 0
+ ;;
+ makeroot)
+ readconf
+ pkg_makeroot
+ exit 0
+ ;;
+ build)
+ readconf
+ checkroot
+ pkg_build $pkgnames
+ exit 0
+ ;;
+ install)
+ readconf
+ checkroot
+ pkg_install $pkgnames
+ exit 0
+ ;;
+ chroot)
+ readconf
+ checkroot
+ pkg_chroot
+ exit 0
+ ;;
+ removepkgs)
+ readconf
+ checkroot
+ pkg_removepkgs
+ ;;
+ removeroot)
+ readconf
+ checkroot
+ pkg_removeroot
+ ;;
+ auto)
+ readconf
+ BUILD_TARGET="package"
+ if [ -z "$REAL_PACKAGES" ]; then
+ err "this is useless without REAL_PACKAGES"
+ fi
+ if [ -z "$MAKE_PACKAGES" -a -z "$pkgnames" ]; then
+ err "this is useless without MAKE_PACKAGES nor package names"
+ fi
+ pkg_makeroot
+ checkroot
+ if [ ! -z "$pkgnames" ]; then
+ pkg_build $pkgnames
+ fi
+ pkg_removeroot
+ ;;
+ *)
+ err "unknown target '$target'"
+ ;;
+esac
+
+exit 0
+