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.

816 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
  373. echo "INFO: download from mirror failed, trying direct."
  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. echo "cvs://$url/"
  449. # cvs://mode:loc::module!date/
  450. #
  451. mode="${url%%:*}"; loc="${url#*:}"
  452. module="${loc##*::}"; loc="${loc%%::*}"
  453. revision="${module#*!}"; module="${module%%!*}"
  454. [[ $loc != *@* ]] && loc="anonymous@$loc"
  455. echo "mode: $mode"
  456. echo "loc : $loc"
  457. echo "mod : $module"
  458. echo "rev : $revision"
  459. # everything after the first 'bang' (!) is analysed here
  460. # someday we could add more cvs options.
  461. #
  462. dat="$( echo $revision | \
  463. sed -n -e 's,\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\),-D \1,p' )"
  464. echo "date: $dat"
  465. cvsdir="src/down.cvsdir.`echo $bzfile | tr / -`"
  466. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  467. echo CVS $mode $loc $dat $module
  468. { [ $mode = ssh ] && export CVS_RSH=ssh
  469. [ $mode = pserver ] && loc=":pserver:$loc"
  470. # for ssh we need some way to quitely accept
  471. # the key ...
  472. echo cvs -z9 -Q -d $loc checkout $dat -P $module
  473. if ! cvs -z9 -Q -d $loc checkout $dat -P $module
  474. then touch .cvs_error ; fi
  475. } &> .cvs_output &
  476. while fuser .cvs_output &> /dev/null ; do
  477. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  478. 'CVS archive so far...\r'
  479. sleep 3
  480. done
  481. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  482. 'CVS archive (download finished).'
  483. if [ ! -f .cvs_error ] ; then
  484. cd `dirname $module`
  485. dir="`echo "$bzfile" | sed s/\.tar\.bz2$//`"
  486. dir="`basename $dir`"
  487. mv `basename $module` $dir
  488. tar --owner root --group root \
  489. --use-compress-program=bzip2 \
  490. -cf $dir.tar.bz2 $dir
  491. mv $dir.tar.bz2 $saved_pwd/$bzfile
  492. cd $saved_pwd ; rm -rf $cvsdir
  493. else
  494. cat .cvs_output
  495. cd $saved_pwd ; rm -rf $cvsdir
  496. echo ERROR: CVS $dat $loc $module \
  497. returned an error.
  498. echo "0 $gzfile $url" >> src/Download-Errors
  499. fi
  500. else
  501. if [ -s "$gzfile.incomplete" ] ; then
  502. echo "INFO: Trying to resume previous download .."
  503. resume="-C -"
  504. else
  505. resume=""
  506. fi
  507. 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"
  508. curlret="$?"
  509. if [ "$resume" ] && \
  510. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  511. echo "INFO: Resuming download not possible. ->" \
  512. "Overwriting old file."
  513. rm -f "$gzfile.incomplete"
  514. 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"
  515. curlret="$?"
  516. fi
  517. if [ $curlret -ne 0 ] ; then
  518. rm -f "$lkfile" ; trap INT
  519. case "$curlret" in
  520. 18)
  521. echo "WARNING: Got only some of the" \
  522. "file. A re-run of $0"
  523. echo "WARNING: is required to complete" \
  524. "the download." ;;
  525. 130)
  526. echo -e '\rWARNING: CURL got a SIGINT' \
  527. "(someone pressed Ctrl-C). A re-run of"
  528. echo "WARNING: $0 is required to complete" \
  529. "the download." ; sleep 1 ;;
  530. *)
  531. echo "$curlret $gzfile $url" \
  532. >> src/Download-Errors
  533. echo -e '\rERROR: CURL Returned Error' \
  534. "$curlret. Please read" \
  535. "the curl manpage." ;;
  536. esac
  537. return 1
  538. elif [ ! -s "$gzfile.incomplete" ] ; then
  539. echo "0 $gzfile $url" >> src/Download-Errors
  540. echo "ERROR: CURL returned success but" \
  541. "we have no data!"
  542. curlret=1
  543. else
  544. case "$gzfile" in
  545. *.gz|*.tgz)
  546. typeexpr="gzip compressed data" ;;
  547. *.bz2|*.tbz2)
  548. typeexpr="bzip2 compressed data" ;;
  549. *.Z|*.tZ)
  550. typeexpr="compress'd data" ;;
  551. *.zip|*.jar)
  552. typeexpr="Zip archive data" ;;
  553. *.tar)
  554. typeexpr="tar archive" ;;
  555. *)
  556. echo "WARNING: Unkown file extension: $gzfile"
  557. typeexpr="." ;;
  558. esac
  559. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  560. then
  561. echo "ERROR: File type does not match" \
  562. "filename ($typeexpr)!"
  563. mv "$gzfile.incomplete" "$gzfile.extck-err"
  564. else
  565. mv "$gzfile.incomplete" "$gzfile"
  566. fi
  567. fi
  568. fi
  569. }
  570. # handle_file filename
  571. #
  572. # This function fetches the checksum and download information
  573. # from the desc files and calls the download_file function.
  574. #
  575. handle_file() {
  576. # Handle pkg file (package/.../*.desc)
  577. #
  578. tree="`echo "$1" | cut -f2 -d/`"
  579. pkg="` echo "$1" | cut -f3 -d/`"
  580. file="`echo "$1" | cut -f4 -d/`"
  581. if grep -q "^\[D\].* $file " package/$tree/$pkg/$pkg.desc 2> /dev/null
  582. then
  583. grep "^\[D\].* $file " package/$tree/$pkg/$pkg.desc |
  584. while read tag cksum file url ; do
  585. download_file "$1" "$url" "$cksum"
  586. done
  587. return 0
  588. fi
  589. # Handle target file (target/.../download.txt)
  590. #
  591. target="`echo "$1" | cut -f2 -d/`"
  592. file="`echo "$1" | cut -f3- -d/`"
  593. if grep -q " $file " target/$target/download.txt 2> /dev/null
  594. then
  595. grep " $file " target/$target/download.txt |
  596. while read cksum file url ; do
  597. download_file "$1" "$url" "$cksum"
  598. done
  599. return 0
  600. fi
  601. # Handle misc file (scripts/miscdown.txt)
  602. #
  603. if [ "${1#download/misc/}" != "$1" ] ; then
  604. file="`echo "$1" | cut -f3- -d/`"
  605. if grep -q " $file " scripts/miscdown.txt
  606. then
  607. grep " $file " scripts/miscdown.txt |
  608. while read cksum file url ; do
  609. download_file "$1" "$url" "$cksum"
  610. done
  611. return 0
  612. fi
  613. fi
  614. # Can't handle file / file not found
  615. #
  616. return 1
  617. }
  618. list_cksums() {
  619. trap '' INT
  620. { grep -H '^\[D\] ' package/*/*/*.desc | tr '\t' ' ' | tr -s ' ' |
  621. sed -e 's,^package/,download/,;'
  622. grep -H '^[X0-9]' target/*/download.txt | tr '\t' ' ' | tr -s ' ' |
  623. sed -e 's,^target/,download/,; s,:,:[D] ,;'
  624. grep -H '^[X0-9]' scripts/miscdown.txt | tr '\t' ' ' | tr -s ' ' |
  625. sed 's,^scripts/,download/misc/,; s,:,:[D] ,;'
  626. } | sed 's,^\(.*/\)[^/:]*:[^ ]* \([X0-9]*\) ,\2 \1,;' | cut -f1,2 -d' '
  627. trap INT
  628. }
  629. list() {
  630. trap '' INT
  631. list_cksums | cut -f2- -d' '
  632. trap INT
  633. }
  634. list_unknown() {
  635. trap '' INT
  636. mkdir -p src/ ; list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' > src/down.$$.lst
  637. ls download/{INDEX,README,DOWNTEST,LAST-UPDATE} \
  638. >> src/down.$$.lst 2> /dev/null
  639. find download/* -type f -o -type l | \
  640. while read fn ; do
  641. grep -qx "$fn" src/down.$$.lst || echo "Unknown file: $fn"
  642. done
  643. rm -f src/down.$$.lst
  644. trap INT
  645. }
  646. list_missing() {
  647. trap '' INT
  648. list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' | \
  649. while read fn ; do
  650. [ -f "$fn" ] || echo "$fn"
  651. done
  652. trap INT
  653. }
  654. pattern() {
  655. for pattern ; do
  656. echo "Processing pattern $pattern ..."
  657. list | while read fn ; do
  658. if [ "${fn##$pattern}" = '' ] ; then
  659. echo "Matched: $fn"
  660. $0 $options "$fn"
  661. fi
  662. done
  663. done
  664. }
  665. package() {
  666. for package ; do
  667. pattern "download/*/$package/*"
  668. done
  669. }
  670. repository() {
  671. for repository ; do
  672. pattern "download/$repository/*"
  673. done
  674. }
  675. required() {
  676. while read on a b tree pkg c ; do
  677. if [ "$on" = "X" ] ; then
  678. grep -H '^\[D\] ' package/$tree/$pkg/$pkg.desc > src/down.$$.lst
  679. while read tag cksum file url ; do
  680. download_file "download/$tree/$pkg/$file" "$url" "$cksum"
  681. done < src/down.$$.lst ; rm -f src/down.$$.lst
  682. fi
  683. done < config/$config/packages
  684. target=`grep '^export ROCKCFG_TARGET=' config/$config/config | \
  685. cut -f2 -d= | tr -d "'"`
  686. if [ -f target/$target/download.txt ] ; then
  687. while read cksum file url ; do
  688. download_file "download/$target/$file" "$url" "$cksum"
  689. done < target/$target/download.txt
  690. fi
  691. }
  692. single_files() {
  693. for file_name ; do
  694. file_name_gz="`echo "$file_name" | sed 's,\.\(t\?\)bz2$,.\1gz,'`"
  695. file_name_Z="`echo "$file_name" | sed 's,\.\(t\?\)bz2$,.\1Z,'`"
  696. if ! handle_file "$file_name" && \
  697. ! handle_file "$file_name_gz" && \
  698. ! handle_file "$file_name_Z"
  699. then
  700. echo "ERROR: Unknown file: $file_name."
  701. fi
  702. done
  703. }
  704. all() {
  705. if [ $checkonly = 1 ] ; then list
  706. else list_missing ; fi > src/down.$$.lst
  707. while read fn ; do single_files $fn ; done < src/down.$$.lst
  708. rm -f src/down.$$.lst
  709. }
  710. # Do mirror detection only once
  711. #
  712. if [ $this_is_the_2nd_run = 0 ]; then
  713. detect_mirror
  714. fi
  715. case "$1" in
  716. -list) list ;;
  717. -list-unknown) list_unknown ;;
  718. -list-missing) list_missing ;;
  719. -list-cksums) list_cksums ;;
  720. -pattern) shift ; pattern "$@" ;;
  721. -package) shift ; package "$@" ;;
  722. -repository) shift ; repository "$@" ;;
  723. -required) required ;;
  724. -all) all ;;
  725. -*|"") exec $0 --help ;;
  726. *) single_files "$@" ;;
  727. esac
  728. exit 0