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