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.

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