View previous topic :: View next topic |
Author |
Message |
l_arbalette Guru
Joined: 05 Feb 2006 Posts: 569 Location: Paris - FRANCE
|
Posted: Mon Jan 22, 2018 9:20 pm Post subject: [iPhone auto mount script] with udev launching the script |
|
|
Hello Gentoers,
I've decided to let my family's iPhone (my wife's, sons' and mine's) auto-mount when plugged to a USB port.
rather than manually launching a script, which my family is not fond of...
I've created a udev rule as follow in /etc/udev/rules.d/90-iphone.rules:
Code: |
# udev rules for setting correct configuration and pairing on tethered iPhones
ATTR{idVendor}!="05ac", GOTO="iphone_rules_end"
# Execute mon script quand un iphone est connecté.
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05ac", ATTR{idProduct}=="12[9a][0-9a-f]", GROUP="users", RUN+="/usr/monter_iphone"
SUBSYSTEM=="usb", ACTION=="remove", ATTR{idVendor}=="05ac", ATTR{idProduct}=="12[9a][0-9a-f]", GROUP="users", RUN+="fusermount -u /mnt/iphone"
LABEL="iphone_rules_end"
|
I've searched for the path of my device by looking into the output of
Code: | udevadm info -e > udev_database
nano udev_database # look for an Apple entry, and when found, for DEVPATH value |
I've tested the udev rule with the DEVPATH value : Code: | udevadm test /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5 |
The output looks pretty satisfying : https://pastebin.com/0Vhbbbq5
especially with the run: '/usr/monter_iphone' at the end, confirming that the script will be ran.
Manually lauching the script works : iPhone is mounted, and automatically, Dolphin file manager is opening directly to the Pictures directory.
Script looks like :
Code: | #!/bin/bash
idevicepair pair
su $(who am i | cut -f 1 -d ' ') -c "ifuse /mnt/iphone -o nonempty"
su $(who am i | cut -f 1 -d ' ') -c "dolphin --select /mnt/iphone/DCIM" |
the reason why I have this su $(who am i | cut -f 1 -d ' ') -c part is because if I run ifuse as root, I cannot access files...and second reason is that Dolphin cannot be ran as root.
running, as root, the command who am i | cut -f 1 -d ' ', return my user...which is exactly what I want to do (I want to run the commands as the user who has the active X session : it canbe me, my son, my wife, whoever has a user account).
But, 1st problem : when udev is running the script, who am i | cut -f 1 -d ' ' returns nothing
Second problem : when udev is running the script, idevicepair pair returns No device found, is it plugged in? (I know it because I've added a redirection of idevicepair pair output to a text file, confirming that the script was ran, and giving me some information why it failed)
running the script manually immediately after is sucessfull....
I tried,with very little hope, to add a SLEEP 1 at the beginning of the script, in case the device was not completely ready for beeing mounted at the time the script is launched....but still the same issue. But the device is clearly plugged in and ready, since running the script manually is a sucess.
Any idea how to solve my 2 issues ?
Thanks ! _________________ Proverbe chinois : L'homme qui pose une question peut sembler stupide, celui qui ne la pose pas le restera.
Abraham Maslow : Lorsque votre seul outil est un marteau, vous avez tendance à traiter tous les problèmes comme un clou. |
|
Back to top |
|
|
l_arbalette Guru
Joined: 05 Feb 2006 Posts: 569 Location: Paris - FRANCE
|
Posted: Wed Jan 24, 2018 8:57 pm Post subject: |
|
|
I tried many things, still with no success :
I changed the $(who am i | cut -f 1 -d ' ') part by $(echo $PWD | cut -f 3 -d '/'), which is giving the active X user as well, since environment variable $PWD is updated with the current working directory (being the /home/user on my config)
I discovered that udev has no access to any usual ENV variables in the usual shell context...
Reading this article : http://reactivated.net/writing_udev_rules.html#external-run
and especially this part :
Quote: | udev does not run these programs on any active terminal, and it does not execute them under the context of a shell |
I understand that this is normal...
I tried to call printenv in my script => a lots of other ENV variables are accessible (iPhone serial number, DEVPATH, etc...) but nothing helpfull related to the user
Conclusion : my approach to get the user is wrong...looking for another approach...Any idea ?
I tried as well to detach the script as explained in the article :
If we don't detach the script, udev is paused while the script is running.
I achieved this by adding (in bold) { myscript goes here }& to let the script run in background while udev carry on
Nothing changed : i still have the problem that idevicepair pair returns No device found, is it plugged in?
In the meanwhile, I discovered that running
is returning 3 serial numbers...one of them being my own iPhone...
I'm wondering if the pairing is persistent ? because the 2 others serial number are related to iPhone that are not currently plugged ! _________________ Proverbe chinois : L'homme qui pose une question peut sembler stupide, celui qui ne la pose pas le restera.
Abraham Maslow : Lorsque votre seul outil est un marteau, vous avez tendance à traiter tous les problèmes comme un clou. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|