source: fedkit/smbmount.Linux.pl @ 0ea5050

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

checkpoint includes some ucb and some FC6 code

  • Property mode set to 100755
File size: 2.7 KB
RevLine 
[f3691ff]1#!/usr/bin/perl
2
3#############################################################################
4# smbmounts.pl: Setup Automounter to mount via SMB for federated experiments
5# $Id: smbmount.Linux.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
16chomp $ADDR;
17
18# ADDR is probably a DNS name (and we assume so if it has letters.  mount cifs
19# wants an IP address, so this hex dereferences the DNS name and converts the
20# first address into the string representation of the IP.  It is, perhaps, a
21# but terse.
22if ($ADDR =~ /[a-z]/ ) {
23    my @addrs = (gethostbyname($ADDR))[4];
24    $ADDR = join(".", unpack("C4", @addrs[0]))
25        if @addrs;
26}
27
28
29$TMCC="/usr/local/etc/emulab/tmcc";
30$UMOUNT="/bin/umount";
31$MOUNT="/bin/mount";
32$MKDIR="/bin/mkdir";
33$CP="/bin/cp";
34
35print "Unmounting all nfs and cifs filesystems.\n";
36system("$UMOUNT -a -f -t nfs,cifs"); # 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, "$TMCC accounts windows |") or die("Failed to execute TMCC");
46open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB");
47
48print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n";
49
50while(<TM>) {
51        if (/ADDUSER LOGIN=(\S+) PSWD=(\S+) UID=(\d+) GID=(\d+).*HOMEDIR=(\S+) / ) {
52                ($user, $pswd, $uid, $gid, $homedir) = ($1, $2, $3, $4, $5);
53
54
55                open(PWDFILE, ">/tmp/$user.cifs_creds") || 
56                    warn "Can't create credentials for $user:$!\n";
57                print PWDFILE "username=$user\npassword=$pswd\n";
58                close(PWDFILE);
59                chmod(0600, "/tmp/$user.cifs_creds") == 1 || 
60                    warn "Credential file /tmp/$user.cifs_creds may have " .
61                        "bad permissions:$!\n";
62
63                print FSTAB "//$SHARE/$user\t";
64                print FSTAB "$homedir\tcifs\t";
65                print FSTAB "auto,rw,credentials=/tmp/$user.cifs_creds,ip=$ADDR\t0\t0\n";
66
67                #
68                # If we are PUSER, the user assigned to mount the project
69                # directory, then we add in the mount for that.  The share is
70                # called proj-$PNAME where PNAME is the name of the project at
71                # the mothership.  We need a second map for this since we will
72                # be mounting under /proj.  We should really not use share in
73                # federation.
74                #
75
76                if($user =~ m/$PUSER/i) {
77                        print FSTAB "//$SHARE/proj-$PNAME\t";
78                        print FSTAB "$PROJROOT/$PNAME\tcifs\t";
79                        print FSTAB "rw,credentials=/tmp/$user.cifs_creds\t0\t0\n";
80
81                }
82        }
83}
84
85close(FSTAB);
86
87print("Mounting the cifs versions of everything\n");
88system("$MOUNT -a -t cifs");
Note: See TracBrowser for help on using the repository browser.