lol
1Index: usb-modeswitch-2.6.0/Makefile
2===================================================================
3--- usb-modeswitch-2.6.0.orig/Makefile
4+++ usb-modeswitch-2.6.0/Makefile
5@@ -5,17 +5,24 @@ CFLAGS += -Wall -Wno-deprecated-dec
6 LIBS = `pkg-config --libs --cflags libusb-1.0`
7 RM = /bin/rm -f
8 OBJS = usb_modeswitch.c
9-PREFIX = $(DESTDIR)/usr
10-ETCDIR = $(DESTDIR)/etc
11+PREFIX = /usr/local
12+ETCDIR = $(PREFIX)/etc
13 SYSDIR = $(ETCDIR)/systemd/system
14 UPSDIR = $(ETCDIR)/init
15-UDEVDIR = $(DESTDIR)/lib/udev
16+UDEVDIR = $(PREFIX)/lib/udev
17 SBINDIR = $(PREFIX)/sbin
18 MANDIR = $(PREFIX)/share/man/man1
19
20+USE_UPSTART=$(shell if command -v initctl > /dev/null; then echo "true"; fi)
21+USE_SYSTEMD=$(shell if command -v systemctl > /dev/null; then echo "true"; fi)
22+
23 .PHONY: clean install install-common uninstall \
24 dispatcher-script dispatcher-dynlink dispatcher-statlink \
25- install-script install-dynlink install-statlink
26+ install-script install-dynlink install-statlink \
27+ install-upstart install-systemd \
28+ configure-dispatcher configure-script \
29+ configure-upstart configure-systemd \
30+ configure
31
32 all: all-with-script-dispatcher
33
34@@ -28,7 +35,25 @@ all-with-statlink-dispatcher: $(PROG) di
35 $(PROG): $(OBJS) usb_modeswitch.h
36 $(CC) -o $(PROG) $(OBJS) $(CFLAGS) $(LIBS) $(LDFLAGS)
37
38-dispatcher-script: usb_modeswitch_dispatcher.tcl
39+configure-dispatcher:
40+ sed -i \
41+ -e 's,^\(set setup(sbindir) \).*$$,\1$(SBINDIR),' \
42+ -e 's,^\(set setup(etcdir) \).*$$,\1$(ETCDIR),' \
43+ usb_modeswitch_dispatcher.tcl
44+
45+configure-script:
46+ sed -i -e 's,^\(SBINDIR=\).*$$,\1$(SBINDIR),' usb_modeswitch.sh
47+
48+configure-systemd:
49+ sed -i -e 's,@sbindir@,$(SBINDIR),' usb_modeswitch@.service
50+
51+configure-upstart:
52+ sed -i -e 's,@sbindir@,$(SBINDIR),' usb-modeswitch-upstart.conf
53+
54+configure: configure-dispatcher configure-script \
55+ configure-systemd configure-upstart
56+
57+dispatcher-script: configure-dispatcher usb_modeswitch_dispatcher.tcl
58 DISPATCH=dispatcher-script
59 cp -f usb_modeswitch_dispatcher.tcl usb_modeswitch_dispatcher
60
61@@ -53,16 +78,28 @@ distclean: clean
62 # If the systemd folder is present, install the service for starting the dispatcher
63 # If not, use the dispatcher directly from the udev rule as in previous versions
64
65-install-common: $(PROG) $(DISPATCH)
66- install -D --mode=755 usb_modeswitch $(SBINDIR)/usb_modeswitch
67- install -D --mode=755 usb_modeswitch.sh $(UDEVDIR)/usb_modeswitch
68- install -D --mode=644 usb_modeswitch.conf $(ETCDIR)/usb_modeswitch.conf
69- install -D --mode=644 usb_modeswitch.1 $(MANDIR)/usb_modeswitch.1
70- install -D --mode=644 usb_modeswitch_dispatcher.1 $(MANDIR)/usb_modeswitch_dispatcher.1
71- install -D --mode=755 usb_modeswitch_dispatcher $(SBINDIR)/usb_modeswitch_dispatcher
72+install-common: $(PROG) configure $(DISPATCH)
73+ install -D --mode=755 usb_modeswitch $(DESTDIR)$(SBINDIR)/usb_modeswitch
74+ install -D --mode=755 usb_modeswitch.sh $(DESTDIR)$(UDEVDIR)/usb_modeswitch
75+ install -D --mode=644 usb_modeswitch.conf $(DESTDIR)$(ETCDIR)/usb_modeswitch.conf
76+ install -D --mode=644 usb_modeswitch.1 $(DESTDIR)$(MANDIR)/usb_modeswitch.1
77+ install -D --mode=644 usb_modeswitch_dispatcher.1 $(DESTDIR)$(MANDIR)/usb_modeswitch_dispatcher.1
78+ install -D --mode=755 usb_modeswitch_dispatcher $(DESTDIR)$(SBINDIR)/usb_modeswitch_dispatcher
79 install -d $(DESTDIR)/var/lib/usb_modeswitch
80- test -d $(UPSDIR) -a -e /sbin/initctl && install --mode=644 usb-modeswitch-upstart.conf $(UPSDIR) || test 1
81- test -d $(SYSDIR) -a \( -e /usr/bin/systemctl -o -e /bin/systemctl \) && install --mode=644 usb_modeswitch@.service $(SYSDIR) || test 1
82+
83+install-upstart:
84+ install -D --mode=644 usb-modeswitch-upstart.conf $(DESTDIR)$(UPSDIR)/usb-modeswitch-upstart.conf
85+
86+install-systemd:
87+ install -D --mode=644 usb_modeswitch@.service $(DESTDIR)$(SYSDIR)/usb_modeswitch@.service
88+
89+ifeq ($(USE_UPSTART),true)
90+install-common: install-upstart
91+endif
92+
93+ifeq ($(USE_SYSTEMD),true)
94+install-common: install-systemd
95+endif
96
97 install: install-script
98
99@@ -73,10 +110,10 @@ install-dynlink: dispatcher-dynlink inst
100 install-statlink: dispatcher-statlink install-common
101
102 uninstall:
103- $(RM) $(SBINDIR)/usb_modeswitch
104- $(RM) $(SBINDIR)/usb_modeswitch_dispatcher
105- $(RM) $(UDEVDIR)/usb_modeswitch
106- $(RM) $(ETCDIR)/usb_modeswitch.conf
107- $(RM) $(MANDIR)/usb_modeswitch.1
108+ $(RM) $(DESTDIR)$(SBINDIR)/usb_modeswitch
109+ $(RM) $(DESTDIR)$(SBINDIR)/usb_modeswitch_dispatcher
110+ $(RM) $(DESTDIR)$(UDEVDIR)/usb_modeswitch
111+ $(RM) $(DESTDIR)$(ETCDIR)/usb_modeswitch.conf
112+ $(RM) $(DESTDIR)$(MANDIR)/usb_modeswitch.1
113 $(RM) -R $(DESTDIR)/var/lib/usb_modeswitch
114- $(RM) $(SYSDIR)/usb_modeswitch@.service
115+ $(RM) $(DESTDIR)$(SYSDIR)/usb_modeswitch@.service
116Index: usb-modeswitch-2.6.0/usb-modeswitch-upstart.conf
117===================================================================
118--- usb-modeswitch-2.6.0.orig/usb-modeswitch-upstart.conf
119+++ usb-modeswitch-2.6.0/usb-modeswitch-upstart.conf
120@@ -1,5 +1,5 @@
121 start on usb-modeswitch-upstart
122 task
123 script
124- exec /usr/sbin/usb_modeswitch_dispatcher --switch-mode $UMS_PARAM
125+ exec @sbindir@/usb_modeswitch_dispatcher --switch-mode $UMS_PARAM
126 end script
127Index: usb-modeswitch-2.6.0/usb_modeswitch.sh
128===================================================================
129--- usb-modeswitch-2.6.0.orig/usb_modeswitch.sh
130+++ usb-modeswitch-2.6.0/usb_modeswitch.sh
131@@ -1,5 +1,9 @@
132 #!/bin/sh
133 # part of usb_modeswitch 2.6.0
134+
135+# Compile time configuration, injected by the Makefile
136+SBINDIR=/usr/sbin
137+
138 device_in()
139 {
140 if [ ! -e /var/lib/usb_modeswitch/$1 ]; then
141@@ -37,7 +41,7 @@ if [ $(expr "$1" : "--.*") ]; then
142 v_id=$3
143 fi
144 fi
145-PATH=/sbin:/usr/sbin:$PATH
146+
147 case "$1" in
148 --driver-bind)
149 # driver binding code removed
150@@ -46,9 +50,7 @@ case "$1" in
151 --symlink-name)
152 device_in "link_list" $v_id $p_id
153 if [ "$?" = "1" ]; then
154- if [ -e "/usr/sbin/usb_modeswitch_dispatcher" ]; then
155- exec usb_modeswitch_dispatcher $1 $2 2>>/dev/null
156- fi
157+ exec $SBINDIR/usb_modeswitch_dispatcher $1 $2 2>>/dev/null
158 fi
159 exit 0
160 ;;
161@@ -61,15 +63,13 @@ if [ "$p2" = "" -a "$p1" != "" ]; then
162 p2=$p1
163 fi
164
165-PATH=/bin:/sbin:/usr/bin:/usr/sbin
166-init_path=`readlink -f /sbin/init`
167-if [ `basename $init_path` = "systemd" ]; then
168+if command -v systemctl > /dev/null; then
169 systemctl --no-block restart usb_modeswitch@$p2.service
170-elif [ -e "/etc/init/usb-modeswitch-upstart.conf" ]; then
171+elif command -v initctl > /dev/null; then
172 initctl emit --no-wait usb-modeswitch-upstart UMS_PARAM=$p2
173 else
174 # only old distros, new udev will kill all subprocesses
175 exec 1<&- 2<&- 5<&- 7<&-
176- exec usb_modeswitch_dispatcher --switch-mode $p2 &
177+ exec $SBINDIR/usb_modeswitch_dispatcher --switch-mode $p2 &
178 fi
179 exit 0
180Index: usb-modeswitch-2.6.0/usb_modeswitch@.service
181===================================================================
182--- usb-modeswitch-2.6.0.orig/usb_modeswitch@.service
183+++ usb-modeswitch-2.6.0/usb_modeswitch@.service
184@@ -3,6 +3,6 @@ Description=USB_ModeSwitch_%i
185
186 [Service]
187 Type=oneshot
188-ExecStart=/usr/sbin/usb_modeswitch_dispatcher --switch-mode %i
189+ExecStart=@sbindir@/usb_modeswitch_dispatcher --switch-mode %i
190 #ExecStart=/bin/echo %i
191
192Index: usb-modeswitch-2.6.0/usb_modeswitch_dispatcher.tcl
193===================================================================
194--- usb-modeswitch-2.6.0.orig/usb_modeswitch_dispatcher.tcl
195+++ usb-modeswitch-2.6.0/usb_modeswitch_dispatcher.tcl
196@@ -12,6 +12,16 @@
197 # Part of usb-modeswitch-2.6.0 package
198 # (C) Josua Dietze 2009-2019
199
200+# Compile-time configuration, injected by the Makefile.
201+set setup(sbindir) /usr/sbin
202+set setup(etcdir) /etc
203+
204+# External dependency default location
205+set setup(dbdir) /usr/share/usb_modeswitch
206+
207+# Derived configuration
208+set setup(dbdir_etc) $setup(etcdir)/usb_modeswitch.d
209+
210 set arg0 [lindex $argv 0]
211 if [regexp {\.tcl$} $arg0] {
212 if [file exists $arg0] {
213@@ -115,10 +125,8 @@ if {![regexp {(.*?):.*$} $arg1 d device]
214 }
215 }
216
217-set setup(dbdir) /usr/share/usb_modeswitch
218-set setup(dbdir_etc) /etc/usb_modeswitch.d
219 if {![file exists $setup(dbdir)] && ![file exists $setup(dbdir_etc)]} {
220- Log "\nError: no config database found in /usr/share or /etc. Exit"
221+ Log "\nError: no config database found in $setup(dbdir) or $setup(dbdir_etc). Exit"
222 SafeExit
223 }
224
225@@ -285,7 +293,7 @@ if {$config(NoMBIMCheck)==0 && $usb(bNum
226 if [CheckMBIM] {
227 Log " driver for MBIM devices is available"
228 Log "Find MBIM configuration number ..."
229- if [catch {set cfgno [exec /usr/sbin/usb_modeswitch -j -Q $busParam $devParam -v $usb(idVendor) -p $usb(idProduct)]} err] {
230+ if [catch {set cfgno [exec $setup(sbindir)/usb_modeswitch -j -Q $busParam $devParam -v $usb(idVendor) -p $usb(idProduct)]} err] {
231 Log "Error when trying to find MBIM configuration, switch to legacy modem mode"
232 } else {
233 set cfgno [string trim $cfgno]
234@@ -321,7 +329,7 @@ if {$report == ""} {
235 # Now we are actually switching
236 if $flags(logging) {
237 Log "Command line:\nusb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f \$flags(config)"
238- catch {set report [exec /usr/sbin/usb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]} report
239+ catch {set report [exec $setup(sbindir)/usb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]} report
240 Log "\nVerbose debug output of usb_modeswitch and libusb follows"
241 Log "(Note that some USB errors are to be expected in the process)"
242 Log "--------------------------------"
243@@ -329,7 +337,7 @@ if {$report == ""} {
244 Log "--------------------------------"
245 Log "(end of usb_modeswitch output)\n"
246 } else {
247- catch {set report [exec /usr/sbin/usb_modeswitch -Q -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]} report
248+ catch {set report [exec $setup(sbindir)/usb_modeswitch -Q -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]} report
249 }
250 }
251
252@@ -522,12 +530,12 @@ return 1
253
254 proc {ParseGlobalConfig} {path} {
255
256-global flags
257+global flags setup
258 set configFile ""
259 if [string length $path] {
260 set places [list $path]
261 } else {
262- set places [list /etc/usb_modeswitch.conf /etc/sysconfig/usb_modeswitch /etc/default/usb_modeswitch]
263+ set places [list $setup(etcdir)/usb_modeswitch.conf $setup(etcdir)/sysconfig/usb_modeswitch $setup(etcdir)/default/usb_modeswitch]
264 }
265 foreach cfg $places {
266 if [file exists $cfg] {
267@@ -923,10 +931,12 @@ proc {SysLog} {msg} {
268
269 global flags
270 if {![info exists flags(logger)]} {
271- set flags(logger) ""
272- foreach fn {/bin/logger /usr/bin/logger} {
273- if [file exists $fn] {
274- set flags(logger) $fn
275+ set flags(logger) [exec sh -c "command -v logger || true"]
276+ if {$flags(logger) == ""} {
277+ foreach fn {/bin/logger /usr/bin/logger} {
278+ if [file exists $fn] {
279+ set flags(logger) $fn
280+ }
281 }
282 }
283 Log "Logger is $flags(logger)"