2 * The new sysinstall program.
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
7 * $FreeBSD: src/release/sysinstall/installUpgrade.c,v 1.71.2.12 2002/06/10 04:28:53 obrien Exp $
8 * $DragonFly: src/release/sysinstall/Attic/installUpgrade.c,v 1.3 2003/08/05 07:45:42 asmodai Exp $
11 * Jordan Hubbard. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer,
18 * verbatim and that no modifications are made prior to this
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "sysinstall.h"
39 #include <sys/disklabel.h>
40 #include <sys/errno.h>
41 #include <sys/ioctl.h>
42 #include <sys/fcntl.h>
44 #include <sys/param.h>
47 #include <sys/mount.h>
49 static int installUpgradeNonInteractive(dialogMenuItem *self);
51 typedef struct _hitList {
52 enum { JUST_COPY, CALL_HANDLER } action ;
55 void (*handler)(struct _hitList *self);
58 /* These are the only meaningful files I know about */
59 static HitList etc_files [] = {
60 { JUST_COPY, "Xaccel.ini", TRUE, NULL },
61 { JUST_COPY, "X11", TRUE, NULL },
62 { JUST_COPY, "adduser.conf", TRUE, NULL },
63 { JUST_COPY, "aliases", TRUE, NULL },
64 { JUST_COPY, "aliases.db", TRUE, NULL },
65 { JUST_COPY, "amd.map", TRUE, NULL },
66 { JUST_COPY, "auth.conf", TRUE, NULL },
67 { JUST_COPY, "crontab", TRUE, NULL },
68 { JUST_COPY, "csh.cshrc", TRUE, NULL },
69 { JUST_COPY, "csh.login", TRUE, NULL },
70 { JUST_COPY, "csh.logout", TRUE, NULL },
71 { JUST_COPY, "cvsupfile", TRUE, NULL },
72 { JUST_COPY, "dhclient.conf", TRUE, NULL },
73 { JUST_COPY, "disktab", TRUE, NULL },
74 { JUST_COPY, "dm.conf", TRUE, NULL },
75 { JUST_COPY, "dumpdates", TRUE, NULL },
76 { JUST_COPY, "exports", TRUE, NULL },
77 { JUST_COPY, "fbtab", TRUE, NULL },
78 { JUST_COPY, "fstab", FALSE, NULL },
79 { JUST_COPY, "ftpusers", TRUE, NULL },
80 { JUST_COPY, "gettytab", TRUE, NULL },
81 { JUST_COPY, "gnats", TRUE, NULL },
82 { JUST_COPY, "group", FALSE, NULL },
83 { JUST_COPY, "hosts", TRUE, NULL },
84 { JUST_COPY, "host.conf", TRUE, NULL },
85 { JUST_COPY, "hosts.allow", TRUE, NULL },
86 { JUST_COPY, "hosts.equiv", TRUE, NULL },
87 { JUST_COPY, "hosts.lpd", TRUE, NULL },
88 { JUST_COPY, "inetd.conf", TRUE, NULL },
89 { JUST_COPY, "localtime", TRUE, NULL },
90 { JUST_COPY, "login.access", TRUE, NULL },
91 { JUST_COPY, "login.conf", TRUE, NULL },
92 { JUST_COPY, "mail", TRUE, NULL },
93 { JUST_COPY, "mail.rc", TRUE, NULL },
94 { JUST_COPY, "make.conf", TRUE, NULL },
95 { JUST_COPY, "manpath.config", TRUE, NULL },
96 { JUST_COPY, "master.passwd", FALSE, NULL },
97 { JUST_COPY, "modems", TRUE, NULL },
98 { JUST_COPY, "motd", TRUE, NULL },
99 { JUST_COPY, "namedb", TRUE, NULL },
100 { JUST_COPY, "networks", TRUE, NULL },
101 { JUST_COPY, "newsyslog.conf", TRUE, NULL },
102 { JUST_COPY, "nsmb.conf", TRUE, NULL },
103 { JUST_COPY, "pam.conf", TRUE, NULL },
104 { JUST_COPY, "passwd", TRUE, NULL },
105 { JUST_COPY, "periodic", TRUE, NULL },
106 { JUST_COPY, "ppp", TRUE, NULL },
107 { JUST_COPY, "printcap", TRUE, NULL },
108 { JUST_COPY, "profile", TRUE, NULL },
109 { JUST_COPY, "pwd.db", TRUE, NULL },
110 { JUST_COPY, "rc.local", TRUE, NULL },
111 { JUST_COPY, "rc.firewall", TRUE, NULL },
112 { JUST_COPY, "rc.conf.local", TRUE, NULL },
113 { JUST_COPY, "remote", TRUE, NULL },
114 { JUST_COPY, "resolv.conf", TRUE, NULL },
115 { JUST_COPY, "rmt", TRUE, NULL },
116 { JUST_COPY, "sendmail.cf", TRUE, NULL },
117 { JUST_COPY, "sendmail.cw", TRUE, NULL },
118 { JUST_COPY, "services", TRUE, NULL },
119 { JUST_COPY, "shells", TRUE, NULL },
120 { JUST_COPY, "skeykeys", TRUE, NULL },
121 { JUST_COPY, "spwd.db", TRUE, NULL },
122 { JUST_COPY, "ssh", TRUE, NULL },
123 { JUST_COPY, "syslog.conf", TRUE, NULL },
124 { JUST_COPY, "ttys", TRUE, NULL },
125 { JUST_COPY, "uucp", TRUE, NULL },
130 traverseHitlist(HitList *h)
132 system("rm -rf /etc/upgrade");
133 Mkdir("/etc/upgrade");
135 if (!file_readable(h->name)) {
137 msgConfirm("Unable to find an old /etc/%s file! That is decidedly non-standard and\n"
138 "your upgraded system may function a little strangely as a result.", h->name);
141 if (h->action == JUST_COPY) {
142 /* Move the just-loaded copy aside */
143 vsystem("mv /etc/%s /etc/upgrade/%s", h->name, h->name);
145 /* Copy the old one into its place */
146 msgNotify("Resurrecting %s..", h->name);
147 /* Do this with tar so that symlinks and such are preserved */
148 if (vsystem("tar cf - %s | tar xpf - -C /etc", h->name))
149 msgConfirm("Unable to resurrect your old /etc/%s! Hmmmm.", h->name);
151 else /* call handler */
159 installUpgrade(dialogMenuItem *self)
161 char saved_etc[FILENAME_MAX];
162 Boolean extractingBin = TRUE;
164 if (variable_get(VAR_NONINTERACTIVE))
165 return installUpgradeNonInteractive(self);
167 variable_set2(SYSTEM_STATE, "upgrade", 0);
170 if (msgYesNo("Before beginning a binary upgrade, please review the upgrade instructions,\n"
171 "which are located in the \"Install\" document under the main documentation\n"
172 "menu. Given that you have read these instructions and understand the risks\n"
173 "and precautions involved, are you sure that you want to proceed with\n"
174 "this upgrade?") != 0)
175 return DITEM_FAILURE;
178 msgConfirm("First, you must select some distribution components. The upgrade procedure\n"
179 "will only upgrade the distributions you select in the next set of menus.");
180 if (!dmenuOpenSimple(&MenuDistributions, FALSE) || !Dists)
181 return DITEM_FAILURE;
183 else if (!(Dists & DIST_BIN)) { /* No bin selected? Not much of an upgrade.. */
184 if (msgYesNo("You didn't select the bin distribution as one of the distributons to load.\n"
185 "This one is pretty vital to a successful upgrade. Are you SURE you don't\n"
186 "want to select the bin distribution? Chose No to bring up the Distributions\n"
187 "menu again.") != 0) {
188 if (!dmenuOpenSimple(&MenuDistributions, FALSE))
189 return DITEM_FAILURE;
193 /* Still?! OK! They must know what they're doing.. */
194 if (!(Dists & DIST_BIN))
195 extractingBin = FALSE;
202 cp = variable_get(VAR_DISK);
203 devs = deviceFind(cp, DEVICE_TYPE_DISK);
204 cnt = deviceCount(devs);
206 msgConfirm("No disks found! Please verify that your disk controller is being\n"
207 "properly probed at boot time. See the Hardware Guide on the\n"
208 "Documentation menu for clues on diagnosing this type of problem.");
209 return DITEM_FAILURE | DITEM_RESTORE;
212 /* Enable all the drives before we start */
213 for (i = 0; i < cnt; i++)
214 devs[i]->enabled = TRUE;
217 msgConfirm("OK. First, we're going to go to the disk label editor. In this editor\n"
218 "you will be expected to Mount any partitions you're interested in\n"
219 "upgrading. DO NOT set the Newfs flag to Y on anything in the label editor\n"
220 "unless you're absolutely sure you know what you're doing! In this\n"
221 "instance, you'll be using the label editor as little more than a fancy\n"
222 "screen-oriented partition mounting tool.\n\n"
223 "Once you're done in the label editor, press Q to return here for the next\n"
226 if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE) {
227 msgConfirm("The disk label editor returned an error status. Upgrade operation\n"
229 return DITEM_FAILURE | DITEM_RESTORE;
232 /* Don't write out MBR info */
233 variable_set2(DISK_PARTITIONED, "written", 0);
234 if (DITEM_STATUS(diskLabelCommit(self)) == DITEM_FAILURE) {
235 msgConfirm("Not all file systems were properly mounted. Upgrade operation\n"
237 variable_unset(DISK_PARTITIONED);
238 return DITEM_FAILURE | DITEM_RESTORE;
241 msgNotify("Updating /stand on root filesystem");
242 (void)vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity());
244 if (DITEM_STATUS(chroot("/mnt")) == DITEM_FAILURE) {
245 msgConfirm("Unable to chroot to /mnt - something is wrong with the\n"
246 "root partition or the way it's mounted if this doesn't work.");
247 variable_unset(DISK_PARTITIONED);
248 return DITEM_FAILURE | DITEM_RESTORE;
251 installEnvironment();
252 systemCreateHoloshell();
257 /* Don't allow sources to be upgraded unless if we have src already */
258 if (directory_exists("/usr/src/") && (Dists & DIST_SRC)) {
261 msgConfirm("Warning: /usr/src exists and sources were selected as upgrade\n"
262 "targets. Unfortunately, this is not the way to upgrade your\n"
263 "sources - please use CTM or CVSup or some other method which\n"
264 "handles ``deletion events'', unlike this particular feature.\n\n"
265 "Your existing /usr/src will not be affected by this upgrade.\n");
269 while (!*saved_etc) {
270 char *cp = msgGetInput("/var/tmp/etc", "Under which directory do you wish to save your current /etc?");
272 if (!cp || !*cp || Mkdir(cp)) {
273 if (msgYesNo("Directory was not specified, was invalid or user selected Cancel.\n\n"
274 "Doing an upgrade without first backing up your /etc directory is a very\n"
275 "bad idea! Do you want to go back and specify the save directory again?") != 0)
279 SAFE_STRCPY(saved_etc, cp);
284 msgNotify("Preserving /etc directory..");
285 if (vsystem("tar -cBpf - -C /etc . | tar --unlink -xBpf - -C %s", saved_etc))
286 if (msgYesNo("Unable to backup your /etc into %s.\n"
287 "Do you want to continue anyway?", saved_etc) != 0)
288 return DITEM_FAILURE;
289 msgNotify("Preserving /root directory..");
290 vsystem("tar -cBpf - -C / root | tar --unlink -xBpf - -C %s", saved_etc);
293 msgNotify("chflags'ing old binaries - please wait.");
294 (void)vsystem("chflags -R noschg /bin /sbin /usr/sbin /usr/bin /usr/lib /usr/libexec /kernel*");
296 if (file_readable("/kernel")) {
297 msgNotify("Moving old kernel to /kernel.prev");
298 if (system("mv /kernel /kernel.prev")) {
299 if (!msgYesNo("Hmmm! I couldn't move the old kernel over! Do you want to\n"
300 "treat this as a big problem and abort the upgrade? Due to the\n"
301 "way that this upgrade process works, you will have to reboot\n"
302 "and start over from the beginning. Select Yes to reboot now"))
306 msgConfirm("NOTICE: Your old kernel is in /kernel.prev should this upgrade\n"
307 "fail for any reason and you need to boot your old kernel");
312 /* We do this very late, but we unfortunately need to back up /etc first */
314 return DITEM_FAILURE;
316 if (!DEVICE_INIT(mediaDevice)) {
317 if (!msgYesNo("Couldn't initialize the media. Would you like\n"
318 "to adjust your media selection and try again?")) {
323 return DITEM_FAILURE | DITEM_REDRAW | DITEM_RESTORE;
326 msgNotify("Beginning extraction of distributions..");
327 if (DITEM_STATUS(distExtractAll(self)) == DITEM_FAILURE) {
328 msgConfirm("Hmmmm. We couldn't even extract the bin distribution. This upgrade\n"
329 "should be considered a failure and started from the beginning, sorry!\n"
330 "The system will reboot now.");
335 if (!extractingBin || !(Dists & DIST_BIN)) {
336 msgNotify("The extraction process seems to have had some problems, but we got most\n"
337 "of the essentials. We'll treat this as a warning since it may have been\n"
338 "only non-essential distributions which failed to load.");
341 msgConfirm("Hmmmm. We couldn't even extract the bin distribution. This upgrade\n"
342 "should be considered a failure and started from the beginning, sorry!\n"
343 "The system will reboot now.");
350 vsystem("disklabel -B `awk '$2~/\\/$/ {print substr($1, 6, 3)}' /etc/fstab`");
351 msgNotify("First stage of upgrade completed successfully!\n\n"
352 "Next comes stage 2, where we attempt to resurrect your /etc\n"
355 if (saved_etc && chdir(saved_etc)) {
356 msgConfirm("Unable to go to your saved /etc directory in %s?! Argh!\n"
357 "Something went seriously wrong! It's quite possible that\n"
358 "your former /etc is toast. I hope you didn't have any\n"
359 "important customizations you wanted to keep in there.. :(", saved_etc);
362 /* Now try to resurrect the /etc files */
363 traverseHitlist(etc_files);
364 /* Resurrect the root dotfiles */
365 vsystem("tar -cBpf - root | tar -xBpf - -C / && rm -rf root");
368 msgConfirm("Upgrade completed! All of your old /etc files have been restored.\n"
369 "For your reference, the new /etc files are in /etc/upgrade/ in case\n"
370 "you wish to upgrade these files by hand (though that should not be\n"
371 "strictly necessary). If your root partition is specified in /etc/fstab\n"
372 "using the old \"compatibility\" slice, you may also wish to update it to\n"
373 "use a fully qualified slice name in order to avoid warnings on startup.\n\n"
374 "When you're ready to reboot into the new system, simply exit the installation.");
375 return DITEM_SUCCESS | DITEM_REDRAW | DITEM_RESTORE;
379 installUpgradeNonInteractive(dialogMenuItem *self)
382 Boolean extractingBin = TRUE;
384 variable_set2(SYSTEM_STATE, "upgrade", 0);
386 /* Make sure at least BIN is selected */
394 cp = variable_get(VAR_DISK);
395 devs = deviceFind(cp, DEVICE_TYPE_DISK);
396 cnt = deviceCount(devs);
398 msgConfirm("No disks found! Please verify that your disk controller is being\n"
399 "properly probed at boot time. See the Hardware Guide on the\n"
400 "Documentation menu for clues on diagnosing this type of problem.");
401 return DITEM_FAILURE;
404 /* Enable all the drives befor we start */
405 for (i = 0; i < cnt; i++)
406 devs[i]->enabled = TRUE;
409 msgConfirm("OK. First, we're going to go to the disk label editor. In this editor\n"
410 "you will be expected to Mount any partitions you're interested in\n"
411 "upgrading. DO NOT set the Newfs flag to Y on anything in the label editor\n"
412 "unless you're absolutely sure you know what you're doing! In this\n"
413 "instance, you'll be using the label editor as little more than a fancy\n"
414 "screen-oriented partition mounting tool.\n\n"
415 "Once you're done in the label editor, press Q to return here for the next\n"
418 if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE) {
419 msgConfirm("The disk label editor returned an error status. Upgrade operation\n"
421 return DITEM_FAILURE;
424 /* Don't write out MBR info */
425 variable_set2(DISK_PARTITIONED, "written", 0);
426 if (DITEM_STATUS(diskLabelCommit(self)) == DITEM_FAILURE) {
427 msgConfirm("Not all file systems were properly mounted. Upgrade operation\n"
429 variable_unset(DISK_PARTITIONED);
430 return DITEM_FAILURE;
434 msgNotify("chflags'ing old binaries - please wait.");
435 (void)vsystem("chflags -R noschg /mnt/");
437 msgNotify("Updating /stand on root filesystem");
438 (void)vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity());
440 if (DITEM_STATUS(chroot("/mnt")) == DITEM_FAILURE) {
441 msgConfirm("Unable to chroot to /mnt - something is wrong with the\n"
442 "root partition or the way it's mounted if this doesn't work.");
443 variable_unset(DISK_PARTITIONED);
444 return DITEM_FAILURE;
447 systemCreateHoloshell();
450 if (!mediaVerify() || !DEVICE_INIT(mediaDevice)) {
451 msgNotify("Upgrade: Couldn't initialize media.");
452 return DITEM_FAILURE;
455 saved_etc = "/var/tmp/etc";
457 msgNotify("Preserving /etc directory..");
458 if (vsystem("tar -cpBf - -C /etc . | tar -xpBf - -C %s", saved_etc)) {
459 msgNotify("Unable to backup your /etc into %s.", saved_etc);
460 return DITEM_FAILURE;
463 if (file_readable("/kernel")) {
464 msgNotify("Moving old kernel to /kernel.prev");
465 if (!system("chflags noschg /kernel && mv /kernel /kernel.prev")) {
466 /* Give us a working kernel in case we crash and reboot */
467 system("cp /kernel.prev /kernel");
471 msgNotify("Beginning extraction of distributions..");
472 if (DITEM_STATUS(distExtractAll(self)) == DITEM_FAILURE) {
473 msgConfirm("Hmmmm. We couldn't even extract the bin distribution. This upgrade\n"
474 "should be considered a failure and started from the beginning, sorry!\n"
475 "The system will reboot now.");
480 if (!(Dists & DIST_BIN)) {
481 msgNotify("The extraction process seems to have had some problems, but we got most\n"
482 "of the essentials. We'll treat this as a warning since it may have been\n"
483 "only non-essential distributions which failed to upgrade.");
486 msgConfirm("Hmmmm. We couldn't even extract the bin distribution. This upgrade\n"
487 "should be considered a failure and started from the beginning, sorry!\n"
488 "The system will reboot now.");
494 msgNotify("First stage of upgrade completed successfully.");
495 if (vsystem("tar -cpBf - -C %s . | tar --unlink -xpBf - -C /etc", saved_etc)) {
496 msgNotify("Unable to resurrect your old /etc!");
497 return DITEM_FAILURE;
499 return DITEM_SUCCESS | DITEM_REDRAW;