]> andersk Git - moira.git/blob - incremental/afs_create.pl
Preserve hidden status of groups
[moira.git] / incremental / afs_create.pl
1 #!/afs/athena/contrib/perl/perl
2 # Usage: afs_create locker type cell path quota user group
3
4 require "/moira/bin/afs_utils.pl";
5
6 $protodir="/moira/dotfiles";
7 $quota=1;
8
9 %vtypes_ATHENA_MIT_EDU =
10     ("ACTIVITY", "activity",
11      "APROJ", "aproj",
12      "AREF", "aref",
13      "CONTRIB", "contrib",
14      "COURSE", "course",
15      "HOMEDIR", "user",
16      "PROJECT", "project",
17      "REF", "ref",
18      "SW", "sw",
19      "SYSTEM", "system",
20      );
21
22 %proc =
23     ("ATHENA.MIT.EDU", 'athena_proc' );
24
25 umask(0);
26
27 die "Usage: $0 locker type cell path user group\n" if (@ARGV != 6);
28 ($locker,$type,$cell,$path,$user,$group) = @ARGV;
29
30 # Lookup volume type
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;
35
36 # Find free space
37 ($asrv,$apart) = &afs_find($cell,$type,$quota);
38 die "Unable to find space to create $vname in $cell\n" unless ($asrv&&$apart);
39
40 # Create volume
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");
44
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");
50
51 # Obtain user/group information
52 $uid = $gid = 0;
53 open(PTS, "$pts ex $user -cell $cell|");
54 chop($_ = <PTS>);
55 close(PTS);
56 ($uid,$uid,$uid,$uid) = split(/[:,] /, $_) unless ($?);
57
58 open(PTS, "$pts ex system:$group -cell $cell|");
59 chop($_ = <PTS>);
60 close(PTS);
61 ($gid,$gid,$gid,$gid) = split(/[:,] /, $_) unless ($?);
62 $gid = 0-$gid;
63
64 # Dispatch to the cell-specific creation routines
65 eval "&$proc{$cell}";
66 &fatal($@) if ($@);
67
68 # Set the filesystem quota
69 system("$fs sq $path $quota");
70 &fatal("Unable to set the quota on $path") if ($?);
71
72 # Release the parent volume
73 ($p = $path) =~ s:/[^/]+$::;
74 open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
75 chop($_ = <FS>);
76 close(FS);
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");
81
82 &afs_quota_adj($cell,$asrv,$apart,$quota);
83 exit(0);
84
85 sub fatal
86 {
87     local($cmd);
88     $_ = join(' ',@_);
89     s/\n$//;
90
91     while (@clean) {
92         $cmd = pop(@clean);
93         warn "$locker: Cleanup failed: $cmd\n" if (system("$cmd"));
94     }
95     die "$locker: $_\n";
96 }
97
98 # Cell specific procedures
99 sub athena_proc
100 {
101     # Default acls:
102     #
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
108     # HOMEDIR   <user> all
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     #
114     # Notes:
115     # 1. All directories also have "system:expunge ld".
116
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)/);
130
131     if ($type !~ /^(AREF|SYSTEM)/) {
132         system("$fs mkm $path/OldFiles $vname.backup");
133         warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
134     }
135
136     if ($type eq "HOMEDIR") {
137         die "Unable to get uid for user\n" unless ($uid);
138
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";
147
148         opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
149         @files=readdir(DIR);
150         closedir(DIR);
151
152         for $i (@files) {
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 $_; };
158             close(OUT);
159             close(IN);
160             chown($uid,0,"$path/$i");
161         }
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";
165         return;
166     }
167
168     system("$fs sa $path @acl -clear") &&
169         die "Unable to set acl of $path\n";
170 }
This page took 0.048645 seconds and 5 git commands to generate.