]> git.ipfire.org Git - ipfire-2.x.git/blame - src/setup/main.c
IDS: Call helper script when red interface gets up
[ipfire-2.x.git] / src / 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
e1457ba0
MT
11// Translation
12#include <libintl.h>
13#define _(x) dgettext("setup", x)
14
8af06406
HS
15#include "setup.h"
16
17FILE *flog = NULL;
18char *mylog;
19
8af06406
HS
20int automode = 0;
21
96ed9998 22struct nic nics[20] = { { "" , "" , "" , "" } };
f9cc0d70 23struct knic knics[20] = { { "" , "" , "" , "" } };
5057b611 24
8af06406
HS
25int main(int argc, char *argv[])
26{
8af06406 27 int choice;
a350ea6d 28 char *sections[8]; /* need to fill this out AFTER knowning lang */
8af06406
HS
29 int rc;
30 struct keyvalue *kv;
782ae35d 31 char lang[STRING_SIZE] = "en_US.utf8";
8af06406
HS
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
069680ac 40 mylog = strdup("/var/log/setup.log");
8af06406
HS
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
9b040aa0
HS
53 if (!setlocale(LC_CTYPE,""))
54 fprintf(flog, "Locale not spezified. Check LANG, LC_CTYPE, RC_ALL.");
55
8af06406
HS
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 }
782ae35d 62 findkey(kv, "LANGUAGE", lang);
8af06406 63
782ae35d
MT
64 setlocale(LC_ALL, lang);
65 setenv("LANGUAGE", lang, 1);
8af06406 66
e1457ba0
MT
67 sections[0] = _("Keyboard mapping");
68 sections[1] = _("Timezone");
69 sections[2] = _("Hostname");
70 sections[3] = _("Domain name");
71 sections[4] = _("Networking");
a350ea6d
MT
72 sections[5] = _("'root' password");
73 sections[6] = _("'admin' password");
74 sections[7] = NULL;
8af06406
HS
75
76 newtInit();
77 newtCls();
78 FILE *f_title;
79 if ((f_title = fopen ("/etc/issue", "r")))
80 {
81 fgets (title, STRING_SIZE, f_title);
82 if (title[strlen(title) - 1] == '\n')
83 title[strlen(title) - 1] = '\0';
84 fclose (f_title);
85 } else {
d1782bf0 86 sprintf (title, "%s - %s", NAME, SLOGAN);
8af06406
HS
87 }
88 newtDrawRootText(14, 0, title);
e1457ba0 89 newtPushHelpLine(_(" <Tab>/<Alt-Tab> between elements | <Space> selects"));
8af06406
HS
90
91 if (automode == 0)
92 {
93 choice = 0;
94 for (;;)
95 {
e1457ba0
MT
96 rc = newtWinMenu(_("Section menu"),
97 _("Select the item you wish to configure."), 50, 5, 5, 11,
98 sections, &choice, _("OK"), _("Quit"), NULL);
8af06406
HS
99
100 if (rc == 2)
101 break;
102
103 switch (choice)
104 {
105 case 0:
106 handlekeymap();
107 break;
108
109 case 1:
110 handletimezone();
111 break;
112
113 case 2:
114 handlehostname();
115 break;
116
117 case 3:
118 handledomainname();
119 break;
120
121 case 4:
8af06406
HS
122 handlenetworking();
123 break;
bba7212c 124
ca385da6 125 case 5:
8af06406
HS
126 handlerootpassword();
127 break;
128
a350ea6d 129 case 6:
8af06406
HS
130 handleadminpassword();
131 break;
132
133 default:
134 break;
135 }
136 }
137 }
138 else
139 {
140 if (!(handlekeymap()))
141 goto EXIT;
142 if (!(handletimezone()))
143 goto EXIT;
144 if (!(handlehostname()))
145 goto EXIT;
146 if (!(handledomainname()))
147 goto EXIT;
71a5950f 148 if (!(handlerootpassword()))
8af06406 149 goto EXIT;
71a5950f 150 if (!(handleadminpassword()))
bba7212c 151 goto EXIT;
71a5950f 152 if (!(handlenetworking()))
8af06406 153 goto EXIT;
71a5950f 154 if (!(handledhcp()))
8af06406
HS
155 goto EXIT;
156
157 autook = 1;
158 }
159
e1457ba0 160EXIT:
8af06406
HS
161 if (automode != 0)
162 {
d1782bf0 163 sprintf (title, "%s - %s", NAME, SLOGAN);
8af06406 164 if (autook)
e1457ba0
MT
165 newtWinMessage(title, _("OK"), _("Setup is complete."));
166 else {
167 newtWinMessage(_("Warning"), _("OK"),
168 _("Initial setup was not entirely complete. "
169 "You must ensure that Setup is properly finished by running "
170 "setup again at the shell."));
e238e4c2 171
20fa8ccd 172 fprintf(flog, "Setup program has not finished.\n");
e238e4c2
AF
173 fflush(flog);
174 fclose(flog);
175
176 newtFinished();
177
178 return 1;
179 }
8af06406 180 }
069680ac 181
8af06406
HS
182 fprintf(flog, "Setup program ended.\n");
183 fflush(flog);
184 fclose(flog);
069680ac 185
8af06406
HS
186 newtFinished();
187
188 return 0;
189}