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.

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