2 # Usage: afs_create locker type cell path quota user group
4 require "/moira/bin/afs_utils.pl";
6 $protodir="/moira/dotfiles";
10 ("ATHENA.MIT.EDU", 'athena_proc' );
14 die "Usage: $0 locker type cell path user group\n" if (@ARGV != 6);
15 ($locker,$type,$cell,$path,$user,$group) = @ARGV;
18 ($c = $cell) =~ s/\./_/g;
19 $vtype = eval "\$vtypes_${c}{$type}";
20 die "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
24 # Find free space/Create volume
25 $tries = 0; $code = 1;
26 while ($tries<3 && $code) {
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");
33 &fatal("Unable to create $vname in $cell") if ($code); # Too many create errors
34 push(@clean, "$vos remove $asrv $apart $vname -cell $cell >/dev/null");
36 # Create mountpoint and set quota
37 $path =~ s:^/afs/([^.]):/afs/.\1:;
38 system("$fs checkv >/dev/null; $fs mkm $path $vname");
39 &fatal("Unable to create $path") if ($?);
40 push(@clean, "$fs rmm $path");
42 # Obtain user/group information (uid >= 0, gid <= 0)
44 open(PTS, "$pts ex $user -cell $cell|");
47 ($uid,$uid,$uid,$uid) = split(/[:,] /, $_) unless ($?);
49 open(PTS, "$pts ex system:$group -cell $cell|");
52 ($gid,$gid,$gid,$gid) = split(/[:,] /, $_) unless ($?);
54 # Dispatch to the cell-specific creation routines
58 # Set the filesystem quota
59 system("$fs sq $path $quota");
60 &fatal("Unable to set the quota on $path") if ($?);
62 # Release the parent volume
63 ($p = $path) =~ s:/[^/]+$::;
64 open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
67 &fatal("Can't get information about $p") if ($?);
68 @tmp = (split(/ /,$_));
69 if ($tmp[$#tmp] !~ /user\../) {
70 system("$vos release $tmp[$#tmp] -cell $cell >/dev/null") &&
71 &fatal("Can't release $tmp[$#tmp] in cell $cell");
74 # Update the quota records.
75 &afs_quota_adj($cell,$asrv,$apart,$quota,0);
86 warn "$locker: Cleanup failed: $cmd\n" if (system("$cmd"));
91 # Cell specific procedures
96 # ACTIVITY <user> all <group> all system:anyuser rl
97 # APROJ <user> all <group> all system:anyuser rl
98 # AREF <user> all <group> rl
99 # CONTRIB <user> all system:anyuser rl
100 # COURSE <user> all <group> all system:facdev all system:authuser rl
103 # ORG <user> all <group> all system:cwisfac all
104 # PROJECT <user> all <group> all
105 # REF <user> all system:anyuser rl
106 # SW <user> all system:swmaint all system:authuser rl
107 # SYSTEM system:administrators all system:anyuser rl
108 # UROP <user> all <group> all system:facdev all system:authuser rl
111 # 1. All directories also have "system:expunge ld".
113 @acl=("system:expunge ld");
114 push(@acl,"system:facdev all") if ($type =~ /^(COURSE|UROP)/);
115 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
116 push(@acl,"system:cwisfac all") if ($type =~ /^(ORG)/);
117 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
118 push(@acl,"$user all")
119 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|LEASE|ORG|PROJECT|REF|SW|UROP)/);
120 push(@acl,"system:$group all")
121 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|ORG|PROJECT|UROP)/);
122 push(@acl,"system:$group rl") if ($gid != 0 && $type =~ /^(AREF)/);
123 push(@acl,"system:authuser rl")
124 if ($type =~ /^(COURSE|SW|UROP)/);
125 push(@acl,"system:anyuser rl")
126 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|REF|SYSTEM)/);
128 if ($type !~ /^(AREF|ORG|SYSTEM)/) {
129 system("$fs mkm $path/OldFiles $vname.backup");
130 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
133 if ($type =~ /ACTIVITY|APROJ|PROJECT/) {
134 system("/moira/bin/uchown $path $gid");
135 die "Unable to set volume ownership\n" if ($?);
136 } elsif ($type =~ /HOMEDIR|UROP/) {
137 chown($uid,0,$path) ||
138 die "Unable to set volume ownership\n";
141 if ($type =~ /^(ORG|COURSE)/) {
142 mkdir("$path/www",0755) &&
143 chown(0,0,"$path/www") ||
144 die "Unable to create subdirectories\n";
145 system("$fs sa $path/www @acl system:anyuser rl -clear") &&
146 die "Unable to set acl on www directory\n";
148 system("$fs sa $path @acl system:anyuser l -clear") &&
149 die "Unable to set acl on top-level directory\n";
153 if ($type eq "HOMEDIR") {
154 die "Unable to get uid for user\n" unless ($uid);
157 mkdir("$path/Public",0755) && mkdir("$path/www",0755) &&
158 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
159 chown($uid,0,"$path/Public","$path/www",
160 "$path/Private","$path/Mail") ||
161 die "Unable to create subdirectories\n";
162 system("$fs sa -dir $path/Public $path/www -acl @acl system:anyuser rl -clear") &&
163 die "Unable to set acl on Public directory";
164 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
165 die "Unable to set acl on Private and/or Mail directories\n";
167 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
172 next if ($i eq "." || $i eq "..");
173 next unless -f "$protodir/$i";
174 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
175 open(OUT,">$path/$i") || die "Unable to create $i\n";
176 while ($_=<IN>) { print OUT $_; };
179 chown($uid,0,"$path/$i");
181 system("$fs sa $path @acl system:anyuser l -clear") &&
182 die "Unable to set acl on top-level directory\n";
186 system("$fs sa $path @acl -clear") &&
187 die "Unable to set acl of $path\n";