Posts: 26
tuto
Joined: 07 Aug 2016
#1
Hello community...!

I like this operating system... I am using AntiX-13.2 with desktop SpaceFM-IceWM with some small adjustment"to own taste", and is amazing... __{{emoticon}}__

I am using the lastest version of SpaceFM (1.0.5+alpha), installed trough spacefm-installer.sh script from its official website.
To removable media automount, I using devmon script as daemon using SpaceFM Devices|Settings|Auto-Run|On unmount option with

Code: Select all

eject %v ; sleep 7 ; eject -t %v
command for eject CD/DVD after unmounted, only.
This feature work fine!

For to unmount USB drives, I added the following line at startup file in $HOME/.icewm directory:

Code: Select all

devmon --exec-on-drive"spacefm %d" --exec-on-drive"killall yad ; sleep 1 ; yad --image=\"$ICON\" --text=\"A USB drive has been \ndetected and mounted\" --geometry=\"150x45+734-25\" --no-buttons --skip-taskbar --on-top --undecorated --timeout=\"5\"" --exec-on-drive"sleep 3 ; yad --notification --image=\"$ICON" --text=\"Click for unmount USB drive(s) mounted\" --command=\"/usr/local/bin/unplugdrive.sh\"" --exec-on-disc"spacefm %d" --exec-on-audio"deadbeef cdda://%f" --exec-on-video"smplayer dvd://%f" --exec-on-remove"sleep 10 ; /usr/local/bin/kill-usb-icon.sh" & > /tmp/devmon.log
and for log in on new session without some devmon process running, well I added it to exitantix.sh script:

Code: Select all

devmon_daemon=$(ps ax | grep -v grep | grep"devmon")
if ["$devmon_daemon" > /dev/null ]; then
   echo"Kill some devmon process that be running"
    kill -9 `"$devmon_daemon" | awk '{ print $1 }' | cut -d' ' -f 1`;
    pkill -u $USER devmon
fi
Several USB drives are mounted and can be unmounted easily with a click on usb-icon in WM's systray.

But after that some device is unmounted, the usb-icon disappear when exists others USB drives mounted yet. This behaviour is because to kill-usb-icon.sh script:

Code: Select all

#!/bin/bash

## Name of script: kill-usb-icon.sh
## Function: Close USB icon on systray if not exists usb drive mounted.
## Author: fdm
## Adapted from unplugdrive.sh bash script by SamK and Anticapitalista 
## Date: 21/07/2016 23:42.
## Lastest update: 
#
# Copyright (C) <2016>  <fdm>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################

# Variables
ICON1=$HOME/.icons/usbdrv.png
ICON2=$HOME/.icons/removable_media_mounted.png
TEXT1=A USB drive has been \ndetected and mounted
TEXT2=One or more USB drive(s) \nare mounted yet
# Collect details of each removable device that has at least one mounted partition
discovered=$(pmount|grep /dev/|sort|tr ' ' '_'|cut -d _ -f 1,2,3)

# Create a list of removable devices excluding CD/DVD
for item in $discovered;do
   if [[ ! $item = /dev/sr* ]];then
     detectedlist="$detectedlist$item"
   fi
done

# Create a list of each removable drive, mounted partition and mountpoint
removablelist=""
removablenow=""
for item in $detectedlist;do
   removablenow=$(echo $item|cut -c 6-|tr '_' ' ')
   removablelist="$removablelist$removablenow\n"
done

# Create a list of each unplugable drive
drivelist=""
drivenow=""
driveprevious=""
position=0
for item in $detectedlist;do
   drivenow=$(echo $item|cut -d _ -f 1|cut -c 6-8)
   if ["$drivenow" !="$driveprevious" ];then
      drivelist="$drivelist $position $drivenow"
      driveprevious=$drivenow
   fi
#   position=$(expr $position + 1)
done

if [ !"$drivenow" ="" ]; then

   kill -9 `ps ax | grep -v grep | grep"yad" | awk '{ print $1 }' | cut -d' ' -f 1`;

   devmon --exec-on-drive"spacefm %d" --exec-on-drive"yad --notification --image=\"$ICON1" --text=\"$TEXT1\" --geometry=\"150x45+734-25\" --no-buttons --skip-taskbar --on-top --undecorated --timeout=\"5\"" --exec-on-disc"spacefm %d" -on-audio"deadbeef cdda://%f" --exec-on-video"smplayer dvd://%f"" & > /tmp/devmon.log
   
