mirror of the now-defunct rocklinux.org
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.

810 lines
22 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Download
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. #
  25. # Run this command from the ROCK directory as ./scripts/Download [ options ]
  26. #
  27. # It enables you to download source files as described in the package
  28. # definitions (optionally using a mirroring 'cache' server).
  29. #
  30. # This script also allows for checksum display/validation.
  31. #
  32. # Key to understanding this script is that all file lists get broken
  33. # down to a single file download using ./scripts/Download filename.
  34. umask 022
  35. if [ "$1" = '--help' ] ; then
  36. { echo
  37. echo "Usage:"
  38. echo
  39. echo " ./scripts/Download [options] [ Filename(s) ]"
  40. echo " ./scripts/Download [options] -pattern Pattern(s)"
  41. echo " ./scripts/Download [options] -package Package(s)"
  42. echo " ./scripts/Download [options] -repository Repositories"
  43. echo " ./scripts/Download [options] { -all | -required }"
  44. echo
  45. echo " Where [options] is an alias for:"
  46. echo " [ -cfg <config> ] [ -nock ] [ -alt-dir <AlternativeDirectory> ]"
  47. echo " [ -mirror <URL> | -check ] [ -try-questionable ] [ -notimeout ]"
  48. echo " [ -longtimeout ] [ -curl-opt <curl-option>[:<curl-option>[:..]] ]"
  49. echo " [ -proxy <server>[:<port>] ] [ -proxy-auth <username>[:<password>] ]"
  50. echo
  51. echo " On default, this script auto-detects the best ROCK Linux mirror."
  52. echo
  53. echo " Mirrors can also be a local directories in the form of 'file:///<dir>'."
  54. echo
  55. echo " ./scripts/Download -mk-cksum Filename(s)"
  56. echo " ./scripts/Download [ -list | -list-unknown | -list-missing | -list-cksums ]"
  57. echo
  58. echo "See '-mirror none' output for help on bypassing the official mirrors."
  59. echo ; } >&2
  60. exit 1
  61. fi
  62. # -mk-cksum mode (display ROCK type package checksum): it
  63. # displays the checksum ROCK validates against.
  64. #
  65. # Currently bz2, tbz2, gz, tgz, Z are unpacked
  66. #
  67. if [ "$1" = -mk-cksum ] ; then
  68. shift
  69. for x ; do
  70. echo -n "$x: "
  71. if [ ! -f "$x" ] ; then
  72. echo "No such file."
  73. elif [ "${x%.bz2}" != "$x" -o "${x%.tbz2}" != "$x" ] ; then
  74. bunzip2 < "$x" | cksum | cut -f1 -d' '
  75. elif [ "${x%.gz}" != "$x" -o "${x%.tgz}" != "$x" ] ; then
  76. gunzip < "$x" | cksum | cut -f1 -d' '
  77. elif [ "${x%.Z}" != "$x" ] ; then
  78. uncompress < "$x" | cksum | cut -f1 -d' '
  79. else
  80. cksum < "$x" | cut -f1 -d' '
  81. fi
  82. done
  83. exit 1
  84. fi
  85. # Handle options passed on the command line
  86. #
  87. mkdir -p src/ download/ ; config=default
  88. this_is_the_2nd_run=0
  89. mirror='' ; checkonly=0 ; altdir='' ; loop=1
  90. tryques=0 ; nocheck=0 ; options='-this_is_the_2nd_run '
  91. notimeout=0 ; curl_options='--disable-epsv'
  92. #
  93. while [ $loop -eq 1 ] ; do
  94. case "$1" in
  95. -this_is_the_2nd_run)
  96. this_is_the_2nd_run=1
  97. shift ;;
  98. -cfg)
  99. options="$options -cfg $2"
  100. config="$2" ; shift ; shift ;;
  101. -nock)
  102. # -nock skips checksum checking (don't use lightly)
  103. options="$options -nock"
  104. nocheck=1 ; shift ;;
  105. -mirror)
  106. # -mirror uses a mirror for finding source files
  107. if [ "$2" = none ]; then
  108. echo
  109. echo "The option '-mirror none' is not supported anymore!"
  110. echo
  111. echo "You may 'echo none > download/Mirror' if you really"
  112. echo "want to use the original download resources. However, this"
  113. echo "is not supported and if such a download fails, this is not"
  114. echo "a bug in ROCK Linux and doesn't neccessarily needs fixing."
  115. echo
  116. exit 1;
  117. else
  118. mkdir -p download
  119. echo "$2" > download/Mirror
  120. options="$options -mirror $2"
  121. mirror="$2"
  122. fi
  123. shift ; shift ;;
  124. -check)
  125. # -check just validates the file using the checksum
  126. options="$options -check"
  127. checkonly=1 ; shift ;;
  128. -notimeout)
  129. # don't add timeout curl options
  130. options="$options -notimeout"
  131. notimeout=2 ; shift ;;
  132. -longtimeout)
  133. # don't add timeout curl options
  134. options="$options -longtimeout"
  135. notimeout=1 ; shift ;;
  136. -curl-opt)
  137. # additional curl options
  138. options="$options -curl-opt $2"
  139. curl_options="$curl_options `echo $2 | tr : ' '`"
  140. shift ; shift ;;
  141. -proxy)
  142. # proxy option for curl
  143. mkdir -p download
  144. echo -n "$2" > download/Proxy
  145. options="$options -proxy $2"
  146. shift ; shift ;;
  147. -proxy-auth)
  148. # proxy authentication for curl - can be seen with ps!
  149. mkdir -p download
  150. echo -n "$2" > download/Proxy-auth
  151. chmod 600 download/Proxy-auth
  152. options="$options -proxy-auth $2"
  153. shift ; shift ;;
  154. -alt-dir)
  155. # check for an alternative directory where to search for
  156. # package source tarballs
  157. options="$options -alt-dir $2"
  158. altdir=$2 ; shift ; shift ;;
  159. -try-questionable)
  160. # also try to download questionable URLs
  161. options="$options -try-questionable"
  162. tryques=1 ; shift ;;
  163. *)
  164. loop=0 ;;
  165. esac
  166. done
  167. if [ $notimeout -eq 0 ] ; then
  168. curl_options="$curl_options -y 10 -Y 10 --connect-timeout 60"
  169. fi
  170. if [ $notimeout -eq 1 ] ; then
  171. curl_options="$curl_options -y 60 -Y 1 --connect-timeout 300"
  172. fi
  173. if [ -f download/Proxy ]; then
  174. proxy="`cat download/Proxy`"
  175. if [ "$proxy" ]; then
  176. test $this_is_the_2nd_run -eq 0 && \
  177. echo "INFO: Setting proxy to $proxy."
  178. curl_options="$curl_options --proxy $proxy"
  179. else
  180. echo "INFO: Empty proxy definition... removing download/Proxy."
  181. rm download/Proxy
  182. fi
  183. fi
  184. if [ -f download/Proxy-auth ]; then
  185. proxyauth="`cat download/Proxy-auth`"
  186. if [ "$proxyauth" ]; then
  187. test $this_is_the_2nd_run -eq 0 && \
  188. echo "INFO: Setting proxy authentication information."
  189. curl_options="$curl_options --proxy-user $proxyauth"
  190. else
  191. echo "INFO: No proxy-auth information... removing download/Proxy-auth."
  192. rm download/Proxy-auth
  193. fi
  194. fi
  195. # cksum_chk filename cksum origfile
  196. #
  197. # This function verifies the checksum. If it fails it renames the file
  198. # to file.chksum-err and returns failure.
  199. #
  200. # It seams like the [ ] command has problems with comparing high numbers.
  201. # That's why I'm using a text comparison here.
  202. #
  203. # Not doing anything if checksum is '0' or a text of 'X'.
  204. #
  205. cksum_chk() {
  206. y="`echo $2 | sed 's,^0*,,;'`"
  207. [ $nocheck = 1 -o -z "$y" -o -z "${2//X/}" ] && return 0
  208. x="`cksum "$1" | cut -f1 -d' ' | sed 's,^0*,,;'`"
  209. if [ "$x" != "$y" ] ; then
  210. # Add .cksum-err extension to filename:
  211. echo "Cksum ERROR: $3.cksum-err ($x)"
  212. mv "$3" "$3.cksum-err" ; return 1
  213. fi
  214. return 0
  215. }
  216. # Choosen config must exist
  217. #
  218. if [ ! -f config/$config/packages ]; then
  219. echo "ERROR: Config $config doesn't exist."
  220. echo "ERROR: try ./scripts/Config -cfg $config first."
  221. exit 1
  222. fi
  223. # Autodetect best Mirror and safe url in $mirror
  224. #
  225. detect_mirror() {
  226. if [ -f download/Mirror ] ; then
  227. mirror="`cat download/Mirror`"
  228. if [ -z "$mirror" -o "$mirror" = "none" ] ; then
  229. echo "INFO: Found download/Mirror: none" \
  230. "(use the original download locations)"
  231. else
  232. echo "INFO: Found cached mirror URL in download/Mirror:"
  233. echo "INFO: $mirror"
  234. fi
  235. echo "INFO: To force a new mirror auto-detection, remove download/Mirror."
  236. else
  237. echo "INFO: Auto-detecting best mirror ..."
  238. eval "$(egrep '^(rockver)=' scripts/parse-config)"
  239. echo "INFO: Downloading mirror-list from www.rocklinux.net."
  240. curl -s -S $curl_options -o src/Download-Mirror-List \
  241. "http://www.rocklinux.net/mirrors.cgi?$rockver"
  242. bestval=0 ; result='No Mirror Found!'
  243. while read mirror_name ; do
  244. if [ "${mirror_name#=}" != "$mirror_name" ] ; then
  245. mirror_name="${mirror_name#= }"
  246. mirror_name="${mirror_name% =}"
  247. read mirror_url
  248. echo -n "INFO: Testing <$mirror_name> ..."
  249. val="$(curl -s $curl_options -m 20 "${mirror_url%/}/DOWNTEST" \
  250. -w "ok %{speed_download}" -o /dev/null)"
  251. if [ "$val" = "${val#ok }" -o "$val" = "ok 0.000" ] ; then
  252. echo " error"
  253. else
  254. xval=`echo ${val#ok } | tr -d .` ; echo " $val"
  255. if [ "$xval" -gt "$bestval" ] ; then
  256. bestval=$xval ; mirror="${mirror_url%/}"
  257. result="Using mirror <$mirror>."
  258. fi
  259. fi
  260. fi
  261. done < src/Download-Mirror-List
  262. echo $mirror > download/Mirror
  263. echo "INFO: $result"
  264. fi
  265. }
  266. # download_file local-filename download-location cksum
  267. #
  268. # This function decides if download directly or from a mirror,
  269. # validates checksum, etc.
  270. # Calls download_file_now to do the actual download.
  271. #
  272. download_file() {
  273. # Init
  274. #
  275. gzfile="$1" ; location="$2" ; cksum="$3"
  276. # Make src directory for creating tar balls
  277. mkdir -p src/
  278. # Tar ball file name:
  279. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  280. # Lock file name:
  281. lkfile="src/down.lockfile.`echo $bzfile | tr / -`"
  282. # Check if it's already there
  283. #
  284. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  285. # Make locking
  286. #
  287. if [ -s "$lkfile" ]; then
  288. echo "Found $lkfile -> skip download."
  289. return 0
  290. fi
  291. trap 'rm -f "$lkfile"' INT
  292. echo $$ > "$lkfile"
  293. # Check if we only like to test the cksum(s)
  294. #
  295. if [ $checkonly = 1 ] ; then
  296. gzfile="$bzfile"
  297. if [ ! -f "$bzfile" ] ; then
  298. echo "File missing: $bzfile"
  299. rm -f "$lkfile" ; trap INT ; return 1
  300. fi
  301. if [ -z "${cksum##X*}" ] ; then
  302. echo "No checksum (ignore): $bzfile"
  303. rm -f "$lkfile" ; trap INT ; return 1
  304. fi
  305. if [ "$cksum" -eq 0 ] ; then
  306. echo "No checksum (missing): $bzfile"
  307. rm -f "$lkfile" ; trap INT ; return 1
  308. fi
  309. elif [ -s "$gzfile" ] ; then
  310. echo ; echo "Already downloaded $gzfile ..."
  311. else
  312. echo ; echo "Downloading $gzfile ..."
  313. # Existing *.cksum-err
  314. #
  315. if [ -s "$gzfile.cksum-err" ] ; then
  316. # cksum-err file alread exists:
  317. echo "ERROR: Found $gzfile.cksum-err."
  318. echo "ERROR: That means that we downloaded the" \
  319. "file already and it had an"
  320. echo "ERROR: incorrect checksum. Remove the" \
  321. "*.cksum-err file to force a"
  322. echo "ERROR: new download of that file."
  323. rm -f "$lkfile" ; trap INT ; return 1
  324. fi
  325. # Existing *.extck-err
  326. #
  327. if [ -s "$gzfile.extck-err" ] ; then
  328. # extck-err file alread exists:
  329. echo "ERROR: Found $gzfile.extck-err."
  330. echo "ERROR: That means that we downloaded the" \
  331. "file already and it's content"
  332. echo "ERROR: did not match it's filename extension." \
  333. "Remove the *.extck-err file"
  334. echo "ERROR: to force a new download of that file."
  335. rm -f "$lkfile" ; trap INT ; return 1
  336. fi
  337. # Questionable URL
  338. #
  339. if [ "$location" != "${location#\?}" ] ; then
  340. if [ "$tryques" = 0 ] ; then
  341. echo "ERROR: URL is marked as questionable." \
  342. "Not downloading this file."
  343. rm -f "$lkfile" ; trap INT ; return 1
  344. else
  345. echo "WARNING: URL is marked as questionable." \
  346. "Downloading it anyways."
  347. location="${location#\?}"
  348. fi
  349. fi
  350. # Make directory (if required)
  351. #
  352. if [ ! -d `dirname "$bzfile"` ] ; then
  353. mkdir -p `dirname "$bzfile"`
  354. fi
  355. # Alternative Directory
  356. #
  357. if [ "$altdir" ] ; then
  358. altfile=$(find $altdir/ -name `basename $bzfile` | head -1)
  359. else
  360. altfile=""
  361. fi
  362. if [ "$altfile" ] ; then
  363. echo "Found `basename $bzfile` as $altfile."
  364. cp -lv $altfile $bzfile ; gzfile="$bzfile"
  365. else
  366. # Mirroring
  367. #
  368. mirror="$( cat download/Mirror )"
  369. if [ "$mirror" -a "$mirror" != "none" ] ; then
  370. # try to use mirror
  371. if ! download_file_now "!$mirror/${bzfile#download/}" $bzfile $bzfile; then
  372. # oops... so try direct (original URL)
  373. echo "INFO: download from mirror failed, trying original URL."
  374. download_file_now $location $gzfile $bzfile
  375. else
  376. gzfile="$bzfile"
  377. fi
  378. else
  379. # don't want to use mirror
  380. download_file_now $location $gzfile $bzfile
  381. fi
  382. fi
  383. if [ ! -s "$gzfile" ]; then
  384. rm -f "$lkfile" ; trap INT ; return 1
  385. fi
  386. fi
  387. # Convert a .gz to .bz2 and test checksum
  388. #
  389. if [ "$gzfile" != "$bzfile" ] ; then
  390. echo "bzip'ing + cksum-test: $gzfile"
  391. gunzip < "$gzfile" > src/down.$$.dat
  392. if cksum_chk src/down.$$.dat $cksum "$gzfile" ; then
  393. bzip2 < src/down.$$.dat > "$bzfile" ; rm -f "$gzfile"
  394. fi
  395. rm -f src/down.$$.dat
  396. # Execute a cksum test on a bzip2 file
  397. #
  398. elif [ "${gzfile%.bz2}" != "$gzfile" -o \
  399. "${gzfile%.tbz2}" != "$gzfile" ]
  400. then
  401. echo "cksum-test (bzip2): $bzfile"
  402. if [ $nocheck = 0 ] ; then
  403. bunzip2 < "$bzfile" > src/down.$$.dat
  404. cksum_chk src/down.$$.dat $cksum "$bzfile"
  405. fi
  406. rm -f src/down.$$.dat
  407. # Execute a cksum test on a raw data file
  408. #
  409. else
  410. echo "cksum-test (raw): $gzfile"
  411. cksum_chk "$gzfile" $cksum "$gzfile"
  412. fi
  413. # Free Lock and finish
  414. #
  415. rm -f "$lkfile" ; trap INT ; return 0
  416. }
  417. # download_file_now location remote_filename local_filename
  418. #
  419. # This function executes the actual download using curl.
  420. #
  421. download_file_now() {
  422. local location="$1" gzfile="$2" bzfile="$3"
  423. # Create URL
  424. #
  425. if [ "${location#!}" != "$location" ] ; then
  426. url="`echo "$location" | sed 's,!,,'`"
  427. else
  428. url="`echo "$location" | \
  429. sed 's,/[^/]*$,,'`/`echo $gzfile | sed 's,.*/,,'`"
  430. fi
  431. # Check for existing Error Log
  432. #
  433. if test -s src/Download-Errors &&
  434. grep -q " $url\$" src/Download-Errors ; then
  435. echo "ERROR: According to src/Download-Errors" \
  436. "we had already an error for that URL."
  437. echo "ERROR: So I'm not trying to download" \
  438. "it again (remove src/Download-Errors"
  439. echo "ERROR: if you want to force a retry)."
  440. rm -f "$lkfile" ; trap INT ; return 1
  441. fi
  442. # Download
  443. #
  444. if [[ $url = cvs://* ]] ; then
  445. # cvs://mode:[login[:password]@]server[:port]:/path::module!revision/
  446. # btw, at least current cvs supports password at CVSROOT.
  447. url="${url#cvs://}"; url="${url%/*}"
  448. # cvs://mode:loc::module!date/
  449. #
  450. mode="${url%%:*}"; loc="${url#*:}"
  451. module="${loc##*::}"; loc="${loc%%::*}"
  452. revision="${module#*!}"; module="${module%%!*}"
  453. [[ $loc != *@* ]] && loc="anonymous@$loc"
  454. # everything after the first 'bang' (!) is analysed here
  455. # someday we could add more cvs options.
  456. #
  457. dat="$( echo $revision | \
  458. sed -n -e 's,\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\),-D \1,p' )"
  459. cvsdir="src/down.cvsdir.`echo $bzfile | tr / -`"
  460. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  461. echo CVS $mode $loc $dat $module
  462. { [ $mode = ssh ] && export CVS_RSH=ssh
  463. [ $mode = pserver ] && loc=":pserver:$loc"
  464. # for ssh we need some way to quitely accept
  465. # the key ...
  466. echo cvs -z9 -Q -d $loc checkout $dat -P $module
  467. if ! cvs -z9 -Q -d $loc checkout $dat -P $module
  468. then touch .cvs_error ; fi
  469. } &> .cvs_output &
  470. while fuser .cvs_output &> /dev/null ; do
  471. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  472. 'CVS archive so far...\r'
  473. sleep 3
  474. done
  475. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  476. 'CVS archive (download finished).'
  477. if [ ! -f .cvs_error ] ; then
  478. cd `dirname $module`
  479. dir="`echo "$bzfile" | sed s/\.tar\.bz2$//`"
  480. dir="`basename $dir`"
  481. mv `basename $module` $dir
  482. tar --owner root --group root \
  483. --use-compress-program=bzip2 \
  484. -cf $dir.tar.bz2 $dir
  485. mv $dir.tar.bz2 $saved_pwd/$bzfile
  486. cd $saved_pwd ; rm -rf $cvsdir
  487. else
  488. cat .cvs_output
  489. cd $saved_pwd ; rm -rf $cvsdir
  490. echo ERROR: CVS $dat $loc $module \
  491. returned an error.
  492. echo "0 $gzfile $url" >> src/Download-Errors
  493. fi
  494. else
  495. if [ -s "$gzfile.incomplete" ] ; then
  496. echo "INFO: Trying to resume previous download .."
  497. resume="-C -"
  498. else
  499. resume=""
  500. fi
  501. curl -w '\rFinished downloading %{size_download} bytes in %{time_total} seconds (%{speed_download} bytes/sec). \n' -f --progress-bar $resume $curl_options "$url" -o "$gzfile.incomplete"
  502. curlret="$?"
  503. if [ "$resume" ] && \
  504. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  505. echo "INFO: Resuming download not possible. ->" \
  506. "Overwriting old file."
  507. rm -f "$gzfile.incomplete"
  508. curl -w '\rFinished downloading %{size_download} bytes in %{time_total} seconds (%{speed_download} bytes/sec). \n' -f --progress-bar $curl_options "$url" -o "$gzfile.incomplete"
  509. curlret="$?"
  510. fi
  511. if [ $curlret -ne 0 ] ; then
  512. rm -f "$lkfile" ; trap INT
  513. case "$curlret" in
  514. 18)
  515. echo "WARNING: Got only some of the" \
  516. "file. A re-run of $0"
  517. echo "WARNING: is required to complete" \
  518. "the download." ;;
  519. 130)
  520. echo -e '\rWARNING: CURL got a SIGINT' \
  521. "(someone pressed Ctrl-C). A re-run of"
  522. echo "WARNING: $0 is required to complete" \
  523. "the download." ; sleep 1 ;;
  524. *)
  525. echo "$curlret $gzfile $url" \
  526. >> src/Download-Errors
  527. echo -e '\rERROR: CURL Returned Error' \
  528. "$curlret. Please read" \
  529. "the curl manpage." ;;
  530. esac
  531. return 1
  532. elif [ ! -s "$gzfile.incomplete" ] ; then
  533. echo "0 $gzfile $url" >> src/Download-Errors
  534. echo "ERROR: CURL returned success but" \
  535. "we have no data!"
  536. curlret=1
  537. else
  538. case "$gzfile" in
  539. *.gz|*.tgz)
  540. typeexpr="gzip compressed data" ;;
  541. *.bz2|*.tbz2)
  542. typeexpr="bzip2 compressed data" ;;
  543. *.Z|*.tZ)
  544. typeexpr="compress'd data" ;;
  545. *.zip|*.jar)
  546. typeexpr="Zip archive data" ;;
  547. *.tar)
  548. typeexpr="tar archive" ;;
  549. *)
  550. echo "WARNING: Unkown file extension: $gzfile"
  551. typeexpr="." ;;
  552. esac
  553. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  554. then
  555. echo "ERROR: File type does not match" \
  556. "filename ($typeexpr)!"
  557. mv "$gzfile.incomplete" "$gzfile.extck-err"
  558. else
  559. mv "$gzfile.incomplete" "$gzfile"
  560. fi
  561. fi
  562. fi
  563. }
  564. # handle_file filename
  565. #
  566. # This function fetches the checksum and download information
  567. # from the desc files and calls the download_file function.
  568. #
  569. handle_file() {
  570. # Handle pkg file (package/.../*.desc)
  571. #
  572. tree="`echo "$1" | cut -f2 -d/`"
  573. pkg="` echo "$1" | cut -f3 -d/`"
  574. file="`echo "$1" | cut -f4 -d/`"
  575. if grep -q "^\[D\].* $file " package/$tree/$pkg/$pkg.desc 2> /dev/null
  576. then
  577. grep "^\[D\].* $file " package/$tree/$pkg/$pkg.desc |
  578. while read tag cksum file url ; do
  579. download_file "$1" "$url" "$cksum"
  580. done
  581. return 0
  582. fi
  583. # Handle target file (target/.../download.txt)
  584. #
  585. target="`echo "$1" | cut -f2 -d/`"
  586. file="`echo "$1" | cut -f3- -d/`"
  587. if grep -q " $file " target/$target/download.txt 2> /dev/null
  588. then
  589. grep " $file " target/$target/download.txt |
  590. while read cksum file url ; do
  591. download_file "$1" "$url" "$cksum"
  592. done
  593. return 0
  594. fi
  595. # Handle misc file (scripts/miscdown.txt)
  596. #
  597. if [ "${1#download/misc/}" != "$1" ] ; then
  598. file="`echo "$1" | cut -f3- -d/`"
  599. if grep -q " $file " scripts/miscdown.txt
  600. then
  601. grep " $file " scripts/miscdown.txt |
  602. while read cksum file url ; do
  603. download_file "$1" "$url" "$cksum"
  604. done
  605. return 0
  606. fi
  607. fi
  608. # Can't handle file / file not found
  609. #
  610. return 1
  611. }
  612. list_cksums() {
  613. trap '' INT
  614. { grep -H '^\[D\] ' package/*/*/*.desc | tr '\t' ' ' | tr -s ' ' |
  615. sed -e 's,^package/,download/,;'
  616. grep -H '^[X0-9]' target/*/download.txt | tr '\t' ' ' | tr -s ' ' |
  617. sed -e 's,^target/,download/,; s,:,:[D] ,;'
  618. grep -H '^[X0-9]' scripts/miscdown.txt | tr '\t' ' ' | tr -s ' ' |
  619. sed 's,^scripts/,download/misc/,; s,:,:[D] ,;'
  620. } | sed 's,^\(.*/\)[^/:]*:[^ ]* \([X0-9]*\) ,\2 \1,;' | cut -f1,2 -d' '
  621. trap INT
  622. }
  623. list() {
  624. trap '' INT
  625. list_cksums | cut -f2- -d' '
  626. trap INT
  627. }
  628. list_unknown() {
  629. trap '' INT
  630. mkdir -p src/ ; list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' > src/down.$$.lst
  631. ls download/{INDEX,README,DOWNTEST,LAST-UPDATE} \
  632. >> src/down.$$.lst 2> /dev/null
  633. find download/* -type f -o -type l | \
  634. while read fn ; do
  635. grep -qx "$fn" src/down.$$.lst || echo "Unknown file: $fn"
  636. done
  637. rm -f src/down.$$.lst
  638. trap INT
  639. }
  640. list_missing() {
  641. trap '' INT
  642. list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' | \
  643. while read fn ; do
  644. [ -f "$fn" ] || echo "$fn"
  645. done
  646. trap INT
  647. }
  648. pattern() {
  649. for pattern ; do
  650. echo "Processing pattern $pattern ..."
  651. list | while read fn ; do
  652. if [ "${fn##$pattern}" = '' ] ; then
  653. echo "Matched: $fn"
  654. $0 $options "$fn"
  655. fi
  656. done
  657. done
  658. }
  659. package() {
  660. for package ; do
  661. pattern "download/*/$package/*"
  662. done
  663. }
  664. repository() {
  665. for repository ; do
  666. pattern "download/$repository/*"
  667. done
  668. }
  669. required() {
  670. while read on a b tree pkg c ; do
  671. if [ "$on" = "X" ] ; then
  672. grep -H '^\[D\] ' package/$tree/$pkg/$pkg.desc > src/down.$$.lst
  673. while read tag cksum file url ; do
  674. download_file "download/$tree/$pkg/$file" "$url" "$cksum"
  675. done < src/down.$$.lst ; rm -f src/down.$$.lst
  676. fi
  677. done < config/$config/packages
  678. target=`grep '^export ROCKCFG_TARGET=' config/$config/config | \
  679. cut -f2 -d= | tr -d "'"`
  680. if [ -f target/$target/download.txt ] ; then
  681. while read cksum file url ; do
  682. download_file "download/$target/$file" "$url" "$cksum"
  683. done < target/$target/download.txt
  684. fi
  685. }
  686. single_files() {
  687. for file_name ; do
  688. file_name_gz="`echo "$file_name" | sed 's,\.\(t\?\)bz2$,.\1gz,'`"
  689. file_name_Z="`echo "$file_name" | sed 's,\.\(t\?\)bz2$,.\1Z,'`"
  690. if ! handle_file "$file_name" && \
  691. ! handle_file "$file_name_gz" && \
  692. ! handle_file "$file_name_Z"
  693. then
  694. echo "ERROR: Unknown file: $file_name."
  695. fi
  696. done
  697. }
  698. all() {
  699. if [ $checkonly = 1 ] ; then list
  700. else list_missing ; fi > src/down.$$.lst
  701. while read fn ; do single_files $fn ; done < src/down.$$.lst
  702. rm -f src/down.$$.lst
  703. }
  704. # Do mirror detection only once
  705. #
  706. if [ $this_is_the_2nd_run = 0 ]; then
  707. detect_mirror
  708. fi
  709. case "$1" in
  710. -list) list ;;
  711. -list-unknown) list_unknown ;;
  712. -list-missing) list_missing ;;
  713. -list-cksums) list_cksums ;;
  714. -pattern) shift ; pattern "$@" ;;
  715. -package) shift ; package "$@" ;;
  716. -repository) shift ; repository "$@" ;;
  717. -required) required ;;
  718. -all) all ;;
  719. -*|"") exec $0 --help ;;
  720. *) single_files "$@" ;;
  721. esac
  722. exit 0