projects/guix·blob python-team · refs

153 lines · 5.7 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018, 2020 Mathieu Othacehe <[email protected]>
3;;; Copyright © 2019, 2020 Ludovic Courtès <[email protected]>
4;;; Copyright © 2024 Janneke Nieuwenhuizen <[email protected]>
5;;;
6;;; This file is part of GNU Guix.
7;;;
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.
12;;;
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.
17;;;
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/>.
20
21(define-module (gnu installer newt final)
22 #:use-module (gnu installer final)
23 #:use-module (gnu installer parted)
24 #:use-module (gnu installer steps)
25 #:use-module (gnu installer utils)
26 #:use-module (gnu installer newt page)
27 #:use-module (gnu installer newt utils)
28 #:use-module (guix i18n)
29 #:use-module (guix colors)
30 #:use-module (srfi srfi-34)
31 #:use-module (srfi srfi-35)
32 #:use-module (ice-9 match)
33 #:use-module ((ice-9 rdelim) #:select (read-line))
34 #:use-module (newt)
35 #:export (run-final-page))
36
37(define* (strip-prefix file #:optional (prefix (%installer-target-dir)))
38 "Strip PREFIX from FILE, if PREFIX actually is a prefix of FILE."
39 (if (string-prefix? prefix file)
40 (string-drop file (string-length prefix))
41 file))
42
43(define* (run-config-display-page #:key locale)
44 (let ((width (max 70 (- (screen-columns) 20)))
45 (height (default-listbox-height)))
46 (run-file-textbox-page
47 #:info-text (format #f (G_ "\
48We're now ready to proceed with the installation! \
49A system configuration file has been generated, it is displayed below. \
50This file will be available as '~a' on the installed system. \
51The new system will be created from this file once you've pressed OK. \
52This will take a few minutes.")
53 (strip-prefix (%installer-configuration-file)))
54 #:title (G_ "Configuration file")
55 #:file (%installer-configuration-file)
56 #:edit-button? #t
57 #:editor-locale locale
58 #:info-textbox-width width
59 #:file-textbox-width width
60 #:file-textbox-height height
61 #:exit-button-callback-procedure
62 (lambda ()
63 (abort-to-prompt 'installer-step 'abort)))))
64
65(define (run-install-success-page)
66 (match (current-clients)
67 (()
68 (message-window
69 (G_ "Installation complete")
70 (G_ "Reboot")
71 (G_ "Congratulations! Installation is now complete. \
72You may remove the device containing the installation image and \
73press the button to reboot.")))
74 (_
75 ;; When there are clients connected, send them a message and keep going.
76 (send-to-clients '(installation-complete))))
77
78 ;; Return success so that the installer happily reboots.
79 'success)
80
81(define (run-install-failed-page)
82 (match (current-clients)
83 (()
84 (match (ternary-window
85 (G_ "Installation failed")
86 (G_ "Resume")
87 (G_ "Restart the installer")
88 (G_ "Report the failure")
89 (G_ "The final system installation step failed. You can resume from \
90a specific step, or restart the installer."))
91 (1 (abort-to-prompt 'installer-step 'abort))
92 (2
93 ;; Keep going, the installer will be restarted later on.
94 #t)
95 (3 (raise
96 (condition
97 (&user-abort-error))))))
98 (_
99 (send-to-clients '(installation-failure))
100 #t)))
101
102(define* (run-install-shell locale
103 #:key (users '()))
104 (clear-screen)
105 (newt-suspend)
106 (let ((install-ok? (install-system locale #:users users)))
107 (newt-resume)
108 install-ok?))
109
110(define (run-final-page-install result prev-steps)
111 (define (wait-for-clients)
112 (unless (null? (current-clients))
113 (installer-log-line "waiting with clients before starting final step")
114 (send-to-clients '(starting-final-step))
115 (match (select (current-clients) '() '())
116 (((port _ ...) _ _)
117 (read-line port)))))
118
119 ;; Before generating the configuration file, give clients a chance to do
120 ;; things such as changing the swap partition label.
121 (wait-for-clients)
122
123 (installer-log-line "proceeding with final step")
124 (let* ((configuration (format-configuration prev-steps result))
125 (user-partitions (result-step result 'partition))
126 (locale (result-step result 'locale))
127 (users (result-step result 'user))
128 (install-ok?
129 (with-mounted-partitions
130 user-partitions
131 (configuration->file configuration)
132 (run-config-display-page #:locale locale)
133 (run-install-shell locale #:users users))))
134 (if install-ok?
135 (run-install-success-page)
136 (run-install-failed-page))))
137
138(define (dry-run-final-page result prev-steps)
139 (installer-log-line "proceeding with final step -- dry-run")
140 (let* ((configuration (format-configuration prev-steps result))
141 (user-partitions (result-step result 'partition))
142 (locale (result-step result 'locale))
143 (users (result-step result 'user))
144 (file (configuration->file configuration))
145 (install-ok? (run-config-display-page #:locale locale)))
146 (if install-ok?
147 (run-install-success-page)
148 (run-install-failed-page))))
149
150(define (run-final-page result prev-steps dry-run?)
151 (if dry-run?
152 (dry-run-final-page result prev-steps)
153 (run-final-page-install result prev-steps)))