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