1 /* SmoothWall install program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Contains main entry point, and misc functions.6
14 #include <libsmooth.h>
18 #include <sys/mount.h>
24 #define _(x) dgettext("installer", x)
26 #define INST_FILECOUNT 30000
27 #define LICENSE_FILE "/cdrom/COPYING"
28 #define SOURCE_TEMPFILE "/tmp/downloads/image.iso"
30 extern char url
[STRING_SIZE
];
34 static int newtChecklist(const char* title
, const char* message
,
35 unsigned int width
, unsigned int height
, unsigned int num_entries
,
36 const char** entries
, int* states
) {
38 const int list_height
= 4;
40 char cbstates
[num_entries
];
42 for (unsigned int i
= 0; i
< num_entries
; i
++) {
43 cbstates
[i
] = states
[i
] ? '*' : ' ';
46 newtCenteredWindow(width
, height
, title
);
48 newtComponent textbox
= newtTextbox(1, 1, width
- 2, height
- 6 - list_height
,
50 newtTextboxSetText(textbox
, message
);
52 int top
= newtTextboxGetNumLines(textbox
) + 2;
54 newtComponent form
= newtForm(NULL
, NULL
, 0);
56 newtComponent sb
= NULL
;
57 if (list_height
< num_entries
) {
58 sb
= newtVerticalScrollbar(
59 width
- 4, top
+ 1, list_height
,
60 NEWT_COLORSET_CHECKBOX
, NEWT_COLORSET_ACTCHECKBOX
);
62 newtFormAddComponent(form
, sb
);
65 newtComponent subform
= newtForm(sb
, NULL
, 0);
66 newtFormSetBackground(subform
, NEWT_COLORSET_CHECKBOX
);
68 newtFormSetHeight(subform
, list_height
);
69 newtFormSetWidth(subform
, width
- 10);
71 for (unsigned int i
= 0; i
< num_entries
; i
++) {
72 newtComponent cb
= newtCheckbox(4, top
+ i
, entries
[i
], cbstates
[i
],
75 newtFormAddComponent(subform
, cb
);
78 newtFormAddComponents(form
, textbox
, subform
, NULL
);
80 newtComponent btn_okay
= newtButton((width
- 18) / 3, height
- 4, _("OK"));
81 newtComponent btn_cancel
= newtButton((width
- 18) / 3 * 2 + 9, height
- 4, _("Cancel"));
82 newtFormAddComponents(form
, btn_okay
, btn_cancel
, NULL
);
84 newtComponent answer
= newtRunForm(form
);
86 if ((answer
== NULL
) || (answer
== btn_cancel
)) {
91 for (unsigned int i
= 0; i
< num_entries
; i
++) {
92 states
[i
] = (cbstates
[i
] != ' ');
99 newtFormDestroy(form
);
105 static int newtWinOkCancel(const char* title
, const char* message
, int width
, int height
,
106 const char* btn_txt_ok
, const char* btn_txt_cancel
) {
109 unsigned int btn_width_ok
= strlen(btn_txt_ok
);
110 unsigned int btn_width_cancel
= strlen(btn_txt_cancel
);
112 // Maybe make the box wider to fix both buttons inside
113 unsigned int min_width
= btn_width_ok
+ btn_width_cancel
+ 5;
114 if (width
< min_width
)
117 unsigned int btn_pos_ok
= (width
/ 3) - (btn_width_ok
/ 2) - 1;
118 unsigned int btn_pos_cancel
= (width
* 2 / 3) - (btn_width_cancel
/ 2) - 1;
120 // Move buttons a bit if they overlap
121 while ((btn_pos_ok
+ btn_width_ok
+ 5) > btn_pos_cancel
) {
122 // Move the cancel button to the right if there is enough space left
123 if ((btn_pos_cancel
+ btn_width_cancel
+ 2) < width
) {
128 // Move the OK button to the left if possible
129 if (btn_pos_ok
> 1) {
134 // If they still overlap, we cannot fix the situtation
135 // and break. Should actually never get here, because we
136 // adjust the width of the window earlier.
140 newtCenteredWindow(width
, height
, title
);
142 newtComponent form
= newtForm(NULL
, NULL
, 0);
144 newtComponent textbox
= newtTextbox(1, 1, width
- 2, height
- 6, NEWT_FLAG_WRAP
);
145 newtTextboxSetText(textbox
, message
);
146 newtFormAddComponent(form
, textbox
);
148 newtComponent btn_ok
= newtButton(btn_pos_ok
, height
- 4, btn_txt_ok
);
149 newtComponent btn_cancel
= newtButton(btn_pos_cancel
, height
- 4, btn_txt_cancel
);
151 newtFormAddComponents(form
, btn_ok
, btn_cancel
, NULL
);
153 newtComponent answer
= newtRunForm(form
);
155 if (answer
== btn_ok
) {
159 newtFormDestroy(form
);
165 static int newtLicenseBox(const char* title
, const char* text
, int width
, int height
) {
168 newtCenteredWindow(width
, height
, title
);
170 newtComponent form
= newtForm(NULL
, NULL
, 0);
172 newtComponent textbox
= newtTextbox(1, 1, width
- 2, height
- 7,
173 NEWT_FLAG_WRAP
|NEWT_FLAG_SCROLL
);
174 newtTextboxSetText(textbox
, text
);
175 newtFormAddComponent(form
, textbox
);
178 newtComponent checkbox
= newtCheckbox(3, height
- 3, _("I accept this license"),
181 newtComponent btn
= newtButton(width
- 15, height
- 4, _("OK"));
183 newtFormAddComponents(form
, checkbox
, btn
, NULL
);
185 newtComponent answer
= newtRunForm(form
);
186 if (answer
== btn
&& choice
== '*')
189 newtFormDestroy(form
);
195 int write_lang_configs(const char* lang
) {
196 struct keyvalue
*kv
= initkeyvalues();
198 /* default stuff for main/settings. */
199 replacekeyvalue(kv
, "LANGUAGE", (char*)lang
);
200 replacekeyvalue(kv
, "HOSTNAME", DISTRO_SNAME
);
201 replacekeyvalue(kv
, "THEME", "ipfire");
202 writekeyvalues(kv
, "/harddisk" CONFIG_ROOT
"/main/settings");
208 static char* get_system_release() {
209 char system_release
[STRING_SIZE
] = "\0";
211 FILE* f
= fopen("/etc/system-release", "r");
213 fgets(system_release
, sizeof(system_release
), f
);
217 return strdup(system_release
);
220 static char* center_string(const char* str
, int width
) {
225 unsigned int str_len
= strlen(str
);
227 if (str_len
== width
) {
228 string
= strdup(str
);
230 } else if (str_len
> width
) {
231 string
= strdup(str
);
232 string
[width
- 1] = '\0';
235 unsigned int indent_length
= (width
- str_len
) / 2;
236 char indent
[indent_length
+ 1];
238 for (unsigned int i
= 0; i
< indent_length
; i
++) {
241 indent
[indent_length
] = '\0';
243 if (asprintf(&string
, "%s%s", indent
, str
) < 0)
250 #define DEFAULT_LANG "en.utf8"
256 } languages
[NUM_LANGS
+ 1] = {
257 { "fa.utf8", "فارسی (Persian)" },
258 { "da.utf8", "Dansk (Danish)" },
259 { "es.utf8", "Español (Spanish)" },
260 { "en.utf8", "English" },
261 { "fr.utf8", "Français (French)" },
262 { "hr.utf8", "Hrvatski (Croatian)" },
263 { "it.utf8", "Italiano (Italian)" },
264 { "de.utf8", "Deutsch (German)" },
265 { "nl.utf8", "Nederlands (Dutch)" },
266 { "pl.utf8", "Polski (Polish)" },
267 { "pt.utf8", "Portuguese (Brasil)" },
268 { "ru.utf8", "Русский (Russian)" },
269 { "tr.utf8", "Türkçe (Turkish)" },
273 static struct config
{
277 int require_networking
;
278 int perform_download
;
280 char download_url
[STRING_SIZE
];
281 char postinstall
[STRING_SIZE
];
282 const char* language
;
287 .require_networking
= 0,
288 .perform_download
= 0,
290 .download_url
= DOWNLOAD_URL
,
292 .language
= DEFAULT_LANG
,
295 static void parse_command_line(FILE* flog
, struct config
* c
) {
296 char buffer
[STRING_SIZE
];
297 char cmdline
[STRING_SIZE
];
299 FILE* f
= fopen("/proc/cmdline", "r");
301 fprintf(flog
, "Could not open /proc/cmdline: %m");
305 int r
= fread(&cmdline
, 1, sizeof(cmdline
) - 1, f
);
307 // Remove the trailing newline
308 if (cmdline
[r
-1] == '\n')
311 char* token
= strtok(cmdline
, " ");
313 snprintf(buffer
, sizeof(buffer
), "%s", token
);
316 char* key
= strsep(&val
, "=");
319 if ((strcmp(key
, "console") == 0) && (strncmp(val
, "ttyS", 4) == 0))
320 c
->serial_console
= 1;
323 else if (strcmp(key
, "novga") == 0)
326 // enable networking?
327 else if (strcmp(token
, "installer.net") == 0)
328 c
->require_networking
= 1;
331 else if (strcmp(token
, "installer.unattended") == 0)
335 else if (strcmp(token
, "installer.disable-swap") == 0)
339 else if (strcmp(key
, "installer.download-url") == 0) {
340 snprintf(c
->download_url
, sizeof(c
->download_url
), "%s", val
);
341 c
->perform_download
= 1;
343 // Require networking for the download
344 c
->require_networking
= 1;
346 // postinstall script
347 } else if (strcmp(key
, "installer.postinstall") == 0) {
348 snprintf(c
->postinstall
, sizeof(c
->postinstall
), "%s", val
);
350 // Require networking for the download
351 c
->require_networking
= 1;
354 token
= strtok(NULL
, " ");
361 int main(int argc
, char *argv
[]) {
362 struct hw
* hw
= hw_init();
363 const char* logfile
= NULL
;
365 // Read /etc/system-release
366 char* system_release
= get_system_release();
368 char discl_msg
[40000] = "Disclaimer\n";
370 char* sourcedrive
= NULL
;
371 struct hw_destination
* destination
= NULL
;
372 struct hw_disk
** selected_disks
= NULL
;
374 char commandstring
[STRING_SIZE
];
376 char message
[STRING_SIZE
];
377 char title
[STRING_SIZE
];
381 setlocale(LC_ALL
, "");
382 sethostname(DISTRO_SNAME
, strlen(DISTRO_SNAME
));
384 /* Log file/terminal stuff. */
388 if (!(flog
= fopen(logfile
, "w+")))
394 fprintf(flog
, "Install program started.\n");
396 fprintf(flog
, "EFI mode enabled\n");
401 // Determine the size of the screen
405 newtGetScreenSize(&screen_cols
, &screen_rows
);
408 char* roottext
= center_string(system_release
, screen_cols
);
410 newtDrawRootText(0, 0, roottext
);
412 snprintf(title
, sizeof(title
), "%s - %s", DISTRO_NAME
, DISTRO_SLOGAN
);
414 // Parse parameters from the kernel command line
415 parse_command_line(flog
, &config
);
417 if (config
.unattended
) {
418 splashWindow(title
, _("Warning: Unattended installation will start in 10 seconds..."), 10);
421 // Load common modules
422 mysystem(logfile
, "/sbin/modprobe vfat"); // USB key
423 mysystem(logfile
, "/sbin/modprobe ntfs3"); // USB key
424 hw_stop_all_raid_arrays(logfile
);
426 if (!config
.unattended
) {
427 // Language selection
428 char* langnames
[NUM_LANGS
+ 1];
430 for (unsigned int i
= 0; i
< NUM_LANGS
; i
++) {
431 if (strcmp(languages
[i
].code
, DEFAULT_LANG
) == 0)
434 langnames
[i
] = languages
[i
].name
;
436 langnames
[NUM_LANGS
] = NULL
;
438 rc
= newtWinMenu(_("Language selection"), _("Select the language you wish to use for the installation."),
439 50, 5, 5, 8, langnames
, &choice
, _("OK"), NULL
);
441 assert(choice
<= NUM_LANGS
);
443 fprintf(flog
, "Selected language: %s (%s)\n", languages
[choice
].name
, languages
[choice
].code
);
444 config
.language
= languages
[choice
].code
;
446 setlocale(LC_ALL
, config
.language
);
447 setenv("LANGUAGE", config
.language
, 1);
451 char* helpline
= NULL
;
452 if (config
.unattended
)
453 helpline
= center_string(_("Unattended mode"), screen_cols
);
455 helpline
= center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols
);
458 newtPushHelpLine(helpline
);
460 if (!config
.unattended
) {
461 snprintf(message
, sizeof(message
),
462 _("Welcome to the %s installation program.\n\n"
463 "Selecting Cancel on any of the following screens will reboot the computer."), DISTRO_NAME
);
464 newtWinMessage(title
, _("Start installation"), message
);
467 /* Search for a source drive that holds the right
468 * version of the image we are going to install. */
469 if (!config
.perform_download
) {
470 sourcedrive
= hw_find_source_medium(hw
);
471 fprintf(flog
, "Source drive: %s\n", sourcedrive
);
474 /* If we could not find a source drive, we will try
475 * downloading the install image */
477 config
.perform_download
= 1;
479 if (config
.perform_download
) {
480 if (!config
.unattended
) {
481 // Show the right message to the user
482 char reason
[STRING_SIZE
];
483 if (config
.perform_download
) {
484 snprintf(reason
, sizeof(reason
),
485 _("The installer will now try downloading the installation image."));
487 snprintf(reason
, sizeof(reason
),
488 _("No source drive could be found.\n\n"
489 "You can try downloading the required installation image."));
491 snprintf(message
, sizeof(message
), "%s %s", reason
,
492 _("Please make sure to connect your machine to a network and "
493 "the installer will try connect to acquire an IP address."));
495 rc
= newtWinOkCancel(title
, message
, 55, 12,
496 _("Download installation image"), _("Cancel"));
502 // Make sure that we enable networking before download
503 config
.require_networking
= 1;
506 // Try starting the networking if we require it
507 if (config
.require_networking
) {
509 statuswindow(60, 4, title
, _("Trying to start networking (DHCP)..."));
511 rc
= hw_start_networking(logfile
);
514 // Networking was successfully started
518 // An error happened, ask the user what to do
520 rc
= newtWinOkCancel(title
, _("Networking could not be started "
521 "but is required to go on with the installation.\n\n"
522 "Please connect your machine to a network with a "
523 "DHCP server and retry."), 50, 10, _("Retry"), _("Cancel"));
530 // Download the image if required
531 if (config
.perform_download
) {
532 fprintf(flog
, "Download URL: %s\n", config
.download_url
);
533 snprintf(commandstring
, sizeof(commandstring
), "/usr/bin/downloadsource.sh %s %s",
534 SOURCE_TEMPFILE
, config
.download_url
);
536 while (!sourcedrive
) {
537 rc
= runcommandwithstatus(commandstring
, title
, _("Downloading installation image..."), logfile
);
539 FILE* f
= fopen(SOURCE_TEMPFILE
, "r");
541 sourcedrive
= strdup(SOURCE_TEMPFILE
);
544 char reason
[STRING_SIZE
] = "-";
546 snprintf(reason
, sizeof(STRING_SIZE
), _("BLAKE2 checksum mismatch"));
548 snprintf(message
, sizeof(message
),
549 _("The installation image could not be downloaded.\n Reason: %s\n\n%s"),
550 reason
, config
.download_url
);
552 rc
= newtWinOkCancel(title
, message
, 75, 12, _("Retry"), _("Cancel"));
562 int r
= hw_mount(sourcedrive
, SOURCE_MOUNT_PATH
, "iso9660", MS_RDONLY
);
563 if (r
) r
= hw_mount(sourcedrive
, SOURCE_MOUNT_PATH
, "ntfs3", MS_RDONLY
);
564 if (r
) r
= hw_mount(sourcedrive
, SOURCE_MOUNT_PATH
, "vfat", MS_RDONLY
);
567 snprintf(message
, sizeof(message
), _("Could not mount %s to %s:\n %s\n"),
568 sourcedrive
, SOURCE_MOUNT_PATH
, strerror(errno
));
573 if (!config
.unattended
) {
574 // Read the license file.
575 if (!(copying
= fopen(LICENSE_FILE
, "r"))) {
576 sprintf(discl_msg
, "Could not open license file: %s\n", LICENSE_FILE
);
577 fprintf(flog
, "%s", discl_msg
);
579 fread(discl_msg
, 1, 40000, copying
);
582 if (newtLicenseBox(_("License Agreement"), discl_msg
, 75, 20)) {
583 errorbox(_("License not accepted!"));
590 int part_type
= HW_PART_TYPE_NORMAL
;
592 // Scan for disks to install on.
593 struct hw_disk
** disks
= hw_find_disks(hw
, sourcedrive
);
594 unsigned int num_selected_disks
= 0;
596 // Check how many disks have been found and what
597 // we can do with them.
598 unsigned int num_disks
= hw_count_disks(disks
);
601 // no harddisks found
602 if (num_disks
== 0) {
603 errorbox(_("No hard disk found."));
606 // exactly one disk has been found
607 // or if we are running in unattended mode, we will select
608 // the first disk and go with that one
609 } else if ((num_disks
== 1) || (config
.unattended
&& num_disks
>= 1)) {
610 selected_disks
= hw_select_first_disk(disks
);
612 // more than one usable disk has been found and
613 // the user needs to choose what to do with them
615 const char* disk_names
[num_disks
];
616 int disk_selection
[num_disks
];
618 for (unsigned int i
= 0; i
< num_disks
; i
++) {
619 disk_names
[i
] = disks
[i
]->description
;
620 disk_selection
[i
] = 0;
623 while (!selected_disks
) {
624 rc
= newtChecklist(_("Disk Selection"),
625 _("Select the disk(s) you want to install IPFire on. "
626 "First those will be partitioned, and then the partitions will have a filesystem put on them.\n\n"
627 "ALL DATA ON THE DISK WILL BE DESTROYED."),
628 50, 20, num_disks
, disk_names
, disk_selection
);
634 // Nothing has been selected
635 } else if (rc
== 0) {
636 errorbox(_("No disk has been selected.\n\n"
637 "Please select one or more disks you want to install IPFire on."));
640 selected_disks
= hw_select_disks(disks
, disk_selection
);
645 // Don't print the auto-selected harddisk setup in
647 if (config
.unattended
)
650 num_selected_disks
= hw_count_disks(selected_disks
);
652 if (num_selected_disks
== 1) {
653 snprintf(message
, sizeof(message
),
654 _("The installation program will now prepare the chosen harddisk:\n\n %s\n\n"
655 "Do you agree to continue?"), (*selected_disks
)->description
);
656 rc
= newtWinOkCancel(_("Disk Setup"), message
, 50, 10,
657 _("Delete all data"), _("Cancel"));
662 } else if (num_selected_disks
== 2) {
663 snprintf(message
, sizeof(message
),
664 _("The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\n"
665 "Do you agree to continue?"), selected_disks
[0]->description
, selected_disks
[1]->description
);
666 rc
= newtWinOkCancel(_("RAID Setup"), message
, 50, 14,
667 _("Delete all data"), _("Cancel"));
670 part_type
= HW_PART_TYPE_RAID1
;
675 // Currently not supported
677 errorbox(_("Your disk configuration is currently not supported."));
678 fprintf(flog
, "Num disks selected: %d\n", num_selected_disks
);
681 if (selected_disks
) {
682 hw_free_disks(selected_disks
);
683 selected_disks
= NULL
;
687 hw_free_disks(disks
);
689 // Filesystem selection
690 int filesystem
= HW_FS_DEFAULT
;
692 if (!config
.unattended
) {
697 { HW_FS_EXT4
, _("ext4 Filesystem") },
698 { HW_FS_EXT4_WO_JOURNAL
, _("ext4 Filesystem without journal") },
699 { HW_FS_XFS
, _("XFS Filesystem") },
700 { HW_FS_BTRFS
, _("BTRFS Filesystem (EXPERIMENTAL)") },
703 unsigned int num_filesystems
= sizeof(filesystems
) / sizeof(*filesystems
);
705 char* fs_names
[num_filesystems
];
707 for (unsigned int i
= 0; i
< num_filesystems
; i
++) {
708 if (HW_FS_DEFAULT
== filesystems
[i
].fstype
)
711 fs_names
[i
] = filesystems
[i
].description
;
714 rc
= newtWinMenu(_("Filesystem Selection"), _("Please choose your filesystem:"),
715 50, 5, 5, 5, fs_names
, &fs_choice
, _("OK"), _("Cancel"), NULL
);
720 filesystem
= filesystems
[fs_choice
].fstype
;
723 destination
= hw_make_destination(hw
, part_type
, selected_disks
, config
.disable_swap
, filesystem
);
726 errorbox(_("Your harddisk is too small."));
730 fprintf(flog
, "Destination drive: %s\n", destination
->path
);
731 fprintf(flog
, " bootldr: %s (%lluMB)\n", destination
->part_bootldr
, BYTES2MB(destination
->size_bootldr
));
732 fprintf(flog
, " boot : %s (%lluMB)\n", destination
->part_boot
, BYTES2MB(destination
->size_boot
));
733 fprintf(flog
, " ESP : %s (%lluMB)\n", destination
->part_boot_efi
, BYTES2MB(destination
->size_boot_efi
));
734 fprintf(flog
, " swap : %s (%lluMB)\n", destination
->part_swap
, BYTES2MB(destination
->size_swap
));
735 fprintf(flog
, " root : %s (%lluMB)\n", destination
->part_root
, BYTES2MB(destination
->size_root
));
736 fprintf(flog
, "Memory : %lluMB\n", BYTES2MB(hw_memory()));
738 // Warn the user if there is not enough space to create a swap partition
739 if (!config
.unattended
) {
740 if (!config
.disable_swap
&& !*destination
->part_swap
) {
741 rc
= newtWinChoice(title
, _("OK"), _("Cancel"),
742 _("Your harddisk is very small, but you can continue without a swap partition."));
749 // Setting up RAID if needed.
750 if (destination
->is_raid
) {
751 statuswindow(60, 4, title
, _("Building RAID..."));
753 rc
= hw_setup_raid(destination
, logfile
);
755 errorbox(_("Unable to build the RAID."));
761 // We will have to destroy all RAID setups that may have
762 // been on the devices that we want to use now.
763 hw_destroy_raid_superblocks(destination
, logfile
);
766 // Execute the partitioning...
767 statuswindow(60, 4, title
, _("Partitioning disk..."));
769 rc
= hw_create_partitions(destination
, logfile
);
771 errorbox(_("Unable to partition the disk."));
777 // Execute the formatting...
778 statuswindow(60, 4, title
, _("Creating filesystems..."));
780 rc
= hw_create_filesystems(destination
, logfile
);
782 errorbox(_("Unable to create filesystems."));
786 rc
= hw_mount_filesystems(destination
, DESTINATION_MOUNT_PATH
);
788 errorbox(_("Unable to mount filesystems."));
795 snprintf(commandstring
, STRING_SIZE
,
796 "/bin/tar --acls --xattrs --xattrs-include='*' -C /harddisk -xvf /cdrom/distro.img --zstd 2>/dev/null");
798 if (runcommandwithprogress(60, 4, title
, commandstring
, INST_FILECOUNT
,
799 _("Installing the system..."), logfile
)) {
800 errorbox(_("Unable to install the system."));
805 rc
= hw_write_fstab(destination
);
807 fprintf(flog
, "Could not write /etc/fstab\n");
811 /* Save language und local settings */
812 write_lang_configs(config
.language
);
814 /* Build cache lang file */
815 snprintf(commandstring
, STRING_SIZE
, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT
"/lang.pl'; &Lang::BuildCacheLang\"");
816 if (runcommandwithstatus(commandstring
, title
, _("Installing the language cache..."), logfile
)) {
817 errorbox(_("Unable to install the language cache."));
821 /* trigger udev to add disk-by-uuid entries */
822 snprintf(commandstring
, STRING_SIZE
, "/usr/sbin/chroot /harddisk /sbin/udevadm trigger");
823 if (runcommandwithstatus(commandstring
, title
, _("Trigger udev to redetect partitions..."), logfile
)) {
824 errorbox(_("Error triggering udev to redetect partitions."));
828 // Installing bootloader...
829 statuswindow(60, 4, title
, _("Installing the bootloader..."));
831 /* Serial console ? */
832 if (config
.serial_console
) {
834 FILE* f
= fopen(DESTINATION_MOUNT_PATH
"/etc/default/grub", "a");
836 errorbox(_("Unable to open /etc/default/grub for writing."));
840 fprintf(f
, "GRUB_TERMINAL=\"serial\"\n");
841 fprintf(f
, "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=%d\"\n", SERIAL_BAUDRATE
);
844 replace(DESTINATION_MOUNT_PATH
"/etc/default/grub", "panic=10", "panic=10 console=ttyS0,115200n8");
850 FILE* f
= fopen(DESTINATION_MOUNT_PATH
"/etc/default/grub", "a");
852 errorbox(_("Unable to open /etc/default/grub for writing."));
856 fprintf(f
, "GRUB_GFXMODE=\"none\"\n");
860 rc
= hw_install_bootloader(hw
, destination
, logfile
);
862 errorbox(_("Unable to install the bootloader."));
868 /* Set marker that the user has already accepted the GPL if the license has been shown
869 * in the installation process. In unatteded mode, the user will be presented the
870 * license when he or she logs on to the web user interface for the first time. */
871 if (!config
.unattended
)
872 mysystem(logfile
, "/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");
874 /* Copy restore file from cdrom */
875 char* backup_file
= hw_find_backup_file(logfile
, SOURCE_MOUNT_PATH
);
878 if (!config
.unattended
) {
879 rc
= newtWinOkCancel(title
, _("A backup file has been found on the installation image.\n\n"
880 "Do you want to restore the backup?"), 50, 10, _("Yes"), _("No"));
884 rc
= hw_restore_backup(logfile
, backup_file
, DESTINATION_MOUNT_PATH
);
887 errorbox(_("An error occured when the backup file was restored."));
895 // Download and execute the postinstall script
896 if (*config
.postinstall
) {
897 snprintf(commandstring
, sizeof(commandstring
),
898 "/usr/bin/execute-postinstall.sh %s %s", DESTINATION_MOUNT_PATH
, config
.postinstall
);
900 if (runcommandwithstatus(commandstring
, title
, _("Running post-install script..."), logfile
)) {
901 errorbox(_("Post-install script failed."));
906 // Umount the destination drive
907 statuswindow(60, 4, title
, _("Umounting filesystems..."));
909 rc
= hw_umount_filesystems(destination
, DESTINATION_MOUNT_PATH
);
911 // Show an error message if filesystems could not be umounted properly
912 snprintf(message
, sizeof(message
),
913 _("Could not umount all filesystems successfully:\n\n %s"), strerror(errno
));
918 // Umount source drive and eject
919 hw_umount(SOURCE_MOUNT_PATH
, NULL
);
921 // Free downloaded ISO image
922 if (strcmp(sourcedrive
, SOURCE_TEMPFILE
) == 0) {
923 rc
= unlink(sourcedrive
);
925 fprintf(flog
, "Could not free downloaded ISO image: %s\n", sourcedrive
);
927 // or eject real images
929 snprintf(commandstring
, STRING_SIZE
, "/usr/bin/eject %s", sourcedrive
);
930 mysystem(logfile
, commandstring
);
934 // Stop the RAID array if we are using RAID
935 if (destination
->is_raid
)
936 hw_stop_all_raid_arrays(logfile
);
938 // Show a short message that the installation went well and
939 // wait a moment so that all disk caches get flushed.
940 if (config
.unattended
) {
941 splashWindow(title
, _("Unattended installation has finished. The system will be shutting down in a moment..."), 5);
944 snprintf(message
, sizeof(message
), _(
945 "%s was successfully installed!\n\n"
946 "Please remove any installation mediums from this system and hit the reboot button. "
947 "Once the system has restarted you will be asked to setup networking and system passwords. "
948 "After that, you should point your web browser at https://%s:444 (or what ever you name "
949 "your %s) for the web configuration console."), DISTRO_NAME
, DISTRO_SNAME
, DISTRO_NAME
);
950 newtWinMessage(_("Congratulations!"), _("Reboot"), message
);
956 fprintf(flog
, "Install program ended.\n");
961 newtWinMessage(title
, _("OK"), _("Setup has failed. Press Ok to reboot."));
967 free(system_release
);
981 hw_stop_all_raid_arrays(logfile
);
984 hw_free_disks(selected_disks
);