I found extremely difficult to setup hotplug daemon (as proposed in http://synce.sourceforge.net/synce/hotplug.php\); and quite useless as auto-connecting my iPAQ would be it's only job in my case... Instead, I've found a way of using devfs daemon (which is standart on Gentoo distro) for the same purpose. This setup was only tested on Gentoo but I beleive any devfs user would be able to "port" it. So, here we go:
1) Create '/etc/devfs.d/synce' with following:
--cut here--
LOOKUP ^ttyUSB([0-9])$ CFUNCTION GLOBAL mksymlink usb/tts/\1 ttyUSB\1
REGISTER ^usb/tts/([0-9])$ CFUNCTION GLOBAL mksymlink $devname ttyUSB\1
REGISTER ^usb/tts/([0-9])$ EXECUTE /usr/local/bin/synce-usb-start
UNREGISTER ^usb/tts/([0-9])$ CFUNCTION GLOBAL unlink ttyUSB\1
--cut here--
This adds '/dev/ttyUSB0' alias instead of messy '/dev/usb/tts/0', and executes '/usr/local/bin/synce-usb-start' on module activation.
I implemented the following, NOT using devfs, but hotplugging. It should support both devfs and udev, but it's only tested on udev. The "remove" action does not seem to be called, will try and figure that out later. Be sure to make the ipaq file executeable! The script will work without the config file at the bottom, but it's nice if you want to customize. The dccm automatic startup will only work if you have valid users in /etc/dccm.users
/etc/hotplug/usb/ipaq
------------from here
#!/bin/bash
LOG=/var/log/synce
#stop and synce serial connections
synce-serial-abort >> /dev/null
#Sleep awhile to give the device time to be created
sleep 2
#Startup dccm users
if [ -e /etc/dccm.users ]
then
echo "Starting DCCM users" >> $LOG
for user in `cat /etc/dccm.users`
do
sudo -u $user /usr/bin/dccm
done
else
echo "No DCCM users." >> $LOG
fi
if [ "$ACTION" = "add" ]
then
#Get the Device
if [ -e /dev/tts ];
then
DEVDIR=/dev/tts
DEVFILE=USB*
else
DEVDIR=/dev
DEVFILE=ttyUSB
fi
DEVICE=`cd $DEVDIR; ls -1 --sort=t $DEVFILE | head -n 1`
#Reconfigure the serial connection
if [ -e /etc/ipaq.conf ]
then
. /etc/ipaq.conf
Excellent, thank you!
It would be great for someone else (perhaps with better devfs knowledge) to test this; mine is a hack ripped from default /etc/devfsd.conf USB mouse config =D
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wanted to share my experience getting hotplugging set up with udev and Fedora Core 3 in the hopes that it will save someone else time. I needed to do three things:
(1) Create a rule for my device and save it under /etc/udev/rules/10-siemens. (The 10-siemens part is a bit arbitrary.) This step is not strictly necessary, but the default is to treat this device as ttyUSB0, and it seemed a bit presumptuous to write a hotplug script that would start synce every time a device was registered as ttyUSB0. So, I made _my_ device be "/dev/synceUSB[0,1..]" -- obviously you may need to change this rule if you have a different device; you can figure out the vendor and product id from usbview. My device is a siemens SX-56, and so my rule is:
2. Create a script that would launch after the device was registered and removed. It will need to be saved as /etc/dev.d/[device name]/[whateveryoulike].dev. So for example mine was /etc/dev.d/synceUSB0/synce.dev. I also created scripts for synceUSB1 and synceUSB2 because I found it would sometimes not unregister and reregister properly the second time I plugged it in. Anyway, here is my script:
-----------snip-----------
#!/bin/sh
if [ "$ACTION" = "add" ]; then
/usr/bin/synce-serial-config /dev/synceUSB0
/usr/bin/synce-serial-start
fi
if [ "$ACTION" = "remove" ]; then
/usr/bin/synce-serial-abort
fi
----------snip--------------
3. The script /usr/bin/synce-serial-start, as of my version (0.90), was not able to find a path to modprobe when called this way. For that reason, I had to change the reference to modprobe in that script to include the full path (/sbin/modprobe).
Finally, just a caveat: I haven't been able to get the synce-serial-abort script to properly shut down all of the daemons. I have to do ps | grep synce | xargs kill and maybe I'll put that in my script. But hopefully someone will fix the problem soon. Anyway, at least it works the first time after you turn the machine on! :)
Cheers,
Tavis
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm working on this one now. It appears that 'remove' is never called because when the ipaq is removed from the cradle, pppd doesn't die, which keeps /dev/synceUSB0 alive. Since /dev/synceUSB0 doesn't 'go away' 'remove' is never called. What we need is a way to kill pppd after removing the ipaq from the cradle. Something like a ping test, maybe. I'll post it if I get it fixed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#copy this file to /etc/hotplug/usb/
if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
then
/usr/bin/synce_setup.pl &
if [ -n "$REMOVER" ]; then
cat > $REMOVER <<EOF
#!/bin/sh
/usr/bin/synce-serial-abort
rm -f $REMOVER
EOF
chmod +x $REMOVER
fi
fi
------------------end---------------------
#setup and start synce service
#copy this file to /usr/bin
## abort any possible connection first
system("synce-serial-abort");
#sleep 2 sec, wait the device show up in /dev
sleep 2;
#find the newest device which we just plugged
open(INPUT, "cd /dev; ls -1 -r --sort=t ttyUSB* |");
local $device="";
while(<INPUT>)
{ s/\n//;
$device=$_;
}
# if we find the device
# config it and start the service
if($device ne "")
{
system("synce-serial-config $device");
system("synce-serial-start");
}
--------------end---------------------
PS. on my system, /dev/ttyUSBx dont show up before the hotplug script finish,that's why synce_setup.pl sleep 2 seconds.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found extremely difficult to setup hotplug daemon (as proposed in http://synce.sourceforge.net/synce/hotplug.php\); and quite useless as auto-connecting my iPAQ would be it's only job in my case... Instead, I've found a way of using devfs daemon (which is standart on Gentoo distro) for the same purpose. This setup was only tested on Gentoo but I beleive any devfs user would be able to "port" it. So, here we go:
1) Create '/etc/devfs.d/synce' with following:
--cut here--
LOOKUP ^ttyUSB([0-9])$ CFUNCTION GLOBAL mksymlink usb/tts/\1 ttyUSB\1
REGISTER ^usb/tts/([0-9])$ CFUNCTION GLOBAL mksymlink $devname ttyUSB\1
REGISTER ^usb/tts/([0-9])$ EXECUTE /usr/local/bin/synce-usb-start
UNREGISTER ^usb/tts/([0-9])$ CFUNCTION GLOBAL unlink ttyUSB\1
--cut here--
This adds '/dev/ttyUSB0' alias instead of messy '/dev/usb/tts/0', and executes '/usr/local/bin/synce-usb-start' on module activation.
2) Now, create '/usr/local/bin/synce-usb-start':
--cut here--
#!/bin/sh
exec /usr/bin/synce-serial-start &>/dev/null
--cut here--
It's just a wrapper for '/usr/bin/synce-serial-start' to discard undesired output.
3) That's it! No confusing vendor/product ID's and no wasting RAM with hotplug daemon :D
Good luck!
Stanislaw,
Thank you very much for this information! I have added a link to your post on the hotplug web page!
\David
I implemented the following, NOT using devfs, but hotplugging. It should support both devfs and udev, but it's only tested on udev. The "remove" action does not seem to be called, will try and figure that out later. Be sure to make the ipaq file executeable! The script will work without the config file at the bottom, but it's nice if you want to customize. The dccm automatic startup will only work if you have valid users in /etc/dccm.users
/etc/hotplug/usb/ipaq
------------from here
#!/bin/bash
LOG=/var/log/synce
#stop and synce serial connections
synce-serial-abort >> /dev/null
#Sleep awhile to give the device time to be created
sleep 2
#Startup dccm users
if [ -e /etc/dccm.users ]
then
echo "Starting DCCM users" >> $LOG
for user in `cat /etc/dccm.users`
do
sudo -u $user /usr/bin/dccm
done
else
echo "No DCCM users." >> $LOG
fi
if [ "$ACTION" = "add" ]
then
#Get the Device
if [ -e /dev/tts ];
then
DEVDIR=/dev/tts
DEVFILE=USB*
else
DEVDIR=/dev
DEVFILE=ttyUSB
fi
DEVICE=`cd $DEVDIR; ls -1 --sort=t $DEVFILE | head -n 1`
#Reconfigure the serial connection
if [ -e /etc/ipaq.conf ]
then
. /etc/ipaq.conf
echo "Configuring iPAQ" >> $LOG
echo " Device:$DEVDIR/$DEVICE" >> $LOG
echo " Local IP:$LOCAL" >> $LOG
echo " Remote IP:$REMOTE" >> $LOG
echo " NameServer:$NAMESERV" >> $LOG
synce-serial-config $DEVDIR/$DEVICE $LOCAL:$REMOTE $NAMESERV >> /dev/null
else
echo "Configuring iPAQ" >> $LOG
echo "Device:$DEVDIR/$DEVICE" >> $LOG
echo "Default values" >> $LOG
synce-serial-config $DEVDIR/$DEVICE >> /dev/null
fi
#Start the serial script
synce-serial-start >> /dev/null
fi
if [ "$ACTION" = "remove" ]
echo "Removing..." >> $LOG
synce-serial-abort >> /dev/null
fi
-------------till here!
My /etc/ipaq.conf
-------from here
LOCAL=192.168.1.12
REMOTE=192.168.1.122
NAMESERV=192.168.1.53
-------till here
My /etc/dccm.users
-------from here
myusername
-------till here
Enjoy!
Excellent, thank you!
It would be great for someone else (perhaps with better devfs knowledge) to test this; mine is a hack ripped from default /etc/devfsd.conf USB mouse config =D
This isn't right because it executes on all USB plugins.
I wanted to share my experience getting hotplugging set up with udev and Fedora Core 3 in the hopes that it will save someone else time. I needed to do three things:
(1) Create a rule for my device and save it under /etc/udev/rules/10-siemens. (The 10-siemens part is a bit arbitrary.) This step is not strictly necessary, but the default is to treat this device as ttyUSB0, and it seemed a bit presumptuous to write a hotplug script that would start synce every time a device was registered as ttyUSB0. So, I made _my_ device be "/dev/synceUSB[0,1..]" -- obviously you may need to change this rule if you have a different device; you can figure out the vendor and product id from usbview. My device is a siemens SX-56, and so my rule is:
-----snip---------
BUS="usb",SYSFS{idVendor}="0bb4", SYSFS{idProduct}="00ce", name="synceUSB%n"
-----snip-------
2. Create a script that would launch after the device was registered and removed. It will need to be saved as /etc/dev.d/[device name]/[whateveryoulike].dev. So for example mine was /etc/dev.d/synceUSB0/synce.dev. I also created scripts for synceUSB1 and synceUSB2 because I found it would sometimes not unregister and reregister properly the second time I plugged it in. Anyway, here is my script:
-----------snip-----------
#!/bin/sh
if [ "$ACTION" = "add" ]; then
/usr/bin/synce-serial-config /dev/synceUSB0
/usr/bin/synce-serial-start
fi
if [ "$ACTION" = "remove" ]; then
/usr/bin/synce-serial-abort
fi
----------snip--------------
3. The script /usr/bin/synce-serial-start, as of my version (0.90), was not able to find a path to modprobe when called this way. For that reason, I had to change the reference to modprobe in that script to include the full path (/sbin/modprobe).
Finally, just a caveat: I haven't been able to get the synce-serial-abort script to properly shut down all of the daemons. I have to do ps | grep synce | xargs kill and maybe I'll put that in my script. But hopefully someone will fix the problem soon. Anyway, at least it works the first time after you turn the machine on! :)
Cheers,
Tavis
I'm working on this one now. It appears that 'remove' is never called because when the ipaq is removed from the cradle, pppd doesn't die, which keeps /dev/synceUSB0 alive. Since /dev/synceUSB0 doesn't 'go away' 'remove' is never called. What we need is a way to kill pppd after removing the ipaq from the cradle. Something like a ping test, maybe. I'll post it if I get it fixed.
Hello, I'm Juan Bokser from Argentina, (i'm very new to linux), i make this .dev script:
#!/bin/bash
USER=jbokser
LOCALIP=192.168.20.1
REMOTEIP=192.168.20.2
if [ "${ACTION}" = "add" ] ; then
PID=`ps -C dccm -o pid --no-headers`
if [ ! -x $PID ]; then
kill $PID
fi
synce-serial-abort
synce-serial-config $DEVNAME $LOCALIP:$REMOTEIP
synce-serial-start
LOGCOUNT=`who | cut -d " " -f 1 | grep -c $USER`
if [ "$LOGCOUNT" != "0" ] ; then
sudo -u $USER /usr/bin/dccm
fi
fi
if [ "${ACTION}" = "remove" ] ; then
synce-serial-abort
PID=`ps -C dccm -o pid --no-headers`
if [ ! -x $PID ]; then
kill $PID
fi
fi
Sorry for my english ....
I have extended this method slightly on my system and it appears to be working. I added an extra line to the end of the /etc/devfs.d/synce...
--cut here--
UNREGISTER ^usb/tts/([0-9])$ EXECUTE /usr/local/bin/synce-usb-stop
--cut here--
I extended the /usr/local/bin/synce-usb-start file to match the behaviour suggested in the hotplug tutorial...
--cut here--
#!/bin/sh
export time=`date +"%b %d %X"`
export uname=`uname -n`
echo "$time $uname $0: iPAQ added" >> /var/log/synce
echo /usr/bin/synce-serial-abort >> /dev/null
exec /usr/bin/synce-serial-start >>/var/log/synce
--cut here--
And added /usr/local/bin/synce-usb-stop ...
--cut here--
#!/bin/bash
export time=`date +"%b %d %X"`
export uname=`uname -n`
echo "$time $uname $0: iPAQ removed" >> /var/log/synce
sleep 15
synce-serial-abort >> /var/log/synce
--cut here--
I might look into detecting whether dccm or vdccm is running, as this might be a useful extra. Does anyone know how I can go about this?
here is my hotplug script for synce which has worked reasonably well.
/etc/hotplug/usb/synce
-----------------start-----------------------
#!/bin/bash
#copy this file to /etc/hotplug/usb/
if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
then
/usr/bin/synce_setup.pl &
if [ -n "$REMOVER" ]; then
cat > $REMOVER <<EOF
#!/bin/sh
/usr/bin/synce-serial-abort
rm -f $REMOVER
EOF
chmod +x $REMOVER
fi
fi
------------------end---------------------
/usr/sbin/synce_setup.pl
------------------start-------------------
#!/usr/bin/perl -w
#setup and start synce service
#copy this file to /usr/bin
## abort any possible connection first
system("synce-serial-abort");
#sleep 2 sec, wait the device show up in /dev
sleep 2;
#find the newest device which we just plugged
open(INPUT, "cd /dev; ls -1 -r --sort=t ttyUSB* |");
local $device="";
while(<INPUT>)
{ s/\n//;
$device=$_;
}
# if we find the device
# config it and start the service
if($device ne "")
{
system("synce-serial-config $device");
system("synce-serial-start");
}
--------------end---------------------
PS. on my system, /dev/ttyUSBx dont show up before the hotplug script finish,that's why synce_setup.pl sleep 2 seconds.