newt.scm 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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-set-color COLORSET-ROOT "white" "red")
  62. (define action
  63. (run-textbox-page
  64. #:info-text (G_ "The installer has encountered an unexpected problem. \
  65. The backtrace is displayed below. You may choose to exit or create a dump \
  66. archive.")
  67. #:title (G_ "Unexpected problem")
  68. #:content error
  69. #:buttons-spec
  70. (list
  71. (cons (G_ "Dump") (const 'dump))
  72. (cons (G_ "Exit") (const 'exit)))))
  73. (newt-set-color COLORSET-ROOT "white" "blue")
  74. action)
  75. (define (report-page dump-archive)
  76. (define text
  77. (format #f (G_ "The dump archive was created as ~a. Would you like to \
  78. send this archive to the Guix servers?") dump-archive))
  79. (define title (G_ "Dump archive created"))
  80. (when (run-confirmation-page text title)
  81. (let* ((uploaded-name (send-dump-report dump-archive))
  82. (text (if uploaded-name
  83. (format #f (G_ "The dump was uploaded as ~a. Please \
  84. report it by email to ~a.") uploaded-name %guix-bug-report-address)
  85. (G_ "The dump could not be uploaded."))))
  86. (run-error-page
  87. text
  88. (G_ "Dump upload result")))))
  89. (define (dump-page dump-dir)
  90. (define files
  91. (scandir dump-dir (lambda (x)
  92. (not (or (string=? x ".")
  93. (string=? x ".."))))))
  94. (fold (match-lambda*
  95. (((file . enable?) acc)
  96. (if enable?
  97. (cons file acc)
  98. acc)))
  99. '()
  100. (run-dump-page
  101. dump-dir
  102. (map (lambda (x)
  103. (cons x #f))
  104. files))))
  105. (define (newt-run-command . args)
  106. (define command-output "")
  107. (define (line-accumulator line)
  108. (set! command-output
  109. (string-append/shared command-output line "\n")))
  110. (define displayed-command
  111. (string-join
  112. (map (lambda (s) (string-append "\"" s "\"")) args)
  113. " "))
  114. (define result (run-external-command-with-line-hooks (list line-accumulator)
  115. args))
  116. (define exit-val (status:exit-val result))
  117. (define term-sig (status:term-sig result))
  118. (define stop-sig (status:stop-sig result))
  119. (if (and exit-val (zero? exit-val))
  120. #t
  121. (let ((info-text
  122. (cond
  123. (exit-val
  124. (format #f (G_ "External command ~s exited with code ~a")
  125. args exit-val))
  126. (term-sig
  127. (format #f (G_ "External command ~s terminated by signal ~a")
  128. args term-sig))
  129. (stop-sig
  130. (format #f (G_ "External command ~s stopped by signal ~a")
  131. args stop-sig)))))
  132. (run-textbox-page #:title (G_ "External command error")
  133. #:info-text info-text
  134. #:content command-output
  135. #:buttons-spec
  136. (list
  137. (cons "Ignore" (const #t))
  138. (cons "Abort"
  139. (lambda ()
  140. (abort-to-prompt 'installer-step 'abort)))
  141. (cons "Report"
  142. (lambda ()
  143. (raise
  144. (condition
  145. ((@@ (guix build utils)
  146. &invoke-error)
  147. (program (car args))
  148. (arguments (cdr args))
  149. (exit-status exit-val)
  150. (term-signal term-sig)
  151. (stop-signal stop-sig)))))))))))
  152. (define (final-page result prev-steps)
  153. (run-final-page result prev-steps))
  154. (define* (locale-page #:key
  155. supported-locales
  156. iso639-languages
  157. iso3166-territories)
  158. (run-locale-page
  159. #:supported-locales supported-locales
  160. #:iso639-languages iso639-languages
  161. #:iso3166-territories iso3166-territories))
  162. (define (timezone-page zonetab)
  163. (run-timezone-page zonetab))
  164. (define (welcome-page logo)
  165. (run-welcome-page logo))
  166. (define (menu-page steps)
  167. (run-menu-page steps))
  168. (define* (keymap-page layouts context)
  169. (run-keymap-page layouts #:context context))
  170. (define (network-page)
  171. (run-network-page))
  172. (define (substitutes-page)
  173. (run-substitutes-page))
  174. (define (hostname-page)
  175. (run-hostname-page))
  176. (define (user-page)
  177. (run-user-page))
  178. (define (partition-page)
  179. (run-partitioning-page))
  180. (define (services-page)
  181. (run-services-page))
  182. (define (parameters-menu menu-proc)
  183. (newt-set-help-callback menu-proc))
  184. (define (parameters-page keyboard-layout-selection)
  185. (run-parameters-page keyboard-layout-selection))
  186. (define newt-installer
  187. (installer
  188. (name 'newt)
  189. (init init)
  190. (exit exit)
  191. (exit-error exit-error)
  192. (final-page final-page)
  193. (keymap-page keymap-page)
  194. (locale-page locale-page)
  195. (menu-page menu-page)
  196. (network-page network-page)
  197. (substitutes-page substitutes-page)
  198. (timezone-page timezone-page)
  199. (hostname-page hostname-page)
  200. (user-page user-page)
  201. (partition-page partition-page)
  202. (services-page services-page)
  203. (welcome-page welcome-page)
  204. (parameters-menu parameters-menu)
  205. (parameters-page parameters-page)
  206. (dump-page dump-page)
  207. (run-command newt-run-command)
  208. (report-page report-page)))