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.

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