]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/install+setup/setup/main.c
Neue Netzwerkdialoge sind zum ersten Test verfuegbar.
[people/pmueller/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 * modified 16/11/2002 eoberlander - French language added
10 *
11 * $Id: main.c,v 1.4.2.7 2005/12/01 20:13:08 eoberlander Exp $
12 *
13 */
14
15 #include "setup.h"
16
17 FILE *flog = NULL;
18 char *mylog;
19
20 char **ctr = NULL;
21
22 int automode = 0;
23
24 struct nic nics[20] = { { "" , "" } };
25 struct knic knics[20] = { { "" , "" , "" } };
26
27 extern char *en_tr[];
28 extern char *de_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", NULL };
37 char **langtrs[] = { de_tr, en_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 kv = initkeyvalues();
66 if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
67 {
68 printf("%s is not properly installed.\n", NAME);
69 return 1;
70 }
71 findkey(kv, "LANGUAGE", selectedshortlang);
72
73 for (langcounter = 0; langtrs[langcounter]; langcounter++)
74 {
75 if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0)
76 {
77 ctr = langtrs[langcounter];
78 break;
79 }
80 }
81
82 if (!ctr)
83 {
84 /* zh,lt,ro,ru,th languages not available in setup, so use English */
85 for (choice = 0; shortlangnames[choice]; choice++)
86 {
87 if (strcmp(shortlangnames[choice], "en") == 0)
88 break;
89 }
90 if (!shortlangnames[choice])
91 goto EXIT;
92 ctr = langtrs[choice];
93 }
94
95 sections[0] = ctr[TR_KEYBOARD_MAPPING];
96 sections[1] = ctr[TR_TIMEZONE];
97 sections[2] = ctr[TR_HOSTNAME];
98 sections[3] = ctr[TR_DOMAINNAME];
99 sections[4] = ctr[TR_ISDN_CONFIGURATION];
100 sections[5] = ctr[TR_NETWORKING];
101 sections[6] = ctr[TR_ROOT_PASSWORD];
102 sections[7] = ctr[TR_ADMIN_PASSWORD];
103 sections[8] = NULL;
104
105 newtInit();
106 newtCls();
107 FILE *f_title;
108 if ((f_title = fopen ("/etc/issue", "r")))
109 {
110 fgets (title, STRING_SIZE, f_title);
111 if (title[strlen(title) - 1] == '\n')
112 title[strlen(title) - 1] = '\0';
113 fclose (f_title);
114 } else {
115 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
116 }
117 newtDrawRootText(14, 0, title);
118 newtPushHelpLine(ctr[TR_HELPLINE]);
119
120 if (automode == 0)
121 {
122 choice = 0;
123 for (;;)
124 {
125 rc = newtWinMenu(ctr[TR_SECTION_MENU],
126 ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 11,
127 sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
128
129 if (rc == 2)
130 break;
131
132 switch (choice)
133 {
134 case 0:
135 handlekeymap();
136 break;
137
138 case 1:
139 handletimezone();
140 break;
141
142 case 2:
143 handlehostname();
144 break;
145
146 case 3:
147 handledomainname();
148 break;
149
150 case 4:
151 handleisdn();
152 break;
153
154 case 5:
155 handlenetworking();
156 break;
157
158 case 6:
159 handlerootpassword();
160 break;
161
162 case 7:
163 handleadminpassword();
164 break;
165
166 default:
167 break;
168 }
169 }
170 }
171 else
172 {
173 if (!(handlekeymap()))
174 goto EXIT;
175 if (!(handletimezone()))
176 goto EXIT;
177 if (!(handlehostname()))
178 goto EXIT;
179 if (!(handledomainname()))
180 goto EXIT;
181 if (!(handleisdn()))
182 goto EXIT;
183 if (!(handlenetworking()))
184 goto EXIT;
185 if (!(handledhcp()))
186 goto EXIT;
187 if (!(handlerootpassword()))
188 goto EXIT;
189 if (!(handleadminpassword()))
190 goto EXIT;
191
192 autook = 1;
193 }
194
195 EXIT:
196 if (automode != 0)
197 {
198 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
199 if (autook)
200 newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
201 else
202 newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
203 }
204
205 fprintf(flog, "Setup program ended.\n");
206 fflush(flog);
207 fclose(flog);
208
209 newtFinished();
210
211 return 0;
212 }
213