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, "$TMCC accounts windows |") or die("Failed to execute TMCC"); |
---|
46 | open(TM, "/usr/local/federation/etc/userconf")or die("Failed to open userconf"); |
---|
47 | open(CONFIG, ">/etc/nsmb.conf") or die("Failed to open /etc/nsmb.conf"); |
---|
48 | #open(MAP, ">$AMDMAP") or die("Failed to open $AMDMAP"); |
---|
49 | #open(PMAP, ">$PAMDMAP") or die("Failed to open $PAMDMAP"); |
---|
50 | open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB"); |
---|
51 | |
---|
52 | print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n"; |
---|
53 | #print MAP "# AMD Configuration Generated by smbmount.pl\n"; |
---|
54 | print CONFIG "# SMB Configuration Generated by smbmount.pl\n\n"; |
---|
55 | print CONFIG "[$SHARE]\naddr=$ADDR\n\n"; |
---|
56 | |
---|
57 | while(<TM>) { |
---|
58 | /ADDUSER/ && do { |
---|
59 | /LOGIN=(\S+)/ && do { $user = $1; }; |
---|
60 | /WPSWD=(\S+)/ && do { $pswd = $1; }; |
---|
61 | /UID=(\S+)/ && do { $uid = $1; }; |
---|
62 | /GID=(\S+)/ && do { $gid = $1; }; |
---|
63 | /HOMEDIR=(\S+)/ && do { $homedir = $1; }; |
---|
64 | |
---|
65 | $userlc = $user; |
---|
66 | # SMB demands upper case. |
---|
67 | $user =~ tr/a-z/A-Z/; |
---|
68 | my $pass = `smbutil crypt '$pswd'`; |
---|
69 | |
---|
70 | print CONFIG "[$SHARE:$user]\npassword=$pass\n"; |
---|
71 | |
---|
72 | if(! -d "$AMDROOT$homedir") { |
---|
73 | system("$MKDIR -p $AMDROOT$homedir") && |
---|
74 | die("Failed to make directory"); |
---|
75 | } |
---|
76 | |
---|
77 | print FSTAB "//$user\@$SHARE/$user\t"; |
---|
78 | print FSTAB "$homedir\t$FSTYPE\t"; |
---|
79 | print FSTAB "rw,-N,-f744,-d755,-u$uid,-g$gid\t0\t0\n"; |
---|
80 | |
---|
81 | #print MAP "\n$userlc type:=program;fs:=$AMDROOT$homedir;\\\n"; |
---|
82 | #print MAP "mount:=\"$MOUNT mount $AMDROOT$homedir\";\\\n"; |
---|
83 | #print MAP "unmount:=\"$UMOUNT unmount $AMDROOT$homedir\";"; |
---|
84 | |
---|
85 | # |
---|
86 | # If we are PUSER, the user assigned to mount the project directory, |
---|
87 | # then we add in the mount for that. The share is called proj-$PNAME |
---|
88 | # where PNAME is the name of the project at the mothership. We need |
---|
89 | # a second map for this since we will be mounting under /proj. |
---|
90 | |
---|
91 | if($user =~ m/$PUSER/i) { |
---|
92 | print FSTAB "//$user\@$SHARE/proj-$PNAME\t"; |
---|
93 | print FSTAB "/proj/$PNAME\t$FSTYPE\t"; |
---|
94 | print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n"; |
---|
95 | |
---|
96 | #print PMAP "$PNAME type:=program;fs:=$AMDROOT/proj;\\\n"; |
---|
97 | #print PMAP "mount:=\"$MOUNT mount $AMDROOT/proj\";\\\n"; |
---|
98 | #print PMAP "unmount:=\"$UMOUNT unmount $AMDROOT/proj\";\n"; |
---|
99 | |
---|
100 | if(! -d "/proj/$PNAME") { |
---|
101 | system("$MKDIR -p /proj/$PNAME") && |
---|
102 | die("Failed to make directory"); |
---|
103 | } |
---|
104 | if ( $share) { |
---|
105 | print FSTAB "//$user\@$SHARE/share\t"; |
---|
106 | print FSTAB "/share\t$FSTYPE\t"; |
---|
107 | print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n"; |
---|
108 | |
---|
109 | #print PMAP "$PNAME type:=program;fs:=$AMDROOT/share\\\n"; |
---|
110 | #print PMAP "mount:=\"$MOUNT mount $AMDROOT/share\";\\\n"; |
---|
111 | #print PMAP "unmount:=\"$UMOUNT unmount $AMDROOT/share\";\n"; |
---|
112 | |
---|
113 | if(! -d "/share") { |
---|
114 | system("$MKDIR -p /share") && |
---|
115 | die("Failed to make directory"); |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | close(CONFIG); |
---|
123 | close(FSTAB); |
---|
124 | print("Mounting the $FSTYPE versions of everything\n"); |
---|
125 | system("$MOUNT -a -t $FSTYPE"); |
---|
126 | #close(MAP); |
---|
127 | #close(PMAP); |
---|
128 | |
---|
129 | #print "Starting the automounter: $AMD -l syslog -a $AMDROOT $HOMEROOT $AMDMAP $PROJROOT $PAMDMAP\n"; |
---|
130 | #system("$AMD -l syslog -a $AMDROOT $HOMEROOT $AMDMAP $PROJROOT $PAMDMAP") && die("Unable to start amd"); |
---|