Merge branch 'master' of ssh://jolly@www.mISDN.org/var/git/lcr
[lcr.git] / wizzard.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** installation wizzard                                                      **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 char *check_mISDN(void)
17 {
18 }
19
20 char *install_mISDN(void)
21 {
22 }
23
24 char *check_kernel(void)
25 {
26 }
27
28 char *install_kernel(void)
29 {
30 }
31
32 char *check_includes(void)
33 {
34 }
35
36 char *install_includes(void)
37 {
38 }
39
40 char *check_device(void)
41 {
42 }
43
44 char *install_device(void)
45 {
46 }
47
48 char *check_lib(void)
49 {
50 }
51
52 char *install_lib(void)
53 {
54 }
55
56 char *check_isdnnet(void)
57 {
58 }
59
60 char *install_isdnnet(void)
61 {
62 }
63
64 char *check_pbx(void)
65 {
66 }
67
68 char *install_pbx(void)
69 {
70 }
71
72 char *check_mISDNrc(void)
73 {
74 }
75
76 char *install_mISDNrc(void)
77 {
78 }
79
80
81 struct jobs {
82         char *name;
83         (char *(check))(void);
84         (char *(install))(void);
85 } jobs[] = {
86         { "Install mISDN to kernel Source.", check_mISDN, install_mISDN },
87         { "Compile and install Kernel.", check_kernel, install_kernel },
88         { "Copy user space includes.", check_includes, install_includes },
89         { "Create \"/dev/mISDN\" device", check_device, install_device },
90         { "Compile mISDN device library.", check_lib, install_lib },
91         { "Compile mISDN NT-mode library.", check_isdnnet, install_isdnnet },
92         { "Compile and install PBX4Linux.", check_pbx, install_pbx },
93         { "Create mISDNrc to load mISDN.", check_mISDNrc, install_mISDNrc },
94         { NULL, NULL, NULL},
95 };
96
97
98 int main(int argc, char *argv[])
99 {
100         int allok = 1;
101         int i;
102         char *ret;
103         char input[256];
104
105         printf("\nWelcome to PBX4Linux installation wizzard.\n\n");
106
107         again:
108
109         /* check what to do */
110         i = 0;
111         while(jobs[i].name)
112         {
113                 printf("Checking: %s - ", jobs[i].name);
114                 fflush(stdout);
115                 ret = jobs[i].check();
116                 if (ret == NULL)
117                         printf("OK\n");
118                 else {
119                         printf("%s\n", ret);
120                         allok = 0;
121                 }
122                 i++;
123         }
124
125         /* if all ok */
126         if (allok)
127         {
128                 printf("\nEverything seems to be correctly installed. Do you like to continue? (y/n)");
129                 fflush(stdout);
130                 do {
131                         scanf("%s", input);
132                 } while(input[0] != 'y' && input[0] != 'n');
133                 if (input[0] == 'n')
134                         return(0);
135                 
136         }
137
138         /* select installation step(s) */
139         printf("\nPlease select one of the following install options:\n");
140         printf("a - Complete installation with all of the following steps\n");
141         i = 0;
142         while(jobs[i].name)
143         {
144                 printf("%d - Step %d: %s\n", i+1, i+1, jobs[i].name);
145                 i++;
146         }
147         printf("x - Exit wizzard.\n");
148         printf("\n(a/1-%d/x)", i);
149         fflush(stdout);
150         do {
151                 scanf("%s", input);
152         } while(input[0]!='a' && (input[0]<'1' || input[0]>('0'+i)) && input[0]!='x');
153         if (input[0] == 'x')
154                 return(0);
155         i = 0;
156         while(jobs[i].name)
157         {
158                 if (input[0]=='a' || (input[0]-'1')==i)
159                 {
160                         printf("\nDoing Step %d: %s\n", i+1, jobs[i].name);
161                         ret = jobs[i].check();
162                         if (ret)
163                                 printf("It is required to continue with this step. Dou you want to continue? (y/n)");
164                         else
165                                 printf("It is not required to continue with this step. Still want to continue? (y/n)");
166                         fflush(stdout);
167                         do {
168                                 scanf("%s", input);
169                         } while(input[0] != 'y' && input[0] != 'n');
170                         if (input[0] == 'n')
171                                 i++;
172                                 continue;
173                         }
174                         ret = jobs[i].install();
175                         if (ret)
176                         {
177                                 printf("Failed to install step: %s\n", jobs[i].name);
178                                 printf("%s\n", ret);
179                                 printf("Do you like to retry? (y/n)");
180                                 fflush(stdout);
181                                 do {
182                                         scanf("%s", input);
183                                 } while(input[0] != 'y' && input[0] != 'n');
184                                 if (input[0] == 'y')
185                                         continue;
186                                 }
187                                 break;
188                         }
189                 i++;
190         }
191         goto again;
192 }
193
194