newt.scm 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu installer newt)
  19. #:use-module (gnu installer record)
  20. #:use-module (gnu installer utils)
  21. #:use-module (gnu installer dump)
  22. #:use-module (gnu installer newt ethernet)
  23. #:use-module (gnu installer newt final)
  24. #:use-module (gnu installer newt parameters)
  25. #:use-module (gnu installer newt hostname)
  26. #:use-module (gnu installer newt keymap)
  27. #:use-module (gnu installer newt locale)
  28. #:use-module (gnu installer newt menu)
  29. #:use-module (gnu installer newt network)
  30. #:use-module (gnu installer newt page)
  31. #:use-module (gnu installer newt partition)
  32. #:use-module (gnu installer newt services)
  33. #:use-module (gnu installer newt substitutes)
  34. #:use-module (gnu installer newt timezone)
  35. #:use-module (gnu installer newt user)
  36. #:use-module (gnu installer newt utils)
  37. #:use-module (gnu installer newt welcome)
  38. #:use-module (gnu installer newt wifi)
  39. #:use-module (guix config)
  40. #:use-module (guix discovery)
  41. #:use-module (guix i18n)
  42. #:use-module (srfi srfi-1)
  43. #:use-module (srfi srfi-26)
  44. #:use-module (srfi srfi-34)
  45. #:use-module (srfi srfi-35)
  46. #:use-module (ice-9 ftw)
  47. #:use-module (ice-9 match)
  48. #:use-module (newt)
  49. #:export (newt-installer))
  50. (define (init)
  51. (newt-init)
  52. (clear-screen)
  53. (set-screen-size!)
  54. (installer-log-line "Display is ~ax~a." (screen-columns) (screen-rows))
  55. (push-help-line
  56. (format #f (G_ "Press <F1> for installation parameters."))))
  57. (define (exit)
  58. (newt-finish)
  59. (clear-screen))
  60. (define (exit-error error)
  61. ;; Newt may be suspended in the context of the "install-system"
  62. ;; procedure. Resume it unconditionnally.
  63. (newt-resume)
  64. (newt-set-color COLORSET-ROOT "white" "red")
  65. (define action
  66. (run-textbox-page
  67. #:info-text (G_ "The installer has encountered an unexpected problem. \
  68. The backtrace is displayed below. You may choose to exit or create a dump \
  69. archive.")
  70. #:title (G_ "Unexpected problem")
  71. #:content error
  72. #:buttons-spec
  73. (list
  74. (cons (G_ "Dump") (const 'dump))
  75. (cons (G_ "Exit") (const 'exit)))))
  76. (newt-set-color COLORSET-ROOT "white" "blue")
  77. action)
  78. (define (report-page dump-archive)
  79. (define text
  80. (format #f (G_ "The dump archive was created as ~a. Would you like to \
  81. send this archive to the Guix servers?") dump-archive))
  82. (define title (G_ "Dump archive created"))
  83. (when (run-confirmation-page text title)
  84. (let* ((uploaded-name (send-dump-report dump-archive))
  85. (text (if uploaded-name
  86. (format #f (G_ "The dump was uploaded as ~a. Please \
  87. report it by email to ~a.") uploaded-name %guix-bug-report-address)
  88. (G_ "The dump could not be uploaded."))))
  89. (run-error-page
  90. text
  91. (G_ "Dump upload result")))))
  92. (define (dump-page dump-dir)
  93. (define files
  94. (scandir dump-dir (lambda (x)
  95. (not (or (string=? x ".")
  96. (string=? x ".."))))))
  97. (fold (match-lambda*
  98. (((file . enable?) acc)
  99. (if enable?
  100. (cons file acc)
  101. acc)))
  102. '()
  103. (run-dump-page
  104. dump-dir
  105. (map (lambda (x)
  106. (cons x #f))
  107. files))))
  108. (define (newt-run-command . args)
  109. (define command-output "")
  110. (define (line-accumulator line)
  111. (set! command-output
  112. (string-append/shared command-output line)))
  113. (define result (run-external-command-with-line-hooks (list line-accumulator)
  114. args))
  115. (define exit-val (status:exit-val result))
  116. (define term-sig (status:term-sig result))
  117. (define stop-sig (status:stop-sig result))
  118. (if (and exit-val (zero? exit-val))
  119. #t
  120. (let ((info-text
  121. (cond
  122. (exit-val
  123. (format #f (G_ "External command ~s exited with code ~a")
  124. args exit-val))
  125. (term-sig
  126. (format #f (G_ "External command ~s terminated by signal ~a")
  127. args term-sig))
  128. (stop-sig
  129. (format #f (G_ "External command ~s stopped by signal ~a")
  130. args stop-sig)))))
  131. (run-textbox-page #:title (G_ "External command error")
  132. #:info-text info-text
  133. #:content command-output
  134. #:buttons-spec
  135. (list
  136. (cons "Ignore" (const #t))
  137. (cons "Abort"
  138. (lambda ()
  139. (abort-to-prompt 'installer-step 'abort)))
  140. (cons "Report"
  141. (lambda ()
  142. (raise
  143. (condition
  144. ((@@ (guix build utils)
  145. &invoke-error)
  146. (program (car args))
  147. (arguments (cdr args))
  148. (exit-status exit-val)
  149. (term-signal term-sig)
  150. (stop-signal stop-sig)))))))))))
  151. (define (final-page result prev-steps)
  152. (run-final-page result prev-steps))
  153. (define* (locale-page #:key
  154. supported-locales
  155. iso639-languages
  156. iso3166-territories)
  157. (run-locale-page
  158. #:supported-locales supported-locales
  159. #:iso639-languages iso639-languages
  160. #:iso3166-territories iso3166-territories))
  161. (define (timezone-page zonetab)
  162. (run-timezone-page zonetab))
  163. (define* (welcome-page logo #:key pci-database)
  164. (run-welcome-page logo #:pci-database pci-database))
  165. (define (menu-page steps)
  166. (run-menu-page steps))
  167. (define* (keymap-page layouts context)
  168. (run-keymap-page layouts #:context context))
  169. (define (network-page)
  170. (run-network-page))
  171. (define (substitutes-page)
  172. (run-substitutes-page))
  173. (define (hostname-page)
  174. (run-hostname-page))
  175. (define (user-page)
  176. (run-user-page))
  177. (define (partition-page)
  178. (run-partitioning-page))
  179. (define (services-page)
  180. (run-services-page))
  181. (define (parameters-menu menu-proc)
  182. (newt-set-help-callback menu-proc))
  183. (define (parameters-page keyboard-layout-selection)
  184. (run-parameters-page keyboard-layout-selection))
  185. (define newt-installer
  186. (installer
  187. (name 'newt)
  188. (init init)
  189. (exit exit)
  190. (exit-error exit-error)
  191. (final-page final-page)
  192. (keymap-page keymap-page)
  193. (locale-page locale-page)
  194. (menu-page menu-page)
  195. (network-page network-page)
  196. (substitutes-page substitutes-page)
  197. (timezone-page timezone-page)
  198. (hostname-page hostname-page)
  199. (user-page user-page)
  200. (partition-page partition-page)
  201. (services-page services-page)
  202. (welcome-page welcome-page)
  203. (parameters-menu parameters-menu)
  204. (parameters-page parameters-page)
  205. (dump-page dump-page)
  206. (run-command newt-run-command)
  207. (report-page report-page)))