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.

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