else

    yad --image="$ICON2" --text="$TEXT2" --geometry="150x45+734-25" --no-buttons --skip-taskbar --on-top --undecorated --timeout="5"

fi
At last, I have a question:
What parameter I should write in
if [ !"$drivenow" ="" ]; then
condition section of kill-usb-icon.sh script for others drives be detected, and consequently, perform the
else
statement?

I am biologist and have little knowledge on programming.
(Sorry by my English use... ).

I hope you can help me.

Thanks

fdm
Last edited by tuto on 07 Sep 2016, 22:02, edited 1 time in total.
Posts: 4,164
rokytnji
Joined: 20 Feb 2009
#2
Howdy and Welcome. I am just wondering if you have watched



^---- embedded YouTube-hosted video: https://www.youtube.com/L4pnACi6QBA



or read


========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://www.mepiscommunity.org/wiki/antix-faqs/automount-usb-sticks-and-cddvd-discs-antix"
linktext was:"http://www.mepiscommunity.org/wiki/anti ... iscs-antix"
====================================


Yet? It might help. or not. I am not sure as I am posting from a hospital bed and a bit groggy.
Posts: 26
tuto
Joined: 07 Aug 2016
#3
Dear rokytnji

Thanks for your by reply...

I saw and read those links. I succeeded unmount a usb drive by clicking on the icon showed in systray.

I think that the only thing missing is to know what the appropriate parameter to add in the condition statement of previous script.

I'm still in search.

I hope you recover soon.
Posts: 26
tuto
Joined: 07 Aug 2016
#4
Hi Antixers!

After a long time thinking how to solve this topic, I found a solution that works for me and hopefully to others as well.

In summary:

1) I am using AntiX-13.2 on a desktop PC.

2) I am using SpaceFM_1.0.5+alpha (this version bring in many improvements), and my principal desktop is space-icewm.

3) The automount it of USB devices is carried out by devmon script, both SpaceFM well as for Rox-Filer, being available from any window manager (be added to startup file).


========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"https://igurublog.wordpress.com/downloads/script-devmon/"
linktext was:"https://igurublog.wordpress.com/downloa ... pt-devmon/"
====================================


Here my IceWM startup file:

Code: Select all

#!/bin/bash

# ### Well see $HOME/.xinitrc-custom script.

# Save gpid for graceful killing of orphans
cut -d"" -f5 /proc/$$/stat > $HOME/.antix-session/startup-pgid:${DISPLAY%.[0-9]}

# Set wallpaper
login_background.sh 

# Auto update menu
auto-icewm-menu.sh 

# run icewm systray. 
# Do NOT run if icewm-session is running.
#icewmtray &

# kill icewmbg if is running.
if ps ax | grep -v grep | grep"icewmbg" > /dev/null; then pkill -u $USER icewmbg ; fi

# wicd
# sleep 2 && wicd-client -t &

# keyring
# gnome-keyring-daemon &

# run devmon_startup.sh script as automounter daemon for removables devices.
devmon_startup.sh

# run spacefm -d to automount plugin devices and popup spacefm filer.
# Do NOT enable if you use spacefm desktop.
# spacefm -d &

# mount Samba and/or NFS shares  
# connectshares &

# set live keyboard.
# Do NOT enable if use some keyboard layout switcher, as fbxkb.
# setxkbmap -layout"$XKBLAYOUT" -variant"$XKBVARIANT" -option"$XKBOPTIONS"

# run numlockx to LED NumLock-key on and activate the numpad.
# A bug in actual version SLiM unallow activate it from log in.  
numlockx &

# run unclutter to hide the mouse pointer on screen after 5 s without move it.
# When mouse move, the pointer will be show it again.
unclutter &

# run volumeicon to change volume level from systray and keyboard control.
volumeicon &

# run fbxkb
fbxkb &

# run system monitor conky
sleep 1 && conky -c ~/.conky/conkyrc_icewm
4) The devmon_startup script (located in /usr/local/bin directory) is:

Code: Select all

#!/bin/bash
## Script's name: devmon_startup.sh
## Function: Run devmon script as automounter daemon for removables devices depending of file manager running.
## Author: fdm from others scripts as unplugdrive.sh and devmon.
## Last update: 
#
# Requires that devmon be installed, and devmon script is provided by udevil.
#
# Copyright (C) <2016>  <fdm>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

