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