#!/bin/sh # part of usb_modeswitch 2.2.0 device_in() { if [ ! -e /var/lib/usb_modeswitch/$1 ]; then return 0 fi while read line do if [ $(expr "$line" : "$2:$3") != 0 ]; then return 1 fi done /dev/null) sleep 1 if [ ! -z "$dir" ]; then exit 0 fi set +e device_in "bind_list" $v_id $p_id if [ "$?" = "1" ]; then id_attr="/sys/bus/usb-serial/drivers/option1/new_id" if [ ! -e "$id_attr" ]; then modprobe option 2>/dev/null || true fi if [ -e "$id_attr" ]; then echo "$v_id $p_id ff" > $id_attr else modprobe -r usbserial 2>/dev/null modprobe usbserial "vendor=0x$v_id" "product=0x$p_id" 2>/dev/null fi fi ) & exit 0 ;; --symlink-name) device_in "link_list" $v_id $p_id if [ "$?" = "1" ]; then if [ -e "/usr/sbin/usb_modeswitch_dispatcher" ]; then exec usb_modeswitch_dispatcher $1 $2 2>>/dev/null fi fi exit 0 ;; esac exec 1<&- 2<&- 5<&- 7<&- ( count=20 while [ $count != 0 ]; do if [ ! -e "/usr/sbin/usb_modeswitch_dispatcher" ]; then sleep 1 count=$(($count - 1)) else if [ -e "/etc/init/usb-modeswitch-upstart.conf" ]; then exec /sbin/initctl emit --no-wait usb-modeswitch-upstart UMS_PARAM=$1 elif [ -e "/etc/systemd/system/usb_modeswitch@.service" ]; then exec /usr/bin/systemctl --no-block start usb_modeswitch@$1.service else exec /usr/sbin/usb_modeswitch_dispatcher --switch-mode $1 & fi exit 0 fi done ) & exit 0