2013-01-06 00:47:50 +01:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2016-04-15 00:08:28 +02:00
|
|
|
|
;;; Copyright © 2012, 2013, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
|
2012-10-24 23:10:09 +02:00
|
|
|
|
;;;
|
2013-01-06 00:47:50 +01:00
|
|
|
|
;;; This file is part of GNU Guix.
|
2012-10-24 23:10:09 +02:00
|
|
|
|
;;;
|
2013-01-06 00:47:50 +01:00
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
2012-10-24 23:10:09 +02:00
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
2013-01-06 00:47:50 +01:00
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
2012-10-24 23:10:09 +02:00
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
2013-01-06 00:47:50 +01:00
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
2012-10-24 23:10:09 +02:00
|
|
|
|
|
Replace individual scripts with master 'guix' script.
* scripts/guix.in: New script.
* Makefile.am (bin_SCRIPTS): Add 'scripts/guix'. Remove 'guix-build',
'guix-download', 'guix-import', 'guix-package', and 'guix-gc'.
(MODULES): Add 'guix/scripts/build.scm', 'guix/scripts/download.scm',
'guix/scripts/import.scm', 'guix/scripts/package.scm', and
'guix/scripts/gc.scm'.
* configure.ac (AC_CONFIG_FILES): Add 'scripts/guix'. Remove 'guix-build',
'guix-download', 'guix-import', 'guix-package', and 'guix-gc'.
* guix-build.in, guix-download.in, guix-gc.in, guix-import.in,
guix-package.in: Remove shell script boilerplate. Move to guix-COMMAND.in
to guix/scripts/COMMAND.scm. Rename module from (guix-COMMAND) to
(guix scripts COMMAND). Change "guix-COMMAND" to "guix COMMAND" in
usage help string.
* pre-inst-env.in: Add "@abs_top_builddir@/scripts" to the front of $PATH.
Export $GUIX_UNINSTALLED.
* tests/guix-build.sh, tests/guix-daemon.sh, tests/guix-download.sh,
tests/guix-gc.sh, tests/guix-package.sh: Use "guix COMMAND" instead of
"guix-COMMAND".
* doc/guix.texi: Replace all occurrences of "guix-COMMAND" with
"guix COMMAND".
* po/POTFILES.in: Update.
2013-02-14 10:15:25 +01:00
|
|
|
|
(define-module (guix scripts download)
|
2012-11-01 00:50:01 +01:00
|
|
|
|
#:use-module (guix ui)
|
2015-09-10 11:37:36 +02:00
|
|
|
|
#:use-module (guix scripts)
|
2012-10-24 23:10:09 +02:00
|
|
|
|
#:use-module (guix store)
|
2013-07-01 23:28:21 +02:00
|
|
|
|
#:use-module (guix hash)
|
2012-10-24 23:10:09 +02:00
|
|
|
|
#:use-module (guix utils)
|
Move base32 code to (guix base32).
* guix/utils.scm (bytevector-quintet-ref, bytevector-quintet-ref-right,
bytevector-quintet-length, bytevector-quintet-fold,
bytevector-quintet-fold-right, make-bytevector->base32-string,
%nix-base32-chars, %rfc4648-base32-chars, bytevector->base32-string,
bytevector->nix-base32-string, bytevector-quintet-set!,
bytevector-quintet-set-right!, base32-string-unfold,
base32-string-unfold-right, make-base32-string->bytevector,
base32-string->bytevector, nix-base32-string->bytevector): Move to...
* guix/base32.scm: ... here. New file.
* tests/utils.scm (%nix-hash, "bytevector->base32-string",
"base32-string->bytevector", "nix-base32-string->bytevector", "sha256
& bytevector->base32-string"): Move to...
* tests/base32.scm: ... here. New file
* guix-download.in, guix/derivations.scm, guix/packages.scm,
guix/snix.scm, tests/builders.scm, tests/derivations.scm: Adjust
accordingly.
* guix.scm (%public-modules): Add `base32'.
2012-11-11 22:33:28 +01:00
|
|
|
|
#:use-module (guix base32)
|
2016-10-29 01:16:24 +02:00
|
|
|
|
#:use-module ((guix download) #:hide (url-fetch))
|
|
|
|
|
#:use-module ((guix build download)
|
|
|
|
|
#:select (url-fetch current-terminal-columns))
|
|
|
|
|
#:use-module ((guix build syscalls)
|
|
|
|
|
#:select (terminal-columns))
|
2012-11-13 22:57:36 +01:00
|
|
|
|
#:use-module (web uri)
|
2012-10-24 23:10:09 +02:00
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:use-module (srfi srfi-1)
|
2016-10-29 01:16:24 +02:00
|
|
|
|
#:use-module (srfi srfi-26)
|
2012-10-24 23:10:09 +02:00
|
|
|
|
#:use-module (srfi srfi-37)
|
|
|
|
|
#:use-module (rnrs bytevectors)
|
2016-10-19 14:28:56 +02:00
|
|
|
|
#:use-module (ice-9 binary-ports)
|
2012-10-24 23:10:09 +02:00
|
|
|
|
#:export (guix-download))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Command-line options.
|
|
|
|
|
;;;
|
|
|
|
|
|
2016-10-29 01:16:24 +02:00
|
|
|
|
(define (download-to-file url file)
|
|
|
|
|
"Download the file at URI to FILE. Return FILE."
|
|
|
|
|
(let ((uri (string->uri url)))
|
|
|
|
|
(match (uri-scheme uri)
|
|
|
|
|
((or 'file #f)
|
|
|
|
|
(copy-file (uri-path uri) file))
|
|
|
|
|
(_
|
|
|
|
|
(url-fetch url file)))
|
|
|
|
|
file))
|
|
|
|
|
|
|
|
|
|
(define* (download-to-store* url #:key (verify-certificate? #t))
|
|
|
|
|
(with-store store
|
|
|
|
|
(download-to-store store url
|
|
|
|
|
#:verify-certificate? verify-certificate?)))
|
|
|
|
|
|
2012-10-24 23:10:09 +02:00
|
|
|
|
(define %default-options
|
|
|
|
|
;; Alist of default option values.
|
2016-11-07 23:29:45 +01:00
|
|
|
|
`((format . ,bytevector->nix-base32-string)
|
2016-10-29 01:16:24 +02:00
|
|
|
|
(verify-certificate? . #t)
|
|
|
|
|
(download-proc . ,download-to-store*)))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
|
|
|
|
|
(define (show-help)
|
2013-04-21 20:41:30 +02:00
|
|
|
|
(display (_ "Usage: guix download [OPTION] URL
|
2016-10-29 01:16:24 +02:00
|
|
|
|
Download the file at URL to the store or to the given file, and print its
|
|
|
|
|
file name and the hash of its contents.
|
2013-04-21 20:41:30 +02:00
|
|
|
|
|
|
|
|
|
Supported formats: 'nix-base32' (default), 'base32', and 'base16'
|
|
|
|
|
('hex' and 'hexadecimal' can be used as well).\n"))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
(format #t (_ "
|
2013-04-21 20:41:30 +02:00
|
|
|
|
-f, --format=FMT write the hash in the given format"))
|
2016-11-07 23:29:45 +01:00
|
|
|
|
(format #t (_ "
|
|
|
|
|
--no-check-certificate
|
|
|
|
|
do not validate the certificate of HTTPS servers "))
|
2016-10-29 01:16:24 +02:00
|
|
|
|
(format #f (_ "
|
|
|
|
|
-o, --output=FILE download to FILE"))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
(newline)
|
|
|
|
|
(display (_ "
|
|
|
|
|
-h, --help display this help and exit"))
|
|
|
|
|
(display (_ "
|
|
|
|
|
-V, --version display version information and exit"))
|
|
|
|
|
(newline)
|
2013-01-05 15:55:47 +01:00
|
|
|
|
(show-bug-report-information))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
|
|
|
|
|
(define %options
|
|
|
|
|
;; Specifications of the command-line options.
|
|
|
|
|
(list (option '(#\f "format") #t #f
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(define fmt-proc
|
|
|
|
|
(match arg
|
|
|
|
|
("nix-base32"
|
|
|
|
|
bytevector->nix-base32-string)
|
|
|
|
|
("base32"
|
|
|
|
|
bytevector->base32-string)
|
|
|
|
|
((or "base16" "hex" "hexadecimal")
|
|
|
|
|
bytevector->base16-string)
|
|
|
|
|
(x
|
2013-04-11 22:30:06 +02:00
|
|
|
|
(leave (_ "unsupported hash format: ~a~%") arg))))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
|
|
|
|
|
(alist-cons 'format fmt-proc
|
|
|
|
|
(alist-delete 'format result))))
|
2016-11-07 23:29:45 +01:00
|
|
|
|
(option '("no-check-certificate") #f #f
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(alist-cons 'verify-certificate? #f result)))
|
2016-10-29 01:16:24 +02:00
|
|
|
|
(option '(#\o "output") #t #f
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(alist-cons 'download-proc
|
|
|
|
|
(lambda* (url #:key verify-certificate?)
|
|
|
|
|
(download-to-file url arg))
|
|
|
|
|
(alist-delete 'download result))))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
|
|
|
|
|
(option '(#\h "help") #f #f
|
|
|
|
|
(lambda args
|
|
|
|
|
(show-help)
|
|
|
|
|
(exit 0)))
|
|
|
|
|
(option '(#\V "version") #f #f
|
|
|
|
|
(lambda args
|
2013-02-17 16:25:30 +01:00
|
|
|
|
(show-version-and-exit "guix download")))))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Entry point.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (guix-download . args)
|
|
|
|
|
(define (parse-options)
|
|
|
|
|
;; Return the alist of option values.
|
2013-04-27 16:46:39 +02:00
|
|
|
|
(args-fold* args %options
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(leave (_ "~A: unrecognized option~%") name))
|
|
|
|
|
(lambda (arg result)
|
2015-11-23 17:37:29 +01:00
|
|
|
|
(when (assq 'argument result)
|
|
|
|
|
(leave (_ "~A: extraneous argument~%") arg))
|
|
|
|
|
|
2013-04-27 16:46:39 +02:00
|
|
|
|
(alist-cons 'argument arg result))
|
|
|
|
|
%default-options))
|
2012-10-24 23:10:09 +02:00
|
|
|
|
|
2013-03-07 19:29:12 +01:00
|
|
|
|
(with-error-handling
|
|
|
|
|
(let* ((opts (parse-options))
|
2015-11-23 17:32:02 +01:00
|
|
|
|
(arg (or (assq-ref opts 'argument)
|
|
|
|
|
(leave (_ "no download URI was specified~%"))))
|
2013-03-07 19:29:12 +01:00
|
|
|
|
(uri (or (string->uri arg)
|
2013-04-21 10:08:40 +02:00
|
|
|
|
(leave (_ "~a: failed to parse URI~%")
|
2013-03-07 19:29:12 +01:00
|
|
|
|
arg)))
|
2016-10-29 01:16:24 +02:00
|
|
|
|
(fetch (assq-ref opts 'download-proc))
|
|
|
|
|
(path (parameterize ((current-terminal-columns
|
|
|
|
|
(terminal-columns)))
|
|
|
|
|
(fetch arg
|
|
|
|
|
#:verify-certificate?
|
|
|
|
|
(assq-ref opts 'verify-certificate?))))
|
2013-03-07 19:29:12 +01:00
|
|
|
|
(hash (call-with-input-file
|
|
|
|
|
(or path
|
2013-04-21 10:08:40 +02:00
|
|
|
|
(leave (_ "~a: download failed~%")
|
2013-03-07 19:29:12 +01:00
|
|
|
|
arg))
|
2013-07-03 01:17:11 +02:00
|
|
|
|
port-sha256))
|
2013-03-07 19:29:12 +01:00
|
|
|
|
(fmt (assq-ref opts 'format)))
|
|
|
|
|
(format #t "~a~%~a~%" path (fmt hash))
|
|
|
|
|
#t)))
|