Annotation of src/distrib/utils/sysinst/upgrade.c, Revision 1.36
1.36 ! dsl 1: /* $NetBSD: upgrade.c,v 1.35 2003/06/27 22:20:16 dsl Exp $ */
1.1 phil 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. All advertising materials mentioning features or use of this software
18: * must display the following acknowledgement:
1.18 cgd 19: * This product includes software developed for the NetBSD Project by
1.1 phil 20: * Piermont Information Systems Inc.
21: * 4. The name of Piermont Information Systems Inc. may not be used to endorse
22: * or promote products derived from this software without specific prior
23: * written permission.
24: *
25: * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28: * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35: * THE POSSIBILITY OF SUCH DAMAGE.
36: *
37: */
38:
39: /* upgrade.c -- upgrade an installation. */
40:
41: #include <stdio.h>
42: #include <curses.h>
1.9 jonathan 43: #include <errno.h>
1.1 phil 44: #include "defs.h"
45: #include "msg_defs.h"
46: #include "menu_defs.h"
47:
1.9 jonathan 48: /*
49: * local prototypes
50: */
1.28 mrg 51: void check_prereqs (void);
52: int save_etc (void);
53: int merge_etc (void);
54: int save_X (void);
55: int merge_X (void);
1.9 jonathan 56:
1.15 mrg 57: /*
58: * Do the system upgrade.
59: */
60: void
1.34 dsl 61: do_upgrade(void)
1.1 phil 62: {
1.15 mrg 63:
64: msg_display(MSG_upgradeusure);
1.33 dsl 65: process_menu(MENU_noyes, NULL);
1.1 phil 66: if (!yesno)
67: return;
68:
1.15 mrg 69: get_ramsize();
1.2 phil 70:
1.35 dsl 71: if (find_disks(msg_string(MSG_upgrade)) < 0)
1.23 fvdl 72: return;
73:
74: if (md_pre_update() < 0)
1.2 phil 75: return;
1.36 ! dsl 76:
! 77: process_menu(MENU_distset, NULL);
1.11 jonathan 78:
79: /* if we need the user to mount root, ask them to. */
80: if (must_mount_root()) {
1.32 chris 81: msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev, diskdev);
1.33 dsl 82: process_menu(MENU_ok, NULL);
1.11 jonathan 83: return;
84: }
1.2 phil 85:
86: if (!fsck_disks())
1.1 phil 87: return;
1.5 phil 88:
1.24 fvdl 89:
1.14 jonathan 90: /*
1.22 hubertf 91: * Save X symlink, ...
1.14 jonathan 92: */
1.22 hubertf 93: if (save_X())
1.9 jonathan 94: return;
95:
1.21 hubertf 96: /*
1.22 hubertf 97: * Move target /etc -> target /etc.old so existing configuration
98: * isn't overwritten by upgrade.
1.21 hubertf 99: */
1.22 hubertf 100: if (save_etc()) {
101: merge_X();
1.21 hubertf 102: return;
1.22 hubertf 103: }
1.1 phil 104:
1.3 phil 105: /* Do any md updating of the file systems ... e.g. bootblocks,
106: copy file systems ... */
1.15 mrg 107: if (!md_update())
1.2 phil 108: return;
1.8 jonathan 109:
110: /* Done with disks. Ready to get and unpack tarballs. */
1.29 jdc 111: msg_display(MSG_disksetupdoneupdate);
1.17 bouyer 112: getchar();
1.30 jdc 113: wrefresh(curscr);
1.27 jdc 114: wmove(stdscr, 0, 0);
1.17 bouyer 115: wclear(stdscr);
116: wrefresh(stdscr);
1.1 phil 117:
1.20 cgd 118: if (get_and_unpack_sets(MSG_upgrcomplete, MSG_abortupgr) != 0)
119: return;
1.9 jonathan 120:
1.14 jonathan 121: /* Copy back any files we should restore after the upgrade.*/
1.10 jonathan 122: merge_etc();
1.21 hubertf 123: merge_X();
1.10 jonathan 124:
1.9 jonathan 125: sanity_check();
126: }
127:
128: /*
129: * save target /etc files.
130: * if target /etc.old exists, print a warning message and give up.
131: * otherwise move /etc into target /etc.old, and then copy
132: * back files we might want during the installation -- in case
133: * we are upgrading the target root.
134: */
1.15 mrg 135: int
1.34 dsl 136: save_etc(void)
1.9 jonathan 137: {
138:
1.12 jonathan 139: if (target_dir_exists_p("/etc.old")) {
1.9 jonathan 140: msg_display(MSG_etc_oldexists);
1.33 dsl 141: process_menu(MENU_ok, NULL);
1.9 jonathan 142: return EEXIST;
143: }
144:
145: #ifdef DEBUG
146: printf("saving /etc as /etc.old...");
147: #endif
148:
1.14 jonathan 149: /* Move target /etc to /etc.old. Abort on error. */
1.15 mrg 150: mv_within_target_or_die("/etc", "/etc.old");
1.9 jonathan 151:
1.14 jonathan 152: /* now make an /etc that should let the user reboot. */
1.9 jonathan 153: make_target_dir("/etc");
154:
155: #ifdef DEBUG
156: printf("Copying essential files back into new /etc...");
157: #endif
158: /* essential stuff */
159: cp_within_target("/etc.old/ld.so.cache", "/etc/");
160: cp_within_target("/etc.old/ld.so.conf", "/etc/");
161: cp_within_target("/etc.old/resolv.conf", "/etc/");
162:
163: /*
164: * do NOT create fstab so that restarting an incomplete
165: * upgrade (eg., after power failure) will fail, and
166: * force the user to check and restore their old /etc.
167: */
168:
169: /* general config */
170: cp_within_target("/etc.old/rc", "/etc/");
171: cp_within_target("/etc.old/rc.conf", "/etc/");
172: cp_within_target("/etc.old/rc.local", "/etc/");
173:
174: /* network config */
175: cp_within_target("/etc.old/ifconfig.*", "/etc/");
1.31 mrg 176: /* these should become parts of rc.conf */
1.9 jonathan 177: cp_within_target("/etc.old/myname", "/etc/");
178: cp_within_target("/etc.old/mygate", "/etc/");
179: cp_within_target("/etc.old/defaultdomain", "/etc/");
180:
181: /* old-style network config */
182: cp_within_target("/etc.old/hostname.*", "/etc/");
183:
184: return 0;
1.10 jonathan 185: }
186:
187: /*
1.21 hubertf 188: * Save X symlink to X.old so it can be recovered later
189: */
190: int
1.34 dsl 191: save_X(void)
1.21 hubertf 192: {
193: /* Only care for X if it's a symlink */
194: if (target_symlink_exists_p("/usr/X11R6/bin/X")) {
195: if (target_symlink_exists_p("/usr/X11R6/bin/X.old")) {
196: msg_display(MSG_X_oldexists);
1.33 dsl 197: process_menu(MENU_ok, NULL);
1.21 hubertf 198: return EEXIST;
199: }
200:
201: #ifdef DEBUG
202: printf("saving /usr/X11R6/bin/X as .../X.old ...");
203: #endif
204:
205: /* Move target .../X to .../X.old. Abort on error. */
206: mv_within_target_or_die("/usr/X11R6/bin/X",
207: "/usr/X11R6/bin/X.old");
208: }
209:
210: return 0;
211: }
212:
213: /*
1.10 jonathan 214: * Merge back saved target /etc files after unpacking the new
215: * sets has completed.
216: */
1.15 mrg 217: int
1.34 dsl 218: merge_etc(void)
1.10 jonathan 219: {
1.15 mrg 220:
1.10 jonathan 221: /* just move back fstab, so we can boot cleanly. */
222: cp_within_target("/etc.old/fstab", "/etc/");
1.21 hubertf 223:
224: return 0;
225: }
226:
227: /*
228: * Merge back saved target X files after unpacking the new
229: * sets has completed.
230: */
231: int
1.34 dsl 232: merge_X(void)
1.21 hubertf 233: {
234: if (target_symlink_exists_p("/usr/X11R6/bin/X.old")) {
235: /* Only move back X if it's a symlink - we don't want
236: * to restore old binaries */
237: mv_within_target_or_die("/usr/X11R6/bin/X.old",
238: "/usr/X11R6/bin/X");
239: }
1.10 jonathan 240:
241: return 0;
1.12 jonathan 242: }
243:
244: /*
1.29 jdc 245: * Unpacks sets, clobbering existing contents.
1.12 jonathan 246: */
247: void
1.34 dsl 248: do_reinstall_sets(void)
1.12 jonathan 249: {
250:
251: unwind_mounts();
1.15 mrg 252: msg_display(MSG_reinstallusure);
1.33 dsl 253: process_menu(MENU_noyes, NULL);
1.12 jonathan 254: if (!yesno)
255: return;
256:
1.35 dsl 257: if (find_disks(msg_string(MSG_reinstall)) < 0)
1.12 jonathan 258: return;
259:
260: /* if we need the user to mount root, ask them to. */
261: if (must_mount_root()) {
1.32 chris 262: msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev, diskdev);
1.33 dsl 263: process_menu(MENU_ok, NULL);
1.12 jonathan 264: return;
265: }
266:
267: if (!fsck_disks())
268: return;
1.13 fvdl 269:
1.15 mrg 270: fflush(stdout);
1.30 jdc 271: wrefresh(curscr);
1.27 jdc 272: wmove(stdscr, 0, 0);
1.24 fvdl 273: touchwin(stdscr);
1.19 cgd 274: wclear(stdscr);
1.15 mrg 275: wrefresh(stdscr);
1.12 jonathan 276:
277: /* Unpack the distribution. */
1.20 cgd 278: if (get_and_unpack_sets(MSG_unpackcomplete, MSG_abortunpack) != 0)
279: return;
1.12 jonathan 280:
281: sanity_check();
1.1 phil 282: }
CVSweb <webmaster@jp.NetBSD.org>