Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
4050e5d6 | 2 | ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> |
aa1e1947 | 3 | ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org> |
ac5aa288 | 4 | ;;; |
233e7676 | 5 | ;;; This file is part of GNU Guix. |
ac5aa288 | 6 | ;;; |
233e7676 | 7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
ac5aa288 LC |
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. | |
11 | ;;; | |
233e7676 | 12 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
ac5aa288 LC |
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. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
233e7676 | 18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
ac5aa288 LC |
19 | |
20 | ;;; | |
21 | ;;; Download a binary file from an external source. | |
22 | ;;; | |
23 | ||
24 | (use-modules (ice-9 match) | |
25 | (web uri) | |
26 | (web client) | |
27 | (rnrs io ports) | |
28 | (srfi srfi-11) | |
a1c39ede LC |
29 | (guix utils) |
30 | (guix hash)) | |
ac5aa288 LC |
31 | |
32 | (define %url-base | |
04732c37 LC |
33 | "http://alpha.gnu.org/gnu/guix/bootstrap" |
34 | ||
35 | ;; Alternately: | |
36 | ;;"http://www.fdn.fr/~lcourtes/software/guix/packages" | |
37 | ) | |
ac5aa288 | 38 | |
881a4cf1 LC |
39 | ;; XXX: Work around <http://bugs.gnu.org/13095>, present in Guile |
40 | ;; up to 2.0.7. | |
41 | (module-define! (resolve-module '(web client)) | |
42 | 'shutdown (const #f)) | |
43 | ||
ac5aa288 LC |
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) | |
68c141f1 | 48 | (string->uri (string-append %url-base "/" system |
aa1e1947 MW |
49 | (match system |
50 | ("armhf-linux" | |
51 | "/20150101/") | |
52 | (_ | |
53 | "/20131110/")) | |
54 | basename))))) | |
ac5aa288 LC |
55 | |
56 | (match (command-line) | |
57 | ((_ file expected-hash) | |
58 | (let ((uri (file-name->uri file))) | |
8c3d8894 | 59 | (format #t "downloading file `~a'~%from `~a'...~%" |
ac5aa288 LC |
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) | |
65 | (begin | |
66 | (call-with-output-file part | |
67 | (lambda (port) | |
68 | (put-bytevector port data))) | |
69 | (rename-file part file)) | |
70 | (begin | |
71 | (format (current-error-port) | |
72 | "file at `~a' has SHA256 ~a; expected ~a~%" | |
73 | (uri->string uri) hash expected-hash) | |
74 | (exit 1))))))) |