]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/install+setup/setup/main.c
firstsetup: add reboot if setup was not finnished.
[people/pmueller/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[];
8af06406
HS
27
28int main(int argc, char *argv[])
29{
30#ifdef LANG_EN_ONLY
31 char *shortlangnames[] = { "en", NULL };
32 char **langtrs[] = { en_tr, NULL };
8af06406 33#else
38a76ff4
AF
34 char *shortlangnames[] = { "de", "en", "fr", "es", NULL };
35 char **langtrs[] = { de_tr, en_tr, fr_tr, es_tr, NULL };
8af06406
HS
36#endif
37 int choice;
38 char *sections[11]; /* need to fill this out AFTER knowning lang */
39 int rc;
40 struct keyvalue *kv;
41 char selectedshortlang[STRING_SIZE] = "en";
42 char title[STRING_SIZE];
43 int langcounter;
44 int autook = 0;
45
46 /* Log file/terminal stuff. */
47 if (argc >= 2)
48 mylog = argv[1];
49 else
069680ac 50 mylog = strdup("/var/log/setup.log");
8af06406
HS
51
52 if (!(flog = fopen(mylog, "w+")))
53 {
54 printf("Couldn't open log terminal\n");
55 return 1;
56 }
57
58 if (argc >= 3)
59 automode = 1;
60
61 fprintf(flog, "Setup program started.\n");
62
9b040aa0
HS
63 if (!setlocale(LC_CTYPE,""))
64 fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL.");
65
8af06406
HS
66 kv = initkeyvalues();
67 if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
68 {
69 printf("%s is not properly installed.\n", NAME);
70 return 1;
71 }
72 findkey(kv, "LANGUAGE", selectedshortlang);
73
74 for (langcounter = 0; langtrs[langcounter]; langcounter++)
75 {
76 if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0)
77 {
78 ctr = langtrs[langcounter];
79 break;
80 }
81 }
82
83 if (!ctr)
84 {
8af06406
HS
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];
ca385da6 99 sections[4] = ctr[TR_NETWORKING];
bba7212c
MT
100 sections[5] = ctr[TR_ISDN];
101 sections[6] = ctr[TR_ROOT_PASSWORD];
102 sections[7] = ctr[TR_ADMIN_PASSWORD];
103 sections[8] = NULL;
8af06406
HS
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 {
069680ac 115 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
8af06406
HS
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:
8af06406
HS
151 handlenetworking();
152 break;
bba7212c 153
ca385da6 154 case 5:
bba7212c
MT
155 handleisdn();
156 break;
157
158 case 6:
8af06406
HS
159 handlerootpassword();
160 break;
161
bba7212c 162 case 7:
8af06406
HS
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;
71a5950f 181 if (!(handlerootpassword()))
8af06406 182 goto EXIT;
71a5950f 183 if (!(handleadminpassword()))
bba7212c 184 goto EXIT;
71a5950f 185 if (!(handleisdn()))
8af06406 186 goto EXIT;
71a5950f 187 if (!(handlenetworking()))
8af06406 188 goto EXIT;
71a5950f 189 if (!(handledhcp()))
8af06406
HS
190 goto EXIT;
191
192 autook = 1;
193 }
194
195EXIT:
196 if (automode != 0)
197 {
069680ac 198 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
8af06406
HS
199 if (autook)
200 newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
201 else
e238e4c2 202 {
8af06406 203 newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
e238e4c2
AF
204
205 fprintf(flog, "Setup program not finnished.\n");
206 fflush(flog);
207 fclose(flog);
208
209 newtFinished();
210
211 return 1;
212 }
8af06406 213 }
069680ac 214
8af06406
HS
215 fprintf(flog, "Setup program ended.\n");
216 fflush(flog);
217 fclose(flog);
069680ac 218
8af06406
HS
219 newtFinished();
220
221 return 0;
222}