]> andersk Git - moira.git/blame - incremental/afs_create.pl
Forgot to setacl on www subdir, and do not want OldFiles for type ORG
[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
b22cf8b8 102 # ORG <user> all <group> all system:cwisfac all
6231b320 103 # PROJECT <user> all <group> all
104 # REF <user> all system:anyuser rl
105 # SW <user> all system:swmaint all system:authuser rl
106 # SYSTEM system:administrators all system:anyuser rl
9edc1a1d 107 # UROP <user> all <group> all system:facdev all system:authuser rl
6231b320 108 #
109 # Notes:
110 # 1. All directories also have "system:expunge ld".
111
112 @acl=("system:expunge ld");
9edc1a1d 113 push(@acl,"system:facdev all") if ($type =~ /^(COURSE|UROP)/);
6231b320 114 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
b22cf8b8 115 push(@acl,"system:cwisfac all") if ($type =~ /^(ORG)/);
6231b320 116 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
117 push(@acl,"$user all")
b22cf8b8 118 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|LEASE|ORG|PROJECT|REF|SW|UROP)/);
6231b320 119 push(@acl,"system:$group all")
b22cf8b8 120 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|ORG|PROJECT|UROP)/);
6ff63c15 121 push(@acl,"system:$group rl") if ($gid != 0 && $type =~ /^(AREF)/);
6231b320 122 push(@acl,"system:authuser rl")
9edc1a1d 123 if ($type =~ /^(COURSE|SW|UROP)/);
6231b320 124 push(@acl,"system:anyuser rl")
125 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|REF|SYSTEM)/);
126
1738dc4c 127 if ($type !~ /^(AREF|ORG|SYSTEM)/) {
6231b320 128 system("$fs mkm $path/OldFiles $vname.backup");
129 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
130 }
131
6ff63c15 132 if ($type =~ /ACTIVITY|APROJ|PROJECT/) {
133 chown($gid,0,$path) ||
134 die "Unable to set volume ownership\n";
135 } elsif ($type =~ /HOMEDIR|UROP/) {
136 chown($uid,0,$path) ||
137 die "Unable to set volume ownership\n";
138 }
139
b22cf8b8 140 if ($type eq "ORG") {
141 mkdir("$path/www",0755) || die "Unable to create subdirectories\n";
1738dc4c 142 system("$fs sa $path/www @acl system:anyuser rl -clear") &&
b22cf8b8 143 die "Unable to set acl on www directory\n";
144
145 system("$fs sa $path @acl system:anyuser l -clear") &&
146 die "Unable to set acl on top-level directory\n";
1738dc4c 147 return;
b22cf8b8 148 }
149
6231b320 150 if ($type eq "HOMEDIR") {
151 die "Unable to get uid for user\n" unless ($uid);
152
153 mkdir("$path/Public",0755) && chown($uid,0,"$path/Public") &&
154 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
155 chown($uid,0,"$path/Public","$path/Private","$path/Mail") ||
156 die "Unable to create subdirectories\n";
157 system("$fs sa $path/Public @acl system:anyuser rl -clear") &&
158 die "Unable to set acl on Public directory";
159 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
160 die "Unable to set acl on Private and/or Mail directories\n";
161
162 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
163 @files=readdir(DIR);
164 closedir(DIR);
165
166 for $i (@files) {
167 next if ($i eq "." || $i eq "..");
168 next unless -f "$protodir/$i";
169 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
170 open(OUT,">$path/$i") || die "Unable to create $i\n";
171 while ($_=<IN>) { print OUT $_; };
172 close(OUT);
173 close(IN);
174 chown($uid,0,"$path/$i");
175 }
6ff63c15 176 system("$fs sa $path @acl system:anyuser l -clear") &&
177 die "Unable to set acl on top-level directory\n";
6231b320 178 return;
179 }
180
181 system("$fs sa $path @acl -clear") &&
182 die "Unable to set acl of $path\n";
183}
This page took 0.135862 seconds and 5 git commands to generate.