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