]> git.ipfire.org Git - ipfire-2.x.git/blame - src/installer/main.c
installer: Drop user to an emergency shell if the installer crashes.
[ipfire-2.x.git] / src / installer / main.c
CommitLineData
d6aaa55d
MT
1/* SmoothWall install 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
f9cc0d70 7 * Contains main entry point, and misc functions.6
d6aaa55d 8 *
d6aaa55d 9 */
10bc6f06 10
f0fa1795
MT
11#include <assert.h>
12#include <errno.h>
b83b8f70 13#include <stdio.h>
f0fa1795
MT
14#include <stdlib.h>
15#include <string.h>
16#include <sys/mount.h>
17
18#include "hw.h"
19#include "install.h"
5315fae6
MT
20
21// Translation
22#include <libintl.h>
23#define _(x) dgettext("installer", x)
24
68561214 25#define INST_FILECOUNT 21000
33634aa8 26#define UNATTENDED_CONF "/cdrom/boot/unattended.conf"
918546e2 27#define LICENSE_FILE "/cdrom/COPYING"
d6aaa55d 28
d6aaa55d
MT
29FILE *flog = NULL;
30char *mylog;
10bc6f06 31
d6aaa55d
MT
32char **ctr;
33
d6aaa55d
MT
34extern char url[STRING_SIZE];
35
d7dd283b
MT
36static int newtChecklist(const char* title, const char* message,
37 unsigned int width, unsigned int height, unsigned int num_entries,
38 const char** entries, int* states) {
39 int ret;
40 const int list_height = 4;
41
42 char cbstates[num_entries];
43
44 for (unsigned int i = 0; i < num_entries; i++) {
45 cbstates[i] = states[i] ? '*' : ' ';
46 }
47
48 newtCenteredWindow(width, height, title);
49
50 newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6 - list_height,
51 NEWT_FLAG_WRAP);
52 newtTextboxSetText(textbox, message);
53
54 int top = newtTextboxGetNumLines(textbox) + 2;
55
56 newtComponent form = newtForm(NULL, NULL, 0);
57
58 newtComponent sb = NULL;
59 if (list_height < num_entries) {
60 sb = newtVerticalScrollbar(
61 width - 4, top + 1, list_height,
62 NEWT_COLORSET_CHECKBOX, NEWT_COLORSET_ACTCHECKBOX);
63
64 newtFormAddComponent(form, sb);
65 }
66
67 newtComponent subform = newtForm(sb, NULL, 0);
68 newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX);
69
70 newtFormSetHeight(subform, list_height);
71 newtFormSetWidth(subform, width - 10);
72
73 for (unsigned int i = 0; i < num_entries; i++) {
74 newtComponent cb = newtCheckbox(4, top + i, entries[i], cbstates[i],
75 NULL, &cbstates[i]);
76
77 newtFormAddComponent(subform, cb);
78 }
79
80 newtFormAddComponents(form, textbox, subform, NULL);
81
5315fae6
MT
82 newtComponent btn_okay = newtButton((width - 18) / 3, height - 4, _("OK"));
83 newtComponent btn_cancel = newtButton((width - 18) / 3 * 2 + 9, height - 4, _("Cancel"));
d7dd283b
MT
84 newtFormAddComponents(form, btn_okay, btn_cancel, NULL);
85
86 newtComponent answer = newtRunForm(form);
87
88 if ((answer == NULL) || (answer == btn_cancel)) {
89 ret = -1;
90 } else {
91 ret = 0;
92
93 for (unsigned int i = 0; i < num_entries; i++) {
94 states[i] = (cbstates[i] != ' ');
95
96 if (states[i])
97 ret++;
98 }
99 }
100
101 newtFormDestroy(form);
102 newtPopWindow();
103
104 return ret;
105}
106
107static int newtWinOkCancel(const char* title, const char* message, int width, int height,
108 const char* btn_txt_ok, const char* btn_txt_cancel) {
109 int ret = 1;
110
111 newtCenteredWindow(width, height, title);
112
113 newtComponent form = newtForm(NULL, NULL, 0);
114
115 newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6, NEWT_FLAG_WRAP);
116 newtTextboxSetText(textbox, message);
117 newtFormAddComponent(form, textbox);
118
119 newtComponent btn_ok = newtButton((width - 16) / 3, height - 4, btn_txt_ok);
120 newtComponent btn_cancel = newtButton((width - 16) / 3 * 2 + 9, height - 4,
121 btn_txt_cancel);
122
123 newtFormAddComponents(form, btn_ok, btn_cancel, NULL);
124
125 newtComponent answer = newtRunForm(form);
126
127 if (answer == btn_ok) {
128 ret = 0;
129 }
130
131 newtFormDestroy(form);
132 newtPopWindow();
133
134 return ret;
135}
136
bd5e7c29
MT
137static int newtLicenseBox(const char* title, const char* text, int width, int height) {
138 int ret = 1;
139
140 newtCenteredWindow(width, height, title);
141
142 newtComponent form = newtForm(NULL, NULL, 0);
143
144 newtComponent textbox = newtTextbox(1, 1, width - 2, height - 7,
145 NEWT_FLAG_WRAP|NEWT_FLAG_SCROLL);
146 newtTextboxSetText(textbox, text);
147 newtFormAddComponent(form, textbox);
148
149 char choice;
5315fae6 150 newtComponent checkbox = newtCheckbox(3, height - 3, _("I accept this license"),
bd5e7c29
MT
151 ' ', " *", &choice);
152
5315fae6 153 newtComponent btn = newtButton(width - 15, height - 4, _("OK"));
bd5e7c29
MT
154
155 newtFormAddComponents(form, checkbox, btn, NULL);
156
157 newtComponent answer = newtRunForm(form);
158 if (answer == btn && choice == '*')
159 ret = 0;
160
161 newtFormDestroy(form);
162 newtPopWindow();
163
164 return ret;
165}
166
5315fae6
MT
167int write_lang_configs(const char *lang) {
168 struct keyvalue *kv = initkeyvalues();
169
170 /* default stuff for main/settings. */
171 replacekeyvalue(kv, "LANGUAGE", lang);
172 replacekeyvalue(kv, "HOSTNAME", SNAME);
173 replacekeyvalue(kv, "THEME", "ipfire");
174 writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings");
175 freekeyvalues(kv);
176
177 return 1;
178}
179
b83b8f70
MT
180static char* get_system_release() {
181 char system_release[STRING_SIZE] = "\0";
182
183 FILE* f = fopen("/etc/system-release", "r");
184 if (f) {
185 fgets(system_release, sizeof(system_release), f);
186 fclose(f);
187 }
188
189 return strdup(system_release);
190}
191
192static char* center_string(const char* str, int width) {
193 unsigned int str_len = strlen(str);
194
195 unsigned int indent_length = (width - str_len) / 2;
196 char indent[indent_length + 1];
197
198 for (unsigned int i = 0; i < indent_length; i++) {
199 indent[i] = ' ';
200 }
201 indent[indent_length] = '\0';
202
203 char* string = NULL;
204 if (asprintf(&string, "%s%s", indent, str) < 0)
205 return NULL;
206
207 return string;
208}
209
f0fa1795
MT
210int main(int argc, char *argv[]) {
211 struct hw* hw = hw_init();
e0bbaf87 212
b83b8f70
MT
213 // Read /etc/system-release
214 char* system_release = get_system_release();
215
e0bbaf87
AF
216 char discl_msg[40000] = "Disclaimer\n";
217
910193da
EY
218 char *langnames[] = { "Deutsch", "English", "Français", "Español", "Nederlands", "Polski", "Русский", "Türkçe", NULL };
219 char *shortlangnames[] = { "de", "en", "fr", "es", "nl", "pl", "ru", "tr", NULL };
f0fa1795 220 char* sourcedrive = NULL;
72d80898 221 int rc = 0;
d6aaa55d 222 char commandstring[STRING_SIZE];
d6aaa55d
MT
223 int choice;
224 char shortlangname[10];
d7dd283b 225 char message[STRING_SIZE];
d6aaa55d
MT
226 char title[STRING_SIZE];
227 int allok = 0;
e0bbaf87 228 FILE *handle, *cmdfile, *copying;
d6aaa55d 229 char line[STRING_SIZE];
5057b611 230
72d80898 231 int unattended = 0;
5faa66cf 232 int serialconsole = 0;
72d80898 233 struct keyvalue *unattendedkv = initkeyvalues();
66335974 234 char restore_file[STRING_SIZE] = "";
d6aaa55d
MT
235
236 setlocale (LC_ALL, "");
10bc6f06 237 sethostname( SNAME , 10);
72d80898 238
d6aaa55d
MT
239 /* Log file/terminal stuff. */
240 if (argc >= 2)
241 {
242 if (!(flog = fopen(argv[1], "w+")))
243 return 0;
244 }
245 else
246 return 0;
247
248 mylog = argv[1];
249
250 fprintf(flog, "Install program started.\n");
251
252 newtInit();
253 newtCls();
254
b83b8f70
MT
255 // Determine the size of the screen
256 int screen_cols = 0;
257 int screen_rows = 0;
258
259 newtGetScreenSize(&screen_cols, &screen_rows);
260
261 // Draw title
262 char* roottext = center_string(system_release, screen_cols);
263 newtDrawRootText(0, 0, roottext);
264
7ea444c8
AF
265 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
266
d6aaa55d
MT
267 if (! (cmdfile = fopen("/proc/cmdline", "r")))
268 {
269 fprintf(flog, "Couldn't open commandline: /proc/cmdline\n");
270 } else {
271 fgets(line, STRING_SIZE, cmdfile);
61e3d218 272
72d80898 273 // check if we have to make an unattended install
ee78a5ef 274 if (strstr (line, "unattended") != NULL) {
72d80898 275 unattended = 1;
5315fae6 276 runcommandwithstatus("/bin/sleep 10", title, "WARNING: Unattended installation will start in 10 seconds...");
bba7212c 277 }
5faa66cf
AF
278 // check if we have to patch for serial console
279 if (strstr (line, "console=ttyS0") != NULL) {
280 serialconsole = 1;
281 }
d6aaa55d 282 }
0db33b56 283
7ea444c8 284 // Load common modules
bba7212c 285 mysystem("/sbin/modprobe vfat"); // USB key
4a0d9bef
MT
286 hw_stop_all_raid_arrays();
287
72d80898 288 /* German is the default */
d6aaa55d
MT
289 for (choice = 0; langnames[choice]; choice++)
290 {
215bd18d 291 if (strcmp(langnames[choice], "English") == 0)
d6aaa55d
MT
292 break;
293 }
294 if (!langnames[choice])
295 goto EXIT;
296
72d80898 297 if (!unattended) {
51f3b7f5 298 rc = newtWinMenu("Language selection", "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8,
72d80898
MT
299 langnames, &choice, "Ok", NULL);
300 }
301
5315fae6 302 setlocale(LC_ALL, shortlangnames[choice]);
3d6e1202 303
b83b8f70
MT
304 char* helpline = center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols);
305 newtPushHelpLine(helpline);
0db33b56 306
e0bbaf87 307 if (!unattended) {
5315fae6
MT
308 snprintf(message, sizeof(message),
309 _("Welcome to the %s installation program. "
310 "Selecting Cancel on any of the following screens will reboot the computer."), NAME);
311 newtWinMessage(title, _("Start installation"), message);
e0bbaf87
AF
312 }
313
f0fa1795
MT
314 /* Search for a source drive that holds the right
315 * version of the image we are going to install. */
316 sourcedrive = hw_find_source_medium(hw);
9607771a 317
f0fa1795
MT
318 fprintf(flog, "Source drive: %s\n", sourcedrive);
319 if (!sourcedrive) {
5315fae6
MT
320 newtWinMessage(title, _("OK"), _("No local source media found. Starting download."));
321 runcommandwithstatus("/bin/downloadsource.sh", title, _("Downloading installation image ..."));
0f680bcc 322 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
5315fae6 323 errorbox(_("Download error"));
0f680bcc
AF
324 goto EXIT;
325 }
f0fa1795
MT
326
327 fgets(sourcedrive, 5, handle);
328 fclose(handle);
72d80898 329 }
0f680bcc 330
f0fa1795
MT
331 assert(sourcedrive);
332
25fcce25 333 int r = hw_mount(sourcedrive, SOURCE_MOUNT_PATH, "iso9660", MS_RDONLY);
f0fa1795
MT
334 if (r) {
335 fprintf(flog, "Could not mount %s to %s\n", sourcedrive, SOURCE_MOUNT_PATH);
336 fprintf(flog, strerror(errno));
337 exit(1);
338 }
918546e2 339
d7dd283b
MT
340 /* load unattended configuration */
341 if (unattended) {
342 fprintf(flog, "unattended: Reading unattended.conf\n");
343
344 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
345 findkey(unattendedkv, "RESTORE_FILE", restore_file);
346 }
347
918546e2
MT
348 if (!unattended) {
349 // Read the license file.
350 if (!(copying = fopen(LICENSE_FILE, "r"))) {
351 sprintf(discl_msg, "Could not open license file: %s\n", LICENSE_FILE);
352 fprintf(flog, discl_msg);
353 } else {
354 fread(discl_msg, 1, 40000, copying);
355 fclose(copying);
356
bd5e7c29 357 if (newtLicenseBox(title, discl_msg, 75, 20)) {
5315fae6 358 errorbox(_("License not accepted!"));
bd5e7c29 359
918546e2
MT
360 goto EXIT;
361 }
362 }
363 }
364
d7dd283b 365 int part_type = HW_PART_TYPE_NORMAL;
ee78a5ef 366
d7dd283b
MT
367 // Scan for disks to install on.
368 struct hw_disk** disks = hw_find_disks(hw);
369
370 struct hw_disk** selected_disks = NULL;
371 unsigned int num_selected_disks = 0;
372
373 // Check how many disks have been found and what
374 // we can do with them.
375 unsigned int num_disks = hw_count_disks(disks);
376
377 while (1) {
378 // no harddisks found
379 if (num_disks == 0) {
5315fae6 380 errorbox(_("No hard disk found."));
d7dd283b
MT
381 goto EXIT;
382
383 // exactly one disk has been found
384 } else if (num_disks == 1) {
385 selected_disks = hw_select_disks(disks, NULL);
386
387 // more than one usable disk has been found and
388 // the user needs to choose what to do with them
389 } else {
390 const char* disk_names[num_disks];
391 int disk_selection[num_disks];
392
393 for (unsigned int i = 0; i < num_disks; i++) {
394 disk_names[i] = &disks[i]->description;
395 disk_selection[i] = 0;
396 }
397
398 while (!selected_disks) {
5315fae6
MT
399 rc = newtChecklist(_("Disk Selection"),
400 _("Select the disk(s) you want to install IPFire on. "
401 "First those will be partitioned, and then the partitions will have a filesystem put on them.\n\n"
402 "ALL DATA ON THE DISK WILL BE DESTROYED."),
d7dd283b
MT
403 50, 20, num_disks, disk_names, disk_selection);
404
405 // Error
406 if (rc < 0) {
407 goto EXIT;
408
409 // Nothing has been selected
410 } else if (rc == 0) {
5315fae6
MT
411 errorbox(_("No disk has been selected.\n\n"
412 "Please select one or more disks you want to install IPFire on."));
d7dd283b
MT
413
414 } else {
415 selected_disks = hw_select_disks(disks, disk_selection);
416 }
417 }
418 }
419
420 num_selected_disks = hw_count_disks(selected_disks);
421
422 if (num_selected_disks == 1) {
5315fae6
MT
423 snprintf(message, sizeof(message),
424 _("The installation program will now prepare the chosen harddisk:\n\n %s\n\n"
425 "Do you agree to continue?"), (*selected_disks)->description);
426 rc = newtWinOkCancel(_("Disk Setup"), message, 50, 10,
427 _("Delete all data"), _("Cancel"));
d7dd283b
MT
428
429 if (rc == 0)
56b548f1 430 break;
d7dd283b
MT
431
432 } else if (num_selected_disks == 2) {
5315fae6
MT
433 snprintf(message, sizeof(message),
434 _("The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\n"
435 "Do you agree to continue?"), (*selected_disks)->description, (*selected_disks + 1)->description);
436 rc = newtWinOkCancel(_("RAID Setup"), message, 50, 14,
437 _("Delete all data"), _("Cancel"));
d7dd283b
MT
438
439 if (rc == 0) {
440 part_type = HW_PART_TYPE_RAID1;
441
ee78a5ef 442 break;
d7dd283b
MT
443 }
444
445 // Currently not supported
446 } else {
5315fae6 447 errorbox(_("You disk configuration is currently not supported."));
aee3027d 448 }
ee78a5ef 449
d7dd283b
MT
450 if (selected_disks) {
451 hw_free_disks(selected_disks);
452 selected_disks = NULL;
453 }
212cab4f 454 }
212cab4f 455
d7dd283b 456 hw_free_disks(disks);
72d80898 457
d7dd283b 458 struct hw_destination* destination = hw_make_destination(part_type, selected_disks);
5057b611 459
25fcce25 460 if (!destination) {
5315fae6 461 errorbox(_("Your harddisk is too small."));
cd8dd8dd 462 goto EXIT;
25fcce25 463 }
cd8dd8dd 464
25fcce25 465 fprintf(flog, "Destination drive: %s\n", destination->path);
48d6a112
MT
466 fprintf(flog, " bootldr: %s (%lluMB)\n", destination->part_bootldr, BYTES2MB(destination->size_bootldr));
467 fprintf(flog, " boot : %s (%lluMB)\n", destination->part_boot, BYTES2MB(destination->size_boot));
468 fprintf(flog, " swap : %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap));
469 fprintf(flog, " root : %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root));
470 fprintf(flog, " data : %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data));
72d80898 471
25fcce25
MT
472 // Warn the user if there is not enough space to create a swap partition
473 if (!unattended && !*destination->part_swap) {
5315fae6
MT
474 rc = newtWinChoice(title, _("OK"), _("Cancel"),
475 _("Your harddisk is very small, but you can continue with an very small swap. (Use with caution)."));
4f26ff7f 476
25fcce25
MT
477 if (rc != 1)
478 goto EXIT;
72d80898 479 }
9a3d3d95 480
25fcce25
MT
481 // Filesystem selection
482 if (!unattended) {
483 struct filesystems {
484 int fstype;
485 const char* description;
486 } filesystems[] = {
5315fae6
MT
487 { HW_FS_EXT4, _("ext4 Filesystem") },
488 { HW_FS_EXT4_WO_JOURNAL, _("ext4 Filesystem without journal") },
489 { HW_FS_XFS, _("XFS Filesystem") },
490 { HW_FS_REISERFS, _("ReiserFS Filesystem") },
25fcce25
MT
491 { 0, NULL },
492 };
493 unsigned int num_filesystems = sizeof(filesystems) / sizeof(*filesystems);
494
495 char* fs_names[num_filesystems];
496 int fs_choice = 0;
497 for (unsigned int i = 0; i < num_filesystems; i++) {
498 if (HW_FS_DEFAULT == filesystems[i].fstype)
499 fs_choice = i;
500
501 fs_names[i] = filesystems[i].description;
502 }
72d80898 503
5315fae6
MT
504 rc = newtWinMenu(_("Filesystem Selection"), _("Please choose your filesystem:"),
505 50, 5, 5, 6, fs_names, &fs_choice, _("OK"), _("Cancel"), NULL);
25fcce25 506
139cb500 507 if (rc != 1)
72d80898 508 goto EXIT;
139cb500
MT
509
510 destination->filesystem = filesystems[fs_choice].fstype;
72d80898
MT
511 }
512
4a0d9bef
MT
513 // Setting up RAID if needed.
514 if (destination->is_raid) {
5315fae6 515 statuswindow(60, 4, title, _("Building RAID..."));
4a0d9bef
MT
516
517 rc = hw_setup_raid(destination);
518 if (rc) {
5315fae6 519 errorbox(_("Unable to build the RAID."));
4a0d9bef
MT
520 goto EXIT;
521 }
522
523 newtPopWindow();
524 }
525
25fcce25 526 // Execute the partitioning...
5315fae6 527 statuswindow(60, 4, title, _("Partitioning disk..."));
72d80898 528
25fcce25
MT
529 rc = hw_create_partitions(destination);
530 if (rc) {
5315fae6 531 errorbox(_("Unable to partition the disk."));
72d80898 532 goto EXIT;
9607771a 533 }
72d80898 534
25fcce25 535 newtPopWindow();
72d80898 536
25fcce25 537 // Execute the formatting...
5315fae6 538 statuswindow(60, 4, title, _("Creating filesystems..."));
b8e2d108 539
25fcce25
MT
540 rc = hw_create_filesystems(destination);
541 if (rc) {
5315fae6 542 errorbox(_("Unable to create filesystems."));
72d80898
MT
543 goto EXIT;
544 }
25fcce25
MT
545
546 rc = hw_mount_filesystems(destination, DESTINATION_MOUNT_PATH);
547 if (rc) {
5315fae6 548 errorbox(_("Unable to mount filesystems."));
72d80898 549 goto EXIT;
9607771a 550 }
c78a77eb 551
25fcce25
MT
552 newtPopWindow();
553
554 // Extract files...
03d956be 555 snprintf(commandstring, STRING_SIZE,
5315fae6
MT
556 "/bin/tar -C /harddisk -xvf /cdrom/distro.img --lzma 2>/dev/null");
557
edd536b6 558 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
5315fae6
MT
559 _("Installing the system..."))) {
560 errorbox(_("Unable to install the system."));
d6aaa55d
MT
561 goto EXIT;
562 }
7f69d8a4
MT
563
564 // Write fstab
565 rc = hw_write_fstab(destination);
566 if (rc) {
567 fprintf(flog, "Could not write /etc/fstab\n");
568 goto EXIT;
569 }
570
406f019f
MT
571 /* Save language und local settings */
572 write_lang_configs(shortlangname);
d6aaa55d 573
330345c2 574 /* Build cache lang file */
6cf9e770 575 snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
5315fae6
MT
576 if (runcommandwithstatus(commandstring, title, _("Installing the language cache..."))) {
577 errorbox(_("Unable to install the language cache."));
330345c2
MT
578 goto EXIT;
579 }
580
f5007e9c 581 // Installing bootloader...
5315fae6 582 statuswindow(60, 4, title, _("Installing the bootloader..."));
423400cf 583
f5007e9c
MT
584 rc = hw_install_bootloader(destination);
585 if (rc) {
5315fae6 586 errorbox(_("Unable to install the bootloader."));
edd536b6
MT
587 goto EXIT;
588 }
5faa66cf 589
f5007e9c
MT
590 newtPopWindow();
591
5faa66cf
AF
592 /* Serial console ? */
593 if (serialconsole) {
594 /* grub */
595 replace("/harddisk/boot/grub/grub.conf", "splashimage", "#splashimage");
596 replace("/harddisk/boot/grub/grub.conf", "#serial", "serial");
597 replace("/harddisk/boot/grub/grub.conf", "#terminal", "terminal");
1445c9e0 598 replace("/harddisk/boot/grub/grub.conf", " panic=10 ", " console=ttyS0,115200n8 panic=10 ");
5faa66cf
AF
599
600 /*inittab*/
601 replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:");
602 replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:");
603 replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:");
604 replace("/harddisk/etc/inittab", "4:2345:respawn:", "#4:2345:respawn:");
605 replace("/harddisk/etc/inittab", "5:2345:respawn:", "#5:2345:respawn:");
606 replace("/harddisk/etc/inittab", "6:2345:respawn:", "#6:2345:respawn:");
607 replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:");
608 }
609
dfa59dbd
AF
610 /* Set marker that the user has already accepted the gpl */
611 mysystem("/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");
612
c25a0343 613 /* Copy restore file from cdrom */
7062cecd 614 if (unattended && (strlen(restore_file) > 0)) {
c25a0343 615 fprintf(flog, "unattended: Copy restore file\n");
dca095e1 616 snprintf(commandstring, STRING_SIZE,
c25a0343 617 "cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file);
dca095e1 618 mysystem(commandstring);
c25a0343 619 }
2c9c458c
MT
620
621 // Umount source drive and eject
622 hw_umount(SOURCE_MOUNT_PATH);
623
624 snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive);
3ef6c343 625 mysystem(commandstring);
22b9e405 626
73d9a908 627 if (!unattended) {
5315fae6
MT
628 snprintf(message, sizeof(message), _("%s was successfully installed. "
629 "Please remove any installation mediums from this system. "
630 "Setup will now run where you may configure networking and the system passwords. "
631 "After Setup has been completed, you should point your web browser at https://%s:444 "
632 "(or whatever you name your %s), and configure dialup networking (if required) and "
633 "remote access."), NAME, SNAME, NAME);
634 newtWinMessage(_("Congratulations!"), _("Reboot"), message);
73d9a908 635 }
cd8dd8dd 636
22b9e405 637 allok = 1;
edd536b6 638
d6aaa55d 639EXIT:
10bc6f06 640 fprintf(flog, "Install program ended.\n");
d6aaa55d 641
10bc6f06 642 if (!(allok))
5315fae6 643 newtWinMessage(title, _("OK"), _("Press Ok to reboot."));
d6aaa55d 644
25fcce25 645 if (allok) {
ee78a5ef
MT
646 fflush(flog);
647 fclose(flog);
3a1019f6
MT
648 }
649
650 newtFinished();
651
f0fa1795 652 // Free resources
b83b8f70
MT
653 free(system_release);
654 free(roottext);
655 free(helpline);
656
f0fa1795 657 free(sourcedrive);
25fcce25
MT
658
659 if (destination) {
660 hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH);
661 free(destination);
662 }
d7dd283b 663
4a0d9bef
MT
664 hw_stop_all_raid_arrays();
665
d7dd283b
MT
666 if (selected_disks)
667 hw_free_disks(selected_disks);
668
669 hw_free(hw);
f0fa1795 670
25fcce25
MT
671 fcloseall();
672
f0a61a0a
MT
673 if (allok == 1)
674 return 0;
25fcce25 675
f0a61a0a 676 return 1;
d6aaa55d 677}