1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Download a binary file from an external source.
24 (use-modules (ice-9 match)
33 "http://alpha.gnu.org/gnu/guix/bootstrap"
36 ;;"http://www.fdn.fr/~lcourtes/software/guix/packages"
39 ;; XXX: Work around <http://bugs.gnu.org/13095>, present in Guile
41 (module-define! (resolve-module '(web client))
44 (define (file-name->uri file)
45 "Return the URI for FILE."
46 (match (string-tokenize file (char-set-complement (char-set #\/)))
47 ((_ ... system basename)
48 (string->uri (string-append %url-base "/" system
57 ((_ file expected-hash)
58 (let ((uri (file-name->uri file)))
59 (format #t "downloading file `~a' from `~a'...~%"
60 file (uri->string uri))
61 (let*-values (((resp data) (http-get uri #:decode-body? #f))
62 ((hash) (bytevector->base16-string (sha256 data)))
63 ((part) (string-append file ".part")))
64 (if (string=? expected-hash hash)
66 (call-with-output-file part
68 (put-bytevector port data)))
69 (rename-file part file))
71 (format (current-error-port)
72 "file at `~a' has SHA256 ~a; expected ~a~%"
73 (uri->string uri) hash expected-hash)