aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;;
;;; 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)
  #:use-module (ice-9 match)
  #:use-module (web client)
  #:use-module (web response)
  #: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)))

  (match (technology-items)
    (()
     (case (choice-window
            (G_ "Internet access")
            (G_ "Continue")
            (G_ "Exit")
            (G_ "The install process requires Internet access but no \
network devices were found. Do you want to continue anyway?"))
       ((1) (abort-to-prompt 'installer-step 'break))
       ((2) (abort-to-prompt 'installer-step 'abort))))
    ((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.\
 Please select a network device.")
      #:title (G_ "Internet access")
      #:listbox-items items
      #:listbox-item->text technology->text
      #:listbox-height (min (+ (length items) 2) 5)
      #:button-text (G_ "Exit")
      #:button-callback-procedure
      (lambda _
        (abort-to-prompt 'installer-step 'abort))))))

(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")
     #:info-text (format #f (G_ "Waiting for technology ~a to be powered.")
                         name)
     #: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."
  (define (url-alive? url)
    (false-if-exception
     (= (response-code (http-request url))
        200)))

  (define (ci-available?)
    (dynamic-wind
      (lambda ()
        (sigaction SIGALRM
          (lambda _ #f))
        (alarm 3))
      (lambda ()
        (or (url-alive? "https://bordeaux.guix.gnu.org")
            (url-alive? "https://ci.guix.gnu.org")))
      (lambda ()
        (alarm 0))))

  (define (online?)
    (or (and (connman-online?)
             (ci-available?))
        (file-exists? "/tmp/installer-assume-online")))

  (let* ((full-value 5))
    (run-scale-page
     #:title (G_ "Checking connectivity")
     #:info-text (G_ "Waiting for Internet access establishment...")
     #:scale-full-value full-value
     #:scale-update-proc
     (lambda (value)
       (sleep 1)
       (if (online?)
           full-value
           (+ value 1))))
    (unless (online?)
      (run-error-page
       (G_ "The selected network does not provide access to the \
Internet and the Guix substitute server, please try again.")
       (G_ "Connection error"))
      (abort-to-prompt 'installer-step 'abort))))

(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
       (lambda (result _)
         (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
       (lambda (result _)
         (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))
>2019-04-22gnu: openssh: Update to 8.0p1....* gnu/packages/ssh.scm (openssh): Update to 8.0p1. [source]: Remove patch. * gnu/packages/patches/openssh-CVE-2018-20685.patch: Delete file. * gnu/local.mk (dist_patch_DATA): Remove it. Mark H Weaver 2019-04-07gnu: libssh2@1.8.0: Move to ssh.scm....This fixes a top-level circular dependency introduced in c1f4e6491cecc5d121ef371a8fb2aa0a07030d36. * gnu/packages/curl.scm (libssh2-1.8.0): Move to... * gnu/packages/ssh.scm (libssh2-1.8.0): ... here. Ludovic Courtès 2019-03-31gnu: libssh2: Update to 1.8.2....* gnu/packages/ssh.scm (libssh2): Update to 1.8.2. Marius Bakke 2019-03-28gnu: dropbear: Update to 2019.78....* gnu/packages/ssh.scm (dropbear): Update to 2019.78. Tobias Geerinckx-Rice 2019-03-23gnu: dropbear: Update to 2019.77....* gnu/packages/ssh.scm (dropbear): Update to 2019.77. [source]: Remove patch. * gnu/packages/patches/dropbear-CVE-2018-15599.patch: Delete file. * gnu/local.mk (dist_patch_DATA): Remove it. Tobias Geerinckx-Rice 2019-03-23gnu: dropbear: Don't use NAME in source URI....* gnu/packages/ssh.scm (dropbear)[source]: Hard-code NAME. Tobias Geerinckx-Rice 2019-03-21gnu: curl: Restore derivation....Commit af8f7eb4f2a664c2d0fb3faabaf2e80c72993ef6 accidentally changed the cURL derivation. Remove use of HIDDEN-PACKAGE and restore input order to prevent a large number of rebuilds. * gnu/packages/ssh.scm (libssh2-1.8.0): Move from here ... * gnu/packages/curl.scm (libssh2-1.8.0): ... to here. Don't use HIDDEN-PACKAGE and make it non-public. (curl)[inputs]: Move LIBSSH2-1.8.0 where it was before af8f7eb4f2a66. Marius Bakke 2019-03-21gnu: libssh2: Update to 1.8.1 [security fixes]....Fixes CVE-2019-{3855,3856,3857,3858,3859,3860,3861,3862,3863}. * gnu/packages/ssh.scm (libssh2): Update to 1.8.1. (libssh2-1.8.0): New variable. * gnu/packages/curl.scm (curl)[inputs]: Use libssh2-1.8.0. Leo Famulari 2019-03-18Correct name and email address for ng0....* .mailmap, Makefile.am, doc/guix.de.texi, doc/guix.fr.texi, doc/guix.texi, etc/completion/fish/guix.fish, gnu/packages/accessibility.scm, gnu/packages/admin.scm, gnu/packages/audio.scm, gnu/packages/autotools.scm, gnu/packages/cdrom.scm, gnu/packages/check.scm, gnu/packages/cinnamon.scm, gnu/packages/compression.scm, gnu/packages/crypto.scm, gnu/packages/databases.scm, gnu/packages/django.scm, gnu/packages/dns.scm, gnu/packages/elixir.scm, gnu/packages/emacs-xyz.scm, gnu/packages/emacs.scm, gnu/packages/enlightenment.scm, gnu/packages/erlang.scm, gnu/packages/fonts.scm, gnu/packages/fontutils.scm, gnu/packages/forth.scm, gnu/packages/fvwm.scm, gnu/packages/games.scm, gnu/packages/gl.scm, gnu/packages/gnome.scm, gnu/packages/gnunet.scm, gnu/packages/gnupg.scm, gnu/packages/gnuzilla.scm, gnu/packages/gtk.scm, gnu/packages/guile-wm.scm,gnu/packages/guile-xyz.scm, gnu/packages/haskell-check.scm, gnu/packages/haskell-crypto.scm, gnu/packages/haskell.scm, gnu/packages/image-viewers.scm, gnu/packages/image.scm, gnu/packages/irc.scm, gnu/packages/language.scm, gnu/packages/libcanberra.scm, gnu/packages/linux.scm, gnu/packages/lisp.scm, gnu/packages/lolcode.scm, gnu/packages/lxde.scm, gnu/packages/lxqt.scm, gnu/packages/mail.scm, gnu/packages/markup.scm, gnu/packages/mate.scm, gnu/packages/maths.scm, gnu/packages/mc.scm, gnu/packages/messaging.scm, gnu/packages/music.scm, gnu/packages/ncurses.scm, gnu/packages/networking.scm, gnu/packages/nickle.scm, gnu/packages/openbox.scm, gnu/packages/pdf.scm, gnu/packages/perl-check.scm, gnu/packages/perl.scm, gnu/packages/python-compression.scm, gnu/packages/python-crypto.scm, gnu/packages/python-web.scm, gnu/packages/python-xyz.scm, gnu/packages/python.scm, gnu/packages/qt.scm, gnu/packages/ruby.scm, gnu/packages/rust.scm, gnu/packages/scheme.scm, gnu/packages/serialization.scm, gnu/packages/shells.scm, gnu/packages/ssh.scm, gnu/packages/suckless.scm, gnu/packages/tbb.scm, gnu/packages/telephony.scm, gnu/packages/text-editors.scm, gnu/packages/textutils.scm, gnu/packages/time.scm, gnu/packages/tls.scm, gnu/packages/tor.scm, gnu/packages/version-control.scm, gnu/packages/video.scm, gnu/packages/vim.scm, gnu/packages/web.scm, gnu/packages/wm.scm, gnu/packages/xdisorg.scm, gnu/packages/xfce.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, gnu/services/certbot.scm, gnu/services/desktop.scm, gnu/services/version-control.scm, gnu/services/web.scm, guix/import/hackage.scm, guix/licenses.scm: Correct name and email address for ng0. Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr> ng0 2019-03-15gnu: libssh2: Update home page....* gnu/packages/ssh.scm (libssh2)[home-page]: Use HTTPS. Marius Bakke 2019-03-01gnu: libssh: Update to 0.8.7....* gnu/packages/ssh.scm (libssh): Update to 0.8.7. Marius Bakke 2019-02-26gnu: openssh: Add libedit support....* gnu/packages/ssh.scm (openssh)[native-inputs]: Add pkg-config. [inputs]: Add libedit. [arguments](configure-flags): Add --with-libedit. Gábor Boskovits 2019-02-10gnu: Dropbear: Add a comment about bundled libraries....* gnu/packages/ssh.scm (dropbear): Comment. Leo Famulari 2019-02-04gnu: autossh: Update to 1.4g....* gnu/packages/ssh.scm (autossh): Update to 1.4g. Tobias Geerinckx-Rice 2019-02-04gnu: autossh: Use HTTPS home page....* gnu/packages/ssh.scm (autossh)[source, home-page]: Use HTTPS. Tobias Geerinckx-Rice