#!/usr/bin/env bash
# rlocate -- run 'locate' across all machines

. lib.bash || exit

usage() {
	echo "Usage: $progname [-H hosts] [-bw] <keyword>..."
	echo
	echo_opt "-H hosts"	"list of hosts to search"
	echo_opt "-b"		"match against file name only"
	echo_opt "-w"		"match against entire path"
}

hosts="+myth"
args=""

while getopts ":H:bw" OPT; do
	case $OPT in
	H) hosts=${OPTARG//,/ };;
	b) args+=" -$OPT";;
	w) args+=" -$OPT";;
	*) lib:die_getopts;;
	esac
done; shift $((OPTIND-1))

hosts=`rlisthosts "$hosts"` || exit

if (( ! $# )); then
	vdie "query not specified"
fi

for arg; do
	args+=" ${arg@Q}"
done

rdo -q -H "$hosts" "bin/loc $args | sed \"s,^,/net/\$(hostname),\""
