source: fedkit/smbmount.FreeBSD.pl @ c5b28bf

axis_examplecompt_changesinfo-opsversion-3.01version-3.02
Last change on this file since c5b28bf was 1102368, checked in by Ted Faber <faber@…>, 15 years ago

stop mounting share

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