# Variables
DESKTOP_CODE="$HOME/.antix-session/desktop-code$DISPLAY"
FM=`cat $DESKTOP_CODE | cut -d"-" -f1`
IMG1="/usr/share/icons/gTangish-2.0a1/48x48/actions/go-down.png"
TXT1="A USB drive has been \ndetected and mounted"
IMG2="/home/tesistas/.icons/usbdrv.png"
TXT2="Click for unmount USB drive(s) mounted"
if ["$FM" =="space" ] ; then

     # Run"spacefm --desktop" if not run at startup automatically.
   ps_out=$(/bin/ps ax | grep -v grep | grep"spacefm --desktop" | cut -d"" -f2)
   SPACE_PID=$(echo $ps_out)
   
   if ["$SPACE_PID" !="" ] ; then 
   
      echo"spacefm --desktop is running"
      
   else
   
      (spacefm --desktop) &
      
   fi
      
#   if [ ! -e"$SPACE_PID" ] ; then 
#      echo"spacefm --desktop is not running" >>/dev/null
#      spacefm --desktop 
#   fi

#   if [ -z"$ps_out" ] ; then 
#      echo"spacefm --desktop is not running" >>/dev/null
#      spacefm --desktop 
#   fi

     # Run devmon for automount it removables media on SpaceFM. In SpaceFM's menupath Devices|Settings|Auto Run|"On unmount" option was added"eject %v ; sleep 7 ; eject -t %v" without double quotes marks.
     which devmon &>/dev/null && which udevil &>/dev/null && devmon --exec-on-drive"spacefm %d" --exec-on-drive"killall yad ; sleep 1 ; yad --image=\"$IMG1\" --text=\"$TXT1\" --geometry=\"150x45+710-35\" --no-buttons --skip-taskbar --on-top --undecorated --timeout=\"5\"" --exec-on-drive"sleep 3 ; yad --notification --image=\"$IMG2\" --text=\"$TXT2\" --command=\"/usr/local/bin/unplugdrive_v3.sh\"" --exec-on-disc"spacefm %d" --exec-on-audio"deadbeef cdda://%f" --exec-on-video"smplayer dvd://%f" --exec-on-remove"sleep 10 ; /usr/local/bin/kill-usb-icon.sh" & > /tmp/devmon.log

   
elif ["$FM" =="rox" ] ; then

        # Run devmon for automount it removables media on Rox-Filer.
     which devmon &>/dev/null && which udevil &>/dev/null && devmon --exec-on-drive"rox %d" --exec-on-drive"killall yad ; sleep 1 ; yad --image=\"$IMG1\" --text=\"$TXT1\" --geometry=\"150x45+710-35\" --no-buttons --skip-taskbar --on-top --undecorated --timeout=\"5\"" --exec-on-drive"sleep 3 ; yad --notification --image=\"$IMG2\" --text=\"$TXT2\" --command=\"/usr/local/bin/unplugdrive_v3.sh\"" --exec-on-disc"rox %d" --exec-on-audio"deadbeef cdda://%f" --exec-on-video"smplayer dvd://%f" --exec-on-remove"sleep 10 ; /usr/local/bin/kill-usb-icon.sh" & > /tmp/devmon.log

else

   urxvt -hold -e echo"File manager by default running is not found." & sleep 3 && killall urxvt
   
fi

Here the" usbdrv.png" usb icon used (adapted from Puppy Linux"Lucid"):

Image


5) I used the unplugdrive.sh script from AntiX-15 on AntiX-13.2. I did small changes so I renamed to unplugdrive_v3.sh, but the credits are of anticapitalista and SamK being the script's original authors.

Code: Select all

#!/bin/bash

## Script's name: unplugdrive_v3.sh
## Function:
## Enables unmounting prior to unplugging removable storage
## Allows simultaneous selection of multiple drives
## Unmounts all mounted partitions on nominated drive(s)
## Removes mountpoints
## Original Authors: anticapitalista from unplugdrive.sh script. 
## Modified by: fdm
## Lastest Update:
#
# Requires yad and pmount to be installed.
# Requires / etc/udev/rules.d/99-usbstorage.unused to be renamed 99-usbstorage
#
# Copyright (C) <2016>  <fdm>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ##############################################################################

# Variables
TEXTDOMAINDIR="/usr/share/locale"
TEXTDOMAIN="unplugdrive.sh"
ICONS="/home/tesistas/.icons"
ICON="/usr/share/icons/gnome/32x32/devices/media-removable.png"

# Collect details of each removable device that has at least one mounted partition
discovered=$(pmount|grep /dev/|sort|tr ' ' '_'|cut -d _ -f 1,2,3)

