#include <libintl.h>
#define _(x) dgettext("installer", x)
-#define INST_FILECOUNT 21000
+#define INST_FILECOUNT 24800
#define LICENSE_FILE "/cdrom/COPYING"
-#define SOURCE_TEMPFILE "/tmp/downloaded-image.iso"
+#define SOURCE_TEMPFILE "/tmp/downloads/image.iso"
extern char url[STRING_SIZE];
const char* btn_txt_ok, const char* btn_txt_cancel) {
int ret = 1;
+ unsigned int btn_width_ok = strlen(btn_txt_ok);
+ unsigned int btn_width_cancel = strlen(btn_txt_cancel);
+
+ // Maybe make the box wider to fix both buttons inside
+ unsigned int min_width = btn_width_ok + btn_width_cancel + 5;
+ if (width < min_width)
+ width = min_width;
+
+ unsigned int btn_pos_ok = (width / 3) - (btn_width_ok / 2) - 1;
+ unsigned int btn_pos_cancel = (width * 2 / 3) - (btn_width_cancel / 2) - 1;
+
+ // Move buttons a bit if they overlap
+ while ((btn_pos_ok + btn_width_ok + 5) > btn_pos_cancel) {
+ // Move the cancel button to the right if there is enough space left
+ if ((btn_pos_cancel + btn_width_cancel + 2) < width) {
+ ++btn_pos_cancel;
+ continue;
+ }
+
+ // Move the OK button to the left if possible
+ if (btn_pos_ok > 1) {
+ --btn_pos_ok;
+ continue;
+ }
+
+ // If they still overlap, we cannot fix the situtation
+ // and break. Should actually never get here, because we
+ // adjust the width of the window earlier.
+ break;
+ }
+
newtCenteredWindow(width, height, title);
newtComponent form = newtForm(NULL, NULL, 0);
newtTextboxSetText(textbox, message);
newtFormAddComponent(form, textbox);
- unsigned int btn_width_ok = strlen(btn_txt_ok);
- unsigned int btn_width_cancel = strlen(btn_txt_cancel);
-
- newtComponent btn_ok = newtButton((width / 3) - (btn_width_ok / 2) - 2, height - 4, btn_txt_ok);
- newtComponent btn_cancel = newtButton((width * 2 / 3) - (btn_width_cancel / 2) - 2, height - 4,
- btn_txt_cancel);
+ newtComponent btn_ok = newtButton(btn_pos_ok, height - 4, btn_txt_ok);
+ newtComponent btn_cancel = newtButton(btn_pos_cancel, height - 4, btn_txt_cancel);
newtFormAddComponents(form, btn_ok, btn_cancel, NULL);
/* default stuff for main/settings. */
replacekeyvalue(kv, "LANGUAGE", lang);
- replacekeyvalue(kv, "HOSTNAME", SNAME);
+ replacekeyvalue(kv, "HOSTNAME", DISTRO_SNAME);
replacekeyvalue(kv, "THEME", "ipfire");
writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings");
freekeyvalues(kv);
}
static char* center_string(const char* str, int width) {
+ if (!str)
+ return NULL;
+
+ char* string = NULL;
unsigned int str_len = strlen(str);
- unsigned int indent_length = (width - str_len) / 2;
- char indent[indent_length + 1];
+ if (str_len == width) {
+ string = strdup(str);
- for (unsigned int i = 0; i < indent_length; i++) {
- indent[i] = ' ';
- }
- indent[indent_length] = '\0';
+ } else if (str_len > width) {
+ string = strdup(str);
+ string[width - 1] = '\0';
- char* string = NULL;
- if (asprintf(&string, "%s%s", indent, str) < 0)
- return NULL;
+ } else {
+ unsigned int indent_length = (width - str_len) / 2;
+ char indent[indent_length + 1];
+
+ for (unsigned int i = 0; i < indent_length; i++) {
+ indent[i] = ' ';
+ }
+ indent[indent_length] = '\0';
+
+ if (asprintf(&string, "%s%s", indent, str) < 0)
+ return NULL;
+ }
return string;
}
-#define DEFAULT_LANG "English"
-#define NUM_LANGS 10
+#define DEFAULT_LANG "en.utf8"
+#define NUM_LANGS 13
static struct lang {
const char* code;
char* name;
} languages[NUM_LANGS + 1] = {
- { "da.utf8", "Danish (Dansk)" },
- { "nl_NL.utf8", "Dutch (Nederlands)" },
- { "en_US.utf8", "English" },
- { "fr_FR.utf8", "French (Français)" },
- { "de_DE.utf8", "German (Deutsch)" },
- { "pl_PL.utf8", "Polish (Polski)" },
- { "pt_BR.utf8", "Portuguese (Brasil)" },
- { "ru_RU.utf8", "Russian (Русский)" },
- { "es_ES.utf8", "Spanish (Español)" },
- { "tr_TR.utf8", "Turkish (Türkçe)" },
+ { "fa.utf8", "فارسی (Persian)" },
+ { "da.utf8", "Dansk (Danish)" },
+ { "es.utf8", "Español (Spanish)" },
+ { "en.utf8", "English" },
+ { "fr.utf8", "Français (French)" },
+ { "hr.utf8", "Hrvatski (Croatian)" },
+ { "it.utf8", "Italiano (Italian)" },
+ { "de.utf8", "Deutsch (German)" },
+ { "nl.utf8", "Nederlands (Dutch)" },
+ { "pl.utf8", "Polski (Polish)" },
+ { "pt.utf8", "Portuguese (Brasil)" },
+ { "ru.utf8", "Русский (Russian)" },
+ { "tr.utf8", "Türkçe (Turkish)" },
{ NULL, NULL },
};
static struct config {
int unattended;
int serial_console;
+ int novga;
int require_networking;
int perform_download;
+ int disable_swap;
char download_url[STRING_SIZE];
+ char postinstall[STRING_SIZE];
+ char* language;
} config = {
.unattended = 0,
.serial_console = 0,
+ .novga = 0,
.require_networking = 0,
.perform_download = 0,
+ .disable_swap = 0,
.download_url = DOWNLOAD_URL,
+ .postinstall = "\0",
+ .language = DEFAULT_LANG,
};
static void parse_command_line(struct config* c) {
char* key = strsep(&val, "=");
// serial console
- if (strcmp(token, "console=ttyS0") == 0)
+ if ((strcmp(key, "console") == 0) && (strncmp(val, "ttyS", 4) == 0))
c->serial_console = 1;
+ // novga
+ else if (strcmp(key, "novga") == 0)
+ c->novga = 1;
+
// enable networking?
else if (strcmp(token, "installer.net") == 0)
c->require_networking = 1;
else if (strcmp(token, "installer.unattended") == 0)
c->unattended = 1;
+ // disable swap
+ else if (strcmp(token, "installer.disable-swap") == 0)
+ c->disable_swap = 1;
+
// download url
else if (strcmp(key, "installer.download-url") == 0) {
strncpy(c->download_url, val, sizeof(c->download_url));
c->perform_download = 1;
+ // Require networking for the download
+ c->require_networking = 1;
+
+ // postinstall script
+ } else if (strcmp(key, "installer.postinstall") == 0) {
+ strncpy(c->postinstall, val, sizeof(c->postinstall));
+
// Require networking for the download
c->require_networking = 1;
}
int rc = 0;
char commandstring[STRING_SIZE];
int choice;
- char language[STRING_SIZE];
char message[STRING_SIZE];
char title[STRING_SIZE];
int allok = 0;
FILE *copying;
setlocale(LC_ALL, "");
- sethostname(SNAME, 10);
+ sethostname(DISTRO_SNAME, 10);
/* Log file/terminal stuff. */
FILE* flog = NULL;
}
fprintf(flog, "Install program started.\n");
-
+ if (hw->efi)
+ fprintf(flog, "EFI mode enabled\n");
+
newtInit();
newtCls();
// Draw title
char* roottext = center_string(system_release, screen_cols);
- newtDrawRootText(0, 0, roottext);
+ if (roottext)
+ newtDrawRootText(0, 0, roottext);
- snprintf(title, sizeof(title), "%s - %s", NAME, SLOGAN);
+ snprintf(title, sizeof(title), "%s - %s", DISTRO_NAME, DISTRO_SLOGAN);
// Parse parameters from the kernel command line
parse_command_line(&config);
char* langnames[NUM_LANGS + 1];
for (unsigned int i = 0; i < NUM_LANGS; i++) {
- if (strcmp(languages[i].name, DEFAULT_LANG) == 0)
+ if (strcmp(languages[i].code, DEFAULT_LANG) == 0)
choice = i;
langnames[i] = languages[i].name;
assert(choice <= NUM_LANGS);
fprintf(flog, "Selected language: %s (%s)\n", languages[choice].name, languages[choice].code);
- snprintf(language, sizeof(language), "%s", languages[choice].code);
+ config.language = languages[choice].code;
- setenv("LANGUAGE", language, 1);
- setlocale(LC_ALL, language);
+ setlocale(LC_ALL, config.language);
+ setenv("LANGUAGE", config.language, 1);
}
- char* helpline = center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols);
- newtPushHelpLine(helpline);
+ // Set helpline
+ char* helpline = NULL;
+ if (config.unattended)
+ helpline = center_string(_("Unattended mode"), screen_cols);
+ else
+ helpline = center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols);
+
+ if (helpline)
+ newtPushHelpLine(helpline);
if (!config.unattended) {
snprintf(message, sizeof(message),
_("Welcome to the %s installation program.\n\n"
- "Selecting Cancel on any of the following screens will reboot the computer."), NAME);
+ "Selecting Cancel on any of the following screens will reboot the computer."), DISTRO_NAME);
newtWinMessage(title, _("Start installation"), message);
}
FILE* f = fopen(SOURCE_TEMPFILE, "r");
if (f) {
- sourcedrive = SOURCE_TEMPFILE;
+ sourcedrive = strdup(SOURCE_TEMPFILE);
fclose(f);
} else {
char reason[STRING_SIZE] = "-";
hw_free_disks(disks);
- struct hw_destination* destination = hw_make_destination(part_type, selected_disks);
+ struct hw_destination* destination = hw_make_destination(hw, part_type,
+ selected_disks, config.disable_swap);
if (!destination) {
errorbox(_("Your harddisk is too small."));
fprintf(flog, "Destination drive: %s\n", destination->path);
fprintf(flog, " bootldr: %s (%lluMB)\n", destination->part_bootldr, BYTES2MB(destination->size_bootldr));
fprintf(flog, " boot : %s (%lluMB)\n", destination->part_boot, BYTES2MB(destination->size_boot));
+ fprintf(flog, " ESP : %s (%lluMB)\n", destination->part_boot_efi, BYTES2MB(destination->size_boot_efi));
fprintf(flog, " swap : %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap));
fprintf(flog, " root : %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root));
- fprintf(flog, " data : %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data));
fprintf(flog, "Memory : %lluMB\n", BYTES2MB(hw_memory()));
// Warn the user if there is not enough space to create a swap partition
- if (!config.unattended && !*destination->part_swap) {
- rc = newtWinChoice(title, _("OK"), _("Cancel"),
- _("Your harddisk is very small, but you can continue without a swap partition."));
+ if (!config.unattended) {
+ if (!config.disable_swap && !*destination->part_swap) {
+ rc = newtWinChoice(title, _("OK"), _("Cancel"),
+ _("Your harddisk is very small, but you can continue without a swap partition."));
- if (rc != 1)
- goto EXIT;
+ if (rc != 1)
+ goto EXIT;
+ }
}
// Filesystem selection
if (!config.unattended) {
struct filesystems {
int fstype;
- const char* description;
+ char* description;
} filesystems[] = {
{ HW_FS_EXT4, _("ext4 Filesystem") },
{ HW_FS_EXT4_WO_JOURNAL, _("ext4 Filesystem without journal") },
if (HW_FS_DEFAULT == filesystems[i].fstype)
fs_choice = i;
- fs_names[i] = &filesystems[i].description;
+ fs_names[i] = filesystems[i].description;
}
rc = newtWinMenu(_("Filesystem Selection"), _("Please choose your filesystem:"),
// Extract files...
snprintf(commandstring, STRING_SIZE,
- "/bin/tar -C /harddisk -xvf /cdrom/distro.img --lzma 2>/dev/null");
+ "/bin/tar -C /harddisk -xvf /cdrom/distro.img --xz 2>/dev/null");
if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
_("Installing the system..."), logfile)) {
}
/* Save language und local settings */
- write_lang_configs(language);
+ write_lang_configs(config.language);
/* Build cache lang file */
snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
fclose(f);
replace(DESTINATION_MOUNT_PATH "/etc/default/grub", "panic=10", "panic=10 console=ttyS0,115200n8");
+ }
+
+ /* novga */
+ if (config.novga) {
+ /* grub */
+ FILE* f = fopen(DESTINATION_MOUNT_PATH "/etc/default/grub", "a");
+ if (!f) {
+ errorbox(_("Unable to open /etc/default/grub for writing."));
+ goto EXIT;
+ }
- /* inittab */
- replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:");
- replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:");
- replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:");
- replace("/harddisk/etc/inittab", "4:2345:respawn:", "#4:2345:respawn:");
- replace("/harddisk/etc/inittab", "5:2345:respawn:", "#5:2345:respawn:");
- replace("/harddisk/etc/inittab", "6:2345:respawn:", "#6:2345:respawn:");
- replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:");
+ fprintf(f, "GRUB_GFXMODE=\"none\"\n");
+ fclose(f);
}
- rc = hw_install_bootloader(destination, logfile);
+ rc = hw_install_bootloader(hw, destination, logfile);
if (rc) {
errorbox(_("Unable to install the bootloader."));
goto EXIT;
newtPopWindow();
- /* Set marker that the user has already accepted the gpl */
- mysystem(logfile, "/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");
+ /* Set marker that the user has already accepted the GPL if the license has been shown
+ * in the installation process. In unatteded mode, the user will be presented the
+ * license when he or she logs on to the web user interface for the first time. */
+ if (!config.unattended)
+ mysystem(logfile, "/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");
/* Copy restore file from cdrom */
char* backup_file = hw_find_backup_file(logfile, SOURCE_MOUNT_PATH);
free(backup_file);
}
+ // Download and execute the postinstall script
+ if (*config.postinstall) {
+ snprintf(commandstring, sizeof(commandstring),
+ "/usr/bin/execute-postinstall.sh %s %s", DESTINATION_MOUNT_PATH, config.postinstall);
+
+ if (runcommandwithstatus(commandstring, title, _("Running post-install script..."), logfile)) {
+ errorbox(_("Post-install script failed."));
+ goto EXIT;
+ }
+ }
+
// Umount the destination drive
- hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH);
+ statuswindow(60, 4, title, _("Umounting filesystems..."));
- // Stop the RAID array if we are using RAID
- if (destination->is_raid)
- hw_stop_all_raid_arrays(logfile);
+ rc = hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH);
+ if (rc) {
+ // Show an error message if filesystems could not be umounted properly
+ snprintf(message, sizeof(message),
+ _("Could not umount all filesystems successfully:\n\n %s"), strerror(errno));
+ errorbox(message);
+ goto EXIT;
+ }
// Umount source drive and eject
hw_umount(SOURCE_MOUNT_PATH);
- snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive);
- mysystem(logfile, commandstring);
+ // Free downloaded ISO image
+ if (strcmp(sourcedrive, SOURCE_TEMPFILE) == 0) {
+ rc = unlink(sourcedrive);
+ if (rc)
+ fprintf(flog, "Could not free downloaded ISO image: %s\n", sourcedrive);
- if (!config.unattended) {
+ // or eject real images
+ } else {
+ snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive);
+ mysystem(logfile, commandstring);
+ }
+ newtPopWindow();
+
+ // Stop the RAID array if we are using RAID
+ if (destination->is_raid)
+ hw_stop_all_raid_arrays(logfile);
+
+ // Show a short message that the installation went well and
+ // wait a moment so that all disk caches get flushed.
+ if (config.unattended) {
+ splashWindow(title, _("Unattended installation has finished. The system will be shutting down in a moment..."), 5);
+
+ } else {
snprintf(message, sizeof(message), _(
"%s was successfully installed!\n\n"
"Please remove any installation mediums from this system and hit the reboot button. "
"Once the system has restarted you will be asked to setup networking and system passwords. "
"After that, you should point your web browser at https://%s:444 (or what ever you name "
- "your %s) for the web configuration console."), NAME, SNAME, NAME);
+ "your %s) for the web configuration console."), DISTRO_NAME, DISTRO_SNAME, DISTRO_NAME);
newtWinMessage(_("Congratulations!"), _("Reboot"), message);
}
newtFinished();
// Free resources
- free(system_release);
- free(roottext);
- free(helpline);
+ if (system_release)
+ free(system_release);
+
+ if (roottext)
+ free(roottext);
+
+ if (helpline)
+ free(helpline);
+
+ if (sourcedrive)
+ free(sourcedrive);
- free(sourcedrive);
- free(destination);
+ if (destination)
+ free(destination);
hw_stop_all_raid_arrays(logfile);
if (selected_disks)
hw_free_disks(selected_disks);
- hw_free(hw);
+ if (hw)
+ hw_free(hw);
fcloseall();