]>
Commit | Line | Data |
---|---|---|
1 | ||
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 | |
8 | * Contains main entry point, and misc functions.6 | |
9 | * | |
10 | */ | |
11 | ||
12 | #define _GNU_SOURCE | |
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" | |
22 | ||
23 | #define INST_FILECOUNT 21000 | |
24 | #define UNATTENDED_CONF "/cdrom/boot/unattended.conf" | |
25 | #define LICENSE_FILE "/cdrom/COPYING" | |
26 | ||
27 | FILE *flog = NULL; | |
28 | char *mylog; | |
29 | ||
30 | char **ctr; | |
31 | ||
32 | extern char url[STRING_SIZE]; | |
33 | ||
34 | struct nic nics[20] = { { "" , "" , "" } }; // only defined for compile | |
35 | struct knic knics[20] = { { "" , "" , "" , "" } }; // only defined for compile | |
36 | ||
37 | extern char *en_tr[]; | |
38 | extern char *es_tr[]; | |
39 | extern char *de_tr[]; | |
40 | extern char *fr_tr[]; | |
41 | extern char *nl_tr[]; | |
42 | extern char *pl_tr[]; | |
43 | extern char *ru_tr[]; | |
44 | extern char *tr_tr[]; | |
45 | ||
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 | ||
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 | ||
177 | int main(int argc, char *argv[]) { | |
178 | struct hw* hw = hw_init(); | |
179 | ||
180 | char discl_msg[40000] = "Disclaimer\n"; | |
181 | ||
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 }; | |
185 | char* sourcedrive = NULL; | |
186 | int rc = 0; | |
187 | char commandstring[STRING_SIZE]; | |
188 | int choice; | |
189 | char shortlangname[10]; | |
190 | char message[STRING_SIZE]; | |
191 | char title[STRING_SIZE]; | |
192 | int allok = 0; | |
193 | FILE *handle, *cmdfile, *copying; | |
194 | char line[STRING_SIZE]; | |
195 | ||
196 | int unattended = 0; | |
197 | int serialconsole = 0; | |
198 | struct keyvalue *unattendedkv = initkeyvalues(); | |
199 | char restore_file[STRING_SIZE] = ""; | |
200 | ||
201 | setlocale (LC_ALL, ""); | |
202 | sethostname( SNAME , 10); | |
203 | ||
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 | ||
220 | newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN ); | |
221 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
222 | ||
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); | |
228 | ||
229 | // check if we have to make an unattended install | |
230 | if (strstr (line, "unattended") != NULL) { | |
231 | unattended = 1; | |
232 | runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds..."); | |
233 | } | |
234 | // check if we have to patch for serial console | |
235 | if (strstr (line, "console=ttyS0") != NULL) { | |
236 | serialconsole = 1; | |
237 | } | |
238 | } | |
239 | ||
240 | // Load common modules | |
241 | mysystem("/sbin/modprobe vfat"); // USB key | |
242 | hw_stop_all_raid_arrays(); | |
243 | ||
244 | /* German is the default */ | |
245 | for (choice = 0; langnames[choice]; choice++) | |
246 | { | |
247 | if (strcmp(langnames[choice], "English") == 0) | |
248 | break; | |
249 | } | |
250 | if (!langnames[choice]) | |
251 | goto EXIT; | |
252 | ||
253 | if (!unattended) { | |
254 | rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, | |
255 | langnames, &choice, "Ok", NULL); | |
256 | } | |
257 | ||
258 | ctr = langtrs[choice]; | |
259 | strcpy(shortlangname, shortlangnames[choice]); | |
260 | ||
261 | newtPushHelpLine(ctr[TR_HELPLINE]); | |
262 | ||
263 | if (!unattended) { | |
264 | sprintf(message, ctr[TR_WELCOME], NAME); | |
265 | newtWinMessage(title, ctr[TR_OK], message); | |
266 | } | |
267 | ||
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); | |
271 | ||
272 | fprintf(flog, "Source drive: %s\n", sourcedrive); | |
273 | if (!sourcedrive) { | |
274 | newtWinMessage(title, ctr[TR_OK], ctr[TR_NO_LOCAL_SOURCE]); | |
275 | runcommandwithstatus("/bin/downloadsource.sh", ctr[TR_DOWNLOADING_ISO]); | |
276 | if ((handle = fopen("/tmp/source_device", "r")) == NULL) { | |
277 | errorbox(ctr[TR_DOWNLOAD_ERROR]); | |
278 | goto EXIT; | |
279 | } | |
280 | ||
281 | fgets(sourcedrive, 5, handle); | |
282 | fclose(handle); | |
283 | } | |
284 | ||
285 | assert(sourcedrive); | |
286 | ||
287 | int r = hw_mount(sourcedrive, SOURCE_MOUNT_PATH, "iso9660", MS_RDONLY); | |
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 | } | |
293 | ||
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 | ||
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 | ||
311 | if (newtLicenseBox(title, discl_msg, 75, 20)) { | |
312 | errorbox(ctr[TR_LICENSE_NOT_ACCEPTED]); | |
313 | ||
314 | goto EXIT; | |
315 | } | |
316 | } | |
317 | } | |
318 | ||
319 | int part_type = HW_PART_TYPE_NORMAL; | |
320 | ||
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) | |
378 | break; | |
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 | ||
389 | break; | |
390 | } | |
391 | ||
392 | // Currently not supported | |
393 | } else { | |
394 | errorbox(ctr[TR_DISK_CONFIGURATION_NOT_SUPPORTED]); | |
395 | } | |
396 | ||
397 | if (selected_disks) { | |
398 | hw_free_disks(selected_disks); | |
399 | selected_disks = NULL; | |
400 | } | |
401 | } | |
402 | ||
403 | hw_free_disks(disks); | |
404 | ||
405 | struct hw_destination* destination = hw_make_destination(part_type, selected_disks); | |
406 | ||
407 | if (!destination) { | |
408 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
409 | goto EXIT; | |
410 | } | |
411 | ||
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)); | |
417 | ||
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]); | |
421 | ||
422 | if (rc != 1) | |
423 | goto EXIT; | |
424 | } | |
425 | ||
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 | } | |
447 | ||
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; | |
453 | ||
454 | else | |
455 | goto EXIT; | |
456 | } | |
457 | ||
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 | ||
471 | // Execute the partitioning... | |
472 | statuswindow(60, 4, title, ctr[TR_PARTITIONING_DISK]); | |
473 | ||
474 | rc = hw_create_partitions(destination); | |
475 | if (rc) { | |
476 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
477 | goto EXIT; | |
478 | } | |
479 | ||
480 | newtPopWindow(); | |
481 | ||
482 | // Execute the formatting... | |
483 | statuswindow(60, 4, title, ctr[TR_CREATING_FILESYSTEMS]); | |
484 | ||
485 | rc = hw_create_filesystems(destination); | |
486 | if (rc) { | |
487 | errorbox(ctr[TR_UNABLE_TO_CREATE_FILESYSTEMS]); | |
488 | goto EXIT; | |
489 | } | |
490 | ||
491 | rc = hw_mount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
492 | if (rc) { | |
493 | errorbox(ctr[TR_UNABLE_TO_MOUNT_FILESYSTEMS]); | |
494 | goto EXIT; | |
495 | } | |
496 | ||
497 | newtPopWindow(); | |
498 | ||
499 | // Extract files... | |
500 | snprintf(commandstring, STRING_SIZE, | |
501 | "/bin/tar -C /harddisk -xvf /cdrom/" SNAME "-" VERSION ".tlz --lzma 2>/dev/null"); | |
502 | ||
503 | if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT, | |
504 | ctr[TR_INSTALLING_FILES])) | |
505 | { | |
506 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
507 | goto EXIT; | |
508 | } | |
509 | ||
510 | /* Save language und local settings */ | |
511 | write_lang_configs(shortlangname); | |
512 | ||
513 | /* Build cache lang file */ | |
514 | snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); | |
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 */ | |
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); | |
523 | system(commandstring); | |
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); | |
525 | system(commandstring); | |
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); | |
527 | system(commandstring); | |
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); | |
529 | system(commandstring); | |
530 | ||
531 | system("/bin/sed -e 's#/harddisk#/#g' -e 's#//#/#g' < /proc/mounts > /harddisk/etc/mtab"); | |
532 | ||
533 | // Installing bootloader... | |
534 | statuswindow(60, 4, title, ctr[TR_INSTALLING_GRUB]); | |
535 | ||
536 | rc = hw_install_bootloader(destination); | |
537 | if (rc) { | |
538 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
539 | goto EXIT; | |
540 | } | |
541 | ||
542 | newtPopWindow(); | |
543 | ||
544 | /* Serial console ? */ | |
545 | if (serialconsole) { | |
546 | /* grub */ | |
547 | replace("/harddisk/boot/grub/grub.conf", "splashimage", "#splashimage"); | |
548 | replace("/harddisk/boot/grub/grub.conf", "#serial", "serial"); | |
549 | replace("/harddisk/boot/grub/grub.conf", "#terminal", "terminal"); | |
550 | replace("/harddisk/boot/grub/grub.conf", " panic=10 ", " console=ttyS0,115200n8 panic=10 "); | |
551 | ||
552 | /*inittab*/ | |
553 | replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:"); | |
554 | replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:"); | |
555 | replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:"); | |
556 | replace("/harddisk/etc/inittab", "4:2345:respawn:", "#4:2345:respawn:"); | |
557 | replace("/harddisk/etc/inittab", "5:2345:respawn:", "#5:2345:respawn:"); | |
558 | replace("/harddisk/etc/inittab", "6:2345:respawn:", "#6:2345:respawn:"); | |
559 | replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:"); | |
560 | } | |
561 | ||
562 | /* Set marker that the user has already accepted the gpl */ | |
563 | mysystem("/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted"); | |
564 | ||
565 | /* Copy restore file from cdrom */ | |
566 | if (unattended && (strlen(restore_file) > 0)) { | |
567 | fprintf(flog, "unattended: Copy restore file\n"); | |
568 | snprintf(commandstring, STRING_SIZE, | |
569 | "cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file); | |
570 | mysystem(commandstring); | |
571 | } | |
572 | ||
573 | // Umount source drive and eject | |
574 | hw_umount(SOURCE_MOUNT_PATH); | |
575 | ||
576 | snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive); | |
577 | mysystem(commandstring); | |
578 | ||
579 | if (!unattended) { | |
580 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
581 | NAME, SNAME, NAME); | |
582 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_PRESS_OK_TO_REBOOT], message); | |
583 | } | |
584 | ||
585 | allok = 1; | |
586 | ||
587 | EXIT: | |
588 | fprintf(flog, "Install program ended.\n"); | |
589 | ||
590 | if (!(allok)) | |
591 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); | |
592 | ||
593 | if (allok) { | |
594 | fflush(flog); | |
595 | fclose(flog); | |
596 | } | |
597 | ||
598 | newtFinished(); | |
599 | ||
600 | // Free resources | |
601 | free(sourcedrive); | |
602 | ||
603 | if (destination) { | |
604 | hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH); | |
605 | free(destination); | |
606 | } | |
607 | ||
608 | hw_stop_all_raid_arrays(); | |
609 | ||
610 | if (selected_disks) | |
611 | hw_free_disks(selected_disks); | |
612 | ||
613 | hw_free(hw); | |
614 | ||
615 | fcloseall(); | |
616 | ||
617 | if (!(allok)) | |
618 | system("/etc/halt"); | |
619 | ||
620 | return 0; | |
621 | } |