]>
Commit | Line | Data |
---|---|---|
2bb7b134 | 1 | |
d6aaa55d MT |
2 | /* SmoothWall install program. |
3 | * | |
4 | * This program is distributed under the terms of the GNU General Public | |
5 | * Licence. See the file COPYING for details. | |
6 | * | |
7 | * (c) Lawrence Manning, 2001 | |
f9cc0d70 | 8 | * Contains main entry point, and misc functions.6 |
d6aaa55d | 9 | * |
d6aaa55d | 10 | */ |
10bc6f06 | 11 | |
72d80898 | 12 | #define _GNU_SOURCE |
f0fa1795 MT |
13 | |
14 | #include <assert.h> | |
15 | #include <errno.h> | |
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
18 | #include <sys/mount.h> | |
19 | ||
20 | #include "hw.h" | |
21 | #include "install.h" | |
72d80898 | 22 | |
68561214 | 23 | #define INST_FILECOUNT 21000 |
33634aa8 | 24 | #define UNATTENDED_CONF "/cdrom/boot/unattended.conf" |
918546e2 | 25 | #define LICENSE_FILE "/cdrom/COPYING" |
d6aaa55d | 26 | |
d6aaa55d MT |
27 | FILE *flog = NULL; |
28 | char *mylog; | |
10bc6f06 | 29 | |
d6aaa55d MT |
30 | char **ctr; |
31 | ||
d6aaa55d MT |
32 | extern char url[STRING_SIZE]; |
33 | ||
f9cc0d70 HS |
34 | struct nic nics[20] = { { "" , "" , "" } }; // only defined for compile |
35 | struct knic knics[20] = { { "" , "" , "" , "" } }; // only defined for compile | |
5057b611 | 36 | |
10bc6f06 | 37 | extern char *en_tr[]; |
cf4dd3c0 | 38 | extern char *es_tr[]; |
10bc6f06 | 39 | extern char *de_tr[]; |
462515e4 | 40 | extern char *fr_tr[]; |
1d76272b | 41 | extern char *nl_tr[]; |
b6c9668f | 42 | extern char *pl_tr[]; |
2bb7b134 | 43 | extern char *ru_tr[]; |
910193da | 44 | extern char *tr_tr[]; |
d6aaa55d | 45 | |
d7dd283b MT |
46 | static int newtChecklist(const char* title, const char* message, |
47 | unsigned int width, unsigned int height, unsigned int num_entries, | |
48 | const char** entries, int* states) { | |
49 | int ret; | |
50 | const int list_height = 4; | |
51 | ||
52 | char cbstates[num_entries]; | |
53 | ||
54 | for (unsigned int i = 0; i < num_entries; i++) { | |
55 | cbstates[i] = states[i] ? '*' : ' '; | |
56 | } | |
57 | ||
58 | newtCenteredWindow(width, height, title); | |
59 | ||
60 | newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6 - list_height, | |
61 | NEWT_FLAG_WRAP); | |
62 | newtTextboxSetText(textbox, message); | |
63 | ||
64 | int top = newtTextboxGetNumLines(textbox) + 2; | |
65 | ||
66 | newtComponent form = newtForm(NULL, NULL, 0); | |
67 | ||
68 | newtComponent sb = NULL; | |
69 | if (list_height < num_entries) { | |
70 | sb = newtVerticalScrollbar( | |
71 | width - 4, top + 1, list_height, | |
72 | NEWT_COLORSET_CHECKBOX, NEWT_COLORSET_ACTCHECKBOX); | |
73 | ||
74 | newtFormAddComponent(form, sb); | |
75 | } | |
76 | ||
77 | newtComponent subform = newtForm(sb, NULL, 0); | |
78 | newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX); | |
79 | ||
80 | newtFormSetHeight(subform, list_height); | |
81 | newtFormSetWidth(subform, width - 10); | |
82 | ||
83 | for (unsigned int i = 0; i < num_entries; i++) { | |
84 | newtComponent cb = newtCheckbox(4, top + i, entries[i], cbstates[i], | |
85 | NULL, &cbstates[i]); | |
86 | ||
87 | newtFormAddComponent(subform, cb); | |
88 | } | |
89 | ||
90 | newtFormAddComponents(form, textbox, subform, NULL); | |
91 | ||
92 | newtComponent btn_okay = newtButton((width - 18) / 3, height - 4, ctr[TR_OK]); | |
93 | newtComponent btn_cancel = newtButton((width - 18) / 3 * 2 + 9, height - 4, ctr[TR_CANCEL]); | |
94 | newtFormAddComponents(form, btn_okay, btn_cancel, NULL); | |
95 | ||
96 | newtComponent answer = newtRunForm(form); | |
97 | ||
98 | if ((answer == NULL) || (answer == btn_cancel)) { | |
99 | ret = -1; | |
100 | } else { | |
101 | ret = 0; | |
102 | ||
103 | for (unsigned int i = 0; i < num_entries; i++) { | |
104 | states[i] = (cbstates[i] != ' '); | |
105 | ||
106 | if (states[i]) | |
107 | ret++; | |
108 | } | |
109 | } | |
110 | ||
111 | newtFormDestroy(form); | |
112 | newtPopWindow(); | |
113 | ||
114 | return ret; | |
115 | } | |
116 | ||
117 | static int newtWinOkCancel(const char* title, const char* message, int width, int height, | |
118 | const char* btn_txt_ok, const char* btn_txt_cancel) { | |
119 | int ret = 1; | |
120 | ||
121 | newtCenteredWindow(width, height, title); | |
122 | ||
123 | newtComponent form = newtForm(NULL, NULL, 0); | |
124 | ||
125 | newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6, NEWT_FLAG_WRAP); | |
126 | newtTextboxSetText(textbox, message); | |
127 | newtFormAddComponent(form, textbox); | |
128 | ||
129 | newtComponent btn_ok = newtButton((width - 16) / 3, height - 4, btn_txt_ok); | |
130 | newtComponent btn_cancel = newtButton((width - 16) / 3 * 2 + 9, height - 4, | |
131 | btn_txt_cancel); | |
132 | ||
133 | newtFormAddComponents(form, btn_ok, btn_cancel, NULL); | |
134 | ||
135 | newtComponent answer = newtRunForm(form); | |
136 | ||
137 | if (answer == btn_ok) { | |
138 | ret = 0; | |
139 | } | |
140 | ||
141 | newtFormDestroy(form); | |
142 | newtPopWindow(); | |
143 | ||
144 | return ret; | |
145 | } | |
146 | ||
bd5e7c29 MT |
147 | static int newtLicenseBox(const char* title, const char* text, int width, int height) { |
148 | int ret = 1; | |
149 | ||
150 | newtCenteredWindow(width, height, title); | |
151 | ||
152 | newtComponent form = newtForm(NULL, NULL, 0); | |
153 | ||
154 | newtComponent textbox = newtTextbox(1, 1, width - 2, height - 7, | |
155 | NEWT_FLAG_WRAP|NEWT_FLAG_SCROLL); | |
156 | newtTextboxSetText(textbox, text); | |
157 | newtFormAddComponent(form, textbox); | |
158 | ||
159 | char choice; | |
160 | newtComponent checkbox = newtCheckbox(3, height - 3, ctr[TR_LICENSE_ACCEPT], | |
161 | ' ', " *", &choice); | |
162 | ||
163 | newtComponent btn = newtButton(width - 15, height - 4, ctr[TR_OK]); | |
164 | ||
165 | newtFormAddComponents(form, checkbox, btn, NULL); | |
166 | ||
167 | newtComponent answer = newtRunForm(form); | |
168 | if (answer == btn && choice == '*') | |
169 | ret = 0; | |
170 | ||
171 | newtFormDestroy(form); | |
172 | newtPopWindow(); | |
173 | ||
174 | return ret; | |
175 | } | |
176 | ||
f0fa1795 MT |
177 | int main(int argc, char *argv[]) { |
178 | struct hw* hw = hw_init(); | |
e0bbaf87 AF |
179 | |
180 | char discl_msg[40000] = "Disclaimer\n"; | |
181 | ||
910193da EY |
182 | char *langnames[] = { "Deutsch", "English", "Français", "Español", "Nederlands", "Polski", "Русский", "Türkçe", NULL }; |
183 | char *shortlangnames[] = { "de", "en", "fr", "es", "nl", "pl", "ru", "tr", NULL }; | |
184 | char **langtrs[] = { de_tr, en_tr, fr_tr, es_tr, nl_tr, pl_tr, ru_tr, tr_tr, NULL }; | |
f0fa1795 | 185 | char* sourcedrive = NULL; |
72d80898 | 186 | int rc = 0; |
d6aaa55d | 187 | char commandstring[STRING_SIZE]; |
d6aaa55d MT |
188 | int choice; |
189 | char shortlangname[10]; | |
d7dd283b | 190 | char message[STRING_SIZE]; |
d6aaa55d MT |
191 | char title[STRING_SIZE]; |
192 | int allok = 0; | |
e0bbaf87 | 193 | FILE *handle, *cmdfile, *copying; |
d6aaa55d | 194 | char line[STRING_SIZE]; |
5057b611 | 195 | |
72d80898 | 196 | int unattended = 0; |
5faa66cf | 197 | int serialconsole = 0; |
72d80898 | 198 | struct keyvalue *unattendedkv = initkeyvalues(); |
66335974 | 199 | char restore_file[STRING_SIZE] = ""; |
d6aaa55d MT |
200 | |
201 | setlocale (LC_ALL, ""); | |
10bc6f06 | 202 | sethostname( SNAME , 10); |
72d80898 | 203 | |
d6aaa55d MT |
204 | /* Log file/terminal stuff. */ |
205 | if (argc >= 2) | |
206 | { | |
207 | if (!(flog = fopen(argv[1], "w+"))) | |
208 | return 0; | |
209 | } | |
210 | else | |
211 | return 0; | |
212 | ||
213 | mylog = argv[1]; | |
214 | ||
215 | fprintf(flog, "Install program started.\n"); | |
216 | ||
217 | newtInit(); | |
218 | newtCls(); | |
219 | ||
7ea444c8 AF |
220 | newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN ); |
221 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
222 | ||
d6aaa55d MT |
223 | if (! (cmdfile = fopen("/proc/cmdline", "r"))) |
224 | { | |
225 | fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); | |
226 | } else { | |
227 | fgets(line, STRING_SIZE, cmdfile); | |
61e3d218 | 228 | |
72d80898 | 229 | // check if we have to make an unattended install |
ee78a5ef | 230 | if (strstr (line, "unattended") != NULL) { |
72d80898 | 231 | unattended = 1; |
bba7212c MT |
232 | runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds..."); |
233 | } | |
5faa66cf AF |
234 | // check if we have to patch for serial console |
235 | if (strstr (line, "console=ttyS0") != NULL) { | |
236 | serialconsole = 1; | |
237 | } | |
d6aaa55d | 238 | } |
0db33b56 | 239 | |
7ea444c8 | 240 | // Load common modules |
bba7212c | 241 | mysystem("/sbin/modprobe vfat"); // USB key |
4a0d9bef MT |
242 | hw_stop_all_raid_arrays(); |
243 | ||
72d80898 | 244 | /* German is the default */ |
d6aaa55d MT |
245 | for (choice = 0; langnames[choice]; choice++) |
246 | { | |
215bd18d | 247 | if (strcmp(langnames[choice], "English") == 0) |
d6aaa55d MT |
248 | break; |
249 | } | |
250 | if (!langnames[choice]) | |
251 | goto EXIT; | |
252 | ||
72d80898 | 253 | if (!unattended) { |
51f3b7f5 | 254 | rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, |
72d80898 MT |
255 | langnames, &choice, "Ok", NULL); |
256 | } | |
257 | ||
d6aaa55d MT |
258 | ctr = langtrs[choice]; |
259 | strcpy(shortlangname, shortlangnames[choice]); | |
3d6e1202 | 260 | |
d6aaa55d | 261 | newtPushHelpLine(ctr[TR_HELPLINE]); |
0db33b56 | 262 | |
e0bbaf87 | 263 | if (!unattended) { |
c5685c24 MT |
264 | sprintf(message, ctr[TR_WELCOME], NAME); |
265 | newtWinMessage(title, ctr[TR_OK], message); | |
e0bbaf87 AF |
266 | } |
267 | ||
f0fa1795 MT |
268 | /* Search for a source drive that holds the right |
269 | * version of the image we are going to install. */ | |
270 | sourcedrive = hw_find_source_medium(hw); | |
9607771a | 271 | |
f0fa1795 MT |
272 | fprintf(flog, "Source drive: %s\n", sourcedrive); |
273 | if (!sourcedrive) { | |
0f680bcc | 274 | newtWinMessage(title, ctr[TR_OK], ctr[TR_NO_LOCAL_SOURCE]); |
f0fa1795 | 275 | runcommandwithstatus("/bin/downloadsource.sh", ctr[TR_DOWNLOADING_ISO]); |
0f680bcc AF |
276 | if ((handle = fopen("/tmp/source_device", "r")) == NULL) { |
277 | errorbox(ctr[TR_DOWNLOAD_ERROR]); | |
278 | goto EXIT; | |
279 | } | |
f0fa1795 MT |
280 | |
281 | fgets(sourcedrive, 5, handle); | |
282 | fclose(handle); | |
72d80898 | 283 | } |
0f680bcc | 284 | |
f0fa1795 MT |
285 | assert(sourcedrive); |
286 | ||
25fcce25 | 287 | int r = hw_mount(sourcedrive, SOURCE_MOUNT_PATH, "iso9660", MS_RDONLY); |
f0fa1795 MT |
288 | if (r) { |
289 | fprintf(flog, "Could not mount %s to %s\n", sourcedrive, SOURCE_MOUNT_PATH); | |
290 | fprintf(flog, strerror(errno)); | |
291 | exit(1); | |
292 | } | |
918546e2 | 293 | |
d7dd283b MT |
294 | /* load unattended configuration */ |
295 | if (unattended) { | |
296 | fprintf(flog, "unattended: Reading unattended.conf\n"); | |
297 | ||
298 | (void) readkeyvalues(unattendedkv, UNATTENDED_CONF); | |
299 | findkey(unattendedkv, "RESTORE_FILE", restore_file); | |
300 | } | |
301 | ||
918546e2 MT |
302 | if (!unattended) { |
303 | // Read the license file. | |
304 | if (!(copying = fopen(LICENSE_FILE, "r"))) { | |
305 | sprintf(discl_msg, "Could not open license file: %s\n", LICENSE_FILE); | |
306 | fprintf(flog, discl_msg); | |
307 | } else { | |
308 | fread(discl_msg, 1, 40000, copying); | |
309 | fclose(copying); | |
310 | ||
bd5e7c29 | 311 | if (newtLicenseBox(title, discl_msg, 75, 20)) { |
918546e2 | 312 | errorbox(ctr[TR_LICENSE_NOT_ACCEPTED]); |
bd5e7c29 | 313 | |
918546e2 MT |
314 | goto EXIT; |
315 | } | |
316 | } | |
317 | } | |
318 | ||
d7dd283b | 319 | int part_type = HW_PART_TYPE_NORMAL; |
ee78a5ef | 320 | |
d7dd283b MT |
321 | // Scan for disks to install on. |
322 | struct hw_disk** disks = hw_find_disks(hw); | |
323 | ||
324 | struct hw_disk** selected_disks = NULL; | |
325 | unsigned int num_selected_disks = 0; | |
326 | ||
327 | // Check how many disks have been found and what | |
328 | // we can do with them. | |
329 | unsigned int num_disks = hw_count_disks(disks); | |
330 | ||
331 | while (1) { | |
332 | // no harddisks found | |
333 | if (num_disks == 0) { | |
334 | errorbox(ctr[TR_NO_HARDDISK]); | |
335 | goto EXIT; | |
336 | ||
337 | // exactly one disk has been found | |
338 | } else if (num_disks == 1) { | |
339 | selected_disks = hw_select_disks(disks, NULL); | |
340 | ||
341 | // more than one usable disk has been found and | |
342 | // the user needs to choose what to do with them | |
343 | } else { | |
344 | const char* disk_names[num_disks]; | |
345 | int disk_selection[num_disks]; | |
346 | ||
347 | for (unsigned int i = 0; i < num_disks; i++) { | |
348 | disk_names[i] = &disks[i]->description; | |
349 | disk_selection[i] = 0; | |
350 | } | |
351 | ||
352 | while (!selected_disks) { | |
353 | rc = newtChecklist(ctr[TR_DISK_SELECTION], ctr[TR_DISK_SELECTION_MSG], | |
354 | 50, 20, num_disks, disk_names, disk_selection); | |
355 | ||
356 | // Error | |
357 | if (rc < 0) { | |
358 | goto EXIT; | |
359 | ||
360 | // Nothing has been selected | |
361 | } else if (rc == 0) { | |
362 | errorbox(ctr[TR_NO_DISK_SELECTED]); | |
363 | ||
364 | } else { | |
365 | selected_disks = hw_select_disks(disks, disk_selection); | |
366 | } | |
367 | } | |
368 | } | |
369 | ||
370 | num_selected_disks = hw_count_disks(selected_disks); | |
371 | ||
372 | if (num_selected_disks == 1) { | |
373 | snprintf(message, sizeof(message), ctr[TR_DISK_SETUP_DESC], (*selected_disks)->description); | |
374 | rc = newtWinOkCancel(ctr[TR_DISK_SETUP], message, 50, 10, | |
375 | ctr[TR_DELETE_ALL_DATA], ctr[TR_CANCEL]); | |
376 | ||
377 | if (rc == 0) | |
56b548f1 | 378 | break; |
d7dd283b MT |
379 | |
380 | } else if (num_selected_disks == 2) { | |
381 | snprintf(message, sizeof(message), ctr[TR_RAID_SETUP_DESC], | |
382 | (*selected_disks)->description, (*selected_disks + 1)->description); | |
383 | rc = newtWinOkCancel(ctr[TR_RAID_SETUP], message, 50, 10, | |
384 | ctr[TR_DELETE_ALL_DATA], ctr[TR_CANCEL]); | |
385 | ||
386 | if (rc == 0) { | |
387 | part_type = HW_PART_TYPE_RAID1; | |
388 | ||
ee78a5ef | 389 | break; |
d7dd283b MT |
390 | } |
391 | ||
392 | // Currently not supported | |
393 | } else { | |
394 | errorbox(ctr[TR_DISK_CONFIGURATION_NOT_SUPPORTED]); | |
aee3027d | 395 | } |
ee78a5ef | 396 | |
d7dd283b MT |
397 | if (selected_disks) { |
398 | hw_free_disks(selected_disks); | |
399 | selected_disks = NULL; | |
400 | } | |
212cab4f | 401 | } |
212cab4f | 402 | |
d7dd283b | 403 | hw_free_disks(disks); |
72d80898 | 404 | |
d7dd283b | 405 | struct hw_destination* destination = hw_make_destination(part_type, selected_disks); |
5057b611 | 406 | |
25fcce25 MT |
407 | if (!destination) { |
408 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
cd8dd8dd | 409 | goto EXIT; |
25fcce25 | 410 | } |
cd8dd8dd | 411 | |
25fcce25 MT |
412 | fprintf(flog, "Destination drive: %s\n", destination->path); |
413 | fprintf(flog, " boot: %s (%lluMB)\n", destination->part_boot, BYTES2MB(destination->size_boot)); | |
414 | fprintf(flog, " swap: %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap)); | |
415 | fprintf(flog, " root: %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root)); | |
416 | fprintf(flog, " data: %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data)); | |
72d80898 | 417 | |
25fcce25 MT |
418 | // Warn the user if there is not enough space to create a swap partition |
419 | if (!unattended && !*destination->part_swap) { | |
420 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
4f26ff7f | 421 | |
25fcce25 MT |
422 | if (rc != 1) |
423 | goto EXIT; | |
72d80898 | 424 | } |
9a3d3d95 | 425 | |
25fcce25 MT |
426 | // Filesystem selection |
427 | if (!unattended) { | |
428 | struct filesystems { | |
429 | int fstype; | |
430 | const char* description; | |
431 | } filesystems[] = { | |
432 | { HW_FS_EXT4, ctr[TR_EXT4FS] }, | |
433 | { HW_FS_EXT4_WO_JOURNAL, ctr[TR_EXT4FS_WO_JOURNAL] }, | |
434 | { HW_FS_REISERFS, ctr[TR_REISERFS] }, | |
435 | { 0, NULL }, | |
436 | }; | |
437 | unsigned int num_filesystems = sizeof(filesystems) / sizeof(*filesystems); | |
438 | ||
439 | char* fs_names[num_filesystems]; | |
440 | int fs_choice = 0; | |
441 | for (unsigned int i = 0; i < num_filesystems; i++) { | |
442 | if (HW_FS_DEFAULT == filesystems[i].fstype) | |
443 | fs_choice = i; | |
444 | ||
445 | fs_names[i] = filesystems[i].description; | |
446 | } | |
72d80898 | 447 | |
25fcce25 MT |
448 | rc = newtWinMenu(ctr[TR_CHOOSE_FILESYSTEM], ctr[TR_CHOOSE_FILESYSTEM], |
449 | 50, 5, 5, 6, fs_names, &fs_choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); | |
450 | ||
451 | if (rc == 0) | |
452 | destination->filesystem = filesystems[fs_choice].fstype; | |
72d80898 | 453 | |
25fcce25 | 454 | else |
72d80898 | 455 | goto EXIT; |
72d80898 MT |
456 | } |
457 | ||
4a0d9bef MT |
458 | // Setting up RAID if needed. |
459 | if (destination->is_raid) { | |
460 | statuswindow(60, 4, title, ctr[TR_BUILDING_RAID]); | |
461 | ||
462 | rc = hw_setup_raid(destination); | |
463 | if (rc) { | |
464 | errorbox(ctr[TR_UNABLE_TO_BUILD_RAID]); | |
465 | goto EXIT; | |
466 | } | |
467 | ||
468 | newtPopWindow(); | |
469 | } | |
470 | ||
25fcce25 MT |
471 | // Execute the partitioning... |
472 | statuswindow(60, 4, title, ctr[TR_PARTITIONING_DISK]); | |
72d80898 | 473 | |
25fcce25 MT |
474 | rc = hw_create_partitions(destination); |
475 | if (rc) { | |
476 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
72d80898 | 477 | goto EXIT; |
9607771a | 478 | } |
72d80898 | 479 | |
25fcce25 | 480 | newtPopWindow(); |
72d80898 | 481 | |
25fcce25 MT |
482 | // Execute the formatting... |
483 | statuswindow(60, 4, title, ctr[TR_CREATING_FILESYSTEMS]); | |
b8e2d108 | 484 | |
25fcce25 MT |
485 | rc = hw_create_filesystems(destination); |
486 | if (rc) { | |
487 | errorbox(ctr[TR_UNABLE_TO_CREATE_FILESYSTEMS]); | |
72d80898 MT |
488 | goto EXIT; |
489 | } | |
25fcce25 MT |
490 | |
491 | rc = hw_mount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
492 | if (rc) { | |
493 | errorbox(ctr[TR_UNABLE_TO_MOUNT_FILESYSTEMS]); | |
72d80898 | 494 | goto EXIT; |
9607771a | 495 | } |
c78a77eb | 496 | |
25fcce25 MT |
497 | newtPopWindow(); |
498 | ||
499 | // Extract files... | |
03d956be | 500 | snprintf(commandstring, STRING_SIZE, |
23ed79cb | 501 | "/bin/tar -C /harddisk -xvf /cdrom/" SNAME "-" VERSION ".tlz --lzma 2>/dev/null"); |
d6aaa55d | 502 | |
edd536b6 MT |
503 | if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT, |
504 | ctr[TR_INSTALLING_FILES])) | |
d6aaa55d MT |
505 | { |
506 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
507 | goto EXIT; | |
508 | } | |
406f019f MT |
509 | |
510 | /* Save language und local settings */ | |
511 | write_lang_configs(shortlangname); | |
d6aaa55d | 512 | |
330345c2 | 513 | /* Build cache lang file */ |
6cf9e770 | 514 | snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); |
330345c2 MT |
515 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE])) |
516 | { | |
517 | errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]); | |
518 | goto EXIT; | |
519 | } | |
520 | ||
521 | /* Update /etc/fstab */ | |
d7dd283b | 522 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE1#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_boot); |
a9a26c5a | 523 | system(commandstring); |
d7dd283b | 524 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE2#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_swap); |
a9a26c5a | 525 | system(commandstring); |
d7dd283b | 526 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE3#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_root); |
a9a26c5a | 527 | system(commandstring); |
d7dd283b | 528 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE4#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_data); |
a9a26c5a AF |
529 | system(commandstring); |
530 | ||
25fcce25 MT |
531 | switch (destination->filesystem) { |
532 | case HW_FS_REISERFS: | |
533 | replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs"); | |
534 | replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro"); | |
535 | break; | |
536 | ||
537 | case HW_FS_EXT4: | |
538 | case HW_FS_EXT4_WO_JOURNAL: | |
539 | replace("/harddisk/etc/fstab", "FSTYPE", "ext4"); | |
540 | replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro"); | |
541 | break; | |
542 | ||
543 | default: | |
544 | assert(0); | |
cd8dd8dd | 545 | } |
73d9a908 | 546 | |
a869b064 AF |
547 | replace("/harddisk/boot/grub/grub.conf", "KVER", KERNEL_VERSION); |
548 | ||
d7dd283b | 549 | snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#root=ROOT#root=UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/boot/grub/grub.conf", destination->part_root); |
a9a26c5a AF |
550 | system(commandstring); |
551 | ||
f4e27420 | 552 | mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst"); |
fd0763dc | 553 | |
a9a26c5a | 554 | system("/bin/sed -e 's#/harddisk#/#g' -e 's#//#/#g' < /proc/mounts > /harddisk/etc/mtab"); |
edd536b6 | 555 | |
423400cf MT |
556 | /* |
557 | * Generate device.map to help grub finding the device to install itself on. | |
558 | */ | |
559 | FILE *f = NULL; | |
560 | if (f = fopen("/harddisk/boot/grub/device.map", "w")) { | |
d7dd283b | 561 | fprintf(f, "(hd0) %s\n", destination->path); |
423400cf MT |
562 | fclose(f); |
563 | } | |
564 | ||
edd536b6 | 565 | snprintf(commandstring, STRING_SIZE, |
d7dd283b | 566 | "/usr/sbin/chroot /harddisk /usr/sbin/grub-install --no-floppy %s", destination->path); |
edd536b6 MT |
567 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) { |
568 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
569 | goto EXIT; | |
570 | } | |
5faa66cf AF |
571 | |
572 | /* Serial console ? */ | |
573 | if (serialconsole) { | |
574 | /* grub */ | |
575 | replace("/harddisk/boot/grub/grub.conf", "splashimage", "#splashimage"); | |
576 | replace("/harddisk/boot/grub/grub.conf", "#serial", "serial"); | |
577 | replace("/harddisk/boot/grub/grub.conf", "#terminal", "terminal"); | |
1445c9e0 | 578 | replace("/harddisk/boot/grub/grub.conf", " panic=10 ", " console=ttyS0,115200n8 panic=10 "); |
5faa66cf AF |
579 | |
580 | /*inittab*/ | |
581 | replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:"); | |
582 | replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:"); | |
583 | replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:"); | |
584 | replace("/harddisk/etc/inittab", "4:2345:respawn:", "#4:2345:respawn:"); | |
585 | replace("/harddisk/etc/inittab", "5:2345:respawn:", "#5:2345:respawn:"); | |
586 | replace("/harddisk/etc/inittab", "6:2345:respawn:", "#6:2345:respawn:"); | |
587 | replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:"); | |
588 | } | |
589 | ||
dfa59dbd AF |
590 | /* Set marker that the user has already accepted the gpl */ |
591 | mysystem("/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted"); | |
592 | ||
c25a0343 | 593 | /* Copy restore file from cdrom */ |
7062cecd | 594 | if (unattended && (strlen(restore_file) > 0)) { |
c25a0343 | 595 | fprintf(flog, "unattended: Copy restore file\n"); |
dca095e1 | 596 | snprintf(commandstring, STRING_SIZE, |
c25a0343 | 597 | "cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file); |
dca095e1 | 598 | mysystem(commandstring); |
c25a0343 | 599 | } |
2c9c458c MT |
600 | |
601 | // Umount source drive and eject | |
602 | hw_umount(SOURCE_MOUNT_PATH); | |
603 | ||
604 | snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive); | |
3ef6c343 | 605 | mysystem(commandstring); |
22b9e405 | 606 | |
73d9a908 MT |
607 | if (!unattended) { |
608 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
3ad8835c | 609 | NAME, SNAME, NAME); |
fac85ccd | 610 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_PRESS_OK_TO_REBOOT], message); |
73d9a908 | 611 | } |
cd8dd8dd | 612 | |
22b9e405 | 613 | allok = 1; |
edd536b6 | 614 | |
d6aaa55d | 615 | EXIT: |
10bc6f06 | 616 | fprintf(flog, "Install program ended.\n"); |
d6aaa55d | 617 | |
10bc6f06 | 618 | if (!(allok)) |
d6aaa55d | 619 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); |
d6aaa55d | 620 | |
25fcce25 | 621 | if (allok) { |
ee78a5ef MT |
622 | fflush(flog); |
623 | fclose(flog); | |
3a1019f6 MT |
624 | } |
625 | ||
626 | newtFinished(); | |
627 | ||
f0fa1795 MT |
628 | // Free resources |
629 | free(sourcedrive); | |
25fcce25 MT |
630 | |
631 | if (destination) { | |
632 | hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
633 | free(destination); | |
634 | } | |
d7dd283b | 635 | |
4a0d9bef MT |
636 | hw_stop_all_raid_arrays(); |
637 | ||
d7dd283b MT |
638 | if (selected_disks) |
639 | hw_free_disks(selected_disks); | |
640 | ||
641 | hw_free(hw); | |
f0fa1795 | 642 | |
25fcce25 MT |
643 | fcloseall(); |
644 | ||
645 | if (!(allok)) | |
646 | system("/etc/halt"); | |
647 | ||
d6aaa55d MT |
648 | return 0; |
649 | } |