This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Scriptable Mount Points


Hey everyone, since I and a few of my friends have set up mount points
in Cygwin for some the directories that we commonly used, I whipped up
a bunch of scripts to take care that automatically.

First of all, you need to create a ".mount" file in your home
directory.  Trust me, its really easy, in fact I made it up.  The
syntax is... [Windows Path:POSIX path] but without the []'s and only
one per line.  Now, in the windows path, make sure to escape that colon
after the drive letter and the slash after that.  For example, use
"c\:\\" instead of "c:\"  Also, that POSIX path is the location in the
file system that you want the windows directory mounted to.  And, yes,
there can be spaces in the Windows path.
Here's my file... (Cygwin on Win95)
D\:\\Download:/home/download
D\:\\My Documents\\Class:/home/class

Second, in order for the mounted directories to show up in ls, we need
to create a dummy directory, and mount over it.  Really easy.  So, in
your ~/.bash_profile file, add the following:

setup_mount_point() {
    echo "$1 -> $2"
    if [ ! -d "$2" ]
    then
        mkdir -p "$2"
    fi
    mount -f -b -u "$1" "$2"
}
while IFS=: read windows posix
do
    setup_mount_point "$windows" "$posix"
done <~/.mount

And lastly, in order to clean up that mess when we exit, add the
following to your ~/.bash_logout file.

cleanup_mount_directories() {
    umount -u "$1"
    if [ -d "$1" ]
    then
        rmdir "$1"
    fi
}
while IFS=: read windows posix
do
    echo "Cleaning up $posix"
    cleanup_mount_directories $posix
done <~/.mount

And, restart your cygwin session, and this will all take place on log
in and log out for interactive Bash sessions only.
Keep in mind, that while Cygwin is running, there will be empty dummy
directories created in your home directory.  You can delete these
before you logout if you want, but then they won't show up in an ls
listing.
I hope this is interesting for at least one other person, any comments
or questions can be sent my way.
Doug Jenkinson

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]