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.

101 lines
2.2 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-git
  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 [-vq] <target> <source> <tag>
  22. EOT
  23. }
  24. shortopts='qv'
  25. longopts='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. verbose=1
  34. target=
  35. source=
  36. while [ $# -gt 0 ]; do
  37. case "$1" in
  38. --) shift; break ;;
  39. -v|--verbose)
  40. let verbose++ ;;
  41. -q|--quiet)
  42. let verbose-- ;;
  43. esac
  44. shift
  45. done
  46. # now take the real arguments
  47. if [ $# -ne 3 ]; then
  48. echo_error "Not enough arguments given."
  49. download_usage
  50. exit -1
  51. fi
  52. target="$1"
  53. source="$2"
  54. tag="$3"
  55. errno=0
  56. if [ -e "$target.lock" ]; then
  57. echo_warning "$target: File locked"
  58. exit 111
  59. else
  60. trap '' INT
  61. echo "$$" > "$target.lock"
  62. prefix=${source##*/}; prefix=${prefix%.git}-${tag}
  63. [ $verbose -le 1 ] || echo_info "git-archive --format=tar --prefix=$prefix/ --remote='$source' '$tag'"
  64. # download in background
  65. (
  66. git-archive --format=tar --prefix=$prefix/ --remote="$source" "$tag" | bzip2 > $target
  67. echo $? > $target.errno
  68. ) &
  69. # and wait until it ends
  70. while fuser $target &> /dev/null ; do
  71. echo -ne "$( nice du -sh "$target" 2> /dev/null | cut -f1 ) downloaded from archive so far...\r"
  72. sleep 3
  73. done
  74. errno=$( cat $target.errno 2> /dev/null )
  75. if [ "$errno" != "0" -o ! -s "$target" ]; then
  76. rm -f "$target"
  77. echo_error "Download failed (errno:${errno:-undefined})"
  78. elif [ $verbose -gt 0 ]; then
  79. echo_info "$( du -sh "$target" 2> /dev/null | cut -f1 ) downloaded from archive."
  80. fi
  81. rm -f "$target.errno" "$target.lock"
  82. trap - INT
  83. exit ${errno:-1}
  84. fi