#!/bin/sh
#BK called from udev rule in /etc/udev/rules.d/52-usb_modem_puppy.rules
#120109 usb_modeswitch 1.2.1: my optus 3g modem, not creating /dev/gsmmodem. call usb_modeswitch_status to do all the work.

#some variables passed in:
#ACTION=add
#DEVLINKS=/dev/gsmmodem
#DEVNAME=/dev/ttyUSB0
#DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2:1.0/ttyUSB0/tty/ttyUSB0
#MAJOR=188
#MINOR=0
#SEQNUM=3815
#SUBSYSTEM=tty

#if [ "$DEVLINKS" = "/dev/gsmmodem" ];then
##if [ -e /dev/gsmmodem ];then
# killall yaf-splash
# DISPLAY=":0" yaf-splash -placement center -close never -bg green -fontsize large -timeout 5 -text "USB Modem ready for use" &
#else
# if pidof yaf-splash ;then exit ;fi
# DISPLAY=":0" yaf-splash -placement center -close never -bg yellow -fontsize large -timeout 30 -text "USB Modem inserted, please wait, configuring..." &
#fi

PARAM1=""
[ $1 ] && PARAM1="$1"

if [ "$PARAM1" = "3g" ];then #120109 3g: see 52-usb_modem_puppy.rules
 #just go to normal status script...
 echo "Mode switching was successful" > /var/log/usb_modeswitch_special_status #read by usb_modeswitch_status
 #do not use 'exec' as udev calls this script multiple times and it must complete. but,
 #usb_modeswitch_status has a lock region that prevents near-simultaneous multiple instances, but need
 #to also do a running-check here first...
 [ "`/bin/pidof usb_modeswitch_status`" = "" ] && /usr/sbin/usb_modeswitch_status &
fi
