source: fedkit/smbmount.FreeBSD.pl @ d58ee5e

compt_changes
Last change on this file since d58ee5e 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
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]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");
[45ed8ee]47open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB");
[61f19e0]48
[45ed8ee]49print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n";
50print CONFIG "# SMB Configuration Generated by smbmount.pl\n\n";
[61f19e0]51print CONFIG "[$SHARE]\naddr=$ADDR\n\n";
52
53while(<TM>) {
[c0a8738]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";
[4e9719b]74        print FSTAB "$homedir\t$FSTYPE\t";
75        print FSTAB "rw,-N,-f744,-d755,-u$uid,-g$gid\t0\t0\n";
[c0a8738]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";
[4e9719b]85            print FSTAB "/proj/$PNAME\t$FSTYPE\t";
86            print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n";
[c0a8738]87
[4e9719b]88            if(! -d "/proj/$PNAME") {
89                    system("$MKDIR -p /proj/$PNAME") && 
[c0a8738]90                        die("Failed to make directory");
91            }
[2b11a1d]92            if ( $share) {
93                print FSTAB "//$user\@$SHARE/share\t";
[4e9719b]94                print FSTAB "/share\t$FSTYPE\t";
95                print FSTAB "rw,-N,-f774,-d775,-u$uid,-g$gid\t0\t0\n";
[2b11a1d]96
[4e9719b]97                if(! -d "/share") {
98                        system("$MKDIR -p /share") && 
[2b11a1d]99                            die("Failed to make directory");
100                }
101            }
[c0a8738]102        }
103    }
[61f19e0]104}
105
106close(CONFIG);
[45ed8ee]107close(FSTAB);
[4e9719b]108print("Mounting the $FSTYPE versions of everything\n");
109system("$MOUNT -a -t $FSTYPE");
Note: See TracBrowser for help on using the repository browser.