#!/bin/sh
# $NetBSD: build-client-start,v 1.5 2016/12/18 22:59:35 joerg Exp $

. ${PBULK_CONF:-/opt/tools/etc/pbulk.conf}

set -e

if [ "${config_version}" != "0.68" ]; then
	echo "Your configuration has version ${config_version}."
	echo "This version of pbulk expects version 0.68."
	exit 1
fi

for client in ${build_clients}; do
	case ${client} in 
	/*)
		path=${client}
		port=
		client=
		;;
	*:*)
		path=
		port="-p ${client##*:}"
		client=${client%%:*}
		;;
	*)
		path=
		port=
		;;
	esac
	if [ -z "$path" ]; then
		if [ -n "${chroot_create}" -a "${chroot_dir}" ]; then
			ssh $port $client "for dir in ${chroot_dir}-build*; do
				PBULK_CONF=${PBULK_CONF} chroot \${dir} /bin/sh -c \"${pbuild} -c ${master_port_build} -b ${pbuild_script}\" &
			done" &
		else
			ssh $port $client "${pbuild} -c ${master_port_build} -b ${pbuild_script}" &
		fi
	else
		chroot "$path" ${pbuild} -c ${master_port_build} -b ${pbuild_script} &
	fi
done
