diff options
Diffstat (limited to 'sysutils/sysbuild')
-rw-r--r-- | sysutils/sysbuild/DESCR | 10 | ||||
-rw-r--r-- | sysutils/sysbuild/INSTALL | 32 | ||||
-rw-r--r-- | sysutils/sysbuild/MESSAGE | 15 | ||||
-rw-r--r-- | sysutils/sysbuild/Makefile | 67 | ||||
-rw-r--r-- | sysutils/sysbuild/PLIST | 6 | ||||
-rw-r--r-- | sysutils/sysbuild/files/crontab | 19 | ||||
-rw-r--r-- | sysutils/sysbuild/files/default.conf | 49 | ||||
-rw-r--r-- | sysutils/sysbuild/files/sysbuild.8 | 439 | ||||
-rw-r--r-- | sysutils/sysbuild/files/sysbuild.sh | 570 |
9 files changed, 1207 insertions, 0 deletions
diff --git a/sysutils/sysbuild/DESCR b/sysutils/sysbuild/DESCR new file mode 100644 index 00000000000..1bc2a3abb16 --- /dev/null +++ b/sysutils/sysbuild/DESCR @@ -0,0 +1,10 @@ +sysbuild is a script that simplifies the process of building NetBSD +releases and kernels as an unprivileged user. It should be clear enough +that it does not add any kind of magic to the NetBSD build system. It +just automates boring steps, like setup of permissions, directories, +execution of the build process, etc. It also provides enough +functionality to automatically update CVS source trees. + +sysbuild can be easily used from command line or as a cron job, so +you can schedule most of the build jobs (really, it has been designed +to run perfectly from cron). diff --git a/sysutils/sysbuild/INSTALL b/sysutils/sysbuild/INSTALL new file mode 100644 index 00000000000..262be46e13c --- /dev/null +++ b/sysutils/sysbuild/INSTALL @@ -0,0 +1,32 @@ +#!/bin/sh +# +# $NetBSD: INSTALL,v 1.1.1.1 2002/11/28 19:57:28 jmmv Exp $ + +SYSBUILD_USER=@SYSBUILD_USER@ +SYSBUILD_HOMEDIR=@SYSBUILD_HOMEDIR@ +EGDIR=@EGDIR@ + +case ${STAGE} in +POST-INSTALL) + echo "Creating sysbuild's home directory..." + if [ ! -d ${SYSBUILD_HOMEDIR} ]; then + ${MKDIR} -p ${SYSBUILD_HOMEDIR} > /dev/null 2>&1 + ${CP} /etc/skel/.[a-z]* ${SYSBUILD_HOMEDIR} > /dev/null 2>&1 + fi + echo "Setting up sysbuild's crontab..." + crontab -u ${SYSBUILD_USER} -r > /dev/null 2>&1 + crontab -u ${SYSBUILD_USER} ${EGDIR}/crontab > /dev/null 2>&1 + ;; + +DEINSTALL) + echo "Removing sysbuild's crontab..." + crontab -u ${SYSBUILD_USER} -r > /dev/null 2>&1 + ${CAT} << EOF +=========================================================================== +If you will not be using sysbuild any longer, you may want to remove +sysbuild's home directory and all work areas. Just to let you know, work +areas can be removed using the 'destroy' target of the program. +=========================================================================== +EOF + ;; +esac diff --git a/sysutils/sysbuild/MESSAGE b/sysutils/sysbuild/MESSAGE new file mode 100644 index 00000000000..5d4e4a3fa50 --- /dev/null +++ b/sysutils/sysbuild/MESSAGE @@ -0,0 +1,15 @@ +=========================================================================== +$NetBSD: MESSAGE,v 1.1.1.1 2002/11/28 19:57:28 jmmv Exp $ + +sysbuild has been installed successfully. These lines are a must to get +started: + + ${PREFIX}/bin/sysbuild config + ${PREFIX}/bin/sysbuild init + +A sample crontab file for the '${SYSBUILD_USER}' user has been installed. +Use the following command (as root) to edit it interactively: + + crontab -e -u ${SYSBUILD_USER} + +=========================================================================== diff --git a/sysutils/sysbuild/Makefile b/sysutils/sysbuild/Makefile new file mode 100644 index 00000000000..f82739971e5 --- /dev/null +++ b/sysutils/sysbuild/Makefile @@ -0,0 +1,67 @@ +# $NetBSD: Makefile,v 1.1.1.1 2002/11/28 19:57:28 jmmv Exp $ +# + +DISTNAME= sysbuild-1.0 +CATEGORIES= sysutils +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= jmmv@netbsd.org +COMMENT= Automate NetBSD system and kernel unprivileged builds + +EXTRACT_ONLY= # empty +NO_CHECKSUM= yes +NO_PATH= yes +NO_CONFIGURE= yes +WRKSRC= ${WRKDIR} +CHECK_SHLIBS= no +SHLIB_HANDLING= no + +.include "../../mk/bsd.prefs.mk" + +# SYSBUILD_HOME - Home directory of SYSBUILD_USER user. +SYSBUILD_HOMEDIR?= /home/sysbuild +# SYSBUILD_USER - Unpriviledged user that runs the build script. +SYSBUILD_USER?= sysbuild +# SYSBUILD_OBJGROUP - Group that owns build files (should not be shared). +SYSBUILD_OBJGROUP?= wobj +# SYSBUILD_SRCGROUP - Group that owns sources (may be shared). +SYSBUILD_SRCGROUP?= wsrc + +FILES_SUBST+= SYSBUILD_HOMEDIR=${SYSBUILD_HOMEDIR} +FILES_SUBST+= SYSBUILD_USER=${SYSBUILD_USER} +FILES_SUBST+= SYSBUILD_OBJGROUP=${SYSBUILD_OBJGROUP} +FILES_SUBST+= SYSBUILD_SRCGROUP=${SYSBUILD_SRCGROUP} +FILES_SUBST+= EGDIR=${EGDIR} +MESSAGE_SUBST+= SYSBUILD_USER=${SYSBUILD_USER} + +DEINSTALL_EXTRA_TMPL= ${.CURDIR}/INSTALL +INSTALL_EXTRA_TMPL= ${.CURDIR}/INSTALL + +PKG_GROUPS= ${SYSBUILD_OBJGROUP} ${SYSBUILD_SRCGROUP} +PKG_USERS= ${SYSBUILD_USER}:${SYSBUILD_OBJGROUP}::`hostname`\\ sysbuild\\ output:${SYSBUILD_HOMEDIR}:${SH} + +EGDIR= ${PREFIX}/share/examples/sysbuild + +do-build: + @${ECHO} "Generating sysbuild.sh..." + @${SED} ${FILES_SUBST_SED} ${FILESDIR}/sysbuild.sh > \ + ${WRKSRC}/sysbuild.sh + @${ECHO} "Generating sysbuild.8..." + @${SED} ${FILES_SUBST_SED} ${FILESDIR}/sysbuild.8 > \ + ${WRKSRC}/sysbuild.8 + @${ECHO} "Generating sample default.conf..." + @${SED} ${FILES_SUBST_SED} ${FILESDIR}/default.conf > \ + ${WRKSRC}/default.conf + @${ECHO} "Generating sample crontab..." + @${SED} ${FILES_SUBST_SED} ${FILESDIR}/crontab > ${WRKSRC}/crontab + +do-install: + ${INSTALL_DATA_DIR} ${PREFIX}/share/examples/sysbuild + ${INSTALL_SCRIPT} ${WRKSRC}/sysbuild.sh ${PREFIX}/bin/sysbuild + ${INSTALL_MAN} ${WRKSRC}/sysbuild.8 ${PREFIX}/man/man8/sysbuild.8 + ${INSTALL_DATA} ${WRKSRC}/default.conf ${EGDIR}/default.conf + ${INSTALL_DATA} ${WRKSRC}/crontab ${EGDIR}/crontab + +.include "../../mk/bsd.pkg.install.mk" +.include "../../mk/bsd.pkg.mk" diff --git a/sysutils/sysbuild/PLIST b/sysutils/sysbuild/PLIST new file mode 100644 index 00000000000..237c060bae8 --- /dev/null +++ b/sysutils/sysbuild/PLIST @@ -0,0 +1,6 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2002/11/28 19:57:28 jmmv Exp $ +bin/sysbuild +man/man8/sysbuild.8 +share/examples/sysbuild/crontab +share/examples/sysbuild/default.conf +@dirrm share/examples/sysbuild diff --git a/sysutils/sysbuild/files/crontab b/sysutils/sysbuild/files/crontab new file mode 100644 index 00000000000..90f5bf23a95 --- /dev/null +++ b/sysutils/sysbuild/files/crontab @@ -0,0 +1,19 @@ +# $NetBSD: crontab,v 1.1.1.1 2002/11/28 19:57:29 jmmv Exp $ +# +# sysbuild - crontab file for '@SYSBUILD_USER@' user +# + +HOME=@SYSBUILD_HOMEDIR@ +SHELL=@SH@ +PATH=/bin:/sbin:/usr/bin:/usr/sbin:@PREFIX@/bin:@PREFIX@/sbin + +#minute hour mday month wday command + +# Update sources daily +#0 0 * * * @PREFIX@/bin/sysbuild -m update-srcs + +# Build kernel weekly +#0 4 * * 0 @PREFIX@/bin/sysbuild -m build-kernels + +# Build release weekly +#0 6 * * 0 @PREFIX@/bin/sysbuild -m build-release diff --git a/sysutils/sysbuild/files/default.conf b/sysutils/sysbuild/files/default.conf new file mode 100644 index 00000000000..ddea1d2f6b9 --- /dev/null +++ b/sysutils/sysbuild/files/default.conf @@ -0,0 +1,49 @@ +# $NetBSD: default.conf,v 1.1.1.1 2002/11/28 19:57:29 jmmv Exp $ +# +# sysbuild - System wide configuration file +# + +# ----------- Build time setup; be careful if you change these ----------- +HOMEDIR=@SYSBUILD_HOMEDIR@ +USER=@SYSBUILD_USER@ +OBJGROUP=@SYSBUILD_OBJGROUP@ +SRCGROUP=@SYSBUILD_SRCGROUP@ +# ------------------------------------------------------------------------ + +# Directory that holds all object files and DESTDIR (requires *lots* +# of space). +BUILDDIR=/var/sysbuild + +# Release directory (it will require around 100-200 Mb). +RELEASEDIR=/var/sysbuild/NetBSD-1.6/i386 + +# Source directory. +SRCDIR=/usr/src + +# List of directories that are updated via cvs. +CVSDIRS="/usr/src /usr/pkgsrc /usr/xsrc" + +# Ownerships and permissions to set on CVSDIRS during clean-srcs. +CVSDIRS_OWNER=$USER +CVSDIRS_GROUP=$SRCGROUP +CVSDIRS_PERMS="g+w" + +# Base directory of kernel configuration files; sysbuild can only read +# the ones contained here. +KERNCONFDIR=$HOMEDIR + +# List of kernel names to build (files inside $KERNCONFDIR). You can +# specify several; the first one is the kernel installed locally. +KERNCONF="MYKERNEL GENERIC" + +# If using the `-m' flag, the user who will receive the logs. +MAILTO=root + +# Set to `yes' to send the entire log of commands through mail. +# Logs can become *very* big. +MAIL_CMDLOG=no + +# When using the install-sets target, unpack these sets. Note that +# etc.tgz is not specified, as it is specially installed through the +# etcupdate target. +SETS="base.tgz comp.tgz games.tgz man.tgz misc.tgz text.tgz" diff --git a/sysutils/sysbuild/files/sysbuild.8 b/sysutils/sysbuild/files/sysbuild.8 new file mode 100644 index 00000000000..39e53ba107a --- /dev/null +++ b/sysutils/sysbuild/files/sysbuild.8 @@ -0,0 +1,439 @@ +.\" $NetBSD: sysbuild.8,v 1.1.1.1 2002/11/28 19:57:29 jmmv Exp $ +.\" +.\" sysbuild - Automatic NetBSD system builds +.\" Copyright (c) 2002, Julio Merino <jmmv@netbsd.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 November 16, 2002 +.Dt SYSBUILD 8 +.Os +.Sh NAME +.Nm sysbuild +.Nd Automates +.Nx +release and kernel builds +.Sh SYNOPSIS +.Nm +.Op Fl ms +.Op Fl c Ar conf +.Ar target +.Op Ar target_args ... +.Sh DESCRIPTION +The +.Nm +utility automates the building process of a +.Nx +release and all related stuff (like kernels), everything working as an +unprivileged, special user. +It should be clear enough that this program does not add any kind of +magic to the existing build mechanisms of the +.Nx +operating system; it just makes things easier if you want to automate +them (for example, to run them from a +.Xr cron 8 +job). +.Pp +The following options are recognized: +.Bl -tag -width indent +.It Fl c Ar conf +Specify the name of the configuration file. +This is not a full name; it is just a symbolic name. +See +.Sx CONFIGURATION +for for information. +.It Fl m +Capture all output and send it by mail to the +.Va MAILTO +user specified in the configuration file. +.It Fl s +Automatically change privileges using +.Xr su 1 . +By default the program will +exit if user credentials for the specified target are incorrect. +.El +.Sh EXIT STATUS +Returns 0 on success, 1 if any error happened. +.Sh TARGETS +.Nm +behavior is controlled through a target. +A target specifies what the program should do when executed. +The following targets are recognized: +.Bl -tag -width ident +.It build-kernels +Automatically build all kernels listed in the +.Va KERNCONF +variable. +.Pp +Each kernel name listed in this variable is configured, cleaned, +depended and built inside its own directory, which is in turn placed in +.Pa $BUILDDIR/kernels . +Note that kernel configuration files must be stored inside the +directory pointed to by +.Va KERNCONFDIR . +.Pp +This target requires +.Ql @SYSBUILD_USER@ +privileges. +.It build-release +Build a full release of the system. +A release is formed by all compressed system sets, installation floppy +disks and standard kernels. +.Pp +Release files are placed inside the directory pointed by +.Va RELEASEDIR . +During the build, +.Va BSDOBJDIR +is set to +.Pa $BUILDDIR/obj +and +.Va DESTDIR +is set to +.Pa $BUILDDIR/root . +.Pp +Depends on +.Ql clean . +.Pp +This target requires +.Ql @SYSBUILD_USER@ +privileges. +.It build-sets +Build compressed system sets only. +If you want the sets to install them later on your own system, this is +the recommended target, as building a release takes much more time. +.Pp +Depends on +.Ql clean . +.Pp +This target requires +.Ql @SYSBUILD_USER@ +privileges. +.It clean +Cleanup all work areas. +This will unconditionally clean all the stuff located under the +directory specified by +.Va BUILDDIR , +but will not destroy the main directory hierarchy inside it. +.Pp +This target requires +.Ql @SYSBUILD_USER@ +privileges. +.It clean-srcs Op Ar dir ... +Cleanup permissions of all source files inside the directories +specified by +.Va CVSDIRS , +or the ones specified by the optional list +.Ar dir . +All files are set to +.Va CVSDIRS_OWNER +owner and +.Va CVSDIRS_GROUP +group. +Optional permissions can be provided through +.Va CVSDIRS_PERMS , +which are set on all files using +.Xr chown 8 . +.Pp +This target requires +.Ql root +privileges. +.It config Op Ar conf +Edit the default configuration file or the one specified by +.Ar conf , +if given (remember that these are symbolic names, not full paths). +This will run +.Xr vi 1 +if no editor is specified by the +.Ev EDITOR +variable. +.Pp +If the specified configuration file does not exist, a sample one is +copied from +.Pa @EGDIR@/default.conf . +.Pp +This command is interactive, so output cannot be captured with +.Fl m . +.Pp +This target requires +.Ql root +privileges. +.It destroy +Completely remove the work area specified by +.Va BUILDDIR . +You should run this target before deinstalling this program. +.It etcupdate +Extract the compressed +.Pa etc.tgz +file, generated during the +.Ql build-sets +or the +.Ql build-release +stages, in a temporary place and then run +.Xr etcupdate 8 +over it to update your +.Pa /etc +directory. +.Pp +This command is interactive, so output cannot be captured with +.Fl m . +.Pp +This target requires +.Ql root +privileges. +.It init +Initialize the work directory specified in +.Va BUILDDIR +plus all the subdirectories required inside it. +Should be run once, after configuring the program with the +.Ql config +target (or when creating new configuration files). +.Pp +This target requires +.Ql root +privileges. +.It install-kernel Op Ar kernel +Install the first kernel specified in the +.Va KERNCONF +variable or the one supplied by the +.Ar kernel +argument. +.Pp +This target requires +.Ql root +privileges. +.It install-sets +Install built system sets, placed inside +.Pa $RELEASEDIR/binary/sets . +Only sets specified in the +.Va SETS +variable are installed. +.Pp +This target requires +.Ql root +privileges. +.It update-srcs Op Ar dir ... +Use +.Xr cvs 1 +to update all source trees specified by +.Va CVSDIRS , +or the ones specified by the optional +.Ar dir +arguments. +.Pp +This target requires +.Ql @SYSBUILD_USER@ +privileges. +.El +.Sh CONFIGURATION +.Nm +supports multiple configuration files. +This is specially useful if you usually need to build different +versions of +.Nx , +that is, one configuration for each version. +.Pp +Configuration files are directly stored inside +.Pa @SYSBUILD_HOMEDIR@ , +and have a +.Ql .conf +extension. +The symbolic name of the configuration file (the one used with the +.Ar -c +flag) is formed by the name of the configuration file, without the +path and without the extension. +For example, the default configuration file (used when no other one is +specified) is named +.Pa @SYSBUILD_HOMEDIR@/default.conf , +but you could use +.Fl c Ar default +to select it. +You should not worry about where these files are stored, as the +.Ql config +target will take care of it. +.Pp +The sample configuration file (copied to all new configurations +created) is well documented and contains some reasonable +defaults. +Even though, a list of all known variables is provided here, +for reference: +.Bl -tag -width indent +.It BUILDDIR +The directory which holds all working stuff (object files, temporary +root, etc.). +You will need lots of space in this directory if you want +to build full releases. +.It CVSDIRS +White-space separated list of directories that are updated using +.Xr cvs 1 +when executing the +.Ql update-srcs +target. +.It KERNCONF +White-space separated list of kernels that are built with the +.Ql build-kernels +target. +The first one is the kernel that will be installed when running +.Ql install-kernel . +.It KERNCONFDIR +Directory which holds kernel configuration files. +Defaults to +.Pa @SYSBUILD_HOMEDIR@ . +.It RELEASEDIR +Base directory which will hold release files. +.It MAILTO +User who will receive all logs by mail when using the +.Fl m +flag. +.It MAIL_CMDLOG +If set to +.Ql yes , +mail the entire log of commands to the user specified in +.Va MAILTO +(if using the +.Fl m +flag). +If set to +.Ql no , +logs are left in +.Pa /tmp . +A summary of the process is always sent, regardless of this variable. +Remember that logs can become very big! +.It SETS +White-space separated list of compressed sets that should be +extracted in the machine while running +.Ql install-sets . +.It SRCDIR +Path to +.Nx +source directory tree, usually +.Pa /usr/src . +.El +.Sh SEE ALSO +.Xr crontab 1 , +.Xr cvs 1 , +.Xr mk.conf 5 , +.Xr cron 8 , +.Xr etcupdate 8 , +.Pa /usr/src/BUILDING +.Sh CRON JOBS +.Xr cron 8 +is our best friend to schedule these CPU tasks. +You can, for example, set a task to build a release while you are +sleeping, another to install it and when you get up you just have to +run the interactive +.Ql etcupdate +target to finish the process. +.Pp +To make this even easier, the +.Ql @SYSBUILD_USER@ +comes with a sample crontab file, with several (disabled) entries, +ready to be edited. +You should note that the +.Fl m +flag is a good choice for unattended tasks, because you will get a +report by mail when they finish. +.Pp +To edit it, simply type: +.Pp +.Dl crontab -e -u @SYSBUILD_USER@ +.Sh EXAMPLES +To initialize +.Nm +for the first time: +.Pp +.Dl sysbuild config +.Dl sysbuild init +.Pp +Once you have configured it properly, you can execute the following, as +.Ql root , +to build your kernels and system sets. +Note that the +.Fl s +flag will automatically downgrade privileges. +.Pp +.Dl sysbuild -s build-kernels +.Dl sysbuild -s build-sets +.Pp +And then, as +.Ql root , +you can install the results: +.Pp +.Dl sysbuild install-kernel +.Dl sysbuild install-sets +.Pp +Or, if you want to update all your source trees: +.Pp +.Dl sysbuild clean-srcs +.Dl sysbuild -s update-srcs +.Pp +The first command should be only required once, the first time you +want to do this task. +.Pp +Note that where we are using the +.Fl s +you could as well become the +.Ql @SYSBUILD_USER@ +user using +.Xr su 1 +and execute the command from there. +Read +.Sx SECURITY CONSIDERATIONS +for more details on this. +.Sh SECURITY CONSIDERATIONS +The unprivileged user +.Ql @SYSBUILD_USER@ +account is disabled by default. +This means that root can access it through +.Xr su 1 , +but no other user will be able to run +.Nm +properly. +If you want anybody to be able to use it, just set a password for the +account, give it to the user, and tell him to use the +.Fl s +flag. +.Sh NOTES +This program will only work in +.Nx 1.6 +and above. +Some targets may work in previous versions, but do not expect it to +work fine. +.Sh AUTHORS +.An Julio Merino Aq jmmv@netbsd.org +.Sh TO DO +There are many other things to do, but are left for future releases. +Here is a small list with some ideas: +.Bl -bullet -width indent +.It +Add support for X11R6 unprivileged builds. +This will require the use of +.Xr mount_union 8 +because X11R6 build system creates object files together with sources. +.It +Support building for multiple architectures. +.It +Add an update flag, so that the user can avoid automatic cleans before +builds. +.El diff --git a/sysutils/sysbuild/files/sysbuild.sh b/sysutils/sysbuild/files/sysbuild.sh new file mode 100644 index 00000000000..9d029607c79 --- /dev/null +++ b/sysutils/sysbuild/files/sysbuild.sh @@ -0,0 +1,570 @@ +#!/bin/sh +# +# $NetBSD: sysbuild.sh,v 1.1.1.1 2002/11/28 19:57:29 jmmv Exp $ +# +# sysbuild - Automatic NetBSD system builds +# Copyright (c) 2002, Julio Merino <jmmv@netbsd.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. +# + +progname=`basename $0` +allargs="$*" +conffile=@SYSBUILD_HOMEDIR@/default.conf + +# XXX: This is needed when downgrading privileges with su... +PATH=/bin:/sbin:/usr/bin:/usr/sbin:@PREFIX@/bin:@PREFIX@/sbin + +usage() { + echo "usage: sysbuild [-ms] [-c conf] target [target_arguments]" + echo + echo "Flags:" + echo " -c conf Base name of configuration file" + echo " -m Send all output by mail instead of console" + echo " -s Run 'su' to change privileges if needed" + echo + echo "Available targets:" + echo " build-kernels Build kernels" + echo " build-release Build a complete release" + echo " build-sets Build system sets only" + echo " clean Clean work directories" + echo " clean-srcs Fix ownerships in source directories" + echo " config Create or edit a configuration file" + echo " destroy Remove all build stuff" + echo " etcupdate Run etcupdate (interactive)" + echo " init Initialize work directories" + echo " install-kernel Install a built kernel" + echo " install-sets Install system sets" + echo " update-srcs Use CVS to update source directories" +} + +err() { + echo "$progname: $*" + exit 1 +} + +# -------------------------------------------------------------------- +# Checks +# -------------------------------------------------------------------- + +check_noroot() { + if [ "`id -un`" != "$USER" ]; then + if [ "$autosu" = "yes" ]; then + echo "$progname: downgrading privileges to '$USER'" + su -l $USER -c "@PREFIX@/bin/sysbuild $allargs" + if [ $? -ne 0 ]; then + err "cannot switch privileges; aborting" + fi + # XXX: After su, terminate inmediately. + exit 0 + else + err "this target must be run as '$USER' user (use the '-s' flag)" + fi + fi +} + +check_root() { + if [ `id -u` -ne 0 ]; then + if [ "$autosu" = "yes" ]; then + echo "$progname: becoming root" + su -l root -c "@PREFIX@/bin/sysbuild $allargs" + if [ $? -ne 0 ]; then + err "cannot switch privileges; aborting" + fi + # XXX: After su, terminate inmediately. + exit 0 + else + err "this target must be run as root (use the '-s' flag)" + fi + fi +} + +check_init() { + _ok=1 + if [ ! -d $HOMEDIR ]; then _ok=0; fi + if [ ! -d $BUILDDIR ]; then _ok=0; fi + if [ ! -d $BUILDDIR/kernel ]; then _ok=0; fi + if [ ! -d $BUILDDIR/obj ]; then _ok=0; fi + if [ ! -d $BUILDDIR/root ]; then _ok=0; fi + if [ ! -d $BUILDDIR/tools ]; then _ok=0; fi + if [ $_ok -eq 0 ]; then + err "trees not initialized; use the 'init' target first" + fi +} + +# -------------------------------------------------------------------- +# Kernel related functions +# -------------------------------------------------------------------- + +sysbuild_build_kernels() { + check_noroot + check_init + + _confs="$*" + if [ -z "$_confs" ]; then + _confs="$KERNCONF" + fi + + _log=`mktemp /tmp/sysbuild.XXXX` + if [ "$MAIL_CMDLOG" = "yes" ]; then + echo "Logging to $_log (will be removed later)" + else + echo "Logging to $_log (will NOT be removed later)" + fi + echo + for _k in $_confs; do + if [ ! -f "$KERNCONFDIR/$_k" ]; then + echo "No such kernel configuration $_k" + else + echo -n "Configuring kernel $_k:" + mkdir -p $BUILDDIR/kernel/$_k + config -s $SRCDIR/sys -b $BUILDDIR/kernel/$_k $KERNCONFDIR/$_k >> $_log 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + cd $BUILDDIR/kernel/$_k + + echo -n "Cleaning kernel $_k:" + make cleandir >> $_log 2>&1 + echo " done." + + echo -n "Depending kernel $_k:" + make depend >> $_log 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + + echo -n "Buildling kernel $_k:" + make >> $_log 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + echo "Kernel MD5: `md5 netbsd`" + fi + fi + fi + fi + echo + done + + if [ "$MAIL_CMDLOG" = "yes" ]; then + echo "Command log follows:" + cat $_log + rm -f $_log + fi +} + +sysbuild_install_kernel() { + check_root + check_init + + _conf="$*" + if [ -z "$_conf" ]; then + _conf="$KERNCONF" + fi + _conf=`echo $_conf | cut -d ' ' -f 1` + + if [ ! -f $BUILDDIR/kernel/$_conf/netbsd ]; then + err "kernel $_conf is not built." + else + cd $BUILDDIR/kernel/$_conf + echo "Kernel MD5: `md5 netbsd`" + echo "Installing $_conf kernel:" + make install + fi +} + +# -------------------------------------------------------------------- +# Release related functions +# -------------------------------------------------------------------- + +sysbuild_build_release() { + check_noroot + check_init + + _log=`mktemp /tmp/sysbuild.XXXX` + + sysbuild_clean + if [ "$MAIL_CMDLOG" = "yes" ]; then + echo "Logging to $_log (will be removed later)" + else + echo "Logging to $_log (will NOT be removed later)" + fi + echo -n "Building full release:" + mkdir -p $RELEASEDIR + cd $SRCDIR + BSDOBJDIR=$BUILDDIR/obj ./build.sh -T $BUILDDIR/tools -D $BUILDDIR/root -R $RELEASEDIR -U >> $_log 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + fi + + if [ "$MAIL_CMDLOG" != "yes" ]; then + echo "Command log follows:" + cat $_log + rm -f $_log + fi +} + +sysbuild_build_sets() { + check_noroot + check_init + + _log=`mktemp /tmp/sysbuild.XXXX` + + sysbuild_clean + if [ "$MAIL_CMDLOG" = "yes" ]; then + echo "Logging to $_log (will be removed later)" + else + echo "Logging to $_log (will NOT be removed later)" + fi + echo -n "Building system:" + cd $SRCDIR + BSDOBJDIR=$BUILDDIR/obj ./build.sh -T $BUILDDIR/tools -d -D $BUILDDIR/root -U >> $_log 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + + echo -n "Making sets:" + mkdir -p $RELEASEDIR/binary/sets + cd $SRCDIR/distrib/sets + make sets DESTDIR=$BUILDDIR/root RELEASEDIR=$RELEASEDIR UNPRIVED=yes >> $_log 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + fi + fi + + if [ "$MAIL_CMDLOG" != "yes" ]; then + echo "Command log follows:" + cat $_log + rm -f $_log + fi +} + +sysbuild_install_sets() { + check_root + check_init + + for _s in $SETS; do + echo -n "Installing $_s:" + if [ ! -f $RELEASEDIR/binary/sets/$_s ]; then + echo " not built yet" + else + cd / && tar xzpf $RELEASEDIR/binary/sets/$_s > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + fi + fi + done + echo + echo "You MUST now run 'sysbuild etcupdate' by hand to update /etc." +} + +# -------------------------------------------------------------------- +# Cleanup functions +# -------------------------------------------------------------------- + +sysbuild_clean() { + check_noroot + check_init + + echo -n "Cleaning $BUILDDIR/obj contents:" + rm -rf $BUILDDIR/obj/* + echo " done." + + echo -n "Cleaning $BUILDDIR/root contents:" + rm -rf $BUILDDIR/root/* + echo " done." + + echo -n "Cleaning $BUILDDIR/tools contents:" + rm -rf $BUILDDIR/tools/* + echo " done." +} + +sysbuild_destroy() { + check_root + + echo -n "Destroying $BUILDDIR:" + rm -rf $BUILDDIR + echo " done." +} + +sysbuild_etcupdate() { + check_root + + tmp=`mktemp -d /tmp/sysbuild.XXXX` + if [ ! -f $RELEASEDIR/binary/sets/etc.tgz ]; then + err "etc.tgz is not yet built." + fi + echo -n "Backing up /etc to /etc.old:" + rm -rf /etc.old + cp -rf /etc /etc.old > /dev/null 2>&1 + echo " done." + echo -n "Unpacking etc.tgz:" + cd $tmp && tar xzpf $RELEASEDIR/binary/sets/etc.tgz > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo " failed." + else + echo " done." + etcupdate -b $tmp + rm -rf $tmp + fi +} + +# -------------------------------------------------------------------- +# Initialization and configuration +# -------------------------------------------------------------------- + +sysbuild_init() { + check_root + + echo -n "Initializing $HOMEDIR:" + mkdir -p $HOMEDIR + chown $USER:$OBJGROUP $HOMEDIR + echo " done." + + echo -n "Initializing $BUILDDIR:" + # Make main directory + mkdir -p $BUILDDIR + chown $USER:$OBJGROUP $BUILDDIR + chmod 750 $BUILDDIR + # Make kernel work area + mkdir -p $BUILDDIR/kernel + chown $USER:$OBJGROUP $BUILDDIR/kernel + chmod 750 $BUILDDIR/kernel + # Make obj work area + mkdir -p $BUILDDIR/obj + chown $USER:$OBJGROUP $BUILDDIR/obj + chmod 750 $BUILDDIR/obj + # Make root work area + mkdir -p $BUILDDIR/root + chown $USER:$OBJGROUP $BUILDDIR/root + chmod 750 $BUILDDIR/root + # Make tools directory + mkdir -p $BUILDDIR/tools + chown $USER:$OBJGROUP $BUILDDIR/tools + chmod 750 $BUILDDIR/tools + echo " done." +} + +sysbuild_config() { + check_root + + _conf="$1" + if [ -z "$_conf" ]; then + _conf="default" + fi + _conffile="@SYSBUILD_HOMEDIR@/$_conf.conf" + + if [ ! -f "$_conffile" ]; then + echo -n "Copying template to $_conffile:" + cp @EGDIR@/default.conf $_conffile + chmod 644 $_conffile + echo " done." + fi + + if [ -z "$EDITOR" ]; then + vi $_conffile + else + $EDITOR $_conffile + fi +} + +# -------------------------------------------------------------------- +# Source related functions +# -------------------------------------------------------------------- + +sysbuild_clean_srcs() { + check_root + + _dirs="$*" + if [ -z "$_dirs" ]; then + _dirs="$CVSDIRS" + fi + + for _d in $_dirs; do + echo -n "Fixing ownerships and permissions of $_d:" + chown -R $CVSDIRS_OWNER:$CVSDIRS_GROUP $_d + if [ -n "$CVSDIRS_PERMS" ]; then + chmod -R $CVSDIRS_PERMS $_d + fi + echo " done." + done +} + +sysbuild_update_srcs() { + check_noroot + + _dirs="$*" + if [ -z "$_dirs" ]; then + _dirs="$CVSDIRS" + fi + + for _d in $_dirs; do + echo "Updating source tree $_d" + cd $_d && CVS_RSH=ssh cvs -q -z6 update -dP + echo + done +} + +# -------------------------------------------------------------------- +# Main program +# -------------------------------------------------------------------- + +# Parse options +args=`getopt c:ms $*` +if [ $? != 0 ]; then + usage + exit 1 +fi +set -- $args +maillog="no" +autosu="no" +while [ $# -gt 0 ]; do + case "$1" in + -c) + conffile="@SYSBUILD_HOMEDIR@/$2.conf" + shift + ;; + -m) + maillog="yes" + maillogfile=`mktemp /tmp/sysbuild.XXXX` + ;; + -s) + autosu="yes" + ;; + --) + shift; break + ;; + esac + shift +done + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +target="$1" +shift + +# Read configuration file. +if [ "$target" != "config" -a ! -f $conffile ]; then + err "configuration file $conffile not found" +elif [ "$target" != "config" ]; then + . $conffile +fi + +# Parse targets. +case $target in + build-kernels) + if [ "$maillog" = "yes" ]; then + sysbuild_build_kernels $* >> $maillogfile + else + sysbuild_build_kernels $* + fi + ;; + build-release) + if [ "$maillog" = "yes" ]; then + sysbuild_build_release >> $maillogfile + else + sysbuild_build_release + fi + ;; + build-sets) + if [ "$maillog" = "yes" ]; then + sysbuild_build_sets >> $maillogfile + else + sysbuild_build_sets + fi + ;; + clean) + if [ "$maillog" = "yes" ]; then + sysbuild_clean >> $maillogfile + else + sysbuild_clean + fi + ;; + clean-srcs) + if [ "$maillog" = "yes" ]; then + sysbuild_clean_srcs $* >> $maillogfile + else + sysbuild_clean_srcs $* + fi + ;; + config) + sysbuild_config $* + ;; + destroy) + sysbuild_destroy + ;; + etcupdate) + sysbuild_etcupdate + ;; + init) + sysbuild_init + ;; + install-kernel) + if [ "$maillog" = "yes" ]; then + sysbuild_install_kernel >> $maillogfile + else + sysbuild_install_kernel + fi + ;; + install-sets) + if [ "$maillog" = "yes" ]; then + sysbuild_install_sets >> $maillogfile + else + sysbuild_install_sets + fi + ;; + update-srcs) + if [ "$maillog" = "yes" ]; then + sysbuild_update_srcs $* >> $maillogfile 2>&1 + else + sysbuild_update_srcs $* + fi + ;; + *) + err "unknown target '$target'" + ;; +esac + +if [ "$maillog" = "yes" ]; then + mail -s "Output of $target target" $MAILTO < $maillogfile + rm -f $maillogfile +fi + +exit 0 |