Quick setup script "taxidermy.pl"

Soren Andersen soren@wonderstorm.com
Sat Jan 6 11:30:00 GMT 2001


Hello,

I spent quite a bit of the recent holiday season setting up the latest Cygwin 
on several systems (one Win98, one Win95, one WinNT) since it is much 
more fun to work with now, that so much great effort has resulted in fewer 
bugs. Playing (*laziness*).

I noticed that I wanted to have a fast way to just mount every logical drive 
on each system to it's appropriate POSIX mount point ('X:' to '/x')  and 
that, being the incredibly *impatient* hacker I am, I disliked the repetitious 
nature of that task when done manually.

Since I tend to have Perl installed on every system I can get my hands on 
for even a few moments (*hubris*), I cooked up a little Perl script to make 
this automatic. What it doesn't yet do is check for existing mounts and 
`umount' them before re-mounting anything (or skip them entirely). That's 
a future To-Do refinement. This is just a rough script but I thought maybe 
somebody would want to use it especially on a brand-new Cygwin 
installation.

One problem, however: the script uses a Perl module that isn't standard: 
Win32::API. It's on CPAN and at http://dada.perl.it/#api (on that site is a 
PPM package to make it an easy install to ActivePerl -- *laziness*). But 
when I ran the script from Cygwin bash the perl process faulted (memory 
access violation I think). So, *don't run it in bash* but rather from cmd.exe 
(or command.com if you must use that brain-damaged shell*). I think it 
likely that a Win32::API compiled for a Cygwin Perl might not have this 
problem, but I don't know quite enough of these matters for that to be 
more than a speculation at this time. As a matter of fact, I would love to 
know if anyone else gets Win32::API -- a really powerful module to access 
arbitrary Win32 API calls from system DLLs -- built from source using 
Cygwin or MinGW.

I have attached the script to this message, since it is relative short.

   Best,
       soren andersen

* When you aren't using Cygwin.

P.S. "Why `taxidermy.pl'?" Aww come ON! "mounting"(as in hunting 
trophies or monster trout) -> taxidermy, get it?

-------------- next part --------------
#!perl -w

# Perl program Copyright (c)2001 Soren Andersen
#     e-mail:    <libertador@flashmail.com>
#  Licensing: Perl Artistic License.
#  L/M 1/6/01 4:09 AM
#  requires Cygwin 1.1 or later, maybe -- has not been
#  tested on earlier Cygwin versions. `mount' and `cygpath'
#  must be in your PATH or fully qualified by hand-editing
#  this script.

use Win32::API;
use Getopt::Std;
use strict;

use vars qw[ $opt_n $opt_f $opt_t $srt ];
sub DrivesInUse;

#  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Options:
#      -n		dry-run only
#      -f		mount floppy drives too
#      -t		just see existing mount points and exit

 getopts( 'nft' );   $srt = 0;

#  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 if ($opt_t)   {
	 my $rcd = system("mount");
	 exit 0;
 }
my $floppies = ($opt_f)? '0' : '[a-b]';
my $cygprfx  = join q[], grep( /\/[a-z]+/i,
         `mount --show-cygdrive-prefixes` );
chomp $cygprfx;
$cygprfx =~s@^(/[a-z]+).+@$1@;
my $cygdrive = `cygpath -paw $cygprfx`;
chomp $cygdrive;
( $cygdrive =~s@^([A-Z]) \: .*@$1@xi ) or die qq[Careful, need good `cygdrive'.\n];

 for (DrivesInUse()) {
  next if /(?:$cygdrive | $floppies)/xi;
  printf(qq[  %1.3s:  mounting to %2.4s\n], $_, q[/]. lc);
 ( $srt = system( "mount -b -s -f", $_ .":","/". lc ) ) unless $opt_n;
  warn qq[\n Trouble making the mounted drive with $_ - ] .
  qq[ret code not zero: $srt\n $!] if $srt;
 }


 # from "Win32::DriveInfo.pm ver 0.03" by Mike Blazer
#===========================
sub DrivesInUse   {
#===========================
no strict 'subs';
   my (@dr, $i);
   my $h = new Win32::API("kernel32", "GetLogicalDrives", [], N);
   return undef unless $h =~/Win32::API/i;
   my $bitmask = $h->Call();
    for $i(0..25) {
       push (@dr, (A..Z)[$i]) if $bitmask & 2**$i;
    }
   return @dr;
}


More information about the Cygwin mailing list