install.c revision 26598
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.187 1997/05/30 01:03: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 "uc_main.h" 39#include <ctype.h> 40#include <sys/disklabel.h> 41#include <sys/errno.h> 42#include <sys/ioctl.h> 43#include <sys/fcntl.h> 44#include <sys/wait.h> 45#include <sys/param.h> 46#define MSDOSFS 47#include <sys/mount.h> 48#include <ufs/ufs/ufsmount.h> 49#include <msdosfs/msdosfsmount.h> 50#undef MSDOSFS 51#include <sys/stat.h> 52#include <unistd.h> 53 54static void create_termcap(void); 55static void fixit_common(void); 56#ifdef SAVE_USERCONFIG 57static void save_userconfig_to_kernel(char *); 58#endif 59 60#define TERMCAP_FILE "/usr/share/misc/termcap" 61 62static void installConfigure(void); 63 64Boolean 65checkLabels(Boolean whinge, Chunk **rdev, Chunk **sdev, Chunk **udev, Chunk **vdev) 66{ 67 Device **devs; 68 Boolean status; 69 Disk *disk; 70 Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev; 71 int i; 72 73 status = TRUE; 74 *rdev = *sdev = *udev = *vdev = rootdev = swapdev = usrdev = vardev = NULL; 75 76 /* We don't need to worry about root/usr/swap if we're already multiuser */ 77 if (!RunningAsInit) 78 return status; 79 80 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 81 /* First verify that we have a root device */ 82 for (i = 0; devs[i]; i++) { 83 if (!devs[i]->enabled) 84 continue; 85 disk = (Disk *)devs[i]->private; 86 msgDebug("Scanning disk %s for root filesystem\n", disk->name); 87 if (!disk->chunks) 88 msgFatal("No chunk list found for %s!", disk->name); 89 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 90 if (c1->type == freebsd) { 91 for (c2 = c1->part; c2; c2 = c2->next) { 92 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 93 if (c2->flags & CHUNK_IS_ROOT) { 94 if (rootdev) { 95 if (whinge) 96 msgConfirm("WARNING: You have more than one root device set?!\n" 97 "Using the first one found."); 98 continue; 99 } 100 else { 101 rootdev = c2; 102 if (isDebug()) 103 msgDebug("Found rootdev at %s!\n", rootdev->name); 104 } 105 } 106 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/usr")) { 107 if (usrdev) { 108 if (whinge) 109 msgConfirm("WARNING: You have more than one /usr filesystem.\n" 110 "Using the first one found."); 111 continue; 112 } 113 else { 114 usrdev = c2; 115 if (isDebug()) 116 msgDebug("Found usrdev at %s!\n", usrdev->name); 117 } 118 } 119 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/var")) { 120 if (vardev) { 121 if (whinge) 122 msgConfirm("WARNING: You have more than one /var filesystem.\n" 123 "Using the first one found."); 124 continue; 125 } 126 else { 127 vardev = c2; 128 if (isDebug()) 129 msgDebug("Found vardev at %s!\n", vardev->name); 130 } 131 } 132 } 133 } 134 } 135 } 136 } 137 138 /* Now check for swap devices */ 139 for (i = 0; devs[i]; i++) { 140 if (!devs[i]->enabled) 141 continue; 142 disk = (Disk *)devs[i]->private; 143 msgDebug("Scanning disk %s for swap partitions\n", disk->name); 144 if (!disk->chunks) 145 msgFatal("No chunk list found for %s!", disk->name); 146 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 147 if (c1->type == freebsd) { 148 for (c2 = c1->part; c2; c2 = c2->next) { 149 if (c2->type == part && c2->subtype == FS_SWAP && !swapdev) { 150 swapdev = c2; 151 if (isDebug()) 152 msgDebug("Found swapdev at %s!\n", swapdev->name); 153 break; 154 } 155 } 156 } 157 } 158 } 159 160 /* Copy our values over */ 161 *rdev = rootdev; 162 *sdev = swapdev; 163 *udev = usrdev; 164 *vdev = vardev; 165 166 if (!rootdev && whinge) { 167 msgConfirm("No root device found - you must label a partition as /\n" 168 "in the label editor."); 169 status = FALSE; 170 } 171 if (!swapdev && whinge) { 172 msgConfirm("No swap devices found - you must create at least one\n" 173 "swap partition."); 174 status = FALSE; 175 } 176 if (!usrdev && whinge) { 177 msgConfirm("WARNING: No /usr filesystem found. This is not technically\n" 178 "an error if your root filesystem is big enough (or you later\n" 179 "intend to mount your /usr filesystem over NFS), but it may otherwise\n" 180 "cause you trouble if you're not exactly sure what you are doing!"); 181 } 182 if (!vardev && whinge) { 183 msgConfirm("WARNING: No /var filesystem found. This is not technically\n" 184 "an error if your root filesystem is big enough (or you later\n" 185 "intend to link /var to someplace else), but it may otherwise\n" 186 "cause your root filesystem to fill up if you receive lots of mail\n" 187 "or edit large temporary files."); 188 } 189 return status; 190} 191 192static int 193installInitial(void) 194{ 195 static Boolean alreadyDone = FALSE; 196 197 if (alreadyDone) 198 return DITEM_SUCCESS; 199 200 if (!variable_get(DISK_LABELLED)) { 201 msgConfirm("You need to assign disk labels before you can proceed with\n" 202 "the installation."); 203 return DITEM_FAILURE; 204 } 205 /* If it's labelled, assume it's also partitioned */ 206 if (!variable_get(DISK_PARTITIONED)) 207 variable_set2(DISK_PARTITIONED, "yes"); 208 209 /* If we refuse to proceed, bail. */ 210 dialog_clear_norefresh(); 211 if (msgYesNo("Last Chance! Are you SURE you want continue the installation?\n\n" 212 "If you're running this on a disk with data you wish to save\n" 213 "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n" 214 "proceeding!\n\n" 215 "We can take no responsibility for lost disk contents!") != 0) 216 return DITEM_FAILURE | DITEM_RESTORE; 217 218 if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) { 219 msgConfirm("Couldn't make filesystems properly. Aborting."); 220 return DITEM_FAILURE; 221 } 222 else if (isDebug()) 223 msgDebug("installInitial: Scribbled successfully on the disk(s)\n"); 224 225 if (!copySelf()) { 226 msgConfirm("Couldn't clone the boot floppy onto the root file system.\n" 227 "Aborting."); 228 return DITEM_FAILURE; 229 } 230 231 if (chroot("/mnt") == -1) { 232 msgConfirm("Unable to chroot to %s - this is bad!", "/mnt"); 233 return DITEM_FAILURE; 234 } 235 236 chdir("/"); 237 variable_set2(RUNNING_ON_ROOT, "yes"); 238 configResolv(); 239 240 /* stick a helpful shell over on the 4th VTY */ 241 systemCreateHoloshell(); 242 243 alreadyDone = TRUE; 244 return DITEM_SUCCESS; 245} 246 247int 248installFixitHoloShell(dialogMenuItem *self) 249{ 250 systemCreateHoloshell(); 251 return DITEM_SUCCESS; 252} 253 254int 255installFixitCDROM(dialogMenuItem *self) 256{ 257 struct stat sb; 258 259 if (!RunningAsInit) 260 return DITEM_SUCCESS; 261 262 variable_set2(SYSTEM_STATE, "fixit"); 263 (void)unlink("/mnt2"); 264 (void)rmdir("/mnt2"); 265 266 while (1) { 267 msgConfirm("Please insert the second FreeBSD CDROM and press return"); 268 if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS || !mediaDevice || !mediaDevice->init(mediaDevice)) { 269 /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */ 270 if (mediaDevice) { 271 mediaDevice->shutdown(mediaDevice); 272 mediaDevice = NULL; 273 } 274 if (msgYesNo("Unable to mount the CDROM - do you want to try again?") != 0) 275 return DITEM_FAILURE; 276 } 277 else 278 break; 279 } 280 281 /* Since the fixit code expects everything to be in /mnt2, and the CDROM mounting stuff /dist, do 282 * a little kludge dance here.. 283 */ 284 if (symlink("/dist", "/mnt2")) { 285 msgConfirm("Unable to symlink /mnt2 to the CDROM mount point. Please report this\n" 286 "unexpected failure to freebsd-bugs@FreeBSD.org."); 287 return DITEM_FAILURE; 288 } 289 290 /* 291 * If /tmp points to /mnt2/tmp from a previous fixit floppy session, it's 292 * not very good for us if we point it to the CDROM now. Rather make it 293 * a directory in the root MFS then. Experienced admins will still be 294 * able to mount their disk's /tmp over this if they need. 295 */ 296 if (lstat("/tmp", &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFLNK) 297 (void)unlink("/tmp"); 298 Mkdir("/tmp"); 299 300 /* 301 * Since setuid binaries ignore LD_LIBRARY_PATH, we indeed need the 302 * ld.so.hints file. Fortunately, it's fairly small (~ 3 KB). 303 */ 304 if (!file_readable("/var/run/ld.so.hints")) { 305 Mkdir("/var/run"); 306 if (vsystem("/mnt2/sbin/ldconfig -s /mnt2/usr/lib")) { 307 msgConfirm("Warning: ldconfig could not create the ld.so hints file.\n" 308 "Dynamic executables from the CDROM likely won't work."); 309 } 310 } 311 312 /* Yet another iggly hardcoded pathname. */ 313 if (!file_readable("/usr/libexec/ld.so")) { 314 Mkdir("/usr/libexec"); 315 if (symlink("/mnt2/usr/libexec/ld.so", "/usr/libexec/ld.so")) { 316 msgConfirm("Warning: could not create the symlink for ld.so.\n" 317 "Dynamic executables from the CDROM likely won't work."); 318 } 319 } 320 321 fixit_common(); 322 323 mediaDevice->shutdown(mediaDevice); 324 msgConfirm("Please remove the FreeBSD CDROM now."); 325 return DITEM_SUCCESS; 326} 327 328int 329installFixitFloppy(dialogMenuItem *self) 330{ 331 struct ufs_args args; 332 333 if (!RunningAsInit) 334 return DITEM_SUCCESS; 335 336 variable_set2(SYSTEM_STATE, "fixit"); 337 memset(&args, 0, sizeof(args)); 338 args.fspec = "/dev/fd0"; 339 Mkdir("/mnt2"); 340 341 while (1) { 342 msgConfirm("Please insert a writable fixit floppy and press return"); 343 if (mount(MOUNT_UFS, "/mnt2", 0, (caddr_t)&args) != -1) 344 break; 345 msgConfirm("An attempt to mount the fixit floppy failed, maybe the filesystem\n" 346 "is unclean. Trying a forcible mount as a last resort..."); 347 if (mount(MOUNT_UFS, "/mnt2", MNT_FORCE, (caddr_t)&args) != -1) 348 break; 349 if (msgYesNo("Unable to mount the fixit floppy - do you want to try again?") != 0) 350 return DITEM_FAILURE; 351 } 352 353 if (!directory_exists("/tmp")) 354 (void)symlink("/mnt2/tmp", "/tmp"); 355 356 fixit_common(); 357 358 unmount("/mnt2", MNT_FORCE); 359 msgConfirm("Please remove the fixit floppy now."); 360 return DITEM_SUCCESS; 361} 362 363/* 364 * The common code for both fixit variants. 365 */ 366static void 367fixit_common(void) 368{ 369 pid_t child; 370 int waitstatus; 371 372 if (!directory_exists("/var/tmp/vi.recover")) { 373 if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) { 374 msgConfirm("Warning: Was unable to create a /var/tmp/vi.recover directory.\n" 375 "vi will kvetch and moan about it as a result but should still\n" 376 "be essentially usable."); 377 } 378 } 379 if (!directory_exists("/bin")) 380 (void)Mkdir("/bin"); 381 (void)symlink("/stand/sh", "/bin/sh"); 382 /* Link the /etc/ files */ 383 if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS) 384 msgConfirm("Unable to create an /etc directory! Things are weird on this floppy.."); 385 else if ((symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) || 386 (symlink("/mnt2/etc/protocols", "/etc/protocols") == -1 && errno != EEXIST) || 387 (symlink("/mnt2/etc/services", "/etc/services") == -1 && errno != EEXIST)) 388 msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this.."); 389 if (!file_readable(TERMCAP_FILE)) 390 create_termcap(); 391 if (!(child = fork())) { 392 int i, fd; 393 struct termios foo; 394 extern int login_tty(int); 395 396 ioctl(0, TIOCNOTTY, NULL); 397 for (i = getdtablesize(); i >= 0; --i) 398 close(i); 399 fd = open("/dev/ttyv3", O_RDWR); 400 ioctl(0, TIOCSCTTY, &fd); 401 dup2(0, 1); 402 dup2(0, 2); 403 DebugFD = 2; 404 if (login_tty(fd) == -1) 405 msgDebug("fixit: I can't set the controlling terminal.\n"); 406 407 signal(SIGTTOU, SIG_IGN); 408 if (tcgetattr(0, &foo) != -1) { 409 foo.c_cc[VERASE] = '\010'; 410 if (tcsetattr(0, TCSANOW, &foo) == -1) 411 msgDebug("fixit shell: Unable to set erase character.\n"); 412 } 413 else 414 msgDebug("fixit shell: Unable to get terminal attributes!\n"); 415 setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:" 416 "/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin", 1); 417 /* use the .profile from the fixit medium */ 418 setenv("HOME", "/mnt2", 1); 419 chdir("/mnt2"); 420 execlp("sh", "-sh", 0); 421 msgDebug("fixit shell: Failed to execute shell!\n"); 422 _exit(1);; 423 } 424 else { 425 msgNotify("Waiting for fixit shell to exit. Go to VTY4 now by\n" 426 "typing ALT-F4. When you are done, type ``exit'' to exit\n" 427 "the fixit shell and be returned here."); 428 (void)waitpid(child, &waitstatus, 0); 429 } 430 dialog_clear(); 431} 432 433 434int 435installExpress(dialogMenuItem *self) 436{ 437 int i; 438 439 variable_set2(SYSTEM_STATE, "express"); 440 if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE) 441 return i; 442 443 if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE) 444 return i; 445 446 if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) { 447 i |= DITEM_LEAVE_MENU; 448 /* Give user the option of one last configuration spree */ 449 installConfigure(); 450 } 451 return i | DITEM_RESTORE; 452} 453 454/* Novice mode installation */ 455int 456installNovice(dialogMenuItem *self) 457{ 458 int i; 459 460 variable_set2(SYSTEM_STATE, "novice"); 461 dialog_clear_norefresh(); 462 msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n" 463 "scheme for your hard disk. If you simply wish to devote all disk space\n" 464 "to FreeBSD (overwriting anything else that might be on the disk(s) selected)\n" 465 "then use the (A)ll command to select the default partitioning scheme followed\n" 466 "by a (Q)uit. If you wish to allocate only free space to FreeBSD, move to a\n" 467 "partition marked \"unused\" and use the (C)reate command."); 468 469 if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE) 470 return DITEM_FAILURE; 471 472 dialog_clear_norefresh(); 473 msgConfirm("Next, you need to create BSD partitions inside of the fdisk partition(s)\n" 474 "just created. If you have a reasonable amount of disk space (200MB or more)\n" 475 "and don't have any special requirements, simply use the (A)uto command to\n" 476 "allocate space automatically. If you have more specific needs or just don't\n" 477 "care for the layout chosen by (A)uto, press F1 for more information on\n" 478 "manual layout."); 479 480 if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE) 481 return DITEM_FAILURE; 482 483 if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) { 484 dialog_clear_norefresh(); 485 msgConfirm("Installation completed with some errors. You may wish to\n" 486 "scroll through the debugging messages on VTY1 with the\n" 487 "scroll-lock feature. You can also chose \"No\" at the next\n" 488 "prompt and go back into the installation menus to try and retry\n" 489 "whichever operations have failed."); 490 return i | DITEM_RESTORE; 491 492 } 493 else { 494 dialog_clear_norefresh(); 495 msgConfirm("Congratulations! You now have FreeBSD installed on your system.\n\n" 496 "We will now move on to the final configuration questions.\n" 497 "For any option you do not wish to configure, simply select\n" 498 "No.\n\n" 499 "If you wish to re-enter this utility after the system is up, you\n" 500 "may do so by typing: /stand/sysinstall."); 501 } 502 if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) { 503 if (!msgYesNo("Would you like to configure any Ethernet or SLIP/PPP network devices?")) { 504 Device *tmp; 505 506 dialog_clear_norefresh(); 507 tmp = tcpDeviceSelect(); 508 dialog_clear_norefresh(); 509 if (tmp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) 510 if (!tmp->init(tmp)) 511 msgConfirm("Initialization of %s device failed.", tmp->name); 512 } 513 } 514 515 dialog_clear_norefresh(); 516 if (!msgYesNo("Would you like to configure Samba for connecting NETBUI clients to this\n" 517 "machine? Windows 95, Windows NT and Windows for Workgroups\n" 518 "machines can use NETBUI transport for disk and printer sharing.")) 519 configSamba(self); 520 521 dialog_clear_norefresh(); 522 if (!msgYesNo("Will this machine be an IP gateway (e.g. will it forward packets\n" 523 "between interfaces)?")) 524 variable_set2("gateway", "YES"); 525 526 dialog_clear_norefresh(); 527 if (!msgYesNo("Do you want to allow anonymous FTP connections to this machine?")) 528 configAnonFTP(self); 529 530 dialog_clear_norefresh(); 531 if (!msgYesNo("Do you want to configure this machine as an NFS server?")) 532 configNFSServer(self); 533 534 dialog_clear_norefresh(); 535 if (!msgYesNo("Do you want to configure this machine as an NFS client?")) 536 variable_set2("nfs_client", "YES"); 537 538 dialog_clear_norefresh(); 539 if (!msgYesNo("Would you like to customize your system console settings?")) { 540 WINDOW *w = savescr(); 541 542 dmenuOpenSimple(&MenuSyscons, FALSE); 543 restorescr(w); 544 } 545 546 dialog_clear_norefresh(); 547 if (!msgYesNo("Would you like to set this machine's time zone now?")) { 548 WINDOW *w = savescr(); 549 550 dialog_clear(); 551 systemExecute("tzsetup"); 552 restorescr(w); 553 } 554 555 dialog_clear_norefresh(); 556 if (!msgYesNo("Does this system have a mouse attached to it?")) { 557 WINDOW *w = savescr(); 558 559 dmenuOpenSimple(&MenuMouse, FALSE); 560 restorescr(w); 561 } 562 563 /* Now would be a good time to checkpoint the configuration data */ 564 configRC_conf("/etc/rc.conf"); 565 sync(); 566 567 if (directory_exists("/usr/X11R6")) { 568 dialog_clear_norefresh(); 569 if (!msgYesNo("Would you like to configure your X server at this time?")) 570 configXFree86(self); 571 } 572 573 dialog_clear_norefresh(); 574 if (!msgYesNo("The FreeBSD package collection is a collection of hundreds of ready-to-run\n" 575 "applications, from text editors to games to WEB servers and more. Would you\n" 576 "like to browse the collection now?")) 577 configPackages(self); 578 579 dialog_clear_norefresh(); 580 if (!msgYesNo("Would you like to add any initial user accounts to the system?\n" 581 "Adding at least one account for yourself at this stage is suggested\n" 582 "since working as the \"root\" user is dangerous (it is easy to do\n" 583 "things which adversely affect the entire system).")) 584 configUsers(self); 585 586 dialog_clear_norefresh(); 587 msgConfirm("Now you must set the system manager's password.\n" 588 "This is the password you'll use to log in as \"root\"."); 589 { 590 WINDOW *w = savescr(); 591 592 if (!systemExecute("passwd root")) 593 variable_set2("root_password", "YES"); 594 restorescr(w); 595 } 596 597 dialog_clear_norefresh(); 598 if (!msgYesNo("Would you like to register your FreeBSD system at this time?\n\n" 599 "PLEASE, take just 5 minutes to do this. If we're ever to get any\n" 600 "significant base of commercial software for FreeBSD, we need to\n" 601 "be able to provide more information about the size of our user community.\n" 602 "This is where your registration can really help us, and you can also\n" 603 "sign up for the new FreeBSD newsletter (its free!) at the same time.\n")) 604 configRegister(NULL); 605 else 606 msgConfirm("OK, but if you should change your mind then you always can register\n" 607 "later by typing ``/stand/sysinstall register'' or by simply visiting our\n" 608 "web site at http://www.freebsd.org/register.html"); 609 610 /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */ 611 612 /* Give user the option of one last configuration spree */ 613 installConfigure(); 614 615 return DITEM_LEAVE_MENU | DITEM_RESTORE; 616} 617 618/* The version of commit we call from the Install Custom menu */ 619int 620installCustomCommit(dialogMenuItem *self) 621{ 622 int i; 623 624 i = installCommit(self); 625 if (DITEM_STATUS(i) == DITEM_SUCCESS) { 626 /* Give user the option of one last configuration spree */ 627 installConfigure(); 628 return i; 629 } 630 else 631 msgConfirm("The commit operation completed with errors. Not\n" 632 "updating /etc files."); 633 return i; 634} 635 636/* 637 * What happens when we finally decide to going ahead with the installation. 638 * 639 * This is broken into multiple stages so that the user can do a full 640 * installation but come back here again to load more distributions, 641 * perhaps from a different media type. This would allow, for 642 * example, the user to load the majority of the system from CDROM and 643 * then use ftp to load just the DES dist. 644 */ 645int 646installCommit(dialogMenuItem *self) 647{ 648 int i; 649 char *str; 650 Boolean need_bin; 651 652 if (!Dists) 653 distConfig(NULL); 654 655 if (!Dists) 656 if (!dmenuOpenSimple(&MenuDistributions, FALSE) && !Dists) 657 return DITEM_FAILURE | DITEM_RESTORE; 658 659 if (!mediaVerify()) 660 return DITEM_FAILURE | DITEM_RESTORE; 661 662 str = variable_get(SYSTEM_STATE); 663 if (isDebug()) 664 msgDebug("installCommit: System state is `%s'\n", str); 665 666 if (RunningAsInit) { 667 /* Do things we wouldn't do to a multi-user system */ 668 if (DITEM_STATUS((i = installInitial())) == DITEM_FAILURE) 669 return i; 670 if (DITEM_STATUS((i = configFstab())) == DITEM_FAILURE) 671 return i; 672 } 673 674try_media: 675 if (!mediaDevice->init(mediaDevice)) { 676 if (!msgYesNo("Unable to initialize selected media. Would you like to\n" 677 "adjust your media configuration and try again?")) { 678 mediaDevice = NULL; 679 if (!mediaVerify()) 680 return DITEM_FAILURE | DITEM_RESTORE; 681 else 682 goto try_media; 683 } 684 else 685 return DITEM_FAILURE | DITEM_RESTORE; 686 } 687 688 need_bin = Dists & DIST_BIN; 689 i = distExtractAll(self); 690 if (DITEM_STATUS(i) == DITEM_SUCCESS) { 691 if (need_bin && !(Dists & DIST_BIN)) 692 i = installFixup(self); 693 } 694 variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install"); 695 return i | DITEM_RESTORE; 696} 697 698static void 699installConfigure(void) 700{ 701 /* Final menu of last resort */ 702 dialog_clear_norefresh(); 703 if (!msgYesNo("Visit the general configuration menu for a chance to set\n" 704 "any last options?")) { 705 WINDOW *w = savescr(); 706 707 dmenuOpenSimple(&MenuConfigure, FALSE); 708 restorescr(w); 709 } 710 configRC_conf("/etc/rc.conf"); 711 sync(); 712} 713 714int 715installFixup(dialogMenuItem *self) 716{ 717 Device **devs; 718 int i; 719 720 if (!file_readable("/kernel")) { 721 if (file_readable("/kernel.GENERIC")) { 722#ifdef SAVE_USERCONFIG 723 /* Snapshot any boot -c changes back to the GENERIC kernel */ 724 if (!strcmp(variable_get(VAR_RELNAME), RELEASE_NAME)) 725 save_userconfig_to_kernel("/kernel.GENERIC"); 726#endif 727 if (vsystem("cp -p /kernel.GENERIC /kernel")) { 728 msgConfirm("Unable to link /kernel into place!"); 729 return DITEM_FAILURE; 730 } 731 } 732 else { 733 msgConfirm("Can't find a kernel image to link to on the root file system!\n" 734 "You're going to have a hard time getting this system to\n" 735 "boot from the hard disk, I'm afraid!"); 736 return DITEM_FAILURE; 737 } 738 } 739 740 /* Resurrect /dev after bin distribution screws it up */ 741 if (RunningAsInit) { 742 msgNotify("Remaking all devices.. Please wait!"); 743 if (vsystem("cd /dev; sh MAKEDEV all")) { 744 msgConfirm("MAKEDEV returned non-zero status"); 745 return DITEM_FAILURE; 746 } 747 748 msgNotify("Resurrecting /dev entries for slices.."); 749 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 750 if (!devs) 751 msgFatal("Couldn't get a disk device list!"); 752 753 /* Resurrect the slices that the former clobbered */ 754 for (i = 0; devs[i]; i++) { 755 Disk *disk = (Disk *)devs[i]->private; 756 Chunk *c1; 757 758 if (!devs[i]->enabled) 759 continue; 760 if (!disk->chunks) 761 msgFatal("No chunk list found for %s!", disk->name); 762 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 763 if (c1->type == freebsd) { 764 msgNotify("Making slice entries for %s", c1->name); 765 if (vsystem("cd /dev; sh MAKEDEV %sh", c1->name)) { 766 msgConfirm("Unable to make slice entries for %s!", c1->name); 767 return DITEM_FAILURE; 768 } 769 } 770 } 771 } 772 /* XXX Do all the last ugly work-arounds here which we'll try and excise someday right?? XXX */ 773 774 msgNotify("Fixing permissions.."); 775 /* BOGON #1: XFree86 extracting /usr/X11R6 with root-only perms */ 776 if (directory_exists("/usr/X11R6")) { 777 vsystem("chmod -R a+r /usr/X11R6"); 778 vsystem("find /usr/X11R6 -type d | xargs chmod a+x"); 779 } 780 /* BOGON #2: We leave /etc in a bad state */ 781 chmod("/etc", 0755); 782 783 /* BOGON #3: No /var/db/mountdtab complains */ 784 Mkdir("/var/db"); 785 creat("/var/db/mountdtab", 0644); 786 787 /* Now run all the mtree stuff to fix things up */ 788 vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /"); 789 vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var"); 790 vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr"); 791 } 792 return DITEM_SUCCESS; 793} 794 795/* Go newfs and/or mount all the filesystems we've been asked to */ 796int 797installFilesystems(dialogMenuItem *self) 798{ 799 int i; 800 Disk *disk; 801 Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev; 802 Device **devs; 803 PartInfo *root; 804 char dname[80], *str; 805 extern int MakeDevChunk(Chunk *c, char *n); 806 Boolean upgrade = FALSE; 807 808 /* If we've already done this, bail out */ 809 if ((str = variable_get(DISK_LABELLED)) && !strcmp(str, "written")) 810 return DITEM_SUCCESS; 811 812 str = variable_get(SYSTEM_STATE); 813 814 if (!checkLabels(TRUE, &rootdev, &swapdev, &usrdev, &vardev)) 815 return DITEM_FAILURE; 816 817 if (rootdev) 818 root = (PartInfo *)rootdev->private_data; 819 else 820 root = NULL; 821 822 command_clear(); 823 upgrade = str && !strcmp(str, "upgrade"); 824 825 if (swapdev && RunningAsInit) { 826 /* As the very first thing, try to get ourselves some swap space */ 827 sprintf(dname, "/dev/%s", swapdev->name); 828 if (!Fake && (!MakeDevChunk(swapdev, "/dev") || !file_readable(dname))) { 829 msgConfirm("Unable to make device node for %s in /dev!\n" 830 "The creation of filesystems will be aborted.", dname); 831 return DITEM_FAILURE; 832 } 833 834 if (!Fake) { 835 if (!swapon(dname)) 836 msgNotify("Added %s as initial swap device", dname); 837 else 838 msgConfirm("WARNING! Unable to swap to %s: %s\n" 839 "This may cause the installation to fail at some point\n" 840 "if you don't have a lot of memory.", dname, strerror(errno)); 841 } 842 } 843 844 if (rootdev && RunningAsInit) { 845 /* Next, create and/or mount the root device */ 846 sprintf(dname, "/dev/r%sa", rootdev->disk->name); 847 if (!Fake && (!MakeDevChunk(rootdev, "/dev") || !file_readable(dname))) { 848 msgConfirm("Unable to make device node for %s in /dev!\n" 849 "The creation of filesystems will be aborted.", dname); 850 return DITEM_FAILURE; 851 } 852 if (strcmp(root->mountpoint, "/")) 853 msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", rootdev->name, root->mountpoint); 854 855 if (root->newfs) { 856 int i; 857 858 msgNotify("Making a new root filesystem on %s", dname); 859 i = vsystem("%s %s", root->newfs_cmd, dname); 860 if (i) { 861 msgConfirm("Unable to make new root filesystem on %s!\n" 862 "Command returned status %d", dname, i); 863 return DITEM_FAILURE; 864 } 865 } 866 else { 867 if (!upgrade) { 868 msgConfirm("Warning: Using existing root partition. It will be assumed\n" 869 "that you have the appropriate device entries already in /dev."); 870 } 871 msgNotify("Checking integrity of existing %s filesystem.", dname); 872 i = vsystem("fsck -y %s", dname); 873 if (i) 874 msgConfirm("Warning: fsck returned status of %d for %s.\n" 875 "This partition may be unsafe to use.", i, dname); 876 } 877 878 /* Switch to block device */ 879 sprintf(dname, "/dev/%sa", rootdev->disk->name); 880 if (Mount("/mnt", dname)) { 881 msgConfirm("Unable to mount the root file system on %s! Giving up.", dname); 882 return DITEM_FAILURE; 883 } 884 } 885 886 /* Now buzz through the rest of the partitions and mount them too */ 887 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 888 for (i = 0; devs[i]; i++) { 889 if (!devs[i]->enabled) 890 continue; 891 892 disk = (Disk *)devs[i]->private; 893 if (!disk->chunks) { 894 msgConfirm("No chunk list found for %s!", disk->name); 895 return DITEM_FAILURE; 896 } 897 if (RunningAsInit && root && (root->newfs || upgrade)) { 898 Mkdir("/mnt/dev"); 899 if (!Fake) 900 MakeDevDisk(disk, "/mnt/dev"); 901 } 902 else if (!RunningAsInit && !Fake) 903 MakeDevDisk(disk, "/dev"); 904 905 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 906 if (c1->type == freebsd) { 907 for (c2 = c1->part; c2; c2 = c2->next) { 908 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 909 PartInfo *tmp = (PartInfo *)c2->private_data; 910 911 /* Already did root */ 912 if (c2 == rootdev) 913 continue; 914 915 if (tmp->newfs) 916 command_shell_add(tmp->mountpoint, "%s %s/dev/r%s", tmp->newfs_cmd, RunningAsInit ? "/mnt" : "", c2->name); 917 else 918 command_shell_add(tmp->mountpoint, "fsck -y %s/dev/r%s", RunningAsInit ? "/mnt" : "", c2->name); 919 command_func_add(tmp->mountpoint, Mount, c2->name); 920 } 921 else if (c2->type == part && c2->subtype == FS_SWAP) { 922 char fname[80]; 923 int i; 924 925 if (c2 == swapdev) 926 continue; 927 sprintf(fname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name); 928 i = (Fake || swapon(fname)); 929 if (!i) 930 msgNotify("Added %s as an additional swap device", fname); 931 else 932 msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno)); 933 } 934 } 935 } 936 else if (c1->type == fat && c1->private_data && (root->newfs || upgrade)) { 937 char name[FILENAME_MAX]; 938 939 sprintf(name, "%s/%s", RunningAsInit ? "/mnt" : "", ((PartInfo *)c1->private_data)->mountpoint); 940 Mkdir(name); 941 } 942 } 943 } 944 945 if (RunningAsInit) { 946 msgNotify("Copying initial device files.."); 947 /* Copy the boot floppy's dev files */ 948 if ((root->newfs || upgrade) && vsystem("find -x /dev | cpio %s -pdum /mnt", cpioVerbosity())) { 949 msgConfirm("Couldn't clone the /dev files!"); 950 return DITEM_FAILURE; 951 } 952 } 953 954 command_sort(); 955 command_execute(); 956 return DITEM_SUCCESS; 957} 958 959/* Initialize various user-settable values to their defaults */ 960int 961installVarDefaults(dialogMenuItem *self) 962{ 963 char *cp; 964 965 /* Set default startup options */ 966 variable_set2(VAR_ROUTER_ENABLE, "NO"); 967 variable_set2(VAR_RELNAME, RELEASE_NAME); 968 variable_set2(VAR_CPIO_VERBOSITY, "high"); 969 variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE); 970 variable_set2(VAR_INSTALL_ROOT, "/"); 971 variable_set2(VAR_INSTALL_CFG, "install.cfg"); 972 cp = getenv("EDITOR"); 973 if (!cp) 974 cp = "/usr/bin/ee"; 975 variable_set2(VAR_EDITOR, cp); 976 variable_set2(VAR_FTP_USER, "ftp"); 977 variable_set2(VAR_BROWSER_PACKAGE, PACKAGE_LYNX); 978 variable_set2(VAR_BROWSER_BINARY, "/usr/local/bin/lynx"); 979 variable_set2(VAR_FTP_STATE, "passive"); 980 variable_set2(VAR_NFS_SECURE, "YES"); 981 variable_set2(VAR_PKG_TMPDIR, "/usr/tmp"); 982 variable_set2(VAR_SAMBA_PKG, PACKAGE_SAMBA); 983 variable_set2(VAR_GATED_PKG, PACKAGE_GATED); 984 variable_set2(VAR_PCNFSD_PKG, PACKAGE_PCNFSD); 985 variable_set2(VAR_MEDIA_TIMEOUT, itoa(MEDIA_TIMEOUT)); 986 if (getpid() != 1) 987 variable_set2(SYSTEM_STATE, "update"); 988 else 989 variable_set2(SYSTEM_STATE, "init"); 990 return DITEM_SUCCESS; 991} 992 993/* Load the environment up from various system configuration files */ 994void 995installEnvironment(void) 996{ 997 if (file_readable("/etc/rc.conf")) 998 configEnvironmentRC_conf("/etc/rc.conf"); 999 if (file_readable("/etc/resolv.conf")) 1000 configEnvironmentResolv("/etc/resolv.conf"); 1001} 1002 1003/* Copy the boot floppy contents into /stand */ 1004Boolean 1005copySelf(void) 1006{ 1007 int i; 1008 1009 msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem"); 1010 i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity()); 1011 if (i) { 1012 msgConfirm("Copy returned error status of %d!", i); 1013 return FALSE; 1014 } 1015 1016 /* Copy the /etc files into their rightful place */ 1017 if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) { 1018 msgConfirm("Couldn't copy up the /etc files!"); 1019 return TRUE; 1020 } 1021 return TRUE; 1022} 1023 1024static void 1025create_termcap(void) 1026{ 1027 FILE *fp; 1028 1029 const char *caps[] = { 1030 termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r, 1031 termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m, NULL, 1032 }; 1033 const char **cp; 1034 1035 if (!file_readable(TERMCAP_FILE)) { 1036 Mkdir("/usr/share/misc"); 1037 fp = fopen(TERMCAP_FILE, "w"); 1038 if (!fp) { 1039 msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work."); 1040 return; 1041 } 1042 cp = caps; 1043 while (*cp) 1044 fprintf(fp, "%s\n", *(cp++)); 1045 fclose(fp); 1046 } 1047} 1048 1049#ifdef SAVE_USERCONFIG 1050static void 1051save_userconfig_to_kernel(char *kern) 1052{ 1053 struct kernel *core, *boot; 1054 struct list *c_isa, *b_isa, *c_dev, *b_dev; 1055 int i, d; 1056 1057 if ((core = uc_open("-incore")) == NULL) { 1058 msgDebug("save_userconf: Can't read in-core information for kernel.\n"); 1059 return; 1060 } 1061 1062 if ((boot = uc_open(kern)) == NULL) { 1063 msgDebug("save_userconf: Can't read device information for kernel image %s\n", kern); 1064 return; 1065 } 1066 1067 msgNotify("Saving any boot -c changes to new kernel..."); 1068 c_isa = uc_getdev(core, "-isa"); 1069 b_isa = uc_getdev(boot, "-isa"); 1070 if (isDebug()) 1071 msgDebug("save_userconf: got %d ISA device entries from core, %d from boot.\n", c_isa->ac, b_isa->ac); 1072 for (d = 0; d < c_isa->ac; d++) { 1073 if (isDebug()) 1074 msgDebug("save_userconf: ISA device loop, c_isa->av[%d] = %s\n", d, c_isa->av[d]); 1075 if (strcmp(c_isa->av[d], "npx0")) { /* special case npx0, which mucks with its id_irq member */ 1076 c_dev = uc_getdev(core, c_isa->av[d]); 1077 b_dev = uc_getdev(boot, b_isa->av[d]); 1078 if (!c_dev || !b_dev) { 1079 msgDebug("save_userconf: c_dev: %x b_dev: %x\n", c_dev, b_dev); 1080 continue; 1081 } 1082 if (isDebug()) 1083 msgDebug("save_userconf: ISA device %s: %d config parameters (core), %d (boot)\n", 1084 c_isa->av[d], c_dev->ac, b_dev->ac); 1085 for (i = 0; i < c_dev->ac; i++) { 1086 if (isDebug()) 1087 msgDebug("save_userconf: c_dev->av[%d] = %s, b_dev->av[%d] = %s\n", i, c_dev->av[i], i, b_dev->av[i]); 1088 if (strcmp(c_dev->av[i], b_dev->av[i])) { 1089 if (isDebug()) 1090 msgDebug("save_userconf: %s (boot) -> %s (core)\n", 1091 c_dev->av[i], b_dev->av[i]); 1092 isa_setdev(boot, c_dev); 1093 } 1094 } 1095 } 1096 else { 1097 if (isDebug()) 1098 msgDebug("skipping npx0\n"); 1099 } 1100 } 1101 if (isDebug()) 1102 msgDebug("Closing kernels\n"); 1103 uc_close(core, 0); 1104 uc_close(boot, 1); 1105} 1106#endif 1107