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.

825 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 --location'
  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. #Disable checking for certificates on https downloads
  174. curl_options="$curl_options -k"
  175. # cksum_chk filename cksum origfile
  176. #
  177. # This function verifies the checksum. If it fails it renames the file
  178. # to file.chksum-err and returns failure.
  179. #
  180. # It seams like the [ ] command has problems with comparing high numbers.
  181. # That's why I'm using a text comparison here.
  182. #
  183. # Not doing anything if checksum is '0' or a text of 'X'.
  184. #
  185. cksum_chk() {
  186. y="`echo $2 | sed 's,^0*,,;'`"
  187. [ $nocheck = 1 -o -z "$y" -o -z "${2//X/}" ] && return 0
  188. x="`cksum "$1" | cut -f1 -d' ' | sed 's,^0*,,;'`"
  189. if [ "$x" != "$y" ] ; then
  190. # Add .cksum-err extension to filename:
  191. echo "Cksum ERROR: $3.cksum-err ($x)"
  192. mv "$3" "$3.cksum-err" ; return 1
  193. fi
  194. return 0
  195. }
  196. # Autodetect best Mirror and safe url in $mirror
  197. #
  198. detect_mirror() {
  199. if [ -f download/Mirror ] ; then
  200. mirror="`cat download/Mirror`"
  201. if [ -z "$mirror" -o "$mirror" = "none" ] ; then
  202. echo "INFO: Found download/Mirror: none" \
  203. "(use the original download locations)"
  204. else
  205. echo "INFO: Found cached mirror URL in download/Mirror:"
  206. echo "INFO: $mirror"
  207. fi
  208. echo "INFO: To force a new mirror auto-detection, remove download/Mirror."
  209. else
  210. echo "INFO: Auto-detecting best mirror ..."
  211. eval "$(egrep '^(rockver)=' scripts/parse-config)"
  212. echo "INFO: Downloading mirror-list from www.rocklinux.net."
  213. curl -s -S $curl_options -o src/Download-Mirror-List \
  214. "http://www.rocklinux.net/mirrors.cgi?$rockver"
  215. bestval=0 ; result='No Mirror Found!'
  216. while read mirror_name ; do
  217. if [ "${mirror_name#=}" != "$mirror_name" ] ; then
  218. mirror_name="${mirror_name#= }"
  219. mirror_name="${mirror_name% =}"
  220. read mirror_url
  221. echo -n "INFO: Testing <$mirror_name> ..."
  222. val="$(curl -s $curl_options -m 20 "${mirror_url%/}/DOWNTEST" \
  223. -w "ok %{speed_download}" -o /dev/null)"
  224. if [ "$val" = "${val#ok }" -o "$val" = "ok 0.000" ] ; then
  225. echo " error"
  226. else
  227. xval=`echo ${val#ok } | tr -d .` ; echo " $val"
  228. if [ "$xval" -gt "$bestval" ] ; then
  229. bestval=$xval ; mirror="${mirror_url%/}"
  230. result="Using mirror <$mirror>."
  231. fi
  232. fi
  233. fi
  234. done < src/Download-Mirror-List
  235. echo $mirror > download/Mirror
  236. echo "INFO: $result"
  237. fi
  238. }
  239. # download_file local-filename download-location cksum
  240. #
  241. # This function decides if download directly or from a mirror,
  242. # validates checksum, etc.
  243. # Calls download_file_now to do the actual download.
  244. #
  245. download_file() {
  246. # Init
  247. #
  248. gzfile="$1" ; location="$2" ; cksum="$3"
  249. # Make src directory for creating tar balls
  250. mkdir -p src/
  251. # Tarball file name: (if you change this one - also adapt Create-ISO)
  252. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  253. # Lock file name:
  254. lkfile="src/down.lockfile.`echo $bzfile | tr / -`"
  255. # Check if it's already there
  256. #
  257. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  258. # Make locking
  259. #
  260. if [ -s "$lkfile" ]; then
  261. echo "Found $lkfile -> skip download."
  262. return 0
  263. fi
  264. trap 'rm -f "$lkfile"' INT
  265. echo $$ > "$lkfile"
  266. # Check if we only like to test the cksum(s)
  267. #
  268. if [ $checkonly = 1 ] ; then
  269. gzfile="$bzfile"
  270. if [ ! -f "$bzfile" ] ; then
  271. echo "File missing: $bzfile"
  272. rm -f "$lkfile" ; trap INT ; return 1
  273. fi
  274. if [ -z "${cksum##X*}" ] ; then
  275. echo "No checksum (ignore): $bzfile"
  276. rm -f "$lkfile" ; trap INT ; return 1
  277. fi
  278. if [ "$cksum" -eq 0 ] ; then
  279. echo "No checksum (missing): $bzfile"
  280. rm -f "$lkfile" ; trap INT ; return 1
  281. fi
  282. elif [ -s "$gzfile" ] ; then
  283. echo ; echo "Already downloaded $gzfile ..."
  284. else
  285. echo ; echo "Downloading $gzfile ..."
  286. # Existing *.cksum-err
  287. #
  288. if [ -s "$gzfile.cksum-err" ] ; then
  289. # cksum-err file alread exists:
  290. echo "ERROR: Found $gzfile.cksum-err."
  291. echo "ERROR: That means that we downloaded the" \
  292. "file already and it had an"
  293. echo "ERROR: incorrect checksum. Remove the" \
  294. "*.cksum-err file to force a"
  295. echo "ERROR: new download of that file."
  296. rm -f "$lkfile" ; trap INT ; return 1
  297. fi
  298. # Existing *.extck-err
  299. #
  300. if [ -s "$gzfile.extck-err" ] ; then
  301. # extck-err file alread exists:
  302. echo "ERROR: Found $gzfile.extck-err."
  303. echo "ERROR: That means that we downloaded the" \
  304. "file already and it's content"
  305. echo "ERROR: did not match it's filename extension." \
  306. "Remove the *.extck-err file"
  307. echo "ERROR: to force a new download of that file."
  308. rm -f "$lkfile" ; trap INT ; return 1
  309. fi
  310. # Questionable URL
  311. #
  312. if [ "$location" != "${location#\?}" ] ; then
  313. if [ "$tryques" = 0 ] ; then
  314. echo "ERROR: URL is marked as questionable." \
  315. "Not downloading this file."
  316. rm -f "$lkfile" ; trap INT ; return 1
  317. else
  318. echo "WARNING: URL is marked as questionable." \
  319. "Downloading it anyways."
  320. location="${location#\?}"
  321. fi
  322. fi
  323. # Make directory (if required)
  324. #
  325. if [ ! -d `dirname "$bzfile"` ] ; then
  326. mkdir -p `dirname "$bzfile"`
  327. fi
  328. # Alternative Directory
  329. #
  330. if [ "$altdir" ] ; then
  331. altfile=$(find $altdir/ -name `basename $bzfile` | head -n 1)
  332. else
  333. altfile=""
  334. fi
  335. if [ "$altfile" ] ; then
  336. echo "Found `basename $bzfile` as $altfile."
  337. cp -lv $altfile $bzfile ; gzfile="$bzfile"
  338. else
  339. # Mirroring
  340. #
  341. mirror="$( cat download/Mirror )"
  342. if [ "$mirror" -a "$mirror" != "none" ] ; then
  343. # try to use mirror
  344. if ! download_file_now "!$mirror/${bzfile#download/}" $bzfile $bzfile; then
  345. # oops... so try direct (original URL)
  346. echo "INFO: download from mirror failed, trying original URL."
  347. download_file_now $location $gzfile $bzfile
  348. else
  349. gzfile="$bzfile"
  350. fi
  351. else
  352. # don't want to use mirror
  353. download_file_now $location $gzfile $bzfile
  354. fi
  355. fi
  356. if [ ! -s "$gzfile" ]; then
  357. rm -f "$lkfile" ; trap INT ; return 1
  358. fi
  359. fi
  360. # Convert a .gz to .bz2 and test checksum
  361. #
  362. if [ "$gzfile" != "$bzfile" ] ; then
  363. echo "bzip'ing + cksum-test: $gzfile"
  364. gunzip < "$gzfile" > src/down.$$.dat
  365. if cksum_chk src/down.$$.dat $cksum "$gzfile" ; then
  366. bzip2 < src/down.$$.dat > "$bzfile" ; rm -f "$gzfile"
  367. fi
  368. rm -f src/down.$$.dat
  369. # Execute a cksum test on a bzip2 file
  370. #
  371. elif [ "${gzfile%.bz2}" != "$gzfile" -o \
  372. "${gzfile%.tbz2}" != "$gzfile" ]
  373. then
  374. echo "cksum-test (bzip2): $bzfile"
  375. if [ $nocheck = 0 ] ; then
  376. bunzip2 < "$bzfile" > src/down.$$.dat
  377. cksum_chk src/down.$$.dat $cksum "$bzfile"
  378. fi
  379. rm -f src/down.$$.dat
  380. # Execute a cksum test on a raw data file
  381. #
  382. else
  383. echo "cksum-test (raw): $gzfile"
  384. cksum_chk "$gzfile" $cksum "$gzfile"
  385. fi
  386. # Free Lock and finish
  387. #
  388. rm -f "$lkfile" ; trap INT ; return 0
  389. }
  390. # download_file_now location remote_filename local_filename
  391. #
  392. # This function executes the actual download using curl.
  393. #
  394. download_file_now() {
  395. local location="$1" gzfile="$2" bzfile="$3"
  396. # Create URL
  397. #
  398. if [ "${location#!}" != "$location" ] ; then
  399. url="`echo "$location" | sed 's,!,,'`"
  400. else
  401. url="`echo "$location" | \
  402. sed 's,/[^/]*$,,'`/`echo $gzfile | sed 's,.*/,,'`"
  403. fi
  404. # Check for existing Error Log
  405. #
  406. if test -s src/Download-Errors &&
  407. grep -q " $url\$" src/Download-Errors ; then
  408. echo "ERROR: According to src/Download-Errors" \
  409. "we had already an error for that URL."
  410. echo "ERROR: So I'm not trying to download" \
  411. "it again (remove src/Download-Errors"
  412. echo "ERROR: if you want to force a retry)."
  413. return 1
  414. fi
  415. # Download
  416. #
  417. if [[ $url = cvs://* ]] ; then
  418. # cvs://mode:[login[:password]@]server[:port]:/path::module!revision/
  419. # btw, at least current cvs supports password at CVSROOT.
  420. url="${url#cvs://}"; url="${url%/*}"
  421. # cvs://mode:loc::module!date/
  422. #
  423. mode="${url%%:*}"; loc="${url#*:}"
  424. module="${loc##*::}"; loc="${loc%%::*}"
  425. revision="${module#*!}"; module="${module%%!*}"
  426. [[ $loc != *@* ]] && loc="anonymous@$loc"
  427. # everything after the first 'bang' (!) is analysed here
  428. # someday we could add more cvs options.
  429. #
  430. dat="$( echo $revision | \
  431. sed -n -e 's,\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\),-D \1,p' )"
  432. cvsdir="src/down.cvsdir.`echo $bzfile | tr / -`"
  433. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  434. echo CVS $mode $loc $dat $module
  435. { [ $mode = ssh ] && export CVS_RSH=ssh
  436. [ $mode = pserver ] && loc=":pserver:$loc"
  437. # sometimes cvs wants to read ~/.cvspass just for fun ..
  438. touch $HOME/.cvspass
  439. # for ssh we need some way to quitely accept the key ...
  440. echo cvs -z9 -Q -d $loc checkout $dat -P $module
  441. if ! cvs -z9 -Q -d $loc checkout $dat -P $module
  442. then touch .cvs_error ; fi
  443. } &> .cvs_output &
  444. while fuser .cvs_output &> /dev/null ; do
  445. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  446. 'CVS archive so far...\r'
  447. sleep 3
  448. done
  449. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  450. 'CVS archive (download finished).'
  451. if [ ! -f .cvs_error ] ; then
  452. cd `dirname $module`
  453. dir="`echo "$bzfile" | sed s/\.tar\.bz2$//`"
  454. dir="`basename $dir`"
  455. mv `basename $module` $dir
  456. tar --owner root --group root \
  457. --use-compress-program=bzip2 \
  458. -cf $dir.tar.bz2 $dir
  459. mv $dir.tar.bz2 $saved_pwd/$bzfile
  460. cd $saved_pwd ; rm -rf $cvsdir
  461. else
  462. cat .cvs_output
  463. cd $saved_pwd ; rm -rf $cvsdir
  464. echo ERROR: CVS $dat $loc $module \
  465. returned an error.
  466. echo "0 $gzfile $url" >> src/Download-Errors
  467. fi
  468. else
  469. if [ -s "$gzfile.incomplete" ] ; then
  470. echo "INFO: Trying to resume previous download .."
  471. resume="-C -"
  472. else
  473. resume=""
  474. fi
  475. 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"
  476. curlret="$?"
  477. if [ "$resume" ] && \
  478. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  479. echo "INFO: Resuming download not possible. ->" \
  480. "Overwriting old file."
  481. rm -f "$gzfile.incomplete"
  482. 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"
  483. curlret="$?"
  484. fi
  485. if [ $curlret -ne 0 ] ; then
  486. case "$curlret" in
  487. 18)
  488. echo "WARNING: Got only some of the" \
  489. "file. A re-run of $0"
  490. echo "WARNING: is required to complete" \
  491. "the download." ;;
  492. 130)
  493. echo -e '\rWARNING: CURL got a SIGINT' \
  494. "(someone pressed Ctrl-C). A re-run of"
  495. echo "WARNING: $0 is required to complete" \
  496. "the download." ; sleep 1 ;;
  497. *)
  498. echo "$curlret $gzfile $url" \
  499. >> src/Download-Errors
  500. echo -e '\rERROR: CURL Returned Error' \
  501. "$curlret. Please read" \
  502. "the curl manpage." ;;
  503. esac
  504. return 1
  505. elif [ ! -s "$gzfile.incomplete" ] ; then
  506. echo "0 $gzfile $url" >> src/Download-Errors
  507. echo "ERROR: CURL returned success but" \
  508. "we have no data!"
  509. curlret=1
  510. else
  511. case "$gzfile" in
  512. *.gz|*.tgz)
  513. typeexpr="gzip compressed data" ;;
  514. *.bz2|*.tbz2)
  515. typeexpr="bzip2 compressed data" ;;
  516. *.Z|*.tZ)
  517. typeexpr="compress'd data" ;;
  518. *.zip|*.jar)
  519. typeexpr="Zip archive data" ;;
  520. *.tar)
  521. typeexpr="tar archive" ;;
  522. *)
  523. echo "WARNING: Unkown file extension: $gzfile"
  524. typeexpr="." ;;
  525. esac
  526. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  527. then
  528. echo "ERROR: File type does not match" \
  529. "filename ($typeexpr)!"
  530. mv "$gzfile.incomplete" "$gzfile.extck-err"
  531. else
  532. mv "$gzfile.incomplete" "$gzfile"
  533. fi
  534. fi
  535. fi
  536. }
  537. # handle_file filename
  538. #
  539. # This function fetches the checksum and download information
  540. # from the desc files and calls the download_file function.
  541. #
  542. handle_file() {
  543. # Handle pkg file (package/.../*.desc)
  544. #
  545. tree="`echo "$1" | cut -f2 -d/`"
  546. pkg="` echo "$1" | cut -f3 -d/`"
  547. file="`echo "$1" | cut -f4 -d/`"
  548. if grep -q "^\[D\].* $file " package/$tree/$pkg/$pkg.desc 2> /dev/null
  549. then
  550. grep "^\[D\].* $file " package/$tree/$pkg/$pkg.desc |
  551. while read tag cksum file url ; do
  552. download_file "$1" "$url" "$cksum"
  553. done
  554. return 0
  555. fi
  556. # Handle target file (target/.../download.txt)
  557. #
  558. target="`echo "$1" | cut -f2 -d/`"
  559. file="`echo "$1" | cut -f3- -d/`"
  560. if grep -q " $file " target/$target/download.txt 2> /dev/null
  561. then
  562. grep " $file " target/$target/download.txt |
  563. while read cksum file url ; do
  564. download_file "$1" "$url" "$cksum"
  565. done
  566. return 0
  567. fi
  568. # Handle misc file (scripts/miscdown.txt)
  569. #
  570. if [ "${1#download/misc/}" != "$1" ] ; then
  571. file="`echo "$1" | cut -f3- -d/`"
  572. if grep -q " $file " scripts/miscdown.txt
  573. then
  574. grep " $file " scripts/miscdown.txt |
  575. while read cksum file url ; do
  576. download_file "$1" "$url" "$cksum"
  577. done
  578. return 0
  579. fi
  580. fi
  581. # Can't handle file / file not found
  582. #
  583. return 1
  584. }
  585. list_cksums() {
  586. trap '' INT
  587. { grep -H '^\[D\] ' package/*/*/*.desc | tr '\t' ' ' | tr -s ' ' |
  588. sed -e 's,^package/,download/,;'
  589. grep -H '^[X0-9]' target/*/download.txt | tr '\t' ' ' | tr -s ' ' |
  590. sed -e 's,^target/,download/,; s,:,:[D] ,;'
  591. grep -H '^[X0-9]' scripts/miscdown.txt | tr '\t' ' ' | tr -s ' ' |
  592. sed 's,^scripts/,download/misc/,; s,:,:[D] ,;'
  593. } | sed 's,^\(.*/\)[^/:]*:[^ ]* \([X0-9]*\) ,\2 \1,;' | cut -f1,2 -d' '
  594. trap INT
  595. }
  596. list() {
  597. trap '' INT
  598. list_cksums | cut -f2- -d' '
  599. trap INT
  600. }
  601. list_unknown() {
  602. trap '' INT
  603. mkdir -p src/ ; list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' > src/down.$$.lst
  604. ls download/{INDEX,README,DOWNTEST,LAST-UPDATE} \
  605. >> src/down.$$.lst 2> /dev/null
  606. find download/* -type f -o -type l | grep -v -e download/Mirror \
  607. -e download/Proxy -e download/Proxy-auth | \
  608. while read fn ; do
  609. grep -qx "$fn" src/down.$$.lst || echo "Unknown file: $fn"
  610. done
  611. rm -f src/down.$$.lst
  612. trap INT
  613. }
  614. list_missing() {
  615. trap '' INT
  616. list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' | \
  617. while read fn ; do
  618. [ -f "$fn" ] || echo "$fn"
  619. done
  620. trap INT
  621. }
  622. pattern() {
  623. for pattern ; do
  624. echo "Processing pattern $pattern ..."
  625. list | while read fn ; do
  626. if [ "${fn##$pattern}" = '' ] ; then
  627. echo "Matched: $fn"
  628. $0 $options "$fn"
  629. fi
  630. done
  631. done
  632. }
  633. package() {
  634. for package ; do
  635. pattern "download/*/$package/*"
  636. done
  637. }
  638. repository() {
  639. for repository ; do
  640. pattern "download/$repository/*"
  641. done
  642. }
  643. required() {
  644. # Choosen config must exist
  645. #
  646. if [ ! -f config/$config/packages ]; then
  647. echo "ERROR: Config $config doesn't exist."
  648. echo "ERROR: try ./scripts/Config -cfg $config first."
  649. exit 1
  650. fi
  651. while read on a b tree pkg c ; do
  652. if [ "$on" = "X" ] ; then
  653. grep -H '^\[D\] ' package/$tree/$pkg/$pkg.desc > src/down.$$.lst
  654. while read tag cksum file url ; do
  655. download_file "download/$tree/$pkg/$file" "$url" "$cksum"
  656. done < src/down.$$.lst ; rm -f src/down.$$.lst
  657. fi
  658. done < config/$config/packages
  659. target=`grep '^export ROCKCFG_TARGET=' config/$config/config | \
  660. cut -f2 -d= | tr -d "'"`
  661. if [ -f target/$target/download.txt ] ; then
  662. while read cksum file url ; do
  663. download_file "download/$target/$file" "$url" "$cksum"
  664. done < target/$target/download.txt
  665. fi
  666. }
  667. single_files() {
  668. for file_name ; do
  669. file_name_gz="`echo "$file_name" | sed 's,\.\(t\?\)bz2$,.\1gz,'`"
  670. file_name_Z="`echo "$file_name" | sed 's,\.\(t\?\)bz2$,.\1Z,'`"
  671. if ! handle_file "$file_name" && \
  672. ! handle_file "$file_name_gz" && \
  673. ! handle_file "$file_name_Z"
  674. then
  675. echo "ERROR: Unknown file: $file_name."
  676. fi
  677. done
  678. }
  679. all() {
  680. if [ $checkonly = 1 ] ; then list
  681. else list_missing ; fi > src/down.$$.lst
  682. while read fn ; do single_files $fn ; done < src/down.$$.lst
  683. rm -f src/down.$$.lst
  684. }
  685. # Things to do only for downloading
  686. #
  687. if [ "${1:0:5}" != "-list" -a $checkonly = 0 ]; then
  688. # Set proxy information
  689. if [ -f download/Proxy ]; then
  690. proxy="`cat download/Proxy`"
  691. if [ "$proxy" ]; then
  692. curl_options="$curl_options --proxy $proxy"
  693. else
  694. echo "INFO: No proxy information... removing download/Proxy."
  695. rm download/Proxy
  696. fi
  697. fi
  698. if [ -f download/Proxy-auth ]; then
  699. proxyauth="`cat download/Proxy-auth`"
  700. if [ "$proxyauth" ]; then
  701. curl_options="$curl_options --proxy-user $proxyauth"
  702. else
  703. echo "INFO: No proxy-auth information... removing download/Proxy-auth."
  704. rm download/Proxy-auth
  705. fi
  706. fi
  707. # Thing to do only once
  708. #
  709. if [ $this_is_the_2nd_run = 0 ]; then
  710. # am i using a proxy?
  711. # -- say i'm doing it even when i already did ;-)
  712. if [ "$proxy" ]; then
  713. echo "INFO: Setting proxy to $proxy."
  714. fi
  715. if [ "$proxyauth" ]; then
  716. echo "INFO: Setting proxy authentication information."
  717. fi
  718. # do mirror detection
  719. detect_mirror
  720. fi
  721. fi
  722. case "$1" in
  723. -list) list ;;
  724. -list-unknown) list_unknown ;;
  725. -list-missing) list_missing ;;
  726. -list-cksums) list_cksums ;;
  727. -pattern) shift ; pattern "$@" ;;
  728. -package) shift ; package "$@" ;;
  729. -repository) shift ; repository "$@" ;;
  730. -required) required ;;
  731. -all) all ;;
  732. -*|"") exec $0 --help ;;
  733. *) single_files "$@" ;;
  734. esac
  735. exit 0