#!/bin/sh # == Objective == # Create a virgin chroot # Copy in build (make.conf) and port (/var/db/ports) configuration # Compute build/runtime dependencies for leaf port # Install build/runtime dependency packages, if they exist from a previous leaf port build # Build a single leaf port # Create packages for leaf port and its runtime dependencies # Create a separate set of packages for its build-time dependencies, to use for later leaf port builds ROOT="$(realpath "$(dirname "${0}")")" TARGET=amd64 CONFIG=SS4200 meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; } omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; } wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; } tgtdir="${TARGET}/${CONFIG}" build="${ROOT}/port/root" # Location of build environment date="$(date +%Y%m%d)" srctree="${ROOT}/${tgtdir}" # Virgin build env will be copied from here # Prepare a build chroot prepare() { mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue" # Put cleanup trap here so that an abort during prepare properly cleans up trap "cleanup" exit hup int term kill meh "Preparing build environment" mkdir -p "${build}" || wtf cd "${srctree}"; find . | cpio -p "${build}" || wtf # Hold packages for build deps mkdir -p "${build}/pkg/build" || wtf # Hold packages for runtime deps mkdir -p "${build}/pkg/run" || wtf meh "Mounting chroot directories" || wtf mkdir -p "${build}/usr/ports" || wtf mkdir -p "${build}/usr/obj" || wtf mount -t devfs devfs "${build}/dev" || wtf mount -t nullfs -r /usr/src "${build}/usr/src" || wtf # Just in case a port needs kernel sources mount -t nullfs -r /usr/ports "${build}/usr/ports" || wtf if [ -d "${world}/config" ] then meh "Installing build-time configuration" # Install make.conf [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/" || wtf # Install port options files [ -d "${world}/config/ports" ] && ( cd "${world}/config/ports"; find . -type d -o -type f -name 'options' | cpio -p "${build}/var/db/ports/" ) || wtf fi } # Evaluate a bit of code within the ${build} chroot # If ${chroot_env} is set, replace environment with it before chrooting chroot_eval() { [ "${chroot_env}" ] && env="env -i ${chroot_env}" ${env} chroot "${build}" /bin/sh } # Clean up and remove the build chroot cleanup() { meh "Cleaning up" umount -f "${build}/usr/ports" umount -f "${build}/usr/src" umount -f "${build}/dev" mount |grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing" chflags -R noschg "${build}" rm -Rf "${build}" } prepare chroot_eval cleanup