2 # Usage: afs_create locker type cell path quota user group
4 require "/moira/bin/afs_utils.pl";
6 $protodir="/moira/dotfiles";
9 %vtypes_ATHENA_MIT_EDU =
10 ("ACTIVITY", "activity",
24 ("ATHENA.MIT.EDU", 'athena_proc' );
28 die "Usage: $0 locker type cell path user group\n" if (@ARGV != 6);
29 ($locker,$type,$cell,$path,$user,$group) = @ARGV;
32 ($c = $cell) =~ s/\./_/g;
33 $vtype = eval "\$vtypes_$c{$type}";
34 die "Cannot create $type volumes in $cell\n" unless $vtype;
35 $vname = $vtype . "." . $locker;
38 ($asrv,$apart) = &afs_find($cell,$type,$quota);
39 die "Unable to find space to create $vname in $cell\n" unless ($asrv&&$apart);
42 system("$vos create $asrv $apart $vname -cell $cell >/dev/null") &&
43 &fatal("Unable to create $vname in $cell");
44 push(@clean, "$vos remove $asrv $apart $vname -cell $cell >/dev/null");
46 # Create mountpoint and set quota
47 $path =~ s:^/afs/([^.]):/afs/.\1:;
48 system("$fs checkb >/dev/null; $fs mkm $path $vname");
49 &fatal("Unable to create $path") if ($?);
50 push(@clean, "$fs rmm $path");
52 # Obtain user/group information (uid >= 0, gid <= 0)
54 open(PTS, "$pts ex $user -cell $cell|");
57 ($uid,$uid,$uid,$uid) = split(/[:,] /, $_) unless ($?);
59 open(PTS, "$pts ex system:$group -cell $cell|");
62 ($gid,$gid,$gid,$gid) = split(/[:,] /, $_) unless ($?);
64 # Dispatch to the cell-specific creation routines
68 # Set the filesystem quota
69 system("$fs sq $path $quota");
70 &fatal("Unable to set the quota on $path") if ($?);
72 # Release the parent volume
73 ($p = $path) =~ s:/[^/]+$::;
74 open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
77 &fatal("Can't get information about $p") if ($?);
78 @tmp = (split(/ /,$_));
79 system("$vos release $tmp[$#tmp] -cell $cell >/dev/null") &&
80 &fatal("Can't release $tmp[$#tmp] in cell $cell");
82 &afs_quota_adj($cell,$asrv,$apart,$quota);
93 warn "$locker: Cleanup failed: $cmd\n" if (system("$cmd"));
98 # Cell specific procedures
103 # ACTIVITY <user> all <group> all system:anyuser rl
104 # APROJ <user> all <group> all system:anyuser rl
105 # AREF <user> all <group> rl
106 # CONTRIB <user> all system:anyuser rl
107 # COURSE <user> all <group> all system:facdev all system:authuser rl
109 # PROJECT <user> all <group> all
110 # REF <user> all system:anyuser rl
111 # SW <user> all system:swmaint all system:authuser rl
112 # SYSTEM system:administrators all system:anyuser rl
113 # UROP <user> all <group> all system:facdev all system:authuser rl
116 # 1. All directories also have "system:expunge ld".
118 @acl=("system:expunge ld");
119 push(@acl,"system:facdev all") if ($type =~ /^(COURSE|UROP)/);
120 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
121 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
122 push(@acl,"$user all")
123 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|PROJECT|REF|SW|UROP)/);
124 push(@acl,"system:$group all")
125 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|PROJECT|UROP)/);
126 push(@acl,"system:$group rl") if ($gid != 0 && $type =~ /^(AREF)/);
127 push(@acl,"system:authuser rl")
128 if ($type =~ /^(COURSE|SW|UROP)/);
129 push(@acl,"system:anyuser rl")
130 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|REF|SYSTEM)/);
132 if ($type !~ /^(AREF|SYSTEM)/) {
133 system("$fs mkm $path/OldFiles $vname.backup");
134 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
137 if ($type =~ /ACTIVITY|APROJ|PROJECT/) {
138 chown($gid,0,$path) ||
139 die "Unable to set volume ownership\n";
140 } elsif ($type =~ /HOMEDIR|UROP/) {
141 chown($uid,0,$path) ||
142 die "Unable to set volume ownership\n";
145 if ($type eq "HOMEDIR") {
146 die "Unable to get uid for user\n" unless ($uid);
148 mkdir("$path/Public",0755) && chown($uid,0,"$path/Public") &&
149 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
150 chown($uid,0,"$path/Public","$path/Private","$path/Mail") ||
151 die "Unable to create subdirectories\n";
152 system("$fs sa $path/Public @acl system:anyuser rl -clear") &&
153 die "Unable to set acl on Public directory";
154 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
155 die "Unable to set acl on Private and/or Mail directories\n";
157 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
162 next if ($i eq "." || $i eq "..");
163 next unless -f "$protodir/$i";
164 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
165 open(OUT,">$path/$i") || die "Unable to create $i\n";
166 while ($_=<IN>) { print OUT $_; };
169 chown($uid,0,"$path/$i");
171 system("$fs sa $path @acl system:anyuser l -clear") &&
172 die "Unable to set acl on top-level directory\n";
176 system("$fs sa $path @acl -clear") &&
177 die "Unable to set acl of $path\n";