source: fedkit/smbmount.FreeBSD.pl @ 181cf9c

axis_examplecompt_changesinfo-opsversion-2.00version-3.01version-3.02
Last change on this file since 181cf9c was f3691ff, checked in by Ted Faber <faber@…>, 17 years ago

checkpoint includes some ucb and some FC6 code

  • Property mode set to 100755
File size: 3.5 KB
Line 
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$FSTAB="/etc/fstab";
13$HOMEROOT="/users";
14$PROJROOT="/proj";
15$AMDROOT="/auto";
16$AMDMAP="/etc/amd.users";
17$PAMDMAP="/etc/amd.proj";
18
19chomp $ADDR;
20
21$TMCC="/usr/local/etc/emulab/tmcc";
22$UMOUNT="/sbin/umount";
23$MOUNT="/sbin/mount";
24$MKDIR="/bin/mkdir";
25$CP="/bin/cp";
26$KILLALL="/usr/bin/killall";
27$AMD="/usr/sbin/amd";
28
29print "Killing amd.\n";
30system("$KILLALL amd");
31
32print "Unmounting all nfs and smb filesystems.\n";
33system("$UMOUNT -A -f -t nfs,smbfs"); # or die("Failed to unmount NFS");
34
35# Backup the fstab so we can run multiple times
36if (! -f "$FSTAB.bak") {
37        system("$CP $FSTAB $FSTAB.bak") && die("Unable to backup $FSTAB");
38} else {
39        system("$CP $FSTAB.bak $FSTAB") && die("Unable to restore $FSTAB");
40}
41
42open(TM, "$TMCC accounts windows |") or die("Failed to execute TMCC");
43open(CONFIG, ">/etc/nsmb.conf") or die("Failed to open /etc/nsmb.conf");
44open(MAP, ">$AMDMAP") or die("Failed to open $AMDMAP");
45open(PMAP, ">$PAMDMAP") or die("Failed to open $PAMDMAP");
46open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB");
47
48print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n";
49print MAP "# AMD Configuration Generated by smbmount.pl\n";
50print CONFIG "# SMB Configuration Generated by smbmount.pl\n\n";
51print CONFIG "[$SHARE]\naddr=$ADDR\n\n";
52
53while(<TM>) {
54        if (/ADDUSER LOGIN=(\S+) PSWD=(\S+) UID=(\d+) GID=(\d+).*HOMEDIR=(\S+) / ) {
55                $user = $1;
56                $pswd = $2;
57                $uid  = $3;
58                $gid  = $4;
59                $homedir = $5;
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") && die("Failed to make directory");
70                }
71
72                print FSTAB "//$user\@$SHARE/$user\t";
73                print FSTAB "$AMDROOT$homedir\tsmbfs\t";
74                print FSTAB "noauto,rw,-N,-f744,-d755,-u$uid,-g$gid\t0\t0\n";
75
76                print MAP "\n$userlc type:=program;fs:=$AMDROOT$homedir;\\\n";
77                print MAP "mount:=\"$MOUNT mount $AMDROOT$homedir\";\\\n";
78                print MAP "unmount:=\"$UMOUNT unmount $AMDROOT$homedir\";";
79
80                #
81                # If we are PUSER, the user assigned to mount the project directory,
82                # then we add in the mount for that.  The share is called proj-$PNAME
83                # where PNAME is the name of the project at the mothership.  We need
84                # a second map for this since we will be mounting under /proj.
85                # We should really not use share in federation.
86                #
87
88                if($user =~ m/$PUSER/i) {
89                        print FSTAB "//$user\@$SHARE/proj-$PNAME\t";
90                        print FSTAB "$AMDROOT/proj\tsmbfs\t";
91                        print FSTAB "noauto,rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n";
92
93                        print PMAP "$PNAME type:=program;fs:=$AMDROOT/proj;\\\n";
94                        print PMAP "mount:=\"$MOUNT mount $AMDROOT/proj\";\\\n";
95                        print PMAP "unmount:=\"$UMOUNT unmount $AMDROOT/proj\";\n";
96
97                        if(! -d "$AMDROOT/proj") {
98                                system("$MKDIR -p $AMDROOT/proj") && die("Failed to make directory");
99                        }
100                }
101        }
102}
103
104close(CONFIG);
105close(FSTAB);
106close(MAP);
107close(PMAP);
108
109print "Starting the automounter: $AMD -l syslog -a $AMDROOT $HOMEROOT $AMDMAP $PROJROOT $PAMDMAP\n";
110system("$AMD -l syslog -a $AMDROOT $HOMEROOT $AMDMAP $PROJROOT $PAMDMAP") && die("Unable to start amd");
Note: See TracBrowser for help on using the repository browser.