#!/bin/bash # A way of copying files using dsh # Copyright (C) Frank Lee 24-10-2010 # # This program 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. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # VERSION=0.1 # TODO: Command line processing ought to be handled better # Specifically: -q for quiet / -v for verbose # -d for arguments to DSH # -c for compare/verify, perhaps? ### How to use ### function usage() { cat <>$CLIENTTMP `cat $F` EOF" done # If target is directory, append filename if [ ${DST:(-1)} = / ] ; then DST="$DST"/`basename "$SRC"` DST=${DST/\/\//\/} fi # join chunks, decode, tidy up TDIR=`dirname "$DST"` echo Decoding $DST $REMOTE "mkdir -p \"$TDIR\" cat $CLIENTTMP | base64 -d >\"$DST\"; rm $CLIENTTMP touch -d \"`stat -c %y $SRC`\" \"$DST\"; chgrp `stat -c %G $SRC` \"$DST\"; chown `stat -c %U $SRC` \"$DST\"; chmod `stat -c %a $SRC` \"$DST\"" rm -Rf $SPLITD $ENCSRC $CLIENTTMP } DSHARGS=${DSHARGS:--a} REMOTE="dsh $DSHARGS" if [ "$1" = '-h' ] ; then fullusage exit 0 fi if [ $# -lt 2 ] ; then usage exit 1 fi # Last argument is target MDST=${@:$#} echo Analysing target \"$MDST\" on all nodes # If DST ends with trailing /, create directory on target machines if [ ${MDST:(-1)} = / ] ; then $REMOTE mkdir -p \"$MDST\" fi # If DST is a directory on all machines, adjust DST to be target file if $REMOTE [ -d "$MDST" ] ; then # Don't adjust DST here, just leave as explicit directory MDST="$MDST"/ MDST=${MDST/\/\//\/} else # Not a directory on all machines. Is it a directory on any machine? if ! $REMOTE [ ! -d "$MDST" ] ; then echo $MDST is a directory on some machines but not on others. Not sure what to do. exit 2 fi fi I=1 while [ $I -lt $# ] ; do copyfile "${@:$I:1}" "$MDST" I=$((I+1)) done