Hi, Justin
Could you please test this new "supermount" script? (Save the /etc/fstab
first, please...)
cu
Denis
On Thu, 30 Mar 2000, irotsoma wrote:
:~>I have an HP CDWriter+ 8100 and I can't seem to get it to work with the
:~>supermount. I can unmount and mount it manually using /dev/scd0 and it
:~>works but then I have to remount it every time I put in a new CD like in old
:~>Linux. I have Mandrake 7.0. Is there a way that I can get the drive to
:~>work with supermount so that I don't have to remount it manually everytime.
:~>If not, how can I make a script, and an icon on my desktop to run it, that
:~>umounts and mounts the drive.
--
-----------------------------------------------------
Dr. Denis Havlik <http://www.ap.univie.ac.at/users/havlik>
Mandrakesoft ||| e-mail: [EMAIL PROTECTED]
Quality Assurance (@ @) (private: [EMAIL PROTECTED])
-------------------oOO--(_)--OOo---------------------
#!/usr/bin/perl
# (c) MandrakeSoft, Chmouel Boudjnah <[EMAIL PROTECTED]>
# See http://www.gnu.org for license.
## Enable or disable supermount.
# $Id: supermount,v 1.5 2000/04/05 19:38:50 chmouel Exp $
my $file = '/etc/fstab';
my $ofile;
#"bad" or "nessesary" options for "normal" and "supermount" entry
# "bad" options can be regexp.
my @normal_bad = qw ( fs=\S+ dev=\S+);
my @super_bad = qw (sync user);
my @normal_must = qw (user noauto nodev nosuid);
my @super_must = qw (nodev nosuid);
my $fs_ok = '(auto|vfat|iso9660)';
my $dev_ok = '(fd|floppy|zip|cdrom)\d*';
my ($enable, $disable, $infile);
while ($ARGV[0] =~ /^--/ || $ARGV[0] =~ /^-/) {
$_ = shift;
if (/^--file=([^ \t]+)/ || /^-f=([^ \t]+)/) {
$file = $1;
} elsif (/^--infile/ || /^-i/) {
$infile++;
} elsif (/^--help/ || /^-h/ || /^-\?/) {
usage(0);
} else {
print STDERR "Unrecognized switch: $_\n";
usage(1);
}
}
if ($ARGV[0] =~ /enable/) { $enable++; }
elsif ( $ARGV[0] =~ /disable/ ) { $disable++; }
else { usage(1); }
open FH, $file or die "Can't open $file\n";
if ($infile) {
$ofile = `mktemp /tmp/fstab.XXXXXX` || die "Can't create temporary file\n"; chomp
$ofile;
open OU, ">$ofile" or die "Can't write to $ofile\n"; select OU;
}
while (<FH>) {
my ($dev, $point, $fs, $opt, $d1, $d2) = split;
my @opt = split (',', $opt);
if ( $disable && ($fs eq "supermount") ) {
my @must;
map { m/^fs=(\S+)/ && ($fs = $1);
m/dev=(\S+)/ && ($dev= $1); } @opt;
&clean_options(\@opt,\@normal_must,\@normal_bad);
if ($dev =~ /^\/dev\/(fd[0-1]|floppy$)/ ) {
@must = qw (sync unhide);
&clean_options(\@opt,\@must, []);
} elsif (($device =~ /^\/dev\/cdrom\d*$/) || ($fs eq "iso9660" )) {
@must = qw (ro exec);
&clean_options(\@opt,\@must, []);
}
$opt = join (',' , @opt);
print "$dev\t$point\t$fs $opt\t$d1 $d2\n";
next;
} elsif ( $enable && (
$fs eq "iso9660" ||
( ( $fs =~ m/$fs_ok/ ) &&
( ($dev =~ /^\/dev\/($dev_ok)$/)
|| ($opt =~ m/(^|.*,)user.*/ )
)
)
)
) {
&clean_options(\@opt,\@super_must, \@super_bad);
$opt = join (',' , @opt);
print "$point\t$point\tsupermount\tfs=$fs,dev=$dev,$opt 0 0\n";
next;
}
print;
}
close FH;
if ($infile) { close OU; system("/bin/mv", $ofile, $file);chmod 0644, $file; }
sub clean_options {
my ($ap_opt, $ap_must, $ap_bad) = @_;
my $o; my %union; my @opt = @$ap_bad;
foreach $o (@$ap_bad) {@$ap_opt = grep ( !/^$o$/ ,@$ap_opt);}
foreach my $o (@$ap_opt, @$ap_must) { $union{$o}++;}
@$ap_opt=keys %union;
}
sub usage {
my $e = shift @_;
$0 =~ s|.*/||;
print { $e ? STDERR : STDOUT } << "EOF";
Usage: $0 [OPTION]... <disable | enable>
Enable or disable supermount in fstab.
-f=FILE, --file=FILE: Specify an alternarte fstab file (default: /etc/fstab).
-i, --infile: Modify directly in the file.
EOF
exit($e);
}
__END__
CHANGELOG:
Thu Apr 13 2000 Denis Havlik <[EMAIL PROTECTED]>
- moved definitions of "good" and "bad" fs-options, "allowed fs-s" and "good devices"
to top of the script for easier maintainance.
- added &clean_options(\@opt,\@must, \@bad) function, which parses the @opt
array, adds the "must" options and removes the "bad" ones, and re-wrote the
while (<FH>) {} loop to take advantage of this functions.
- simplified the fstab parsing (split instead of regexp-s)
- changed the rules used to decide which mount points are going to be
supermounted to: ($fs eq "iso9660") || (( $fs =~ m/$fs_ok/ ) &&
(($dev =~ /^\/dev\/($dev_ok)$/) || ($opt =~ m/(^|.*,)user.*/ )) )
TODO:
add --mountpoint option to get targeted supermount-enabling/disabling on
the single moint point.