1 #!/afs/athena/contrib/perl/perl
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",
23 ("ATHENA.MIT.EDU", 'athena_proc' );
27 die "Usage: $0 locker type cell path user group\n" if (@ARGV != 6);
28 ($locker,$type,$cell,$path,$user,$group) = @ARGV;
31 ($c = $cell) =~ s/\./_/g;
32 $vtype = eval "\$vtypes_$c{$type}";
33 die "Cannot create $type volumes in $cell\n" unless $vtype;
34 $vname = $vtype . "." . $locker;
37 ($asrv,$apart) = &afs_find($cell,$type,$quota);
38 die "Unable to find space to create $vname in $cell\n" unless ($asrv&&$apart);
41 system("$vos create $asrv $apart $vname -cell $cell >/dev/null") &&
42 &fatal("Unable to create $vname in $cell");
43 push(@clean, "$vos remove $asrv $apart $vname -cell $cell >/dev/null");
45 # Create mountpoint and set quota
46 $path =~ s:^/afs/([^.]):/afs/.\1:;
47 system("$fs checkb >/dev/null; $fs mkm $path $vname");
48 &fatal("Unable to create $path") if ($?);
49 push(@clean, "$fs rmm $path");
51 # Obtain user/group information
53 open(PTS, "$pts ex $user -cell $cell|");
56 ($uid,$uid,$uid,$uid) = split(/[:,] /, $_) unless ($?);
58 open(PTS, "$pts ex system:$group -cell $cell|");
61 ($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
115 # 1. All directories also have "system:expunge ld".
117 @acl=("system:expunge ld");
118 push(@acl,"system:facdev all") if ($type =~ /^(COURSE)/);
119 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
120 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
121 push(@acl,"$user all")
122 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|PROJECT|REF|SW)/);
123 push(@acl,"system:$group all")
124 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|PROJECT)/);
125 push(@acl,"system:$group rl") if ($gid != -1 && $type =~ /^(AREF)/);
126 push(@acl,"system:authuser rl")
127 if ($type =~ /^(COURSE|SW)/);
128 push(@acl,"system:anyuser rl")
129 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|REF|SYSTEM)/);
131 if ($type !~ /^(AREF|SYSTEM)/) {
132 system("$fs mkm $path/OldFiles $vname.backup");
133 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
136 if ($type eq "HOMEDIR") {
137 die "Unable to get uid for user\n" unless ($uid);
139 mkdir("$path/Public",0755) && chown($uid,0,"$path/Public") &&
140 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
141 chown($uid,0,"$path/Public","$path/Private","$path/Mail") ||
142 die "Unable to create subdirectories\n";
143 system("$fs sa $path/Public @acl system:anyuser rl -clear") &&
144 die "Unable to set acl on Public directory";
145 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
146 die "Unable to set acl on Private and/or Mail directories\n";
148 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
153 next if ($i eq "." || $i eq "..");
154 next unless -f "$protodir/$i";
155 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
156 open(OUT,">$path/$i") || die "Unable to create $i\n";
157 while ($_=<IN>) { print OUT $_; };
160 chown($uid,0,"$path/$i");
162 chown($uid,0,$path) &&
163 system("$fs sa $path @acl system:anyuser l -clear") &&
164 die "Unable to set acl on top-level directory\n";
168 system("$fs sa $path @acl -clear") &&
169 die "Unable to set acl of $path\n";