source: fedkit/smbmount.FreeBSD.pl @ 4e9719b

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

SEER stuff

  • Property mode set to 100755
File size: 4.1 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";
[73e0a61]12$FSTYPE=shift || "smbfs";
[45ed8ee]13$FSTAB="/etc/fstab";
14$HOMEROOT="/users";
[30184e4]15$PROJROOT="/proj";
[45ed8ee]16$AMDROOT="/auto";
17$AMDMAP="/etc/amd.users";
[30184e4]18$PAMDMAP="/etc/amd.proj";
19
20chomp $ADDR;
[61f19e0]21
[30184e4]22$TMCC="/usr/local/etc/emulab/tmcc";
[45ed8ee]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";
[61f19e0]29
[1102368]30my $share = 0;
[2b11a1d]31
[45ed8ee]32print "Killing amd.\n";
33system("$KILLALL amd");
[61f19e0]34
[45ed8ee]35print "Unmounting all nfs and smb filesystems.\n";
36system("$UMOUNT -A -f -t nfs,smbfs"); # or die("Failed to unmount NFS");
[61f19e0]37
[45ed8ee]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
[c0a8738]45# open(TM, "$TMCC accounts windows |") or die("Failed to execute TMCC");
46open(TM, "/usr/local/federation/etc/userconf")or die("Failed to open userconf");
[61f19e0]47open(CONFIG, ">/etc/nsmb.conf") or die("Failed to open /etc/nsmb.conf");
[4e9719b]48#open(MAP, ">$AMDMAP") or die("Failed to open $AMDMAP");
49#open(PMAP, ">$PAMDMAP") or die("Failed to open $PAMDMAP");
[45ed8ee]50open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB");
[61f19e0]51
[45ed8ee]52print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n";
[4e9719b]53#print MAP "# AMD Configuration Generated by smbmount.pl\n";
[45ed8ee]54print CONFIG "# SMB Configuration Generated by smbmount.pl\n\n";
[61f19e0]55print CONFIG "[$SHARE]\naddr=$ADDR\n\n";
56
57while(<TM>) {
[c0a8738]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";
[4e9719b]78        print FSTAB "$homedir\t$FSTYPE\t";
79        print FSTAB "rw,-N,-f744,-d755,-u$uid,-g$gid\t0\t0\n";
[c0a8738]80
[4e9719b]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\";";
[c0a8738]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";
[4e9719b]93            print FSTAB "/proj/$PNAME\t$FSTYPE\t";
94            print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n";
[c0a8738]95
[4e9719b]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";
[c0a8738]99
[4e9719b]100            if(! -d "/proj/$PNAME") {
101                    system("$MKDIR -p /proj/$PNAME") && 
[c0a8738]102                        die("Failed to make directory");
103            }
[2b11a1d]104            if ( $share) {
105                print FSTAB "//$user\@$SHARE/share\t";
[4e9719b]106                print FSTAB "/share\t$FSTYPE\t";
107                print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n";
[2b11a1d]108
[4e9719b]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";
[2b11a1d]112
[4e9719b]113                if(! -d "/share") {
114                        system("$MKDIR -p /share") && 
[2b11a1d]115                            die("Failed to make directory");
116                }
117            }
[c0a8738]118        }
119    }
[61f19e0]120}
121
122close(CONFIG);
[45ed8ee]123close(FSTAB);
[4e9719b]124print("Mounting the $FSTYPE versions of everything\n");
125system("$MOUNT -a -t $FSTYPE");
126#close(MAP);
127#close(PMAP);
[61f19e0]128
[4e9719b]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");
Note: See TracBrowser for help on using the repository browser.