source: fedkit/smbmount.FreeBSD.pl @ ccfc03d

Last change on this file since ccfc03d was 881cd02, checked in by Ted Faber <faber@…>, 14 years ago

Remove some commented out code

  • Property mode set to 100755
File size: 3.0 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$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
20chomp $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
30my $share = 0;
31
32print "Killing amd.\n";
33system("$KILLALL amd");
34
35print "Unmounting all nfs and smb filesystems.\n";
36system("$UMOUNT -A -f -t nfs,smbfs"); # or die("Failed to unmount NFS");
37
38# Backup the fstab so we can run multiple times
39if (! -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
45open(TM, "/usr/local/federation/etc/userconf")or die("Failed to open userconf");
46open(CONFIG, ">/etc/nsmb.conf") or die("Failed to open /etc/nsmb.conf");
47open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB");
48
49print FSTAB "\n# SMB 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    /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
106close(CONFIG);
107close(FSTAB);
108print("Mounting the $FSTYPE versions of everything\n");
109system("$MOUNT -a -t $FSTYPE");
Note: See TracBrowser for help on using the repository browser.