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.
 
 
 
 
 
 

74 lines
2.6 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. ;;;
  19. ;;; Download a binary file from an external source.
  20. ;;;
  21. (use-modules (ice-9 match)
  22. (web uri)
  23. (web client)
  24. (rnrs io ports)
  25. (srfi srfi-11)
  26. (guix utils)
  27. (guix hash))
  28. (define %url-base
  29. "http://alpha.gnu.org/gnu/guix/bootstrap"
  30. ;; Alternately:
  31. ;;"http://www.fdn.fr/~lcourtes/software/guix/packages"
  32. )
  33. ;; XXX: Work around <http://bugs.gnu.org/13095>, present in Guile
  34. ;; up to 2.0.7.
  35. (module-define! (resolve-module '(web client))
  36. 'shutdown (const #f))
  37. (define (file-name->uri file)
  38. "Return the URI for FILE."
  39. (match (string-tokenize file (char-set-complement (char-set #\/)))
  40. ((_ ... system basename)
  41. (string->uri (string-append %url-base "/" system
  42. (match system
  43. ("mips64el-linux"
  44. "/20131017/")
  45. (_
  46. "/20130105/"))
  47. basename)))))
  48. (match (command-line)
  49. ((_ file expected-hash)
  50. (let ((uri (file-name->uri file)))
  51. (format #t "downloading file `~a' from `~a'...~%"
  52. file (uri->string uri))
  53. (let*-values (((resp data) (http-get uri #:decode-body? #f))
  54. ((hash) (bytevector->base16-string (sha256 data)))
  55. ((part) (string-append file ".part")))
  56. (if (string=? expected-hash hash)
  57. (begin
  58. (call-with-output-file part
  59. (lambda (port)
  60. (put-bytevector port data)))
  61. (rename-file part file))
  62. (begin
  63. (format (current-error-port)
  64. "file at `~a' has SHA256 ~a; expected ~a~%"
  65. (uri->string uri) hash expected-hash)
  66. (exit 1)))))))