while getopts "a:nc:l:N:p:d:P:R:" opt; do
case $opt in
n) native=yes;;
c) mk_fragment="${OPTARG}";;
l) limited_list="${OPTARG}";;
N) node_list="${OPTARG}";;
a) agent_script="${OPTARG}";;
p) PKGSRCDIR="${OPTARG}";;
d) DISTDIR="${OPTARG}";;
P) PACKAGES="${OPTARG}";;
R) REPORTBASE="${OPTARG}";;
\?) echo "$usage" 1>&2; exit 1;;
esac
done
shift $(expr $OPTIND - 1)
if [ $# -gt 1 ]; then echo "$usage" 1>&2; exit 1; fi
case "$1" in
*/*) CLUSTERBASE="$1";; # path
*) CLUSTERNAME="$1";; # name
esac
: ${CLUSTERNAME:=pbulk-cluster}
: ${JAILBASE:=/usr/jail}
: ${CLUSTERBASE:=${JAILBASE}/${CLUSTERNAME}}
export JAILBASE="${CLUSTERBASE}/nodes" # from now on
NODES="${JAILBASE}"
hosts=${CLUSTERBASE}/hosts
if [ -r "${node_list}" ]; then
cat "${node_list}" > "${hosts}"
elif [ ! -r "${hosts}" ]; then
echo "${0##*/}: node list is required" 1>&2; exit 1
fi
nodes=""; while read addr name; do nodes="${nodes:+$nodes }${name}"; done < ${hosts}
if [ ! -e ${CLUSTERBASE}/pbulk.sh ]; then cat "${agent_script}" > ${CLUSTERBASE}/pbulk.sh; fi
if [ -n "$limited_list" ]; then cat "$limited_list" > ${CLUSTERBASE}/pbulk.list; fi
if [ -n "${mk_fragment}" ]; then cat "${mk_fragment}" > ${CLUSTERBASE}/mk.conf.frag; fi
for node in ${nodes}; do
JAIL=${NODES}/${node}
if [ ! -x ${JAIL}/bin/sh ]; then # create node, if missing
create-root ${JAIL}
fi
start-root ${JAIL}
mkdir -p ${JAIL}/usr/pkgsrc && mount -t null -o ro ${PKGSRCDIR} ${JAIL}/usr/pkgsrc
mount -t null ${DISTDIR} ${JAIL}/usr/pkgsrc/distfiles
mount -t null -o rw ${PACKAGES} ${JAIL}/usr/pkgsrc/packages
mount -t null -o rw ${REPORTBASE} ${JAIL}/mnt
cat ${CLUSTERBASE}/pbulk.sh > ${JAIL}/root/pbulk.sh
if [ -n "${mk_fragment}" ]; then cat ${CLUSTERBASE}/mk.conf.frag > ${JAIL}/root/mk.conf.frag; fi
cp /etc/resolv.conf ${JAIL}/etc/resolv.conf
cp ${hosts} ${JAIL}/etc/hosts
if [ ! -f ${JAIL}/usr/pbulk/etc/mk.conf ]; then
(unset PKGSRCDIR; unset DISTDIR; PACKAGES=/usr/pkgsrc/packages exec chroot ${JAIL} /bin/sh /root/pbulk.sh ${native:+-n} ${limited_list:+-l} ${mk_fragment:+-c /root/mk.conf.frag} -d "${nodes}" >/tmp/${CLUSTERBASE##*/}-${node}.out 2>&1);
fi