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 strncpy(buffer
, token
, sizeof(buffer
));
315 char* key
= strsep(&val
, "=");
318 if ((strcmp(key
, "console") == 0) && (strncmp(val
, "ttyS", 4) == 0))
319 c
->serial_console
= 1;
322 else if (strcmp(key
, "novga") == 0)
325 // enable networking?
326 else if (strcmp(token
, "installer.net") == 0)
327 c
->require_networking
= 1;
330 else if (strcmp(token
, "installer.unattended") == 0)
334 else if (strcmp(token
, "installer.disable-swap") == 0)
338 else if (strcmp(key
, "installer.download-url") == 0) {
339 strncpy(c
->download_url
, val
, sizeof(c
->download_url
));
340 c
->perform_download
= 1;
342 // Require networking for the download
343 c
->require_networking
= 1;
345 // postinstall script
346 } else if (strcmp(key
, "installer.postinstall") == 0) {
347 strncpy(c
->postinstall
, val
, sizeof(c
->postinstall
));
349 // Require networking for the download
350 c
->require_networking
= 1;
353 token
= strtok(NULL
, " ");
360 int main(int argc
, char *argv
[]) {
361 struct hw
* hw
= hw_init();
362 const char* logfile
= NULL
;
364 // Read /etc/system-release
365 char* system_release
= get_system_release();
367 char discl_msg
[40000] = "Disclaimer\n";
369 char* sourcedrive
= NULL
;
371 char commandstring
[STRING_SIZE
];
373 char message
[STRING_SIZE
];
374 char title
[STRING_SIZE
];
378 setlocale(LC_ALL
, "");
379 sethostname(DISTRO_SNAME
, 10);
381 /* Log file/terminal stuff. */
385 if (!(flog
= fopen(logfile
, "w+")))
391 fprintf(flog
, "Install program started.\n");
393 fprintf(flog
, "EFI mode enabled\n");
398 // Determine the size of the screen
402 newtGetScreenSize(&screen_cols
, &screen_rows
);
405 char* roottext
= center_string(system_release
, screen_cols
);
407 newtDrawRootText(0, 0, roottext
);
409 snprintf(title
, sizeof(title
), "%s - %s", DISTRO_NAME
, DISTRO_SLOGAN
);
411 // Parse parameters from the kernel command line
412 parse_command_line(flog
, &config
);
414 if (config
.unattended
) {
415 splashWindow(title
, _("Warning: Unattended installation will start in 10 seconds..."), 10);
418 // Load common modules
419 mysystem(logfile
, "/sbin/modprobe vfat"); // USB key
420 mysystem(logfile
, "/sbin/modprobe ntfs3"); // USB key
421 hw_stop_all_raid_arrays(logfile
);
423 if (!config
.unattended
) {
424 // Language selection
425 char* langnames
[NUM_LANGS
+ 1];
427 for (unsigned int i
= 0; i
< NUM_LANGS
; i
++) {
428 if (strcmp(languages
[i
].code
, DEFAULT_LANG
) == 0)
431 langnames
[i
] = languages
[i
].name
;
433 langnames
[NUM_LANGS
] = NULL
;
435 rc
= newtWinMenu(_("Language selection"), _("Select the language you wish to use for the installation."),
436 50, 5, 5, 8, langnames
, &choice
, _("OK"), NULL
);
438 assert(choice
<= NUM_LANGS
);
440 fprintf(flog
, "Selected language: %s (%s)\n", languages
[choice
].name
, languages
[choice
].code
);
441 config
.language
= languages
[choice
].code
;
443 setlocale(LC_ALL
, config
.language
);
444 setenv("LANGUAGE", config
.language
, 1);
448 char* helpline
= NULL
;
449 if (config
.unattended
)
450 helpline
= center_string(_("Unattended mode"), screen_cols
);
452 helpline
= center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols
);
455 newtPushHelpLine(helpline
);
457 if (!config
.unattended
) {
458 snprintf(message
, sizeof(message
),
459 _("Welcome to the %s installation program.\n\n"
460 "Selecting Cancel on any of the following screens will reboot the computer."), DISTRO_NAME
);
461 newtWinMessage(title
, _("Start installation"), message
);
464 /* Search for a source drive that holds the right
465 * version of the image we are going to install. */
466 if (!config
.perform_download
) {
467 sourcedrive
= hw_find_source_medium(hw
);
468 fprintf(flog
, "Source drive: %s\n", sourcedrive
);
471 /* If we could not find a source drive, we will try
472 * downloading the install image */
474 config
.perform_download
= 1;
476 if (config
.perform_download
) {
477 if (!config
.unattended
) {
478 // Show the right message to the user
479 char reason
[STRING_SIZE
];
480 if (config
.perform_download
) {
481 snprintf(reason
, sizeof(reason
),
482 _("The installer will now try downloading the installation image."));
484 snprintf(reason
, sizeof(reason
),
485 _("No source drive could be found.\n\n"
486 "You can try downloading the required installation image."));
488 snprintf(message
, sizeof(message
), "%s %s", reason
,
489 _("Please make sure to connect your machine to a network and "
490 "the installer will try connect to acquire an IP address."));
492 rc
= newtWinOkCancel(title
, message
, 55, 12,
493 _("Download installation image"), _("Cancel"));
499 // Make sure that we enable networking before download
500 config
.require_networking
= 1;
503 // Try starting the networking if we require it
504 if (config
.require_networking
) {
506 statuswindow(60, 4, title
, _("Trying to start networking (DHCP)..."));
508 rc
= hw_start_networking(logfile
);
511 // Networking was successfully started
515 // An error happened, ask the user what to do
517 rc
= newtWinOkCancel(title
, _("Networking could not be started "
518 "but is required to go on with the installation.\n\n"
519 "Please connect your machine to a network with a "
520 "DHCP server and retry."), 50, 10, _("Retry"), _("Cancel"));
527 // Download the image if required
528 if (config
.perform_download
) {
529 fprintf(flog
, "Download URL: %s\n", config
.download_url
);
530 snprintf(commandstring
, sizeof(commandstring
), "/usr/bin/downloadsource.sh %s %s",
531 SOURCE_TEMPFILE
, config
.download_url
);
533 while (!sourcedrive
) {
534 rc
= runcommandwithstatus(commandstring
, title
, _("Downloading installation image..."), logfile
);
536 FILE* f
= fopen(SOURCE_TEMPFILE
, "r");
538 sourcedrive
= strdup(SOURCE_TEMPFILE
);
541 char reason
[STRING_SIZE
] = "-";
543 snprintf(reason
, sizeof(STRING_SIZE
), _("BLAKE2 checksum mismatch"));
545 snprintf(message
, sizeof(message
),
546 _("The installation image could not be downloaded.\n Reason: %s\n\n%s"),
547 reason
, config
.download_url
);
549 rc
= newtWinOkCancel(title
, message
, 75, 12, _("Retry"), _("Cancel"));
559 int r
= hw_mount(sourcedrive
, SOURCE_MOUNT_PATH
, "iso9660", MS_RDONLY
);
560 if (r
) r
= hw_mount(sourcedrive
, SOURCE_MOUNT_PATH
, "ntfs3", MS_RDONLY
);
561 if (r
) r
= hw_mount(sourcedrive
, SOURCE_MOUNT_PATH
, "vfat", MS_RDONLY
);
564 snprintf(message
, sizeof(message
), _("Could not mount %s to %s:\n %s\n"),
565 sourcedrive
, SOURCE_MOUNT_PATH
, strerror(errno
));
570 if (!config
.unattended
) {
571 // Read the license file.
572 if (!(copying
= fopen(LICENSE_FILE
, "r"))) {
573 sprintf(discl_msg
, "Could not open license file: %s\n", LICENSE_FILE
);
574 fprintf(flog
, "%s", discl_msg
);
576 fread(discl_msg
, 1, 40000, copying
);
579 if (newtLicenseBox(_("License Agreement"), discl_msg
, 75, 20)) {
580 errorbox(_("License not accepted!"));
587 int part_type
= HW_PART_TYPE_NORMAL
;
589 // Scan for disks to install on.
590 struct hw_disk
** disks
= hw_find_disks(hw
, sourcedrive
);
592 struct hw_disk
** selected_disks
= NULL
;
593 unsigned int num_selected_disks
= 0;
595 // Check how many disks have been found and what
596 // we can do with them.
597 unsigned int num_disks
= hw_count_disks((const struct hw_disk
**)disks
);
600 // no harddisks found
601 if (num_disks
== 0) {
602 errorbox(_("No hard disk found."));
605 // exactly one disk has been found
606 // or if we are running in unattended mode, we will select
607 // the first disk and go with that one
608 } else if ((num_disks
== 1) || (config
.unattended
&& num_disks
>= 1)) {
609 selected_disks
= hw_select_first_disk(disks
);
611 // more than one usable disk has been found and
612 // the user needs to choose what to do with them
614 const char* disk_names
[num_disks
];
615 int disk_selection
[num_disks
];
617 for (unsigned int i
= 0; i
< num_disks
; i
++) {
618 disk_names
[i
] = disks
[i
]->description
;
619 disk_selection
[i
] = 0;
622 while (!selected_disks
) {
623 rc
= newtChecklist(_("Disk Selection"),
624 _("Select the disk(s) you want to install IPFire on. "
625 "First those will be partitioned, and then the partitions will have a filesystem put on them.\n\n"
626 "ALL DATA ON THE DISK WILL BE DESTROYED."),
627 50, 20, num_disks
, disk_names
, disk_selection
);
633 // Nothing has been selected
634 } else if (rc
== 0) {
635 errorbox(_("No disk has been selected.\n\n"
636 "Please select one or more disks you want to install IPFire on."));
639 selected_disks
= hw_select_disks(disks
, disk_selection
);
644 // Don't print the auto-selected harddisk setup in
646 if (config
.unattended
)
649 num_selected_disks
= hw_count_disks((const struct hw_disk
**)selected_disks
);
651 if (num_selected_disks
== 1) {
652 snprintf(message
, sizeof(message
),
653 _("The installation program will now prepare the chosen harddisk:\n\n %s\n\n"
654 "Do you agree to continue?"), (*selected_disks
)->description
);
655 rc
= newtWinOkCancel(_("Disk Setup"), message
, 50, 10,
656 _("Delete all data"), _("Cancel"));
661 } else if (num_selected_disks
== 2) {
662 snprintf(message
, sizeof(message
),
663 _("The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\n"
664 "Do you agree to continue?"), selected_disks
[0]->description
, selected_disks
[1]->description
);
665 rc
= newtWinOkCancel(_("RAID Setup"), message
, 50, 14,
666 _("Delete all data"), _("Cancel"));
669 part_type
= HW_PART_TYPE_RAID1
;
674 // Currently not supported
676 errorbox(_("Your disk configuration is currently not supported."));
677 fprintf(flog
, "Num disks selected: %d\n", num_selected_disks
);
680 if (selected_disks
) {
681 hw_free_disks(selected_disks
);
682 selected_disks
= NULL
;
686 hw_free_disks(disks
);
688 // Filesystem selection
689 int filesystem
= HW_FS_DEFAULT
;
691 if (!config
.unattended
) {
696 { HW_FS_EXT4
, _("ext4 Filesystem") },
697 { HW_FS_EXT4_WO_JOURNAL
, _("ext4 Filesystem without journal") },
698 { HW_FS_XFS
, _("XFS Filesystem") },
699 { HW_FS_BTRFS
, _("BTRFS Filesystem (EXPERIMENTAL)") },
702 unsigned int num_filesystems
= sizeof(filesystems
) / sizeof(*filesystems
);
704 char* fs_names
[num_filesystems
];
706 for (unsigned int i
= 0; i
< num_filesystems
; i
++) {
707 if (HW_FS_DEFAULT
== filesystems
[i
].fstype
)
710 fs_names
[i
] = filesystems
[i
].description
;
713 rc
= newtWinMenu(_("Filesystem Selection"), _("Please choose your filesystem:"),
714 50, 5, 5, 5, fs_names
, &fs_choice
, _("OK"), _("Cancel"), NULL
);
719 filesystem
= filesystems
[fs_choice
].fstype
;
722 struct hw_destination
* destination
= hw_make_destination(hw
, part_type
,
723 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
);