#!/bin/sh # $Id: pbulk.sh,v 1.1 2014/07/15 21:29:38 asau Exp $ set -e usage="usage: ${0##*/} [-lun] [-c mk.conf.fragment] [-d nodes]" while getopts lunc:d: opt; do case $opt in l) limited=yes;; u) unprivileged=yes;; n) native=yes;; c) mk_fragment="${OPTARG}";; d) nodes="${OPTARG}";; \?) echo "$usage" 1>&2; exit 1;; esac done shift $(expr $OPTIND - 1) if [ $# != 0 ]; then echo "$usage" 1>&2; exit 1; fi : ${TMPDIR:=/tmp} ## settings for unprivileged build: if [ -n "$unprivileged" ]; then : ${PBULKPREFIX:=${HOME}/pbulk} : ${PKGSRCDIR:=${HOME}/pkgsrc} : ${PREFIX:=${HOME}/pkg} : ${PACKAGES:=${HOME}/packages} : ${DISTDIR:=${HOME}/distfiles} : ${BULKLOG:=${HOME}/bulklog} fi ## : ${PBULKPREFIX:=/usr/pbulk} : ${PBULKWORK:=${TMPDIR}/work-pbulk} : ${PACKAGES:=/mnt/packages} : ${DISTDIR:=/mnt/distfiles} : ${BULKLOG:=/mnt/bulklog} # almost constant: : ${PKGSRCDIR:=/usr/pkgsrc} # Do it early since adding it after it fails is problematic: if [ ! -n "$unprivileged" ]; then case "$(uname)" in NetBSD) if ! id pbulk; then user add -m -g users pbulk; fi ;; FreeBSD) if ! id pbulk; then if ! pw groupshow users; then pw groupadd users; fi pw useradd pbulk -m -g users fi ;; *) if ! id pbulk; then echo "user \"pbulk\" is absent"; exit 1; fi ;; esac fi # Deploying pbulk packages: # - bootstrapping cat >${TMPDIR}/pbulk.mk <> ${PBULKPREFIX}/etc/pbulk.conf.over <> ${PBULKPREFIX}/etc/pbulk.conf.over <> ${PBULKPREFIX}/etc/pbulk.conf.over <<"EOF" # Don't forget to recompute dependent settings: loc=${bulklog}/meta EOF if [ -n "$limited" ]; then cat >> ${PBULKPREFIX}/etc/pbulk.conf.over < ${PBULKPREFIX}/etc/pbulk.list <> ${PBULKPREFIX}/etc/pbulk.conf.over <> ${PBULKPREFIX}/etc/pbulk.conf.over <<"EOF" # Don't forget to recompute dependent settings: make=${prefix}/bin/bmake EOF if [ -n "$native" ]; then # Native bulk build (native make, no bootstrap kit needed): cat >> ${PBULKPREFIX}/etc/pbulk.conf.over <> ${PBULKPREFIX}/etc/pbulk.conf.over <> ${PBULKPREFIX}/etc/pbulk.conf.over <<"EOF" # Recompute dependent settings: master_port_scan=${master_ip}:2001 master_port_build=${master_ip}:2002 EOF fi cat ${PBULKPREFIX}/etc/pbulk.conf ${PBULKPREFIX}/etc/pbulk.conf.over > ${PBULKPREFIX}/etc/pbulk.conf.new cp ${PBULKPREFIX}/etc/pbulk.conf ${PBULKPREFIX}/etc/pbulk.conf.bak mv ${PBULKPREFIX}/etc/pbulk.conf.new ${PBULKPREFIX}/etc/pbulk.conf # Bootstrapping cat ${mk_fragment:+"$mk_fragment"} - >${TMPDIR}/mk.conf.inc < /etc/mk.conf else # Ensure that the directory for bootstrap kit exists: mkdir -p ${PACKAGES} # Creating the bootstrap kit ${PKGSRCDIR}/bootstrap/bootstrap \ ${unprivileged:+--unprivileged --prefix=${PREFIX}} \ --mk-fragment=${TMPDIR}/mk.conf.inc \ --workdir=${TMPDIR}/work \ --gzip-binary-kit=${PACKAGES}/bootstrap.tar.gz rm -rf ${TMPDIR}/work rm -f ${TMPDIR}/mk.conf.inc fi # Final preparations: mkdir -p ${PACKAGES} if [ ! -n "$unprivileged" ]; then chown pbulk:"$(id -gn pbulk)" ${PACKAGES} fi # Let's start: #${PBULKPREFIX}/bin/bulkbuild