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