#!/bin/sh
#############################################################################
#  dist_all,v 1.7 2003/01/22 04:19:42 garlick Exp
#############################################################################
#  Copyright (C) 2001-2002 The Regents of the University of California.
#  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
#  Written by Jim Garlick <garlick@llnl.gov>.
#  UCRL-CODE-2003-004.
#  
#  This file is part of Genders, a cluster configuration database and
#  rdist preprocessor.
#  For details, see <http://www.llnl.gov/linux/genders/>.
#  
#  Genders is free software; you can redistribute it and/or modify it under
#  the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
#  
#  Genders is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
#  details.
#  
#  You should have received a copy of the GNU General Public License along
#  with Genders; if not, write to the Free Software Foundation, Inc.,
#  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
#############################################################################

PATH=/admin/scripts:/admin/bin:$PATH
DIST=/usr/bin/dist2
FANOUT=32
NUMNODES=`nodeattr -n all|wc -l`

while [ $# -gt 0 ]; do
        case $1 in
		-l)
			ls -1 /var/dist/Distfile.* | sed 's/[^\.]*\.//'
			exit 0
			;;
		-r)
			NOSWITCH=1
			;;
                -w)     
			WOPT="-w$2"
			shift
                        ;;
                *)
			ARGS="$ARGS $1"
			;;
	esac
	shift
done

if [ $NOSWITCH ]; then
	$DIST $WOPT -r $ARGS
else
	# big system
	if [ $NUMNODES -gt 4 ]; then
		nodeattr -rn all | pdsh -b ${WOPT:-'-w-'} \
		    -f$FANOUT "$DIST -l "$ARGS"" | sed 's/[^:]*: //'

	# little system
	else
		$DIST $WOPT $ARGS
	fi
fi

exit 0
