unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: "pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 35640@debbugs.gnu.org
Subject: bug#35640: Make USB modems just work on Guix
Date: Wed, 12 Jun 2019 14:13:12 +0200	[thread overview]
Message-ID: <20190612121312.hobngtkentkiavai@pelzflorian.localdomain> (raw)
In-Reply-To: <87lfyupgxm.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 430 bytes --]

On Sat, May 25, 2019 at 07:44:37PM +0200, Ludovic Courtès wrote:
> >> +                 (substitute* "usb_modeswitch_dispatcher"
> >> +                   (("!/usr/bin/tclsh")
> >> +                    (string-append "!" jimtcl "/bin/jimsh"))
> 
> I don’t think it’s needed, is it?
> 

I see now, you mean the exclamation mark?  It is not needed.  Sorry.

Attached is the same patch without exclamation mark.

Regards,
Florian

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-USB_ModeSwitch.patch --]
[-- Type: text/plain; charset=utf-8, Size: 11331 bytes --]

From 2a790dacdb818387325f7a2a895adde6bacabf8b Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Wed, 12 Jun 2019 14:05:44 +0200
Subject: [PATCH 1/3] gnu: Add USB_ModeSwitch.

* gnu/packages/usb-modeswitch.scm: New file.
* gnu/packages/patches/usb-modeswitch-accept-config-arg.patch: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add package.
  (dist_patch_DATA): Add patch.
---
 gnu/local.mk                                  |   2 +
 .../usb-modeswitch-accept-config-arg.patch    |  42 +++++
 gnu/packages/usb-modeswitch.scm               | 166 ++++++++++++++++++
 3 files changed, 210 insertions(+)
 create mode 100644 gnu/packages/patches/usb-modeswitch-accept-config-arg.patch
 create mode 100644 gnu/packages/usb-modeswitch.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 907641ff3e..7a90b279f6 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -468,6 +468,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/uml.scm				\
   %D%/packages/unrtf.scm			\
   %D%/packages/upnp.scm				\
+  %D%/packages/usb-modeswitch.scm		\
   %D%/packages/uucp.scm				\
   %D%/packages/valgrind.scm			\
   %D%/packages/version-control.scm		\
@@ -1332,6 +1333,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/util-linux-tests.patch			\
   %D%/packages/patches/upower-builddir.patch			\
   %D%/packages/patches/upx-fix-CVE-2017-15056.patch		\
+  %D%/packages/patches/usb-modeswitch-accept-config-arg.patch	\
   %D%/packages/patches/valgrind-enable-arm.patch		\
   %D%/packages/patches/vboot-utils-fix-format-load-address.patch	\
   %D%/packages/patches/vboot-utils-fix-tests-show-contents.patch	\
