DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 17th February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Cool devd based AUTOMOUNTER

Hi,

I have finally made some effort on writing flexible yet very simple automounter for FreeBSD desktop.

Feel free to submit me BUG reports to this thread

It currently supports these file formats:
-- NTFS (rw) requires sysutils/fusefs-ntfs
-- FAT/FAT32
-- exFAT requires sysutils/fusefs-exfat
-- EXT2
-- EXT3
-- EXT4 requires sysutils/fusefs-ext4fuse
-- UFS (DOH!)

It keeps state of the mounted devices at /var/run/automount.state and logs all activities to /var/log/automount.log file.

The place for the script is at /usr/local/sbin/automount.sh executable.

The only additional configuration it requires is /usr/local/etc/devd/automount_devd.conf file.

I have created repository @ GITHUB here:
https://github.com/vermaden/automount
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd

Last edited by vermaden; 20th February 2012 at 01:28 PM.
Reply With Quote
  #2   (View Single Post)  
Old 18th February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Added a check if ntfs-3g is available, if not then mount_ntfs is used instead.
Added deleting of empty directories at ${MNTPREFIX}.
Added ${MNTPREFIX} to be set to /mnt or /media according to preference
Adddd additional checks for NTFS filesystem with label "FAT".
Adddd additional checks for FAT filesystem with label "NTFS".
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #3   (View Single Post)  
Old 19th February 2012
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,080
Thanked 198 Times in 156 Posts
Default

Quote:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
ENCODING="pl_PL.ISO8859-2"
CODEPAGE="cp852"
I'm sorry, but this is just wrong. Try to use the locale(1) utility if available, and if it isn't try checking the LC_* manually. If all else fails, use a sane default (pl_PL.ISO8859-2 is not what I would consider a sane default).
And overriding the user's PATH ... ? Have you been drinking?

And what's with the underscoritus It almost looks like Python
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #4   (View Single Post)  
Old 19th February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Quote:
Originally Posted by Carpetsmoker View Post
I'm sorry, but this is just wrong. lTry to use the locale(1) utility if available, and if it isn't try checking the LC_* manually. If all else fails, use a sane default (pl_PL.ISO8859-2 is not what I would consider a sane default).
But that would not tell me the codepage, even if I would 'grab' the encoding from LC_ALL or LANG or whatever, I would have to keep a table of mappings like that:
pl_PL.ISO8859-2 cp852
... and I do not want to write it myself, besides, You set these options ONCE, then use it all the time, I may even put the 'settings' into the *.conf file, good idea I think.

Also these values are there because I did not finished working on this daemon yet, these are just mine settings.

There is also other 'issue', the 'mount' encoding and my user encoding are different

Quote:
Originally Posted by Carpetsmoker View Post
And overriding the user's PATH ... ? Have you been drinking?
The script would be always run by root (triggered by devd), its like You would blame me for the same PATH settings for cron daemon at /etc/crontab.

Quote:
Originally Posted by Carpetsmoker View Post
And what's with the underscoritus It almost looks like Python
It makes code cleaner, let me explain how I see it, commands/built-ins/keywords are lowercase words, all variables, no matter global/local/temporary are UPPERCASE, functions start with two underscores (two instead of one for better readability), like __lower_case_name.

Typing scripts that way the moment when I look at something I already know what it does and what does not, at least it helps me a lot to write/reuse/modify scripts faster and do not waste time on figuring, keeps WTFs/min at rather low value
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #5   (View Single Post)  
Old 20th February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

CHANGELOG:

Added check if ntfsfix from sysutils/ntfsprogs is available, if Yes then try to fix the NTFS filesystem before mouting it.

Added GPL3 License ... just joking ... added FreeBSD License to the file.

Added 'noatime' as a default mount option when possible.

Added TIMEOUT so when an 'orphan' STATE file lock remains, it will be deleted after a TIMEOUT.

Added /usr/local/etc/devd/automount_devd.conf file instead of messing with the base system config at /etc/devd.conf.

Added config file to be used from /usr/local/etc/automount.conf file, possible options are (these are defaults):

MNTPREFIX="/media"
LOG="/var/log/automount.log"
STATE="/var/run/automount.state"
ENCODING="en_US.ISO8859-1"
CODEPAGE="cp437"
DATEFMT="%Y-%m-%d %H:%M:%S"
USERUMOUNT="NO"


Mine config currently has only these:

ENCODING="pl_PL.ISO8859-2"
CODEPAGE="cp852"
USERUMOUNT="YES"


The USERMOUNT otions if set to YES (default to NO) will 'chmod +s /sbin/umount', so You can click the ^ button on the devices list in NAUTILUS.

These newly mounted devices appear on NAUTILUS sidebar (only with /media prefix).

But THUNAR and PCMANFM does not do that, You know any other FMs that display mounted thumb drives/devices?

EXAMPLE:
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #6   (View Single Post)  
Old 20th February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Hi,

