gnu: deutex: Update to 5.2.1.
[jackhill/guix/guix.git] / gnu / packages / usb-modeswitch.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
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 (gnu packages)
26 #:use-module (gnu packages base)
27 #:use-module (gnu packages compression)
28 #:use-module (gnu packages embedded)
29 #:use-module (gnu packages libusb)
30 #:use-module (gnu packages pkg-config))
31
32 (define-public usb-modeswitch-data
33 (package
34 (name "usb-modeswitch-data")
35 (version "20170806")
36 (source (origin
37 (method url-fetch)
38 (uri (string-append
39 "http://www.draisberghof.de/usb_modeswitch/"
40 "usb-modeswitch-data-" version ".tar.bz2"))
41 (sha256
42 (base32
43 "0b1wari3aza6qjggqd0hk2zsh93k1q8scgmwh6f8wr0flpr3whff"))))
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 "http://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
76 (define-public usb-modeswitch
77 (package
78 (name "usb-modeswitch")
79 (version "2.5.2")
80 (source (origin
81 (method url-fetch)
82 (uri (string-append
83 "http://www.draisberghof.de/usb_modeswitch/"
84 "usb-modeswitch-" version ".tar.bz2"))
85 (sha256
86 (base32
87 "19ifi80g9ns5dmspchjvfj4ykxssq9yrci8m227dgb3yr04srzxb"))
88 (modules '((guix build utils)))
89 (snippet
90 ;; Remove bundled jimtcl.
91 '(begin
92 (delete-file-recursively "jim")
93 #t))
94 (patches
95 (search-patches "usb-modeswitch-accept-config-arg.patch"))))
96 (native-inputs `(("pkg-config" ,pkg-config)))
97 (inputs `(("libusb" ,libusb)
98 ("jimtcl" ,jimtcl)
99 ("usb-modeswitch-data" ,usb-modeswitch-data)))
100 (outputs '("out" "dispatcher"))
101 (build-system gnu-build-system)
102 (arguments
103 `(#:tests? #f ; does not support `make check`
104 #:make-flags (list "CC=gcc")
105 #:phases
106 (modify-phases %standard-phases
107 (delete 'configure) ; no configure script
108 (replace 'install
109 (lambda* (#:key source outputs inputs #:allow-other-keys)
110 (let* ((source (assoc-ref inputs "source"))
111 (jimtcl (assoc-ref inputs "jimtcl"))
112 (data (assoc-ref inputs "usb-modeswitch-data"))
113 (out (assoc-ref outputs "out"))
114 (bin (string-append out "/bin"))
115 (man1 (string-append out "/share/man/man1"))
116 (dispatcher-out (assoc-ref outputs "dispatcher"))
117 (udev (string-append dispatcher-out "/lib/udev"))
118 (etc (string-append dispatcher-out "/etc"))
119 (dispatcher-bin (string-append dispatcher-out "/bin"))
120 (dispatcher-man1 (string-append dispatcher-out
121 "/share/man/man1")))
122 (begin
123 ;; Users can install the default output and
124 ;; usb-modeswitch-data and then modeswitch their USB device
125 ;; by running e.g.:
126 ;;
127 ;; sudo usb_modeswitch -c \
128 ;; ~/.guix-profile/share/usb_modeswitch.d/12d1\:14fe \
129 ;; -v 0x12d1 -p 0x14fe
130 ;;
131 ;; But it is simpler to use the usb-modeswitch-service-type
132 ;; that installs a UDEV rules file which invokes a shell
133 ;; script in lib/udev (also called `usb_modeswitch' like the
134 ;; main binary) which, in turn, invokes the program
135 ;; `usb_modeswitch_dispatcher'. Normal users should not
136 ;; invoke this dispatcher directly, so it is a separate output.
137 (install-file "usb_modeswitch" bin)
138 (install-file "usb_modeswitch.conf" etc)
139 (install-file "usb_modeswitch.1" man1)
140 (install-file "usb_modeswitch_dispatcher.1" dispatcher-man1)
141
142 (substitute* "usb_modeswitch.sh"
143 (("PATH=") "PATH=$PATH:") ; we do not want hardcoded FHS path
144 (("init_path=") "init_path=/does/not/exist")) ; no /sbin/init
145 (rename-file "usb_modeswitch.sh" "usb_modeswitch")
146 (install-file "usb_modeswitch" udev)
147
148 (rename-file "usb_modeswitch.tcl" "usb_modeswitch_dispatcher")
149 (substitute* "usb_modeswitch_dispatcher"
150 (("/usr/bin/tclsh")
151 (string-append jimtcl "/bin/jimsh"))
152 (("/usr/sbin") bin)
153 (("/usr/share/usb_modeswitch")
154 (string-append data "/share/usb_modeswitch.d")))
155 (install-file "usb_modeswitch_dispatcher"
156 dispatcher-bin)
157 #t)))))))
158 (home-page "http://www.draisberghof.de/usb_modeswitch/")
159 (synopsis "Mode switching tool for controlling `multi-mode' USB devices")
160 (description "USB_ModeSwitch is a mode switching tool for controlling USB
161 devices with multiple @dfn{modes}. When plugged in for the first time many
162 USB devices (primarily high-speed WAN modems) act like a flash storage
163 containing installers for Windows drivers. USB_ModeSwitch replays the
164 sequence the Windows drivers would send to switch their mode from storage to
165 modem (or whatever the thing is supposed to do).")
166 (license license:gpl2+)))