source: fedkit/smbmount.Linux.pl @ 8846959

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

PG works (w/o routing)

  • Property mode set to 100755
File size: 3.1 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";
[73e0a61]12$FSTYPE=shift || 'cifs';
[f3691ff]13$FSTAB="/etc/fstab";
14$HOMEROOT="/users";
15$PROJROOT="/proj";
16
[1102368]17my $share = 0;
[2b11a1d]18
[f3691ff]19chomp $ADDR;
20
21# ADDR is probably a DNS name (and we assume so if it has letters.  mount cifs
22# wants an IP address, so this hex dereferences the DNS name and converts the
23# first address into the string representation of the IP.  It is, perhaps, a
24# but terse.
25if ($ADDR =~ /[a-z]/ ) {
26    my @addrs = (gethostbyname($ADDR))[4];
27    $ADDR = join(".", unpack("C4", @addrs[0]))
28        if @addrs;
29}
30
31
32$TMCC="/usr/local/etc/emulab/tmcc";
33$UMOUNT="/bin/umount";
34$MOUNT="/bin/mount";
35$MKDIR="/bin/mkdir";
36$CP="/bin/cp";
37
38print "Unmounting all nfs and cifs filesystems.\n";
39system("$UMOUNT -a -f -t nfs,cifs"); # or die("Failed to unmount NFS");
40
41# Backup the fstab so we can run multiple times
42if (! -f "$FSTAB.bak") {
43        system("$CP $FSTAB $FSTAB.bak") && die("Unable to backup $FSTAB");
44} else {
45        system("$CP $FSTAB.bak $FSTAB") && die("Unable to restore $FSTAB");
46}
47
[c0a8738]48# open(TM, "$TMCC accounts windows |") or die("Failed to execute TMCC");
49open(TM, "/usr/local/federation/etc/userconf")or die("Failed to open userconf");
[f3691ff]50open(FSTAB,">>$FSTAB") or die("Cannot Open File $FSTAB");
51
52print FSTAB "\n# SMB Configuration Generated by smbmount.pl\n";
53
54while(<TM>) {
[c0a8738]55    /ADDUSER/ && do {
56        /LOGIN=(\S+)/ && do { $user = $1; };
57        /WPSWD=(\S+)/ && do { $pswd = $1; };
58        /UID=(\S+)/ && do { $uid = $1; };
59        /GID=(\S+)/ && do { $gid = $1; };
60        /HOMEDIR=(\S+)/ && do { $homedir = $1; };
61
62        open(PWDFILE, ">/tmp/$user.cifs_creds") || 
63            warn "Can't create credentials for $user:$!\n";
64        print PWDFILE "username=$user\npassword=$pswd\n";
65        close(PWDFILE);
66        chmod(0600, "/tmp/$user.cifs_creds") == 1 || 
67            warn "Credential file /tmp/$user.cifs_creds may have " .
68                "bad permissions:$!\n";
69
70        print FSTAB "//$SHARE/$user\t";
[73e0a61]71        print FSTAB "$homedir\t$FSTYPE\t";
[c0a8738]72        print FSTAB "auto,rw,credentials=/tmp/$user.cifs_creds,ip=$ADDR\t0\t0\n";
73
74        #
75        # If we are PUSER, the user assigned to mount the project
76        # directory, then we add in the mount for that.  The share is
77        # called proj-$PNAME where PNAME is the name of the project at
78        # the mothership.  We need a second map for this since we will
79        # be mounting under /proj.  We should really not use share in
80        # federation.
81        #
82
83        if($user =~ m/$PUSER/i) {
84            print FSTAB "//$SHARE/proj-$PNAME\t";
85            print FSTAB "$PROJROOT/$PNAME\tcifs\t";
86            print FSTAB "rw,credentials=/tmp/$user.cifs_creds,ip=$ADDR\t0\t0\n";
[2b11a1d]87            if ( $share) {
88                print FSTAB "//$SHARE/share\t";
[73e0a61]89                print FSTAB "/share\t$FSTYPE\t";
[2b11a1d]90                print FSTAB "rw,credentials=/tmp/$user.cifs_creds,ip=$ADDR\t0\t0\n";
[c0a8738]91
[2b11a1d]92                mkdir("/share") unless -d "/share";
93            }
[c0a8738]94        }
95    }
[f3691ff]96}
97
98close(FSTAB);
99
[73e0a61]100print("Mounting the $FSTYPE versions of everything\n");
101system("$MOUNT -a -t $FSTYPE");
Note: See TracBrowser for help on using the repository browser.