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.

189 lines
3.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-download2
  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. #Description: Download sources
  16. [ -n "$SDEROOT" ] ||
  17. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  18. . $SDEROOT/lib/libsde.in
  19. download_usage() {
  20. local progname=${0##*/}
  21. cat <<EOT >&2
  22. Usage: $progname [DISCRIMINATOR] [OPTIONS] [ITEMS...]
  23. Accepted discriminators:
  24. * config (cfg)
  25. * package (pkg) - default
  26. * repository (repo)
  27. For more information read \`sde help download\`.
  28. EOT
  29. }
  30. # detect discriminator
  31. discriminator=package
  32. if [ $# -gt 0 ]; then
  33. case "$1" in
  34. -*) ;;
  35. config|cfg)
  36. discriminator=config; shift ;;
  37. package|pkg)
  38. discriminator=package; shift ;;
  39. repository|repo)
  40. discriminator=repository; shift ;;
  41. *)
  42. echo_error "$1: invalid discriminator"
  43. download_usage
  44. exit -1 ;;
  45. esac
  46. fi
  47. shortopts='nqvc:m:e'
  48. longopts='dry-run,quiet,verbose,cfg,timeout:,cfg,check:,mirror:,mode:,extenders'
  49. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  50. if [ $? -ne 0 ]; then
  51. download_usage
  52. exit -1
  53. fi
  54. # load new arguments list
  55. eval set -- "$options"
  56. dryrun=
  57. verbose=1
  58. timeout=normal
  59. check=always
  60. mirror=
  61. mode=hardlink
  62. extenders=
  63. config=
  64. while [ $# -gt 0 ]; do
  65. case "$1" in
  66. --) shift; break ;;
  67. -n|--dry-run)
  68. dryrun=yes ;;
  69. -e|--extenders)
  70. extenders=yes ;;
  71. -v|--verbose)
  72. let verbose++ ;;
  73. -q|--quiet)
  74. let verbose-- ;;
  75. --timeout)
  76. shift
  77. case "$1" in
  78. normal|long|no)
  79. timeout="$1" ;;
  80. *)
  81. echo_abort 1 "$1: invalid timeout value: [normal*|long|no]"
  82. ;;
  83. esac ;;
  84. --check)
  85. shift
  86. case "$1" in
  87. always|download|never)
  88. check="$1" ;;
  89. *)
  90. echo_abort 1 "$1: invalid ckeck value: [always*|download|never]"
  91. ;;
  92. esac ;;
  93. --mirror)
  94. shift
  95. case "$1" in
  96. none|auto|http://*|https://*|ftp://*|file://*)
  97. mirror="$1" ;;
  98. *)
  99. echo_abort 1 "$1: invalid mirror value"
  100. ;;
  101. esac ;;
  102. -m|--mode)
  103. shift
  104. case "$1" in
  105. hardlink|copy|move)
  106. mode="$1" ;;
  107. *)
  108. echo_abort 1 "$1: invalid altdir mode [hardlink*|copy|move]"
  109. ;;
  110. esac ;;
  111. -c|--cfg)
  112. shift
  113. config=${1:-default}
  114. ;;
  115. esac
  116. shift
  117. done
  118. # constants to pass to sde-download-get
  119. downloadgetopt=
  120. if [ $verbose -gt 2 ]; then
  121. downloadgetopt='-v'
  122. elif [ $verbose -lt 0 ]; then
  123. downloadgetopt='-q'
  124. fi
  125. if [ -n "$dryrun" ]; then
  126. downloadgetopt="$downloadgetopt --dry-run"
  127. fi
  128. case "$discriminator" in
  129. package)
  130. $SDEROOT/bin/sde-list-download ${config:+--cfg $config} ${extenders:+--extenders} -pkl -- "$@"
  131. ;;
  132. repository)
  133. $SDEROOT/bin/sde-list-download ${config:+--cfg $config} ${extenders:+--extenders} -rpkl -- "$@"
  134. ;;
  135. config)
  136. [ -z "$config" ] || set -- "$config" "$@"
  137. [ $# -gt 0 ] || set -- default
  138. for config; do
  139. $SDEROOT/bin/sde-list-download --cfg "$config" -pkl
  140. done
  141. ;;
  142. esac | while read pkg cksum file location; do
  143. # temporal download location
  144. tmpfile="$SDEROOT/tmp/down.$( echo $file | tr '/' '-' )"
  145. mkdir -p "$SDEROOT/tmp"
  146. [ $? -eq 0 ] || exit -1
  147. if [ -s "$SDEROOT/$file" ]; then
  148. :
  149. elif [ -e "$tmpfile.lock" ]; then
  150. echo_warning "$file: skipping."
  151. else
  152. if [ $verbose -le 0 ]; then
  153. :
  154. elif [ $verbose -le 1 ]; then
  155. echo_info "Downloading $pkg:$file"
  156. else
  157. echo_info "Downloading $pkg:$file ($cksum) $location"
  158. fi
  159. "$SDEROOT"/bin/sde-download-get $downloadgetopt -- "$tmpfile" $location
  160. if [ $? -ne 0 ]; then
  161. echo_warning "$file: failed to download"
  162. rm -f "$tmpfile"
  163. else
  164. mkdir -p "${file%/*}"
  165. mv "${tmpfile}" "$file"
  166. fi
  167. fi
  168. done