install.c revision 18645
1/* 2 * The new sysinstall program. 3 * 4 * This is probably the last program in the `sysinstall' line - the next 5 * generation being essentially a complete rewrite. 6 * 7 * $Id: install.c,v 1.122 1996/10/02 08:25:09 jkh Exp $ 8 * 9 * Copyright (c) 1995 10 * Jordan Hubbard. All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 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 18 * point in the file. 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. 22 * 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 33 * SUCH DAMAGE. 34 * 35 */ 36 37#include "sysinstall.h" 38#include <ctype.h> 39#include <sys/disklabel.h> 40#include <sys/errno.h> 41#include <sys/ioctl.h> 42#include <sys/fcntl.h> 43#include <sys/wait.h> 44#include <sys/param.h> 45#define MSDOSFS 46#include <sys/mount.h> 47#undef MSDOSFS 48#include <sys/stat.h> 49#include <unistd.h> 50#include <sys/mount.h> 51 52static void create_termcap(void); 53static void save_userconfig_to_kernel(char *); 54 55#define TERMCAP_FILE "/usr/share/misc/termcap" 56 57static void installConfigure(void); 58 59Boolean 60checkLabels(Boolean whinge, Chunk **rdev, Chunk **sdev, Chunk **udev, Chunk **vdev) 61{ 62 Device **devs; 63 Boolean status; 64 Disk *disk; 65 Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev; 66 int i; 67 68 status = TRUE; 69 *rdev = *sdev = *udev = *vdev = rootdev = swapdev = usrdev = vardev = NULL; 70 71 /* We don't need to worry about root/usr/swap if we're already multiuser */ 72 if (!RunningAsInit) 73 return status; 74 75 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 76 /* First verify that we have a root device */ 77 for (i = 0; devs[i]; i++) { 78 if (!devs[i]->enabled) 79 continue; 80 disk = (Disk *)devs[i]->private; 81 msgDebug("Scanning disk %s for root filesystem\n", disk->name); 82 if (!disk->chunks) 83 msgFatal("No chunk list found for %s!", disk->name); 84 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 85 if (c1->type == freebsd) { 86 for (c2 = c1->part; c2; c2 = c2->next) { 87 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 88 if (c2->flags & CHUNK_IS_ROOT) { 89 if (rootdev) { 90 if (whinge) 91 msgConfirm("WARNING: You have more than one root device set?!\n" 92 "Using the first one found."); 93 continue; 94 } 95 else { 96 rootdev = c2; 97 if (isDebug()) 98 msgDebug("Found rootdev at %s!\n", rootdev->name); 99 } 100 } 101 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/usr")) { 102 if (usrdev) { 103 if (whinge) 104 msgConfirm("WARNING: You have more than one /usr filesystem.\n" 105 "Using the first one found."); 106 continue; 107 } 108 else { 109 usrdev = c2; 110 if (isDebug()) 111 msgDebug("Found usrdev at %s!\n", usrdev->name); 112 } 113 } 114 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/var")) { 115 if (vardev) { 116 if (whinge) 117 msgConfirm("WARNING: You have more than one /var filesystem.\n" 118 "Using the first one found."); 119 continue; 120 } 121 else { 122 vardev = c2; 123 if (isDebug()) 124 msgDebug("Found vardev at %s!\n", vardev->name); 125 } 126 } 127 } 128 } 129 } 130 } 131 } 132 133 /* Now check for swap devices */ 134 for (i = 0; devs[i]; i++) { 135 if (!devs[i]->enabled) 136 continue; 137 disk = (Disk *)devs[i]->private; 138 msgDebug("Scanning disk %s for swap partitions\n", disk->name); 139 if (!disk->chunks) 140 msgFatal("No chunk list found for %s!", disk->name); 141 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 142 if (c1->type == freebsd) { 143 for (c2 = c1->part; c2; c2 = c2->next) { 144 if (c2->type == part && c2->subtype == FS_SWAP && !swapdev) { 145 swapdev = c2; 146 if (isDebug()) 147 msgDebug("Found swapdev at %s!\n", swapdev->name); 148 break; 149 } 150 } 151 } 152 } 153 } 154 155 /* Copy our values over */ 156 *rdev = rootdev; 157 *sdev = swapdev; 158 *udev = usrdev; 159 *vdev = vardev; 160 161 if (!rootdev && whinge) { 162 msgConfirm("No root device found - you must label a partition as /\n" 163 "in the label editor."); 164 status = FALSE; 165 } 166 if (!swapdev && whinge) { 167 msgConfirm("No swap devices found - you must create at least one\n" 168 "swap partition."); 169 status = FALSE; 170 } 171 if (!usrdev && whinge) { 172 msgConfirm("WARNING: No /usr filesystem found. This is not technically\n" 173 "an error if your root filesystem is big enough (or you later\n" 174 "intend to mount your /usr filesystem over NFS), but it may otherwise\n" 175 "cause you trouble if you're not exactly sure what you are doing!"); 176 } 177 if (!vardev && whinge) { 178 msgConfirm("WARNING: No /var filesystem found. This is not technically\n" 179 "an error if your root filesystem is big enough (or you later\n" 180 "intend to link /var to someplace else), but it may otherwise\n" 181 "cause your root filesystem to fill up if you receive lots of mail\n" 182 "or edit large temporary files."); 183 } 184 return status; 185} 186 187static int 188installInitial(void) 189{ 190 static Boolean alreadyDone = FALSE; 191 192 if (alreadyDone) 193 return DITEM_SUCCESS; 194 195 if (!variable_get(DISK_LABELLED)) { 196 msgConfirm("You need to assign disk labels before you can proceed with\n" 197 "the installation."); 198 return DITEM_FAILURE; 199 } 200 /* If it's labelled, assume it's also partitioned */ 201 if (!variable_get(DISK_PARTITIONED)) 202 variable_set2(DISK_PARTITIONED, "yes"); 203 204 /* If we refuse to proceed, bail. */ 205 dialog_clear_norefresh(); 206 if (msgYesNo("Last Chance! Are you SURE you want continue the installation?\n\n" 207 "If you're running this on a disk with data you wish to save\n" 208 "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n" 209 "proceeding!\n\n" 210 "We can take no responsibility for lost disk contents!")) 211 return DITEM_FAILURE | DITEM_RESTORE; 212 213 if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) { 214 msgConfirm("Couldn't make filesystems properly. Aborting."); 215 return DITEM_FAILURE; 216 } 217 else if (isDebug()) 218 msgDebug("installInitial: Scribbled successfully on the disk(s)\n"); 219 220 if (!copySelf()) { 221 msgConfirm("Couldn't clone the boot floppy onto the root file system.\n" 222 "Aborting."); 223 return DITEM_FAILURE; 224 } 225 226 if (chroot("/mnt") == -1) { 227 msgConfirm("Unable to chroot to /mnt - this is bad!"); 228 return DITEM_FAILURE; 229 } 230 231 chdir("/"); 232 variable_set2(RUNNING_ON_ROOT, "yes"); 233 234 /* stick a helpful shell over on the 4th VTY */ 235 systemCreateHoloshell(); 236 237 alreadyDone = TRUE; 238 return DITEM_SUCCESS; 239} 240 241int 242installFixitCDROM(dialogMenuItem *self) 243{ 244 msgConfirm("Sorry, this feature is currently unimplemented but will,\n" 245 "at some point in the future, support the use of the live\n" 246 "filesystem CD (CD 2) in fixing your system."); 247 return DITEM_SUCCESS; 248} 249 250int 251installFixitFloppy(dialogMenuItem *self) 252{ 253 struct ufs_args args; 254 pid_t child; 255 int waitstatus; 256 257 variable_set2(SYSTEM_STATE, "fixit"); 258 memset(&args, 0, sizeof(args)); 259 args.fspec = "/dev/fd0"; 260 Mkdir("/mnt2"); 261 262 while (1) { 263 msgConfirm("Please insert a writable fixit floppy and press return"); 264 if (mount(MOUNT_UFS, "/mnt2", 0, (caddr_t)&args) != -1) 265 break; 266 if (msgYesNo("Unable to mount the fixit floppy - do you want to try again?")) 267 return DITEM_FAILURE; 268 } 269 dialog_clear(); 270 end_dialog(); 271 DialogActive = FALSE; 272 if (!directory_exists("/tmp")) 273 (void)symlink("/mnt2/tmp", "/tmp"); 274 if (!directory_exists("/var/tmp/vi.recover")) { 275 if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) { 276 msgConfirm("Warning: Was unable to create a /var/tmp/vi.recover directory.\n" 277 "vi will kvetch and moan about it as a result but should still\n" 278 "be essentially usable."); 279 } 280 } 281 /* Link the spwd.db file */ 282 if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS) 283 msgConfirm("Unable to create an /etc directory! Things are weird on this floppy.."); 284 else if (symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) 285 msgConfirm("Couldn't symlink the /etc/spwd.db file! I'm not sure I like this.."); 286 if (!file_readable(TERMCAP_FILE)) 287 create_termcap(); 288 if (!(child = fork())) { 289 struct termios foo; 290 291 signal(SIGTTOU, SIG_IGN); 292 if (tcgetattr(0, &foo) != -1) { 293 foo.c_cc[VERASE] = '\010'; 294 if (tcsetattr(0, TCSANOW, &foo) == -1) 295 msgDebug("fixit shell: Unable to set erase character.\n"); 296 } 297 else 298 msgDebug("fixit shell: Unable to get terminal attributes!\n"); 299 printf("When you're finished with this shell, please type exit.\n"); 300 printf("The fixit floppy itself is mounted as /mnt2\n"); 301 setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:/mnt2/stand", 1); 302 execlp("sh", "-sh", 0); 303 msgDebug("fixit shell: Failed to execute shell!\n"); 304 return -1; 305 } 306 else 307 (void)waitpid(child, &waitstatus, 0); 308 309 DialogActive = TRUE; 310 clear(); 311 dialog_clear(); 312 unmount("/mnt2", MNT_FORCE); 313 msgConfirm("Please remove the fixit floppy now."); 314 return DITEM_SUCCESS; 315} 316 317int 318installExpress(dialogMenuItem *self) 319{ 320 int i; 321 322 variable_set2(SYSTEM_STATE, "express"); 323 if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE) 324 return i; 325 326 if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE) 327 return i; 328 329 if (!Dists) { 330 dialog_clear_norefresh(); 331 if (!dmenuOpenSimple(&MenuDistributions, FALSE) && !Dists) 332 return DITEM_FAILURE | DITEM_RECREATE; 333 } 334 335 if (!mediaDevice) { 336 dialog_clear_norefresh(); 337 if (!dmenuOpenSimple(&MenuMedia, FALSE) || !mediaDevice) 338 return DITEM_FAILURE | DITEM_RECREATE; 339 } 340 341 if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) { 342 i |= DITEM_LEAVE_MENU; 343 /* Give user the option of one last configuration spree */ 344 installConfigure(); 345 346 /* Now write out any changes .. */ 347 configResolv(); 348 configSysconfig("/etc/sysconfig"); 349 } 350 return i | DITEM_RECREATE; 351} 352 353/* Novice mode installation */ 354int 355installNovice(dialogMenuItem *self) 356{ 357 int i; 358 extern int cdromMounted; 359 360 variable_set2(SYSTEM_STATE, "novice"); 361 dialog_clear_norefresh(); 362 msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n" 363 "scheme for your hard disk. If you simply wish to devote all disk space\n" 364 "to FreeBSD (overwritting anything else that might be on the disk(s) selected)\n" 365 "then use the (A)ll command to select the default partitioning scheme followed\n" 366 "by a (Q)uit. If you wish to allocate only free space to FreeBSD, move to a\n" 367 "partition marked \"unused\" and use the (C)reate command."); 368 369 if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE) 370 return DITEM_FAILURE; 371 372 dialog_clear_norefresh(); 373 msgConfirm("Next, you need to create BSD partitions inside of the fdisk partition(s)\n" 374 "just created. If you have a reasonable amount of disk space (200MB or more)\n" 375 "and don't have any special requirements, simply use the (A)uto command to\n" 376 "allocate space automatically. If you have more specific needs or just don't\n" 377 "care for the layout chosen by (A)uto, press F1 for more information on\n" 378 "manual layout."); 379 380 if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE) 381 return DITEM_FAILURE; 382 383 dialog_clear_norefresh(); 384 msgConfirm("Now it is time to select an installation subset. There are a number of\n" 385 "canned distribution sets, ranging from minimal installation sets to full\n" 386 "X11 developer oriented configurations. You can also select a custom set\n" 387 "of distributions if none of the provided ones are suitable."); 388 while (1) { 389 if (!dmenuOpenSimple(&MenuDistributions, FALSE) && !Dists) 390 return DITEM_FAILURE | DITEM_RECREATE; 391 392 if (Dists || !msgYesNo("No distributions selected. Are you sure you wish to continue?")) 393 break; 394 } 395 396 if (!mediaDevice && !dmenuOpenSimple(&MenuMedia, FALSE)) 397 return DITEM_FAILURE | DITEM_RECREATE; 398 399 if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) { 400 dialog_clear(); 401 msgConfirm("Installation completed with some errors. You may wish to\n" 402 "scroll through the debugging messages on VTY1 with the\n" 403 "scroll-lock feature. You can also chose \"No\" at the next\n" 404 "prompt and go back into the installation menus to try and retry\n" 405 "whichever operations have failed."); 406 mediaDevice->shutdown(mediaDevice); 407 if (mediaDevice->type == DEVICE_TYPE_FTP) 408 variable_unset(VAR_FTP_PATH); 409 return i | DITEM_RECREATE; 410 411 } 412 else 413 dialog_clear(); 414 msgConfirm("Congratulations! You now have FreeBSD installed on your system.\n\n" 415 "We will now move on to the final configuration questions.\n" 416 "For any option you do not wish to configure, simply select\n" 417 "No.\n\n" 418 "If you wish to re-enter this utility after the system is up, you\n" 419 "may do so by typing: /stand/sysinstall."); 420 421 if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) { 422 if (!msgYesNo("Would you like to configure any SLIP/PPP or network interface devices?")) { 423 Device *save = mediaDevice; 424 425 /* This will also set the media device, which we don't want */ 426 tcpDeviceSelect(); 427 /* so we restore our saved value below */ 428 mediaDevice = save; 429 dialog_clear_norefresh(); 430 } 431 } 432 433 if (!msgYesNo("Would you like to configure Samba for connecting NETBUI clients to this\n" 434 "machine? Windows 95, Windows NT and Windows for Workgroups\n" 435 "machines can use NETBUI transport for disk and printer sharing.")) 436 configSamba(self); 437 438 dialog_clear_norefresh(); 439 if (!msgYesNo("Will this machine be an IP gateway (e.g. will it forward packets\n" 440 "between interfaces)?")) 441 variable_set2("gateway", "YES"); 442 443 dialog_clear_norefresh(); 444 if (!msgYesNo("Do you want to allow anonymous FTP connections to this machine?")) 445 configAnonFTP(self); 446 447 dialog_clear_norefresh(); 448 if (!msgYesNo("Do you want to configure this machine as an NFS server?")) 449 configNFSServer(self); 450 451 dialog_clear_norefresh(); 452 if (!msgYesNo("Do you want to configure this machine as an NFS client?")) 453 variable_set2("nfs_client", "YES"); 454 455 dialog_clear_norefresh(); 456 if (!msgYesNo("Do you want to configure this machine as a WEB server?")) 457 configApache(self); 458 459 dialog_clear_norefresh(); 460 if (!msgYesNo("Would you like to customize your system console settings?")) { 461 WINDOW *w = savescr(); 462 463 dmenuOpenSimple(&MenuSyscons, FALSE); 464 restorescr(w); 465 } 466 467 dialog_clear_norefresh(); 468 if (!msgYesNo("Would you like to set this machine's time zone now?")) { 469 WINDOW *w = savescr(); 470 471 dialog_clear(); 472 systemExecute("rm -f /etc/wall_cmos_clock /etc/localtime; tzsetup"); 473 restorescr(w); 474 } 475 476 dialog_clear_norefresh(); 477 if (!msgYesNo("Does this system have a mouse attached to it?")) { 478 WINDOW *w = savescr(); 479 480 dmenuOpenSimple(&MenuMouse, FALSE); 481 restorescr(w); 482 } 483 484 if (directory_exists("/usr/X11R6")) { 485 dialog_clear_norefresh(); 486 if (!msgYesNo("Would you like to configure your X server at this time?")) 487 configXFree86(self); 488 } 489 490 if (cdromMounted) { 491 dialog_clear_norefresh(); 492 if (!msgYesNo("Would you like to link to the ports tree on your CDROM?\n\n" 493 "This will require that you have your FreeBSD CD in the CDROM\n" 494 "drive to use the ports collection, but at a substantial savings\n" 495 "in disk space (NOTE: This may take as long as 15 or 20 minutes\n" 496 "depending on the speed of your CDROM drive).")) 497 configPorts(self); 498 } 499 500 dialog_clear_norefresh(); 501 if (!msgYesNo("The FreeBSD package collection is a collection of over 550 ready-to-run\n" 502 "applications, from text editors to games to WEB servers. Would you like\n" 503 "to browse the collection now?")) 504 configPackages(self); 505 506 /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */ 507 508 /* Give user the option of one last configuration spree */ 509 installConfigure(); 510 511 /* Now write out any changes .. */ 512 configResolv(); 513 configSysconfig("/etc/sysconfig"); 514 515 return DITEM_LEAVE_MENU | DITEM_RECREATE; 516} 517 518/* The version of commit we call from the Install Custom menu */ 519int 520installCustomCommit(dialogMenuItem *self) 521{ 522 int i; 523 524 i = installCommit(self); 525 if (DITEM_STATUS(i) == DITEM_SUCCESS) { 526 /* Give user the option of one last configuration spree */ 527 installConfigure(); 528 529 /* Now write out any changes .. */ 530 configResolv(); 531 configSysconfig("/etc/sysconfig"); 532 return i; 533 } 534 else 535 msgConfirm("The commit operation completed with errors. Not\n" 536 "updating /etc files."); 537 return i; 538} 539 540/* 541 * What happens when we finally decide to going ahead with the installation. 542 * 543 * This is broken into multiple stages so that the user can do a full 544 * installation but come back here again to load more distributions, 545 * perhaps from a different media type. This would allow, for 546 * example, the user to load the majority of the system from CDROM and 547 * then use ftp to load just the DES dist. 548 */ 549int 550installCommit(dialogMenuItem *self) 551{ 552 int i; 553 char *str; 554 555 if (!mediaVerify()) 556 return DITEM_FAILURE; 557 558 str = variable_get(SYSTEM_STATE); 559 if (isDebug()) 560 msgDebug("installCommit: System state is `%s'\n", str); 561 562 if (RunningAsInit) { 563 /* Do things we wouldn't do to a multi-user system */ 564 if (DITEM_STATUS((i = installInitial())) == DITEM_FAILURE) 565 return i; 566 if (DITEM_STATUS((i = configFstab())) == DITEM_FAILURE) 567 return i; 568 } 569 570 i = distExtractAll(self); 571 if (DITEM_STATUS(i) != DITEM_FAILURE) 572 i = installFixup(self); 573 else if (!(Dists & DIST_BIN)) 574 (void)installFixup(self); 575 576 /* Don't print this if we're express or novice installing - they have their own error reporting */ 577 if (strcmp(str, "express") && strcmp(str, "novice")) { 578 if (Dists || DITEM_STATUS(i) == DITEM_FAILURE) 579 msgConfirm("Installation completed with some errors. You may wish to\n" 580 "scroll through the debugging messages on VTY1 with the\n" 581 "scroll-lock feature."); 582 else 583 msgConfirm("Installation completed successfully.\n\n" 584 "If you have any network devices you have not yet configured,\n" 585 "see the Interfaces configuration item on the Configuration menu."); 586 } 587 variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install"); 588 return i | DITEM_RECREATE; 589} 590 591static void 592installConfigure(void) 593{ 594 /* Final menu of last resort */ 595 dialog_clear_norefresh(); 596 if (!msgYesNo("Visit the general configuration menu for a chance to set\n" 597 "any last options?")) { 598 WINDOW *w = savescr(); 599 600 dmenuOpenSimple(&MenuConfigure, FALSE); 601 restorescr(w); 602 } 603} 604 605int 606installFixup(dialogMenuItem *self) 607{ 608 Device **devs; 609 int i; 610 611 if (!file_readable("/kernel")) { 612 if (file_readable("/kernel.GENERIC")) { 613 if (vsystem("cp -p /kernel.GENERIC /kernel")) { 614 msgConfirm("Unable to link /kernel into place!"); 615 return DITEM_FAILURE; 616 } 617 } 618 else { 619 msgConfirm("Can't find a kernel image to link to on the root file system!\n" 620 "You're going to have a hard time getting this system to\n" 621 "boot from the hard disk, I'm afraid!"); 622 return DITEM_FAILURE; 623 } 624 } 625 626 /* Snapshot any boot -c changes back to the GENERIC kernel */ 627 save_userconfig_to_kernel("/kernel"); 628 629 /* Resurrect /dev after bin distribution screws it up */ 630 if (RunningAsInit) { 631 msgNotify("Remaking all devices.. Please wait!"); 632 if (vsystem("cd /dev; sh MAKEDEV all")) { 633 msgConfirm("MAKEDEV returned non-zero status"); 634 return DITEM_FAILURE; 635 } 636 637 msgNotify("Resurrecting /dev entries for slices.."); 638 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 639 if (!devs) 640 msgFatal("Couldn't get a disk device list!"); 641 642 /* Resurrect the slices that the former clobbered */ 643 for (i = 0; devs[i]; i++) { 644 Disk *disk = (Disk *)devs[i]->private; 645 Chunk *c1; 646 647 if (!devs[i]->enabled) 648 continue; 649 if (!disk->chunks) 650 msgFatal("No chunk list found for %s!", disk->name); 651 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 652 if (c1->type == freebsd) { 653 msgNotify("Making slice entries for %s", c1->name); 654 if (vsystem("cd /dev; sh MAKEDEV %sh", c1->name)) { 655 msgConfirm("Unable to make slice entries for %s!", c1->name); 656 return DITEM_FAILURE; 657 } 658 } 659 } 660 } 661 /* XXX Do all the last ugly work-arounds here which we'll try and excise someday right?? XXX */ 662 663 msgNotify("Fixing permissions.."); 664 /* BOGON #1: XFree86 extracting /usr/X11R6 with root-only perms */ 665 if (directory_exists("/usr/X11R6")) { 666 vsystem("chmod -R a+r /usr/X11R6"); 667 vsystem("find /usr/X11R6 -type d | xargs chmod a+x"); 668 } 669 /* BOGON #2: We leave /etc in a bad state */ 670 chmod("/etc", 0755); 671 672 /* BOGON #3: No /var/db/mountdtab complains */ 673 Mkdir("/var/db"); 674 creat("/var/db/mountdtab", 0644); 675 676 /* Now run all the mtree stuff to fix things up */ 677 vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /"); 678 vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var"); 679 vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr"); 680 } 681 return DITEM_SUCCESS; 682} 683 684/* Go newfs and/or mount all the filesystems we've been asked to */ 685int 686installFilesystems(dialogMenuItem *self) 687{ 688 int i; 689 Disk *disk; 690 Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev; 691 Device **devs; 692 PartInfo *root; 693 char dname[80], *str; 694 extern int MakeDevChunk(Chunk *c, char *n); 695 Boolean upgrade = FALSE; 696 697 str = variable_get(SYSTEM_STATE); 698 699 if (!checkLabels(TRUE, &rootdev, &swapdev, &usrdev, &vardev)) 700 return DITEM_FAILURE; 701 702 if (rootdev) 703 root = (PartInfo *)rootdev->private_data; 704 else 705 root = NULL; 706 707 command_clear(); 708 upgrade = str && !strcmp(str, "upgrade"); 709 710 if (swapdev) { 711 /* As the very first thing, try to get ourselves some swap space */ 712 sprintf(dname, "/dev/%s", swapdev->name); 713 if (!Fake && (!MakeDevChunk(swapdev, "/dev") || !file_readable(dname))) { 714 msgConfirm("Unable to make device node for %s in /dev!\n" 715 "The creation of filesystems will be aborted.", dname); 716 return DITEM_FAILURE; 717 } 718 719 if (!Fake) { 720 if (!swapon(dname)) 721 msgNotify("Added %s as initial swap device", dname); 722 else 723 msgConfirm("WARNING! Unable to swap to %s: %s\n" 724 "This may cause the installation to fail at some point\n" 725 "if you don't have a lot of memory.", dname, strerror(errno)); 726 } 727 } 728 729 if (rootdev) { 730 /* Next, create and/or mount the root device */ 731 sprintf(dname, "/dev/r%sa", rootdev->disk->name); 732 if (!Fake && (!MakeDevChunk(rootdev, "/dev") || !file_readable(dname))) { 733 msgConfirm("Unable to make device node for %s in /dev!\n" 734 "The creation of filesystems will be aborted.", dname); 735 return DITEM_FAILURE; 736 } 737 if (strcmp(root->mountpoint, "/")) 738 msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", rootdev->name, root->mountpoint); 739 740 if (root->newfs) { 741 int i; 742 743 msgNotify("Making a new root filesystem on %s", dname); 744 i = vsystem("%s %s", root->newfs_cmd, dname); 745 if (i) { 746 msgConfirm("Unable to make new root filesystem on %s!\n" 747 "Command returned status %d", dname, i); 748 return DITEM_FAILURE; 749 } 750 } 751 else { 752 if (!upgrade) { 753 msgConfirm("Warning: Using existing root partition. It will be assumed\n" 754 "that you have the appropriate device entries already in /dev."); 755 } 756 msgNotify("Checking integrity of existing %s filesystem.", dname); 757 i = vsystem("fsck -y %s", dname); 758 if (i) 759 msgConfirm("Warning: fsck returned status of %d for %s.\n" 760 "This partition may be unsafe to use.", i, dname); 761 } 762 763 /* Switch to block device */ 764 sprintf(dname, "/dev/%sa", rootdev->disk->name); 765 if (Mount("/mnt", dname)) { 766 msgConfirm("Unable to mount the root file system on %s! Giving up.", dname); 767 return DITEM_FAILURE; 768 } 769 } 770 771 /* Now buzz through the rest of the partitions and mount them too */ 772 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 773 for (i = 0; devs[i]; i++) { 774 if (!devs[i]->enabled) 775 continue; 776 777 disk = (Disk *)devs[i]->private; 778 if (!disk->chunks) { 779 msgConfirm("No chunk list found for %s!", disk->name); 780 return DITEM_FAILURE; 781 } 782 if (root && (root->newfs || upgrade)) { 783 Mkdir("/mnt/dev"); 784 if (!Fake) 785 MakeDevDisk(disk, "/mnt/dev"); 786 } 787 788 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 789 if (c1->type == freebsd) { 790 for (c2 = c1->part; c2; c2 = c2->next) { 791 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 792 PartInfo *tmp = (PartInfo *)c2->private_data; 793 794 /* Already did root */ 795 if (c2 == rootdev) 796 continue; 797 798 if (tmp->newfs) 799 command_shell_add(tmp->mountpoint, "%s /mnt/dev/r%s", tmp->newfs_cmd, c2->name); 800 else 801 command_shell_add(tmp->mountpoint, "fsck -y /mnt/dev/r%s", c2->name); 802 command_func_add(tmp->mountpoint, Mount, c2->name); 803 } 804 else if (c2->type == part && c2->subtype == FS_SWAP) { 805 char fname[80]; 806 int i; 807 808 if (c2 == swapdev) 809 continue; 810 sprintf(fname, "/mnt/dev/%s", c2->name); 811 i = (Fake || swapon(fname)); 812 if (!i) 813 msgNotify("Added %s as an additional swap device", fname); 814 else 815 msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno)); 816 } 817 } 818 } 819 else if (c1->type == fat && c1->private_data && (root->newfs || upgrade)) { 820 char name[FILENAME_MAX]; 821 822 sprintf(name, "/mnt%s", ((PartInfo *)c1->private_data)->mountpoint); 823 Mkdir(name); 824 } 825 } 826 } 827 828 msgNotify("Copying initial device files.."); 829 /* Copy the boot floppy's dev files */ 830 if ((root->newfs || upgrade) && vsystem("find -x /dev | cpio %s -pdum /mnt", cpioVerbosity())) { 831 msgConfirm("Couldn't clone the /dev files!"); 832 return DITEM_FAILURE; 833 } 834 835 command_sort(); 836 command_execute(); 837 return DITEM_SUCCESS; 838} 839 840/* Initialize various user-settable values to their defaults */ 841int 842installVarDefaults(dialogMenuItem *self) 843{ 844 char *cp; 845 846 /* Set default startup options */ 847 variable_set2(VAR_ROUTEDFLAGS, "-q"); 848 variable_set2(VAR_RELNAME, RELEASE_NAME); 849 variable_set2(VAR_CPIO_VERBOSITY, "high"); 850 variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE); 851 variable_set2(VAR_INSTALL_ROOT, "/"); 852 cp = getenv("EDITOR"); 853 if (!cp) 854 cp = "/usr/bin/ee"; 855 variable_set2(VAR_EDITOR, cp); 856 variable_set2(VAR_FTP_USER, "ftp"); 857 variable_set2(VAR_BROWSER_PACKAGE, "lynx-2.5FM"); 858 variable_set2(VAR_BROWSER_BINARY, "/usr/local/bin/lynx"); 859 variable_set2(VAR_FTP_STATE, "passive"); 860 variable_set2(VAR_PKG_TMPDIR, "/usr/tmp"); 861 if (getpid() != 1) 862 variable_set2(SYSTEM_STATE, "update"); 863 else 864 variable_set2(SYSTEM_STATE, "init"); 865 return DITEM_SUCCESS; 866} 867 868/* Copy the boot floppy contents into /stand */ 869Boolean 870copySelf(void) 871{ 872 int i; 873 874 msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem"); 875 i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity()); 876 if (i) { 877 msgConfirm("Copy returned error status of %d!", i); 878 return FALSE; 879 } 880 881 /* Copy the /etc files into their rightful place */ 882 if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) { 883 msgConfirm("Couldn't copy up the /etc files!"); 884 return TRUE; 885 } 886 return TRUE; 887} 888 889static void 890create_termcap(void) 891{ 892 FILE *fp; 893 894 const char *caps[] = { 895 termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r, 896 termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m, NULL, 897 }; 898 const char **cp; 899 900 if (!file_readable(TERMCAP_FILE)) { 901 Mkdir("/usr/share/misc"); 902 fp = fopen(TERMCAP_FILE, "w"); 903 if (!fp) { 904 msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work."); 905 return; 906 } 907 cp = caps; 908 while (*cp) 909 fprintf(fp, "%s\n", *(cp++)); 910 fclose(fp); 911 } 912} 913 914static void 915save_userconfig_to_kernel(char *kern) 916{ 917 /* place-holder for now */ 918} 919