Changeset 45ed8ee
- Timestamp:
- Sep 26, 2007 7:50:14 PM (17 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- 30184e4
- Parents:
- 5f1cd41
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedkit/smbmount.pl
r5f1cd41 r45ed8ee 1 1 #!/usr/local/bin/perl 2 use IO::Handle;3 2 3 ############################################################################# 4 # smbmounts.pl: Setup Automounter to mount via SMB for federated experiments 5 # $Id: smbmount.pl,v 1.3 2007-09-27 02:50:14 jhickey Exp $ 6 # 7 8 $ADDR="users.isi.deterlab.net"; 4 9 $TMCC="/usr/local/etc/emulab/tmcc"; 5 $SHARE=shift || "USERS"; 6 $PUSER=shift || "jhickey"; 7 $ADDR=shift || `cat /usr/local/etc/emulab/bossnode`; 10 $SHARE="USERS"; 11 $FSTAB="/etc/fstab"; 12 $HOMEROOT="/users"; 13 $AMDROOT="/auto"; 14 $AMDMAP="/etc/amd.users"; 8 15 9 chomp $ADDR; 10 print $ADDR; 16 $UMOUNT="/sbin/umount"; 17 $MOUNT="/sbin/mount"; 18 $MKDIR="/bin/mkdir"; 19 $CP="/bin/cp"; 20 $KILLALL="/usr/bin/killall"; 21 $AMD="/usr/sbin/amd"; 11 22 12 # 13 # Do SMB Mounts 14 # 15 #system("umount -A -f -t nfs,smbfs"); # or die("Failed to unmount NFS"); 23 print "Killing amd.\n"; 24 system("$KILLALL amd"); 16 25 17 open(TM, "$TMCC -s $ADDR accounts windows |") or die("Failed to execute TMCC"); 26 print "Unmounting all nfs and smb filesystems.\n"; 27 system("$UMOUNT -A -f -t nfs,smbfs"); # or die("Failed to unmount NFS"); 18 28 19 # create a smb config to set autoflush for smb config 29 # Backup the fstab so we can run multiple times 30 if (! -f "$FSTAB.bak") { 31 system("$CP $FSTAB $FSTAB.bak") && die("Unable to backup $FSTAB"); 32 } else { 33 system("$CP $FSTAB.bak $FSTAB") && die("Unable to restore $FSTAB"); 34 } 35 36 open(TM, "$TMCC accounts windows |") or die("Failed to execute TMCC"); 20 37 open(CONFIG, ">/etc/nsmb.conf") or die("Failed to open /etc/nsmb.conf"); 21 CONFIG->autoflush(1); 38 open(MAP, ">$AMDMAP") or die("Failed to open /etc/amd.users"); 39 open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB"); 22 40 41 print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n"; 42 print MAP "# AMD Configuration Generated by smbmount.pl\n"; 43 print CONFIG "# SMB Configuration Generated by smbmount.pl\n\n"; 23 44 print CONFIG "[$SHARE]\naddr=$ADDR\n\n"; 24 45 … … 31 52 $homedir = $5; 32 53 33 $user =~ tr/a-z/A-Z/; 34 my $pass = `smbutil crypt '$pswd'`; 54 $userlc = $user; 55 # SMB demands upper case. 56 $user =~ tr/a-z/A-Z/; 57 my $pass = `smbutil crypt '$pswd'`; 35 58 36 59 print CONFIG "[$SHARE:$user]\npassword=$pass\n"; 37 print "mount_smbfs -N -f 744 -d 755 -u $uid -g $gid //$user\@$SHARE/$user $homedir\n"; 38 system("mount_smbfs -N -f 744 -d 755 -u $uid -g $gid //$user\@$SHARE/$user $homedir"); 60 61 if(! -d "$AMDROOT$homedir") { 62 system("$MKDIR -p $AMDROOT$homedir") && die("Failed to make directory"); 63 } 39 64 40 if($user =~ m/$PUSER/i) { 41 print "mount_smbfs -N -f 774 -d 755 -u $uid -g $gid //$user\@$SHARE/share /share\n"; 42 system("mount_smbfs -N -f 774 -d 755 -u $uid -g $gid //$user\@$SHARE/share /share"); 43 open(MOUNTS, "$TMCC -s $ADDR mounts |") or die("Failed to execute TMCC"); 44 while(<MOUNTS>) { 45 if(/LOCAL=\/proj\/(\S+)/) { 46 print "mount_smbfs -N -f 774 -d 755 -u $uid -g $gid //$user\@$SHARE/proj-$1 /proj/$1\n"; 47 system("mount_smbfs -N -f 774 -d 755 -u $uid -g $gid //$user\@$SHARE/proj-$1 /proj/$1"); 48 } 49 } 50 } 65 print FSTAB "//$user\@$SHARE/$user\t"; 66 print FSTAB "$AMDROOT$homedir\tsmbfs\t"; 67 print FSTAB "noauto,rw,-N,-f744,-d755,-u$uid,-g$gid\t0\t0\n"; 68 69 print MAP "\n$userlc type:=program;fs:=$AMDROOT$homedir;\\\n"; 70 print MAP "mount:=\"$MOUNT mount $AMDROOT$homedir\";\\\n"; 71 print MAP "unmount:=\"$UMOUNT unmount $AMDROOT$homedir\";"; 51 72 } 52 73 } 53 74 54 75 close(CONFIG); 76 close(FSTAB); 77 close(MAP); 55 78 79 print "Starting the automounter: $AMD -l syslog -a $AMDROOT $HOMEROOT $AMDMAP\n"; 80 system("$AMD -l syslog -a $AMDROOT $HOMEROOT $AMDMAP") && die("Unable to start amd");
Note: See TracChangeset
for help on using the changeset viewer.