2013-01-05 18:47:50 -05:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
|
2012-10-24 17:10:09 -04:00
|
|
|
|
;;;
|
2013-01-05 18:47:50 -05:00
|
|
|
|
;;; This file is part of GNU Guix.
|
2012-10-24 17:10:09 -04:00
|
|
|
|
;;;
|
2013-01-05 18:47:50 -05:00
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
2012-10-24 17:10:09 -04: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-05 18:47:50 -05:00
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
2012-10-24 17:10:09 -04: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-05 18:47:50 -05:00
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
2012-10-24 17:10:09 -04: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 04:15:25 -05:00
|
|
|
|
(define-module (guix scripts download)
|
2012-10-31 19:50:01 -04:00
|
|
|
|
#:use-module (guix ui)
|
2015-09-10 05:37:36 -04:00
|
|
|
|
#:use-module (guix scripts)
|
2012-10-24 17:10:09 -04:00
|
|
|
|
#:use-module (guix store)
|
2013-07-01 17:28:21 -04:00
|
|
|
|
#:use-module (guix hash)
|
2012-10-24 17:10:09 -04: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 16:33:28 -05:00
|
|
|
|
#:use-module (guix base32)
|
2013-04-21 16:40:23 -04:00
|
|
|
|
#:use-module (guix download)
|
2012-11-13 16:57:36 -05:00
|
|
|
|
#:use-module (web uri)
|
2012-10-24 17:10:09 -04:00
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
#:use-module (srfi srfi-37)
|
|
|
|
|
#:use-module (rnrs bytevectors)
|
|
|
|
|
#:use-module (rnrs io ports)
|
|
|
|
|
#:export (guix-download))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Command-line options.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define %default-options
|
|
|
|
|
;; Alist of default option values.
|
|
|
|
|
`((format . ,bytevector->nix-base32-string)))
|
|
|
|
|
|
|
|
|
|
(define (show-help)
|
2013-04-21 14:41:30 -04:00
|
|
|
|
(display (_ "Usage: guix download [OPTION] URL
|
2012-10-24 17:10:09 -04:00
|
|
|
|
Download the file at URL, add it to the store, and print its store path
|
2013-04-21 14:41:30 -04:00
|
|
|
|
and the hash of its contents.
|
|
|
|
|
|
|
|
|
|
Supported formats: 'nix-base32' (default), 'base32', and 'base16'
|
|
|
|
|
('hex' and 'hexadecimal' can be used as well).\n"))
|
2012-10-24 17:10:09 -04:00
|
|
|
|
(format #t (_ "
|
2013-04-21 14:41:30 -04:00
|
|
|
|
-f, --format=FMT write the hash in the given format"))
|
2012-10-24 17:10:09 -04:00
|
|
|
|
(newline)
|
|
|
|
|
(display (_ "
|
|
|
|
|
-h, --help display this help and exit"))
|
|
|
|
|
(display (_ "
|
|
|
|
|
-V, --version display version information and exit"))
|
|
|
|
|
(newline)
|
2013-01-05 09:55:47 -05:00
|
|
|
|
(show-bug-report-information))
|
2012-10-24 17:10:09 -04: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 16:30:06 -04:00
|
|
|
|
(leave (_ "unsupported hash format: ~a~%") arg))))
|
2012-10-24 17:10:09 -04:00
|
|
|
|
|
|
|
|
|
(alist-cons 'format fmt-proc
|
|
|
|
|
(alist-delete 'format result))))
|
|
|
|
|
|
|
|
|
|
(option '(#\h "help") #f #f
|
|
|
|
|
(lambda args
|
|
|
|
|
(show-help)
|
|
|
|
|
(exit 0)))
|
|
|
|
|
(option '(#\V "version") #f #f
|
|
|
|
|
(lambda args
|
2013-02-17 10:25:30 -05:00
|
|
|
|
(show-version-and-exit "guix download")))))
|
2012-10-24 17:10:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Entry point.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (guix-download . args)
|
|
|
|
|
(define (parse-options)
|
|
|
|
|
;; Return the alist of option values.
|
2013-04-27 10:46:39 -04:00
|
|
|
|
(args-fold* args %options
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(leave (_ "~A: unrecognized option~%") name))
|
|
|
|
|
(lambda (arg result)
|
|
|
|
|
(alist-cons 'argument arg result))
|
|
|
|
|
%default-options))
|
2012-10-24 17:10:09 -04:00
|
|
|
|
|
2013-03-07 13:29:12 -05:00
|
|
|
|
(with-error-handling
|
|
|
|
|
(let* ((opts (parse-options))
|
|
|
|
|
(store (open-connection))
|
|
|
|
|
(arg (assq-ref opts 'argument))
|
|
|
|
|
(uri (or (string->uri arg)
|
2013-04-21 04:08:40 -04:00
|
|
|
|
(leave (_ "~a: failed to parse URI~%")
|
2013-03-07 13:29:12 -05:00
|
|
|
|
arg)))
|
|
|
|
|
(path (case (uri-scheme uri)
|
|
|
|
|
((file)
|
|
|
|
|
(add-to-store store (basename (uri-path uri))
|
|
|
|
|
#f "sha256" (uri-path uri)))
|
|
|
|
|
(else
|
2013-04-21 16:40:23 -04:00
|
|
|
|
(download-to-store store (uri->string uri)
|
|
|
|
|
(basename (uri-path uri))))))
|
2013-03-07 13:29:12 -05:00
|
|
|
|
(hash (call-with-input-file
|
|
|
|
|
(or path
|
2013-04-21 04:08:40 -04:00
|
|
|
|
(leave (_ "~a: download failed~%")
|
2013-03-07 13:29:12 -05:00
|
|
|
|
arg))
|
2013-07-02 19:17:11 -04:00
|
|
|
|
port-sha256))
|
2013-03-07 13:29:12 -05:00
|
|
|
|
(fmt (assq-ref opts 'format)))
|
|
|
|
|
(format #t "~a~%~a~%" path (fmt hash))
|
|
|
|
|
#t)))
|