# Create a list of removable devices excluding CD/DVD
for item in $discovered;do
   if [[ ! $item = /dev/sr* ]];then
     detectedlist="$detectedlist$item"
   fi
done

# Create a list of each removable drive, mounted partition and mountpoint
removablelist=""
removablenow=""
for item in $detectedlist;do
   removablenow=$(echo $item|cut -c 6-|tr '_' ' ')
   removablelist="$removablelist$removablenow\n"
done

# Create a list of each unplugable drive
drivelist=""
drivenow=""
driveprevious=""
position=0
for item in $detectedlist;do
   drivenow=$(echo $item|cut -d _ -f 1|cut -c 6-8)
   if ["$drivenow" !="$driveprevious" ];then
      drivelist="$drivelist $position $drivenow"
      driveprevious=$drivenow
   fi
   position=$(expr $position + 1)
done

# Display a message that no candidate for unmounting was discovered
if [ -z"$drivelist" ];then
   yad --image="$ICONS/usbdrv_unmount.png" --geometry="413x88+464-54" --text $"Attention: \n\nA removable drive with a mounted partition was not found.\nIt is safe to unplug the drive(s)" --no-buttons --on-top --undecorated --skip-taskbar --timeout="8"
   exit 0
fi

# Display a list from which the drives to be unplugged may be selected
selected=$(yad --window-icon="$ICONS/usbdrv.png" --image="$ICONS/removable_media_mounted.png" --title="USB drive" --list --geometry="300x300+514-34" --skip-taskbar --text=$"The following are currently mounted:\n$removablelist\nChoose the drive(s) to be unplugged\n" --checklist --column="Select" --column="Drives" --separator="" $drivelist)
   if [ -z"$selected" ];then
      yad --image="$ICONS/usb_unselected.png" --geometry="250x88+558-41" --text=$"Attention: \n\nNothing selected.\nAborting without unmounting." --no-buttons --on-top --undecorated --skip-taskbar --timeout="10"
      exit 1
   fi
echo selected is $selected

# Create a list of mountpoints used by the drives selected to be unplugged
declare -a mountpointlist
mountpointnow=""

TEMPFILE=/tmp/unpluglist
for item in $selected;do
   if ["$item" ="TRUE" ] ||["$item" ="FALSE" ]; then
    echo"nothing"
   else
   #mountpointnow=$(df |grep $item|awk -F"%" '{print $2}')
   df |grep $item|awk -F"%" '{print $2}'| tee -a $TEMPFILE  
   fi
done
OLDIFS=$IFS
IFS=$'\n'
mountpointlist=(`cat $TEMPFILE`)
   echo mountlist0 is ${mountpointlist[0]}
   echo mountlist1 is ${mountpointlist[1]}
   echo mountlist2 is ${mountpointlist[2]}
   rm -f $TEMPFILE
# Create a list summarising what is about to be unmounted
IFS=$OLDIFS
summarylist=""
summarypoint=""
for item in $selected;do
   if ["$item" ="TRUE" ] ||["$item" ="FALSE" ]; then
    echo"nothing"
   else
   echo item is $item
   summarypoint=$(df --output=source,target |grep $item)
   echo summarypoint is $summarypoint
   summarylist="$summarylist$summarypoint\n"
   fi
done
echo summary list is $summarylist

# Obtain confirmation to proceed with unmounting
yad --window-icon="$ICONS/usbdrv.png" --image="$ICON" --geometry="233x133+552-36" --skip-taskbar --title="USB drive" --text=$"About to unmount:\n$summarylist\nPlease confirm you wish to proceed."
if [ $? ="1" ];then
   yad --window-icon="$ICONS/usbdrv.png" --image="$ICONS/removable_media_mounted.png" --title="Attention" --geometry="318x88+554-52" --skip-taskbar --text=$"Nothing has been unmounted.\nAborting as requested with no action taken."
   exit 1
