]> git.ipfire.org Git - ipfire-2.x.git/blame - src/install+setup/setup/main.c
Merge branch 'iptables-upnpfw' into core67-merge
[ipfire-2.x.git] / src / install+setup / setup / main.c
CommitLineData
8af06406
HS
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.
8af06406
HS
8 *
9 */
10
11#include "setup.h"
12
13FILE *flog = NULL;
14char *mylog;
15
16char **ctr = NULL;
17
18int automode = 0;
19
96ed9998 20struct nic nics[20] = { { "" , "" , "" , "" } };
f9cc0d70 21struct knic knics[20] = { { "" , "" , "" , "" } };
5057b611 22
8af06406 23extern char *en_tr[];
8af06406 24extern char *de_tr[];
462515e4 25extern char *fr_tr[];
38a76ff4 26extern char *es_tr[];
b6c9668f 27extern char *pl_tr[];
2bb7b134 28extern char *ru_tr[];
be82627d 29extern char *nl_tr[];
8af06406
HS
30
31int main(int argc, char *argv[])
32{
33#ifdef LANG_EN_ONLY
34 char *shortlangnames[] = { "en", NULL };
35 char **langtrs[] = { en_tr, NULL };
8af06406 36#else
be82627d
MT
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 };
8af06406
HS
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
069680ac 53 mylog = strdup("/var/log/setup.log");
8af06406
HS
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
9b040aa0
HS
66 if (!setlocale(LC_CTYPE,""))
67 fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL.");
68
8af06406
HS
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 {
8af06406
HS
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];
ca385da6 102 sections[4] = ctr[TR_NETWORKING];
bba7212c
MT
103 sections[5] = ctr[TR_ISDN];
104 sections[6] = ctr[TR_ROOT_PASSWORD];
105 sections[7] = ctr[TR_ADMIN_PASSWORD];
106 sections[8] = NULL;
8af06406
HS
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 {
069680ac 118 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
8af06406
HS
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:
8af06406
HS
154 handlenetworking();
155 break;
bba7212c 156
ca385da6 157 case 5:
bba7212c
MT
158 handleisdn();
159 break;
160
161 case 6:
8af06406
HS
162 handlerootpassword();
163 break;
164
bba7212c 165 case 7:
8af06406
HS
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;
71a5950f 184 if (!(handlerootpassword()))
8af06406 185 goto EXIT;
71a5950f 186 if (!(handleadminpassword()))
bba7212c 187 goto EXIT;
71a5950f 188 if (!(handleisdn()))
8af06406 189 goto EXIT;
71a5950f 190 if (!(handlenetworking()))
8af06406 191 goto EXIT;
71a5950f 192 if (!(handledhcp()))
8af06406
HS
193 goto EXIT;
194
195 autook = 1;
196 }
197
198EXIT:
199 if (automode != 0)
200 {
069680ac 201 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
8af06406
HS
202 if (autook)
203 newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
204 else
e238e4c2 205 {
8af06406 206 newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
e238e4c2 207
20fa8ccd 208 fprintf(flog, "Setup program has not finished.\n");
e238e4c2
AF
209 fflush(flog);
210 fclose(flog);
211
212 newtFinished();
213
214 return 1;
215 }
8af06406 216 }
069680ac 217
8af06406
HS
218 fprintf(flog, "Setup program ended.\n");
219 fflush(flog);
220 fclose(flog);
069680ac 221
8af06406
HS
222 newtFinished();
223
224 return 0;
225}