]> andersk Git - moira.git/blame - incremental/afs_create.pl
Adjusted retry delay of failed prdb updates from 2 to 5 seconds.
[moira.git] / incremental / afs_create.pl
CommitLineData
6231b320 1#!/afs/athena/contrib/perl/perl
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
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",
bc6ad793 19 "SYSTEM", "system",
9edc1a1d 20 "UROP", "urop",
6231b320 21 );
22
23%proc =
24 ("ATHENA.MIT.EDU", 'athena_proc' );
25
26umask(0);
27
28die "Usage: $0 locker type cell path user group\n" if (@ARGV != 6);
29($locker,$type,$cell,$path,$user,$group) = @ARGV;
30
31# Lookup volume type
32($c = $cell) =~ s/\./_/g;
33$vtype = eval "\$vtypes_$c{$type}";
34die "Cannot create $type volumes in $cell\n" unless $vtype;
35$vname = $vtype . "." . $locker;
36
37# Find free space
38($asrv,$apart) = &afs_find($cell,$type,$quota);
39die "Unable to find space to create $vname in $cell\n" unless ($asrv&&$apart);
40
41# Create volume
42system("$vos create $asrv $apart $vname -cell $cell >/dev/null") &&
43 &fatal("Unable to create $vname in $cell");
44push(@clean, "$vos remove $asrv $apart $vname -cell $cell >/dev/null");
45
46# Create mountpoint and set quota
47$path =~ s:^/afs/([^.]):/afs/.\1:;
48system("$fs checkb >/dev/null; $fs mkm $path $vname");
49&fatal("Unable to create $path") if ($?);
50push(@clean, "$fs rmm $path");
51
52# Obtain user/group information
53$uid = $gid = 0;
54open(PTS, "$pts ex $user -cell $cell|");
55chop($_ = <PTS>);
56close(PTS);
57($uid,$uid,$uid,$uid) = split(/[:,] /, $_) unless ($?);
58
59open(PTS, "$pts ex system:$group -cell $cell|");
60chop($_ = <PTS>);
61close(PTS);
62($gid,$gid,$gid,$gid) = split(/[:,] /, $_) unless ($?);
63$gid = 0-$gid;
64
65# Dispatch to the cell-specific creation routines
66eval "&$proc{$cell}";
67&fatal($@) if ($@);
68
69# Set the filesystem quota
70system("$fs sq $path $quota");
71&fatal("Unable to set the quota on $path") if ($?);
72
73# Release the parent volume
74($p = $path) =~ s:/[^/]+$::;
75open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
76chop($_ = <FS>);
77close(FS);
78&fatal("Can't get information about $p") if ($?);
79@tmp = (split(/ /,$_));
80system("$vos release $tmp[$#tmp] -cell $cell >/dev/null") &&
81 &fatal("Can't release $tmp[$#tmp] in cell $cell");
82
83&afs_quota_adj($cell,$asrv,$apart,$quota);
84exit(0);
85
86sub fatal
87{
88 local($cmd);
89 $_ = join(' ',@_);
90 s/\n$//;
91
92 while (@clean) {
93 $cmd = pop(@clean);
94 warn "$locker: Cleanup failed: $cmd\n" if (system("$cmd"));
95 }
96 die "$locker: $_\n";
97}
98
99# Cell specific procedures
100sub athena_proc
101{
102 # Default acls:
103 #
104 # ACTIVITY <user> all <group> all system:anyuser rl
105 # APROJ <user> all <group> all system:anyuser rl
106 # AREF <user> all <group> rl
107 # CONTRIB <user> all system:anyuser rl
108 # COURSE <user> all <group> all system:facdev all system:authuser rl
109 # HOMEDIR <user> all
110 # PROJECT <user> all <group> all
111 # REF <user> all system:anyuser rl
112 # SW <user> all system:swmaint all system:authuser rl
113 # SYSTEM system:administrators all system:anyuser rl
9edc1a1d 114 # UROP <user> all <group> all system:facdev all system:authuser rl
6231b320 115 #
116 # Notes:
117 # 1. All directories also have "system:expunge ld".
118
119 @acl=("system:expunge ld");
9edc1a1d 120 push(@acl,"system:facdev all") if ($type =~ /^(COURSE|UROP)/);
6231b320 121 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
122 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
123 push(@acl,"$user all")
9edc1a1d 124 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|PROJECT|REF|SW|UROP)/);
6231b320 125 push(@acl,"system:$group all")
9edc1a1d 126 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|PROJECT|UROP)/);
6231b320 127 push(@acl,"system:$group rl") if ($gid != -1 && $type =~ /^(AREF)/);
128 push(@acl,"system:authuser rl")
9edc1a1d 129 if ($type =~ /^(COURSE|SW|UROP)/);
6231b320 130 push(@acl,"system:anyuser rl")
131 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|REF|SYSTEM)/);
132
133 if ($type !~ /^(AREF|SYSTEM)/) {
134 system("$fs mkm $path/OldFiles $vname.backup");
135 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
136 }
137
138 if ($type eq "HOMEDIR") {
139 die "Unable to get uid for user\n" unless ($uid);
140
141 mkdir("$path/Public",0755) && chown($uid,0,"$path/Public") &&
142 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
143 chown($uid,0,"$path/Public","$path/Private","$path/Mail") ||
144 die "Unable to create subdirectories\n";
145 system("$fs sa $path/Public @acl system:anyuser rl -clear") &&
146 die "Unable to set acl on Public directory";
147 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
148 die "Unable to set acl on Private and/or Mail directories\n";
149
150 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
151 @files=readdir(DIR);
152 closedir(DIR);
153
154 for $i (@files) {
155 next if ($i eq "." || $i eq "..");
156 next unless -f "$protodir/$i";
157 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
158 open(OUT,">$path/$i") || die "Unable to create $i\n";
159 while ($_=<IN>) { print OUT $_; };
160 close(OUT);
161 close(IN);
162 chown($uid,0,"$path/$i");
163 }
164 chown($uid,0,$path) &&
165 system("$fs sa $path @acl system:anyuser l -clear") &&
166 die "Unable to set acl on top-level directory\n";
167 return;
168 }
169
170 system("$fs sa $path @acl -clear") &&
171 die "Unable to set acl of $path\n";
172}
This page took 0.069148 seconds and 5 git commands to generate.