2018-11-16 11:43:55 +00:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
|
2020-02-19 11:10:47 +00:00
|
|
|
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
|
2018-11-16 11:43:55 +00:00
|
|
|
;;;
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (gnu installer newt network)
|
|
|
|
#:use-module (gnu installer connman)
|
|
|
|
#:use-module (gnu installer steps)
|
|
|
|
#:use-module (gnu installer utils)
|
|
|
|
#:use-module (gnu installer newt ethernet)
|
|
|
|
#:use-module (gnu installer newt page)
|
|
|
|
#:use-module (gnu installer newt wifi)
|
|
|
|
#:use-module (guix i18n)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (srfi srfi-11)
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
#:use-module (srfi srfi-35)
|
2019-05-06 20:23:42 +00:00
|
|
|
#:use-module (ice-9 match)
|
2021-12-28 10:19:55 +00:00
|
|
|
#:use-module (web client)
|
|
|
|
#:use-module (web response)
|
2018-11-16 11:43:55 +00:00
|
|
|
#:use-module (newt)
|
|
|
|
#:export (run-network-page))
|
|
|
|
|
|
|
|
;; Maximum length of a technology name.
|
|
|
|
(define technology-name-max-length (make-parameter 20))
|
|
|
|
|
|
|
|
(define (technology->text technology)
|
|
|
|
"Return a string describing the given TECHNOLOGY."
|
|
|
|
(let* ((name (technology-name technology))
|
|
|
|
(padded-name (string-pad-right name
|
|
|
|
(technology-name-max-length))))
|
|
|
|
(format #f "~a~%" padded-name)))
|
|
|
|
|
|
|
|
(define (run-technology-page)
|
|
|
|
"Run a page to ask the user which technology shall be used to access
|
|
|
|
Internet and return the selected technology. For now, only technologies with
|
|
|
|
\"ethernet\" or \"wifi\" types are supported."
|
|
|
|
(define (technology-items)
|
|
|
|
(filter (lambda (technology)
|
|
|
|
(let ((type (technology-type technology)))
|
|
|
|
(or
|
|
|
|
(string=? type "ethernet")
|
|
|
|
(string=? type "wifi"))))
|
|
|
|
(connman-technologies)))
|
|
|
|
|
2019-05-06 20:23:42 +00:00
|
|
|
(match (technology-items)
|
|
|
|
(()
|
|
|
|
(case (choice-window
|
|
|
|
(G_ "Internet access")
|
|
|
|
(G_ "Continue")
|
|
|
|
(G_ "Exit")
|
|
|
|
(G_ "The install process requires Internet access but no \
|
2019-06-07 23:29:57 +00:00
|
|
|
network devices were found. Do you want to continue anyway?"))
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
((1) (abort-to-prompt 'installer-step 'break))
|
|
|
|
((2) (abort-to-prompt 'installer-step 'abort))))
|
2019-05-06 20:23:42 +00:00
|
|
|
((technology)
|
|
|
|
;; Since there's only one technology available, skip the selection
|
|
|
|
;; screen.
|
|
|
|
technology)
|
|
|
|
((items ...)
|
|
|
|
(run-listbox-selection-page
|
|
|
|
#:info-text (G_ "The install process requires Internet access.\
|
2018-12-05 12:58:26 +00:00
|
|
|
Please select a network device.")
|
2019-05-06 20:23:42 +00:00
|
|
|
#:title (G_ "Internet access")
|
|
|
|
#:listbox-items items
|
|
|
|
#:listbox-item->text technology->text
|
2020-11-06 09:59:54 +00:00
|
|
|
#:listbox-height (min (+ (length items) 2) 5)
|
2019-05-06 20:23:42 +00:00
|
|
|
#:button-text (G_ "Exit")
|
|
|
|
#:button-callback-procedure
|
|
|
|
(lambda _
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort))))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (find-technology-by-type technologies type)
|
|
|
|
"Find and return a technology with the given TYPE in TECHNOLOGIES list."
|
|
|
|
(find (lambda (technology)
|
|
|
|
(string=? (technology-type technology)
|
|
|
|
type))
|
|
|
|
technologies))
|
|
|
|
|
|
|
|
(define (wait-technology-powered technology)
|
|
|
|
"Wait and display a progress bar until the given TECHNOLOGY is powered."
|
|
|
|
(let ((name (technology-name technology))
|
|
|
|
(full-value 5))
|
|
|
|
(run-scale-page
|
|
|
|
#:title (G_ "Powering technology")
|
2019-04-24 14:20:56 +00:00
|
|
|
#:info-text (format #f (G_ "Waiting for technology ~a to be powered.")
|
|
|
|
name)
|
2018-11-16 11:43:55 +00:00
|
|
|
#:scale-full-value full-value
|
|
|
|
#:scale-update-proc
|
|
|
|
(lambda (value)
|
|
|
|
(let* ((technologies (connman-technologies))
|
|
|
|
(type (technology-type technology))
|
|
|
|
(updated-technology
|
|
|
|
(find-technology-by-type technologies type))
|
|
|
|
(technology-powered? updated-technology))
|
|
|
|
(sleep 1)
|
|
|
|
(if technology-powered?
|
|
|
|
full-value
|
|
|
|
(+ value 1)))))))
|
|
|
|
|
|
|
|
(define (wait-service-online)
|
|
|
|
"Display a newt scale until connman detects an Internet access. Do
|
|
|
|
FULL-VALUE tentatives, spaced by 1 second."
|
2022-10-17 12:26:19 +00:00
|
|
|
(define (url-alive? url)
|
|
|
|
(false-if-exception
|
|
|
|
(= (response-code (http-request url))
|
|
|
|
200)))
|
|
|
|
|
2021-12-28 10:19:55 +00:00
|
|
|
(define (ci-available?)
|
|
|
|
(dynamic-wind
|
|
|
|
(lambda ()
|
|
|
|
(sigaction SIGALRM
|
|
|
|
(lambda _ #f))
|
|
|
|
(alarm 3))
|
|
|
|
(lambda ()
|
2024-03-27 13:43:43 +00:00
|
|
|
(or (url-alive? "https://bordeaux.guix.gnu.org")
|
|
|
|
(url-alive? "https://ci.guix.gnu.org")))
|
2021-12-28 10:19:55 +00:00
|
|
|
(lambda ()
|
|
|
|
(alarm 0))))
|
|
|
|
|
2020-02-19 11:10:47 +00:00
|
|
|
(define (online?)
|
2021-12-28 10:19:55 +00:00
|
|
|
(or (and (connman-online?)
|
|
|
|
(ci-available?))
|
2020-02-19 11:10:47 +00:00
|
|
|
(file-exists? "/tmp/installer-assume-online")))
|
|
|
|
|
2018-11-16 11:43:55 +00:00
|
|
|
(let* ((full-value 5))
|
|
|
|
(run-scale-page
|
|
|
|
#:title (G_ "Checking connectivity")
|
2019-03-13 17:14:47 +00:00
|
|
|
#:info-text (G_ "Waiting for Internet access establishment...")
|
2018-11-16 11:43:55 +00:00
|
|
|
#:scale-full-value full-value
|
|
|
|
#:scale-update-proc
|
|
|
|
(lambda (value)
|
|
|
|
(sleep 1)
|
2020-02-19 11:10:47 +00:00
|
|
|
(if (online?)
|
2018-11-16 11:43:55 +00:00
|
|
|
full-value
|
|
|
|
(+ value 1))))
|
2020-02-19 11:10:47 +00:00
|
|
|
(unless (online?)
|
2018-11-16 11:43:55 +00:00
|
|
|
(run-error-page
|
2019-03-13 17:14:47 +00:00
|
|
|
(G_ "The selected network does not provide access to the \
|
2021-12-28 10:19:55 +00:00
|
|
|
Internet and the Guix substitute server, please try again.")
|
2018-11-16 11:43:55 +00:00
|
|
|
(G_ "Connection error"))
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (run-network-page)
|
|
|
|
"Run a page to allow the user to configure connman so that it can access the
|
|
|
|
Internet."
|
|
|
|
(define network-steps
|
|
|
|
(list
|
|
|
|
;; Ask the user to choose between ethernet and wifi technologies.
|
|
|
|
(installer-step
|
|
|
|
(id 'select-technology)
|
|
|
|
(compute
|
|
|
|
(lambda _
|
|
|
|
(run-technology-page))))
|
|
|
|
;; Enable the previously selected technology.
|
|
|
|
(installer-step
|
|
|
|
(id 'power-technology)
|
|
|
|
(compute
|
2018-12-05 08:48:36 +00:00
|
|
|
(lambda (result _)
|
2018-11-16 11:43:55 +00:00
|
|
|
(let ((technology (result-step result 'select-technology)))
|
|
|
|
(connman-enable-technology technology)
|
|
|
|
(wait-technology-powered technology)))))
|
|
|
|
;; Propose the user to connect to one of the service available for the
|
|
|
|
;; previously selected technology.
|
|
|
|
(installer-step
|
|
|
|
(id 'connect-service)
|
|
|
|
(compute
|
2018-12-05 08:48:36 +00:00
|
|
|
(lambda (result _)
|
2018-11-16 11:43:55 +00:00
|
|
|
(let* ((technology (result-step result 'select-technology))
|
|
|
|
(type (technology-type technology)))
|
|
|
|
(cond
|
|
|
|
((string=? "wifi" type)
|
|
|
|
(run-wifi-page))
|
|
|
|
((string=? "ethernet" type)
|
|
|
|
(run-ethernet-page)))))))
|
|
|
|
;; Wait for connman status to switch to 'online, which means it can
|
|
|
|
;; access Internet.
|
|
|
|
(installer-step
|
|
|
|
(id 'wait-online)
|
|
|
|
(compute (lambda _
|
|
|
|
(wait-service-online))))))
|
|
|
|
(run-installer-steps
|
|
|
|
#:steps network-steps
|
|
|
|
#:rewind-strategy 'start))
|