Commit b9a6f6fb authored by Russ Fish's avatar Russ Fish

Retire the S4U NFS code. Use the variable for the mkgroup cmd.

parent 76ad3c41
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# Emulab NFS mount command, called by rc.mounts .
#
# Args are the remote and local mount points, for example:
# emount fs.emulab.net:/q/proj/testbed /proj/testbed
#
# One arg is just the username, with the rest defaulted in for convenience.
# emount russ
# is equivalent to:
# emount fs.emulab.net:/users/russ /users/russ
#
# With no args, reports the current mounts with "net use".
#
# Since this is Windows, mounts go through drive letters, like this:
# S: \\fs.emulab.net\share # Share
# P: \\fs.emulab.net\q\proj\testbed # Project
# Q: \\fs.emulab.net\groups\testbed\TG1 # Group
# H: \\fs.emulab.net\users\fish # Creator
# I: \\fs.emulab.net\users\mike # Swapper
#
# Creator/swapper information comes from tmcc via TMCREATOR()/TMSWAPPER() files.
# Any other user mounts require specifying the drive letter with the -d option.
#
# The Services For Unix (SFU 3.5) NFS client commands are used underneath,
# and CygWin symlinks are made to point to the /cygdrive/driveletter mount,
# completing the Unix-like illusion.
sub usage()
{
print "Usage: emount [-v] [-d driveletter:] remotehost:path localpath\n";
print " or: emount [-v] [-d driveletter:] username\n";
print " or: emount\n";
exit(1);
}
my $optlist = "vd:";
my $verbose = 0;
my $driveletter = "";
my $remote = "";
my $local = "";
my $username = "";
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
#
# Turn off line buffering on output
#
$| = 1;
#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself.
#
use libsetup;
use liblocsetup;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the positional arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"v"})) {
$verbose = 1;
}
if (defined($options{"d"})) {
$driveletter = $options{"d"};
}
if (@ARGV == 0 ) {
system("$NET use");
exit(0);
}
elsif (@ARGV == 1) {
$username = $ARGV[0];
$local = "/users/$username";
$remote = "fs.emulab.net:$local";
}
elsif (@ARGV == 2) {
$remote = $ARGV[0];
$local = $ARGV[1];
}
else {
usage();
}
my $cmd;
# Infer the drive letter from what's being mounted.
my($project, $group, $user);
$driveletter = "S:"
if (!$driveletter && $remote =~ m|:/share$|);
$driveletter = "P:"
if (!$driveletter && (($project) = ($remote =~ m|:/q/proj/([-[:alnum:]]+)$|)) );
$driveletter = "Q:"
if (!$driveletter && (($project, $group) =
($remote =~ m|:/q/proj/([-[:alnum:]]+)/([-[:alnum:]]+)$|)) );
if (!$driveletter && (($user) = ($remote =~ m|:/users/([-[:alnum:]]+)|))) {
my $tmcreator = TMCREATOR();
my $tmswapper = TMSWAPPER();
my $creator = `cat $tmcreator`;
my $swapper = `cat $tmswapper`;
$creator =~ s/\n//;
$swapper =~ s/\n//;
##print "user '$user', creator '$creator', swapper '$swapper'\n";
$driveletter = "H:"
if ($user eq $creator);
$driveletter = "I:"
if (!$driveletter && $user eq $swapper);
}
print "Using drive letter $driveletter\n"
if ($verbose && $driveletter);
if (!$driveletter) {
print STDERR "emount: Must specify a drive letter.\n";
exit(1);
}
# Make sure that mount persistence is off.
os_noisycmd("$NET use /persistent:no", 0);
# Mount onto a drive letter using the Services For Unix NFS client.
print "Mounting remote directory '$remote' on drive letter '$driveletter'.\n"
if ($verbose);
$cmd = "$SFCMOUNT $remote $driveletter";
if (os_noisycmd($cmd, $verbose) != 0) {
print STDERR "emount: Failed SFU mount, $cmd.\n";
exit(1);
}
# Make the CygWin symlink from the local path to the driveletter automount point.
my $localdir = $local;
$localdir =~ s|(.*)/.*|$1|;
my $cygdrive = "/cygdrive/" . lc(substr($driveletter, 0, 1));
if (length($localdir) && ! -e $localdir) {
print "Making CygWin '$localdir' directory to contain symlinks.\n"
if ($verbose);
if (! os_mkdir($localdir, "0777")) { # Writable so anybody can make symlinks.
print STDERR "emount: Failed CygWin mkdir, $cmd.\n";
exit(1);
}
}
if (-e $local) {
print "Removing previous CygWin symlink '$local'.\n"
if ($verbose);
$cmd = "$CHOWN `id -un` $local";
if (system($cmd) != 0) {
print STDERR "emount: Failed to take ownership of symlink, $cmd.\n";
}
$cmd = "$RM -f $local";
if (system($cmd) != 0) {
print STDERR "emount: Failed to remove previous CygWin symlink, $cmd.\n";
exit(1);
}
}
print "Making CygWin symlink '$local' to '$cygdrive'.\n"
if ($verbose);
$cmd = "$LN -f -s $cygdrive $local";
if (system($cmd) != 0) {
print STDERR "emount: Failed CygWin symlink, $cmd.\n";
exit(1);
}
exit(0);
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# Emulab NFS unmount command, called by rc.mounts . See emount for more info.
#
# Arg is the local mount point or user name, for example:
# eumount /users/russ
# or:
# eumount russ
#
# The Services For Unix (SFU 3.5) NFS client commands are used underneath, and the
# CygWin symlink pointing to the /cygdrive/driveletter mount are cleaned up.
sub usage()
{
print "Usage: eumount [-v] /local/path\n";
print " or: eumount [-v] username\n";
exit(1);
}
my $optlist = "v";
my $verbose = 0;
my $local = "";
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
#
# Turn off line buffering on output
#
$| = 1;
#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself.
#
use libsetup;
use liblocsetup;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the positional arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"v"})) {
$verbose = 1;
}
if (@ARGV == 1) {
$local = $ARGV[0];
if ($local !~ m|/|) {
$local = "/users/$local";
}
}
else {
usage();
}
my(%curmounts, $cmd);
if (os_getnfsmountpoints(\%curmounts) < 0) {
fatal("Could not get current NFS mounts!");
}
if (!defined($curmounts{$local})) {
print STDERR "eumount: $local is not mounted.\n";
exit(1);
}
else {
my $rpath = $curmounts{$local}[0];
my $driveletter = $curmounts{$local}[1];
# Unmount from a drive letter using the Services For Unix NFS client.
print "Unmounting remote '$rpath' from drive letter '$driveletter'.\n"
if ($verbose);
$cmd = "$SFCUMOUNT $driveletter";
if (os_noisycmd($cmd, $verbose) != 0) {
print STDERR "eumount: Failed SFU umount, $cmd.\n";
exit(1);
}
# Kill the CygWin symlink from the local path to the driveletter automount point.
print "Removing CygWin symlink '$local'.\n"
if ($verbose);
$cmd = "$RM $local";
if (system($cmd) != 0) {
print STDERR "emount: Failed to remove CygWin symlink, $cmd.\n";
exit(1);
}
}
exit(0);
......@@ -60,19 +60,19 @@ $MOUNT = "/bin/mount";
$UMOUNT = "/bin/umount";
$EGREP = "/bin/egrep -q";
# Emulab wrappers for Windows.
# Cygwin.
$MKPASSWD = "/bin/mkpasswd";
$MKGROUP = "/bin/mkgroup";
$AWK = "/bin/gawk";
$BASH = "/bin/bash";
# Windows under Cygwin.
$NTS = "/cygdrive/c/WINDOWS/system32";
$NET = "$NTS/net";
$NETSH = "$NTS/netsh";
$NTE = "$NTS/drivers/etc";
$HOSTSFILE = "$NTE/hosts";
$BASH = "/bin/bash";
#
# These are not exported
#
......@@ -198,7 +198,7 @@ sub os_accounts_sync()
return -1;
}
$cmd = "mkgroup -l | $AWK '";
$cmd = "$MKGROUP -l | $AWK '";
# Make a duplicate group line that is a wheel alias for Administrators.
$cmd .= '/^Administrators:/{print "wheel" substr($0, index($0,":"))} {print}';
$cmd .= "' > /etc/group";
......@@ -618,73 +618,6 @@ sub os_mountlocal($)
return $local;
}
sub os_getnfsmounts($)
{
my ($rptr) = @_;
my %mounted = ();
#
# Grab the output of the mount command and parse. ("net use" on Windows.)
#
if (! open(MOUNT, "$NET use|")) {
print "os_getnfsmounts: Cannot run net use command\n";
return -1;
}
while (<MOUNT>) {
# We get lines like:
# P: \\fs.emulab.net\q\proj\testbed NFS Network
# When the remote string is too long, "NFS Network" is on the next line.
if ($_ =~ m|^ +(\w:) +([-\w\.\\]+)|) {
# Bash the remote UNC path into a NFS path like fs:/q/proj/testbed .
my $driveletter = $1;
my $rpath = $2;
$rpath =~ s|^\\\\([-\w\.]+)|$1:|; # \\host -> host:
$rpath =~ s|\\|/|g; # Backslashes to forward.
# Key is the remote NFS path, value is the CygWin local path.
$mounted{$rpath} = os_mountlocal($rpath);
}
}
close(MOUNT);
%$rptr = %mounted;
return 0;
}
sub os_getnfsmountpoints($)
{
my ($rptr) = @_;
my %mounted = ();
#
# Grab the output of the mount command and parse. ("net use" on Windows.)
#
if (! open(MOUNT, "$NET use|")) {
print "os_getnfsmounts: Cannot run net use command\n";
return -1;
}
while (<MOUNT>) {
# We get lines like:
# P: \\fs.emulab.net\q\proj\testbed NFS Network
# When the remote string is too long, "NFS Network" is on the next line.
##print;
if ($_ =~ m|^ +(\w:) +([-\w\.\\]+)|) {
# Bash the remote UNC path into a NFS path like fs:/q/proj/testbed .
my $driveletter = $1;
my $rpath = $2;
##print "driveletter '$driveletter', rpath '$rpath'\n";
$rpath =~ s|^\\\\([-\w\.]+)|$1:|; # \\host -> host:
$rpath =~ s|\\|/|g; # Backslashes to forward.
##print "driveletter '$driveletter', rpath '$rpath'\n";
# Key is CygWin local path, value is drive letter and remote NFS path.
my $local = os_mountlocal($rpath);
##print "local '$local'\n";
$mounted{$local} = [$rpath, $driveletter];
}
}
close(MOUNT);
%$rptr = %mounted;
return 0;
}
# Execute a noisy bash command, throwing away the output unless we ask for it.
sub os_noisycmd($$)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment