ethernet.scm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu installer newt ethernet)
  20. #:use-module (gnu installer connman)
  21. #:use-module (gnu installer steps)
  22. #:use-module (gnu installer newt utils)
  23. #:use-module (gnu installer newt page)
  24. #:use-module (guix i18n)
  25. #:use-module (ice-9 format)
  26. #:use-module (ice-9 match)
  27. #:use-module (srfi srfi-34)
  28. #:use-module (srfi srfi-35)
  29. #:use-module (newt)
  30. #:export (run-ethernet-page))
  31. (define (ethernet-services)
  32. "Return all the connman services of ethernet type."
  33. (let ((services (connman-services)))
  34. (filter (lambda (service)
  35. (and (string=? (service-type service) "ethernet")
  36. (not (string-null? (service-name service)))))
  37. services)))
  38. (define (ethernet-service->text service)
  39. "Return a string describing the given ethernet SERVICE."
  40. (let* ((name (service-name service))
  41. (path (service-path service))
  42. (full-name (string-append name "-" path))
  43. (state (service-state service))
  44. (connected? (or (string=? state "online")
  45. (string=? state "ready"))))
  46. (format #f "~c ~a~%"
  47. (if connected? #\* #\ )
  48. full-name)))
  49. (define (connect-ethernet-service service)
  50. "Connect to the given ethernet SERVICE. Display a connecting page while the
  51. connection is pending."
  52. (let* ((service-name (service-name service))
  53. (form (draw-connecting-page service-name)))
  54. (connman-connect service)
  55. (destroy-form-and-pop form)
  56. service))
  57. (define (run-ethernet-page)
  58. (match (ethernet-services)
  59. (()
  60. (run-error-page
  61. (G_ "No ethernet service available, please try again.")
  62. (G_ "No service"))
  63. (abort-to-prompt 'installer-step 'abort))
  64. ((service)
  65. ;; Only one service is available so return it directly.
  66. service)
  67. ((services ...)
  68. (run-listbox-selection-page
  69. #:info-text (G_ "Please select an ethernet network.")
  70. #:title (G_ "Ethernet connection")
  71. #:listbox-items services
  72. #:listbox-item->text ethernet-service->text
  73. #:listbox-height (min (+ (length services) 2) 5)
  74. #:button-text (G_ "Exit")
  75. #:button-callback-procedure
  76. (lambda _
  77. (abort-to-prompt 'installer-step 'abort))
  78. #:listbox-callback-procedure connect-ethernet-service))))