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.

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