1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Download a binary file from an external source.
25 (use-modules (ice-9 match)
34 "http://alpha.gnu.org/gnu/guix/bootstrap"
37 ;;"http://www.fdn.fr/~lcourtes/software/guix/packages"
40 (define (file-name->uri file)
41 "Return the URI for FILE."
42 (match (string-tokenize file (char-set-complement (char-set #\/)))
43 ((_ ... system basename)
45 (string-append %url-base "/" system
56 ((_ file expected-hash)
57 (let ((uri (file-name->uri file)))
58 (format #t "downloading file `~a'~%from `~a'...~%"
59 file (uri->string uri))
60 (let*-values (((resp data) (http-get uri #:decode-body? #f))
61 ((hash) (bytevector->base16-string (sha256 data)))
62 ((part) (string-append file ".part")))
63 (if (string=? expected-hash hash)
65 (call-with-output-file part
67 (put-bytevector port data)))
68 (rename-file part file))
70 (format (current-error-port)
71 "file at `~a' has SHA256 ~a; expected ~a~%"
72 (uri->string uri) hash expected-hash)