diff --git a/Makefile b/Makefile index ff61ac7..d3daeba 100644 --- a/Makefile +++ b/Makefile @@ -94,6 +94,12 @@ install-plugins: $(pck_plugins) $(DESTDIR)$(postplugrcdir)/$$plugin;\ done +install-udev-files: + @echo "installing udev files..." + @$(INSTALL_DIR) $(DESTDIR)/lib/udev/rules.d + $(INSTALL_SCRIPT) udev/android_usb $(DESTDIR)/lib/udev/android_usb + $(INSTALL_DATA) udev/76-android_usb.rules $(DESTDIR)/lib/udev/rules.d/76-android_usb.rules + install-sysconfig: $(pck_sysconfig) @$(INSTALL_DIR) $(DESTDIR)$(sysconfigdir) $(INSTALL_DATA) $^ $(DESTDIR)$(sysconfigdir) @@ -114,7 +120,8 @@ install: \ install-initscript \ install-logrotate \ install-locales \ - install-sysconfig + install-sysconfig \ + install-udev-files uninstall: rm -f $(DESTDIR)$(sbin)/$(PACKAGE) diff --git a/postplug.d/20network b/postplug.d/20network index aa1631b..2cf8f7e 100644 --- a/postplug.d/20network +++ b/postplug.d/20network @@ -106,8 +106,6 @@ function android_usb() { echo 0 > /sys/class/android_usb/android0/enable echo rndis,acm > /sys/class/android_usb/android0/functions echo 2 > /sys/class/android_usb/android0/f_acm/instances - systemctl enable getty@ttyGS0 - systemctl enable getty@ttyGS1 echo $ANDROID_ETHADDR > /sys/class/android_usb/android0/f_rndis/ethaddr echo 2d01 > /sys/class/android_usb/android0/idProduct echo 1 > /sys/class/android_usb/android0/enable @@ -123,6 +121,7 @@ ONBOOT=yes NM_CONTROLLED=no _EOF } + [ -e /etc/dhcpd-rndis0.conf ] || { [ "$NETWORK_ANDROID_SUBNET" ] && ANDROID_SUBNET=$NETWORK_ANDROID_SUBNET [ "$NETWORK_ANDROID_RANGE_FROM" ] && ANDORID_RANGE_FROM=$NETWORK_ANDROID_RANGE_FROM @@ -134,9 +133,11 @@ subnet $ANDROID_SUBNET netmask $ANDROID_NETMASK { } _EOF } - ifup rndis0 - touch /var/lib/dhcp/dhcpd-rndis0.leases - /sbin/dhcpd -q rndis0 -pf /run/dhcpd-rndis0.pid -cf /etc/dhcpd-rndis0.conf -lf /var/lib/dhcp/dhcpd-rndis0.leases + + for d in ttyGS0 ttyGS1; do + [ -e /etc/systemd/system/getty.target.wants/getty@$d.service ] || + ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@$d.service + done fi } diff --git a/udev/76-android_usb.rules b/udev/76-android_usb.rules new file mode 100644 index 0000000..9196f7e --- /dev/null +++ b/udev/76-android_usb.rules @@ -0,0 +1,7 @@ +# do not edit this file, it will be overwritten on update + +ACTION!="add|change", GOTO="android_usb_probe_end" + +SUBSYSTEM=="android_usb", KERNEL=="android*", IMPORT{program}="android_usb %p" + +LABEL="android_usb_probe_end" diff --git a/udev/android_usb b/udev/android_usb new file mode 100755 index 0000000..e007edd --- /dev/null +++ b/udev/android_usb @@ -0,0 +1,10 @@ +#!/bin/bash +# FIXME: hardcoded values +if [ -e /sys$1 ]; then + ANDROID_STATE=`cat /sys$1/state` + [ "$ANDROID_STATE" = "CONFIGURED" ] || exit 0 + + ifup rndis0 + touch /var/lib/dhcp/dhcpd-rndis0.leases + /sbin/dhcpd rndis0 -d -pf /run/dhcpd-rndis0.pid -cf /etc/dhcpd-rndis0.conf -lf /var/lib/dhcp/dhcpd-rndis0.leases +fi