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