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