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 - 2008 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 local-filename download-location cksum repo pkg
  190. #
  191. # This function decides if download directly or from a mirror,
  192. # validates checksum, etc.
  193. # Calls download_file_now to do the actual download.
  194. #
  195. download_file() {
  196. # Init
  197. #
  198. local gzfile="$1" location="$2" cksum="$3" repo="$4" pkg="$5"
  199. # Make src directory for creating tar balls
  200. mkdir -p tmp/
  201. # Tarball file name:
  202. bzfile="`bz2filename "$gzfile"`"
  203. # Remove optional '-' prefix from $location
  204. [ "${location:0:1}" = '-' ] && location="${location:1}"
  205. # Lock file name:
  206. lkfile="tmp/down.lockfile.`echo $bzfile | tr / -`"
  207. # Check if it's already there
  208. #
  209. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  210. # Make locking
  211. #
  212. if [ -s "$lkfile" ]; then
  213. echo "Found $lkfile -> skip download."
  214. return 0
  215. fi
  216. trap 'rm -f "$lkfile"' INT
  217. echo $$ > "$lkfile"
  218. # Check if we only like to test the cksum(s)
  219. #
  220. if [ $checkonly = 1 ] ; then
  221. gzfile="$bzfile"
  222. if [ ! -f "$bzfile" ] ; then
  223. echo "File missing: $bzfile"
  224. rm -f "$lkfile" ; trap INT ; return 1
  225. fi
  226. if [ -z "${cksum##X*}" ] ; then
  227. echo "No checksum (ignore): $bzfile"
  228. rm -f "$lkfile" ; trap INT ; return 1
  229. fi
  230. if [ "$cksum" -eq 0 ] ; then
  231. echo "No checksum (missing): $bzfile"
  232. rm -f "$lkfile" ; trap INT ; return 1
  233. fi
  234. elif [ -s "$gzfile" ] ; then
  235. echo ; echo "Already downloaded $pkg:$gzfile ..."
  236. else
  237. echo ; echo "Downloading $pkg:$gzfile ..."
  238. # Existing *.cksum-err
  239. #
  240. if [ -s "$gzfile.cksum-err" ] ; then
  241. # cksum-err file alread exists:
  242. echo "ERROR: Found $gzfile.cksum-err."
  243. echo "ERROR: That means that we downloaded the" \
  244. "file already and it had an"
  245. echo "ERROR: incorrect checksum. Remove the" \
  246. "*.cksum-err file to force a"
  247. echo "ERROR: new download of that file."
  248. rm -f "$lkfile" ; trap INT ; return 1
  249. fi
  250. # Existing *.extck-err
  251. #
  252. if [ -s "$gzfile.extck-err" ] ; then
  253. # extck-err file alread exists:
  254. echo "ERROR: Found $gzfile.extck-err."
  255. echo "ERROR: That means that we downloaded the" \
  256. "file already and it's content"
  257. echo "ERROR: did not match it's filename extension." \
  258. "Remove the *.extck-err file"
  259. echo "ERROR: to force a new download of that file."
  260. rm -f "$lkfile" ; trap INT ; return 1
  261. fi
  262. # Questionable URL
  263. #
  264. if [ "$location" != "${location#\?}" ] ; then
  265. if [ "$tryques" = 0 ] ; then
  266. echo "ERROR: URL is marked as questionable." \
  267. "Not downloading this file."
  268. rm -f "$lkfile" ; trap INT ; return 1
  269. else
  270. echo "WARNING: URL is marked as questionable." \
  271. "Downloading it anyways."
  272. location="${location#\?}"
  273. fi
  274. fi
  275. # Make directory (if required)
  276. #
  277. if [ ! -d `dirname "$bzfile"` ] ; then
  278. mkdir -p `dirname "$bzfile"`
  279. fi
  280. # Alternative Directory
  281. #
  282. if [ -d "$altdir" ] ; then
  283. altfile=$(find -L "$altdir/" -name `basename $bzfile` | head -n 1)
  284. else
  285. altfile=
  286. fi
  287. if [ -s "$altfile" ] ; then
  288. echo "Found `basename $bzfile` as $altfile."
  289. case "$altcopy" in
  290. copy)
  291. cp "$altfile" "$bzfile" ;;
  292. move)
  293. mv "$altfile" "$bzfile" ;;
  294. *) #link
  295. cp -l "$altfile" "$bzfile" ;;
  296. esac
  297. gzfile="$bzfile"
  298. else
  299. # Mirroring
  300. #
  301. if [ -n "$mirror" -a "$mirror" != "none" -a "$mirror" != "broken" -a -z "${bzfile##download/mirror/*}" ] ; then
  302. # try to use mirror
  303. if ! download_file_now "!$mirror/${bzfile#download/mirror/}" $bzfile $bzfile; then
  304. echo "INFO: download from mirror failed, trying original URL."
  305. download_file_now "$location" $gzfile $bzfile ||
  306. downloaderror=1
  307. else
  308. gzfile="$bzfile"
  309. fi
  310. else
  311. # don't want to use mirror
  312. download_file_now "$location" $gzfile $bzfile ||
  313. downloaderror=1
  314. fi
  315. fi
  316. if [ ! -s "$gzfile" ]; then
  317. rm -f "$lkfile" ; trap INT ; return 1
  318. fi
  319. fi
  320. # unsign .gpg file
  321. if expr "$gzfile" : "*.gpg" > /dev/null; then
  322. gzfile=${gzfile%.gpg}
  323. if [ -f $gzfile.gpg ]; then
  324. echo "unsigning GnuPG file: $gzfile.gpg"
  325. gpg $gzfile.gpg
  326. fi
  327. if [ ! -f $gzfile ]; then
  328. echo "unsigning failed"
  329. rm -f "$lkfile" ; trap INT ; return 1
  330. fi
  331. fi
  332. sh ./lib/sde-download/validate.sh "$gzfile" "$bzfile" "$cksum" || downloaderror=1
  333. # Free Lock and finish
  334. #
  335. rm -f "$lkfile" ; trap INT ; return 0
  336. }
  337. # download_file_now location remote_filename local_filename
  338. #
  339. # This function executes the actual download using curl.
  340. #
  341. download_file_now() {
  342. local location="$1" gzfile="$2" bzfile="$3" curlret=0
  343. # Create URL
  344. #
  345. case "$location" in
  346. manual://*) url="$location" ;;
  347. !*) url="${location#!}" ;;
  348. *) url="${location%/*}/${gzfile##*/}" ;;
  349. esac
  350. # Download
  351. #
  352. case "$url" in
  353. manual://*)
  354. # Determine if the file has already been downloaded
  355. # manually. For this we first look in $HOME then in
  356. # download/manual.
  357. downloadpath=${altdir:-$HOME}
  358. downloadfile="${gzfile##*/}"
  359. if [ -e $downloadpath/$downloadfile ]; then
  360. location="file://$downloadpath/"
  361. else
  362. location="http://${url#manual://}"
  363. # No manual download has taken place yet.
  364. # So inform the user to do so.
  365. cat <<-EOT
  366. The file $downloadfile can not be fetched automatically
  367. please visit: $location
  368. and download it manually into $HOME or somewhere else using -alt-dir
  369. EOT
  370. return 1;
  371. fi
  372. # I am to lazy to do the copy and conversion myself,
  373. # so I use this function again with a modified
  374. # download location.
  375. download_file_now "$location" $gzfile $bzfile
  376. return "$?"
  377. ;;
  378. http://*|https://*|ftp://*|file://*)
  379. if [ -s "$gzfile.incomplete" ] ; then
  380. echo "INFO: Trying to resume previous download .."
  381. resume="-C -"
  382. else
  383. resume=
  384. fi
  385. if [ -s download/translations.sed ]; then
  386. trfile=download/translations.sed
  387. else
  388. trfile=etc/download.sed
  389. fi
  390. trurl="$( echo "$url" | sed -f $trfile )"
  391. if [ -n "$trurl" -a "$trurl" != "$url" ]; then
  392. echo "INFO: url translated."
  393. url="$trurl"
  394. fi
  395. unset trurl trfile
  396. 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"
  397. curlret="$?"
  398. if [ "$resume" ] && \
  399. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  400. echo "INFO: Resuming download not possible. ->" \
  401. "Overwriting old file."
  402. rm -f "$gzfile.incomplete"
  403. curl -w '\rFinished downloading %{size_download} bytes in %{time_total} seconds (%{speed_download} bytes/sec). \n' --progress-bar $curl_options "$url" -o "$gzfile.incomplete"
  404. curlret="$?"
  405. fi
  406. if [ $curlret -ne 0 ] ; then
  407. case "$curlret" in
  408. 18)
  409. echo "WARNING: Got only some of the" \
  410. "file. A re-run of $0"
  411. echo "WARNING: is required to complete" \
  412. "the download." ;;
  413. 130)
  414. $ECHO_E '\rWARNING: CURL got a SIGINT' \
  415. "(someone pressed Ctrl-C). A re-run of"
  416. echo "WARNING: $0 is required to complete" \
  417. "the download." ; sleep 1 ;;
  418. *)
  419. echo "$curlret $gzfile $url" \
  420. >> tmp/Download-Errors
  421. $ECHO_E '\rERROR: CURL Returned Error' \
  422. "$curlret. Please read" \
  423. "the curl manpage." ;;
  424. esac
  425. return 1
  426. elif [ ! -s "$gzfile.incomplete" ] ; then
  427. echo "0 $gzfile $url" >> tmp/Download-Errors
  428. echo "ERROR: CURL returned success but" \
  429. "we have no data!"
  430. curlret=1
  431. else
  432. case "$gzfile" in
  433. *.gz|*.tgz)
  434. typeexpr="gzip compressed data" ;;
  435. *.bz2|*.tbz2|*.tbz)
  436. typeexpr="bzip2 compressed data" ;;
  437. *.Z|*.tZ)
  438. typeexpr="compress'd data" ;;
  439. *.zip|*.jar)
  440. typeexpr="Zip archive data" ;;
  441. *.tar)
  442. typeexpr="tar archive" ;;
  443. *)
  444. echo "WARNING: Unkown file extension: $gzfile"
  445. typeexpr="." ;;
  446. esac
  447. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  448. then
  449. echo "ERROR: File type does not match" \
  450. "filename ($typeexpr)!"
  451. mv "$gzfile.incomplete" "$gzfile.extck-err"
  452. else
  453. mv "$gzfile.incomplete" "$gzfile"
  454. fi
  455. fi
  456. ;;
  457. *)
  458. protocol="${url%%://*}"
  459. # we need to use $location - $url is already mangled above -ReneR
  460. # $protocol://$url $options
  461. url="`echo "$location" | sed "s,$protocol://\([^ ]*\).*,\1,"`"
  462. options="`echo "$location" | cut -d' ' -f2-`"
  463. case "$protocol" in
  464. cvs)
  465. # the first option is the module name
  466. module="${options%% *}"
  467. options="${options#* }"
  468. cmdline="cvs -z4 -Q -d $url co -P $options $module"
  469. # sometimes cvs wants to read ~/.cvspass just for fun ..
  470. touch $HOME/.cvspass
  471. ;;
  472. svn|svn\+http)
  473. if [ "$protocol" = "svn+http" ]; then
  474. url="http://$url"
  475. else
  476. url="svn://$url"
  477. fi
  478. if [ "${options:0:1}" = "-" ]; then
  479. # the module is the last dir of $url
  480. module="${url##*/}"
  481. else
  482. # the first option is the module name
  483. module="${options%% *}"
  484. options="${options#* }"
  485. fi
  486. cmdline="svn co $options $url $module"
  487. ;;
  488. *)
  489. echo "$cmdclient unrecognized!"
  490. return 1
  491. ;;
  492. esac
  493. cvsdir="tmp/down.${protocol}dir.`echo $bzfile | tr / -`"
  494. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  495. echo "$cmdline"
  496. {
  497. $cmdline || touch .cvs_error
  498. } &> .cvs_output &
  499. while fuser .cvs_output &> /dev/null ; do
  500. $ECHO_E -n `nice du -sh 2> /dev/null | \
  501. cut -f1` 'downloaded from archive so far...\r'
  502. sleep 3
  503. done
  504. if [ -f .cvs_error ] ; then
  505. cd $saved_pwd ; rm -rf $cvsdir
  506. $ECHO_E "\nError during checkout."
  507. return 1
  508. fi
  509. echo `du -sh 2> /dev/null | \
  510. cut -f1` 'downloaded from archive (download finished).'
  511. if [ `echo * | wc -w` -gt 1 ]; then
  512. # multi-module module
  513. echo "Multi-module package detected, relocating..."
  514. mkdir t2-module.$$
  515. for x in *; do
  516. [ "$x" != "t2-module.$$" ] && mv -f $x t2-module.$$/
  517. done
  518. mkdir -p "$module"
  519. mv -f t2-module.$$/* "$module"
  520. rm -f t2-module.$$
  521. fi
  522. cd `dirname $module`
  523. tarname="`basename $bzfile`"
  524. echo "Preparing files for final tarball ..."
  525. find -type d \( -name CVS -o -name .svn \) | xargs rm -rf
  526. if [ `find -type f | wc -l` -gt 4 ]; then
  527. find `basename $module` | xargs touch -t 200001010000
  528. tar --owner root --group root \
  529. --use-compress-program=bzip2 \
  530. -cf $tarname `basename $module`
  531. mv $tarname $saved_pwd/$bzfile
  532. else
  533. echo "Too few files - assuming checkout failure."
  534. curlret=1
  535. fi
  536. cd $saved_pwd ; rm -rf $cvsdir
  537. ;;
  538. esac
  539. return $curlret
  540. }
  541. list_dtags() {
  542. {
  543. grep -H '^\[D\] ' package/*/*/*.desc
  544. grep -H '^[X0-9]' target/*/download.txt 2> /dev/null | sed 's,:,:[D] ,'
  545. } | column_clean
  546. }
  547. list_cksums() {
  548. trap '' INT
  549. # we know we only have single spaces due to list_dtags' column_clean
  550. list_dtags | sed -n \
  551. -e 's,[^ ]* \([X0-9]*\) \(.\)\([^ ]*\) -.*,\1 download/local/\2/\2\3,p' \
  552. -e 's,[^ ]* \([X0-9]*\) \(.\)\([^ ]*\) [^-].*,\1 download/mirror/\2/\2\3,p'
  553. trap INT
  554. }
  555. list() {
  556. trap '' INT
  557. list_cksums | cut -f2- -d' '
  558. trap INT
  559. }
  560. list_missing() {
  561. trap '' INT
  562. list | bz2filename | \
  563. while read fn ; do
  564. [ -f "$fn" ] || echo "$fn"
  565. done
  566. trap INT
  567. }
  568. repository() {
  569. for repository ; do
  570. packages `echo package/$repository/*/*.desc`
  571. done
  572. }
  573. required() {
  574. # Choosen config must exist
  575. #
  576. if ! ./lib/sde-config/migrate.sh "$config"; then
  577. echo "ERROR: Config $config doesn't exist."
  578. echo "ERROR: try ./scripts/Config -cfg $config first."
  579. exit 1
  580. fi
  581. while read on a b repo pkg c ; do
  582. if [ "$on" = "X" ] ; then
  583. grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc > tmp/down.$$.lst
  584. while read tag cksum file url ; do
  585. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$repo" "$pkg"
  586. done < tmp/down.$$.lst ; rm -f tmp/down.$$.lst
  587. fi
  588. done < config/$config/packages
  589. target=`grep '^export SDECFG_TARGET=' config/$config/config | \
  590. cut -f2 -d= | tr -d "'"`
  591. targetchain="$target"; x="$target"
  592. while [ -f "target/$x/extends" ]; do
  593. x="`cat target/$x/extends`"
  594. targetchain="$targetchain $x"
  595. done
  596. for target in $targetchain; do
  597. if [ -f target/$target/download.txt ] ; then
  598. while read cksum file url ; do
  599. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$target"
  600. done < target/$target/download.txt
  601. fi
  602. done
  603. }
  604. all() {
  605. local each repo pkg
  606. for repo in $( cd package; ls -1 ); do
  607. for each in package/$repo/*/*.desc; do
  608. pkg="`echo $each | cut -f3 -d/`"
  609. while read tag cksum file url ; do
  610. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$repo" "$pkg"
  611. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  612. done
  613. done
  614. for each in $( ls -1 target/*/download.txt 2> /dev/null ); do
  615. target="`echo $each | cut -f2 -d/`"
  616. while read cksum file url ; do
  617. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$target"
  618. done < <(cat $each)
  619. done
  620. }
  621. package() {
  622. descfile="`echo package/*/$1/$1.desc`"
  623. if [ ! -f $descfile ]; then
  624. echo "Skipping \"$1\" (not found)!"
  625. return
  626. fi
  627. pkg="`echo $descfile | cut -f3 -d/`"
  628. repo="`echo $descfile | cut -f2 -d/`"
  629. while read tag cksum file url ; do
  630. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$repo" "$pkg"
  631. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  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. while read cksum file url ; do
  644. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$target"
  645. done < <(cat $arg)
  646. ;;
  647. *)
  648. if [ "${arg%.desc}" != "$arg" ]; then
  649. arg="`echo $arg | cut -f3 -d/`"; fi
  650. # active extensions
  651. local extender=
  652. # pkg_*_{pre,post}.conf is only activated if extender
  653. # is enabled on $config/packages, so we will only
  654. # download files of those extenders
  655. #
  656. for extender in `ls -1 package/*/*/pkg_${arg}_{pre,post}.conf 2> /dev/null |
  657. cut -d/ -f3 | sort -u`; do
  658. if grep -q "^X .* $extender " \
  659. config/$config/packages; then
  660. echo_info "Also downloading $extender ..."
  661. package $extender
  662. fi
  663. done
  664. package $arg
  665. ;;
  666. esac
  667. done
  668. }
  669. set +e
  670. # Things to do only for downloading
  671. #
  672. if [ "${1:0:5}" != "-list" -a $checkonly = 0 ]; then
  673. # we need curl
  674. if [ -z "`type -p curl`" ]; then
  675. echo_abort 2 "we need \`curl\` installed and available on \$PATH to proceed."
  676. fi
  677. # do mirror detection, only once
  678. [ $this_is_the_2nd_run = 1 ] || detect_mirror
  679. fi
  680. case "$1" in
  681. -list) list ;;
  682. -list-missing) list_missing ;;
  683. -list-cksums) list_cksums ;;
  684. -required) required ;;
  685. -all) all ;;
  686. -repository) shift ; repository "$@" ;;
  687. -*|"") download_usage
  688. exit 1;;
  689. *) packages "$@" ;;
  690. esac
  691. exit $downloaderr