simple automount script

Everytime I want to mount my usb on fluxbox, I run:
Code:
sudo mount_msdosfs /dev/da0s1 /mnt/usb
I want to create a simple script that automatically run this command everytime da0s1 is detected on /dev
Any idea?
 
For my GF I wrote these scripts (Integrated in fvwm)

Check if media is mounted/unmounted
Code:
#!/bin/sh
# check if there is device mounted to ~/mnt

if [ "`mount | grep -e "$HOME/mnt"`" ]; then
	which gxmessage > /dev/null 2> /dev/null && gxmessage -name 'MEDIA' -title 'INFO: Media mounted' -center -bg '#9ADF9C' -buttons '_Ok:0' -default 'Ok' 'Media mounted'
else
	which gxmessage > /dev/null 2> /dev/null && gxmessage -name 'MEDIA' -title 'INFO: Media not mounted' -center -bg '#DF9A9C' -buttons '_Ok:.' -default 'Ok' 'Media not mounted'
fi

# vim: set ts=4 sw=4:

And this mounts/umounts media
Code:
#!/bin/sh

# mount/umount media to ~/mnt and start file manager
# arg1 commant to launch after mount

if [ "`mount | grep -e "$HOME/mnt"`" ]; then
	while [ 1 -eq 1 ]; do
		umount "$HOME/mnt" \
			&& gxmessage -name 'MEDIA' -title 'INFO: Media unmounted' -center -bg '#9ADF9C' -buttons '_Ok:0' -default 'Ok' 'It is now safe to remove media' && exit \
			|| gxmessage -name 'MEDIA' -title 'ERROR: Media still mounted' -center -bg '#DF9A9C' -buttons '_Cancel:0,_Retry:1' -default 'Retry' 'Failed to umount media!!!' && exit
	done
else
	while [ 1 -eq 1 ]; do
		{	   mount -t msdosfs /dev/da0   "$HOME/mnt" \
			|| mount -t msdosfs /dev/da0s1 "$HOME/mnt" \
			|| mount -t msdosfs /dev/da0p1 "$HOME/mnt" \
			|| mount -t cd9660  /dev/acd0  "$HOME/mnt" \
			|| mount -t udf     /dev/acd0  "$HOME/mnt" \
			|| mount -t ufs     /dev/da0   "$HOME/mnt"
		} && { [ "$1" ] && $1; exit; }
		which gxmessage > /dev/null 2> /dev/null || exit
		which gxmessage > /dev/null 2> /dev/null && gxmessage -name 'MEDIA' -title 'ERROR: Media mount failed' -center -bg '#DF9A9C' -buttons '_Cancel:0,_Retry:1' -default 'Retry' 'Failed to mount media!!!' && exit
	done

fi

# vim: set ts=4 sw=4:

You can setup your PC, to avoid using sudo (I think it was in Handbook and it was mentioned in few threads on forum)
 
I think is /etc/devfs.rules.
Code:
[localrules=5] mode 0660 group operator
add path 'da*' mode 0660 group operator
add path 'cuse' mode 0660 group operator
add path 'video0' mode 0660 group operator
For cuse & video0 work. I open my webcam without sudo anymore. But didn't work for da
 
I will read them and then I will run killasmurf86's script (doing some changes like the path of mountpoint) and I will post the results :D
 
Don't change mountpoint... user who want to mount FS without rising privileges must own mountpoint. That's why I mount under ~/mnt/
Maybe you're trying yo mount under /mnt/? That could explain your problem
 
You have right :D Mount of my usb on /home/emberdaemon run without sudo :)
If I do:
Code:
chown -R emberdaemon /mnt
is not solving the "problem" from the time that /mnt will own to me?
 
Ye... because / is not owned by emberdaemon

I guess, I formulated my sentence badly... you need to own mount-point and parent directory
 
From the first script change
Code:
if [ "`mount | grep -e "$HOME/mnt"`" ]; then
to
Code:
if [ "`mount | grep -e "$HOME/emberdaedmon/usb"`" ]; then
After I run:
Code:
sudo chown -R emberdaemon script
sudo chmod +x script
./script
Return none results :/
 
why $HOME/emberdaedmon/usb and not just $HOME/usb?
$HOME resolves to full path of homedir of current user
If your username is emberdaedmon, then $HOME=/home/emberdaedmon
 
on /dev/da0s1 script only checks msdosfs, because it's common that way :D

WHen I format my drives for UFS (For example) I make sure ufs is on entire device (newfs -U /dev/da0 for example)

So either adjust script, or format your drive, like I do....
Otherwise it should work
 
killasmurf86 said:
For my GF I wrote these scripts (Integrated in fvwm)

Check ZENITY mate, it gives a lot more possibilities in 'hiding' scripting under the GUI with very little work.
 
You should also add this:
Code:
[localrules=5]
add path 'msdosfs/*' mode 0660 group operator

So you can use [CMD=">"]mount -t msdosfs /dev/msdosfs/foo /media/bar[/CMD]
 
How to adjust my script? I have none idea about bash but seems to be the commands of console with some variables and I guess should be easy to learn it :D
 
Have you considered using amd(8)()?
It's mostly more flexible/extensible than the other methods discussed here, with the added bonus of automatically unmount'ing inactive drives.

To set up amd, create a suitable map in /etc/amd.removable

Code:
/defaults    opts:=intr,nosuid  
cd0          opts:=ro;type:=cdfs;dev:=/dev/cd0
cd1          opts:=ro;type:=cdfs;dev:=/dev/cd1
# usb devs with fatXX partitions are usually whole disk
da0          opts:=rw;type:=pcfs;dev:=/dev/da0
da1          opts:=rw;type:=pcfs;dev:=/dev/da1
# but sometimes just the first slice (extend as necessary)
da0s1        opts:=rw;type:=pcfs;dev:=/dev/da0s1
da1s1        opts:=rw;type:=pcfs;dev:=/dev/da1s1

create/edit /etc/amd.conf with this

Code:
[global]
auto_dir = /a
cache_duration = 60   
log_file = /var/log/amd
 
[/r]
map_type = file
map_name = amd.removable


edit /etc/rc.conf like this

Code:
amd_enable="YES" 
amd_flags="-F /etc/amd.removable"


Various devices can then be accessed like /r/da0/, etc, and automatically unmounted after 60 seconds of inactivity
 
Back
Top