#!/usr/bin/perl ############################################################################# # smbmounts.pl: Setup Automounter to mount via SMB for federated experiments # $Id: smbmount.FreeBSD.pl,v 1.1 2008-05-18 00:09:31 faber Exp $ # $SHARE=shift || "USERS"; $ADDR=shift || `cat /usr/local/etc/emulab/bossnode`; $PUSER=shift || "jhickey"; $PNAME=shift || "emulab-ops"; $FSTYPE=shift || "smbfs"; $FSTAB="/etc/fstab"; $HOMEROOT="/users"; $PROJROOT="/proj"; $AMDROOT="/auto"; $AMDMAP="/etc/amd.users"; $PAMDMAP="/etc/amd.proj"; chomp $ADDR; $TMCC="/usr/local/etc/emulab/tmcc"; $UMOUNT="/sbin/umount"; $MOUNT="/sbin/mount"; $MKDIR="/bin/mkdir"; $CP="/bin/cp"; $KILLALL="/usr/bin/killall"; $AMD="/usr/sbin/amd"; my $share = 0; print "Killing amd.\n"; system("$KILLALL amd"); print "Unmounting all nfs and smb filesystems.\n"; system("$UMOUNT -A -f -t nfs,smbfs"); # or die("Failed to unmount NFS"); # Backup the fstab so we can run multiple times if (! -f "$FSTAB.bak") { system("$CP $FSTAB $FSTAB.bak") && die("Unable to backup $FSTAB"); } else { system("$CP $FSTAB.bak $FSTAB") && die("Unable to restore $FSTAB"); } open(TM, "/usr/local/federation/etc/userconf")or die("Failed to open userconf"); open(CONFIG, ">/etc/nsmb.conf") or die("Failed to open /etc/nsmb.conf"); open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB"); print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n"; print CONFIG "# SMB Configuration Generated by smbmount.pl\n\n"; print CONFIG "[$SHARE]\naddr=$ADDR\n\n"; while() { /ADDUSER/ && do { /LOGIN=(\S+)/ && do { $user = $1; }; /WPSWD=(\S+)/ && do { $pswd = $1; }; /UID=(\S+)/ && do { $uid = $1; }; /GID=(\S+)/ && do { $gid = $1; }; /HOMEDIR=(\S+)/ && do { $homedir = $1; }; $userlc = $user; # SMB demands upper case. $user =~ tr/a-z/A-Z/; my $pass = `smbutil crypt '$pswd'`; print CONFIG "[$SHARE:$user]\npassword=$pass\n"; if(! -d "$AMDROOT$homedir") { system("$MKDIR -p $AMDROOT$homedir") && die("Failed to make directory"); } print FSTAB "//$user\@$SHARE/$user\t"; print FSTAB "$homedir\t$FSTYPE\t"; print FSTAB "rw,-N,-f744,-d755,-u$uid,-g$gid\t0\t0\n"; # # If we are PUSER, the user assigned to mount the project directory, # then we add in the mount for that. The share is called proj-$PNAME # where PNAME is the name of the project at the mothership. We need # a second map for this since we will be mounting under /proj. if($user =~ m/$PUSER/i) { print FSTAB "//$user\@$SHARE/proj-$PNAME\t"; print FSTAB "/proj/$PNAME\t$FSTYPE\t"; print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n"; if(! -d "/proj/$PNAME") { system("$MKDIR -p /proj/$PNAME") && die("Failed to make directory"); } if ( $share) { print FSTAB "//$user\@$SHARE/share\t"; print FSTAB "/share\t$FSTYPE\t"; print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n"; if(! -d "/share") { system("$MKDIR -p /share") && die("Failed to make directory"); } } } } } close(CONFIG); close(FSTAB); print("Mounting the $FSTYPE versions of everything\n"); system("$MOUNT -a -t $FSTYPE");