I removed the state_lock and stat_unlock mechanisms as they appeared to be not needed, I have shufled with 3 drives all the time and the 'integrity' has not been lost, at it was a lot faster, because the lock always had to wait for the 'slowest' drive (in term of initializing the device, like USB hard drive).

I simplified the 'attach' section a lot, now each filesystem contains only check/fsck (if possible), mount and log info.

I also simplified and improved the 'detach' section a little.

I have added an option to automatically launch the set-up in config file manager (Yes, like in Windows ;p).

These are options that I currently successfully use for NAUTILUS file manager, You need to set-up all three of them to make it work.

Code:
POPUP=YES
FM="nautilus --browser --no-desktop"
USER=vermaden
My whole config looks like that now:

Code:
USERUMOUNT=YES
POPUP=YES
FM="nautilus --browser --no-desktop"
USER=vermaden
ENCODING=pl_PL.ISO8859-2
CODEPAGE=cp852
All latest updates are available at GITHUB:
https://github.com/vermaden/automount

Regards,
vermaden
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #7   (View Single Post)  
Old 21st February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Hi,

I have created a PORT at last, its in the 'port' directory in the usual place:

https://github.com/vermaden/automount/

Its my first PORT so feel free to bash me about my mistakes

After latest 'commits' I think that its ready for day-to-day use.

To make 'full advantage' of *automount* install these ports:

sysutils/ntfsprogs
sysutils/fusefs-ntfs
sysutils/fusefs-ext4fuse
sysutils/fusefs-exfat


I will try to add these ports as OPTIONS in the Makefile later.

I will have to think about creating a man page through ...

Feel free to submit Your propositions about next changes/development,
because I think that I already created everything 'I' needed.

Regards,
vermaden
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #8   (View Single Post)  
Old 21st February 2012
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,080
Thanked 198 Times in 156 Posts
Default

Quote:
Originally Posted by vermaden View Post
But that would not tell me the codepage, even if I would 'grab' the encoding from LC_ALL or LANG or whatever, I would have to keep a table of mappings like that:
pl_PL.ISO8859-2 cp852
Well, having the user specify *one* variable is better than having the user to specify *two* variables. Besides, the default will probably work in >90% if the cases.

It's easy to use a config file, just make it a shell script and source (.) it

Quote:
The script would be always run by root (triggered by devd), its like You would blame me for the same PATH settings for cron daemon at /etc/crontab.
Your script will break if I installed stuff I need/want in /usr/pkg/bin/ or ~/bin/ or .... ?

It's not your script's job to fix a potentially broken PATH ...

At the very least *append* it, instead of overwriting it. And even that *may* cause problems in some exotic setups ...

Quote:
It makes code cleaner, let me explain how I see it, commands/built-ins/keywords are lowercase words, all variables, no matter global/local/temporary are UPPERCASE, functions start with two underscores (two instead of one for better readability), like __lower_case_name.

Typing scripts that way the moment when I look at something I already know what it does and what does not, at least it helps me a lot to write/reuse/modify scripts faster and do not waste time on figuring, keeps WTFs/min at rather low value
I see. It still looks strange You should pick up some other scripting language (Ruby/Perl/Python/...).
I find myself avoiding shell scripting at all costs these days ...
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #9   (View Single Post)  
Old 21st February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Quote:
Originally Posted by Carpetsmoker View Post
It's easy to use a config file, just make it a shell script and source (.)
It already does, check the latest version:

Code:
[ -f /usr/local/etc/automount.conf ] && . /usr/local/etc/automount.conf
... and an exampe configuration file:
https://github.com/vermaden/automoun...automount.conf

Quote:
Originally Posted by Carpetsmoker View Post
Your script will break if I installed stuff I need/want in /usr/pkg/bin/ or ~/bin/ or .... ?
Dunno what script names (ntfs-3g for example) You have in Your PATH ;p

Quote:
Originally Posted by Carpetsmoker View Post
It's not your script's job to fix a potentially broken PATH ...
Its my job to SET needed PATH for the script job.

Quote:
Originally Posted by Carpetsmoker View Post
At the very least *append* it, instead of overwriting it.
Ok, You convinced me.

Quote:
Originally Posted by Carpetsmoker View Post
I see. It still looks strange You should pick up some other scripting language (Ruby/Perl/Python/...).
None of them is in the base, and I wanted to use something from the base system.

Quote:
Originally Posted by Carpetsmoker View Post
I find myself avoiding shell scripting at all costs these days ...
I use sh(1) as long as its quite simple, then I try at python(1)
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Old 21st February 2012
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,080
Thanked 198 Times in 156 Posts
Default

Quote:
Dunno what script names (ntfs-3g for example) You have in Your PATH ;p
I used to set my PREFIX to /usr/pkg/, I did this after some upgrade (5 to 6 IIRC) where I wanted to recompile all ports but have the original software remain just in case.
After that, the /usr/pkg/ habit kind of stuck for many years (But I've reverted back to the mainstream /usr/local since).

In addition it's also useful if you want to install multiple versions of the same problem alongside eachother...

Or if you're on some Read-only FS, you can mount a USB drive with additional software in /mnt/ and set my PATH to /mnt/bin/ ... I did this with jggimi's liveCD a couple of times.

... And there are probably many more scenarios ...

Assuming /usr/local/ is a bad habit, and will break sooner or later.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Old 21st February 2012
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,080
Thanked 198 Times in 156 Posts
Default

Regarding your port:

You can use NOBUILD instead of specifying an empty do-build target.

And running a shell command (/etc/rc.d/devd restart) is the wrong place, this doesn't work when you install the package for example.
You should put this in a pkg-install script.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Old 21st February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Quote:
Originally Posted by Carpetsmoker View Post
Regarding your port:

You can use NOBUILD instead of specifying an empty do-build target.

And running a shell command (/etc/rc.d/devd restart) is the wrong place, this doesn't work when you install the package for example.
You should put this in a pkg-install script.
Thanks You, I will add these changes as well.
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Old 27th February 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Added help page, removed some bugs and added some new features.

Code:
% automount --help
AUTOMOUNT is a devd(8) based automounter for FreeBSD.

It supports following file systems:
UFS/FAT/exFAT/NTFS/EXT2/EXT3/EXT4

It needs these ports to mount NTFS/exFAT/EXT4 respectively:
 o sysutils/fusefs-ntfs
 o sysutils/fusefs-exfat
 o sysutils/fusefs-ext4fuse

By default it mounts/unmounts all removable media but
it is possible to set some additional options at the
/usr/local/etc/automount.conf config file.

Below is a list of possible options with description.

MNTPREFIX (set to /media by default)
  With this options You can alter the default root
  for mounting the removable media, for example to
  the /mnt directory.

  example: MNTPREFIX="/media"

ENCODING (set to en_US.ISO8859-1 by default)
  Only used with FAT32 mounts, specifies which
  encoding to use at the mount.

  example: ENCODING="pl_PL.ISO8859-2"

CODEPAGE (set to cp437 by default)
  Only used with FAT32 mounts, specifies which
  code page to use at the mount.

  example: CODEPAGE="cp852"

USER (unset by default)
  If set to some username, the mount command will
  chown(1) the mount directory with the user and
  its primary user group. If used with FM option
  allows to launch the specified file manager after
  a successful mount.

  example: USER="vermaden"

FM (unset by default)
  If set to file manager command, the mount will
  launch the specified command after successful
  mount. Works only if USER parameter is also set.

  example: FM="nautilus --browser --no-desktop"

USERUMOUNT (set to NO by default)
  When set to YES it will 'chmod +s /sbin/umount'
  which would allow an USER to unmount the file
  system with their selected file manager.

  example: USERUMOUNT="YES"

ATIME (set to YES by default)
  When set to NO it will mount filesystems with
  noatime options when possible.

  example: ATIME="NO"

REMOVEDIRS (set to NO by default)
  When set to YES it will remove empty directories
  under the used  after device detach.

  example: REMOVEDIRS="YES"
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Old 4th March 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Hi,

after some 'fun' with MP3 players I have made some modifications and fixes.

Here is a list of whats changed:

Fixed bug about inproper exFAT detection, now mounts fine.
Fixed bug about creating mount dirs for all attached devices no matter if needed or not.
Revised 'detach' section, now removes only directory that is unmounted (if enabled of course).
Simplified FAT/NTFS sections, removed additional check as it break some MP3 players default filesystems automount.

The latest 1.3 version can be found here as usual:
https://github.com/vermaden/automount/

Regards,
vermaden
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Old 4th March 2012
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Already at 1.3.1 ...

Fixed the 'detach' section (s/PREFIX/MNTPREFIX/g).
Fixed removing directories of manually (properly) unmounted filesystems.
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Old 10th January 2013
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

The sysutils/automount in the latest 1.4.1 version just hit the ports (thanks Bryan).

Changelog since the 1.3.1 version:
Quote:
- Added extended 'already mounted' checking.
- Added logging of FSCK output to the /var/log/automount.log file.
- Added error logging of failed mounts with used mount(8) command.
- Added +s bit for /sbin/mount* when USERUMOUNT is set to YES.
- Properly display the already mounted directory with spaces.
- Wait shorter amount of time to mount device faster.
- Improved readability of the generated /var/log/automount.log file
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which software is most secure for web-based webhosting? steamrent General software and network 4 20th December 2011 02:46 PM
Installing AMD Automounter Kirfew OpenBSD General 2 6th November 2010 05:47 PM
Requirements-based BSD jboisvert FreeBSD General 2 20th October 2010 01:14 PM
A name for an embedded FreeBSD-based OS nimnod Off-Topic 15 16th March 2009 03:06 PM
FOSS web-based accounting? DraconianTimes Off-Topic 0 16th November 2008 02:20 PM


All times are GMT. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick