]> andersk Git - moira.git/blame - incremental/afs_create.pl
ifdef on GDSS; add missing SRCDIR
[moira.git] / incremental / afs_create.pl
CommitLineData
6ff63c15 1#!/usr/athena/bin/perl
6231b320 2# Usage: afs_create locker type cell path quota user group
3
4require "/moira/bin/afs_utils.pl";
5
c09dcc8c 6$protodir="/moira/dotfiles";
6231b320 7$quota=1;
8
6231b320 9%proc =
10 ("ATHENA.MIT.EDU", 'athena_proc' );
11
12umask(0);
13
14die "Usage: $0 locker type cell path user group\n" if (@ARGV != 6);
15($locker,$type,$cell,$path,$user,$group) = @ARGV;
16
17# Lookup volume type
18($c = $cell) =~ s/\./_/g;
754ef493 19$vtype = eval "\$vtypes_$c{$type}";
20die "Cannot create $type volumes in $cell\n" unless $vtype;
21$vname = $vtype . "." . $locker;
22$vname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters
6231b320 23
97798f36 24# Find free space/Create volume
c9e7ea4d 25$tries = 0; $code = 1;
26while ($tries<3 && $code) {
97798f36 27 ($asrv,$apart) = &afs_find($cell,$type,$quota,@except);
28 die "Unable to find space to create $vname in $cell\n" unless ($asrv&&$apart);
29 $code = system("$vos create $asrv $apart $vname -cell $cell >/dev/null");
30 push(@except, $asrv);
c9e7ea4d 31 $tries++;
97798f36 32}
33&fatal("Unable to create $vname in $cell") if ($code); # Too many create errors
6231b320 34push(@clean, "$vos remove $asrv $apart $vname -cell $cell >/dev/null");
35
36# Create mountpoint and set quota
37$path =~ s:^/afs/([^.]):/afs/.\1:;
870213d6 38system("$fs checkv >/dev/null; $fs mkm $path $vname");
6231b320 39&fatal("Unable to create $path") if ($?);
40push(@clean, "$fs rmm $path");
41
6ff63c15 42# Obtain user/group information (uid >= 0, gid <= 0)
6231b320 43$uid = $gid = 0;
44open(PTS, "$pts ex $user -cell $cell|");
45chop($_ = <PTS>);
46close(PTS);
47($uid,$uid,$uid,$uid) = split(/[:,] /, $_) unless ($?);
48
49open(PTS, "$pts ex system:$group -cell $cell|");
50chop($_ = <PTS>);
51close(PTS);
52($gid,$gid,$gid,$gid) = split(/[:,] /, $_) unless ($?);
6231b320 53
54# Dispatch to the cell-specific creation routines
55eval "&$proc{$cell}";
56&fatal($@) if ($@);
57
58# Set the filesystem quota
59system("$fs sq $path $quota");
60&fatal("Unable to set the quota on $path") if ($?);
61
62# Release the parent volume
63($p = $path) =~ s:/[^/]+$::;
64open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
65chop($_ = <FS>);
66close(FS);
67&fatal("Can't get information about $p") if ($?);
68@tmp = (split(/ /,$_));
9efb71b3 69if ($tmp[$#tmp] !~ /user\../) {
70 system("$vos release $tmp[$#tmp] -cell $cell >/dev/null") &&
71 &fatal("Can't release $tmp[$#tmp] in cell $cell");
72}
6231b320 73
74&afs_quota_adj($cell,$asrv,$apart,$quota);
75exit(0);
76
77sub fatal
78{
79 local($cmd);
80 $_ = join(' ',@_);
81 s/\n$//;
82
83 while (@clean) {
84 $cmd = pop(@clean);
85 warn "$locker: Cleanup failed: $cmd\n" if (system("$cmd"));
86 }
87 die "$locker: $_\n";
88}
89
90# Cell specific procedures
91sub athena_proc
92{
93 # Default acls:
94 #
95 # ACTIVITY <user> all <group> all system:anyuser rl
96 # APROJ <user> all <group> all system:anyuser rl
97 # AREF <user> all <group> rl
98 # CONTRIB <user> all system:anyuser rl
99 # COURSE <user> all <group> all system:facdev all system:authuser rl
100 # HOMEDIR <user> all
a2a8b2f6 101 # LEASE <user> all
6231b320 102 # PROJECT <user> all <group> all
103 # REF <user> all system:anyuser rl
104 # SW <user> all system:swmaint all system:authuser rl
105 # SYSTEM system:administrators all system:anyuser rl
9edc1a1d 106 # UROP <user> all <group> all system:facdev all system:authuser rl
6231b320 107 #
108 # Notes:
109 # 1. All directories also have "system:expunge ld".
110
111 @acl=("system:expunge ld");
9edc1a1d 112 push(@acl,"system:facdev all") if ($type =~ /^(COURSE|UROP)/);
6231b320 113 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
114 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
115 push(@acl,"$user all")
a2a8b2f6 116 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|LEASE|PROJECT|REF|SW|UROP)/);
6231b320 117 push(@acl,"system:$group all")
9edc1a1d 118 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|PROJECT|UROP)/);
6ff63c15 119 push(@acl,"system:$group rl") if ($gid != 0 && $type =~ /^(AREF)/);
6231b320 120 push(@acl,"system:authuser rl")
9edc1a1d 121 if ($type =~ /^(COURSE|SW|UROP)/);
6231b320 122 push(@acl,"system:anyuser rl")
123 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|REF|SYSTEM)/);
124
125 if ($type !~ /^(AREF|SYSTEM)/) {
126 system("$fs mkm $path/OldFiles $vname.backup");
127 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
128 }
129
6ff63c15 130 if ($type =~ /ACTIVITY|APROJ|PROJECT/) {
131 chown($gid,0,$path) ||
132 die "Unable to set volume ownership\n";
133 } elsif ($type =~ /HOMEDIR|UROP/) {
134 chown($uid,0,$path) ||
135 die "Unable to set volume ownership\n";
136 }
137
6231b320 138 if ($type eq "HOMEDIR") {
139 die "Unable to get uid for user\n" unless ($uid);
140
141 mkdir("$path/Public",0755) && chown($uid,0,"$path/Public") &&
142 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
143 chown($uid,0,"$path/Public","$path/Private","$path/Mail") ||
144 die "Unable to create subdirectories\n";
145 system("$fs sa $path/Public @acl system:anyuser rl -clear") &&
146 die "Unable to set acl on Public directory";
147 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
148 die "Unable to set acl on Private and/or Mail directories\n";
149
150 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
151 @files=readdir(DIR);
152 closedir(DIR);
153
154 for $i (@files) {
155 next if ($i eq "." || $i eq "..");
156 next unless -f "$protodir/$i";
157 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
158 open(OUT,">$path/$i") || die "Unable to create $i\n";
159 while ($_=<IN>) { print OUT $_; };
160 close(OUT);
161 close(IN);
162 chown($uid,0,"$path/$i");
163 }
6ff63c15 164 system("$fs sa $path @acl system:anyuser l -clear") &&
165 die "Unable to set acl on top-level directory\n";
6231b320 166 return;
167 }
168
169 system("$fs sa $path @acl -clear") &&
170 die "Unable to set acl of $path\n";
171}
This page took 0.088307 seconds and 5 git commands to generate.