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.

834 lines
21 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 - 2007 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 -mk-cksum Filename(s)
  39. sde download [ -list | -list-unknown | -list-missing | -list-cksums ]
  40. See '-mirror none' output for help on bypassing the official mirrors.
  41. EOT
  42. }
  43. umask 022
  44. cd "$SDEROOT"
  45. # -mk-cksum mode (display OpenSDE type package checksum): it
  46. # displays the checksum OpenSDE validates against.
  47. #
  48. # Currently bz2, tbz2, gz, tgz, Z are unpacked
  49. #
  50. if [ "$1" = -mk-cksum ] ; then
  51. shift
  52. exec sh ./lib/sde-download/cksum.sh "$@"
  53. fi
  54. # Handle options passed on the command line
  55. #
  56. mkdir -p tmp/ download/
  57. # Load system wide configuration for this tool
  58. #
  59. config=default mirror= altdir= proxy= proxyauth=
  60. if [ -s "$SDESETTINGS" ]; then
  61. eval $( $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" download )
  62. eval $( $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" download-$sdever )
  63. fi
  64. this_is_the_2nd_run=0
  65. checkonly=0 tryques=0 nocheck=0 notimeout=0
  66. options='-this_is_the_2nd_run '
  67. curl_options='-A opensde-downloader --disable-epsv --location -f'
  68. altcopy=link ; verbose=1
  69. downloaderror=0
  70. #
  71. while [ $# -gt 0 ]; do
  72. case "$1" in
  73. -this_is_the_2nd_run)
  74. this_is_the_2nd_run=1
  75. ;;
  76. -cfg)
  77. options="$options -cfg $2"
  78. config="$2" ; shift ;;
  79. -q)
  80. options="$options -q"
  81. verbose=0 ;;
  82. -nock)
  83. # -nock skips checksum checking (don't use lightly)
  84. options="$options -nock"
  85. nocheck=1 ; shift ;;
  86. -mirror)
  87. # -mirror uses a mirror for finding source files
  88. if [ "$2" = none ]; then
  89. echo
  90. echo "The option '-mirror none' is not supported anymore!"
  91. echo
  92. echo "You may edit \$HOME/.sde/settings if you really"
  93. echo "want to use the original download resources. However, this"
  94. echo "is not supported and if such a download fails, this is not"
  95. echo "a bug in the OpenSDE and doesn't neccessarily needs fixing."
  96. echo
  97. exit 1;
  98. elif [ "$2" = auto ]; then
  99. mirror=
  100. else
  101. options="$options -mirror $2"
  102. mirror="$2"
  103. $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" "download-$sdever.mirror=$mirror"
  104. fi
  105. shift ;;
  106. -check)
  107. # -check just validates the file using the checksum
  108. options="$options -check"
  109. checkonly=1 ;;
  110. -notimeout)
  111. # don't add timeout curl options
  112. options="$options -notimeout"
  113. notimeout=2 ;;
  114. -longtimeout)
  115. # don't add timeout curl options
  116. options="$options -longtimeout"
  117. notimeout=1 ;;
  118. -curl-opt)
  119. # additional curl options
  120. options="$options -curl-opt $2"
  121. curl_options="$curl_options `echo $2 | tr : ' '`"
  122. shift ;;
  123. -alt-dir)
  124. # check for an alternative directory where to search for
  125. # package source tarballs
  126. altdir=$( cd $2; pwd -P )
  127. options="$options -alt-dir $2"
  128. shift ;;
  129. -try-questionable)
  130. # also try to download questionable URLs
  131. options="$options -try-questionable"
  132. tryques=1 ;;
  133. -move) altcopy=move ;;
  134. -copy) altcopy=copy ;;
  135. *) break ;;
  136. esac
  137. shift
  138. done
  139. if [ $notimeout -eq 0 ] ; then
  140. curl_options="$curl_options -y 10 -Y 10 --connect-timeout 60"
  141. fi
  142. if [ $notimeout -eq 1 ] ; then
  143. curl_options="$curl_options -y 60 -Y 1 --connect-timeout 300"
  144. fi
  145. # proxy (server[:port])
  146. if [ -n "$proxy" ]; then
  147. curl_options="$curl_options --proxy $proxy"
  148. # proxy needs auth (username[:password])
  149. [ -z "$proxyauth" ] || curl_options="$curl_options --proxy-user $proxyauth"
  150. # only show once
  151. [ $this_is_the_2nd_run = 1 ] || echo_info "Using <$proxy> as ${proxyauth:+authenticated }http proxy."
  152. fi
  153. #Disable checking for certificates on https downloads
  154. curl_options="$curl_options -k"
  155. # Autodetect best Mirror and safe url in $mirror
  156. #
  157. detect_mirror() {
  158. if [ "$mirror" = "none" ] ; then
  159. echo_info "Using original download locations only."
  160. return
  161. elif [ "$mirror" = "broken" ]; then
  162. echo_warning "Previous detection of the mirror failed, trying again."
  163. elif [ -n "$mirror" ]; then
  164. echo_info "Using mirror <$mirror>."
  165. return
  166. fi
  167. echo_warning "Auto-detecting best mirror ..."
  168. echo_info "Downloading mirror-list from opensde.net."
  169. curl -s -S $curl_options -o tmp/Download-Mirror-List \
  170. "http://opensde.net/opensde-download-mirrors/$sdever"
  171. if [ -r tmp/Download-Mirror-List ]; then
  172. bash lib/sde-download/mirror-test.sh < tmp/Download-Mirror-List
  173. fi 2>&1 | echo_info
  174. # read new mirror info
  175. mirror=
  176. eval $( $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" download-$sdever )
  177. if [ -z "$mirror" ]; then
  178. echo_error "Mirror detection loop hit a bug!"
  179. elif [ "$mirror" == "broken" ]; then
  180. echo_warning "No Mirror Found!"
  181. else
  182. echo_info "Using mirror <$mirror>."
  183. fi
  184. }
  185. # download_file local-filename download-location cksum repo pkg
  186. #
  187. # This function decides if download directly or from a mirror,
  188. # validates checksum, etc.
  189. # Calls download_file_now to do the actual download.
  190. #
  191. download_file() {
  192. # Init
  193. #
  194. local gzfile="$1" location="$2" cksum="$3" repo="$4" pkg="$5"
  195. # Make src directory for creating tar balls
  196. mkdir -p tmp/
  197. # Tarball file name:
  198. bzfile="`bz2filename "$gzfile"`"
  199. # Remove optional '-' prefix from $location
  200. [ "${location:0:1}" == '-' ] && location="${location:1}"
  201. # Lock file name:
  202. lkfile="tmp/down.lockfile.`echo $bzfile | tr / -`"
  203. # Check if it's already there
  204. #
  205. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  206. # Make locking
  207. #
  208. if [ -s "$lkfile" ]; then
  209. echo "Found $lkfile -> skip download."
  210. return 0
  211. fi
  212. trap 'rm -f "$lkfile"' INT
  213. echo $$ > "$lkfile"
  214. # Check if we only like to test the cksum(s)
  215. #
  216. if [ $checkonly = 1 ] ; then
  217. gzfile="$bzfile"
  218. if [ ! -f "$bzfile" ] ; then
  219. echo "File missing: $bzfile"
  220. rm -f "$lkfile" ; trap INT ; return 1
  221. fi
  222. if [ -z "${cksum##X*}" ] ; then
  223. echo "No checksum (ignore): $bzfile"
  224. rm -f "$lkfile" ; trap INT ; return 1
  225. fi
  226. if [ "$cksum" -eq 0 ] ; then
  227. echo "No checksum (missing): $bzfile"
  228. rm -f "$lkfile" ; trap INT ; return 1
  229. fi
  230. elif [ -s "$gzfile" ] ; then
  231. echo ; echo "Already downloaded $pkg:$gzfile ..."
  232. else
  233. echo ; echo "Downloading $pkg:$gzfile ..."
  234. # Existing *.cksum-err
  235. #
  236. if [ -s "$gzfile.cksum-err" ] ; then
  237. # cksum-err file alread exists:
  238. echo "ERROR: Found $gzfile.cksum-err."
  239. echo "ERROR: That means that we downloaded the" \
  240. "file already and it had an"
  241. echo "ERROR: incorrect checksum. Remove the" \
  242. "*.cksum-err file to force a"
  243. echo "ERROR: new download of that file."
  244. rm -f "$lkfile" ; trap INT ; return 1
  245. fi
  246. # Existing *.extck-err
  247. #
  248. if [ -s "$gzfile.extck-err" ] ; then
  249. # extck-err file alread exists:
  250. echo "ERROR: Found $gzfile.extck-err."
  251. echo "ERROR: That means that we downloaded the" \
  252. "file already and it's content"
  253. echo "ERROR: did not match it's filename extension." \
  254. "Remove the *.extck-err file"
  255. echo "ERROR: to force a new download of that file."
  256. rm -f "$lkfile" ; trap INT ; return 1
  257. fi
  258. # Questionable URL
  259. #
  260. if [ "$location" != "${location#\?}" ] ; then
  261. if [ "$tryques" = 0 ] ; then
  262. echo "ERROR: URL is marked as questionable." \
  263. "Not downloading this file."
  264. rm -f "$lkfile" ; trap INT ; return 1
  265. else
  266. echo "WARNING: URL is marked as questionable." \
  267. "Downloading it anyways."
  268. location="${location#\?}"
  269. fi
  270. fi
  271. # Make directory (if required)
  272. #
  273. if [ ! -d `dirname "$bzfile"` ] ; then
  274. mkdir -p `dirname "$bzfile"`
  275. fi
  276. # Alternative Directory
  277. #
  278. if [ "$altdir" ] ; then
  279. altfile=$(find $altdir/ -name `basename $bzfile` | head -n 1)
  280. else
  281. altfile=""
  282. fi
  283. #FIXME: compatibility, can be removed sooner or later...
  284. # Check old download dir layout
  285. if [ -z "$altfile" ]; then
  286. if [ -f "download/$repo${pkg:+/}$pkg/`basename $bzfile`" ]; then
  287. altfile="download/$repo${pkg:+/}$pkg/`basename $bzfile`"
  288. fi
  289. fi
  290. if [ "$altfile" ] ; then
  291. echo "Found `basename $bzfile` as $altfile."
  292. if [ "$altcopy" = 'link' ]; then
  293. cp -lv $altfile $bzfile
  294. elif [ "$altcopy" = 'copy' ]; then
  295. cp -v $altfile $bzfile
  296. elif [ "$altcopy" = 'move' ]; then
  297. mv -v $altfile $bzfile
  298. fi
  299. gzfile="$bzfile"
  300. else
  301. # Mirroring
  302. #
  303. if [ -n "$mirror" -a "$mirror" != "none" -a "$mirror" != "broken" -a -z "${bzfile##download/mirror/*}" ] ; then
  304. # try to use mirror
  305. if ! download_file_now "!$mirror/${bzfile#download/mirror/}" $bzfile $bzfile; then
  306. echo "INFO: download from mirror failed, trying original URL."
  307. download_file_now "$location" $gzfile $bzfile \
  308. || downloaderror=1
  309. else
  310. gzfile="$bzfile"
  311. fi
  312. else
  313. # don't want to use mirror
  314. download_file_now "$location" $gzfile $bzfile \
  315. downloaderror=1
  316. fi
  317. fi
  318. if [ ! -s "$gzfile" ]; then
  319. rm -f "$lkfile" ; trap INT ; return 1
  320. fi
  321. fi
  322. # unsign .gpg file
  323. if [[ $gzfile = *.gpg ]]; then
  324. gzfile=${gzfile%.gpg}
  325. if [ -f $gzfile.gpg ]; then
  326. echo "unsigning GnuPG file: $gzfile.gpg"
  327. gpg $gzfile.gpg
  328. fi
  329. if [ ! -f $gzfile ]; then
  330. echo "unsigning failed"
  331. rm -f "$lkfile" ; trap INT ; return 1
  332. fi
  333. fi
  334. sh ./lib/sde-download/validate.sh "$gzfile" "$bzfile" "$cksum" || downloaderror=1
  335. # Free Lock and finish
  336. #
  337. rm -f "$lkfile" ; trap INT ; return 0
  338. }
  339. # download_file_now location remote_filename local_filename
  340. #
  341. # This function executes the actual download using curl.
  342. #
  343. download_file_now() {
  344. local location="$1" gzfile="$2" bzfile="$3" curlret=0
  345. # Create URL
  346. #
  347. case "$location" in
  348. manual://*) url="$location" ;;
  349. !*) url="${location#!}" ;;
  350. *) url="${location%/*}/${gzfile##*/}" ;;
  351. esac
  352. # Download
  353. #
  354. case "$url" in
  355. manual://*)
  356. # Determine if the file has already been downloaded
  357. # manually. For this we first look in $HOME then in
  358. # download/manual.
  359. downloadpath=${altdir:-$HOME}
  360. downloadfile="${gzfile##*/}"
  361. if [ -e $downloadpath/$downloadfile ]; then
  362. location="file://$downloadpath/"
  363. else
  364. location="http://${url#manual://}"
  365. # No manual download has taken place yet.
  366. # So inform the user to do so.
  367. cat <<-EOT
  368. The file $downloadfile can not be fetched automatically
  369. please visit: $location
  370. and download it manually into $HOME or somewhere else using -alt-dir
  371. EOT
  372. return 1;
  373. fi
  374. # I am to lazy to do the copy and conversion myself,
  375. # so I use this function again with a modified
  376. # download location.
  377. download_file_now "$location" $gzfile $bzfile
  378. return "$?"
  379. ;;
  380. http://*|https://*|ftp://*|file://*)
  381. if [ -s "$gzfile.incomplete" ] ; then
  382. echo "INFO: Trying to resume previous download .."
  383. resume="-C -"
  384. else
  385. resume=""
  386. fi
  387. [ -s download/translations.sed ] &&
  388. trfile=download/translations.sh ||
  389. trfile=etc/download.sed
  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 -ne `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_unknown() {
  561. trap '' INT
  562. mkdir -p tmp/ ; list | bz2filename > tmp/down.$$.lst
  563. ls download/{Proxy,Proxy-auth,Me,Mirror} \
  564. download/mirror/{README,DOWNTEST,LAST-UPDATE} \
  565. >> tmp/down.$$.lst 2> /dev/null
  566. find download/* -type f -o -type l 2> /dev/null |
  567. while read fn ; do
  568. grep -qx "$fn" tmp/down.$$.lst || echo "Unknown file: $fn"
  569. done
  570. rm -f tmp/down.$$.lst
  571. trap INT
  572. }
  573. list_missing() {
  574. trap '' INT
  575. list | bz2filename | \
  576. while read fn ; do
  577. [ -f "$fn" ] || echo "$fn"
  578. done
  579. trap INT
  580. }
  581. repository() {
  582. for repository ; do
  583. packages `echo package/$repository/*/*.desc`
  584. done
  585. }
  586. required() {
  587. # Choosen config must exist
  588. #
  589. if [ ! -f config/$config/packages ]; then
  590. echo "ERROR: Config $config doesn't exist."
  591. echo "ERROR: try ./scripts/Config -cfg $config first."
  592. exit 1
  593. fi
  594. while read on a b repo pkg c ; do
  595. if [ "$on" = "X" ] ; then
  596. grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc > tmp/down.$$.lst
  597. while read tag cksum file url ; do
  598. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$repo" "$pkg"
  599. done < tmp/down.$$.lst ; rm -f tmp/down.$$.lst
  600. fi
  601. done < config/$config/packages
  602. # NOTE: ROCKCFG -> SDECFG automatized convertion
  603. grep -q 'ROCKCFG' ./config/$config/config &&
  604. sed -i -e 's,ROCKCFG,SDECFG,g' ./config/$config/config
  605. target=`grep '^export SDECFG_TARGET=' config/$config/config | \
  606. cut -f2 -d= | tr -d "'"`
  607. targetchain="$target"; x="$target"
  608. while [ -f "target/$x/extends" ]; do
  609. x="`cat target/$x/extends`"
  610. targetchain="$targetchain $x"
  611. done
  612. for target in $targetchain; do
  613. if [ -f target/$target/download.txt ] ; then
  614. while read cksum file url ; do
  615. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$target"
  616. done < target/$target/download.txt
  617. fi
  618. done
  619. }
  620. all() {
  621. local each repo pkg
  622. for repo in $( cd package; ls -1 ); do
  623. for each in package/$repo/*/*.desc; do
  624. pkg="`echo $each | cut -f3 -d/`"
  625. while read tag cksum file url ; do
  626. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$repo" "$pkg"
  627. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  628. done
  629. done
  630. for each in $( ls -1 target/*/download.txt 2> /dev/null ); do
  631. target="`echo $each | cut -f2 -d/`"
  632. while read cksum file url ; do
  633. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$target"
  634. done < <(cat $each)
  635. done
  636. }
  637. package() {
  638. descfile="`echo package/*/$1/$1.desc`"
  639. if [ ! -f $descfile ]; then
  640. echo "Skipping \"$1\" (not found)!"
  641. return
  642. fi
  643. pkg="`echo $descfile | cut -f3 -d/`"
  644. repo="`echo $descfile | cut -f2 -d/`"
  645. while read tag cksum file url ; do
  646. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$repo" "$pkg"
  647. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  648. }
  649. packages() {
  650. local descfile
  651. for arg; do
  652. case "$arg" in
  653. target/*)
  654. if [ ! -f $arg ]; then
  655. echo "Skipping \"$arg\" (not found)!"
  656. continue
  657. fi
  658. target="`echo $arg | cut -f2 -d/`"
  659. while read cksum file url ; do
  660. download_file "`source_file cksum $file "$url"`" "$url" "$cksum" "$target"
  661. done < <(cat $arg)
  662. ;;
  663. *)
  664. if [ "${arg%.desc}" != "$arg" ]; then
  665. arg="`echo $arg | cut -f3 -d/`"; fi
  666. # active extensions
  667. local extender=
  668. # pkg_*_{pre,post}.conf is only activated if extender
  669. # is enabled on $config/packages, so we will only
  670. # download files of those extenders
  671. #
  672. for extender in `ls -1 package/*/*/pkg_${arg}_{pre,post}.conf 2> /dev/null |
  673. cut -d/ -f3 | sort -u`; do
  674. if grep -q "^X .* $extender " \
  675. config/$config/packages; then
  676. echo_info "Also downloading $extender ..."
  677. package $extender
  678. fi
  679. done
  680. package $arg
  681. ;;
  682. esac
  683. done
  684. }
  685. set +e
  686. # Things to do only for downloading
  687. #
  688. if [ "${1:0:5}" != "-list" -a $checkonly = 0 ]; then
  689. # we need curl
  690. if [ -z "`type -p curl`" ]; then
  691. echo_abort 2 "we need \`curl\` installed and available on \$PATH to proceed."
  692. fi
  693. # do mirror detection, only once
  694. [ $this_is_the_2nd_run = 1 ] || detect_mirror
  695. fi
  696. case "$1" in
  697. -list) list ;;
  698. -list-unknown) list_unknown ;;
  699. -list-missing) list_missing ;;
  700. -list-cksums) list_cksums ;;
  701. -required) required ;;
  702. -all) all ;;
  703. -repository) shift ; repository "$@" ;;
  704. -*|"") download_usage
  705. exit 1;;
  706. *) packages "$@" ;;
  707. esac
  708. exit $downloaderr