aboutsummaryrefslogtreecommitdiff
path: root/gnu/installer/utils.scm
blob: ddb96bc3382fad948cd10e4fddb9f752bec4a82a (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; 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.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; 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
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu installer utils)
  #:use-module (guix utils)
  #:use-module (guix build utils)
  #:use-module (guix i18n)
  #:use-module (srfi srfi-34)
  #:use-module (ice-9 rdelim)
  #:use-module (ice-9 regex)
  #:use-module (ice-9 textual-ports)
  #:export (read-lines
            read-all
            nearest-exact-integer
            read-percentage
            run-shell-command))

(define* (read-lines #:optional (port (current-input-port)))
  "Read lines from PORT and return them as a list."
  (let loop ((line (read-line port))
             (lines '()))
    (if (eof-object? line)
        (reverse lines)
        (loop (read-line port)
              (cons line lines)))))

(define (read-all file)
  "Return the content of the given FILE as a string."
  (call-with-input-file file
    get-string-all))

(define (nearest-exact-integer x)
  "Given a real number X, return the nearest exact integer, with ties going to
the nearest exact even integer."
  (inexact->exact (round x)))

(define (read-percentage percentage)
  "Read PERCENTAGE string and return the corresponding percentage as a
number. If no percentage is found, return #f"
  (let ((result (string-match "^([0-9]+)%$" percentage)))
    (and result
         (string->number (match:substring result 1)))))

(define* (run-shell-command command #:key locale)
  "Run COMMAND, a string, with Bash, and in the given LOCALE.  Return true if
COMMAND exited successfully, #f otherwise."
  (define (pause)
    (format #t (G_ "Press Enter to continue.~%"))
    (read-line (current-input-port)))

  (call-with-temporary-output-file
   (lambda (file port)
     (when locale
       (let ((supported? (false-if-exception
                          (setlocale LC_ALL locale))))
         ;; If LOCALE is not supported, then set LANGUAGE, which might at
         ;; least give us translated messages.
         (if supported?
             (format port "export LC_ALL=\"~a\"~%" locale)
             (format port "export LANGUAGE=\"~a\"~%"
                     (string-take locale
                                  (string-index locale #\_))))))

     (format port "exec ~a~%" command)
     (close port)

     (guard (c ((invoke-error? c)
                (newline)
                (format (current-error-port)
                        (G_ "Command failed with exit code ~a.~%")
                        (invoke-error-exit-status c))
                (pause)
                #f))
       (invoke "bash" "--init-file" file)
       (newline)
       (pause)
       #t))))
alls to 'gettext'. 2019-04-12installer: Choosing a locale opens the translated manual on tty2.Ludovic Courtès Suggested by Florian Pelz. * gnu/system/install.scm (%installation-node-names): New variable. (log-to-info): Expect the chosen locale as an argument. Compute the language, Info file name, and node name. Install the locale. (documentation-shepherd-service): Add 'locale' parameter to the 'start' action and honor it. Set GUIX_LOCPATH and TERM as environment variables for the process. * gnu/installer.scm (apply-locale): Use (gnu services herd). Call 'stop-service' and 'start-service' with the chosen locale. 2019-04-07installer: Generalize desktop environments to system services.Ludovic Courtès * gnu/installer/services.scm (<desktop-environment>): Rename to... (<system-service>): ... this. Add a 'type' field. (%desktop-environments): Rename to... (%system-services): ... this. (desktop-system-service?): New procedure. (desktop-environments->configuration): Rename to... (system-services->configuration): ... this. Determine the base list of services based on whether SERVICES contains at least one "desktop" service. * gnu/installer/newt/services.scm (run-desktop-environments-cbt-page): Adjust accordingly. * gnu/installer.scm (installer-steps): Likewise. 2019-04-07installer: Move the 'locale' step before the 'welcome' step.Ludovic Courtès * gnu/installer.scm (installer-steps): Move the 'locale step before 'welcome. 2019-03-27installer: Produce an 'initrd-modules' field if needed.Ludovic Courtès * gnu/installer/parted.scm (root-user-partition?): New procedure. (bootloader-configuration): Use it. (user-partition-missing-modules, initrd-configuration): New procedures. (user-partitions->configuration): Call 'initrd-configuration'.o * gnu/installer.scm (not-config?): Rename to... (module-to-import?): ... this. Add cases to exclude non-installer and non-build (gnu …) modules. (installer-program)[installer-builder]: Add GUIX to the extension list. 2019-03-25installer: Set the system's 'keyboard-layout' field.Ludovic Courtès * gnu/installer/newt/keymap.scm (keyboard-layout->configuration): New procedure. * gnu/installer.scm (compute-keymap-step): Return RESULT. (installer-steps) <'keymap>: Add 'configuration-formatter' field. (installer-program): Use (gnu installer newt keymap). * gnu/installer/parted.scm (bootloader-configuration): Set 'keyboard-layout'. 2019-01-28gnu: Move most packages from guile.scm to new module.Ricardo Wurmus * gnu/packages/guile.scm (artanis, guildhall, guile-aspell, guile-bash, guile-8sync, guile-daemon, guile-dsv, guile-fibers, guile-syntax-highlight, guile-sjson, guile-colorized, guile-pfds, guile-aa-tree, guile-simple-zmq, jupyter-guile-kernel, guile-sparql, guile-debbugs, guile-email, guile-debbugs-next, guile-newt, guile-mastodon, guile-parted, guile-xosd, guile-dbi, guile-dbd-sqlite3, guile-config, guile-hall, guile-ics, guile-wisp, guile-sly, g-wrap, guile-miniadapton, guile-reader, guile2.2-reader, guile-ncurses, guile-ncurses/gpm, guile-lib, guile2.0-lib, guile2.2-lib, guile-minikanren, guile2.0-minikanren, guile2.2-minikanren, guile-irregex, guile2.0-irregex, guile2.2-irregex, haunt, guile2.0-haunt, guile2.2-haunt, guile-redis, guile2.0-redis, guile2.2-redis, guile-commonmark, guile2.0-commonmark, guile2.2-commonmark, mcron, mcron2): Move these variables from here... * gnu/packages/guile-xyz.scm: ...to this new file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. * gnu/installer.scm, gnu/packages/bioinformatics.scm, gnu/packages/ci.scm, gnu/packages/gtk.scm, gnu/packages/guile.scm, gnu/packages/mail.scm, gnu/packages/package-management.scm, gnu/packages/skribilo.scm, gnu/packages/web.scm, gnu/services/mcron.scm: Update module references. 2019-01-17installer: Various renamings.Mathieu Othacehe 1. s/partitionment/partitioning/ 2. s/crypted/encrypted/ * gnu/installer.scm (installer-steps): Apply renamings. * gnu/installer/newt/partition.scm (run-disk-page): ditto, * gnu/installer/parted.scm (auto-partition): ditto, (luks-format-and-open): ditto, (luks-close): ditto, (user-partitions->configuration): ditto. 2019-01-17installer: partionment: Add encryption support.Mathieu Othacehe * gnu/installer.scm (set-installer-path): Add cryptsetup. * gnu/installer/newt/partition.scm (prompt-luks-passwords): New procedure, (run-partioning-page): Add the possibility to set encryption to "On" on a partition and choose a label, add a new partition scheme: "Guided - using the entire disk with encryption", prompt for encryption passwords before proceeding to formating. * gnu/installer/parted.scm (<user-partition>)[crypt-label], [crypt-password]: New fields, (partition-description): add the encryption label, (user-partition-description): add an encryption field, (auto-partition): add two partitioning schemes: entire-crypted-root and entire-crypted-root-home, (call-with-luks-key-file): new procedure, (user-partition-upper-path): new procedure, (luks-format-and-open): new procedure, (luks-close): new procedure, (format-user-partitions): format and open luks partitions before creating file-system. (mount-user-partitions): use the path returned by user-partition-upper-path, (umount-user-partitions): close the luks partitions, (user-partition->file-system): set device field to label for luks partitions and to uuid for the rest, (user-partition->mapped-device): new procedure, (user-partitions->configuration): add mapped-devices field. 2019-01-17installer: Display an eventual backtrace in a page.Mathieu Othacehe * gnu/installer.scm (installer-program): Write the backtrace in "/tmp/last-installer-error" and pass the filename to installer-exit-error. * gnu/installer/newt.scm (exit-error): Display the file passed above in a textbox. 2019-01-17installer: Reorder partitionment step.Mathieu Othacehe * gnu/installer.scm (installer-steps): Run partitionment step after keymap step, so that the keyboard is correctly mapped when filling the mount-point entry in partitionment page. 2019-01-17installer: Add partitioning support.Mathieu Othacehe * gnu/installer.scm (installer-steps): Add partitioning step. * gnu/installer/newt.scm (newt-installer): Add partition-page field. * gnu/installer/newt/partition.scm: New file. * gnu/installer/parted.scm: New file. * gnu/installer/record (installer): New partition-page field. * gnu/local.mk (GNU_SYSTEM_MODULES): Add new files. * po/guix/POTFILES.in: Add new files. 2019-01-17installer: Fix comments.Mathieu Othacehe * gnu/installer.scm (installer-steps): Fix comments. 2019-01-17installer: Add hostname.Mathieu Othacehe * gnu/installer/hostname.scm: New file. * gnu/installer.scm (installer-program): Use new module above. * gnu/local.mk (GNU_SYSTEM_MODULES): Add new file. * po/guix/POTFILES.in: Add new file. 2019-01-17installer: Add services page.Mathieu Othacehe Add a page to select services, for now only desktop environments choice is available. * gnu/installer.scm (steps): Add services step. * gnu/installer/newt.scm (newt-installer): Add services-page field. * gnu/installer/newt/services.scm: New file. * gnu/installer/record.scm (installer): Add services-page field. * gnu/installer/services.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add new files. * po/guix/POTFILES.in: Add new files. 2019-01-17installer: Do not ask for keyboard model.Mathieu Othacehe Suppose that the keyboard model is "pc105". * gnu/installer.scm (apply-keymap): Remove model ... * gnu/installer/newt/keymap.scm (run-keymap-page): passed here. (run-model-page): remove procedure * gnu/installer/record.scm (installer): Edit keymap-page prototype in comment. * gnu/installer/keymap.scm (default-keyboard-model): New exported parameter. 2019-01-17installer: Add configuration formatter.Mathieu Othacehe * gnu/installer.scm (installer-steps): Add configuration-formatter procedures. * gnu/installer/final.scm: New file. * gnu/installer/locale.scm (locale->configuration): New exported procedure. * gnu/installer/newt.scm (newt-installer): Add final page. * gnu/installer/newt/final.scm: New file. * gnu/installer/record.scm (installer): Add final-page field. * gnu/installer/timezone.scm (posix-tz->configuration): New exported procedure. * gnu/installer/steps.scm (installer-step): Rename configuration-proc field to configuration-formatter. (%installer-configuration-file): New exported parameter, (%installer-target-dir): ditto, (%configuration-file-width): ditto, (format-configuration): new exported procedure, (configuration->file): new exported procedure. 2019-01-17installer: Fix locale installation.Mathieu Othacehe For some mysterious reason, calling 'setlocale' as first instruction of installer-builder does not install unicode support correctly. So set LANG env variable and start the installer until this is understood. * gnu/installer.scm (installer-program): Wrap installer-builder to have the opportunity to set LANG environment variable before starting the installer. 2019-01-17installer: Move everything to the build side.Mathieu Othacehe * gnu/installer.scm: Rename to ... * gnu/installer/record.scm: ... this. * gnu/installer/build-installer.scm: Move everything to the build side and rename to gnu/installer.scm. * gnu/installer/newt.scm: Remove all the gexps and add depencies to newt modules as this code will only be used on the build side by now. * gnu/local.mk (GNU_SYSTEM_MODULES): Adapt it, (dist_installer_DATA): New rule to install installer's aux-files. * gnu/system/install.scm (%installation-services): Use only 'installer-program' from (gnu installer). The installer is now choosen on the build side. * guix/self.scm (*system-modules*): Restore previous behaviour and add all installer files to #:extra-files field of the scheme-node. * po/guix/POTFILES.in: Adapt it. 2019-01-17gnu: Add graphical installer support.Mathieu Othacehe * configure.ac: Require that guile-newt is available. * gnu/installer.scm: New file. * gnu/installer/aux-files/logo.txt: New file. * gnu/installer/build-installer.scm: New file. * gnu/installer/connman.scm: New file. * gnu/installer/keymap.scm: New file. * gnu/installer/locale.scm: New file. * gnu/installer/newt.scm: New file. * gnu/installer/newt/ethernet.scm: New file. * gnu/installer/newt/hostname.scm: New file. * gnu/installer/newt/keymap.scm: New file. * gnu/installer/newt/locale.scm: New file. * gnu/installer/newt/menu.scm: New file. * gnu/installer/newt/network.scm: New file. * gnu/installer/newt/page.scm: New file. * gnu/installer/newt/timezone.scm: New file. * gnu/installer/newt/user.scm: New file. * gnu/installer/newt/utils.scm: New file. * gnu/installer/newt/welcome.scm: New file. * gnu/installer/newt/wifi.scm: New file. * gnu/installer/steps.scm: New file. * gnu/installer/timezone.scm: New file. * gnu/installer/utils.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add previous files. * gnu/system.scm: Export %root-account. * gnu/system/install.scm (%installation-services): Use kmscon instead of linux VT for all tty. (installation-os)[users]: Add the graphical installer as shell of the root account. [packages]: Add font related packages. * po/guix/POTFILES.in: Add installer files.