| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | ############################################################################# |
|---|
| 4 | # smbmounts.pl: Setup Automounter to mount via SMB for federated experiments |
|---|
| 5 | # $Id: smbmount.FreeBSD.pl,v 1.1 2008-05-18 00:09:31 faber Exp $ |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | $SHARE=shift || "USERS"; |
|---|
| 9 | $ADDR=shift || `cat /usr/local/etc/emulab/bossnode`; |
|---|
| 10 | $PUSER=shift || "jhickey"; |
|---|
| 11 | $PNAME=shift || "emulab-ops"; |
|---|
| 12 | $FSTYPE=shift || "smbfs"; |
|---|
| 13 | $FSTAB="/etc/fstab"; |
|---|
| 14 | $HOMEROOT="/users"; |
|---|
| 15 | $PROJROOT="/proj"; |
|---|
| 16 | $AMDROOT="/auto"; |
|---|
| 17 | $AMDMAP="/etc/amd.users"; |
|---|
| 18 | $PAMDMAP="/etc/amd.proj"; |
|---|
| 19 | |
|---|
| 20 | chomp $ADDR; |
|---|
| 21 | |
|---|
| 22 | $TMCC="/usr/local/etc/emulab/tmcc"; |
|---|
| 23 | $UMOUNT="/sbin/umount"; |
|---|
| 24 | $MOUNT="/sbin/mount"; |
|---|
| 25 | $MKDIR="/bin/mkdir"; |
|---|
| 26 | $CP="/bin/cp"; |
|---|
| 27 | $KILLALL="/usr/bin/killall"; |
|---|
| 28 | $AMD="/usr/sbin/amd"; |
|---|
| 29 | |
|---|
| 30 | my $share = 0; |
|---|
| 31 | |
|---|
| 32 | print "Killing amd.\n"; |
|---|
| 33 | system("$KILLALL amd"); |
|---|
| 34 | |
|---|
| 35 | print "Unmounting all nfs and smb filesystems.\n"; |
|---|
| 36 | system("$UMOUNT -A -f -t nfs,smbfs"); # or die("Failed to unmount NFS"); |
|---|
| 37 | |
|---|
| 38 | # Backup the fstab so we can run multiple times |
|---|
| 39 | if (! -f "$FSTAB.bak") { |
|---|
| 40 | system("$CP $FSTAB $FSTAB.bak") && die("Unable to backup $FSTAB"); |
|---|
| 41 | } else { |
|---|
| 42 | system("$CP $FSTAB.bak $FSTAB") && die("Unable to restore $FSTAB"); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | open(TM, "/usr/local/federation/etc/userconf")or die("Failed to open userconf"); |
|---|
| 46 | open(CONFIG, ">/etc/nsmb.conf") or die("Failed to open /etc/nsmb.conf"); |
|---|
| 47 | open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB"); |
|---|
| 48 | |
|---|
| 49 | print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n"; |
|---|
| 50 | print CONFIG "# SMB Configuration Generated by smbmount.pl\n\n"; |
|---|
| 51 | print CONFIG "[$SHARE]\naddr=$ADDR\n\n"; |
|---|
| 52 | |
|---|
| 53 | while(<TM>) { |
|---|
| 54 | /ADDUSER/ && do { |
|---|
| 55 | /LOGIN=(\S+)/ && do { $user = $1; }; |
|---|
| 56 | /WPSWD=(\S+)/ && do { $pswd = $1; }; |
|---|
| 57 | /UID=(\S+)/ && do { $uid = $1; }; |
|---|
| 58 | /GID=(\S+)/ && do { $gid = $1; }; |
|---|
| 59 | /HOMEDIR=(\S+)/ && do { $homedir = $1; }; |
|---|
| 60 | |
|---|
| 61 | $userlc = $user; |
|---|
| 62 | # SMB demands upper case. |
|---|
| 63 | $user =~ tr/a-z/A-Z/; |
|---|
| 64 | my $pass = `smbutil crypt '$pswd'`; |
|---|
| 65 | |
|---|
| 66 | print CONFIG "[$SHARE:$user]\npassword=$pass\n"; |
|---|
| 67 | |
|---|
| 68 | if(! -d "$AMDROOT$homedir") { |
|---|
| 69 | system("$MKDIR -p $AMDROOT$homedir") && |
|---|
| 70 | die("Failed to make directory"); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | print FSTAB "//$user\@$SHARE/$user\t"; |
|---|
| 74 | print FSTAB "$homedir\t$FSTYPE\t"; |
|---|
| 75 | print FSTAB "rw,-N,-f744,-d755,-u$uid,-g$gid\t0\t0\n"; |
|---|
| 76 | |
|---|
| 77 | # |
|---|
| 78 | # If we are PUSER, the user assigned to mount the project directory, |
|---|
| 79 | # then we add in the mount for that. The share is called proj-$PNAME |
|---|
| 80 | # where PNAME is the name of the project at the mothership. We need |
|---|
| 81 | # a second map for this since we will be mounting under /proj. |
|---|
| 82 | |
|---|
| 83 | if($user =~ m/$PUSER/i) { |
|---|
| 84 | print FSTAB "//$user\@$SHARE/proj-$PNAME\t"; |
|---|
| 85 | print FSTAB "/proj/$PNAME\t$FSTYPE\t"; |
|---|
| 86 | print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n"; |
|---|
| 87 | |
|---|
| 88 | if(! -d "/proj/$PNAME") { |
|---|
| 89 | system("$MKDIR -p /proj/$PNAME") && |
|---|
| 90 | die("Failed to make directory"); |
|---|
| 91 | } |
|---|
| 92 | if ( $share) { |
|---|
| 93 | print FSTAB "//$user\@$SHARE/share\t"; |
|---|
| 94 | print FSTAB "/share\t$FSTYPE\t"; |
|---|
| 95 | print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n"; |
|---|
| 96 | |
|---|
| 97 | if(! -d "/share") { |
|---|
| 98 | system("$MKDIR -p /share") && |
|---|
| 99 | die("Failed to make directory"); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | close(CONFIG); |
|---|
| 107 | close(FSTAB); |
|---|
| 108 | print("Mounting the $FSTYPE versions of everything\n"); |
|---|
| 109 | system("$MOUNT -a -t $FSTYPE"); |
|---|