#include <sys/param.h>
#include <stdio.h>
#include <curses.h>
#include "defs.h"
#include "msg_defs.h"
#include "menu_defs.h"
static bool
write_all_parts(struct install_partition_desc *install)
{
struct disk_partitions **allparts, *parts;
#ifndef NO_CLONES
struct selected_partition *src;
#endif
size_t num_parts, i, j;
bool found, res;
allparts = calloc(install->num + install->num_write_back,
sizeof(*allparts));
if (allparts == NULL)
return false;
num_parts = 0;
for (i = 0; i < install->num_write_back; i++) {
parts = install->write_back[i];
if (parts == NULL)
continue;
found = false;
for (j = 0; j < num_parts; j++) {
if (allparts[j] == parts) {
found = true;
break;
}
}
if (found)
continue;
allparts[num_parts++] = parts;
}
for (i = 0; i < install->num; i++) {
parts = install->infos[i].parts;
if (parts == NULL)
continue;
found = false;
for (j = 0; j < num_parts; j++) {
if (allparts[j] == parts) {
found = true;
break;
}
}
if (found)
continue;
allparts[num_parts++] = parts;
}
res = true;
for (i = 0; i < num_parts; i++) {
if (!md_pre_disklabel(install, allparts[i])) {
res = false;
goto out;
}
}
for (i = 0; i < num_parts; i++) {
if (!allparts[i]->pscheme->write_to_disk(allparts[i])) {
res = false;
goto out;
}
}
set_swap_if_low_ram(install);
#ifndef NO_CLONES
for (i = 0; i < install->num; i++) {
if ((install->infos[i].flags & PUIFLG_CLONE_PARTS) == 0
|| install->infos[i].clone_src == NULL
|| !install->infos[i].clone_src->with_data)
continue;
src = &install->infos[i].clone_src
->selection[install->infos[i].clone_ndx];
clone_partition_data(install->infos[i].parts,
install->infos[i].cur_part_id,
src->parts, src->id);
}
#endif
for (i = 0; i < num_parts; i++) {
if (!md_post_disklabel(install, allparts[i])) {
res = false;
goto out;
}
}
out:
free(allparts);
return res;
}
void
do_install(void)
{
int find_disks_ret;
int retcode = 0, res;
struct install_partition_desc install = {};
#ifndef NO_PARTMAN
partman_go = -1;
#else
partman_go = 0;
#endif
#ifndef DEBUG
msg_display(MSG_installusure);
if (!ask_noyes(NULL))
return;
#endif
memset(&install, 0, sizeof install);
find_disks_ret = find_disks(msg_string(MSG_install), false);
if (partman_go == 1) {
if (partman(&install) < 0) {
hit_enter_to_continue(MSG_abort_part, NULL);
return;
}
} else if (find_disks_ret < 0)
return;
else {
partman_go = 0;
clear();
refresh();
if (check_swap(pm->diskdev, 0) > 0) {
hit_enter_to_continue(MSG_swapactive, NULL);
if (check_swap(pm->diskdev, 1) < 0) {
hit_enter_to_continue(MSG_swapdelfailed, NULL);
if (!debug)
return;
}
}
for (;;) {
if (md_get_info(&install)) {
res = md_make_bsd_partitions(&install);
if (res == -1) {
pm->parts = NULL;
continue;
} else if (res == 1) {
break;
}
}
hit_enter_to_continue(MSG_abort_inst, NULL);
goto error;
}
clear();
refresh();
msg_fmt_display(MSG_lastchance, "%s", pm->diskdev);
if (!ask_noyes(NULL))
goto error;
if ((!pm->no_part && !write_all_parts(&install)) ||
make_filesystems(&install) ||
make_fstab(&install) != 0 ||
md_post_newfs(&install) != 0)
goto error;
}
process_menu(MENU_distset, &retcode);
if (retcode == 0)
goto error;
if (get_and_unpack_sets(0, MSG_disksetupdone,
MSG_extractcomplete, MSG_abortinst) != 0)
goto error;
if (md_post_extract(&install, false) != 0)
goto error;
unsetenv("FTPSSLNOVERIFY");
root_pw_setup();
#if CHECK_ENTROPY
do_add_entropy();
#endif
do_configmenu(&install);
sanity_check();
md_cleanup_install(&install);
hit_enter_to_continue(MSG_instcomplete, NULL);
error:
free_install_desc(&install);
}