Home | History | Annotate | Line # | Download | only in sysinst
upgrade.c revision 1.12.2.1
      1  1.12.2.1   msaitoh /*	$NetBSD: upgrade.c,v 1.12.2.1 2019/08/28 10:00:53 msaitoh Exp $	*/
      2       1.1  dholland 
      3       1.1  dholland /*
      4       1.1  dholland  * Copyright 1997 Piermont Information Systems Inc.
      5       1.1  dholland  * All rights reserved.
      6       1.1  dholland  *
      7       1.1  dholland  * Written by Philip A. Nelson for Piermont Information Systems Inc.
      8       1.1  dholland  *
      9       1.1  dholland  * Redistribution and use in source and binary forms, with or without
     10       1.1  dholland  * modification, are permitted provided that the following conditions
     11       1.1  dholland  * are met:
     12       1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     13       1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     14       1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     16       1.1  dholland  *    documentation and/or other materials provided with the distribution.
     17       1.1  dholland  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
     18       1.1  dholland  *    or promote products derived from this software without specific prior
     19       1.1  dholland  *    written permission.
     20       1.1  dholland  *
     21       1.1  dholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
     22       1.1  dholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23       1.1  dholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24       1.1  dholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
     25       1.1  dholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26       1.1  dholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27       1.1  dholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28       1.1  dholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29       1.1  dholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30       1.1  dholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31       1.1  dholland  * THE POSSIBILITY OF SUCH DAMAGE.
     32       1.1  dholland  *
     33       1.1  dholland  */
     34       1.1  dholland 
     35       1.1  dholland /* upgrade.c -- upgrade an installation. */
     36       1.1  dholland 
     37       1.1  dholland #include <sys/param.h>
     38       1.1  dholland #include <stdio.h>
     39       1.1  dholland #include <curses.h>
     40       1.1  dholland #include <errno.h>
     41       1.1  dholland #include "defs.h"
     42       1.1  dholland #include "msg_defs.h"
     43       1.1  dholland #include "menu_defs.h"
     44       1.1  dholland 
     45       1.1  dholland /*
     46       1.1  dholland  * local prototypes
     47       1.1  dholland  */
     48       1.1  dholland static int save_X(const char *);
     49       1.1  dholland static int merge_X(const char *);
     50       1.1  dholland 
     51       1.1  dholland /*
     52       1.1  dholland  * Do the system upgrade.
     53       1.1  dholland  */
     54       1.1  dholland void
     55       1.1  dholland do_upgrade(void)
     56       1.1  dholland {
     57      1.12    martin 	struct install_partition_desc install = {};
     58       1.2    martin 	int retcode = 0;
     59       1.2    martin 	partman_go = 0;
     60       1.1  dholland 
     61       1.1  dholland 	msg_display(MSG_upgradeusure);
     62       1.4    martin 	if (!ask_noyes(NULL))
     63       1.1  dholland 		return;
     64       1.1  dholland 
     65       1.1  dholland 	get_ramsize();
     66       1.1  dholland 
     67  1.12.2.1   msaitoh 	if (find_disks(msg_string(MSG_upgrade), !root_is_read_only()) < 0)
     68       1.1  dholland 		return;
     69       1.1  dholland 
     70      1.12    martin 	if (pm->parts == NULL && !pm->cur_system) {
     71      1.10    martin 		hit_enter_to_continue(MSG_noroot, NULL);
     72      1.10    martin 		return;
     73      1.10    martin 	}
     74      1.10    martin 
     75      1.12    martin 	if (!pm->cur_system) {
     76      1.12    martin 		if (pm->parts->pscheme->pre_update_verify) {
     77      1.12    martin 			if (pm->parts->pscheme->pre_update_verify(pm->parts))
     78      1.12    martin 				pm->parts->pscheme->write_to_disk(pm->parts);
     79      1.12    martin 		}
     80      1.12    martin 
     81      1.12    martin 		install_desc_from_parts(&install, pm->parts);
     82      1.12    martin 	} else {
     83      1.12    martin 		install.cur_system = true;
     84       1.7    martin 	}
     85       1.7    martin 
     86       1.9    martin 	if (set_swap_if_low_ram(&install) < 0)
     87       1.9    martin 		return;
     88       1.9    martin 
     89       1.7    martin 	if (md_pre_update(&install) < 0)
     90       1.7    martin 		goto free_install;
     91       1.1  dholland 
     92       1.7    martin 	if (mount_disks(&install) != 0)
     93       1.7    martin 		goto free_install;
     94       1.1  dholland 
     95       1.1  dholland 
     96       1.1  dholland 	/*
     97       1.1  dholland 	 * Save X symlink, ...
     98       1.1  dholland 	 */
     99       1.1  dholland 	if (save_X("/usr/X11R6"))
    100       1.7    martin 		goto free_install;
    101       1.1  dholland 	if (save_X("/usr/X11R7"))
    102       1.7    martin 		goto free_install;
    103       1.1  dholland 
    104       1.1  dholland #ifdef AOUT2ELF
    105       1.1  dholland 	move_aout_libs();
    106       1.1  dholland #endif
    107       1.1  dholland 	/* Do any md updating of the file systems ... e.g. bootblocks,
    108       1.1  dholland 	   copy file systems ... */
    109       1.7    martin 	/* XXX pass install here too */
    110       1.7    martin 	if (!md_update(&install))
    111       1.7    martin 		goto free_install;
    112       1.1  dholland 
    113       1.1  dholland 	wrefresh(curscr);
    114       1.1  dholland 	wmove(stdscr, 0, 0);
    115       1.1  dholland 	wclear(stdscr);
    116       1.1  dholland 	wrefresh(stdscr);
    117       1.1  dholland 
    118       1.1  dholland 	/* Done with disks. Ready to get and unpack tarballs. */
    119       1.2    martin 	process_menu(MENU_distset, &retcode);
    120       1.2    martin 	if (retcode == 0)
    121       1.7    martin 		goto free_install;
    122       1.1  dholland 	if (get_and_unpack_sets(1, MSG_disksetupdoneupdate,
    123       1.1  dholland 	    MSG_upgrcomplete, MSG_abortupgr) != 0)
    124       1.7    martin 		goto free_install;
    125       1.1  dholland 
    126       1.7    martin 	if (md_post_extract(&install))
    127       1.7    martin 		goto free_install;
    128       1.1  dholland 
    129       1.1  dholland 	merge_X("/usr/X11R6");
    130       1.1  dholland 	merge_X("/usr/X11R7");
    131       1.1  dholland 
    132       1.1  dholland 	sanity_check();
    133       1.7    martin 
    134       1.7    martin free_install:
    135       1.7    martin 	free_install_desc(&install);
    136       1.1  dholland }
    137       1.1  dholland 
    138       1.1  dholland /*
    139       1.1  dholland  * Save X symlink to X.old so it can be recovered later
    140       1.1  dholland  */
    141       1.1  dholland static int
    142       1.1  dholland save_X(const char *xroot)
    143       1.1  dholland {
    144       1.1  dholland 	char newx[MAXPATHLEN], oldx[MAXPATHLEN];
    145       1.1  dholland 
    146       1.1  dholland 	strlcpy(newx, xroot, sizeof(newx));
    147       1.1  dholland 	strlcat(newx, "/bin/X", sizeof(newx));
    148       1.1  dholland 	strlcpy(oldx, newx, sizeof(oldx));
    149       1.1  dholland 	strlcat(oldx, ".old", sizeof(oldx));
    150       1.1  dholland 
    151       1.1  dholland 	/* Only care for X if it's a symlink */
    152       1.1  dholland 	if (target_symlink_exists_p(newx)) {
    153       1.1  dholland 		if (target_symlink_exists_p(oldx)) {
    154       1.8  christos 			msg_fmt_display(MSG_X_oldexists,
    155       1.8  christos 			    "%s%s%s%s%s%s%s%s%s%s%s",
    156       1.1  dholland 			    xroot, xroot, xroot, xroot, xroot, xroot, xroot,
    157       1.8  christos 			    xroot, xroot, xroot, xroot);
    158       1.7    martin 			hit_enter_to_continue(NULL, NULL);
    159       1.1  dholland 			return EEXIST;
    160       1.1  dholland 		}
    161       1.1  dholland 
    162       1.1  dholland #ifdef DEBUG
    163       1.1  dholland 		printf("saving %s as %s ...", newx, oldx);
    164       1.1  dholland #endif
    165       1.1  dholland 
    166       1.1  dholland 		/* Move target .../X to .../X.old.  Abort on error. */
    167       1.1  dholland 		mv_within_target_or_die(newx, oldx);
    168       1.1  dholland 	}
    169       1.1  dholland 
    170       1.1  dholland 	return 0;
    171       1.1  dholland }
    172       1.1  dholland 
    173       1.1  dholland /*
    174       1.1  dholland  * Merge back saved target X files after unpacking the new
    175       1.1  dholland  * sets has completed.
    176       1.1  dholland  */
    177       1.1  dholland static int
    178       1.1  dholland merge_X(const char *xroot)
    179       1.1  dholland {
    180       1.1  dholland 	char newx[MAXPATHLEN], oldx[MAXPATHLEN];
    181       1.1  dholland 
    182       1.1  dholland 	strlcpy(newx, xroot, sizeof(newx));
    183       1.1  dholland 	strlcat(newx, "/bin/X", sizeof(newx));
    184       1.1  dholland 	strlcpy(oldx, newx, sizeof(oldx));
    185       1.1  dholland 	strlcat(oldx, ".old", sizeof(oldx));
    186       1.1  dholland 
    187       1.1  dholland 	if (target_symlink_exists_p(oldx)) {
    188       1.1  dholland 		/* Only move back X if it's a symlink - we don't want
    189       1.1  dholland 		 * to restore old binaries */
    190       1.1  dholland 		mv_within_target_or_die(oldx, newx);
    191       1.1  dholland 	}
    192       1.1  dholland 
    193       1.1  dholland 	return 0;
    194       1.1  dholland }
    195       1.1  dholland 
    196       1.1  dholland /*
    197       1.1  dholland  * Unpacks sets,  clobbering existing contents.
    198       1.1  dholland  */
    199       1.1  dholland void
    200      1.11    martin do_reinstall_sets()
    201       1.1  dholland {
    202      1.12    martin 	struct install_partition_desc install = {};
    203       1.2    martin 	int retcode = 0;
    204      1.11    martin 	partman_go = 0;
    205       1.1  dholland 
    206       1.1  dholland 	unwind_mounts();
    207       1.1  dholland 	msg_display(MSG_reinstallusure);
    208       1.4    martin 	if (!ask_noyes(NULL))
    209       1.1  dholland 		return;
    210       1.1  dholland 
    211  1.12.2.1   msaitoh 	if (find_disks(msg_string(MSG_reinstall), !root_is_read_only()) < 0)
    212       1.1  dholland 		return;
    213       1.1  dholland 
    214      1.12    martin 	if (!pm->cur_system) {
    215      1.12    martin 		if (pm->parts == NULL) {
    216      1.12    martin 			hit_enter_to_continue(MSG_noroot, NULL);
    217      1.12    martin 			return;
    218      1.12    martin 		}
    219      1.12    martin 
    220      1.12    martin 		install_desc_from_parts(&install, pm->parts);
    221      1.12    martin 	} else {
    222      1.12    martin 		install.cur_system = true;
    223      1.11    martin 	}
    224      1.11    martin 
    225      1.11    martin 	if (mount_disks(&install) != 0)
    226      1.11    martin 		goto free_install;
    227       1.1  dholland 
    228       1.1  dholland 	/* Unpack the distribution. */
    229       1.2    martin 	process_menu(MENU_distset, &retcode);
    230       1.2    martin 	if (retcode == 0)
    231      1.11    martin 		goto free_install;
    232       1.1  dholland 	if (get_and_unpack_sets(0, NULL, MSG_unpackcomplete, MSG_abortunpack) != 0)
    233      1.11    martin 		goto free_install;
    234       1.1  dholland 
    235       1.1  dholland 	sanity_check();
    236      1.11    martin 
    237      1.11    martin free_install:
    238      1.11    martin 	free_install_desc(&install);
    239       1.1  dholland }
    240