Annotation of src/distrib/utils/sysinst/upgrade.c, Revision 1.4.2.8
1.4.2.8 ! cgd 1: /* $NetBSD: upgrade.c,v 1.4.2.7 1998/05/29 20:48:52 mycroft 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:
19: * This product includes software develooped for the NetBSD Project by
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.4.2.3 mellon 43: #include <errno.h>
1.1 phil 44: #include "defs.h"
45: #include "msg_defs.h"
46: #include "menu_defs.h"
47:
1.4.2.3 mellon 48: /*
49: * local prototypes
50: */
1.4.2.4 thorpej 51: void check_prereqs __P((void));
52: int save_etc __P((void));
53: int merge_etc __P((void));
1.1 phil 54:
1.4.2.3 mellon 55: /* Do the system upgrade. */
1.1 phil 56: void do_upgrade(void)
57: {
58: doingwhat = msg_string (MSG_upgrade);
59:
60: msg_display (MSG_upgradeusure);
61: process_menu (MENU_noyes);
62: if (!yesno)
63: return;
64:
1.2 phil 65: get_ramsize ();
66:
67: if (find_disks () < 0)
68: return;
69:
1.4.2.4 thorpej 70: /* if we need the user to mount root, ask them to. */
71: if (must_mount_root()) {
72: msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev);
73: process_menu (MENU_ok);
74: return;
75: }
76:
1.2 phil 77: if (!fsck_disks())
1.1 phil 78: return;
1.4.2.1 thorpej 79:
1.4.2.7 mycroft 80: /*
81: * Move target /etc -> target /etc.old so existing configuration
82: * isn't overwritten by upgrade.
83: */
1.4.2.3 mellon 84: if (save_etc())
85: return;
86:
1.1 phil 87:
1.3 phil 88: /* Do any md updating of the file systems ... e.g. bootblocks,
89: copy file systems ... */
1.2 phil 90: if (!md_update ())
91: return;
1.1 phil 92:
1.4.2.3 mellon 93: /* Done with disks. Ready to get and unpack tarballs. */
94: msg_display(MSG_disksetupdone);
95: process_menu (MENU_ok);
96:
1.4.2.2 mellon 97: get_and_unpack_sets(MSG_upgrcomplete, MSG_abortupgr);
1.4.2.3 mellon 98:
1.4.2.7 mycroft 99: /* Copy back any files we should restore after the upgrade.*/
1.4.2.4 thorpej 100: merge_etc();
101:
1.4.2.3 mellon 102: sanity_check();
103: }
104:
105: /*
106: * save target /etc files.
107: * if target /etc.old exists, print a warning message and give up.
108: * otherwise move /etc into target /etc.old, and then copy
109: * back files we might want during the installation -- in case
110: * we are upgrading the target root.
111: */
112: int save_etc(void)
113: {
114:
1.4.2.5 jonathan 115: if (target_dir_exists_p("/etc.old")) {
1.4.2.3 mellon 116: msg_display(MSG_etc_oldexists);
117: process_menu (MENU_ok);
118: return EEXIST;
119: }
120:
121: #ifdef DEBUG
122: printf("saving /etc as /etc.old...");
123: #endif
124:
1.4.2.7 mycroft 125: /* Move target /etc to /etc.old. Abort on error. */
1.4.2.3 mellon 126: mv_within_target_or_die ("/etc", "/etc.old");
127:
1.4.2.7 mycroft 128: /* now make an /etc that should let the user reboot. */
1.4.2.3 mellon 129: make_target_dir("/etc");
130:
131: #ifdef DEBUG
132: printf("Copying essential files back into new /etc...");
133: #endif
134: /* essential stuff */
135: cp_within_target("/etc.old/ld.so.cache", "/etc/");
136: cp_within_target("/etc.old/ld.so.conf", "/etc/");
137: cp_within_target("/etc.old/resolv.conf", "/etc/");
138:
139: /*
140: * do NOT create fstab so that restarting an incomplete
141: * upgrade (eg., after power failure) will fail, and
142: * force the user to check and restore their old /etc.
143: */
144:
145: /* general config */
146: cp_within_target("/etc.old/rc", "/etc/");
147: cp_within_target("/etc.old/rc.conf", "/etc/");
148: cp_within_target("/etc.old/rc.local", "/etc/");
149:
150: /* network config */
151: cp_within_target("/etc.old/ifconfig.*", "/etc/");
152: cp_within_target("/etc.old/myname", "/etc/");
153: cp_within_target("/etc.old/mygate", "/etc/");
154: cp_within_target("/etc.old/defaultdomain", "/etc/");
155:
156: /* old-style network config */
157: cp_within_target("/etc.old/hostname.*", "/etc/");
158:
159: return 0;
1.4.2.4 thorpej 160: }
161:
162:
163: /*
164: * Merge back saved target /etc files after unpacking the new
165: * sets has completed.
166: */
167: int merge_etc(void)
168: {
169: /* just move back fstab, so we can boot cleanly. */
170: cp_within_target("/etc.old/fstab", "/etc/");
171:
172: return 0;
1.4.2.5 jonathan 173: }
174:
175:
176:
177: /*
178: * Unpacks sets, clobbering existintg contents.
179: */
180: void
181: do_reinstall_sets(void)
182: {
1.4.2.8 ! cgd 183: doingwhat = msg_string(MSG_reinstall);
1.4.2.5 jonathan 184:
185: unwind_mounts();
186: msg_display (MSG_reinstallusure);
187: process_menu (MENU_noyes);
188: if (!yesno)
189: return;
190:
191:
192: if (find_disks () < 0)
193: return;
194:
195: /* if we need the user to mount root, ask them to. */
196: if (must_mount_root()) {
197: msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev);
198: process_menu (MENU_ok);
199: return;
200: }
201:
202: if (!fsck_disks())
203: return;
1.4.2.6 perry 204:
205: fflush(stdout); puts(CL); wrefresh(stdscr);
1.4.2.5 jonathan 206:
207: /* Unpack the distribution. */
208: get_and_unpack_sets(MSG_unpackcomplete, MSG_abortunpack);
209:
210: sanity_check();
211:
1.1 phil 212: }
CVSweb <webmaster@jp.NetBSD.org>