rget 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. PORT=8080
  3. usage () {
  4. cat <<EOF>&2
  5. Usage: ${0##*/} NETWORK-ADDRESS [DESTINATION]
  6. Fetched data from rsync NETWORK-ADDRESS to DESTINATION (defaults to current
  7. directory). Only size is used to compare files.
  8. Protocol and port are optional: they can be specified by command line
  9. parameters.
  10. Options:
  11. -H: Fetch from HTTP instead of rsync.
  12. -p: Specify a port number (default: $PORT).
  13. -s: Fetch single file (only in HTTP).
  14. EOF
  15. }
  16. OPT_HTTP=false
  17. OPT_SINGLE="--recursive"
  18. while getopts ":hHp:s" opt; do
  19. case $opt in
  20. h)
  21. usage
  22. exit ;;
  23. H)
  24. OPT_HTTP=true ;;
  25. p)
  26. PORT="$OPTARG" ;;
  27. s)
  28. OPT_SINGLE="";;
  29. \?)
  30. usage
  31. exit 1 ;;
  32. esac
  33. done
  34. shift $(($OPTIND - 1))
  35. [ $# -lt 1 ] && usage && exit 1
  36. [ "$1" = "-h" ] && usage && exit
  37. [ "$1" = "--" ] && shift
  38. ADDRESS="$1"
  39. OUTPUT="."
  40. [ -n "$2" ] && OUTPUT="$2"
  41. case "$ADDRESS" in
  42. http*)
  43. OPT_HTTP=true;;
  44. rsync*)
  45. OPT_HTTP=false;;
  46. *)
  47. if $OPT_HTTP; then
  48. ADDRESS=http://$ADDRESS:$PORT
  49. else
  50. ADDRESS=rsync://$ADDRESS:$PORT
  51. fi
  52. esac
  53. mkdir -p "$OUTPUT"
  54. if $OPT_HTTP; then
  55. wget --reject 'index.html*' $OPT_SINGLE --continue --content-disposition --compression=gzip --no-proxy "$ADDRESS" --directory-prefix="$OUTPUT"
  56. else
  57. # We ignore timestamp by removing "-t" from "-a". See man page.
  58. rsync -ivzzP -rlpgoD --size-only $ADDRESS/files "$OUTPUT"
  59. fi