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.

735 lines
20 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>] ]"
  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 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. else
  78. cksum < "$x" | cut -f1 -d' '
  79. fi
  80. done
  81. exit 1
  82. fi
  83. # Handle options passed on the command line
  84. #
  85. mkdir -p src/ ; config=default
  86. mirror='' ; checkonly=0 ; altdir='' ; loop=1
  87. tryques=0 ; nocheck=0 ; options=''
  88. notimeout=0 ; curl_options='--disable-epsv'
  89. #
  90. while [ $loop -eq 1 ] ; do
  91. case "$1" in
  92. -cfg)
  93. options="$options -cfg $2"
  94. config="$2" ; shift ; shift ;;
  95. -nock)
  96. # -nock skips checksum checking (don't use lightly)
  97. options="$options -nock"
  98. nocheck=1 ; shift ;;
  99. -mirror)
  100. # -mirror uses a mirror for finding source files
  101. if [ "$2" = none ]; then
  102. echo
  103. echo "The option '-mirror none' is not supported anymore!"
  104. echo
  105. echo "You may 'echo none > src/Download-Mirror' if you really"
  106. echo "want to use the original download resources. However, this"
  107. echo "is not supported and if such a download fails, this is not"
  108. echo "a bug in ROCK Linux and doesn't neccessarily needs fixing."
  109. echo
  110. exit 1;
  111. else
  112. echo "$2" > src/Download-Mirror
  113. options="$options -mirror $2"
  114. mirror="$2"
  115. fi
  116. shift ; shift ;;
  117. -check)
  118. # -check just validates the file using the checksum
  119. options="$options -check"
  120. checkonly=1 ; shift ;;
  121. -notimeout)
  122. # don't add timeout curl options
  123. options="$options -notimeout"
  124. notimeout=2 ; shift ;;
  125. -longtimeout)
  126. # don't add timeout curl options
  127. options="$options -longtimeout"
  128. notimeout=1 ; shift ;;
  129. -curl-opt)
  130. # additional curl options
  131. options="$options -curl-opt $2"
  132. curl_options="$curl_options `echo $2 | tr : ' '`"
  133. shift ; shift ;;
  134. -proxy)
  135. # proxy option for curl
  136. echo -n "$2" > src/Download-Proxy
  137. options="$options -proxy $2"
  138. shift ; shift ;;
  139. -alt-dir)
  140. # check for an alternative directory where to search for
  141. # package source tarballs
  142. options="$options -alt-dir $2"
  143. altdir=$2 ; shift ; shift ;;
  144. -try-questionable)
  145. # also try to download questionable URLs
  146. options="$options -try-questionable"
  147. tryques=1 ; shift ;;
  148. *)
  149. loop=0 ;;
  150. esac
  151. done
  152. if [ $notimeout -eq 0 ] ; then
  153. curl_options="$curl_options -y 10 -Y 10 --connect-timeout 60"
  154. fi
  155. if [ $notimeout -eq 1 ] ; then
  156. curl_options="$curl_options -y 60 -Y 1 --connect-timeout 300"
  157. fi
  158. if [ -f src/Download-Proxy ]; then
  159. proxy="`cat src/Download-Proxy`"
  160. if [ "$proxy" ]; then
  161. echo "INFO: Setting proxy to $proxy."
  162. curl_options="$curl_options --proxy $proxy"
  163. else
  164. echo "INFO: Empty proxy definition... removing src/Download-Proxy."
  165. rm src/Download-Proxy
  166. fi
  167. fi
  168. # cksum_chk filename cksum origfile
  169. #
  170. # This function verifies the checksum. If it fails it renames the file
  171. # to file.chksum-err and returns failure.
  172. #
  173. # It seams like the [ ] command has problems with comparing high numbers.
  174. # That's why I'm using a text comparison here.
  175. #
  176. # Not doing anything if checksum is '0' or a text of 'X'.
  177. #
  178. cksum_chk() {
  179. y="`echo $2 | sed 's,^0*,,;'`"
  180. [ $nocheck = 1 -o -z "$y" -o -z "${2//X/}" ] && return 0
  181. x="`cksum "$1" | cut -f1 -d' ' | sed 's,^0*,,;'`"
  182. if [ "$x" != "$y" ] ; then
  183. # Add .cksum-err extension to filename:
  184. echo "Cksum ERROR: $3.cksum-err ($x)"
  185. mv "$3" "$3.cksum-err" ; return 1
  186. fi
  187. return 0
  188. }
  189. # Autodetect best Mirror and safe url in $mirror
  190. #
  191. detect_mirror() {
  192. if [ -f src/Download-Mirror ] ; then
  193. mirror="`cat src/Download-Mirror`"
  194. if [ -z "$mirror" -o "$mirror" = "none" ] ; then
  195. echo "INFO: Found src/Download-Mirror: none" \
  196. "(use the original download locations)"
  197. else
  198. echo "INFO: Found cached mirror URL in src/Download-Mirror:"
  199. echo "INFO: $mirror"
  200. fi
  201. echo "INFO: To force a new mirror auto-detection, remove src/Download-Mirror."
  202. else
  203. echo "INFO: Auto-detecting best mirror ..."
  204. eval "$(egrep '^(rockver)=' scripts/parse-config)"
  205. echo "INFO: Downloading mirror-list from www.rocklinux.net."
  206. curl -s -S $curl_options -o src/Download-Mirror-List \
  207. "http://www.rocklinux.net/mirrors.cgi?$rockver"
  208. bestval=0 ; result='No Mirror Found!'
  209. while read mirror_name ; do
  210. if [ "${mirror_name#=}" != "$mirror_name" ] ; then
  211. mirror_name="${mirror_name#= }"
  212. mirror_name="${mirror_name% =}"
  213. read mirror_url
  214. echo -n "INFO: Testing <$mirror_name> ..."
  215. val="$(curl -s $curl_options -m 20 "${mirror_url%/}/DOWNTEST" \
  216. -w "ok %{speed_download}" -o /dev/null)"
  217. if [ "$val" = "${val#ok }" -o "$val" = "ok 0.000" ] ; then
  218. echo " error"
  219. else
  220. xval=`echo ${val#ok } | tr -d .` ; echo " $val"
  221. if [ "$xval" -gt "$bestval" ] ; then
  222. bestval=$xval ; mirror="${mirror_url%/}"
  223. result="Using mirror <$mirror>."
  224. fi
  225. fi
  226. fi
  227. done < src/Download-Mirror-List
  228. echo $mirror > src/Download-Mirror
  229. echo "INFO: $result"
  230. fi
  231. }
  232. # download_file local-filename download-location cksum
  233. #
  234. # This function executes the actual download using curl.
  235. #
  236. download_file() {
  237. # Init
  238. #
  239. gzfile="$1" ; location="$2" ; cksum="$3"
  240. # Make src directory for creating tar balls
  241. mkdir -p src/
  242. # Tar ball file name:
  243. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)gz$,.\1bz2,'`"
  244. # Lock file name:
  245. lkfile="src/down.lockfile.`echo $bzfile | tr / -`"
  246. # Check if it's already there
  247. #
  248. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  249. # Make locking
  250. #
  251. if [ -s "$lkfile" ]; then
  252. echo "Found $lkfile -> skip download."
  253. return 0
  254. fi
  255. trap 'rm -f "$lkfile"' INT
  256. echo $$ > "$lkfile"
  257. # Check if we only like to test the cksum(s)
  258. #
  259. if [ $checkonly = 1 ] ; then
  260. gzfile="$bzfile"
  261. if [ ! -f "$bzfile" ] ; then
  262. echo "File missing: $bzfile"
  263. rm -f "$lkfile" ; trap INT ; return 1
  264. fi
  265. if [ -z "${cksum##X*}" ] ; then
  266. echo "No checksum (ignore): $bzfile"
  267. rm -f "$lkfile" ; trap INT ; return 1
  268. fi
  269. if [ "$cksum" -eq 0 ] ; then
  270. echo "No checksum (missing): $bzfile"
  271. rm -f "$lkfile" ; trap INT ; return 1
  272. fi
  273. elif [ -s "$gzfile" ] ; then
  274. echo ; echo "Already downloaded $gzfile ..."
  275. else
  276. echo ; echo "Downloading $gzfile ..."
  277. # Existing *.cksum-err
  278. #
  279. if [ -s "$gzfile.cksum-err" ] ; then
  280. # cksum-err file alread exists:
  281. echo "ERROR: Found $gzfile.cksum-err."
  282. echo "ERROR: That means that we downloaded the" \
  283. "file already and it had an"
  284. echo "ERROR: incorrect checksum. Remove the" \
  285. "*.cksum-err file to force a"
  286. echo "ERROR: new download of that file."
  287. rm -f "$lkfile" ; trap INT ; return 1
  288. fi
  289. # Existing *.extck-err
  290. #
  291. if [ -s "$gzfile.extck-err" ] ; then
  292. # extck-err file alread exists:
  293. echo "ERROR: Found $gzfile.extck-err."
  294. echo "ERROR: That means that we downloaded the" \
  295. "file already and it's content"
  296. echo "ERROR: did not match it's filename extension." \
  297. "Remove the *.extck-err file"
  298. echo "ERROR: to force a new download of that file."
  299. rm -f "$lkfile" ; trap INT ; return 1
  300. fi
  301. # Questionable URL
  302. #
  303. if [ "$location" != "${location#\?}" ] ; then
  304. if [ "$tryques" = 0 ] ; then
  305. echo "ERROR: URL is marked as questionable." \
  306. "Not downloading this file."
  307. rm -f "$lkfile" ; trap INT ; return 1
  308. else
  309. echo "WARNING: URL is marked as questionable." \
  310. "Downloading it anyways."
  311. location="${location#\?}"
  312. fi
  313. fi
  314. # Make directory (if required)
  315. #
  316. if [ ! -d `dirname "$bzfile"` ] ; then
  317. mkdir -p `dirname "$bzfile"`
  318. fi
  319. # Alternative Directory
  320. #
  321. if [ "$altdir" ] ; then
  322. altfile=$(find $altdir/ -name `basename $bzfile` | head -1)
  323. else
  324. altfile=""
  325. fi
  326. if [ "$altfile" ] ; then
  327. echo "Found `basename $bzfile` as $altfile."
  328. cp -lv $altfile $bzfile ; gzfile="$bzfile"
  329. else
  330. # Mirroring
  331. #
  332. [ -z "$mirror" ] && detect_mirror
  333. if [ "$mirror" -a "$mirror" != "none" ] ; then
  334. location="!$mirror/${bzfile#download/}"
  335. gzfile="$bzfile"
  336. fi
  337. # Create URL
  338. #
  339. if [ "${location#!}" != "$location" ] ; then
  340. url="`echo "$location" | sed 's,!,,'`"
  341. else
  342. url="`echo "$location" | \
  343. sed 's,/[^/]*$,,'`/`echo $gzfile | sed 's,.*/,,'`"
  344. fi
  345. # Check for existing Error Log
  346. #
  347. if test -s src/Download-Errors &&
  348. grep -q " $url\$" src/Download-Errors ; then
  349. echo "ERROR: According to src/Download-Errors" \
  350. "we had already an error for that URL."
  351. echo "ERROR: So I'm not trying to download" \
  352. "it again (remove src/Download-Errors"
  353. echo "ERROR: if you want to force a retry)."
  354. rm -f "$lkfile" ; trap INT ; return 1
  355. fi
  356. # Download
  357. #
  358. if [[ $url = cvs://* ]] ; then
  359. url="`dirname $url`"
  360. mode="`echo $url | sed -e s,^cvs://,, -e 's,:.*,,'`"
  361. if [ "${url##*\!*}" ] ; then dat=""
  362. else dat="-D ${url##*\!}" ; dat="${dat//_/ }" ; fi
  363. loc="`echo $url | \
  364. sed 's,^cvs://[a-z,A-Z]*:,,; s,::.*$,,'`"
  365. module="`echo $url | sed 's/^.*:://; s,!.*$,,'`"
  366. cvsdir="src/down.cvsdir.`echo $bzfile | tr / -`"
  367. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  368. echo CVS $mode $loc $dat $module
  369. { [ $mode = ssh ] && export CVS_RSH=ssh
  370. [ $mode = pserver ] && loc=":pserver:$loc"
  371. # for ssh we need some way to quitely accept
  372. # the key ...
  373. echo cvs -z9 -Q -d $loc checkout $dat -P $module
  374. if ! cvs -z9 -Q -d $loc checkout $dat -P $module
  375. then touch .cvs_error ; fi
  376. } &> .cvs_output &
  377. while fuser .cvs_output &> /dev/null ; do
  378. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  379. 'CVS archive so far...\r'
  380. sleep 3
  381. done
  382. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  383. 'CVS archive (download finished).'
  384. if [ ! -f .cvs_error ] ; then
  385. cd `dirname $module`
  386. dir="`echo "$bzfile" | sed s/\.tar\.bz2$//`"
  387. dir="`basename $dir`"
  388. mv `basename $module` $dir
  389. tar --owner root --group root \
  390. --use-compress-program=bzip2 \
  391. -cf $dir.tar.bz2 $dir
  392. mv $dir.tar.bz2 $saved_pwd/$bzfile
  393. cd $saved_pwd ; rm -rf $cvsdir
  394. else
  395. cat .cvs_output
  396. cd $saved_pwd ; rm -rf $cvsdir
  397. echo ERROR: CVS $dat $loc $module \
  398. returned an error.
  399. echo "0 $gzfile $url" >> src/Download-Errors
  400. fi
  401. else
  402. if [ -s "$gzfile.incomplete" ] ; then
  403. echo "INFO: Trying to resume previous download .."
  404. resume="-C -"
  405. else
  406. resume=""
  407. fi
  408. 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"
  409. curlret="$?"
  410. if [ "$resume" ] && \
  411. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  412. echo "INFO: Resuming download not possible. ->" \
  413. "Overwriting old file."
  414. rm -f "$gzfile.incomplete"
  415. 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"
  416. curlret="$?"
  417. fi
  418. if [ $curlret -ne 0 ] ; then
  419. rm -f "$lkfile" ; trap INT
  420. case "$curlret" in
  421. 18)
  422. echo "WARNING: Got only some of the" \
  423. "file. A re-run of $0"
  424. echo "WARNING: is required to complete" \
  425. "the download." ;;
  426. 130)
  427. echo -e '\rWARNING: CURL got a SIGINT' \
  428. "(someone pressed Ctrl-C). A re-run of"
  429. echo "WARNING: $0 is required to complete" \
  430. "the download." ; sleep 1 ;;
  431. *)
  432. echo "$curlret $gzfile $url" \
  433. >> src/Download-Errors
  434. echo -e '\rERROR: CURL Returned Error' \
  435. "$curlret. Please read" \
  436. "the curl manpage." ;;
  437. esac
  438. return 1
  439. elif [ ! -s "$gzfile.incomplete" ] ; then
  440. echo "0 $gzfile $url" >> src/Download-Errors
  441. echo "ERROR: CURL returned success but" \
  442. "we have no data!"
  443. curlret=1
  444. else
  445. case "$gzfile" in
  446. *.gz|*.tgz)
  447. typeexpr="gzip compressed data" ;;
  448. *.bz2|*.tbz2)
  449. typeexpr="bzip2 compressed data" ;;
  450. *.Z)
  451. typeexpr="compress'd data" ;;
  452. *.zip|*.jar)
  453. typeexpr="Zip archive data" ;;
  454. *.tar)
  455. typeexpr="tar archive" ;;
  456. *)
  457. echo "WARNING: Unkown file extension: $gzfile"
  458. typeexpr="." ;;
  459. esac
  460. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  461. then
  462. echo "ERROR: File type does not match" \
  463. "filename ($typeexpr)!"
  464. mv "$gzfile.incomplete" "$gzfile.extck-err"
  465. else
  466. mv "$gzfile.incomplete" "$gzfile"
  467. fi
  468. fi
  469. fi
  470. fi
  471. if [ ! -s "$gzfile" ]; then
  472. rm -f "$lkfile" ; trap INT ; return 1
  473. fi
  474. fi
  475. # Convert a .gz to .bz2 and test checksum
  476. #
  477. if [ "$gzfile" != "$bzfile" ] ; then
  478. echo "gzip->bzip2 + cksum-test: $gzfile"
  479. gunzip < "$gzfile" > src/down.$$.dat
  480. if cksum_chk src/down.$$.dat $cksum "$gzfile" ; then
  481. bzip2 < src/down.$$.dat > "$bzfile" ; rm -f "$gzfile"
  482. fi
  483. rm -f src/down.$$.dat
  484. # Execute a cksum test on a bzip2 file
  485. #
  486. elif [ "${gzfile%.bz2}" != "$gzfile" -o \
  487. "${gzfile%.tbz2}" != "$gzfile" ]
  488. then
  489. echo "cksum-test (bzip2): $bzfile"
  490. if [ $nocheck = 0 ] ; then
  491. bunzip2 < "$bzfile" > src/down.$$.dat
  492. cksum_chk src/down.$$.dat $cksum "$bzfile"
  493. fi
  494. rm -f src/down.$$.dat
  495. # Execute a cksum test on a raw data file
  496. #
  497. else
  498. echo "cksum-test (raw): $gzfile"
  499. cksum_chk "$gzfile" $cksum "$gzfile"
  500. fi
  501. # Free Lock and finish
  502. #
  503. rm -f "$lkfile" ; trap INT ; return 0
  504. }
  505. # handle_file filename
  506. #
  507. # This function fetches the checksum and download information
  508. # from the desc files and calls the download_file function.
  509. #
  510. handle_file() {
  511. # Handle pkg file (package/.../*.desc)
  512. #
  513. tree="`echo "$1" | cut -f2 -d/`"
  514. pkg="` echo "$1" | cut -f3 -d/`"
  515. file="`echo "$1" | cut -f4 -d/`"
  516. if grep -q "^\[D\].* $file " package/$tree/$pkg/$pkg.desc 2> /dev/null
  517. then
  518. grep "^\[D\].* $file " package/$tree/$pkg/$pkg.desc |
  519. while read tag cksum file url ; do
  520. download_file "$1" "$url" "$cksum"
  521. done
  522. return 0
  523. fi
  524. # Handle target file (target/.../download.txt)
  525. #
  526. target="`echo "$1" | cut -f2 -d/`"
  527. file="`echo "$1" | cut -f3- -d/`"
  528. if grep -q " $file " target/$target/download.txt 2> /dev/null
  529. then
  530. grep " $file " target/$target/download.txt |
  531. while read cksum file url ; do
  532. download_file "$1" "$url" "$cksum"
  533. done
  534. return 0
  535. fi
  536. # Handle misc file (scripts/miscdown.txt)
  537. #
  538. if [ "${1#download/misc/}" != "$1" ] ; then
  539. file="`echo "$1" | cut -f3- -d/`"
  540. if grep -q " $file " scripts/miscdown.txt
  541. then
  542. grep " $file " scripts/miscdown.txt |
  543. while read cksum file url ; do
  544. download_file "$1" "$url" "$cksum"
  545. done
  546. return 0
  547. fi
  548. fi
  549. # Can't handle file / file not found
  550. #
  551. return 1
  552. }
  553. list_cksums() {
  554. trap '' INT
  555. { grep -H '^\[D\] ' package/*/*/*.desc | tr '\t' ' ' | tr -s ' ' |
  556. sed -e 's,^package/,download/,;'
  557. grep -H '^[X0-9]' target/*/download.txt | tr '\t' ' ' | tr -s ' ' |
  558. sed -e 's,^target/,download/,; s,:,:[D] ,;'
  559. grep -H '^[X0-9]' scripts/miscdown.txt | tr '\t' ' ' | tr -s ' ' |
  560. sed 's,^scripts/,download/misc/,; s,:,:[D] ,;'
  561. } | sed 's,^\(.*/\)[^/:]*:[^ ]* \([X0-9]*\) ,\2 \1,;' | cut -f1,2 -d' '
  562. trap INT
  563. }
  564. list() {
  565. trap '' INT
  566. list_cksums | cut -f2- -d' '
  567. trap INT
  568. }
  569. list_unknown() {
  570. trap '' INT
  571. mkdir -p src/ ; list | sed 's,\.\(t\?\)gz$,.\1bz2,' > src/down.$$.lst
  572. ls download/{INDEX,README,DOWNTEST,LAST-UPDATE} \
  573. >> src/down.$$.lst 2> /dev/null
  574. find download/* -type f -o -type l | \
  575. while read fn ; do
  576. grep -qx "$fn" src/down.$$.lst || echo "Unknown file: $fn"
  577. done
  578. rm -f src/down.$$.lst
  579. trap INT
  580. }
  581. list_missing() {
  582. trap '' INT
  583. list | sed 's,\.\(t\?\)gz$,.\1bz2,' | \
  584. while read fn ; do
  585. [ -f "$fn" ] || echo "$fn"
  586. done
  587. trap INT
  588. }
  589. pattern() {
  590. for pattern ; do
  591. echo "Processing pattern $pattern ..."
  592. list | while read fn ; do
  593. if [ "${fn##$pattern}" = '' ] ; then
  594. echo "Matched: $fn"
  595. $0 $options "$fn"
  596. fi
  597. done
  598. done
  599. }
  600. package() {
  601. for package ; do
  602. pattern "download/*/$package/*"
  603. done
  604. }
  605. repository() {
  606. for repository ; do
  607. pattern "download/$repository/*"
  608. done
  609. }
  610. required() {
  611. while read on a b tree pkg c ; do
  612. if [ "$on" = "X" ] ; then
  613. grep -H '^\[D\] ' package/$tree/$pkg/$pkg.desc > src/down.$$.lst
  614. while read tag cksum file url ; do
  615. download_file "download/$tree/$pkg/$file" "$url" "$cksum"
  616. done < src/down.$$.lst ; rm -f src/down.$$.lst
  617. fi
  618. done < config/$config/packages
  619. target=`grep '^export ROCKCFG_TARGET=' config/$config/config | \
  620. cut -f2 -d= | tr -d "'"`
  621. if [ -f target/$target/download.txt ] ; then
  622. while read cksum file url ; do
  623. download_file "download/$target/$file" "$url" "$cksum"
  624. done < target/$target/download.txt
  625. fi
  626. }
  627. single_files() {
  628. for file_name ; do
  629. if ! handle_file "$file_name" ; then
  630. file_name="`echo "$file_name" | sed 's,\.\(t\?\)bz2$,.\1gz,'`"
  631. if ! handle_file "$file_name" ; then
  632. echo "ERROR: Unknown file: $file_name."
  633. fi
  634. fi
  635. done
  636. }
  637. all() {
  638. if [ $checkonly = 1 ] ; then list
  639. else list_missing ; fi > src/down.$$.lst
  640. while read fn ; do single_files $fn ; done < src/down.$$.lst
  641. rm -f src/down.$$.lst
  642. }
  643. case "$1" in
  644. -list) list ;;
  645. -list-unknown) list_unknown ;;
  646. -list-missing) list_missing ;;
  647. -list-cksums) list_cksums ;;
  648. -pattern) shift ; pattern "$@" ;;
  649. -package) shift ; package "$@" ;;
  650. -repository) shift ; repository "$@" ;;
  651. -required) required ;;
  652. -all) all ;;
  653. -*|"") exec $0 --help ;;
  654. *) single_files "$@" ;;
  655. esac
  656. exit 0