usb-modeswitch.scm 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019, 2020 Florian Pelz <pelzflorian@pelzflorian.de>
  3. ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  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 packages usb-modeswitch)
  20. #:use-module ((guix licenses) #:prefix license:)
  21. #:use-module (guix packages)
  22. #:use-module (guix download)
  23. #:use-module (guix build-system gnu)
  24. #:use-module (guix build-system trivial)
  25. #:use-module (guix utils)
  26. #:use-module (gnu packages)
  27. #:use-module (gnu packages base)
  28. #:use-module (gnu packages compression)
  29. #:use-module (gnu packages embedded)
  30. #:use-module (gnu packages libusb)
  31. #:use-module (gnu packages pkg-config))
  32. (define-public usb-modeswitch-data
  33. (package
  34. (name "usb-modeswitch-data")
  35. (version "20191128")
  36. (source (origin
  37. (method url-fetch)
  38. (uri (string-append
  39. "https://www.draisberghof.de/usb_modeswitch/"
  40. "usb-modeswitch-data-" version ".tar.bz2"))
  41. (sha256
  42. (base32
  43. "1ygahl3r26r38ai8yyblq9nhf3v5i6n6r6672p5wf88wg5h9n0rz"))))
  44. (build-system trivial-build-system)
  45. (native-inputs `(("tar" ,tar)
  46. ("bzip2" ,bzip2)))
  47. (arguments
  48. `(#:modules ((guix build utils))
  49. #:builder
  50. (begin
  51. (use-modules (guix build utils))
  52. (let* ((source (assoc-ref %build-inputs "source"))
  53. (tar (assoc-ref %build-inputs "tar"))
  54. (bzip2 (assoc-ref %build-inputs "bzip2"))
  55. (files (string-append "usb-modeswitch-data-"
  56. ,(package-version this-package)))
  57. (share-dir (string-append %output "/share"))
  58. (doc-dir (string-append share-dir "/doc/"))
  59. (license-dir (string-append doc-dir
  60. (strip-store-file-name %output)))
  61. (udev-dir (string-append %output "/udev")))
  62. (copy-file source "data.tar.bz2")
  63. (invoke (string-append bzip2 "/bin/bzip2") "-d" "data.tar.bz2")
  64. (invoke (string-append tar "/bin/tar") "xvf" "data.tar")
  65. (copy-recursively (string-append files "/usb_modeswitch.d")
  66. (string-append share-dir "/usb_modeswitch.d"))
  67. (install-file (string-append files "/40-usb_modeswitch.rules")
  68. udev-dir)
  69. (install-file (string-append files "/COPYING") license-dir)))))
  70. (home-page "https://www.draisberghof.de/usb_modeswitch/")
  71. (synopsis "Data package for USB_ModeSwitch")
  72. (description "This package contains data about devices and a UDEV rules
  73. file for use with USB_ModeSwitch.")
  74. (license license:gpl2+)))
  75. (define-public usb-modeswitch
  76. (package
  77. (name "usb-modeswitch")
  78. (version "2.6.1")
  79. (source (origin
  80. (method url-fetch)
  81. (uri (string-append
  82. "https://www.draisberghof.de/usb_modeswitch/"
  83. "usb-modeswitch-" version ".tar.bz2"))
  84. (sha256
  85. (base32
  86. "0d7s8p92r36danjd15y1zaznf6rbk17kxyg9367nabz56vhxk5ai"))))
  87. (native-inputs `(("pkg-config" ,pkg-config)))
  88. (inputs `(("libusb" ,libusb)
  89. ("jimtcl" ,jimtcl)
  90. ("usb-modeswitch-data" ,usb-modeswitch-data)))
  91. (outputs '("out" "dispatcher"))
  92. (build-system gnu-build-system)
  93. (arguments
  94. `(#:tests? #f ; does not support `make check`
  95. #:make-flags
  96. (list ,(string-append "CC=" (cc-for-target)))
  97. #:phases
  98. (modify-phases %standard-phases
  99. (delete 'configure) ; no configure script
  100. (replace 'install
  101. (lambda* (#:key source outputs inputs #:allow-other-keys)
  102. (let* ((source (assoc-ref inputs "source"))
  103. (jimtcl (assoc-ref inputs "jimtcl"))
  104. (data (assoc-ref inputs "usb-modeswitch-data"))
  105. (out (assoc-ref outputs "out"))
  106. (bin (string-append out "/bin"))
  107. (man1 (string-append out "/share/man/man1"))
  108. (dispatcher-out (assoc-ref outputs "dispatcher"))
  109. (udev (string-append dispatcher-out "/lib/udev"))
  110. (etc (string-append dispatcher-out "/etc"))
  111. (dispatcher-bin (string-append dispatcher-out "/bin"))
  112. (dispatcher-man1 (string-append dispatcher-out
  113. "/share/man/man1")))
  114. (begin
  115. ;; Users can install the default output and
  116. ;; usb-modeswitch-data and then modeswitch their USB device
  117. ;; by running e.g.:
  118. ;;
  119. ;; sudo usb_modeswitch -c \
  120. ;; ~/.guix-profile/share/usb_modeswitch.d/12d1\:14fe \
  121. ;; -v 0x12d1 -p 0x14fe
  122. ;;
  123. ;; But it is simpler to use the usb-modeswitch-service-type
  124. ;; that installs a UDEV rules file which invokes a shell
  125. ;; script in lib/udev (also called `usb_modeswitch' like the
  126. ;; main binary) which, in turn, invokes the program
  127. ;; `usb_modeswitch_dispatcher'. Normal users should not
  128. ;; invoke this dispatcher directly, so it is a separate output.
  129. (install-file "usb_modeswitch" bin)
  130. (install-file "usb_modeswitch.conf" etc)
  131. (install-file "usb_modeswitch.1" man1)
  132. (install-file "usb_modeswitch_dispatcher.1" dispatcher-man1)
  133. (substitute* "usb_modeswitch.sh"
  134. (("PATH=") "PATH=$PATH:") ; we do not want hardcoded FHS path
  135. (("init_path=") "init_path=/does/not/exist")) ; no /sbin/init
  136. (rename-file "usb_modeswitch.sh" "usb_modeswitch")
  137. (install-file "usb_modeswitch" udev)
  138. (rename-file "usb_modeswitch_dispatcher.tcl" "usb_modeswitch_dispatcher")
  139. (substitute* "usb_modeswitch_dispatcher"
  140. (("/usr/bin/tclsh")
  141. (string-append jimtcl "/bin/jimsh"))
  142. (("/usr/sbin") bin)
  143. (("/usr/share/usb_modeswitch")
  144. (string-append data "/share/usb_modeswitch.d")))
  145. (install-file "usb_modeswitch_dispatcher"
  146. dispatcher-bin)
  147. #t)))))))
  148. (home-page "https://www.draisberghof.de/usb_modeswitch/")
  149. (synopsis "Mode switching tool for controlling `multi-mode' USB devices")
  150. (description "USB_ModeSwitch is a mode switching tool for controlling USB
  151. devices with multiple @dfn{modes}. When plugged in for the first time many
  152. USB devices (primarily high-speed WAN modems) act like a flash storage
  153. containing installers for Windows drivers. USB_ModeSwitch replays the
  154. sequence the Windows drivers would send to switch their mode from storage to
  155. modem (or whatever the thing is supposed to do).")
  156. (license (list license:gpl2+ ;"this program" according to home page
  157. license:bsd-2)))) ;dispatcher.c