OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.9 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-download-get
  6. # Copyright (C) 2007 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. [ -n "$SDEROOT" ] ||
  16. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  17. . $SDEROOT/lib/libsde.in
  18. download_usage() {
  19. local progname=${0##*/}
  20. cat <<EOT >&2
  21. Usage: $progname [-vqd] <target> <source>
  22. EOT
  23. }
  24. shortopts='dqv'
  25. longopts='dry-run,quiet,verbose'
  26. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  27. if [ $? -ne 0 ]; then
  28. download_usage
  29. exit -1
  30. fi
  31. # load new arguments list
  32. eval set -- "$options"
  33. dryrun=
  34. verbose=1
  35. target=
  36. source=
  37. while [ $# -gt 0 ]; do
  38. case "$1" in
  39. --) shift; break ;;
  40. -d|--dry-run)
  41. dryrun="yes" ;;
  42. -v|--verbose)
  43. let verbose++ ;;
  44. -q|--quiet)
  45. let verbose-- ;;
  46. esac
  47. shift
  48. done
  49. # now take the real arguments
  50. if [ $# -ne 2 ]; then
  51. echo_error "Not enough arguments given."
  52. download_usage
  53. exit -1
  54. fi
  55. target="$1"
  56. source="$2"
  57. protocol=${source%%:*}
  58. # debug output
  59. [ $verbose -le 1 ] || echo_info "($protocol) $source"
  60. # find the right handler
  61. handler=$( grep -l "^#Protocol: $protocol\$" "$SDEROOT/bin"/sde-download-* 2> /dev/null )
  62. handleropt=
  63. [ -x "$handler" ] || echo_abort 2 "$protocol: protocol unhandled"
  64. if [ -n "$dryrun" ]; then
  65. echo "(${handler##*/}) $source"
  66. elif [ ! -e "$target.lock" ]; then
  67. # arguments for the handler, reduce the verbosity on one level
  68. if [ $verbose -gt 2 ]; then
  69. handleropt="-v"
  70. elif [ $verbose -lt 0 ]; then
  71. handleropt="-q"
  72. fi
  73. exec "$handler" $handleropt -- "$target" "$source"
  74. fi