]> git.ipfire.org Git - ipfire-2.x.git/blob - src/setup/main.c
asterisk addon: update to 11.13.1
[ipfire-2.x.git] / src / 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 // Translation
12 #include <libintl.h>
13 #define _(x) dgettext("setup", x)
14
15 #include "setup.h"
16
17 FILE *flog = NULL;
18 char *mylog;
19
20 int automode = 0;
21
22 struct nic nics[20] = { { "" , "" , "" , "" } };
23 struct knic knics[20] = { { "" , "" , "" , "" } };
24
25 int main(int argc, char *argv[])
26 {
27 int choice;
28 char *sections[11]; /* need to fill this out AFTER knowning lang */
29 int rc;
30 struct keyvalue *kv;
31 char lang[STRING_SIZE] = "en_US.utf8";
32 char title[STRING_SIZE];
33 int langcounter;
34 int autook = 0;
35
36 /* Log file/terminal stuff. */
37 if (argc >= 2)
38 mylog = argv[1];
39 else
40 mylog = strdup("/var/log/setup.log");
41
42 if (!(flog = fopen(mylog, "w+")))
43 {
44 printf("Couldn't open log terminal\n");
45 return 1;
46 }
47
48 if (argc >= 3)
49 automode = 1;
50
51 fprintf(flog, "Setup program started.\n");
52
53 if (!setlocale(LC_CTYPE,""))
54 fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL.");
55
56 kv = initkeyvalues();
57 if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
58 {
59 printf("%s is not properly installed.\n", NAME);
60 return 1;
61 }
62 findkey(kv, "LANGUAGE", lang);
63
64 setlocale(LC_ALL, lang);
65 setenv("LANGUAGE", lang, 1);
66
67 sections[0] = _("Keyboard mapping");
68 sections[1] = _("Timezone");
69 sections[2] = _("Hostname");
70 sections[3] = _("Domain name");
71 sections[4] = _("Networking");
72 sections[5] = _("ISDN");
73 sections[6] = _("'root' password");
74 sections[7] = _("'admin' password");
75 sections[8] = NULL;
76
77 newtInit();
78 newtCls();
79 FILE *f_title;
80 if ((f_title = fopen ("/etc/issue", "r")))
81 {
82 fgets (title, STRING_SIZE, f_title);
83 if (title[strlen(title) - 1] == '\n')
84 title[strlen(title) - 1] = '\0';
85 fclose (f_title);
86 } else {
87 sprintf (title, "%s - %s", NAME, SLOGAN);
88 }
89 newtDrawRootText(14, 0, title);
90 newtPushHelpLine(_(" <Tab>/<Alt-Tab> between elements | <Space> selects"));
91
92 if (automode == 0)
93 {
94 choice = 0;
95 for (;;)
96 {
97 rc = newtWinMenu(_("Section menu"),
98 _("Select the item you wish to configure."), 50, 5, 5, 11,
99 sections, &choice, _("OK"), _("Quit"), NULL);
100
101 if (rc == 2)
102 break;
103
104 switch (choice)
105 {
106 case 0:
107 handlekeymap();
108 break;
109
110 case 1:
111 handletimezone();
112 break;
113
114 case 2:
115 handlehostname();
116 break;
117
118 case 3:
119 handledomainname();
120 break;
121
122 case 4:
123 handlenetworking();
124 break;
125
126 case 5:
127 handleisdn();
128 break;
129
130 case 6:
131 handlerootpassword();
132 break;
133
134 case 7:
135 handleadminpassword();
136 break;
137
138 default:
139 break;
140 }
141 }
142 }
143 else
144 {
145 if (!(handlekeymap()))
146 goto EXIT;
147 if (!(handletimezone()))
148 goto EXIT;
149 if (!(handlehostname()))
150 goto EXIT;
151 if (!(handledomainname()))
152 goto EXIT;
153 if (!(handlerootpassword()))
154 goto EXIT;
155 if (!(handleadminpassword()))
156 goto EXIT;
157 if (!(handleisdn()))
158 goto EXIT;
159 if (!(handlenetworking()))
160 goto EXIT;
161 if (!(handledhcp()))
162 goto EXIT;
163
164 autook = 1;
165 }
166
167 EXIT:
168 if (automode != 0)
169 {
170 sprintf (title, "%s - %s", NAME, SLOGAN);
171 if (autook)
172 newtWinMessage(title, _("OK"), _("Setup is complete."));
173 else {
174 newtWinMessage(_("Warning"), _("OK"),
175 _("Initial setup was not entirely complete. "
176 "You must ensure that Setup is properly finished by running "
177 "setup again at the shell."));
178
179 fprintf(flog, "Setup program has not finished.\n");
180 fflush(flog);
181 fclose(flog);
182
183 newtFinished();
184
185 return 1;
186 }
187 }
188
189 fprintf(flog, "Setup program ended.\n");
190 fflush(flog);
191 fclose(flog);
192
193 newtFinished();
194
195 return 0;
196 }