Autorun pmount when new usb drive is plugged? [SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

Autorun pmount when new usb drive is plugged? [SOLVED]

#1 Post by Argolance »

Hello,
I noticed that when pmount is running, the application is automatically closed and reopened when, for example, a removable USB drive is unplugged. This doesn't happen when a new removable drive is plugged. User has to to click on the refresh button for the drive to be taken in account/listed. I made a fork of pmount (I saw later that Zigbert and some others made something similar but didn't find the thread again! :oops: ) and would like it to be automatically launched/relaunched as soon as any removable usb drive is plugged in.

Has somebody any track I could explore to do this?

Cordialement.
Attachments
124945_300x529_easyshot.jpg
(19.04 KiB) Downloaded 566 times
Last edited by Argolance on Thu 24 Jan 2013, 18:05, edited 2 times in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#2 Post by sunburnt »

Hi Argolance; Puppy`s mount GUI, pmount has to be refreshed for CD-DVD also.

Are you just trying to change the behavior of pmount, or auto. mount USB devices?

A simple script can auto. mount USB devices without pmount.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: Autorun pmount when new usb drive is plugged?

#3 Post by L18L »

Argolance wrote:...like it to be automatically launched/relaunched as soon as any usb drive is plugged in....
Maybe just this?
Attachments
event.png
(26.91 KiB) Downloaded 570 times

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#4 Post by Argolance »

Hello,
Thank you for answering.
My purpose is to replace (optionally) drives/partitions desktop icons with this fork of pmount (2pmount) because I don't find them very convenient.
2 reasons:
  • - When many applications are running, drives icons being in the background, it is sometimes boring to move windows to reach them, unless minimizing all the applications windows, which is not convenient to.
    - When working with 2 screens (twinview), icons are hidden when screens has not the same size (though I know it is possible to move icons for them to be visible but this has to be done before configuring twinview).
It is why I would like 2pmount to react as soon as any removable drive is plugged (exactly as it is the case when any removable drive is unplugged!) and finally this one to be listed and mountable (by clicking on the corresponding button), all this without having to click on the refresh button.

It probably should not be too much difficult to make but supposes knowledge which I do not currently have! At least a track to follow or an example to be imitated should be great!

Cordialement.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#5 Post by SFR »

I guess this is the thread you've lost track of:
http://murga-linux.com/puppy/viewtopic.php?t=77494

It's /sbin/pup_event_frontend_d script which is responsible for refreshing pmount in case of device removal, but it's easy do add this also in case of device insertion.

I tested it only with USB stick plugging/unplugging and all was fine, but can't guarantee it will be so with everything - perhaps there's a reason why Barry and others didn't design it this way..?

But if you'd like to explore it anyway, find the following block of code and add if..fi condition as shown:

Code: Select all

  ACTION=add
  SUBSYSTEM=block
  DEVTYPE=disk
  for DRV_NAME in $BLOCKSADD
  do
   [ ! -e /sys/block/$DRV_NAME ] && continue #precaution
   DEVPATH=/block/$DRV_NAME
   odPATTERN='^/dev/'"$DRV_NAME"'|'
   PROBEDISK="`probedisk2`"
   DRVS_OPTICAL="`echo "$PROBEDISK" | grep '|optical|' | cut -f 1 -d '|' | cut -f 3 -d '/'`" #update
   DRVS_FLOPPY="`echo "$PROBEDISK" | grep '|floppy|' | cut -f 1 -d '|' | cut -f 3 -d '/'`" #update
   DRV_CATEGORY="`echo -n "$PROBEDISK" | grep "$odPATTERN" | cut -f 2 -d '|'`"
   DRV_DESCRIPTION="`echo -n "$PROBEDISK" | grep "$odPATTERN" | cut -f 3 -d '|' | tr -s ' '`"
   [ "$ICONDESK" = "true" ] && create_icon_func #uses DRV_NAME, DRV_CATEGORY, DRV_DESCRIPTION
   [ "$HOTPLUGNOISY" = "true" ] && /root/.pup_event/drive_${DRV_NAME}/AppRun ${DRV_CATEGORY} & #handler script.
   
   if [ "`pidof gtkdialog_pmount`" != "" ];then #if pmount running, refresh it.
    killall gtkdialog_pmount 2>/dev/null
    sleep 0.1
    LANG=$OLDLANG pmount & #100613 fix from shinobar.
   fi

  done
(btw, this code is taken from Slacko-5.4, so if you're using other Puppy it may vary, but I'm sure you can handle it).

After modifications restart X.

HTH
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#6 Post by Argolance »

SFR wrote:I guess this is the thread you've lost track of:
http://murga-linux.com/puppy/viewtopic.php?t=77494
It was another thread, not specially dedicated to the single Zigbert pmount...
SFR wrote:I tested it only with USB stick plugging/unplugging and all was fine, but can't guarantee it will be so with everything - perhaps there's a reason why Barry and others didn't design it this way..?
Is this zigbert advertisement meaning that this has not to be "touched"?
zigbert wrote:the detection/mounting engine is NOT touched.
I copied lines inside the pmount script as described above. This works... but pmount opens and closes non-stop...
I tried this too, to make pmound automatically running (if not!) when a removable drive is plugged:

Code: Select all

	if [ "`pidof gtkdialog_pmount`" = "" ];then #if pmount not running, launch it.
    LANG=$OLDLANG pmount & #100613 fix from shinobar.
	else #if pmount running, refresh it.
    killall gtkdialog_pmount 2>/dev/null
    sleep 1
	LANG=$OLDLANG pmount & #100613 fix from shinobar.
	fi
But this doesn't work: pmount sleeps...

Cordialement.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#7 Post by SFR »

Argolance wrote:
SFR wrote:I tested it only with USB stick plugging/unplugging and all was fine, but can't guarantee it will be so with everything - perhaps there's a reason why Barry and others didn't design it this way..?
Is this zigbert advertisement meaning that this has not to be "touched"?
zigbert wrote:the detection/mounting engine is NOT touched.
Zigbert is referring to pmount, not to pup_event_frontend_d.
What I mean is that I have tried it only with USB stick (and later with WD MyPassport which has 1 "normal" partition + virtual CD drive), no DVD, SD, etc...
Argolance wrote:I copied lines inside the pmount script as described above. This works... but pmount opens and closes non-stop...
I tried this too, to make pmound automatically running (if not!) when a removable drive is plugged:

Code: Select all

	if [ "`pidof gtkdialog_pmount`" = "" ];then #if pmount not running, launch it.
    LANG=$OLDLANG pmount & #100613 fix from shinobar.
	else #if pmount running, refresh it.
    killall gtkdialog_pmount 2>/dev/null
    sleep 1
	LANG=$OLDLANG pmount & #100613 fix from shinobar.
	fi
But this doesn't work: pmount sleeps...
What can I say - your modified piece of code works well for me.
Could you attach the whole modified script, so I could look into it?

BTW, Slacko-5.4 has Zigbert's fork of pmount installed, perhaps that's why it acts differently to each of us?

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#8 Post by Argolance »

Hello SFR,
Today, pmount ran immediately when I plugged my USB flash drive: yesterday, I forgot to restart X before testing added code lines inside pup_event_frontend_d.
But pmount don't stop opening/closing... To stop the loop, I have to unplug the device.
Could you attach the whole modified script, so I could look into it?
Thank you! Please, see attached file, to be simply renamed without extension.

Cordialement.
Attachments
pup_event_frontend_d.tar
(35.23 KiB) Downloaded 283 times

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#9 Post by SFR »

Hey Argolance

Your version of pup_event_frontend_d is practically the same as mine (and works as mine), just a bit newer. The only difference is:
#121212 try increase sleep to 3 ...still getting rox-filer crashing.
but this is irrelevant here, I believe.

I tried the modification also in Lupu-528 & Wary-5.3 (pristine boot, in VBox) and still ok.

What about some "debugging"? :wink:
Few things to try (if you haven't done so yet):
1. pfix=ram
2. Different USB stick
3. Replace 'pmount' with something else, eg. 'abiword' in the script:

Code: Select all

    if [ "`pidof abiword`" = "" ];then #if pmount not running, launch it.
      LANG=$OLDLANG abiword & #100613 fix from shinobar.
    else #if pmount running, refresh it.
      killall abiword 2>/dev/null
      sleep 1
      LANG=$OLDLANG abiword & #100613 fix from shinobar.
    fi
4. Add the 'echo...' as shown, restart X, plug in USB stick (let pmount restart few times), stop pup_event_frontend_d and see what's inside /root/pup_debug.

Code: Select all

 #########hotplug block event##########
 if [ "$BLOCKDIFF" != "" ];then
  echo "$BLOCKDIFF" >> /root/pup_debug
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#10 Post by Argolance »

Hello SFR,
SFR wrote:4. Add the 'echo...' as shown, restart X, plug in USB stick (let pmount restart few times), stop pup_event_frontend_d and see what's inside /root/pup_debug.
Code:

Code: Select all

 #########hotplug block event##########
 if [ "$BLOCKDIFF" != "" ];then
  echo "$BLOCKDIFF" >> /root/pup_debug	
Sorry, but where do I copy this exactly? :oops:

Cordialement.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#11 Post by SFR »

Yeah, sorry - to pup_event_frontend_d
According to your script this block begins at line 721.

BTW, I don't mean you to do those tasks at once, they should be done as a separate trials (first try pfix=ram, if problem still occurs - try another USB stick and so on).

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#12 Post by Argolance »

Hello SFR,
:oops: :oops: :oops:
Replacing pmount with abiword gives the same issue. I tested with the original pmount, zigbert pmount and mine.
More: Nothing happens anymore... :shock: Even when I plug/unplug an (other) removable USB device (I didn't forget to restart X after modifying pup_event_frontend_d!)
Otherwise, pmount works normally!
Is there any "hidden" config file to clear now for being able to start all over again?
:(
I am very disappointed, because this would be very convenient. But, as you said above, there is probably some reason for this not to have already been done by some "Puppy king": It would be very surprising that nobody thought of this little improvement!
This is what pup_debug says:
> sdc
> sdc
> sdc
> sdc
> sdc
> sdc
> sdc
> sdc
> sdc
> sdc
> sdc
> sdc
3d2
< sdc
2a3
> sdc
3a4
> sdd
> sdd
> sdd
> sdd
> sdd
> sdd
> sdd
> sdd
> sdd
> sdd
> sdd
> sdd
4d3
< sdd
3d2
< sdc
Cordialement.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#13 Post by SFR »

Is there any "hidden" config file to clear now for being able to start all over again?
Just replace /sbin/pup_event_frontend_d with the original one from CD or (if you have frugal install) from /initrd/pup_ro2/sbin/ and restart X, or better reboot.

The debug shows that when you insert a USB stick, it starts to be constantly detected as if it was just plugged in a moment ago - it shouldn't be like this, I guess, and that's why pmount restarts over and over again.

One more thing - did you try to boot with pfix=ram (or even with other Puppy version), modify pup_event_frontend_d and see what happens then?
If this one fails too - I'll be out of ideas why it acts this way in your case, sorry. :cry:


EDIT:
If pfix=ram will fail, clean all things as they were before we started, and try this (it's stand-alone script):

Code: Select all

#!/bin/bash

OLD="`ls -1 --hide=ram* --hide=loop* /sys/block`"

while true; do
  NEW="`ls -1 --hide=ram* --hide=loop* /sys/block`"
  if [ "${#NEW}" -gt "${#OLD}" ]; then
	if [ "`pidof gtkdialog_pmount`" = "" ]; then #if pmount not running, launch it.
      pmount &
	else #if pmount running, refresh it.
      killall gtkdialog_pmount 2>/dev/null
      sleep 0.1
	  pmount &
	fi
  fi
  OLD="$NEW"
  sleep 2
done
It's not an elegant solution since it duplicates some functionality from pup_event_frontend_d, but perhaps at least this will work fine for you...

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#14 Post by Argolance »

Hello SFR,
Thank you for you patience...
I tested on my laptop too and got the same issue.

Your latest idea is great and I finally think a stand alone script would be much better: it could be so activate/deactivate by user, through an additional option in pmount.
I copied your script to /root/startup/ as "pmount_in_out.sh" (for example), cleaned /sbin/pup_event_frontend_d and restarted X: This works! ... but is almost operational: from the second attempt, pmount window is not refreshed properly and this has to be done manually (perhaps is this due to the remove action code part of pmount?)

Anyway, I was wondering if it would not be more appropriate to complete the script for it to support both add/remove actions, and uncomment or simply delete relative lines inside pmount?
I admit that I can just say your script works but cannot say how!

Code: Select all

OLD="`ls -1 --hide=ram* --hide=loop* /sys/block`"

while true; do
  NEW="`ls -1 --hide=ram* --hide=loop* /sys/block`"
  if [ "${#NEW}" -gt "${#OLD}" ]
Thank you so much for this beautiful fish! So, I take the risk of abusing your kindness: may I please ask you to give me the net to try to catch it myself? :wink:

The initial idea is indeed perhaps going to succeed thanks to you? :D :D

Cordialement.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#15 Post by SFR »

Hey Argolance

I'm glad we've achieved some positive results at last. :)
Anyway, I was wondering if it would not be more appropriate to complete the script for it to support both add/remove actions, and uncomment or simply delete relative lines inside pmount?
I admit that I can just say your script works but cannot say how!
(Those lines are in pup_event_frontend_d, not pmount)
Sure, just comment out the if..fi block (it's around line 750, just below the section we were playing with) as shown:

Code: Select all

  ACTION=remove
  for DRV_NAME in $BLOCKSREM
  do
   #[ -e /sys/block/$DRV_NAME ] && continue #precaution. w015 must remove.
   DRVS_OPTICAL="`echo "$DRVS_OPTICAL" | grep -v "$DRV_NAME"`" #update
   DRVS_FLOPPY="`echo "$DRVS_FLOPPY" | grep -v "$DRV_NAME"`" #update
   DEVPATH=/block/$DRV_NAME
   #if [ "`pidof gtkdialog_pmount`" != "" ];then #if pmount running, refresh it.
   # killall gtkdialog_pmount 2>/dev/null
   # sleep 0.1
   # LANG=$OLDLANG pmount & #100613 fix from shinobar.
   #fi
   remove_pinboard_func #needs DRV_NAME
   rm -rf /root/.pup_event/drive_${DRV_NAME}* 2>/dev/null
  done
And the modified script with add & remove support + comments:

Code: Select all

#!/bin/bash

# This line stores in OLD variable the current state of /dev/block/ folder
# (except ram* and loop*, only sd* etc.), where appropriate links
# are being created in case of device insertion/removal.
# BTW, this line is taken from /sbin/pup_event_frontend_d and the whole
# detection mechanism is very simplified here, so may not work with some devices.
# For details see pup_event_frontend_d around lines 680-.
OLD="`ls -1 --hide=ram* --hide=loop* /sys/block`"

# Infinite loop, executed every 2 seconds
while true; do
  # Store the state of /dev/block/ in NEW variable, for comparsion
  NEW="`ls -1 --hide=ram* --hide=loop* /sys/block`"
  
  # If the lenght of NEW is greatest than OLD, most likely a new device
  # was plugged in...
  if [ "${#NEW}" -gt "${#OLD}" ]; then
    # You know this part ;)
	if [ "`pidof gtkdialog_pmount`" = "" ]; then #if pmount not running, launch it.
      pmount &
	else #if pmount running, refresh it.
      killall gtkdialog_pmount 2>/dev/null
      sleep 0.1
	  pmount &
	fi
  fi
  
  # If the lenght of NEW is less than OLD, most likely a device was removed
  if [ "${#NEW}" -lt "${#OLD}" ]; then
    # Don't launch pmount in this case, just refresh it if running.
	if [ "`pidof gtkdialog_pmount`" != "" ]; then #if pmount is running, refresh it.  
      killall gtkdialog_pmount 2>/dev/null
      sleep 0.1
	  pmount &
	fi
  fi
  
  OLD="$NEW"
  sleep 2
done
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#16 Post by Argolance »

Hello SFR,
Really great! This works, as well as plugging or unplugging a removable device and explanations helped me to understand how: thank you!
Last thing :oops: : As said above, pmount window is not always refreshed properly and this has sometimes to be done manually. Is there any sleep delay to put/increase somewhere for this script to work... perfectly?

Cordialement.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#17 Post by SFR »

Perhaps the device was reinserted too quickly..? Hard to say, because I haven't encountered this problem.
You can try decrease sleep 2 to, eg. sleep 1, but don't know if this helps...

To watch up to date what devices (and how quick) are being recognized by system, launch this in terminal:

Code: Select all

watch -n1 ls -1 --hide=ram* --hide=loop* /sys/block
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#18 Post by Argolance »

Hello SFR,
Thank you for all!
There are really fantastic, qualified and incredibly committed guys on this Forum: it is a happiness!
I think I can consider this thread as duly [SOLVED] now! :D
Have a good day.

Cordialement.

Post Reply