]> code.citadel.org Git - citadel.git/blob - citadel/migratenet.c
* Threw a few more lines of code into migratenet.c
[citadel.git] / citadel / migratenet.c
1 /*
2  * $Id$
3  * 
4  * 5.80 to 5.90 migration utility for network files
5  *
6  */
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <sys/types.h>
13 #include <dirent.h>
14 #include <errno.h>
15 #include "citadel.h"
16 #include "ipc.h"
17 #include "tools.h"
18 #include "config.h"
19
20
21 void logoff(int code)
22 {
23         exit(code);
24 }
25
26 int main(int argc, char **argv)
27 {
28         char buf[SIZ];
29         char hostbuf[SIZ];
30         char portbuf[SIZ];
31         DIR *dp;
32         struct dirent *d;
33         long highest = 0L;
34         char room[SIZ];
35         long thighest;
36         FILE *fp;
37         FILE *tempfp;
38
39         printf("\n\n\n\n\n"
40 "This utility migrates your network settings (room sharing with other\n"
41 "Citadel systems) from 5.80 to 5.90.  You should only do this ONCE.  It\n"
42 "will ERASE your 5.80 configuration files when it is finished, and it will\n"
43 "ERASE any 5.90 configuration files that you have already set up.\n\n"
44 "Are you sure you want to do this? ");
45
46         gets(buf);
47         if (tolower(buf[0]) != 'y') exit(0);
48
49         get_config();
50
51         attach_to_server(argc, argv, hostbuf, portbuf);
52         serv_gets(buf);
53         printf("%s\n", &buf[4]);
54         if ( (buf[0]!='2') && (strncmp(buf,"551",3)) ) {
55                 fprintf(stderr, "%s: %s\n", argv[0], &buf[4]);
56                 logoff(atoi(buf));
57         }
58
59         sprintf(buf, "IPGM %d", config.c_ipgm_secret);
60         serv_puts(buf);
61         serv_gets(buf);
62         fprintf(stderr, "%s\n", &buf[4]);
63         if (buf[0] != '2') {
64                 exit(2);
65         }
66
67         if (chdir("network/systems") != 0) {
68                 perror("cannot chdir network/systems");
69                 exit(errno);
70         }
71
72         tempfp = tmpfile();
73         if (tempfp == NULL) {
74                 perror("cannot open temp file");
75                 exit(errno);
76         }
77
78         dp = opendir(".");
79         if (dp == NULL) {
80                 perror("cannot open directory");
81                 exit(errno);
82         }
83
84         while (d = readdir(dp), d != NULL) {
85                 fp = NULL;
86                 if ( (d->d_name[0] != '.') && strcasecmp(d->d_name, "CVS")) {
87                         fp = fopen(d->d_name, "r");
88                 }
89                 if (fp != NULL) {
90                         printf("*** Processing '%s'\n", d->d_name);
91                         while (fgets(room, sizeof room, fp),
92                                 fscanf(fp, "%ld\n", &thighest),
93                                 !feof(fp) ) {
94                                         room[strlen(room) - 1] = 0;
95                                         fprintf(tempfp, "%s|%s\n",
96                                                 room, d->d_name);
97                                         if (thighest > highest) {
98                                                 highest = thighest;
99                                         }
100                         }
101                         fclose(fp);
102                 }
103         }
104
105         closedir(dp);
106         fclose(tempfp);
107         return(0);
108 }
109
110
111