#!/bin/sh -

# mkhomes - make homes file
# Steve Kinzler, steve@kinzler.com, Oct 93
# https://kinzler.com/me/home.html#homedir

homes=${HOMES-$HOME/etc/homes}

tmp=/tmp/mkh$$
trap "rm -f $tmp; exit 2" 1 2 13 15

cat <<EOF > $tmp
# etc/homes - listing of known home directory locations
# https://kinzler.com/me/home.html#homedir

EOF

hosts home | eachhost -V -n -d 30 exec echo \$HOME |
	sed -n 's,^\([^ :]*:\) \(/[^ ]*\)$,\1\2,p' >> $tmp

if cmp $tmp "$homes" > /dev/null 2>&1
then
	rm -f $tmp
	exit
fi

if test -s $tmp
then
	trap '' 1 2 13 15
	rm -f "$homes"
	cat $tmp > "$homes"
	status=$?
else
	echo "$0: $homes not created" 1>&2
	status=1
fi

rm -f $tmp
exit $status
