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.

814 lines
20 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-download
  6. # Copyright (C) 2006 - 2009 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. #Description: Download sources
  18. #Alias: get
  19. set -e
  20. [ -n "$SDEROOT" ] ||
  21. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  22. . $SDEROOT/lib/libsde.in
  23. . $SDEROOT/lib/functions.in
  24. download_usage() {
  25. cat <<EOT
  26. Usage:
  27. sde download <options> [ Package(s) ]
  28. sde download <options> [ Desc file(s) ]
  29. sde download <options> -repository Repositories
  30. sde download <options> [ -all | -required ]
  31. Options is an alias for:
  32. [ -cfg <config> ] [ -nock ] [ -alt-dir <AlternativeDirectory> ]
  33. [ -mirror <URL> | -check ] [ -try-questionable ] [ -notimeout ]
  34. [ -longtimeout ] [ -curl-opt <curl-option>[:<curl-option>[:..]] ]
  35. [ -copy ] [ -move ]
  36. On default, this script auto-detects the best OpenSDE mirror.
  37. Mirrors can also be a local directories in the form of 'file:///<dir>'.
  38. sde download [ -list | -list-missing | -list-cksums ]
  39. See '-mirror none' output for help on bypassing the official mirrors.
  40. EOT
  41. }
  42. umask 022
  43. cd "$SDEROOT"
  44. # Handle options passed on the command line
  45. #
  46. mkdir -p tmp/ download/
  47. # Load system wide configuration for this tool
  48. #
  49. config=default mirror= mirror_last= altdir= proxy= proxyauth=
  50. if [ -s "$SDESETTINGS" ]; then
  51. eval $( $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" download )
  52. eval $( $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" download-$sdever )
  53. fi
  54. this_is_the_2nd_run=0
  55. checkonly=0 tryques=0 nocheck=0 notimeout=0
  56. options='-this_is_the_2nd_run '
  57. curl_options='-A opensde-downloader --disable-epsv --location -f'
  58. altcopy=link ; verbose=1
  59. downloaderror=0
  60. #
  61. while [ $# -gt 0 ]; do
  62. case "$1" in
  63. -this_is_the_2nd_run)
  64. this_is_the_2nd_run=1
  65. ;;
  66. -cfg)
  67. options="$options -cfg $2"
  68. config="$2" ; shift ;;
  69. -q)
  70. options="$options -q"
  71. verbose=0 ;;
  72. -nock)
  73. # -nock skips checksum checking (don't use lightly)
  74. options="$options -nock"
  75. nocheck=1 ; shift ;;
  76. -mirror)
  77. # -mirror uses a mirror for finding source files
  78. if [ "$2" = none ]; then
  79. echo
  80. echo "The option '-mirror none' is not supported anymore!"
  81. echo
  82. echo "You may edit \$HOME/.sde/settings if you really"
  83. echo "want to use the original download resources. However, this"
  84. echo "is not supported and if such a download fails, this is not"
  85. echo "a bug in the OpenSDE and doesn't neccessarily needs fixing."
  86. echo
  87. exit 1;
  88. elif [ "$2" = auto ]; then
  89. mirror=
  90. mirror_last=
  91. else
  92. options="$options -mirror $2"
  93. mirror="$2"
  94. mirror_last=$(date +%s)
  95. $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" \
  96. "download-$sdever.mirror=$mirror" \
  97. "download-$sdever.mirror_last=$mirror_last"
  98. fi
  99. shift ;;
  100. -check)
  101. # -check just validates the file using the checksum
  102. options="$options -check"
  103. checkonly=1 ;;
  104. -notimeout)
  105. # don't add timeout curl options
  106. options="$options -notimeout"
  107. notimeout=2 ;;
  108. -longtimeout)
  109. # don't add timeout curl options
  110. options="$options -longtimeout"
  111. notimeout=1 ;;
  112. -curl-opt)
  113. # additional curl options
  114. options="$options -curl-opt $2"
  115. curl_options="$curl_options `echo $2 | tr : ' '`"
  116. shift ;;
  117. -alt-dir)
  118. # check for an alternative directory where to search for
  119. # package source tarballs
  120. altdir=$( cd "$2" && pwd -P )
  121. $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" \
  122. "download.altdir=$altdir"
  123. shift ;;
  124. -try-questionable)
  125. # also try to download questionable URLs
  126. options="$options -try-questionable"
  127. tryques=1 ;;
  128. -move) altcopy=move ;;
  129. -copy) altcopy=copy ;;
  130. *) break ;;
  131. esac
  132. shift
  133. done
  134. if [ $notimeout -eq 0 ] ; then
  135. curl_options="$curl_options -y 10 -Y 10 --connect-timeout 60"
  136. fi
  137. if [ $notimeout -eq 1 ] ; then
  138. curl_options="$curl_options -y 60 -Y 1 --connect-timeout 300"
  139. fi
  140. # proxy (server[:port])
  141. if [ -n "$proxy" ]; then
  142. curl_options="$curl_options --proxy $proxy"
  143. # proxy needs auth (username[:password])
  144. [ -z "$proxyauth" ] || curl_options="$curl_options --proxy-user $proxyauth"
  145. # only show once
  146. [ $this_is_the_2nd_run = 1 ] || echo_info "Using <$proxy> as ${proxyauth:+authenticated }http proxy."
  147. fi
  148. #Disable checking for certificates on https downloads
  149. curl_options="$curl_options -k"
  150. # Autodetect best Mirror and safe url in $mirror
  151. #
  152. detect_mirror() {
  153. local age=
  154. if [ "$mirror" = "none" ] ; then
  155. echo_info "Using original download locations only."
  156. return
  157. elif [ "$mirror" = "broken" ]; then
  158. echo_warning "Previous detection of the mirror failed, trying again."
  159. elif [ -n "$mirror" ]; then
  160. age=$(expr `date +%s` - ${mirror_last:-0})
  161. age=$(expr $age / 3600)
  162. if [ $age -gt 24 ]; then
  163. echo_warning "Mirror choice <$mirror> is old, checking again."
  164. mirror=
  165. mirror_last=
  166. else
  167. echo_info "Using mirror <$mirror>."
  168. return
  169. fi
  170. fi
  171. echo_warning "Auto-detecting best mirror ..."
  172. echo_info "Downloading mirror-list from opensde.net."
  173. curl -s -S $curl_options -o tmp/Download-Mirror-List \
  174. "http://opensde.net/opensde-download-mirrors/$sdever"
  175. if [ -r tmp/Download-Mirror-List ]; then
  176. bash lib/sde-download/mirror-test.sh < tmp/Download-Mirror-List
  177. fi 2>&1 | echo_info
  178. # read new mirror info
  179. mirror=
  180. eval $( $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" download-$sdever )
  181. if [ -z "$mirror" ]; then
  182. echo_error "Mirror detection loop hit a bug!"
  183. elif [ "$mirror" = "broken" ]; then
  184. echo_warning "No Mirror Found!"
  185. else
  186. echo_info "Using mirror <$mirror>."
  187. fi
  188. }
  189. download_file_desc() {
  190. sed -n -e 's|^\[D\][ \t]\+||p' "package/$1/$2/$2.desc" |
  191. download_file_pipe "$1" "$2"
  192. }
  193. download_file_pipe() {
  194. local filename=
  195. while read cksum file url; do
  196. filename=$(source_file cksum $file "$url")
  197. download_file "$filename" "$url" "$cksum" "$@"
  198. done
  199. }
  200. # download_file local-filename download-location cksum repo pkg
  201. #
  202. # This function decides if download directly or from a mirror,
  203. # validates checksum, etc.
  204. # Calls download_file_now to do the actual download.
  205. #
  206. download_file() {
  207. # Init
  208. #
  209. local gzfile="$1" location="$2" cksum="$3" repo="$4" pkg="$5"
  210. # Make src directory for creating tar balls
  211. mkdir -p tmp/
  212. # Tarball file name:
  213. bzfile="`bz2filename "$gzfile"`"
  214. # Remove optional '-' prefix from $location
  215. [ "${location:0:1}" = '-' ] && location="${location:1}"
  216. # Lock file name:
  217. lkfile="tmp/down.lockfile.`echo $bzfile | tr / -`"
  218. # Check if it's already there
  219. #
  220. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  221. # Make locking
  222. #
  223. if [ -s "$lkfile" ]; then
  224. echo "Found $lkfile -> skip download."
  225. return 0
  226. fi
  227. trap 'rm -f "$lkfile"' INT
  228. echo $$ > "$lkfile"
  229. # Check if we only like to test the cksum(s)
  230. #
  231. if [ $checkonly = 1 ] ; then
  232. gzfile="$bzfile"
  233. if [ ! -f "$bzfile" ] ; then
  234. echo "File missing: $bzfile"
  235. rm -f "$lkfile" ; trap INT ; return 1
  236. fi
  237. if [ -z "${cksum##X*}" ] ; then
  238. echo "No checksum (ignore): $bzfile"
  239. rm -f "$lkfile" ; trap INT ; return 1
  240. fi
  241. if [ "$cksum" -eq 0 ] ; then
  242. echo "No checksum (missing): $bzfile"
  243. rm -f "$lkfile" ; trap INT ; return 1
  244. fi
  245. elif [ -s "$gzfile" ] ; then
  246. echo ; echo "Already downloaded $pkg:$gzfile ..."
  247. else
  248. echo ; echo "Downloading $pkg:$gzfile ..."
  249. # Existing *.cksum-err
  250. #
  251. if [ -s "$gzfile.cksum-err" ] ; then
  252. # cksum-err file alread exists:
  253. echo "ERROR: Found $gzfile.cksum-err."
  254. echo "ERROR: That means that we downloaded the" \
  255. "file already and it had an"
  256. echo "ERROR: incorrect checksum. Remove the" \
  257. "*.cksum-err file to force a"
  258. echo "ERROR: new download of that file."
  259. rm -f "$lkfile" ; trap INT ; return 1
  260. fi
  261. # Existing *.extck-err
  262. #
  263. if [ -s "$gzfile.extck-err" ] ; then
  264. # extck-err file alread exists:
  265. echo "ERROR: Found $gzfile.extck-err."
  266. echo "ERROR: That means that we downloaded the" \
  267. "file already and it's content"
  268. echo "ERROR: did not match it's filename extension." \
  269. "Remove the *.extck-err file"
  270. echo "ERROR: to force a new download of that file."
  271. rm -f "$lkfile" ; trap INT ; return 1
  272. fi
  273. # Questionable URL
  274. #
  275. if [ "$location" != "${location#\?}" ] ; then
  276. if [ "$tryques" = 0 ] ; then
  277. echo "ERROR: URL is marked as questionable." \
  278. "Not downloading this file."
  279. rm -f "$lkfile" ; trap INT ; return 1
  280. else
  281. echo "WARNING: URL is marked as questionable." \
  282. "Downloading it anyways."
  283. location="${location#\?}"
  284. fi
  285. fi
  286. # Make directory (if required)
  287. #
  288. if [ ! -d `dirname "$bzfile"` ] ; then
  289. mkdir -p `dirname "$bzfile"`
  290. fi
  291. # Alternative Directory
  292. #
  293. if [ -d "$altdir" ] ; then
  294. altfile=$(find -L "$altdir/" -name `basename $bzfile` | head -n 1)
  295. else
  296. altfile=
  297. fi
  298. if [ -s "$altfile" ] ; then
  299. echo "Found `basename $bzfile` as $altfile."
  300. case "$altcopy" in
  301. copy)
  302. cp "$altfile" "$bzfile" ;;
  303. move)
  304. mv "$altfile" "$bzfile" ;;
  305. *) #link
  306. cp -l "$altfile" "$bzfile" ;;
  307. esac
  308. gzfile="$bzfile"
  309. else
  310. # Mirroring
  311. #
  312. if [ -n "$mirror" -a "$mirror" != "none" -a "$mirror" != "broken" -a -z "${bzfile##download/mirror/*}" ] ; then
  313. # try to use mirror
  314. if ! download_file_now "!$mirror/${bzfile#download/mirror/}" $bzfile $bzfile; then
  315. echo "INFO: download from mirror failed, trying original URL."
  316. download_file_now "$location" $gzfile $bzfile ||
  317. downloaderror=1
  318. else
  319. gzfile="$bzfile"
  320. fi
  321. else
  322. # don't want to use mirror
  323. download_file_now "$location" $gzfile $bzfile ||
  324. downloaderror=1
  325. fi
  326. fi
  327. if [ ! -s "$gzfile" ]; then
  328. rm -f "$lkfile" ; trap INT ; return 1
  329. fi
  330. fi
  331. # unsign .gpg file
  332. if expr "$gzfile" : "*.gpg" > /dev/null; then
  333. gzfile=${gzfile%.gpg}
  334. if [ -f $gzfile.gpg ]; then
  335. echo "unsigning GnuPG file: $gzfile.gpg"
  336. gpg $gzfile.gpg
  337. fi
  338. if [ ! -f $gzfile ]; then
  339. echo "unsigning failed"
  340. rm -f "$lkfile" ; trap INT ; return 1
  341. fi
  342. fi
  343. sh ./lib/sde-download/validate.sh "$gzfile" "$bzfile" "$cksum" || downloaderror=1
  344. # Free Lock and finish
  345. #
  346. rm -f "$lkfile" ; trap INT ; return 0
  347. }
  348. # download_file_now location remote_filename local_filename
  349. #
  350. # This function executes the actual download using curl.
  351. #
  352. download_file_now() {
  353. local location="$1" gzfile="$2" bzfile="$3" curlret=0
  354. # Create URL
  355. #
  356. case "$location" in
  357. manual://*) url="$location" ;;
  358. !*) url="${location#!}" ;;
  359. *) url="${location%/*}/${gzfile##*/}" ;;
  360. esac
  361. # Download
  362. #
  363. case "$url" in
  364. manual://*)
  365. # Determine if the file has already been downloaded
  366. # manually. For this we first look in $HOME then in
  367. # download/manual.
  368. downloadpath=${altdir:-$HOME}
  369. downloadfile="${gzfile##*/}"
  370. if [ -e $downloadpath/$downloadfile ]; then
  371. location="file://$downloadpath/"
  372. else
  373. location="http://${url#manual://}"
  374. # No manual download has taken place yet.
  375. # So inform the user to do so.
  376. cat <<-EOT
  377. The file $downloadfile can not be fetched automatically
  378. please visit: $location
  379. and download it manually into $HOME or somewhere else using -alt-dir
  380. EOT
  381. return 1;
  382. fi
  383. # I am to lazy to do the copy and conversion myself,
  384. # so I use this function again with a modified
  385. # download location.
  386. download_file_now "$location" $gzfile $bzfile
  387. return "$?"
  388. ;;
  389. http://*|https://*|ftp://*|file://*)
  390. if [ -s "$gzfile.incomplete" ] ; then
  391. echo "INFO: Trying to resume previous download .."
  392. resume="-C -"
  393. else
  394. resume=
  395. fi
  396. if [ -s download/translations.sed ]; then
  397. trfile=download/translations.sed
  398. else
  399. trfile=etc/download.sed
  400. fi
  401. trurl="$( echo "$url" | sed -f $trfile )"
  402. if [ -n "$trurl" -a "$trurl" != "$url" ]; then
  403. echo "INFO: url translated."
  404. url="$trurl"
  405. fi
  406. unset trurl trfile
  407. curl -w '\rFinished downloading %{size_download} bytes in %{time_total} seconds (%{speed_download} bytes/sec). \n' --progress-bar $resume $curl_options "$url" -o "$gzfile.incomplete"
  408. curlret="$?"
  409. if [ "$resume" ] && \
  410. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  411. echo "INFO: Resuming download not possible. ->" \
  412. "Overwriting old file."
  413. rm -f "$gzfile.incomplete"
  414. curl -w '\rFinished downloading %{size_download} bytes in %{time_total} seconds (%{speed_download} bytes/sec). \n' --progress-bar $curl_options "$url" -o "$gzfile.incomplete"
  415. curlret="$?"
  416. fi
  417. if [ $curlret -ne 0 ] ; then
  418. case "$curlret" in
  419. 18)
  420. echo "WARNING: Got only some of the" \
  421. "file. A re-run of $0"
  422. echo "WARNING: is required to complete" \
  423. "the download." ;;
  424. 130)
  425. $ECHO_E '\rWARNING: CURL got a SIGINT' \
  426. "(someone pressed Ctrl-C). A re-run of"
  427. echo "WARNING: $0 is required to complete" \
  428. "the download." ; sleep 1 ;;
  429. *)
  430. echo "$curlret $gzfile $url" \
  431. >> tmp/Download-Errors
  432. $ECHO_E '\rERROR: CURL Returned Error' \
  433. "$curlret. Please read" \
  434. "the curl manpage." ;;
  435. esac
  436. return 1
  437. elif [ ! -s "$gzfile.incomplete" ] ; then
  438. echo "0 $gzfile $url" >> tmp/Download-Errors
  439. echo "ERROR: CURL returned success but" \
  440. "we have no data!"
  441. curlret=1
  442. else
  443. case "$gzfile" in
  444. *.gz|*.tgz)
  445. typeexpr="gzip compressed data" ;;
  446. *.bz2|*.tbz2|*.tbz)
  447. typeexpr="bzip2 compressed data" ;;
  448. *.Z|*.tZ)
  449. typeexpr="compress'd data" ;;
  450. *.zip|*.jar)
  451. typeexpr="Zip archive data" ;;
  452. *.tar)
  453. typeexpr="tar archive" ;;
  454. *)
  455. echo "WARNING: Unkown file extension: $gzfile"
  456. typeexpr="." ;;
  457. esac
  458. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  459. then
  460. echo "ERROR: File type does not match" \
  461. "filename ($typeexpr)!"
  462. mv "$gzfile.incomplete" "$gzfile.extck-err"
  463. else
  464. mv "$gzfile.incomplete" "$gzfile"
  465. fi
  466. fi
  467. ;;
  468. *)
  469. protocol="${url%%://*}"
  470. # we need to use $location - $url is already mangled above -ReneR
  471. # $protocol://$url $options
  472. url="`echo "$location" | sed "s,$protocol://\([^ ]*\).*,\1,"`"
  473. options="`echo "$location" | cut -d' ' -f2-`"
  474. case "$protocol" in
  475. cvs)
  476. # the first option is the module name
  477. module="${options%% *}"
  478. options="${options#* }"
  479. cmdline="cvs -z4 -Q -d $url co -P $options $module"
  480. # sometimes cvs wants to read ~/.cvspass just for fun ..
  481. touch $HOME/.cvspass
  482. ;;
  483. svn|svn\+http)
  484. if [ "$protocol" = "svn+http" ]; then
  485. url="http://$url"
  486. else
  487. url="svn://$url"
  488. fi
  489. if [ "${options:0:1}" = "-" ]; then
  490. # the module is the last dir of $url
  491. module="${url##*/}"
  492. else
  493. # the first option is the module name
  494. module="${options%% *}"
  495. options="${options#* }"
  496. fi
  497. cmdline="svn co $options $url $module"
  498. ;;
  499. *)
  500. echo "$cmdclient unrecognized!"
  501. return 1
  502. ;;
  503. esac
  504. cvsdir="tmp/down.${protocol}dir.`echo $bzfile | tr / -`"
  505. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  506. echo "$cmdline"
  507. {
  508. $cmdline || touch .cvs_error
  509. } &> .cvs_output &
  510. while fuser .cvs_output &> /dev/null ; do
  511. $ECHO_E -n `nice du -sh 2> /dev/null | \
  512. cut -f1` 'downloaded from archive so far...\r'
  513. sleep 3
  514. done
  515. if [ -f .cvs_error ] ; then
  516. cd $saved_pwd ; rm -rf $cvsdir
  517. $ECHO_E "\nError during checkout."
  518. return 1
  519. fi
  520. echo `du -sh 2> /dev/null | \
  521. cut -f1` 'downloaded from archive (download finished).'
  522. if [ `echo * | wc -w` -gt 1 ]; then
  523. # multi-module module
  524. echo "Multi-module package detected, relocating..."
  525. mkdir t2-module.$$
  526. for x in *; do
  527. [ "$x" != "t2-module.$$" ] && mv -f $x t2-module.$$/
  528. done
  529. mkdir -p "$module"
  530. mv -f t2-module.$$/* "$module"
  531. rm -f t2-module.$$
  532. fi
  533. cd `dirname $module`
  534. tarname="`basename $bzfile`"
  535. echo "Preparing files for final tarball ..."
  536. find -type d \( -name CVS -o -name .svn \) | xargs rm -rf
  537. if [ `find -type f | wc -l` -gt 4 ]; then
  538. find `basename $module` | xargs touch -t 200001010000
  539. tar --owner root --group root \
  540. --use-compress-program=bzip2 \
  541. -cf $tarname `basename $module`
  542. mv $tarname $saved_pwd/$bzfile
  543. else
  544. echo "Too few files - assuming checkout failure."
  545. curlret=1
  546. fi
  547. cd $saved_pwd ; rm -rf $cvsdir
  548. ;;
  549. esac
  550. return $curlret
  551. }
  552. list_dtags() {
  553. {
  554. grep -H '^\[D\] ' package/*/*/*.desc
  555. grep -H '^[X0-9]' target/*/download.txt 2> /dev/null | sed 's,:,:[D] ,'
  556. } | column_clean
  557. }
  558. list_cksums() {
  559. trap '' INT
  560. # we know we only have single spaces due to list_dtags' column_clean
  561. list_dtags | sed -n \
  562. -e 's,[^ ]* \([X0-9]*\) \(.\)\([^ ]*\) -.*,\1 download/local/\2/\2\3,p' \
  563. -e 's,[^ ]* \([X0-9]*\) \(.\)\([^ ]*\) [^-].*,\1 download/mirror/\2/\2\3,p'
  564. trap INT
  565. }
  566. list() {
  567. trap '' INT
  568. list_cksums | cut -f2- -d' '
  569. trap INT
  570. }
  571. list_missing() {
  572. trap '' INT
  573. list | bz2filename | \
  574. while read fn ; do
  575. [ -f "$fn" ] || echo "$fn"
  576. done
  577. trap INT
  578. }
  579. repository() {
  580. for repository ; do
  581. packages `echo package/$repository/*/*.desc`
  582. done
  583. }
  584. required() {
  585. # Choosen config must exist
  586. #
  587. if ! ./lib/sde-config/migrate.sh "$config"; then
  588. echo "ERROR: Config $config doesn't exist."
  589. echo "ERROR: try ./scripts/Config -cfg $config first."
  590. exit 1
  591. fi
  592. while read on a b repo pkg c ; do
  593. if [ "$on" = "X" ] ; then
  594. download_file_desc "$repo" "$pkg"
  595. fi
  596. done < config/$config/packages
  597. target=`grep '^export SDECFG_TARGET=' config/$config/config | \
  598. cut -f2 -d= | tr -d "'"`
  599. targetchain="$target"; x="$target"
  600. while [ -f "target/$x/extends" ]; do
  601. x="`cat target/$x/extends`"
  602. targetchain="$targetchain $x"
  603. done
  604. for target in $targetchain; do
  605. if [ -f target/$target/download.txt ] ; then
  606. download_file_pipe "$target" < target/$target/download.txt
  607. fi
  608. done
  609. }
  610. all() {
  611. local each repo pkg
  612. for repo in $( cd package; ls -1 ); do
  613. for each in package/$repo/*/*.desc; do
  614. pkg="`echo $each | cut -f3 -d/`"
  615. download_file_desc "$repo" "$pkg"
  616. done
  617. done
  618. for each in $( ls -1 target/*/download.txt 2> /dev/null ); do
  619. target="`echo $each | cut -f2 -d/`"
  620. download_file_pipe "$target" < "$each"
  621. done
  622. }
  623. package() {
  624. descfile="`echo package/*/$1/$1.desc`"
  625. if [ ! -f $descfile ]; then
  626. echo "Skipping \"$1\" (not found)!"
  627. return
  628. fi
  629. pkg="`echo $descfile | cut -f3 -d/`"
  630. repo="`echo $descfile | cut -f2 -d/`"
  631. download_file_desc "$repo" "$pkg"
  632. }
  633. packages() {
  634. local descfile
  635. for arg; do
  636. case "$arg" in
  637. target/*)
  638. if [ ! -f $arg ]; then
  639. echo "Skipping \"$arg\" (not found)!"
  640. continue
  641. fi
  642. target="`echo $arg | cut -f2 -d/`"
  643. download_file_pipe "$target" < "$arg"
  644. ;;
  645. *)
  646. if [ "${arg%.desc}" != "$arg" ]; then
  647. arg="`echo $arg | cut -f3 -d/`"; fi
  648. # active extensions
  649. local extender=
  650. # pkg_*_{pre,post}.conf is only activated if extender
  651. # is enabled on $config/packages, so we will only
  652. # download files of those extenders
  653. #
  654. for extender in `ls -1 package/*/*/pkg_${arg}_{pre,post}.conf 2> /dev/null |
  655. cut -d/ -f3 | sort -u`; do
  656. if grep -q "^X .* $extender " \
  657. config/$config/packages; then
  658. echo_info "Also downloading $extender ..."
  659. package $extender
  660. fi
  661. done
  662. package $arg
  663. ;;
  664. esac
  665. done
  666. }
  667. set +e
  668. # Things to do only for downloading
  669. #
  670. if [ "${1:0:5}" != "-list" -a $checkonly = 0 ]; then
  671. # we need curl
  672. if [ -z "`type -p curl`" ]; then
  673. echo_abort 2 "we need \`curl\` installed and available on \$PATH to proceed."
  674. fi
  675. # do mirror detection, only once
  676. [ $this_is_the_2nd_run = 1 ] || detect_mirror
  677. fi
  678. case "$1" in
  679. -list) list ;;
  680. -list-missing) list_missing ;;
  681. -list-cksums) list_cksums ;;
  682. -required) required ;;
  683. -all) all ;;
  684. -repository) shift ; repository "$@" ;;
  685. -*|"") download_usage
  686. exit 1;;
  687. *) packages "$@" ;;
  688. esac
  689. exit $downloaderr