ethernet.scm 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. (raise
  64. (condition
  65. (&installer-step-abort))))
  66. ((service)
  67. ;; Only one service is available so return it directly.
  68. service)
  69. ((services ...)
  70. (run-listbox-selection-page
  71. #:info-text (G_ "Please select an ethernet network.")
  72. #:title (G_ "Ethernet connection")
  73. #:listbox-items services
  74. #:listbox-item->text ethernet-service->text
  75. #:listbox-height (min (+ (length services) 2) 5)
  76. #:button-text (G_ "Exit")
  77. #:button-callback-procedure
  78. (lambda _
  79. (raise
  80. (condition
  81. (&installer-step-abort))))
  82. #:listbox-callback-procedure connect-ethernet-service))))