final.scm 4.8 KB

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