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.

853 lines
23 KiB

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