]>
Commit | Line | Data |
---|---|---|
1a4b03d5 | 1 | /* $Header$ */ |
2 | ||
3 | #include <stdio.h> | |
4 | #include <ctype.h> | |
5 | ||
6 | ||
7 | main(argc, argv) | |
8 | int argc; | |
9 | char **argv; | |
10 | { | |
11 | int debug = 0; | |
12 | FILE *input = stdin; | |
13 | char buf[1024], junk[129]; | |
14 | ## int cell, quota, cnt, mach, oquota, id, who; | |
15 | ## char name[81], type[9], volume[81], path[129], quotas[33]; | |
16 | ## char oname[129],otype[9]; | |
17 | char **arg = argv, *first_indir(), *second_indir(), *course_indir(); | |
18 | ||
19 | cnt = 0; | |
20 | ||
21 | while (++arg - argv < argc) { | |
22 | if (**arg == '-') { | |
23 | switch ((*arg)[1]) { | |
24 | case 'd': | |
25 | debug = atoi((*arg)[2] ? *arg+2 : *++arg); | |
26 | break; | |
27 | default: | |
28 | fprintf(stderr, "Usage: %s [-d level] [inputfile]\n", | |
29 | argv[0]); | |
30 | exit(1); | |
31 | } | |
32 | } else { | |
33 | input = fopen(*arg, "r"); | |
34 | if (input == NULL) { | |
35 | fprintf(stderr, "Unable to open in put file %s\n", *arg); | |
36 | exit(1); | |
37 | } | |
38 | } | |
39 | } | |
40 | ||
41 | if (debug > 4) | |
42 | setenv("ING_SET", "set printqry"); | |
43 | ||
44 | if (debug) { printf("Opening database..."); fflush(stdout);} | |
45 | ## ingres sms | |
46 | if (debug) printf("done.\n"); | |
47 | ||
48 | ## range of f is filesys | |
49 | ## range of m is machine | |
50 | ## range of q is #quota | |
51 | ## retrieve (cell = machine.mach_id) where machine.#name="ATHENA.MIT.EDU" | |
52 | ## retrieve (who = users.users_id) where users.login="root" | |
53 | ## begin transaction | |
54 | ||
55 | while (!feof(input)) { | |
56 | fgets(buf, sizeof(buf), input); | |
57 | if (sscanf(buf, "%s %s %s %s %s %s %s %s %s %s %s %s", | |
58 | name, type, junk, junk, junk, junk, | |
59 | quotas, junk, junk, junk, junk, junk) < 12) { | |
60 | fprintf(stderr, "unable to parse line: %s\n", buf); | |
61 | continue; | |
62 | } | |
63 | quota = atoi(quotas); | |
64 | if (!strcmp(type, "HOMEDIR")) { | |
65 | sprintf(path, "/afs/athena.mit.edu/user/%s/%s/%s", | |
66 | first_indir(name), second_indir(name), name); | |
67 | } else if (!strcmp(type, "COURSE")) { | |
68 | sprintf(path, "/afs/athena.mit.edu/course/%s/%s", | |
69 | course_indir(name), name); | |
70 | } else if (!strcmp(type, "ACTIVITY")) { | |
71 | sprintf(path, "/afs/athena.mit.edu/activity/%s/%s", | |
72 | first_indir(name), name); | |
73 | } else if (!strcmp(type, "APROJ")) { | |
74 | sprintf(path, "/afs/athena.mit.edu/astaff/project/%s", | |
75 | name); | |
76 | } else if (!strcmp(type, "PROJECT")) { | |
77 | sprintf(path, "/afs/athena.mit.edu/project/%s", | |
78 | name); | |
79 | } else if (!strcmp(type, "AREF")) { | |
80 | sprintf(path, "/afs/athena.mit.edu/astaff/reference/%s", | |
81 | name); | |
82 | } else if (!strcmp(type, "REF")) { | |
83 | sprintf(path, "/afs/athena.mit.edu/reference/%s", | |
84 | name); | |
85 | } else if (!strcmp(type, "CONTRIB")) { | |
86 | sprintf(path, "/afs/athena.mit.edu/contrib/%s", | |
87 | name); | |
88 | } else if (!strcmp(type, "SW")) { | |
89 | sprintf(path, "/afs/athena.mit.edu/software/%s", | |
90 | name); | |
91 | } else if (!strcmp(type, "SYSTEM")) { | |
92 | sprintf(path, "/afs/athena.mit.edu/system/%s", | |
93 | name); | |
94 | } else { | |
95 | fprintf(stderr, "Don't know how to deal with type %s\n", type); | |
96 | continue; | |
97 | } | |
98 | ## repeat retrieve (otype = f.#type, mach = f.mach_id, oname = f.#name) | |
99 | ## where f.label = @name { | |
100 | strtrim(oname); | |
101 | printf("changing FS %s (%s, %s on %d) to (AFS, %s)\n", | |
102 | name, type, oname, mach, path); | |
103 | ## } | |
104 | ## repeat replace f (phys_id=0, #type="AFS", mach_id=cell, | |
105 | ## #name=@path, modtime=date("now"), | |
106 | ## modby=who, modwith="migrate") | |
107 | ## where f.label = @name | |
108 | ## repeat retrieve (type = q.#type, id=q.entity_id, oquota=q.#quota) | |
109 | ## where q.filsys_id = f.filsys_id and f.label=@name { | |
110 | printf("removing quota (%d (%s %d) on %s)\n", | |
111 | oquota, type, id, name); | |
112 | ## } | |
113 | ## repeat delete q where q.filsys_id = f.filsys_id and f.label=@name | |
114 | printf("adding quota of %d on %s\n", quota, name); | |
115 | ## repeat append #quota (filsys_id = f.filsys_id, #type="ANY", | |
116 | ## entity_id=0, phys_id=0, | |
117 | ## #quota=@quota, modtime=date("now"), | |
118 | ## modby=who, modwith="migrate") | |
119 | ## where f.label= @name | |
120 | cnt++; | |
121 | } | |
122 | ||
123 | if (cnt > 0) { | |
124 | ## replace tblstats (updates = tblstats.updates + cnt, | |
125 | ## modtime = date("now")) | |
126 | ## where tblstats.tbl = "filesys" | |
127 | ## replace tblstats (updates = tblstats.updates + cnt, | |
128 | ## modtime = date("now")) | |
129 | ## where tblstats.tbl = "quota" | |
130 | } | |
131 | ||
132 | ## end transaction | |
133 | if (debug) printf("Done.\n"); | |
134 | exit(0); | |
135 | } | |
136 | ||
137 | ||
138 | char *first_indir(name) | |
139 | char *name; | |
140 | { | |
141 | static char buf[10]; | |
142 | ||
143 | if (islower(name[0])) | |
144 | sprintf(buf, "%c", name[0]); | |
145 | else | |
146 | sprintf(buf, "other"); | |
147 | return(buf); | |
148 | } | |
149 | ||
150 | char *second_indir(name) | |
151 | char *name; | |
152 | { | |
153 | static char buf[10]; | |
154 | ||
155 | if (islower(name[1])) | |
156 | sprintf(buf, "%c", name[1]); | |
157 | else | |
158 | sprintf(buf, "other"); | |
159 | return(buf); | |
160 | } | |
161 | ||
162 | char *course_indir(name) | |
163 | char *name; | |
164 | { | |
165 | static char buf[10]; | |
166 | char *src, *dst; | |
167 | ||
168 | dst = buf; | |
169 | for (src = name; *src && isdigit(*src); src++) | |
170 | *dst++ = *src; | |
171 | ||
172 | if (dst == buf) | |
173 | strcpy(buf, "other"); | |
174 | else | |
175 | *dst = 0; | |
176 | ||
177 | return(buf); | |
178 | } |