#!/bin/sh # $NetBSD: pbulk.sh,v 1.8 2018/10/29 02:47:08 sevan 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} : ${BULKLOG:=${HOME}/bulklog} fi ## : ${PBULKPREFIX:=/usr/pbulk} : ${PBULKWORK:=${TMPDIR}/work-pbulk} : ${PACKAGES:=/mnt/packages} : ${BULKLOG:=/mnt/bulklog} # almost constant: : ${PKGSRCDIR:=/usr/pkgsrc} # setting pkgdb directory: if [ -n "$unprivileged" -o -n "${PREFIX}" ]; then : ${PKGDBDIR:=${PREFIX}/var/db/pkg} fi # Do it early since adding it after it fails is problematic: if [ ! -n "$unprivileged" ]; then case "$(uname)" in NetBSD|Minix) 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 <> ${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 if [ -n "$native" ]; then if [ -n "$mk_fragment" ]; then cat "$mk_fragment" > /etc/mk.conf; fi else # Ensure that the directory for bootstrap kit exists: mkdir -p ${PACKAGES} # Creating the bootstrap kit ${PKGSRCDIR}/bootstrap/bootstrap \ ${unprivileged:+--unprivileged} \ ${PREFIX:+--prefix=${PREFIX}} \ ${mk_fragment:+--mk-fragment="$mk_fragment"} \ --workdir=${TMPDIR}/work \ ${PKGDBDIR:+--pkgdbdir=${PKGDBDIR}} \ --gzip-binary-kit=${PACKAGES}/bootstrap.tar.gz rm -rf ${TMPDIR}/work rm -f ${TMPDIR}/mk.conf.inc fi # Keep "packages" in pbulk.conf and "PACKAGES" in mk.conf fragment in sync. # Final preparations: mkdir -p ${PACKAGES} # Let's start: #PACKAGES=${PACKAGES} WRKOBJDIR=${TMPDIR} ${PBULKPREFIX}/bin/bulkbuild