#!/bin/bash # # This script is started in the background from solidoodle-udev. It is safe # in here to now do long term operations, UDEV isn't waiting on this. # # Two arguments are passed in, the first is the ACTION environment variable # from the UDEV script, the second is the DEVNAME environment variable. # export ACTION="$1" export DEVNAME="$2" # The ever helpful systemd will seek out and destroy any udev cgroup # tasks that hang around too long for it, so we need this perfectly # obvious line to make this a user cgroup task instead of a udev one. echo $$ > /sys/fs/cgroup/systemd/user.slice/tasks # The device isn't really there till a little time has passed, so wait # a bit. sleep 2 # # First trick - these scripts are intended to do funny things when I plug in # my solidoodle, but if I have my AVRISP mkII programmer plugged in, then it # is the one that wants to do funny things, so if lsusb says I have the ISP # plugged in, exit right away. # avrisp=`lsusb | fgrep 'ID 03eb:2104 Atmel Corp. AVR ISP mkII' | wc -l` if [ "$avrisp" -ge 1 ] then exit fi if [ "$ACTION" = "add" ] then # Now find out if $DEVNAME is really a solidoodle by sending a gcode # command to query the device and see if it responds with a string that # says solidoodle somewhere. solid=`/usr/local/bin/send-this "$DEVNAME" M115 2>/dev/null | \ fgrep -i solidoodle | wc -l` if [ "$solid" -ge 1 ] then # Looks like it really is a solidoodle. Make a symlink for this # device named /dev/solidoodle so we don't have to worry about # plugging in multiple different ACM devices in random orders # screwing up our printer config info. rm -f /dev/solidoodle ln -s $DEVNAME /dev/solidoodle su -l tom /bin/bash -c \ "/usr/local/bin/bg-dammit /bin/bash /home/tom/scripts/solidoodle-on" fi exit fi if [ "$ACTION" = "remove" ] then # If /dev/solidoodle is a symlink to $DEVNAME, then remove the symlink. solid=`readlink /dev/solidoodle 2>/dev/null` if [ "$solid" = "$DEVNAME" ] then rm -f /dev/solidoodle su -l tom /bin/bash -c \ "/usr/local/bin/bg-dammit /bin/bash /home/tom/scripts/solidoodle-off" fi exit fi