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.

1055 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 - 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 ] [ -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. y="`echo $2 | sed 's,^0*,,;'`"
  252. [ $nocheck = 1 -o -z "$y" -o -z "${2//X/}" ] && return 0
  253. x="`cksum "$1" | cut -f1 -d' ' | sed 's,^0*,,;'`"
  254. if [ "$x" != "$y" ] ; then
  255. # Add .cksum-err extension to filename:
  256. echo "Cksum ERROR: $3.cksum-err ($x)"
  257. mv "$3" "$3.cksum-err" ; return 1
  258. fi
  259. return 0
  260. }
  261. # Autodetect best Mirror and safe url in $mirror
  262. #
  263. detect_mirror() {
  264. if [ -n "$mirror" -a "$mirror" != "auto" ] ; then
  265. if [ "$mirror" = "none" ] ; then
  266. echo "INFO: Using download mirror: none" \
  267. "(use the original download locations)" 1>&2
  268. else
  269. echo "INFO: Using download mirror:" 1>&2
  270. echo "INFO: $mirror" 1>&2
  271. fi
  272. echo "INFO: To force a new mirror auto-detection, use '-mirror auto'." 1>&2
  273. else
  274. echo "INFO: Auto-detecting best mirror ..." 1>&2
  275. eval "$(egrep '^(rockver)=' scripts/parse-config)"
  276. echo "INFO: Downloading mirror-list from www.rocklinux.net." 1>&2
  277. curl -s -S $curl_options -o src/Download-Mirror-List \
  278. "http://www.rocklinux.net/mirrors.cgi?$rockver"
  279. bestval=0 ; result='No Mirror Found!'
  280. while read mirror_name ; do
  281. if [ "${mirror_name#=}" != "$mirror_name" ] ; then
  282. mirror_name="${mirror_name#= }"
  283. mirror_name="${mirror_name% =}"
  284. read mirror_url
  285. echo -n "INFO: Testing <$mirror_name> ..." 1>&2
  286. val="$(curl -s $curl_options -m 20 "${mirror_url%/}/DOWNTEST" \
  287. -w "ok %{speed_download}" -o /dev/null)"
  288. if [ "$val" = "${val#ok }" -o "$val" = "ok 0.000" -o "$val" = "ok 0,000" ] ; then
  289. echo " error"
  290. else
  291. xval=`echo ${val#ok } | tr -d .,` ; echo " $val"
  292. if [ "$xval" -gt "$bestval" ] ; then
  293. bestval=$xval ; mirror="${mirror_url%/}"
  294. result="Using mirror <$mirror>."
  295. fi
  296. fi
  297. fi
  298. done < src/Download-Mirror-List
  299. echo $mirror > download/Mirror
  300. echo "INFO: $result" 1>&2
  301. fi
  302. }
  303. # Check if static download location is available
  304. #
  305. is_static() {
  306. local repo="$1" pkg="$2" gzfile="$3" url="$4"
  307. local file="package/$repo/$pkg/$pkg.desc"
  308. local pattern="^\[D\].*${gzfile##*/}.*NOAUTO"
  309. if [ "`grep "$file" -e"$pattern"`" != "" ]; then
  310. mkdir -p "${gzfile%/*}"
  311. echo "INFO: File ${gzfile##*/} needs to be downloaded manually."
  312. echo "INFO: Download the file from"
  313. echo "INFO: $url"
  314. echo "INFO: and place it in ${gzfile%/*}"
  315. return 1
  316. fi
  317. return 0
  318. }
  319. # download_file local-filename download-location cksum repo pkg
  320. #
  321. # This function decides if download directly or from a mirror,
  322. # validates checksum, etc.
  323. # Calls download_file_now to do the actual download.
  324. #
  325. download_file() {
  326. # Init
  327. #
  328. local gzfile="$1" location="$2" cksum="$3" repo="$4" pkg="$5"
  329. # Make src directory for creating tar balls
  330. mkdir -p src/
  331. # Tarball file name: (if you change this one - also adapt Create-ISO)
  332. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  333. # Lock file name:
  334. lkfile="src/down.lockfile.`echo $bzfile | tr / -`"
  335. # Check if it's already there
  336. #
  337. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  338. # Make locking
  339. #
  340. if [ -s "$lkfile" ]; then
  341. echo "Found $lkfile -> skip download."
  342. return 0
  343. fi
  344. trap 'rm -f "$lkfile"' INT
  345. echo $$ > "$lkfile"
  346. # Check if we only like to test the cksum(s)
  347. #
  348. if [ $checkonly = 1 ] ; then
  349. gzfile="$bzfile"
  350. if [ ! -f "$bzfile" ] ; then
  351. echo "File missing: $bzfile"
  352. rm -f "$lkfile" ; trap INT ; return 1
  353. fi
  354. if [ -z "${cksum##X*}" ] ; then
  355. echo "No checksum (ignore): $bzfile"
  356. rm -f "$lkfile" ; trap INT ; return 1
  357. fi
  358. if [ "$cksum" -eq 0 ] ; then
  359. echo "No checksum (missing): $bzfile"
  360. rm -f "$lkfile" ; trap INT ; return 1
  361. fi
  362. elif [ -s "$gzfile" ] ; then
  363. echo ; echo "Already downloaded $gzfile ..."
  364. else
  365. echo ; echo "Downloading $gzfile ..."
  366. # Existing *.cksum-err
  367. #
  368. if [ -s "$gzfile.cksum-err" ] ; then
  369. # cksum-err file alread exists:
  370. echo "ERROR: Found $gzfile.cksum-err."
  371. echo "ERROR: That means that we downloaded the" \
  372. "file already and it had an"
  373. echo "ERROR: incorrect checksum. Remove the" \
  374. "*.cksum-err file to force a"
  375. echo "ERROR: new download of that file."
  376. rm -f "$lkfile" ; trap INT ; return 1
  377. fi
  378. # Existing *.extck-err
  379. #
  380. if [ -s "$gzfile.extck-err" ] ; then
  381. # extck-err file alread exists:
  382. echo "ERROR: Found $gzfile.extck-err."
  383. echo "ERROR: That means that we downloaded the" \
  384. "file already and it's content"
  385. echo "ERROR: did not match it's filename extension." \
  386. "Remove the *.extck-err file"
  387. echo "ERROR: to force a new download of that file."
  388. rm -f "$lkfile" ; trap INT ; return 1
  389. fi
  390. # Questionable URL
  391. #
  392. if [ "$location" != "${location#\?}" ] ; then
  393. if [ "$tryques" = 0 ] ; then
  394. echo "ERROR: URL is marked as questionable." \
  395. "Not downloading this file."
  396. rm -f "$lkfile" ; trap INT ; return 1
  397. else
  398. echo "WARNING: URL is marked as questionable." \
  399. "Downloading it anyways."
  400. location="${location#\?}"
  401. fi
  402. fi
  403. # Make directory (if required)
  404. #
  405. if [ ! -d `dirname "$bzfile"` ] ; then
  406. mkdir -p `dirname "$bzfile"`
  407. fi
  408. # Alternative Directory
  409. #
  410. if [ "$altdir" ] ; then
  411. altfile=$(find $altdir/ -name `basename $bzfile` | head -n 1)
  412. else
  413. altfile=""
  414. fi
  415. #FIXME: compatibility, can be removed sooner or later...
  416. # Check old download dir layout
  417. if [ -z "$altfile" ]; then
  418. if [ -f "download/$repo${pkg:+/}$pkg/`basename $bzfile`" ]; then
  419. altfile="download/$repo${pkg:+/}$pkg/`basename $bzfile`"
  420. fi
  421. fi
  422. if [ "$altfile" ] ; then
  423. echo "Found `basename $bzfile` as $altfile."
  424. if [ "$altcopy" = 'link' ]; then
  425. cp -lv $altfile $bzfile
  426. elif [ "$altcopy" = 'copy' ]; then
  427. cp -v $altfile $bzfile
  428. elif [ "$altcopy" = 'move' ]; then
  429. mv -v $altfile $bzfile
  430. fi
  431. gzfile="$bzfile"
  432. else
  433. # Mirroring
  434. #
  435. if [ -n "$mirror" -a "$mirror" != "none" -a -z "${bzfile##download/mirror/*}" ] ; then
  436. # try to use mirror
  437. if ! download_file_now "!$mirror/${bzfile#download/mirror/}" $bzfile $bzfile; then
  438. echo "INFO: download from mirror failed, trying original URL." 1>&2
  439. if ! is_static $repo $pkg "$gzfile" "$location"; then
  440. rm -f "$lkfile" ; trap INT ; return 1
  441. fi
  442. download_file_now $location $gzfile $bzfile
  443. else
  444. gzfile="$bzfile"
  445. fi
  446. else
  447. # don't want to use mirror
  448. if ! is_static $repo $pkg "$gzfile" "$location"; then
  449. rm -f "$lkfile" ; trap INT ; return 1
  450. fi
  451. download_file_now $location $gzfile $bzfile
  452. fi
  453. fi
  454. if [ ! -s "$gzfile" ]; then
  455. rm -f "$lkfile" ; trap INT ; return 1
  456. fi
  457. fi
  458. # Convert a .gz to .bz2 and test checksum
  459. #
  460. if [ "$gzfile" != "$bzfile" ] ; then
  461. echo "bzip'ing + cksum-test: $gzfile"
  462. gunzip < "$gzfile" > src/down.$$.dat
  463. if cksum_chk src/down.$$.dat $cksum "$gzfile" ; then
  464. bzip2 < src/down.$$.dat > "$bzfile" ; rm -f "$gzfile"
  465. fi
  466. rm -f src/down.$$.dat
  467. # Execute a cksum test on a bzip2 file
  468. #
  469. elif [ "${gzfile%.bz2}" != "$gzfile" -o \
  470. "${gzfile%.tbz2}" != "$gzfile" ]
  471. then
  472. echo "cksum-test (bzip2): $bzfile"
  473. if [ $nocheck = 0 ] ; then
  474. bunzip2 < "$bzfile" > src/down.$$.dat
  475. cksum_chk src/down.$$.dat $cksum "$bzfile"
  476. fi
  477. rm -f src/down.$$.dat
  478. # Execute a cksum test on a raw data file
  479. #
  480. else
  481. echo "cksum-test (raw): $gzfile"
  482. cksum_chk "$gzfile" $cksum "$gzfile"
  483. fi
  484. # Free Lock and finish
  485. #
  486. rm -f "$lkfile" ; trap INT ; return 0
  487. }
  488. # download_file_now location remote_filename local_filename
  489. #
  490. # This function executes the actual download using curl.
  491. #
  492. download_file_now() {
  493. local location="$1" gzfile="$2" bzfile="$3"
  494. # Create URL
  495. #
  496. if [ "${location#!}" != "$location" ] ; then
  497. url="`echo "$location" | sed 's,!,,'`"
  498. else
  499. url="`echo "$location" | \
  500. sed 's,/[^/]*$,,'`/`echo $gzfile | sed 's,.*/,,'`"
  501. fi
  502. # Check for existing Error Log
  503. #
  504. if test -s src/Download-Errors &&
  505. grep -q " $url\$" src/Download-Errors ; then
  506. echo "ERROR: According to src/Download-Errors" \
  507. "we had already an error for the URL"
  508. echo "ERROR: $url"
  509. echo "ERROR: So I'm not trying to download" \
  510. "it again (remove src/Download-Errors"
  511. echo "ERROR: if you want to force a retry)."
  512. return 1
  513. fi
  514. # Download
  515. #
  516. if [[ $url = svn://* ]] ; then
  517. # svn://mode:[login[:password]@]server[:port]:/path::revision/
  518. urlorig=${url}
  519. url=${location#!}
  520. url="${url#svn://}"; url="${url%/}"
  521. mode="${url%%:*}"
  522. url="${url#*:}"
  523. if [ "${url%@*}" = "${url}" ] ; then
  524. username=""
  525. password=""
  526. else
  527. username="${url%%@*}"
  528. if [ "${username%:*}" != "${username}" ] ; then
  529. password="--password ${username#*:}"
  530. username="${username%%:*}"
  531. fi
  532. username="--username ${username}"
  533. fi
  534. url="${url##*@}"
  535. rev="${url##*::}"
  536. if [ -z "${rev}" -o "${rev}" == "${url}" ] ; then
  537. rev=""
  538. else
  539. rev="-r ${rev}"
  540. fi
  541. url="${url%::*}"
  542. old=${PWD}
  543. tmp="`mktemp`"
  544. rm -rf ${tmp}
  545. dir=${bzfile%.tar.bz2}
  546. dir="`basename ${dir}`"
  547. mkdir -p ${tmp}
  548. cd ${tmp}
  549. echo SVN ${username} ${password} ${rev} ${mode}://${url}
  550. { echo svn export ${username} ${password} ${rev} ${mode}://${url} ${dir}
  551. if ! svn export ${username} ${password} ${rev} ${mode}://${url} ${dir}
  552. then touch .svn_error ; fi
  553. } &> .svn_output &
  554. while fuser .svn_output &> /dev/null ; do
  555. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  556. 'SVN archive so far...\r'
  557. sleep 3
  558. done
  559. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  560. 'SVN archive (download finished).'
  561. if [ ! -f .svn_error ] ; then
  562. rm -f .svn_output
  563. tar --owner root --group root \
  564. --use-compress-program=bzip2 \
  565. -cf ${dir}.tar.bz2 ${dir}
  566. mv ${dir}.tar.bz2 ${old}/${bzfile}
  567. cd ${old} ; rm -rf ${tmp}
  568. else
  569. cat .svn_output
  570. cd $old ; rm -rf $tmp
  571. echo ERROR: SVN export ${username} ${password} ${mode}://${url} ${dir} \
  572. returned an error.
  573. echo "0 $gzfile $urlorig" >> src/Download-Errors
  574. fi
  575. elif [[ $url = cvs://* ]] ; then
  576. # cvs://mode:[login[:password]@]server[:port]:/path::module!revision/
  577. # btw, at least current cvs supports password at CVSROOT.
  578. url="${url#cvs://}"; url="${url%/*}"
  579. # cvs://mode:loc::module!date/
  580. #
  581. mode="${url%%:*}"; loc="${url#*:}"
  582. module="${loc##*::}"; loc="${loc%%::*}"
  583. revision="${module#*!}"; module="${module%%!*}"
  584. [[ $loc != *@* ]] && loc="anonymous@$loc"
  585. # everything after the first 'bang' (!) is analysed here
  586. # someday we could add more cvs options.
  587. #
  588. dat="$( echo $revision | \
  589. sed -n -e 's,\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\),-D \1,p' )"
  590. cvsdir="src/down.cvsdir.`echo $bzfile | tr / -`"
  591. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  592. echo CVS $mode $loc $dat $module
  593. { [ $mode = ssh ] && export CVS_RSH=ssh
  594. [ $mode = pserver ] && loc=":pserver:$loc"
  595. # sometimes cvs wants to read ~/.cvspass just for fun ..
  596. touch $HOME/.cvspass
  597. # for ssh we need some way to quitely accept the key ...
  598. echo cvs -z9 -Q -d $loc checkout $dat -P $module
  599. if ! cvs -z9 -Q -d $loc checkout $dat -P $module
  600. then touch .cvs_error ; fi
  601. } &> .cvs_output &
  602. while fuser .cvs_output &> /dev/null ; do
  603. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  604. 'CVS archive so far...\r'
  605. sleep 3
  606. done
  607. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  608. 'CVS archive (download finished).'
  609. if [ ! -f .cvs_error ] ; then
  610. cd `dirname $module`
  611. dir="`echo "$bzfile" | sed s/\.tar\.bz2$//`"
  612. dir="`basename $dir`"
  613. mv `basename $module` $dir
  614. tar --owner root --group root \
  615. --use-compress-program=bzip2 \
  616. -cf $dir.tar.bz2 $dir
  617. mv $dir.tar.bz2 $saved_pwd/$bzfile
  618. cd $saved_pwd ; rm -rf $cvsdir
  619. else
  620. cat .cvs_output
  621. cd $saved_pwd ; rm -rf $cvsdir
  622. echo ERROR: CVS $dat $loc $module \
  623. returned an error.
  624. echo "0 $gzfile $url" >> src/Download-Errors
  625. fi
  626. else
  627. if [ -s "$gzfile.incomplete" ] ; then
  628. echo "INFO: Trying to resume previous download .." 1>&2
  629. resume="-C -"
  630. else
  631. resume=""
  632. fi
  633. 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"
  634. curlret="$?"
  635. if [ "$resume" ] && \
  636. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  637. echo "INFO: Resuming download not possible. ->" \
  638. "Overwriting old file." 1>&2
  639. rm -f "$gzfile.incomplete"
  640. 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"
  641. curlret="$?"
  642. fi
  643. if [ $curlret -ne 0 ] ; then
  644. case "$curlret" in
  645. 18)
  646. echo "WARNING: Got only some of the" \
  647. "file. A re-run of $0"
  648. echo "WARNING: is required to complete" \
  649. "the download." ;;
  650. 130)
  651. echo -e '\rWARNING: CURL got a SIGINT' \
  652. "(someone pressed Ctrl-C). A re-run of"
  653. echo "WARNING: $0 is required to complete" \
  654. "the download." ; sleep 1 ;;
  655. *)
  656. echo "$curlret $gzfile $url" \
  657. >> src/Download-Errors
  658. echo -e '\rERROR: CURL Returned Error' \
  659. "$curlret. Please read" \
  660. "the curl manpage." ;;
  661. esac
  662. return 1
  663. elif [ ! -s "$gzfile.incomplete" ] ; then
  664. echo "0 $gzfile $url" >> src/Download-Errors
  665. echo "ERROR: CURL returned success but" \
  666. "we have no data!"
  667. curlret=1
  668. else
  669. case "$gzfile" in
  670. *.gz|*.tgz)
  671. typeexpr="gzip compressed data" ;;
  672. *.bz2|*.tbz2)
  673. typeexpr="bzip2 compressed data" ;;
  674. *.Z|*.tZ)
  675. typeexpr="compress'd data" ;;
  676. *.zip|*.jar)
  677. typeexpr="Zip archive data" ;;
  678. *.tar)
  679. typeexpr="tar archive" ;;
  680. *)
  681. echo "WARNING: Unkown file extension: $gzfile"
  682. typeexpr="." ;;
  683. esac
  684. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  685. then
  686. echo "ERROR: File type does not match" \
  687. "filename ($typeexpr)!"
  688. mv "$gzfile.incomplete" "$gzfile.extck-err"
  689. else
  690. mv "$gzfile.incomplete" "$gzfile"
  691. fi
  692. fi
  693. fi
  694. }
  695. list_dtags() {
  696. {
  697. descparser package/*/*/*.desc | grep '^\[D\] '
  698. grep -h '^[X0-9]' target/*/download.txt | sed 's,^,[D] ,'
  699. grep -h '^[X0-9]' target/*/*/download.txt | sed 's,^,[D] ,'
  700. } | column_clean
  701. }
  702. list_cksums() {
  703. trap '' INT
  704. list_dtags | sed \
  705. -e "s,^$D2re[ ].*\($NODISTre\).*$,\2 download/nodist/\4/\3,;" \
  706. -e "s,^$D2re$,\2 download/mirror/\4/\3,;" \
  707. | sed 's,^\(.*/\)[^/:]*:[^ ]* \([X0-9]*\) ,\2 \1,;' | cut -f1,2 -d' '
  708. trap INT
  709. }
  710. list() {
  711. trap '' INT
  712. list_dtags | sed \
  713. -e "s,^$D2re[ ].*\($NODISTre\).*$,\2 download/nodist/\4/\3,;" \
  714. -e "s,^$D2re$,\2 download/mirror/\4/\3,;" | awk '{print $2;}'
  715. trap INT
  716. }
  717. list_unknown() {
  718. trap '' INT
  719. mkdir -p src/ ; list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' > src/down.$$.lst
  720. ls download/{INDEX,README,DOWNTEST,LAST-UPDATE} \
  721. >> src/down.$$.lst 2> /dev/null
  722. find download/* -follow -type f -o -type l | \
  723. egrep -v '^download/([^/]*(/.)?|mirror/(DOWNTEST|LAST-UPDATE|README))$' | \
  724. while read fn ; do
  725. grep -qx "$fn" src/down.$$.lst || echo "Unknown file: $fn"
  726. done
  727. rm -f src/down.$$.lst
  728. trap INT
  729. }
  730. list_missing() {
  731. if [ -z "${config}" ] ; then
  732. list_missing_all
  733. return
  734. fi
  735. if [ ! -f config/$config/packages ]; then
  736. echo "ERROR: Config $config doesn't exist."
  737. echo "ERROR: try ./scripts/Config -cfg $config first."
  738. exit 1
  739. fi
  740. ignore_xpkg=0
  741. while read on a b repo pkg c ; do
  742. forkedpkg=${pkg#*=}
  743. [ "$forkedpkg" = "$pkg" ] || pkg=${pkg%=*}
  744. if [ "${on}" = "X" ] ; then
  745. descparser "xpkg=${forkedpkg}" "package/${repo}/${pkg}/${pkg}.desc" | column_clean | grep '^\[D\]' | \
  746. sed -e "s,^$D2re[ ].*\($NODISTre\).*$,\2 download/nodist/\4/\3,;" \
  747. -e "s,^$D2re$,\2 download/mirror/\4/\3,;" | awk '{print $2;}' | \
  748. sed -e 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' | \
  749. while read fn ; do
  750. [ -f "${fn}" ] || echo "${fn}"
  751. done
  752. fi
  753. done < config/$config/packages
  754. }
  755. list_missing_all() {
  756. trap '' INT
  757. list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' | \
  758. while read fn ; do
  759. [ -f "$fn" ] || echo "$fn"
  760. done
  761. trap INT
  762. }
  763. repository() {
  764. for repository ; do
  765. packages `echo package/$repository/*/*.desc`
  766. done
  767. }
  768. smpatches() {
  769. submaster_url="http://www.rocklinux.net/submaster"
  770. id2url="s#\([0-9]\{4,4\}\)\([0-9]\{2,2\}\)\([0-9]*\)#$submaster_url/data/\1/\2/\3.patch#"
  771. {
  772. while [ -n "$1" ]
  773. do
  774. # convert $1 (smid) via $id2url to submaster url;
  775. # convert url to curl input for -K (url = "XXX")
  776. echo "$1" | sed "/[0-9]\{10\}/ {$id2url ; s/^\(.*\)$/url = \"\1\"/; p; }; d; "
  777. shift
  778. done
  779. } | curl --progress-bar $curl_options -K -
  780. }
  781. required() {
  782. # Choosen config must exist
  783. #
  784. if [ ! -f config/$config/packages ]; then
  785. echo "ERROR: Config $config doesn't exist."
  786. echo "ERROR: try ./scripts/Config -cfg $config first."
  787. exit 1
  788. fi
  789. ignore_xpkg=0
  790. local forkedpkg
  791. while read on a b repo pkg c ; do
  792. forkedpkg=${pkg#*=}
  793. [ "$forkedpkg" = "$pkg" ] || pkg=${pkg%=*}
  794. if [ "$on" = "X" ] ; then
  795. descparser "xpkg=$forkedpkg" "package/$repo/$pkg/$pkg.desc" | grep '^\[D\] ' > src/down.$$.lst
  796. while read tag cksum file url flags ; do
  797. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$repo" "$pkg"
  798. done < src/down.$$.lst ; rm -f src/down.$$.lst
  799. fi
  800. done < config/$config/packages
  801. target=`grep '^export ROCKCFG_TARGET=' config/$config/config | \
  802. cut -f2 -d= | tr -d "'"`
  803. arch=`grep '^export ROCKCFG_ARCH=' config/$config/config | \
  804. cut -f2 -d= | tr -d "'"`
  805. for targetdl in target/$target/{,$arch/}download.txt ; do
  806. if [ -f $targetdl ] ; then
  807. while read cksum file url flags ; do
  808. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$target"
  809. done < $targetdl
  810. fi
  811. done
  812. }
  813. all() {
  814. local each repo pkg
  815. for each in package/*/*/*.desc; do
  816. pkg="`echo $each | cut -f3 -d/`"
  817. repo="`echo $each | cut -f2 -d/`"
  818. while read tag cksum file url flags ; do
  819. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$repo" "$pkg"
  820. done < <(descparser package/$repo/$pkg/$pkg.desc | grep '^\[D\] ')
  821. done
  822. for each in target/*/download.txt target/*/*/download.txt; do
  823. target="`echo $each | cut -f2 -d/`"
  824. while read cksum file url flags ; do
  825. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$target"
  826. done < <(cat $each)
  827. done
  828. }
  829. packages() {
  830. local descfile
  831. local forkedpkg
  832. for arg; do
  833. # Check if this is a forked package name
  834. case "$arg" in
  835. *=*) ignore_xpkg=0; forkedpkg="xpkg=${arg#*=}"; arg=${arg%=*};;
  836. *) ignore_xpkg=1; forkedpkg="";;
  837. esac
  838. case "$arg" in
  839. target/*)
  840. if [ ! -f $arg ]; then
  841. echo "Skipping \"$arg\" (not found)!"
  842. continue
  843. fi
  844. target="`echo $arg | cut -f2 -d/`"
  845. while read cksum file url flags ; do
  846. download_file "`source_file cksum $file url $flags`" \
  847. "$url" "$cksum" "$target"
  848. done < <(cat $arg)
  849. ;;
  850. *)
  851. if [ ! "${arg%.desc}" = "$arg" ]; then
  852. descfile=$arg
  853. else
  854. descfile="`echo package/*/$arg/$arg.desc`"
  855. fi
  856. if [ ! -f $descfile ]; then
  857. echo "Skipping \"$arg\" (not found)!"
  858. continue
  859. fi
  860. pkg="`echo $descfile | cut -f3 -d/`"
  861. repo="`echo $descfile | cut -f2 -d/`"
  862. while read tag cksum file url flags ; do
  863. download_file "`source_file cksum $file url $flags`" \
  864. "$url" "$cksum" "$repo" "$pkg"
  865. done < <(descparser $forkedpkg package/$repo/$pkg/$pkg.desc |
  866. grep '^\[D\] ')
  867. ;;
  868. esac
  869. done
  870. }
  871. mapped_packages() {
  872. if [ ! -f src/pkgmapper ]
  873. then
  874. mkdir -p src
  875. bash scripts/xfind.sh package/. -type f -name 'pkgmapper.in' \
  876. -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' > src/pkgmapper
  877. fi
  878. for pkg; do
  879. export xpkg=$pkg
  880. . src/pkgmapper
  881. packages $pkg
  882. if [ $cksumpatch = 1 ]; then
  883. ./scripts/Create-CkSumPatch $pkg | patch -p0
  884. fi
  885. done
  886. }
  887. # Things to do only for downloading
  888. #
  889. if [ "${1:0:5}" != "-list" -a $checkonly = 0 ]; then
  890. # Set proxy information
  891. if [ -f download/Proxy ]; then
  892. proxy="`cat download/Proxy`"
  893. if [ "$proxy" ]; then
  894. curl_options="$curl_options --proxy $proxy"
  895. else
  896. echo "INFO: No proxy information... removing download/Proxy." 1>&2
  897. rm download/Proxy
  898. fi
  899. fi
  900. if [ -f download/Proxy-auth ]; then
  901. proxyauth="`cat download/Proxy-auth`"
  902. if [ "$proxyauth" ]; then
  903. curl_options="$curl_options --proxy-user $proxyauth"
  904. else
  905. echo "INFO: No proxy-auth information... removing download/Proxy-auth." 1>&2
  906. rm download/Proxy-auth
  907. fi
  908. fi
  909. # Thing to do only once
  910. #
  911. if [ $this_is_the_2nd_run = 0 ]; then
  912. # am i using a proxy?
  913. # -- say i'm doing it even when i already did ;-)
  914. if [ "$proxy" ]; then
  915. echo "INFO: Setting proxy to $proxy." 1>&2
  916. fi
  917. if [ "$proxyauth" ]; then
  918. echo "INFO: Setting proxy authentication information." 1>&2
  919. fi
  920. # do mirror detection
  921. detect_mirror
  922. fi
  923. fi
  924. case "$1" in
  925. -list) list ;;
  926. -list-dtags) list_dtags ;;
  927. -list-unknown) list_unknown ;;
  928. -list-missing) list_missing ;;
  929. -list-cksums) list_cksums ;;
  930. -required) required ;;
  931. -all) all ;;
  932. -repository) shift ; repository "$@" ;;
  933. -sm) shift ; smpatches "$@" ;;
  934. -*|"") exec $0 -help ;;
  935. *) mapped_packages "$@" ;;
  936. esac
  937. exit 0