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.

194 lines
4.1 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. altdir=
  62. mode=hardlink
  63. extenders=
  64. config=
  65. # load global settings
  66. eval $( $SDEROOT/bin/sde-config-ini --file=$SDESETTINGS download )
  67. eval $( $SDEROOT/bin/sde-config-ini --file=$SDESETTINGS download-$sdever )
  68. while [ $# -gt 0 ]; do
  69. case "$1" in
  70. --) shift; break ;;
  71. -n|--dry-run)
  72. dryrun=yes ;;
  73. -e|--extenders)
  74. extenders=yes ;;
  75. -v|--verbose)
  76. let verbose++ ;;
  77. -q|--quiet)
  78. let verbose-- ;;
  79. --timeout)
  80. shift
  81. case "$1" in
  82. normal|long|no)
  83. timeout="$1" ;;
  84. *)
  85. echo_abort 1 "$1: invalid timeout value: [normal*|long|no]"
  86. ;;
  87. esac ;;
  88. --check)
  89. shift
  90. case "$1" in
  91. always|download|never)
  92. check="$1" ;;
  93. *)
  94. echo_abort 1 "$1: invalid ckeck value: [always*|download|never]"
  95. ;;
  96. esac ;;
  97. --mirror)
  98. shift
  99. case "$1" in
  100. none|auto|http://*|https://*|ftp://*|file://*)
  101. mirror="$1" ;;
  102. *)
  103. echo_abort 1 "$1: invalid mirror value"
  104. ;;
  105. esac ;;
  106. -m|--mode)
  107. shift
  108. case "$1" in
  109. hardlink|copy|move)
  110. mode="$1" ;;
  111. *)
  112. echo_abort 1 "$1: invalid altdir mode [hardlink*|copy|move]"
  113. ;;
  114. esac ;;
  115. -c|--cfg)
  116. shift
  117. config=${1:-default}
  118. ;;
  119. esac
  120. shift
  121. done
  122. # constants to pass to sde-download-get
  123. downloadgetopt=
  124. if [ $verbose -gt 2 ]; then
  125. downloadgetopt='-v'
  126. elif [ $verbose -lt 0 ]; then
  127. downloadgetopt='-q'
  128. fi
  129. if [ -n "$dryrun" ]; then
  130. downloadgetopt="$downloadgetopt --dry-run"
  131. fi
  132. case "$discriminator" in
  133. package)
  134. $SDEROOT/bin/sde-list-download ${config:+--cfg $config} ${extenders:+--extenders} -pkl -- "$@"
  135. ;;
  136. repository)
  137. $SDEROOT/bin/sde-list-download ${config:+--cfg $config} ${extenders:+--extenders} -rpkl -- "$@"
  138. ;;
  139. config)
  140. [ -z "$config" ] || set -- "$config" "$@"
  141. [ $# -gt 0 ] || set -- default
  142. for config; do
  143. $SDEROOT/bin/sde-list-download --cfg "$config" -pkl
  144. done
  145. ;;
  146. esac | while read pkg cksum file location; do
  147. # temporal download location
  148. tmpfile="$SDEROOT/tmp/down.$( echo $file | tr '/' '-' )"
  149. mkdir -p "$SDEROOT/tmp"
  150. [ $? -eq 0 ] || exit -1
  151. if [ -s "$SDEROOT/$file" ]; then
  152. :
  153. elif [ -e "$tmpfile.lock" ]; then
  154. echo_warning "$file: skipping."
  155. else
  156. if [ $verbose -le 0 ]; then
  157. :
  158. elif [ $verbose -le 1 ]; then
  159. echo_info "Downloading $pkg:$file"
  160. else
  161. echo_info "Downloading $pkg:$file ($cksum) $location"
  162. fi
  163. "$SDEROOT"/bin/sde-download-get $downloadgetopt -- "$tmpfile" $location
  164. if [ $? -ne 0 ]; then
  165. echo_warning "$file: failed to download"
  166. rm -f "$tmpfile"
  167. else
  168. mkdir -p "${file%/*}"
  169. mv "${tmpfile}" "$file"
  170. fi
  171. fi
  172. done