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.

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