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.

826 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 [ -n "$mirror" -a "$mirror" != "none" -a -z "${bzfile##download/mirror/*}" ] ; then
  358. # try to use mirror
  359. if ! download_file_now "!$mirror/${bzfile#download/mirror/}" $bzfile $bzfile; then
  360. echo "INFO: download from mirror failed, trying original URL."
  361. download_file_now $location $gzfile $bzfile
  362. else
  363. gzfile="$bzfile"
  364. fi
  365. else
  366. # don't want to use mirror
  367. download_file_now $location $gzfile $bzfile
  368. fi
  369. fi
  370. if [ ! -s "$gzfile" ]; then
  371. rm -f "$lkfile" ; trap INT ; return 1
  372. fi
  373. fi
  374. # Convert a .gz to .bz2 and test checksum
  375. #
  376. if [ "$gzfile" != "$bzfile" ] ; then
  377. echo "bzip'ing + cksum-test: $gzfile"
  378. gunzip < "$gzfile" > src/down.$$.dat
  379. if cksum_chk src/down.$$.dat $cksum "$gzfile" ; then
  380. bzip2 < src/down.$$.dat > "$bzfile" ; rm -f "$gzfile"
  381. fi
  382. rm -f src/down.$$.dat
  383. # Execute a cksum test on a bzip2 file
  384. #
  385. elif [ "${gzfile%.bz2}" != "$gzfile" -o \
  386. "${gzfile%.tbz2}" != "$gzfile" ]
  387. then
  388. echo "cksum-test (bzip2): $bzfile"
  389. if [ $nocheck = 0 ] ; then
  390. bunzip2 < "$bzfile" > src/down.$$.dat
  391. cksum_chk src/down.$$.dat $cksum "$bzfile"
  392. fi
  393. rm -f src/down.$$.dat
  394. # Execute a cksum test on a raw data file
  395. #
  396. else
  397. echo "cksum-test (raw): $gzfile"
  398. cksum_chk "$gzfile" $cksum "$gzfile"
  399. fi
  400. # Free Lock and finish
  401. #
  402. rm -f "$lkfile" ; trap INT ; return 0
  403. }
  404. # download_file_now location remote_filename local_filename
  405. #
  406. # This function executes the actual download using curl.
  407. #
  408. download_file_now() {
  409. local location="$1" gzfile="$2" bzfile="$3"
  410. # Create URL
  411. #
  412. if [ "${location#!}" != "$location" ] ; then
  413. url="`echo "$location" | sed 's,!,,'`"
  414. else
  415. url="`echo "$location" | \
  416. sed 's,/[^/]*$,,'`/`echo $gzfile | sed 's,.*/,,'`"
  417. fi
  418. # Check for existing Error Log
  419. #
  420. if test -s src/Download-Errors &&
  421. grep -q " $url\$" src/Download-Errors ; then
  422. echo "ERROR: According to src/Download-Errors" \
  423. "we had already an error for the URL"
  424. echo "ERROR: $url"
  425. echo "ERROR: So I'm not trying to download" \
  426. "it again (remove src/Download-Errors"
  427. echo "ERROR: if you want to force a retry)."
  428. return 1
  429. fi
  430. # Download
  431. #
  432. if [[ $url = cvs://* ]] ; then
  433. # cvs://mode:[login[:password]@]server[:port]:/path::module!revision/
  434. # btw, at least current cvs supports password at CVSROOT.
  435. url="${url#cvs://}"; url="${url%/*}"
  436. # cvs://mode:loc::module!date/
  437. #
  438. mode="${url%%:*}"; loc="${url#*:}"
  439. module="${loc##*::}"; loc="${loc%%::*}"
  440. revision="${module#*!}"; module="${module%%!*}"
  441. [[ $loc != *@* ]] && loc="anonymous@$loc"
  442. # everything after the first 'bang' (!) is analysed here
  443. # someday we could add more cvs options.
  444. #
  445. dat="$( echo $revision | \
  446. sed -n -e 's,\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\),-D \1,p' )"
  447. cvsdir="src/down.cvsdir.`echo $bzfile | tr / -`"
  448. saved_pwd=$PWD ; mkdir -p $cvsdir ; cd $cvsdir
  449. echo CVS $mode $loc $dat $module
  450. { [ $mode = ssh ] && export CVS_RSH=ssh
  451. [ $mode = pserver ] && loc=":pserver:$loc"
  452. # sometimes cvs wants to read ~/.cvspass just for fun ..
  453. touch $HOME/.cvspass
  454. # for ssh we need some way to quitely accept the key ...
  455. echo cvs -z9 -Q -d $loc checkout $dat -P $module
  456. if ! cvs -z9 -Q -d $loc checkout $dat -P $module
  457. then touch .cvs_error ; fi
  458. } &> .cvs_output &
  459. while fuser .cvs_output &> /dev/null ; do
  460. echo -ne `nice du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  461. 'CVS archive so far...\r'
  462. sleep 3
  463. done
  464. echo `du -sh 2> /dev/null | cut -f1` 'downloaded from' \
  465. 'CVS archive (download finished).'
  466. if [ ! -f .cvs_error ] ; then
  467. cd `dirname $module`
  468. dir="`echo "$bzfile" | sed s/\.tar\.bz2$//`"
  469. dir="`basename $dir`"
  470. mv `basename $module` $dir
  471. tar --owner root --group root \
  472. --use-compress-program=bzip2 \
  473. -cf $dir.tar.bz2 $dir
  474. mv $dir.tar.bz2 $saved_pwd/$bzfile
  475. cd $saved_pwd ; rm -rf $cvsdir
  476. else
  477. cat .cvs_output
  478. cd $saved_pwd ; rm -rf $cvsdir
  479. echo ERROR: CVS $dat $loc $module \
  480. returned an error.
  481. echo "0 $gzfile $url" >> src/Download-Errors
  482. fi
  483. else
  484. if [ -s "$gzfile.incomplete" ] ; then
  485. echo "INFO: Trying to resume previous download .."
  486. resume="-C -"
  487. else
  488. resume=""
  489. fi
  490. 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"
  491. curlret="$?"
  492. if [ "$resume" ] && \
  493. [ $curlret -eq 33 -o $curlret -eq 36 ] ; then
  494. echo "INFO: Resuming download not possible. ->" \
  495. "Overwriting old file."
  496. rm -f "$gzfile.incomplete"
  497. 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"
  498. curlret="$?"
  499. fi
  500. if [ $curlret -ne 0 ] ; then
  501. case "$curlret" in
  502. 18)
  503. echo "WARNING: Got only some of the" \
  504. "file. A re-run of $0"
  505. echo "WARNING: is required to complete" \
  506. "the download." ;;
  507. 130)
  508. echo -e '\rWARNING: CURL got a SIGINT' \
  509. "(someone pressed Ctrl-C). A re-run of"
  510. echo "WARNING: $0 is required to complete" \
  511. "the download." ; sleep 1 ;;
  512. *)
  513. echo "$curlret $gzfile $url" \
  514. >> src/Download-Errors
  515. echo -e '\rERROR: CURL Returned Error' \
  516. "$curlret. Please read" \
  517. "the curl manpage." ;;
  518. esac
  519. return 1
  520. elif [ ! -s "$gzfile.incomplete" ] ; then
  521. echo "0 $gzfile $url" >> src/Download-Errors
  522. echo "ERROR: CURL returned success but" \
  523. "we have no data!"
  524. curlret=1
  525. else
  526. case "$gzfile" in
  527. *.gz|*.tgz)
  528. typeexpr="gzip compressed data" ;;
  529. *.bz2|*.tbz2)
  530. typeexpr="bzip2 compressed data" ;;
  531. *.Z|*.tZ)
  532. typeexpr="compress'd data" ;;
  533. *.zip|*.jar)
  534. typeexpr="Zip archive data" ;;
  535. *.tar)
  536. typeexpr="tar archive" ;;
  537. *)
  538. echo "WARNING: Unkown file extension: $gzfile"
  539. typeexpr="." ;;
  540. esac
  541. if file "$gzfile.incomplete" | grep -v "$typeexpr"
  542. then
  543. echo "ERROR: File type does not match" \
  544. "filename ($typeexpr)!"
  545. mv "$gzfile.incomplete" "$gzfile.extck-err"
  546. else
  547. mv "$gzfile.incomplete" "$gzfile"
  548. fi
  549. fi
  550. fi
  551. }
  552. list_dtags() {
  553. {
  554. grep -H '^\[D\] ' package/*/*/*.desc
  555. grep -H '^[X0-9]' target/*/download.txt | sed 's,:,:[D] ,'
  556. } | column_clean
  557. }
  558. list_cksums() {
  559. trap '' INT
  560. list_dtags | sed \
  561. -e "s,^$Dre[ ].*\($NODISTre\).*$,\3 download/nodist/\5/\4,;" \
  562. -e "s,^$Dre$,\3 download/mirror/\5/\4,;" \
  563. | sed 's,^\(.*/\)[^/:]*:[^ ]* \([X0-9]*\) ,\2 \1,;' | cut -f1,2 -d' '
  564. trap INT
  565. }
  566. list() {
  567. trap '' INT
  568. list_cksums | cut -f2- -d' '
  569. trap INT
  570. }
  571. list_unknown() {
  572. trap '' INT
  573. mkdir -p src/ ; list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' > src/down.$$.lst
  574. ls download/{INDEX,README,DOWNTEST,LAST-UPDATE} \
  575. >> src/down.$$.lst 2> /dev/null
  576. find download/* -type f -o -type l | grep -v -e download/Mirror \
  577. -e download/Proxy -e download/Proxy-auth | \
  578. while read fn ; do
  579. grep -qx "$fn" src/down.$$.lst || echo "Unknown file: $fn"
  580. done
  581. rm -f src/down.$$.lst
  582. trap INT
  583. }
  584. list_missing() {
  585. trap '' INT
  586. list | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' | \
  587. while read fn ; do
  588. [ -f "$fn" ] || echo "$fn"
  589. done
  590. trap INT
  591. }
  592. repository() {
  593. for repository ; do
  594. packages `echo package/$repository/*/*.desc`
  595. done
  596. }
  597. required() {
  598. # Choosen config must exist
  599. #
  600. if [ ! -f config/$config/packages ]; then
  601. echo "ERROR: Config $config doesn't exist."
  602. echo "ERROR: try ./scripts/Config -cfg $config first."
  603. exit 1
  604. fi
  605. local forkedpkg
  606. while read on a b repo pkg c ; do
  607. forkedpkg=${pkg%=*}
  608. [ "$forkedpkg" = "$pkg" ] || pkg=$forkedpkg
  609. if [ "$on" = "X" ] ; then
  610. grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc > src/down.$$.lst
  611. while read tag cksum file url flags ; do
  612. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$repo" "$pkg"
  613. done < src/down.$$.lst ; rm -f src/down.$$.lst
  614. fi
  615. done < config/$config/packages
  616. target=`grep '^export ROCKCFG_TARGET=' config/$config/config | \
  617. cut -f2 -d= | tr -d "'"`
  618. if [ -f target/$target/download.txt ] ; then
  619. while read cksum file url flags ; do
  620. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$target"
  621. done < target/$target/download.txt
  622. fi
  623. }
  624. all() {
  625. local each repo pkg
  626. for each in package/*/*/*.desc; do
  627. pkg="`echo $each | cut -f3 -d/`"
  628. repo="`echo $each | cut -f2 -d/`"
  629. while read tag cksum file url flags ; do
  630. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$repo" "$pkg"
  631. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  632. done
  633. for each in target/*/download.txt; do
  634. target="`echo $each | cut -f2 -d/`"
  635. while read cksum file url flags ; do
  636. download_file "`source_file cksum $file url $flags`" "$url" "$cksum" "$target"
  637. done < <(cat $each)
  638. done
  639. }
  640. packages() {
  641. local descfile
  642. for arg; do
  643. case "$arg" in
  644. target/*)
  645. if [ ! -f $arg ]; then
  646. echo "Skipping \"$arg\" (not found)!"
  647. continue
  648. fi
  649. target="`echo $arg | cut -f2 -d/`"
  650. while read cksum file url flags ; do
  651. download_file "`source_file cksum $file url $flags`" \
  652. "$url" "$cksum" "$target"
  653. done < <(cat $arg)
  654. ;;
  655. *)
  656. if [ ! "${arg%.desc}" = "$arg" ]; then
  657. descfile=$arg
  658. else
  659. descfile="`echo package/*/$arg/$arg.desc`"
  660. fi
  661. if [ ! -f $descfile ]; then
  662. echo "Skipping \"$arg\" (not found)!"
  663. continue
  664. fi
  665. pkg="`echo $descfile | cut -f3 -d/`"
  666. repo="`echo $descfile | cut -f2 -d/`"
  667. while read tag cksum file url flags ; do
  668. download_file "`source_file cksum $file url $flags`" \
  669. "$url" "$cksum" "$repo" "$pkg"
  670. done < <(grep -H '^\[D\] ' package/$repo/$pkg/$pkg.desc)
  671. ;;
  672. esac
  673. done
  674. }
  675. # Things to do only for downloading
  676. #
  677. if [ "${1:0:5}" != "-list" -a $checkonly = 0 ]; then
  678. # Set proxy information
  679. if [ -f download/Proxy ]; then
  680. proxy="`cat download/Proxy`"
  681. if [ "$proxy" ]; then
  682. curl_options="$curl_options --proxy $proxy"
  683. else
  684. echo "INFO: No proxy information... removing download/Proxy."
  685. rm download/Proxy
  686. fi
  687. fi
  688. if [ -f download/Proxy-auth ]; then
  689. proxyauth="`cat download/Proxy-auth`"
  690. if [ "$proxyauth" ]; then
  691. curl_options="$curl_options --proxy-user $proxyauth"
  692. else
  693. echo "INFO: No proxy-auth information... removing download/Proxy-auth."
  694. rm download/Proxy-auth
  695. fi
  696. fi
  697. # Thing to do only once
  698. #
  699. if [ $this_is_the_2nd_run = 0 ]; then
  700. # am i using a proxy?
  701. # -- say i'm doing it even when i already did ;-)
  702. if [ "$proxy" ]; then
  703. echo "INFO: Setting proxy to $proxy."
  704. fi
  705. if [ "$proxyauth" ]; then
  706. echo "INFO: Setting proxy authentication information."
  707. fi
  708. # do mirror detection
  709. detect_mirror
  710. fi
  711. fi
  712. case "$1" in
  713. -list) list ;;
  714. -list-unknown) list_unknown ;;
  715. -list-missing) list_missing ;;
  716. -list-cksums) list_cksums ;;
  717. -required) required ;;
  718. -all) all ;;
  719. -repository) shift ; repository "$@" ;;
  720. -*|"") exec $0 --help ;;
  721. *) packages "$@" ;;
  722. esac
  723. exit 0