]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/install+setup/setup/main.c
mtools enfernt.
[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 */
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
26 int main(int argc, char *argv[])
27 {
28 #ifdef LANG_EN_ONLY
29 char *shortlangnames[] = { "en", NULL };
30 char **langtrs[] = { en_tr, NULL };
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
48 mylog = strdup("/var/log/setup.log");
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
61 if (!setlocale(LC_CTYPE,""))
62 fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL.");
63
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 {
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];
97 sections[4] = ctr[TR_NETWORKING];
98 sections[5] = ctr[TR_ROOT_PASSWORD];
99 sections[6] = ctr[TR_ADMIN_PASSWORD];
100 sections[7] = NULL;
101
102 newtInit();
103 newtCls();
104 FILE *f_title;
105 if ((f_title = fopen ("/etc/issue", "r")))
106 {
107 fgets (title, STRING_SIZE, f_title);
108 if (title[strlen(title) - 1] == '\n')
109 title[strlen(title) - 1] = '\0';
110 fclose (f_title);
111 } else {
112 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
113 }
114 newtDrawRootText(14, 0, title);
115 newtPushHelpLine(ctr[TR_HELPLINE]);
116
117 if (automode == 0)
118 {
119 choice = 0;
120 for (;;)
121 {
122 rc = newtWinMenu(ctr[TR_SECTION_MENU],
123 ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 11,
124 sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
125
126 if (rc == 2)
127 break;
128
129 switch (choice)
130 {
131 case 0:
132 handlekeymap();
133 break;
134
135 case 1:
136 handletimezone();
137 break;
138
139 case 2:
140 handlehostname();
141 break;
142
143 case 3:
144 handledomainname();
145 break;
146
147 case 4:
148 handlenetworking();
149 break;
150
151 case 5:
152 handlerootpassword();
153 break;
154
155 case 6:
156 handleadminpassword();
157 break;
158
159 default:
160 break;
161 }
162 }
163 }
164 else
165 {
166 if (!(handlekeymap()))
167 goto EXIT;
168 if (!(handletimezone()))
169 goto EXIT;
170 if (!(handlehostname()))
171 goto EXIT;
172 if (!(handledomainname()))
173 goto EXIT;
174 if (!(handlenetworking()))
175 goto EXIT;
176 if (!(handledhcp()))
177 goto EXIT;
178 if (!(handlerootpassword()))
179 goto EXIT;
180 if (!(handleadminpassword()))
181 goto EXIT;
182
183 autook = 1;
184 }
185
186 EXIT:
187 if (automode != 0)
188 {
189 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
190 if (autook)
191 newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
192 else
193 newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
194 }
195
196 fprintf(flog, "Setup program ended.\n");
197 fflush(flog);
198 fclose(flog);
199
200 newtFinished();
201
202 return 0;
203 }