#include <sys/param.h>
#include <stdio.h>
#include <curses.h>
#include <errno.h>
#include "defs.h"
#include "msg_defs.h"
#include "menu_defs.h"
static int save_X(const char *);
static int merge_X(const char *);
void
do_upgrade(void)
{
struct install_partition_desc install = {};
int retcode = 0;
partman_go = 0;
msg_display(MSG_upgradeusure);
if (!ask_noyes(NULL))
return;
if (find_disks(msg_string(MSG_upgrade), !root_is_read_only()) < 0)
return;
if (pm->parts == NULL && !pm->cur_system && !pm->no_part) {
hit_enter_to_continue(MSG_noroot, NULL);
return;
}
if (!pm->cur_system && pm->parts != NULL) {
if (pm->parts->pscheme->pre_update_verify) {
if (pm->parts->pscheme->pre_update_verify(pm->parts))
pm->parts->pscheme->write_to_disk(pm->parts);
}
install_desc_from_parts(&install, pm->parts);
} else if (pm->cur_system) {
install.cur_system = true;
}
set_swap_if_low_ram(&install);
if (md_pre_update(&install) < 0)
goto free_install;
if (mount_disks(&install) != 0)
goto free_install;
if (save_X("/usr/X11R6"))
goto free_install;
if (save_X("/usr/X11R7"))
goto free_install;
#ifdef AOUT2ELF
move_aout_libs();
#endif
if (!md_update(&install))
goto free_install;
wrefresh(curscr);
wmove(stdscr, 0, 0);
wclear(stdscr);
wrefresh(stdscr);
process_menu(MENU_distset, &retcode);
if (retcode == 0)
goto free_install;
if (get_and_unpack_sets(1, MSG_disksetupdoneupdate,
MSG_upgrcomplete, MSG_abortupgr) != 0)
goto free_install;
if (md_post_extract(&install, true))
goto free_install;
unsetenv("FTPSSLNOVERIFY");
merge_X("/usr/X11R6");
merge_X("/usr/X11R7");
#if CHECK_ENTROPY
do_add_entropy();
#endif
sanity_check();
free_install:
free_install_desc(&install);
}
static int
save_X(const char *xroot)
{
char newx[MAXPATHLEN], oldx[MAXPATHLEN];
strlcpy(newx, xroot, sizeof(newx));
strlcat(newx, "/bin/X", sizeof(newx));
strlcpy(oldx, newx, sizeof(oldx));
strlcat(oldx, ".old", sizeof(oldx));
if (target_symlink_exists_p(newx)) {
if (target_symlink_exists_p(oldx)) {
msg_fmt_display(MSG_X_oldexists,
"%s%s%s%s%s%s%s%s%s%s%s",
xroot, xroot, xroot, xroot, xroot, xroot, xroot,
xroot, xroot, xroot, xroot);
hit_enter_to_continue(NULL, NULL);
return EEXIST;
}
#ifdef DEBUG
printf("saving %s as %s ...", newx, oldx);
#endif
mv_within_target_or_die(newx, oldx);
}
return 0;
}
static int
merge_X(const char *xroot)
{
char newx[MAXPATHLEN], oldx[MAXPATHLEN];
strlcpy(newx, xroot, sizeof(newx));
strlcat(newx, "/bin/X", sizeof(newx));
strlcpy(oldx, newx, sizeof(oldx));
strlcat(oldx, ".old", sizeof(oldx));
if (target_symlink_exists_p(oldx)) {
mv_within_target_or_die(oldx, newx);
}
return 0;
}
void
do_reinstall_sets(void)
{
struct install_partition_desc install = {};
int retcode = 0;
partman_go = 0;
unwind_mounts();
msg_display(MSG_reinstallusure);
if (!ask_noyes(NULL))
return;
if (find_disks(msg_string(MSG_reinstall), !root_is_read_only()) < 0)
return;
if (!pm->cur_system && pm->parts != NULL) {
install_desc_from_parts(&install, pm->parts);
} else if (pm->cur_system) {
install.cur_system = true;
}
if (mount_disks(&install) != 0)
goto free_install;
process_menu(MENU_distset, &retcode);
if (retcode == 0)
goto free_install;
if (get_and_unpack_sets(0, NULL, MSG_unpackcomplete, MSG_abortunpack) != 0)
goto free_install;
#if CHECK_ENTROPY
do_add_entropy();
#endif
sanity_check();
free_install:
free_install_desc(&install);
}