source: fedkit/smbmount.Linux.pl @ 6a8a9ec

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

Moving toward the federation scripts that don't rely on tmcd forwarding.

  • Property mode set to 100755
File size: 2.8 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
[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");
[f3691ff]47open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB");
48
49print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n";
50
51while(<TM>) {
[c0a8738]52    /ADDUSER/ && do {
53        /LOGIN=(\S+)/ && do { $user = $1; };
54        /WPSWD=(\S+)/ && do { $pswd = $1; };
55        /UID=(\S+)/ && do { $uid = $1; };
56        /GID=(\S+)/ && do { $gid = $1; };
57        /HOMEDIR=(\S+)/ && do { $homedir = $1; };
58
59        open(PWDFILE, ">/tmp/$user.cifs_creds") || 
60            warn "Can't create credentials for $user:$!\n";
61        print PWDFILE "username=$user\npassword=$pswd\n";
62        close(PWDFILE);
63        chmod(0600, "/tmp/$user.cifs_creds") == 1 || 
64            warn "Credential file /tmp/$user.cifs_creds may have " .
65                "bad permissions:$!\n";
66
67        print FSTAB "//$SHARE/$user\t";
68        print FSTAB "$homedir\tcifs\t";
69        print FSTAB "auto,rw,credentials=/tmp/$user.cifs_creds,ip=$ADDR\t0\t0\n";
70
71        #
72        # If we are PUSER, the user assigned to mount the project
73        # directory, then we add in the mount for that.  The share is
74        # called proj-$PNAME where PNAME is the name of the project at
75        # the mothership.  We need a second map for this since we will
76        # be mounting under /proj.  We should really not use share in
77        # federation.
78        #
79
80        if($user =~ m/$PUSER/i) {
81            print FSTAB "//$SHARE/proj-$PNAME\t";
82            print FSTAB "$PROJROOT/$PNAME\tcifs\t";
83            print FSTAB "rw,credentials=/tmp/$user.cifs_creds,ip=$ADDR\t0\t0\n";
84
85        }
86    }
[f3691ff]87}
88
89close(FSTAB);
90
91print("Mounting the cifs versions of everything\n");
92system("$MOUNT -a -t cifs");
Note: See TracBrowser for help on using the repository browser.