usb-modeswitch: fix configurable patch

This commit is contained in:
nyanloutre 2019-12-21 12:55:36 +01:00
parent 178f455494
commit b092c4618a
No known key found for this signature in database
GPG Key ID: 194A92D1103ACB2A

View File

@ -1,8 +1,8 @@
diff --git a/Makefile b/Makefile
index 463a11f..f20072c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,11 +5,11 @@ CFLAGS += -Wall
Index: usb-modeswitch-2.6.0/Makefile
===================================================================
--- usb-modeswitch-2.6.0.orig/Makefile
+++ usb-modeswitch-2.6.0/Makefile
@@ -5,17 +5,24 @@ CFLAGS += -Wall -Wno-deprecated-dec
LIBS = `pkg-config --libs --cflags libusb-1.0`
RM = /bin/rm -f
OBJS = usb_modeswitch.c
@ -16,36 +16,31 @@ index 463a11f..f20072c 100644
+UDEVDIR = $(PREFIX)/lib/udev
SBINDIR = $(PREFIX)/sbin
MANDIR = $(PREFIX)/share/man/man1
VPATH = jimtcl
@@ -22,10 +22,17 @@ endif
JIM_CONFIGURE_OPTS = --disable-lineedit \
--with-out-jim-ext="stdlib posix load signal syslog" --prefix=/usr
+USE_UPSTART=$(shell if command -v initctl > /dev/null; then echo "true"; fi)
+USE_SYSTEMD=$(shell if command -v systemctl > /dev/null; then echo "true"; fi)
+
.PHONY: clean install install-common uninstall \
script shared static \
dispatcher-script dispatcher-shared dispatcher-static \
- install-script install-shared install-static
+ install-script install-shared install-static \
dispatcher-script dispatcher-dynlink dispatcher-statlink \
- install-script install-dynlink install-statlink
+ install-script install-dynlink install-statlink \
+ install-upstart install-systemd \
+ configure-dispatcher configure-script \
+ configure-upstart configure-systemd \
+ configure
all: script
all: all-with-script-dispatcher
@@ -46,7 +53,25 @@ jim/libjim.a:
cd jim && CFLAGS="$(CFLAGS)" CC="$(CC)" ./configure $(JIM_CONFIGURE_OPTS)
$(MAKE) -C jim lib
@@ -28,7 +35,25 @@ all-with-statlink-dispatcher: $(PROG) di
$(PROG): $(OBJS) usb_modeswitch.h
$(CC) -o $(PROG) $(OBJS) $(CFLAGS) $(LIBS) $(LDFLAGS)
-dispatcher-script: usb_modeswitch.tcl
-dispatcher-script: usb_modeswitch_dispatcher.tcl
+configure-dispatcher:
+ sed -i \
+ -e 's,^\(set setup(sbindir) \).*$$,\1$(SBINDIR),' \
+ -e 's,^\(set setup(etcdir) \).*$$,\1$(ETCDIR),' \
+ usb_modeswitch.tcl
+ usb_modeswitch_dispatcher.tcl
+
+configure-script:
+ sed -i -e 's,^\(SBINDIR=\).*$$,\1$(SBINDIR),' usb_modeswitch.sh
@ -59,31 +54,22 @@ index 463a11f..f20072c 100644
+configure: configure-dispatcher configure-script \
+ configure-systemd configure-upstart
+
+dispatcher-script: configure-dispatcher usb_modeswitch.tcl
sed 's_!/usr/bin/tclsh_!'"$(TCL)"'_' < usb_modeswitch.tcl > usb_modeswitch_dispatcher
+dispatcher-script: configure-dispatcher usb_modeswitch_dispatcher.tcl
DISPATCH=dispatcher-script
cp -f usb_modeswitch_dispatcher.tcl usb_modeswitch_dispatcher
dispatcher-shared: jim/libjim.so dispatcher.c usb_modeswitch.string
@@ -55,7 +80,7 @@ dispatcher-shared: jim/libjim.so dispatcher.c usb_modeswitch.string
dispatcher-static: jim/libjim.a dispatcher.c usb_modeswitch.string
$(CC) dispatcher.c $(LDFLAGS) jim/libjim.a -Ijim -o usb_modeswitch_dispatcher $(CFLAGS)
-usb_modeswitch.string: usb_modeswitch.tcl
+usb_modeswitch.string: configure-dispatcher usb_modeswitch.tcl
$(HOST_TCL) make_string.tcl usb_modeswitch.tcl > $@
clean:
@@ -76,16 +101,28 @@ ums-clean:
@@ -53,16 +78,28 @@ distclean: clean
# If the systemd folder is present, install the service for starting the dispatcher
# If not, use the dispatcher directly from the udev rule as in previous versions
-install-common: $(PROG) usb_modeswitch_dispatcher
-install-common: $(PROG) $(DISPATCH)
- install -D --mode=755 usb_modeswitch $(SBINDIR)/usb_modeswitch
- install -D --mode=755 usb_modeswitch.sh $(UDEVDIR)/usb_modeswitch
- install -D --mode=644 usb_modeswitch.conf $(ETCDIR)/usb_modeswitch.conf
- install -D --mode=644 usb_modeswitch.1 $(MANDIR)/usb_modeswitch.1
- install -D --mode=644 usb_modeswitch_dispatcher.1 $(MANDIR)/usb_modeswitch_dispatcher.1
- install -D --mode=755 usb_modeswitch_dispatcher $(SBINDIR)/usb_modeswitch_dispatcher
+install-common: $(PROG) configure usb_modeswitch_dispatcher
+install-common: $(PROG) configure $(DISPATCH)
+ install -D --mode=755 usb_modeswitch $(DESTDIR)$(SBINDIR)/usb_modeswitch
+ install -D --mode=755 usb_modeswitch.sh $(DESTDIR)$(UDEVDIR)/usb_modeswitch
+ install -D --mode=644 usb_modeswitch.conf $(DESTDIR)$(ETCDIR)/usb_modeswitch.conf
@ -110,8 +96,8 @@ index 463a11f..f20072c 100644
install: install-script
@@ -96,10 +133,10 @@ install-shared: dispatcher-shared install-common
install-static: dispatcher-static install-common
@@ -73,10 +110,10 @@ install-dynlink: dispatcher-dynlink inst
install-statlink: dispatcher-statlink install-common
uninstall:
- $(RM) $(SBINDIR)/usb_modeswitch
@ -127,10 +113,10 @@ index 463a11f..f20072c 100644
$(RM) -R $(DESTDIR)/var/lib/usb_modeswitch
- $(RM) $(SYSDIR)/usb_modeswitch@.service
+ $(RM) $(DESTDIR)$(SYSDIR)/usb_modeswitch@.service
diff --git a/usb-modeswitch-upstart.conf b/usb-modeswitch-upstart.conf
index 0d82b69..1c177b4 100644
--- a/usb-modeswitch-upstart.conf
+++ b/usb-modeswitch-upstart.conf
Index: usb-modeswitch-2.6.0/usb-modeswitch-upstart.conf
===================================================================
--- usb-modeswitch-2.6.0.orig/usb-modeswitch-upstart.conf
+++ usb-modeswitch-2.6.0/usb-modeswitch-upstart.conf
@@ -1,5 +1,5 @@
start on usb-modeswitch-upstart
task
@ -138,13 +124,13 @@ index 0d82b69..1c177b4 100644
- exec /usr/sbin/usb_modeswitch_dispatcher --switch-mode $UMS_PARAM
+ exec @sbindir@/usb_modeswitch_dispatcher --switch-mode $UMS_PARAM
end script
diff --git a/usb_modeswitch.sh b/usb_modeswitch.sh
index eb3fa3e..0e93166 100755
--- a/usb_modeswitch.sh
+++ b/usb_modeswitch.sh
Index: usb-modeswitch-2.6.0/usb_modeswitch.sh
===================================================================
--- usb-modeswitch-2.6.0.orig/usb_modeswitch.sh
+++ usb-modeswitch-2.6.0/usb_modeswitch.sh
@@ -1,5 +1,9 @@
#!/bin/sh
# part of usb_modeswitch 2.5.2
# part of usb_modeswitch 2.6.0
+
+# Compile time configuration, injected by the Makefile
+SBINDIR=/usr/sbin
@ -180,7 +166,7 @@ index eb3fa3e..0e93166 100755
-init_path=`readlink -f /sbin/init`
-if [ `basename $init_path` = "systemd" ]; then
+if command -v systemctl > /dev/null; then
systemctl --no-block start usb_modeswitch@$p2.service
systemctl --no-block restart usb_modeswitch@$p2.service
-elif [ -e "/etc/init/usb-modeswitch-upstart.conf" ]; then
+elif command -v initctl > /dev/null; then
initctl emit --no-wait usb-modeswitch-upstart UMS_PARAM=$p2
@ -191,13 +177,25 @@ index eb3fa3e..0e93166 100755
+ exec $SBINDIR/usb_modeswitch_dispatcher --switch-mode $p2 &
fi
exit 0
diff --git a/usb_modeswitch.tcl b/usb_modeswitch.tcl
index d2ee50c..8a48751 100755
--- a/usb_modeswitch.tcl
+++ b/usb_modeswitch.tcl
Index: usb-modeswitch-2.6.0/usb_modeswitch@.service
===================================================================
--- usb-modeswitch-2.6.0.orig/usb_modeswitch@.service
+++ usb-modeswitch-2.6.0/usb_modeswitch@.service
@@ -3,6 +3,6 @@ Description=USB_ModeSwitch_%i
[Service]
Type=oneshot
-ExecStart=/usr/sbin/usb_modeswitch_dispatcher --switch-mode %i
+ExecStart=@sbindir@/usb_modeswitch_dispatcher --switch-mode %i
#ExecStart=/bin/echo %i
Index: usb-modeswitch-2.6.0/usb_modeswitch_dispatcher.tcl
===================================================================
--- usb-modeswitch-2.6.0.orig/usb_modeswitch_dispatcher.tcl
+++ usb-modeswitch-2.6.0/usb_modeswitch_dispatcher.tcl
@@ -12,6 +12,16 @@
# Part of usb-modeswitch-2.5.2 package
# (C) Josua Dietze 2009-2017
# Part of usb-modeswitch-2.6.0 package
# (C) Josua Dietze 2009-2019
+# Compile-time configuration, injected by the Makefile.
+set setup(sbindir) /usr/sbin
@ -212,9 +210,9 @@ index d2ee50c..8a48751 100755
set arg0 [lindex $argv 0]
if [regexp {\.tcl$} $arg0] {
if [file exists $arg0] {
@@ -91,10 +101,8 @@ if {![regexp {(.*?):.*$} $arg1 d device]} {
@@ -115,10 +125,8 @@ if {![regexp {(.*?):.*$} $arg1 d device]
}
}
set flags(logwrite) 1
-set setup(dbdir) /usr/share/usb_modeswitch
-set setup(dbdir_etc) /etc/usb_modeswitch.d
@ -224,7 +222,7 @@ index d2ee50c..8a48751 100755
SafeExit
}
@@ -261,7 +269,7 @@ if {$config(NoMBIMCheck)==0 && $usb(bNumConfigurations) > 1} {
@@ -285,7 +293,7 @@ if {$config(NoMBIMCheck)==0 && $usb(bNum
if [CheckMBIM] {
Log " driver for MBIM devices is available"
Log "Find MBIM configuration number ..."
@ -233,7 +231,7 @@ index d2ee50c..8a48751 100755
Log "Error when trying to find MBIM configuration, switch to legacy modem mode"
} else {
set cfgno [string trim $cfgno]
@@ -297,7 +305,7 @@ if {$report == ""} {
@@ -321,7 +329,7 @@ if {$report == ""} {
# Now we are actually switching
if $flags(logging) {
Log "Command line:\nusb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f \$flags(config)"
@ -242,7 +240,7 @@ index d2ee50c..8a48751 100755
Log "\nVerbose debug output of usb_modeswitch and libusb follows"
Log "(Note that some USB errors are to be expected in the process)"
Log "--------------------------------"
@@ -305,7 +313,7 @@ if {$report == ""} {
@@ -329,7 +337,7 @@ if {$report == ""} {
Log "--------------------------------"
Log "(end of usb_modeswitch output)\n"
} else {
@ -251,19 +249,22 @@ index d2ee50c..8a48751 100755
}
}
@@ -498,9 +506,9 @@ return 1
@@ -522,12 +530,12 @@ return 1
proc {ParseGlobalConfig} {} {
proc {ParseGlobalConfig} {path} {
-global flags
+global flags setup
set configFile ""
-set places [list /etc/usb_modeswitch.conf /etc/sysconfig/usb_modeswitch /etc/default/usb_modeswitch]
+set places [list $setup(etcdir)/usb_modeswitch.conf $setup(etcdir)/sysconfig/usb_modeswitch $setup(etcdir)/default/usb_modeswitch]
if [string length $path] {
set places [list $path]
} else {
- set places [list /etc/usb_modeswitch.conf /etc/sysconfig/usb_modeswitch /etc/default/usb_modeswitch]
+ set places [list $setup(etcdir)/usb_modeswitch.conf $setup(etcdir)/sysconfig/usb_modeswitch $setup(etcdir)/default/usb_modeswitch]
}
foreach cfg $places {
if [file exists $cfg] {
set configFile $cfg
@@ -897,10 +905,12 @@ proc {SysLog} {msg} {
@@ -923,10 +931,12 @@ proc {SysLog} {msg} {
global flags
if {![info exists flags(logger)]} {
@ -280,15 +281,3 @@ index d2ee50c..8a48751 100755
}
}
Log "Logger is $flags(logger)"
diff --git a/usb_modeswitch@.service b/usb_modeswitch@.service
index f74a8bf..90cb96a 100644
--- a/usb_modeswitch@.service
+++ b/usb_modeswitch@.service
@@ -3,6 +3,6 @@ Description=USB_ModeSwitch_%i
[Service]
Type=oneshot
-ExecStart=/usr/sbin/usb_modeswitch_dispatcher --switch-mode %i
+ExecStart=@sbindir@/usb_modeswitch_dispatcher --switch-mode %i
#ExecStart=/bin/echo %i