d078a5258b7bca8f106359ef04bf0270cc7f19ac
[people/teissler/ipfire-2.x.git] / src / install+setup / setup / main.c
1 /* SmoothWall setup program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * Contains main entry point, and misc functions.
8 *
9 */
10
11 #include "setup.h"
12
13 FILE *flog = NULL;
14 char *mylog;
15
16 char **ctr = NULL;
17
18 int automode = 0;
19
20 struct nic nics[20] = { { "" , "" , "" , "" } };
21 struct knic knics[20] = { { "" , "" , "" , "" } };
22
23 extern char *en_tr[];
24 extern char *de_tr[];
25 extern char *fr_tr[];
26 extern char *es_tr[];
27 extern char *pl_tr[];
28 extern char *ru_tr[];
29 extern char *nl_tr[];
30
31 int main(int argc, char *argv[])
32 {
33 #ifdef LANG_EN_ONLY
34 char *shortlangnames[] = { "en", NULL };
35 char **langtrs[] = { en_tr, NULL };
36 #else
37 char *shortlangnames[] = { "de", "en", "fr", "es", "nl", "pl", "ru", NULL };
38 char **langtrs[] = { de_tr, en_tr, fr_tr, es_tr, nl_tr, pl_tr, ru_tr, NULL };
39 #endif
40 int choice;
41 char *sections[11]; /* need to fill this out AFTER knowning lang */
42 int rc;
43 struct keyvalue *kv;
44 char selectedshortlang[STRING_SIZE] = "en";
45 char title[STRING_SIZE];
46 int langcounter;
47 int autook = 0;
48
49 /* Log file/terminal stuff. */
50 if (argc >= 2)
51 mylog = argv[1];
52 else
53 mylog = strdup("/var/log/setup.log");
54
55 if (!(flog = fopen(mylog, "w+")))
56 {
57 printf("Couldn't open log terminal\n");
58 return 1;
59 }
60
61 if (argc >= 3)
62 automode = 1;
63
64 fprintf(flog, "Setup program started.\n");
65
66 if (!setlocale(LC_CTYPE,""))
67 fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL.");
68
69 kv = initkeyvalues();
70 if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
71 {
72 printf("%s is not properly installed.\n", NAME);
73 return 1;
74 }
75 findkey(kv, "LANGUAGE", selectedshortlang);
76
77 for (langcounter = 0; langtrs[langcounter]; langcounter++)
78 {
79 if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0)
80 {
81 ctr = langtrs[langcounter];
82 break;
83 }
84 }
85
86 if (!ctr)
87 {
88 for (choice = 0; shortlangnames[choice]; choice++)
89 {
90 if (strcmp(shortlangnames[choice], "en") == 0)
91 break;
92 }
93 if (!shortlangnames[choice])
94 goto EXIT;
95 ctr = langtrs[choice];
96 }
97
98 sections[0] = ctr[TR_KEYBOARD_MAPPING];
99 sections[1] = ctr[TR_TIMEZONE];
100 sections[2] = ctr[TR_HOSTNAME];
101 sections[3] = ctr[TR_DOMAINNAME];
102 sections[4] = ctr[TR_NETWORKING];
103 sections[5] = ctr[TR_ISDN];
104 sections[6] = ctr[TR_ROOT_PASSWORD];
105 sections[7] = ctr[TR_ADMIN_PASSWORD];
106 sections[8] = NULL;
107
108 newtInit();
109 newtCls();
110 FILE *f_title;
111 if ((f_title = fopen ("/etc/issue", "r")))
112 {
113 fgets (title, STRING_SIZE, f_title);
114 if (title[strlen(title) - 1] == '\n')
115 title[strlen(title) - 1] = '\0';
116 fclose (f_title);
117 } else {
118 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
119 }
120 newtDrawRootText(14, 0, title);
121 newtPushHelpLine(ctr[TR_HELPLINE]);
122
123 if (automode == 0)
124 {
125 choice = 0;
126 for (;;)
127 {
128 rc = newtWinMenu(ctr[TR_SECTION_MENU],
129 ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 11,
130 sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
131
132 if (rc == 2)
133 break;
134
135 switch (choice)
136 {
137 case 0:
138 handlekeymap();
139 break;
140
141 case 1:
142 handletimezone();
143 break;
144
145 case 2:
146 handlehostname();
147 break;
148
149 case 3:
150 handledomainname();
151 break;
152
153 case 4:
154 handlenetworking();
155 break;
156
157 case 5:
158 handleisdn();
159 break;
160
161 case 6:
162 handlerootpassword();
163 break;
164
165 case 7:
166 handleadminpassword();
167 break;
168
169 default:
170 break;
171 }
172 }
173 }
174 else
175 {
176 if (!(handlekeymap()))
177 goto EXIT;
178 if (!(handletimezone()))
179 goto EXIT;
180 if (!(handlehostname()))
181 goto EXIT;
182 if (!(handledomainname()))
183 goto EXIT;
184 if (!(handlerootpassword()))
185 goto EXIT;
186 if (!(handleadminpassword()))
187 goto EXIT;
188 if (!(handleisdn()))
189 goto EXIT;
190 if (!(handlenetworking()))
191 goto EXIT;
192 if (!(handledhcp()))
193 goto EXIT;
194
195 autook = 1;
196 }
197
198 EXIT:
199 if (automode != 0)
200 {
201 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
202 if (autook)
203 newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
204 else
205 {
206 newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
207
208 fprintf(flog, "Setup program has not finished.\n");
209 fflush(flog);
210 fclose(flog);
211
212 newtFinished();
213
214 return 1;
215 }
216 }
217
218 fprintf(flog, "Setup program ended.\n");
219 fflush(flog);
220 fclose(flog);
221
222 newtFinished();
223
224 return 0;
225 }