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.

94 lines
2.0 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='nqv'
  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. -n|--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 [ $# -lt 2 ]; then
  51. echo_error "Not enough arguments given."
  52. download_usage
  53. exit -1
  54. fi
  55. target="$1"; shift
  56. protocol=${1%%:*}
  57. # debug output
  58. [ $verbose -le 1 ] || echo_info "($protocol) $@"
  59. # find the right handler
  60. if [ -x "$SDEROOT/bin/sde-download-$protocol" ]; then
  61. handler="$SDEROOT/bin/sde-download-$protocol"
  62. else
  63. handler=$( grep -l "^#Protocol: $protocol\$" "$SDEROOT/bin"/sde-download-* 2> /dev/null )
  64. fi
  65. handleropt=
  66. [ -x "$handler" ] || echo_abort 2 "$protocol: protocol unhandled"
  67. if [ -n "$dryrun" ]; then
  68. echo "(${handler##*/}) $source"
  69. elif [ ! -e "$target.lock" ]; then
  70. # arguments for the handler, reduce the verbosity on one level
  71. if [ $verbose -gt 2 ]; then
  72. handleropt="-v"
  73. elif [ $verbose -lt 0 ]; then
  74. handleropt="-q"
  75. fi
  76. exec "$handler" $handleropt -- "$target" "$@"
  77. fi