]> andersk Git - moira.git/blame - incremental/afs_create.pl
Remove extra entries that are no longer in /afs/athena/service/afs_data
[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(/ /,$_));
69system("$vos release $tmp[$#tmp] -cell $cell >/dev/null") &&
70 &fatal("Can't release $tmp[$#tmp] in cell $cell");
71
72&afs_quota_adj($cell,$asrv,$apart,$quota);
73exit(0);
74
75sub fatal
76{
77 local($cmd);
78 $_ = join(' ',@_);
79 s/\n$//;
80
81 while (@clean) {
82 $cmd = pop(@clean);
83 warn "$locker: Cleanup failed: $cmd\n" if (system("$cmd"));
84 }
85 die "$locker: $_\n";
86}
87
88# Cell specific procedures
89sub athena_proc
90{
91 # Default acls:
92 #
93 # ACTIVITY <user> all <group> all system:anyuser rl
94 # APROJ <user> all <group> all system:anyuser rl
95 # AREF <user> all <group> rl
96 # CONTRIB <user> all system:anyuser rl
97 # COURSE <user> all <group> all system:facdev all system:authuser rl
98 # HOMEDIR <user> all
99 # PROJECT <user> all <group> all
100 # REF <user> all system:anyuser rl
101 # SW <user> all system:swmaint all system:authuser rl
102 # SYSTEM system:administrators all system:anyuser rl
9edc1a1d 103 # UROP <user> all <group> all system:facdev all system:authuser rl
6231b320 104 #
105 # Notes:
106 # 1. All directories also have "system:expunge ld".
107
108 @acl=("system:expunge ld");
9edc1a1d 109 push(@acl,"system:facdev all") if ($type =~ /^(COURSE|UROP)/);
6231b320 110 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
111 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
112 push(@acl,"$user all")
9edc1a1d 113 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|PROJECT|REF|SW|UROP)/);
6231b320 114 push(@acl,"system:$group all")
9edc1a1d 115 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|PROJECT|UROP)/);
6ff63c15 116 push(@acl,"system:$group rl") if ($gid != 0 && $type =~ /^(AREF)/);
6231b320 117 push(@acl,"system:authuser rl")
9edc1a1d 118 if ($type =~ /^(COURSE|SW|UROP)/);
6231b320 119 push(@acl,"system:anyuser rl")
120 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|REF|SYSTEM)/);
121
122 if ($type !~ /^(AREF|SYSTEM)/) {
123 system("$fs mkm $path/OldFiles $vname.backup");
124 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
125 }
126
6ff63c15 127 if ($type =~ /ACTIVITY|APROJ|PROJECT/) {
128 chown($gid,0,$path) ||
129 die "Unable to set volume ownership\n";
130 } elsif ($type =~ /HOMEDIR|UROP/) {
131 chown($uid,0,$path) ||
132 die "Unable to set volume ownership\n";
133 }
134
6231b320 135 if ($type eq "HOMEDIR") {
136 die "Unable to get uid for user\n" unless ($uid);
137
138 mkdir("$path/Public",0755) && chown($uid,0,"$path/Public") &&
139 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
140 chown($uid,0,"$path/Public","$path/Private","$path/Mail") ||
141 die "Unable to create subdirectories\n";
142 system("$fs sa $path/Public @acl system:anyuser rl -clear") &&
143 die "Unable to set acl on Public directory";
144 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
145 die "Unable to set acl on Private and/or Mail directories\n";
146
147 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
148 @files=readdir(DIR);
149 closedir(DIR);
150
151 for $i (@files) {
152 next if ($i eq "." || $i eq "..");
153 next unless -f "$protodir/$i";
154 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
155 open(OUT,">$path/$i") || die "Unable to create $i\n";
156 while ($_=<IN>) { print OUT $_; };
157 close(OUT);
158 close(IN);
159 chown($uid,0,"$path/$i");
160 }
6ff63c15 161 system("$fs sa $path @acl system:anyuser l -clear") &&
162 die "Unable to set acl on top-level directory\n";
6231b320 163 return;
164 }
165
166 system("$fs sa $path @acl -clear") &&
167 die "Unable to set acl of $path\n";
168}
This page took 0.076459 seconds and 5 git commands to generate.