else
# Ensure everything is written to storage then unmount
   yad --text=$"Data is being written to devices.\nPlease wait..." & pid1="$!"
   sync
   kill $pid1
   count=${#mountpointlist[@]}
   echo count is $count
   i=0
   while ["$i" -lt"$count" ]
   do
    #$(pumount $item)
    echo item $i is ${mountpointlist[i]}
    pumount"${mountpointlist[i]}"
    i=$[$i+1]
   done
fi

#  Collect details of each removable device that has at least one mounted partition
postunmount=$(pmount|grep /dev/|sort|cut -d _ -f 1,2,3)

# Collect details of each mountpoint that pumount failed to remove

mountpointerrorlist=""
   i=0
   while ["$i" -lt"$count" ]
   do
   echo error check mount point ${mountpointlist[i]}
     mountpointerror=$(pmount|grep /dev/|sort|cut -d _ -f 1,2,3|grep -o"${mountpointlist[i]}")
     echo mountpointerror is $mountpointerror
    if [ ! -z"$mountpointerror" ];then
      mountpointerrorlist="$mountpointerrorlist$mountpointerror\n"
   fi
   i=$[$i+1]
   done

# Display a message if unmount failed
if [ ! -z"$mountpointerrorlist" ];then
   yad --window-icon="$ICONS/usbdrv.png" --image="$ICONS/usb_removal_failed.png" --title="Attention" --geometry="422x133+475-59"  --skip-taskbar --text=$"Mountpoint removal FAILED.\n\nA mountpoint remains present at:\n$mountpointerrorlist\nCheck each mountpoint listed before unpluging the drive(s)."
   exit 1
else
   # Display a message if unmount successful   
   yad --image="$ICONS/usb_safe_unplug.png" --geometry="250x90+584-36" --text=$"Unmounted USB drive:\n$summarylist\nIt is safe to unplug the drive(s)" --no-buttons --on-top --undecorated --skip-taskbar --timeout="8"
   exit 0
fi
                                 
Here the"usb_safe_unplug.png" icon used (modified by me):

Image

6) The kill-usb-icon.sh script (located in /usr/local/bin directory and used in devmon_startup.sh script) is:

Code: Select all

#!/bin/bash

## Name of script: kill-usb-icon.sh
## Function: Close USB icon on systray if not exists usb drive mounted.
## Author: fdm
## Adapted from unplugdrive.sh bash script by SamK and Anticapitalista 
## Date: 21/07/2016 23:42.
## Lastest update: 
#
# Requires yad and pmount to be installed.
# Requires / etc/udev/rules.d/99-usbstorage.unused to be renamed 99-usbstorage
#
# Copyright (C) <2016>  <fdm>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

# Variables
DESKTOP_CODE="$HOME/.antix-session/desktop-code$DISPLAY"
FM=`cat $DESKTOP_CODE | cut -d"-" -f1`
ICON="/usr/share/icons/gnome/48x48/devices/media-removable.png"
TEXT="One or more USB drive(s) \nare mounted yet"
# Collect details of each removable device that has at least one mounted partition
discovered=$(pmount|grep /dev/|sort|tr ' ' '_'|cut -d _ -f 1,2,3)

# Create a list of removable devices excluding CD/DVD
for item in $discovered;do
   if [[ ! $item = /dev/sr* ]];then
     detectedlist="$detectedlist$item"
   fi
done

# Create a list of each removable drive, mounted partition and mountpoint
removablelist=""
removablenow=""
for item in $detectedlist;do
   removablenow=$(echo $item|cut -c 6-|tr '_' ' ')
   removablelist="$removablelist$removablenow\n"
done

# Create a list of each unplugable drive
drivelist=""
drivenow=""
driveprevious=""
position=0
for item in $detectedlist;do
   drivenow=$(echo $item|cut -d _ -f 1|cut -c 6-8)
   if ["$drivenow" !="$driveprevious" ];then
      drivelist="$drivelist $position $drivenow"
      driveprevious=$drivenow
   fi
   position=$(expr $position + 1)
done

if [ -z"$drivelist" ];then

#  killall yad

   kill -9 `ps ax | grep -v grep | grep"yad --notification" | awk '{ print $1 }' | cut -d' ' -f 2`;

   if ["$FM" =="space" ] ; then

       /usr/local/bin/devmon_startup.sh

   elif ["$FM" =="rox" ] ; then
   
        /usr/local/bin/devmon_startup.sh
                
   else
   
      urxvt -hold -e echo"File manager by default running is not found." & sleep 3 && killall urxvt
      
   fi     
else

    yad --image="$ICON" --text="$TEXT"  --geometry="150x45+710-35" --no-buttons --skip-taskbar --on-top --undecorated --timeout="5"

fi

With all previous, I can unmount some USB device mounted with a click on usb icon on systray.
If own usb device is mounted only, the usb icon will disappear from systray. But if several usb devices are mounted, when remove it one device the usb icon continues to be displayed until all devices be remove it.