summaryrefslogtreecommitdiff
path: root/localsyncthis
blob: b6a725dd6b9ba369ae1cba8d435d4a0cff7eaaf6 (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. where options are the following:
  19. -v|--verbose Verbose mode
  20. --host Hostname(s) of remote host(s)
  21. -l|--localdir Local base directory (only if path specified)
  22. -r|--remotedir Remote base directory
  23. -p|--port ssh port number
  24. --ssh-opts Arbitrary ssh options
  25. -h|--help This help text
  26. -* Arbitrary rsync options
  27. --upload mirrors from local dir to remote dir.
  28. --download does the opposite.
  29. If no path specified, current working directory is used."
  30. exit 0
  31. ;;
  32. -v|--verbose) V=1; rsync_opts="$rsync_opts --progress --stats";;
  33. --download) action=download;;
  34. --upload) action=upload;;
  35. --test|--dry-run) rsync_opts="$rsync_opts --dry-run";;
  36. --force|--whole-file) rsync_opts="$rsync_opts --whole-file";;
  37. --host) hosts="$hosts $2"; shift;;
  38. -l|--localdir) localdir="$2"; shift;;
  39. -r|--remotedir) remotedir="$2"; shift;;
  40. -p|--port) ssh_opts="$ssh_opts -p $2"; shift;;
  41. --ssh-opts) ssh_opts="$ssh_opts $2"; shift;;
  42. -*) rsync_opts="$rsync_opts $1";;
  43. *) args="$args $1";;
  44. esac
  45. shift
  46. done
  47. set -- $args
  48. if [ -z $hosts ]; then
  49. hosts=$1
  50. shift
  51. fi
  52. if [ -z $hosts ]; then
  53. echo "$prg error: Hostname missing!"
  54. echo
  55. $0 --help
  56. exit 1
  57. fi
  58. if [ "x$1" = "x" ]; then
  59. workdirs=`pwd`
  60. localdir=''
  61. else
  62. workdirs=$@
  63. fi
  64. for workdir in $workdirs; do
  65. for host in $hosts; do
  66. here="$localdir$workdir"
  67. there="$host:$remotedir$workdir"
  68. case $action in
  69. download)
  70. rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here
  71. [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $there/ $here
  72. ;;
  73. upload)
  74. rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there
  75. [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts $here/ $there
  76. ;;
  77. *) echo "$prg error: You need to specify either --upload or --download!"
  78. echo
  79. $0 --help
  80. exit 1
  81. ;;
  82. esac
  83. done
  84. done