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.

914 lines
25 KiB

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