final.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. (abort-to-prompt 'installer-step 'abort)))))
  60. (define (run-install-success-page)
  61. (match (current-clients)
  62. (()
  63. (message-window
  64. (G_ "Installation complete")
  65. (G_ "Reboot")
  66. (G_ "Congratulations! Installation is now complete. \
  67. You may remove the device containing the installation image and \
  68. press the button to reboot.")))
  69. (_
  70. ;; When there are clients connected, send them a message and keep going.
  71. (send-to-clients '(installation-complete))))
  72. ;; Return success so that the installer happily reboots.
  73. 'success)
  74. (define (run-install-failed-page)
  75. (match (current-clients)
  76. (()
  77. (match (choice-window
  78. (G_ "Installation failed")
  79. (G_ "Resume")
  80. (G_ "Restart the installer")
  81. (G_ "The final system installation step failed. You can resume from \
  82. a specific step, or restart the installer."))
  83. (1 (abort-to-prompt 'installer-step 'abort))
  84. (2
  85. ;; Keep going, the installer will be restarted later on.
  86. #t)))
  87. (_
  88. (send-to-clients '(installation-failure))
  89. #t)))
  90. (define* (run-install-shell locale
  91. #:key (users '()))
  92. (clear-screen)
  93. (newt-suspend)
  94. (let ((install-ok? (install-system locale #:users users)))
  95. (newt-resume)
  96. install-ok?))
  97. (define (run-final-page result prev-steps)
  98. (define (wait-for-clients)
  99. (unless (null? (current-clients))
  100. (installer-log-line "waiting with clients before starting final step")
  101. (send-to-clients '(starting-final-step))
  102. (match (select (current-clients) '() '())
  103. (((port _ ...) _ _)
  104. (read-line port)))))
  105. ;; Before generating the configuration file, give clients a chance to do
  106. ;; things such as changing the swap partition label.
  107. (wait-for-clients)
  108. (installer-log-line "proceeding with final step")
  109. (let* ((configuration (format-configuration prev-steps result))
  110. (user-partitions (result-step result 'partition))
  111. (locale (result-step result 'locale))
  112. (users (result-step result 'user))
  113. (install-ok?
  114. (with-mounted-partitions
  115. user-partitions
  116. (configuration->file configuration)
  117. (run-config-display-page #:locale locale)
  118. (run-install-shell locale #:users users))))
  119. (if install-ok?
  120. (run-install-success-page)
  121. (run-install-failed-page))))