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.

831 lines
22 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. # cksum_chk filename cksum origfile
  177. #
  178. # This function verifies the checksum. If it fails it renames the file
  179. # to file.chksum-err and returns failure.
  180. #
  181. # It seams like the [ ] command has problems with comparing high numbers.
  182. # That's why I'm using a text comparison here.
  183. #
  184. # Not doing anything if checksum is '0' or a text of 'X'.
  185. #
  186. cksum_chk() {
  187. y="`echo $2 | sed 's,^0*,,;'`"
  188. [ $nocheck = 1 -o -z "$y" -o -z "${2//X/}" ] && return 0
  189. x="`cksum "$1" | cut -f1 -d' ' | sed 's,^0*,,;'`"
  190. if [ "$x" != "$y" ] ; then
  191. # Add .cksum-err extension to filename:
  192. echo "Cksum ERROR: $3.cksum-err ($x)"
  193. mv "$3" "$3.cksum-err" ; return 1
  194. fi
  195. return 0
  196. }
  197. # Autodetect best Mirror and safe url in $mirror
  198. #
  199. detect_mirror() {
  200. if [ -f download/Mirror ] ; then
  201. mirror="`cat download/Mirror`"
  202. if [ -z "$mirror" -o "$mirror" = "none" ] ; then
  203. echo "INFO: Found download/Mirror: none" \
  204. "(use the original download locations)"
  205. else
  206. echo "INFO: Found cached mirror URL in download/Mirror:"
  207. echo "INFO: $mirror"
  208. fi
  209. echo "INFO: To force a new mirror auto-detection, remove download/Mirror."
  210. else
  211. echo "INFO: Auto-detecting best mirror ..."
  212. eval "$(egrep '^(rockver)=' scripts/parse-config)"
  213. echo "INFO: Downloading mirror-list from www.rocklinux.net."
  214. curl -s -S $curl_options -o src/Download-Mirror-List \
  215. "http://www.rocklinux.net/mirrors.cgi?$rockver"
  216. bestval=0 ; result='No Mirror Found!'
  217. while read mirror_name ; do
  218. if [ "${mirror_name#=}" != "$mirror_name" ] ; then
  219. mirror_name="${mirror_name#= }"
  220. mirror_name="${mirror_name% =}"
  221. read mirror_url
  222. echo -n "INFO: Testing <$mirror_name> ..."
  223. val="$(curl -s $curl_options -m 20 "${mirror_url%/}/DOWNTEST" \
  224. -w "ok %{speed_download}" -o /dev/null)"
  225. if [ "$val" = "${val#ok }" -o "$val" = "ok 0.000" ] ; then
  226. echo " error"
  227. else
  228. xval=`echo ${val#ok } | tr -d .` ; echo " $val"
  229. if [ "$xval" -gt "$bestval" ] ; then
  230. bestval=$xval ; mirror="${mirror_url%/}"
  231. result="Using mirror <$mirror>."
  232. fi
  233. fi
  234. fi
  235. done < src/Download-Mirror-List
  236. echo $mirror > download/Mirror
  237. echo "INFO: $result"
  238. fi
  239. }
  240. # download_file local-filename download-location cksum repo pkg
  241. #
  242. # This function decides if download directly or from a mirror,
  243. # validates checksum, etc.
  244. # Calls download_file_now to do the actual download.
  245. #
  246. download_file() {
  247. # Init
  248. #
  249. local gzfile="$1" location="$2" cksum="$3" repo="$4" pkg="$5"
  250. # Make src directory for creating tar balls
  251. mkdir -p src/
  252. # Tarball file name: (if you change this one - also adapt Create-ISO)
  253. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  254. # Lock file name:
  255. lkfile="src/down.lockfile.`echo $bzfile | tr / -`"
  256. # Check if it's already there
  257. #
  258. [ -s "$bzfile" -a $checkonly != 1 ] && return 0
  259. # Make locking
  260. #
  261. if [ -s "$lkfile" ]; then
  262. echo "Found $lkfile -> skip download."
  263. return 0
  264. fi
  265. trap 'rm -f "$lkfile"' INT
  266. echo $$ > "$lkfile"
  267. # Check if we only like to test the cksum(s)
  268. #
  269. if [ $checkonly = 1 ] ; then
  270. gzfile="$bzfile"
  271. if [ ! -f "$bzfile" ] ; then
  272. echo "File missing: $bzfile"
  273. rm -f "$lkfile" ; trap INT ; return 1
  274. fi
  275. if [ -z "${cksum##X*}" ] ; then
  276. echo "No checksum (ignore): $bzfile"
  277. rm -f "$lkfile" ; trap INT ; return 1
  278. fi
  279. if [ "$cksum" -eq 0 ] ; then
  280. echo "No checksum (missing): $bzfile"
  281. rm -f "$lkfile" ; trap INT ; return 1
  282. fi
  283. elif [ -s "$gzfile" ] ; then
  284. echo ; echo "Already downloaded $gzfile ..."
  285. else
  286. echo ; echo "Downloading $gzfile ..."
  287. # Existing *.cksum-err
  288. #
  289. if [ -s "$gzfile.cksum-err" ] ; then
  290. # cksum-err file alread exists:
  291. echo "ERROR: Found $gzfile.cksum-err."
  292. echo "ERROR: That means that we downloaded the" \
  293. "file already and it had an"
  294. echo "ERROR: incorrect checksum. Remove the" \
  295. "*.cksum-err file to force a"
  296. echo "ERROR: new download of that file."
  297. rm -f "$lkfile" ; trap INT ; return 1
  298. fi
  299. # Existing *.extck-err
  300. #
  301. if [ -s "$gzfile.extck-err" ] ; then
  302. # extck-err file alread exists:
  303. echo "ERROR: Found $gzfile.extck-err."
  304. echo "ERROR: That means that we downloaded the" \
  305. "file already and it's content"
  306. echo "ERROR: did not match it's filename extension." \
  307. "Remove the *.extck-err file"
  308. echo "ERROR: to force a new download of that file."
  309. rm -f "$lkfile" ; trap INT ; return 1
  310. fi
  311. # Questionable URL
  312. #
  313. if [ "$location" != "${location#\?}" ] ; then
  314. if [ "$tryques" = 0 ] ; then
  315. echo "ERROR: URL is marked as questionable." \
  316. "Not downloading this file."
  317. rm -f "$lkfile" ; trap INT ; return 1
  318. else
  319. echo "WARNING: URL is marked as questionable." \
  320. "Downloading it anyways."
  321. location="${location#\?}"
  322. fi
  323. fi
  324. # Make directory (if required)
  325. #
  326. if [ ! -d `dirname "$bzfile"` ] ; then
  327. mkdir -p `dirname "$bzfile"`
  328. fi
  329. # Alternative Directory
  330. #
  331. if [ "$altdir" ] ; then
  332. altfile=$(find $altdir/ -name `basename $bzfile` | head -n 1)
  333. else
  334. altfile=""
  335. fi
  336. #FIXME: compatibility, can be removed sooner or later...
  337. # Check old download dir layout
  338. if [ -z "$altfile" ]; then
  339. if [ -f "download/$repo${pkg:+/}$pkg/`basename $bzfile`" ]; then
  340. altfile="download/$repo${pkg:+/}$pkg/`basename $bzfile`"
  341. fi
  342. fi
  343. if [ "$altfile" ] ; then
  344. echo "Found `basename $bzfile` as $altfile."
  345. if [ "$altcopy" = 'link' ]; then
  346. cp -lv $altfile $bzfile
  347. elif [ "$altcopy" = 'copy' ]; then
  348. cp -v $altfile $bzfile
  349. elif [ "$altcopy" = 'move' ]; then
  350. mv -v $altfile $bzfile
  351. fi
  352. gzfile="$bzfile"
  353. else
  354. # Mirroring
  355. #
  356. mirror="$( cat download/Mirror )"
  357. if [ "$mirror" -a "$mirror" != "none" ] ; then
  358. # try to use mirror
  359. if ! download_file_now "!$mirror/${bzfile#download/}" $bzfile $bzfile; then
  360. #FIXME: compatibility, can be removed sooner or later...
  361. # Try old download format for remote file
  362. if ! download_file_now "!$mirror/$repo${pkg:+/}$pkg/`basename $bzfile`" $bzfile $bzfile; then
  363. # oops... so try direct (original URL)
  364. echo "INFO: download from mirror failed, trying original URL."
  365. download_file_now $location $gzfile $bzfile
  366. fi
  367. else
  368. gzfile="$bzfile"
  369. fi
  370. else
  371. # don't want to use mirror
  372. download_file_now $location $gzfile $bzfile
  373. fi
  374. fi
  375. if [ ! -s "$gzfile" ]; then
  376. rm -f "$lkfile" ; trap INT ; return 1
  377. fi
  378. fi
  379. # Convert a .gz to .bz2 and test checksum
  380. #
  381. if [ "$gzfile" != "$bzfile" ] ; then
  382. echo "bzip'ing + cksum-test: $gzfile"
  383. gunzip < "$gzfile" > src/down.$$.dat
  384. if cksum_chk src/down.$$.dat $cksum "$gzfile" ; then
  385. bzip2 < src/down.$$.dat > "$bzfile" ; rm -f "$gzfile"
  386. fi
  387. rm -f src/down.$$.dat
  388. # Execute a cksum test on a bzip2 file
  389. #
  390. elif [ "${gzfile%.bz2}" != "$gzfile" -o \
  391. "${gzfile%.tbz2}" != "$gzfile" ]
  392. then
  393. echo "cksum-test (bzip2): $bzfile"
  394. if [ $nocheck = 0 ] ; then
  395. bunzip2 < "$bzfile" > src/down.$$.dat
  396. cksum_chk src/down.$$.dat $cksum "$bzfile"
  397. fi
  398. rm -f src/down.$$.dat
  399. # Execute a cksum test on a raw data file
  400. #
  401. else
  402. echo "cksum-test (raw): $gzfile"
  403. cksum_chk "$gzfile" $cksum "$gzfile"
  404. fi
  405. # Free Lock and finish
  406. #
  407. rm -f "$lkfile" ; trap INT ; return 0
  408. }
  409. # download_file_now location remote_filename local_filename
  410. #
  411. # This function executes the actual download using curl.
  412. #
  413. download_file_now() {
  414. local location="$1" gzfile="$2" bzfile="$3"
  415. # Create URL
  416. #
  417. if [ "${location#!}" != "$location" ] ; then
  418. url="`echo "$location" | sed 's,!,,'`"
  419. else
  420. url="`echo "$location" | \
  421. sed 's,/[^/]*$,,'`/`echo $gzfile | sed 's,.*/,,'`"
  422. fi
  423. # Check for existing Error Log
  424. #
  425. if test -s src/Download-Errors &&
  426. grep -q " $url\$" src/Download-Errors ; then
  427. echo "ERROR: According to src/Download-Errors" \
  428. "we had already an error for the URL"
  429. echo "ERROR: $url"
  430. echo "ERROR: So I'm not trying to download" \
  431. "it again (remove src/Download-Errors"
  432. echo "ERROR: if you want to force a retry)."
  433. return 1
  434. fi
  435. # Download
  436. #
  437. if [[ $url = cvs://* ]] ; then
  438. # cvs://mode:[login[:password]@]server[:port]:/path::module!revision/
  439. # btw, at least current cvs supports password at CVSROOT.
  440. url="${url#cvs://}"; url="${url%/*}"
  441. # cvs://mode:loc::module!date/
  442. #
  443. mode="${url%%:*}"; loc="${url#*:}"
  444. module="${loc##*::}"; loc="${loc%%::*}"
  445. revision="${module#*!}"; module="${module%%!*}"
  446. [[ $loc != *@* ]] && loc="anonymous@$loc"
  447. # everything after the first 'bang' (!) is analysed here
  448. # someday we could add more cvs options.
  449. #
  450. dat="$( echo $revision | \
  451. sed -n -e 's,\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\),-D \1,p' )"
  452. cvsdir="src/down.cvsdir.`echo $bzfile | tr / -`"
  453. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  454. echo CVS $mode $loc $dat $module
  455. { [ $mode = ssh ] && export CVS_RSH=ssh
  456. [ $mode = pserver ] && loc=":pserver:$loc"
  457. # sometimes cvs wants to read ~/.cvspass just for fun ..
  458. touch $HOME/.cvspass
  459. # for ssh we need some way to quitely accept the key ...
  460. echo cvs -z9 -Q -d $loc checkout $dat -P $module
  461. if ! cvs -z9 -Q -d $loc checkout $dat -P $module
  462. then touch .cvs_error ; fi
  463. } &> .cvs_output &
  464. while fuser .cvs_output &> /dev/null ; do
  465. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  466. 'CVS archive so far...\r'
  467. sleep 3
  468. done
  469. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  470. 'CVS archive (download finished).'
  471. if [ ! -f .cvs_error ] ; then
  472. cd `dirname $module`
  473. dir="`echo "$bzfile" | sed s/\.tar\.bz2$//`"
  474. dir="`basename $dir`"
  475. mv `basename $module` $dir
  476. tar --owner root --group root \
  477. --use-compress-program=bzip2 \
  478. -cf $dir.tar.bz2 $dir
  479. mv $dir.tar.bz2 $saved_pwd/$bzfile
  480. cd $saved_pwd ; rm -rf $cvsdir
  481. else
  482. cat .cvs_output
  483. cd $saved_pwd ; rm -rf $cvsdir
  484. echo ERROR: CVS $dat $loc $module \
  485. returned an error.
  486. echo "0 $gzfile $url" >> src/Download-Errors
  487. fi
  488. else
  489. if [ -s "$gzfile.incomplete" ] ; then
  490. echo "INFO: Trying to resume previous download .."
  491. resume="-C -"
  492. else
  493. resume=""
  494. fi
  495. 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"
  496. curlret="$?"
  497. if [ "$resume" ] && \
  498. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  499. echo "INFO: Resuming download not possible. ->" \
  500. "Overwriting old file."
  501. rm -f "$gzfile.incomplete"
  502. 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"
  503. curlret="$?"
  504. fi
  505. if [ $curlret -ne 0 ] ; then
  506. case "$curlret" in
  507. 18)
  508. echo "WARNING: Got only some of the" \
  509. "file. A re-run of $0"
  510. echo "WARNING: is required to complete" \
  511. "the download." ;;
  512. 130)
  513. echo -e '\rWARNING: CURL got a SIGINT' \
  514. "(someone pressed Ctrl-C). A re-run of"
  515. echo "WARNING: $0 is required to complete" \
  516. "the download." ; sleep 1 ;;
  517. *)
  518. echo "$curlret $gzfile $url" \
  519. >> src/Download-Errors
  520. echo -e '\rERROR: CURL Returned Error' \
  521. "$curlret. Please read" \
  522. "the curl manpage." ;;
  523. esac
  524. return 1
  525. elif [ ! -s "$gzfile.incomplete" ] ; then
  526. echo "0 $gzfile $url" >> src/Download-Errors
  527. echo "ERROR: CURL returned success but" \
  528. "we have no data!"
  529. curlret=1
  530. else
  531. case "$gzfile" in
  532. *.gz|*.tgz)
  533. typeexpr="gzip compressed data" ;;
  534. *.bz2|*.tbz2)
  535. typeexpr="bzip2 compressed data" ;;
  536. *.Z|*.tZ)
  537. typeexpr="compress'd data" ;;
  538. *.zip|*.jar)
  539. typeexpr="Zip archive data" ;;
  540. *.tar)
  541. typeexpr="tar archive" ;;
  542. *)
  543. echo "WARNING: Unkown file extension: $gzfile"
  544. typeexpr="." ;;
  545. esac
  546. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  547. then
  548. echo "ERROR: File type does not match" \
  549. "filename ($typeexpr)!"
  550. mv "$gzfile.incomplete" "$gzfile.extck-err"
  551. else
  552. mv "$gzfile.incomplete" "$gzfile"
  553. fi
  554. fi
  555. fi
  556. }
  557. list_dtags() {
  558. {
  559. grep -H '^\[D\] ' package/*/*/*.desc
  560. grep -H '^[X0-9]' target/*/download.txt | sed 's,:,:[D] ,'
  561. } | column_clean
  562. }
  563. list_cksums() {
  564. trap '' INT
  565. list_dtags | sed \
  566. -e "s,^$Dre[ ].*\($NODISTre\).*$,\3 download/nodist/\5/\4,;" \
  567. -e "s,^$Dre$,\3 download/mirror/\5/\4,;" \
  568. | sed 's,^\(.*/\)[^/:]*:[^ ]* \([X0-9]*\) ,\2 \1,;' | cut -f1,2 -d' '
  569. trap INT
  570. }
  571. list() {
  572. trap '' INT
  573. list_cksums | cut -f2- -d' '
  574. trap INT
  575. }
  576. list_unknown() {
  577. trap '' INT
  578. mkdir -p src/ ; list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' > src/down.$$.lst
  579. ls download/{INDEX,README,DOWNTEST,LAST-UPDATE} \
  580. >> src/down.$$.lst 2> /dev/null
  581. find download/* -type f -o -type l | grep -v -e download/Mirror \
  582. -e download/Proxy -e download/Proxy-auth | \
  583. while read fn ; do
  584. grep -qx "$fn" src/down.$$.lst || echo "Unknown file: $fn"
  585. done
  586. rm -f src/down.$$.lst
  587. trap INT
  588. }
  589. list_missing() {
  590. trap '' INT
  591. list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' | \
  592. while read fn ; do
  593. [ -f "$fn" ] || echo "$fn"
  594. done
  595. trap INT
  596. }
  597. repository() {
  598. for repository ; do
  599. packages `echo package/$repository/*/*.desc`
  600. done
  601. }
  602. required() {
  603. # Choosen config must exist
  604. #
  605. if [ ! -f config/$config/packages ]; then
  606. echo "ERROR: Config $config doesn't exist."
  607. echo "ERROR: try ./scripts/Config -cfg $config first."
  608. exit 1
  609. fi
  610. local forkedpkg
  611. while read on a b repo pkg c ; do
  612. forkedpkg=${pkg%=*}
  613. [ "$forkedpkg" = "$pkg" ] || pkg=$forkedpkg
  614. if [ "$on" = "X" ] ; then
  615. grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc > src/down.$$.lst
  616. while read tag cksum file url flags ; do
  617. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$repo" "$pkg"
  618. done < src/down.$$.lst ; rm -f src/down.$$.lst
  619. fi
  620. done < config/$config/packages
  621. target=`grep '^export ROCKCFG_TARGET=' config/$config/config | \
  622. cut -f2 -d= | tr -d "'"`
  623. if [ -f target/$target/download.txt ] ; then
  624. while read cksum file url flags ; do
  625. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$target"
  626. done < target/$target/download.txt
  627. fi
  628. }
  629. all() {
  630. local each repo pkg
  631. for each in package/*/*/*.desc; do
  632. pkg="`echo $each | cut -f3 -d/`"
  633. repo="`echo $each | cut -f2 -d/`"
  634. while read tag cksum file url flags ; do
  635. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$repo" "$pkg"
  636. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  637. done
  638. for each in target/*/download.txt; do
  639. target="`echo $each | cut -f2 -d/`"
  640. while read cksum file url flags ; do
  641. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$target"
  642. done < <(cat $each)
  643. done
  644. }
  645. packages() {
  646. local descfile
  647. for arg; do
  648. case "$arg" in
  649. target/*)
  650. if [ ! -f $arg ]; then
  651. echo "Skipping \"$arg\" (not found)!"
  652. continue
  653. fi
  654. target="`echo $arg | cut -f2 -d/`"
  655. while read cksum file url flags ; do
  656. download_file "`source_file cksum $file url $flags`" \
  657. "$url" "$cksum" "$target"
  658. done < <(cat $arg)
  659. ;;
  660. *)
  661. if [ ! "${arg%.desc}" = "$arg" ]; then
  662. descfile=$arg
  663. else
  664. descfile="`echo package/*/$arg/$arg.desc`"
  665. fi
  666. if [ ! -f $descfile ]; then
  667. echo "Skipping \"$arg\" (not found)!"
  668. continue
  669. fi
  670. pkg="`echo $descfile | cut -f3 -d/`"
  671. repo="`echo $descfile | cut -f2 -d/`"
  672. while read tag cksum file url flags ; do
  673. download_file "`source_file cksum $file url $flags`" \
  674. "$url" "$cksum" "$repo" "$pkg"
  675. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  676. ;;
  677. esac
  678. done
  679. }
  680. # Things to do only for downloading
  681. #
  682. if [ "${1:0:5}" != "-list" -a $checkonly = 0 ]; then
  683. # Set proxy information
  684. if [ -f download/Proxy ]; then
  685. proxy="`cat download/Proxy`"
  686. if [ "$proxy" ]; then
  687. curl_options="$curl_options --proxy $proxy"
  688. else
  689. echo "INFO: No proxy information... removing download/Proxy."
  690. rm download/Proxy
  691. fi
  692. fi
  693. if [ -f download/Proxy-auth ]; then
  694. proxyauth="`cat download/Proxy-auth`"
  695. if [ "$proxyauth" ]; then
  696. curl_options="$curl_options --proxy-user $proxyauth"
  697. else
  698. echo "INFO: No proxy-auth information... removing download/Proxy-auth."
  699. rm download/Proxy-auth
  700. fi
  701. fi
  702. # Thing to do only once
  703. #
  704. if [ $this_is_the_2nd_run = 0 ]; then
  705. # am i using a proxy?
  706. # -- say i'm doing it even when i already did ;-)
  707. if [ "$proxy" ]; then
  708. echo "INFO: Setting proxy to $proxy."
  709. fi
  710. if [ "$proxyauth" ]; then
  711. echo "INFO: Setting proxy authentication information."
  712. fi
  713. # do mirror detection
  714. detect_mirror
  715. fi
  716. fi
  717. case "$1" in
  718. -list) list ;;
  719. -list-unknown) list_unknown ;;
  720. -list-missing) list_missing ;;
  721. -list-cksums) list_cksums ;;
  722. -required) required ;;
  723. -all) all ;;
  724. -repository) shift ; repository "$@" ;;
  725. -*|"") exec $0 --help ;;
  726. *) packages "$@" ;;
  727. esac
  728. exit 0