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.

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