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