diff --git a/gnu/packages/patches/usb-modeswitch-accept-config-arg.patch b/gnu/packages/patches/usb-modeswitch-accept-config-arg.patch
new file mode 100644
index 0000000000..9c050f7ee6
--- /dev/null
+++ b/gnu/packages/patches/usb-modeswitch-accept-config-arg.patch
@@ -0,0 +1,42 @@
+--- old/usb_modeswitch.tcl	1970-01-01 01:00:00.000000000 +0100
++++ usb_modeswitch.tcl	2019-06-12 08:39:42.140000000 +0200
+@@ -41,7 +41,7 @@
+ global scsi usb config match device flags setup devdir loginit
+ 
+ set flags(config) ""
+-Log "[ParseGlobalConfig]"
++Log "[ParseGlobalConfig $argv]"
+ 
+ if {$flags(stordelay) > 0} {
+ 	SetStorageDelay $flags(stordelay)
+@@ -496,9 +496,21 @@
+ # end of proc {MatchDevice}
+ 
+ 
+-proc {ParseGlobalConfig} {} {
++proc {ParseGlobalConfig} {argv} {
+ 
+ global flags
++
++set configFileParam ""
++for {set i 0} {$i < [llength $argv]} {incr i} {
++	switch -glob -- [set v [lindex $argv $i]] {
++		--config-file=* {
++			set configFileParam $v
++		}
++	}
++}
++if {$configFileParam != ""} {
++	set configFile [string range $configFileParam [string length "--config-file="] end]
++} else {
+ set configFile ""
+ set places [list /etc/usb_modeswitch.conf /etc/sysconfig/usb_modeswitch /etc/default/usb_modeswitch]
+ foreach cfg $places {
+@@ -507,6 +519,7 @@
+ 		break
+ 	}
+ }
++}
+ if {$configFile == ""} {return}
+ 
+ set rc [open $configFile r]
diff --git a/gnu/packages/usb-modeswitch.scm b/gnu/packages/usb-modeswitch.scm
new file mode 100644
index 0000000000..8f1cf9df60
--- /dev/null
+++ b/gnu/packages/usb-modeswitch.scm
@@ -0,0 +1,166 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages usb-modeswitch)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix packages)
+  #:use-module (guix download)
+  #:use-module (guix build-system gnu)
+  #:use-module (guix build-system trivial)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages base)
+  #:use-module (gnu packages compression)
+  #:use-module (gnu packages embedded)
+  #:use-module (gnu packages libusb)
+  #:use-module (gnu packages pkg-config))
+
+(define-public usb-modeswitch-data
+  (package
+    (name "usb-modeswitch-data")
+    (version "20170806")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "http://www.draisberghof.de/usb_modeswitch/"
+                    "usb-modeswitch-data-" version ".tar.bz2"))
+              (sha256
+               (base32
+                "0b1wari3aza6qjggqd0hk2zsh93k1q8scgmwh6f8wr0flpr3whff"))))
+    (build-system trivial-build-system)
+    (native-inputs `(("tar" ,tar)
+                     ("bzip2" ,bzip2)))
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+         (let* ((source (assoc-ref %build-inputs "source"))
+                (tar (assoc-ref %build-inputs "tar"))
+                (bzip2 (assoc-ref %build-inputs "bzip2"))
+                (files (string-append "usb-modeswitch-data-"
+                                      ,(package-version this-package)))
+                (share-dir (string-append %output "/share"))
+                (doc-dir (string-append share-dir "/doc/"))
+                (license-dir (string-append doc-dir
+                                            (strip-store-file-name %output)))
+                (udev-dir (string-append %output "/udev")))
+           (copy-file source "data.tar.bz2")
+           (invoke (string-append bzip2 "/bin/bzip2") "-d" "data.tar.bz2")
+           (invoke (string-append tar "/bin/tar") "xvf" "data.tar")
+           (copy-recursively (string-append files "/usb_modeswitch.d")
+                             (string-append share-dir "/usb_modeswitch.d"))
+           (install-file (string-append files "/40-usb_modeswitch.rules")
+                         udev-dir)
+           (install-file (string-append files "/COPYING") license-dir)))))
+    (home-page "http://www.draisberghof.de/usb_modeswitch/")
+    (synopsis "Data package for USB_ModeSwitch")
+    (description "This packages contains data about devices and a UDEV rules
+file for use with USB_ModeSwitch.")
+    (license license:gpl2+)))
+
+(define-public usb-modeswitch
+  (package
+    (name "usb-modeswitch")
+    (version "2.5.2")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "http://www.draisberghof.de/usb_modeswitch/"
+                    "usb-modeswitch-" version ".tar.bz2"))
+              (sha256
+               (base32
+                "19ifi80g9ns5dmspchjvfj4ykxssq9yrci8m227dgb3yr04srzxb"))
+              (modules '((guix build utils)))
+              (snippet
+               ;; Remove bundled jimtcl.
+               '(begin
+                  (delete-file-recursively "jim")
+                  #t))
+              (patches
+               (search-patches "usb-modeswitch-accept-config-arg.patch"))))
+    (native-inputs `(("pkg-config" ,pkg-config)))
+    (inputs `(("libusb" ,libusb)
+              ("jimtcl" ,jimtcl)
+              ("usb-modeswitch-data" ,usb-modeswitch-data)))
+    (outputs '("out" "dispatcher"))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f                    ; does not support `make check`
+       #:make-flags (list "CC=gcc")
+       #:phases
+       (modify-phases %standard-phases
+         (delete 'configure)          ; no configure script
+         (replace 'install
+           (lambda* (#:key source outputs inputs #:allow-other-keys)
+             (let* ((source (assoc-ref inputs "source"))
+                    (jimtcl (assoc-ref inputs "jimtcl"))
+                    (data (assoc-ref inputs "usb-modeswitch-data"))
+                    (out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (man1 (string-append out "/share/man/man1"))
+                    (dispatcher-out (assoc-ref outputs "dispatcher"))
+                    (udev (string-append dispatcher-out "/lib/udev"))
+                    (etc (string-append dispatcher-out "/etc"))
+                    (dispatcher-bin (string-append dispatcher-out "/bin"))
+                    (dispatcher-man1 (string-append dispatcher-out
+                                                    "/share/man/man1")))
+               (begin
+                 ;; Users can install the default output and
+                 ;; usb-modeswitch-data and then modeswitch their USB device
+                 ;; by running e.g.:
+                 ;;
+                 ;;   sudo usb_modeswitch -c \
+                 ;;   ~/.guix-profile/share/usb_modeswitch.d/12d1\:14fe \
+                 ;;   -v 0x12d1 -p 0x14fe
+                 ;;
+                 ;; But it is simpler to use the usb-modeswitch-service-type
+                 ;; that installs a UDEV rules file which invokes a shell
+                 ;; script in lib/udev (also called `usb_modeswitch' like the
+                 ;; main binary) which, in turn, invokes the program
+                 ;; `usb_modeswitch_dispatcher'.  Normal users should not
+                 ;; invoke this dispatcher directly, so it is a separate output.
+                 (install-file "usb_modeswitch" bin)
+                 (install-file "usb_modeswitch.conf" etc)
+                 (install-file "usb_modeswitch.1" man1)
+                 (install-file "usb_modeswitch_dispatcher.1" dispatcher-man1)
+
+                 (substitute* "usb_modeswitch.sh"
+                   (("PATH=") "PATH=$PATH:") ; we do not want hardcoded FHS path
+                   (("init_path=") "init_path=/does/not/exist")) ; no /sbin/init
+                 (rename-file "usb_modeswitch.sh" "usb_modeswitch")
+                 (install-file "usb_modeswitch" udev)
+
+                 (rename-file "usb_modeswitch.tcl" "usb_modeswitch_dispatcher")
+                 (substitute* "usb_modeswitch_dispatcher"
+                   (("/usr/bin/tclsh")
+                    (string-append jimtcl "/bin/jimsh"))
+                   (("/usr/sbin") bin)
+                   (("/usr/share/usb_modeswitch")
+                    (string-append data "/share/usb_modeswitch.d")))
+                 (install-file "usb_modeswitch_dispatcher"
+                               dispatcher-bin)
+                 #t)))))))
+    (home-page "http://www.draisberghof.de/usb_modeswitch/")
+    (synopsis "Mode switching tool for controlling `multi-mode' USB devices")
+    (description "USB_ModeSwitch is a mode switching tool for controlling USB
+devices with multiple @dfn{modes}.  When plugged in for the first time many
+USB devices (primarily high-speed WAN modems) act like a flash storage
+containing installers for Windows drivers.  USB_ModeSwitch replays the
+sequence the Windows drivers would send to switch their mode from storage to
+modem (or whatever the thing is supposed to do).")
+    (license license:gpl2+)))
-- 
2.21.0


  parent reply	other threads:[~2019-06-12 12:14 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 18:26 bug#35640: Make USB modems just work on Guix pelzflorian (Florian Pelz)
2019-05-09  5:31 ` pelzflorian (Florian Pelz)
2019-05-09 12:55   ` Danny Milosavljevic
2019-05-09 13:07     ` pelzflorian (Florian Pelz)
2019-05-09 13:43       ` pelzflorian (Florian Pelz)
2019-05-09 15:24 ` Ludovic Courtès
2019-05-13 20:57   ` pelzflorian (Florian Pelz)
2019-05-13 21:04     ` pelzflorian (Florian Pelz)
2019-05-14  7:22       ` pelzflorian (Florian Pelz)
2019-05-14  8:35       ` Danny Milosavljevic
2019-05-14 20:56         ` pelzflorian (Florian Pelz)
2019-05-15 13:01           ` Ludovic Courtès
2019-05-15 14:40             ` pelzflorian (Florian Pelz)
2019-05-22 16:29             ` pelzflorian (Florian Pelz)
2019-05-22 17:58               ` pelzflorian (Florian Pelz)
2019-05-24 15:37               ` Ludovic Courtès
2019-05-24 20:12                 ` pelzflorian (Florian Pelz)
2019-05-25 11:18                   ` pelzflorian (Florian Pelz)
2019-05-25 12:43                     ` pelzflorian (Florian Pelz)
2019-05-25 17:44                     ` Ludovic Courtès
2019-05-25 19:42                       ` pelzflorian (Florian Pelz)
2019-06-12 10:36                         ` pelzflorian (Florian Pelz)
2019-06-12 10:41                           ` pelzflorian (Florian Pelz)
2019-06-12 21:00                             ` Ludovic Courtès
2019-06-12 21:11                           ` Ludovic Courtès
2019-06-13 18:04                             ` pelzflorian (Florian Pelz)
2019-06-13 18:05                               ` pelzflorian (Florian Pelz)
2019-06-15 16:39                                 ` Ludovic Courtès
2019-06-12 12:13                       ` pelzflorian (Florian Pelz) [this message]
2019-06-12 12:21                         ` Ludovic Courtès
2019-06-12 19:51                           ` pelzflorian (Florian Pelz)
2019-06-12 20:42                             ` Ludovic Courtès
2019-06-12 20:58                         ` Ludovic Courtès
2019-05-14 20:48     ` Ludovic Courtès
2019-05-15 11:17     ` pelzflorian (Florian Pelz)
2019-05-15 12:51       ` Ludovic Courtès
2019-05-16  7:50   ` pelzflorian (Florian Pelz)
2019-05-16  8:34     ` pelzflorian (Florian Pelz)
2019-05-16 11:30     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190612121312.hobngtkentkiavai@pelzflorian.localdomain \
    --to=pelzflorian@pelzflorian.de \
    --cc=35640@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).