1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu installer newt network)
20 #:use-module (gnu installer connman)
21 #:use-module (gnu installer steps)
22 #:use-module (gnu installer utils)
23 #:use-module (gnu installer newt ethernet)
24 #:use-module (gnu installer newt page)
25 #:use-module (gnu installer newt wifi)
26 #:use-module (guix i18n)
27 #:use-module (srfi srfi-1)
28 #:use-module (srfi srfi-11)
29 #:use-module (srfi srfi-34)
30 #:use-module (srfi srfi-35)
32 #:export (run-network-page))
34 ;; Maximum length of a technology name.
35 (define technology-name-max-length (make-parameter 20))
37 (define (technology->text technology)
38 "Return a string describing the given TECHNOLOGY."
39 (let* ((name (technology-name technology))
40 (padded-name (string-pad-right name
41 (technology-name-max-length))))
42 (format #f "~a~%" padded-name)))
44 (define (run-technology-page)
45 "Run a page to ask the user which technology shall be used to access
46 Internet and return the selected technology. For now, only technologies with
47 \"ethernet\" or \"wifi\" types are supported."
48 (define (technology-items)
49 (filter (lambda (technology)
50 (let ((type (technology-type technology)))
52 (string=? type "ethernet")
53 (string=? type "wifi"))))
54 (connman-technologies)))
56 (let ((items (technology-items)))
59 (G_ "Internet access")
62 (G_ "The install process requires Internet access but no \
63 network device were found. Do you want to continue anyway?"))
66 (&installer-step-break))))
69 (&installer-step-abort)))))
70 (run-listbox-selection-page
71 #:info-text (G_ "The install process requires Internet access.\
72 Please select a network device.")
73 #:title (G_ "Internet access")
75 #:listbox-item->text technology->text
76 #:button-text (G_ "Exit")
77 #:button-callback-procedure
81 (&installer-step-abort))))))))
83 (define (find-technology-by-type technologies type)
84 "Find and return a technology with the given TYPE in TECHNOLOGIES list."
85 (find (lambda (technology)
86 (string=? (technology-type technology)
90 (define (wait-technology-powered technology)
91 "Wait and display a progress bar until the given TECHNOLOGY is powered."
92 (let ((name (technology-name technology))
95 #:title (G_ "Powering technology")
96 #:info-text (format #f (G_ "Waiting for technology ~a to be powered.")
98 #:scale-full-value full-value
101 (let* ((technologies (connman-technologies))
102 (type (technology-type technology))
104 (find-technology-by-type technologies type))
105 (technology-powered? updated-technology))
107 (if technology-powered?
111 (define (wait-service-online)
112 "Display a newt scale until connman detects an Internet access. Do
113 FULL-VALUE tentatives, spaced by 1 second."
114 (let* ((full-value 5))
116 #:title (G_ "Checking connectivity")
117 #:info-text (G_ "Waiting for Internet access establishment...")
118 #:scale-full-value full-value
122 (if (connman-online?)
125 (unless (connman-online?)
127 (G_ "The selected network does not provide access to the \
128 Internet, please try again.")
129 (G_ "Connection error"))
132 (&installer-step-abort))))))
134 (define (run-network-page)
135 "Run a page to allow the user to configure connman so that it can access the
137 (define network-steps
139 ;; Ask the user to choose between ethernet and wifi technologies.
141 (id 'select-technology)
144 (run-technology-page))))
145 ;; Enable the previously selected technology.
147 (id 'power-technology)
150 (let ((technology (result-step result 'select-technology)))
151 (connman-enable-technology technology)
152 (wait-technology-powered technology)))))
153 ;; Propose the user to connect to one of the service available for the
154 ;; previously selected technology.
156 (id 'connect-service)
159 (let* ((technology (result-step result 'select-technology))
160 (type (technology-type technology)))
162 ((string=? "wifi" type)
164 ((string=? "ethernet" type)
165 (run-ethernet-page)))))))
166 ;; Wait for connman status to switch to 'online, which means it can
171 (wait-service-online))))))
173 #:steps network-steps
174 #:rewind-strategy 'start))