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

. /usr/pkg/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

if [ -f "${bulklog}.old/meta/pscan" ]; then
	extra_pscan_args="-L ${bulklog}.old/meta/pscan"
else
	extra_pscan_args=""
fi

${client_prepare}

for client in ${scan_clients}; do
	case ${client} in
	/*)
		path=${client}
		port=
		client=
		;;
	*:*)
		path=
		port="-p ${client##*:}"
		client=${client%%:*}
		;;
	*)
		path=
		port=
		;;
	esac
	if [ -z "$path" ]; then
		ssh $port $client "${pscan} -c ${master_port_scan} -M ${make} ${extra_pscan_args} ${pkgsrc}" &
	else
		chroot "$path" ${pscan} -c ${master_port_scan} -M ${make} ${extra_pscan_args} ${pkgsrc} &
	fi
done
