dirs 2.08 KB
Newer Older
1 2 3 4 5 6
#
# 
#
use strict;
use libinstall;
use installvars;
7
use Cwd qw(realpath);
8 9 10 11 12 13 14 15 16

sub Install($$$)
{
    my ($server, $isupdate, $impotent) = @_;

    # Replace if this script does an update for ip/domain.
    return 0
	if ($isupdate);

Leigh Stoller's avatar
Leigh Stoller committed
17
    my @TESTBED_DIRS = ([$PREFIX, "0775"],["$PREFIX/etc", "0755"]);
18 19 20
    if ($server eq $OPS_SERVERNAME || $server eq $FS_SERVERNAME) {
	push(@TESTBED_DIRS, ([$USERROOT, "0755"],
			     [$PROJROOT, "0755"],
21
			     [$GROUPROOT, "0755"]));
22

23 24 25
	if ($SHAREDIR) {
	    push(@TESTBED_DIRS, [$SHAREROOT, "0755"]);
	}
26 27 28 29 30
	if ($SCRATCHDIR) {
	    push(@TESTBED_DIRS, [$SCRATCHROOT, "0755"]);
	}
    }

Leigh Stoller's avatar
Leigh Stoller committed
31 32 33 34 35
    Phase "etcdir", "Creating $PREFIX/etc", sub {
	DoneIfExists("$PREFIX/etc");
	mkdir "$PREFIX/etc",0755 or
	    PhaseFail("Unable to create $PREFIX/etc: $!");
    };
36 37 38 39 40 41 42 43
    Phase "dirs", "Setting directory permissions", sub {
    	  foreach my $dirref (@TESTBED_DIRS) {
	      my ($dir, $newmode) = @$dirref;
	      Phase $dir, $dir, sub {
		  if (!-d $dir) {
		      PhaseFail("Directory $dir does not exist");
		  }
		  # Use the real path, to avoid symlink problems
44
		  my $realdir = realpath($dir);
45 46 47 48 49 50 51 52 53 54 55 56
		  chomp $realdir;
		  my ($mode,$group) = (stat($realdir))[2,5];
		  # Fix up the mode (strip file type)
		  $mode = $mode & 0777;
		  if ($mode == eval $newmode && $group eq getgrnam("tbadmin")) {
		      PhaseSkip("Already done");
		  }
		  ExecQuietFatal("$CHGRP tbadmin $realdir");
		  ExecQuietFatal("$CHMOD $newmode $realdir");
	      };
	  }
    };
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    if ($OPSVM_ENABLE) {
	# This only happens on boss.
	Phase "symlinks", "Symlinking to OPS VM", sub {
	    Phase $OPSDIR_MOUNTPOINT, $OPSDIR_MOUNTPOINT, sub {
		PhaseSkip("exists")
		    if (-e $OPSDIR_MOUNTPOINT && -l $OPSDIR_MOUNTPOINT);
		ExecQuietFatal("ln -s ${OPSVM_MOUNTPOINT}/usr/testbed ".
			       "$OPSDIR_MOUNTPOINT");
	    };
	    Phase $USERSVAR_MOUNTPOINT, $USERSVAR_MOUNTPOINT, sub {
		PhaseSkip("exists")
		    if (-e $USERSVAR_MOUNTPOINT && -l $USERSVAR_MOUNTPOINT);
		ExecQuietFatal("ln -s ${OPSVM_MOUNTPOINT}/var ".
			       "$USERSVAR_MOUNTPOINT");
	    };
	};
    }
74 75 76 77 78 79
    return 0;
}

# Local Variables:
# mode:perl
# End: