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.

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