blob: a3948bea6e33f76f62bdcdd010c3d2bd0443a2ed (
plain)
- #!/bin/sh
- # Initial setup
- prg=$(basename $0)
- copyright="(C) 2000-2002 Jonas Smedegaard <dr@jones.dk>"
- V=''
- action=''
- hosts=''
- rsync_opts='-avrtz --delete --force'
- ssh_opts=''
- localdir=''
- remotedir=''
- args=''
- while [ $# -gt 0 ]; do
- case $1 in
- -h|--help) echo "$prg, $copyright
- usage: $prg [<options>] host [path [path...]]
- or: $prg [<options>] \"host [host...]\" [path [path...]]
- and options are the following:
- --download Make local directory equal to the remote one
- --upload Make remote directory equal to the local one
- --test Simulate, don't actually change anything
- --dry-run (Alias for --test)
- --force Always copy whole files (disable rsync feature)
- --whole-file (Alias for --force)
- -v|--verbose Verbose mode
- --host Hostname(s) of remote host(s)
- -l|--localdir Local base directory (only if path specified)
- -r|--remotedir Remote base directory
- -p|--port ssh port number
- -b|--batch Enable BatchMode (for use in automatic scripts)
- --ssh-opts Arbitrary ssh options
- -h|--help This help text
- -* Arbitrary rsync options
- One of either --download or --upload is required. Last occurence
- supersedes earlier ones.
- If no path specified, current working directory is used."
- exit 0
- ;;
- -v|--verbose) V=1; rsync_opts="$rsync_opts --progress --stats";;
- --download) action=download;;
- --upload) action=upload;;
- --test|--dry-run) rsync_opts="$rsync_opts --dry-run";;
- --force|--whole-file) rsync_opts="$rsync_opts --whole-file";;
- --host) hosts="$hosts $2"; shift;;
- -l|--localdir) localdir="$2"; shift;;
- -r|--remotedir) remotedir="$2"; shift;;
- -p|--port) ssh_opts="$ssh_opts -p $2"; shift;;
- -b|--batch) ssh_opts="$ssh_opts -o BatchMode=yes";;
- --ssh-opts) ssh_opts="$ssh_opts $2"; shift;;
- -*) rsync_opts="$rsync_opts $1";;
- *) args="$args $1";;
- esac
- shift
- done
- set -- $args
- if [ -z $hosts ]; then
- hosts=$1
- shift
- fi
- if [ -z $hosts ]; then
- echo "$prg error: Hostname missing!"
- echo
- $0 --help
- exit 1
- fi
- if [ "x$1" = "x" ]; then
- workdirs=`pwd`
- localdir=''
- else
- workdirs=$@
- fi
- for workdir in $workdirs; do
- for host in $hosts; do
- here="$localdir$workdir"
- there="$host:$remotedir$workdir"
- case $action in
- download)
- rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here
- [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here
- ;;
- upload)
- rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there
- [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there
- ;;
- *) echo "$prg error: You need to specify either --upload or --download!"
- echo
- $0 --help
- exit 1
- ;;
- esac
- done
- done
|