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.

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