summaryrefslogtreecommitdiff
path: root/localsyncthis
blob: a3948bea6e33f76f62bdcdd010c3d2bd0443a2ed (plain)
  1. #!/bin/sh
  2. # Initial setup
  3. prg=$(basename $0)
  4. copyright="(C) 2000-2002 Jonas Smedegaard <dr@jones.dk>"
  5. V=''
  6. action=''
  7. hosts=''
  8. rsync_opts='-avrtz --delete --force'
  9. ssh_opts=''
  10. localdir=''
  11. remotedir=''
  12. args=''
  13. while [ $# -gt 0 ]; do
  14. case $1 in
  15. -h|--help) echo "$prg, $copyright
  16. usage: $prg [<options>] host [path [path...]]
  17. or: $prg [<options>] \"host [host...]\" [path [path...]]
  18. and options are the following:
  19. --download Make local directory equal to the remote one
  20. --upload Make remote directory equal to the local one
  21. --test Simulate, don't actually change anything
  22. --dry-run (Alias for --test)
  23. --force Always copy whole files (disable rsync feature)
  24. --whole-file (Alias for --force)
  25. -v|--verbose Verbose mode
  26. --host Hostname(s) of remote host(s)
  27. -l|--localdir Local base directory (only if path specified)
  28. -r|--remotedir Remote base directory
  29. -p|--port ssh port number
  30. -b|--batch Enable BatchMode (for use in automatic scripts)
  31. --ssh-opts Arbitrary ssh options
  32. -h|--help This help text
  33. -* Arbitrary rsync options
  34. One of either --download or --upload is required. Last occurence
  35. supersedes earlier ones.
  36. If no path specified, current working directory is used."
  37. exit 0
  38. ;;
  39. -v|--verbose) V=1; rsync_opts="$rsync_opts --progress --stats";;
  40. --download) action=download;;
  41. --upload) action=upload;;
  42. --test|--dry-run) rsync_opts="$rsync_opts --dry-run";;
  43. --force|--whole-file) rsync_opts="$rsync_opts --whole-file";;
  44. --host) hosts="$hosts $2"; shift;;
  45. -l|--localdir) localdir="$2"; shift;;
  46. -r|--remotedir) remotedir="$2"; shift;;
  47. -p|--port) ssh_opts="$ssh_opts -p $2"; shift;;
  48. -b|--batch) ssh_opts="$ssh_opts -o BatchMode=yes";;
  49. --ssh-opts) ssh_opts="$ssh_opts $2"; shift;;
  50. -*) rsync_opts="$rsync_opts $1";;
  51. *) args="$args $1";;
  52. esac
  53. shift
  54. done
  55. set -- $args
  56. if [ -z $hosts ]; then
  57. hosts=$1
  58. shift
  59. fi
  60. if [ -z $hosts ]; then
  61. echo "$prg error: Hostname missing!"
  62. echo
  63. $0 --help
  64. exit 1
  65. fi
  66. if [ "x$1" = "x" ]; then
  67. workdirs=`pwd`
  68. localdir=''
  69. else
  70. workdirs=$@
  71. fi
  72. for workdir in $workdirs; do
  73. for host in $hosts; do
  74. here="$localdir$workdir"
  75. there="$host:$remotedir$workdir"
  76. case $action in
  77. download)
  78. rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here
  79. [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here
  80. ;;
  81. upload)
  82. rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there
  83. [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there
  84. ;;
  85. *) echo "$prg error: You need to specify either --upload or --download!"
  86. echo
  87. $0 --help
  88. exit 1
  89. ;;
  90. esac
  91. done
  92. done