#!/bin/sh # # Expects BUILDROOTPREFIX environment variable and that the script is run # from the directory in which it resides. # OSNAME=FreeBSD-CURRENT-20071108-amd64 BUILDROOTPREFIX=${BUILDROOTPREFIX-/var/scratch/pkgbuilder} PACKAGES=${PACKAGES-/a/pkg/8-current-amd64} FSTAR=/var/scratch/${OSNAME}.tar.bz2 PORTSDIRIP=192.168.0.2 PORTSDIRNULLMNT="/host/sol/a/ports" ME=`expr "$0" : '.*/\(.*\)'` MAKECONF=make.conf FSNAME=$OSNAME BUILDROOT=${BUILDROOTPREFIX}/${FSNAME} WRKDIRPREFIX=${WRKDIRPREFIX-/a/scratch} PKG_PATH="${PACKAGES}/All" MASTERBUILDER=yes # Command line controlled # doinit= dobuild= dormtar=yes doNullMount= doSoftLink= PKGLIST="${PKGLIST}" # Make sure we clean up if we get interrupted # trap do_cleanup 2 3 15 # set_buildroot path set_buildroot() { [ -z "$1" ] && { echo "set_buildroot: no path"; exit 1; } BUILDROOTPREFIX="$1" BUILDROOT=${BUILDROOTPREFIX}/${FSNAME} } usage() { echo "usage: ${ME} [-n] [-p path] -i | -b | -c" echo " ${ME} [-acn] [-p path] -i" exit 2 } # do_cleanup # do_cleanup() { echo "Unmounting devfs." umount "${BUILDROOT}/dev" echo "Unmounting the ports tree." umount "${BUILDROOT}/usr/ports/distfiles" umount "${BUILDROOT}/usr/ports" } # mycopy src dst quiet # Copy files from src to dst directory. # mycopy() { local quiet src dst src="$1" dst="$2" quiet="$3" [ -z "$src" -o -z "$dst" ] && return for _f in `ls "$src"` ; do if [ ! -f "${dst}/${_f}" ]; then [ -z "$quiet" ] && echo "Copying ${_f}" cp ${src}/${_f} ${dst}/ fi done } [ $# -lt 1 ] && usage args=`getopt abcilnp $*` set -- $args for i ; do case "$i" in -a) doNullMount=true shift;; -b) dobuild=yes shift;; -c) docopy=yes shift;; -i) doinit=yes shift;; -l) doSoftLink=true shift;; -n) dormtar= shift;; -p) set_buildroot "$2" shift;shift;; esac done [ -n "$doinit" -a -n "$dobuild" ] && usage [ -n "$docopy" -a -n "$dobuild" ] && usage [ -z "$doinit" -a -z "$dobuild" -a -z "$docopy" ] && usage if [ -z "$BUILDROOTPREFIX" ]; then echo 1>&2 "No BUILDROOTPREFIX environment variable" exit 1 fi _mntcmd= if [ -n "$doinit" ]; then echo -n "Initializing build:" # Get rid of '--' in reset argument list, and # set the package list to the remaining command line arguments. # shift PKGLIST="$*" # Untar the chroot # if [ -n "$dormtar" ]; then echo -n ' rm' rm -rf "${BUILDROOT}" > /dev/null 2>&1 chflags -R noschg "${BUILDROOT}" > /dev/null 2>&1 rm -rf "${BUILDROOT}" echo -n ' tar' tar -C "$BUILDROOTPREFIX" -xpf "$FSTAR" || exit 1 fi # Copy this script into the chroot # echo -n " copy" cp pkgbuild.sh "${BUILDROOT}/" cp "$ME" "${BUILDROOT}/" chmod a+x "${BUILDROOT}/$ME" "${BUILDROOT}/pkgbuild.sh" cp "$MAKECONF" "${BUILDROOT}/etc" # Setup the package and build directories. # echo -n ' dirs' rm -rf "${BUILDROOT}/${WRKDIRPREFIX}/*" mkdir -p "${BUILDROOT}/${WRKDIRPREFIX}" echo -n ' packages' [ ! -d "${BUILDROOT}/${PKG_PATH}" ] && \ mkdir -p "${BUILDROOT}/${PKG_PATH}" echo '.' echo "Copying Packages into chroot." mycopy "${PACKAGES}" "${BUILDROOT}/${PKG_PATH}" echo "Mounting devfs." [ ! -d "${BUILDROOT}/dev" ] && mkdir "${BUILDROOT}/dev" if ! mount -t devfs dev "${BUILDROOT}/dev" ; then echo "Could not mount devfs!!!" exit 1 fi echo "Mounting the ports tree." if ${doNullMount:-false} ; then if [ -f "${BUILDROOT}/usr/ports" -o -L ${BUILDROOT}/usr/ports ] then rm "${BUILDROOT}/usr/ports" elif [ ! -d "${BUILDROOT}/usr/ports" ]; then rm -rf "${BUILDROOT}/usr/ports" fi mkdir "${BUILDROOT}/usr/ports" _mntcmd="mount -t nullfs $PORTSDIRNULLMNT \"${BUILDROOT}/usr/ports\"; mount -t nullfs $PORTSDIRNULLMNT/distfiles \"${BUILDROOT}/usr/ports/distfiles\"" elif ${doSoftLink:-false}; then if [ -d "${BUILDROOT}/usr/ports" ]; then rmdir "${BUILDROOT}/usr/ports" elif [ -f "${BUILDROOT}/usr/ports" -o -L ${BUILDROOT}/usr/ports ]; then rm "${BUILDROOT}/usr/ports" fi _mntcmd="ln -s ${PORTSDIRNULLMNT} \"${BUILDROOT}/usr/ports\"" else if [ -f "${BUILDROOT}/usr/ports" -o -L ${BUILDROOT}/usr/ports ] then rm "${BUILDROOT}/usr/ports" elif [ ! -d "${BUILDROOT}/usr/ports" ]; then rm -rf "${BUILDROOT}/usr/ports" fi mkdir "${BUILDROOT}/usr/ports" _mntcmd="mount -t nfs ${PORTSDIRIP}:/a/ports \"${BUILDROOT}/usr/ports\"" fi if ! eval $_mntcmd ; then echo "No ports tree!!!" fi export MASTERBUILDER PKGLIST WRKDIRPREFIX PACKAGES PKG_PATH chroot "$BUILDROOT" /${ME} -b do_cleanup elif [ -n "$dobuild" ]; then echo "Executing pkg building script." ./pkgbuild.sh fi if [ -n "$docopy" ]; then echo "Copying packages to repository:" mycopy "${BUILDROOT}/${PKG_PATH}" ${PACKAGES} fi exit 0