diff --git a/usr.sbin/sysinstall/install.c b/usr.sbin/sysinstall/install.c index cd44a7e5cb6a..5782da6e0edf 100644 --- a/usr.sbin/sysinstall/install.c +++ b/usr.sbin/sysinstall/install.c @@ -1,1292 +1,1291 @@ /* * The new sysinstall program. * * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * * $FreeBSD$ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * verbatim and that no modifications are made prior to this * point in the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include "sysinstall.h" #include #include #include #include #include #include #include #include #include #define MSDOSFS #include #include #include #undef MSDOSFS #include #include #include #include #include #include /* Hack for rsaref package add, which displays interactive license. * Used by package.c */ int _interactiveHack; int FixItMode = 0; int NCpus; static void create_termcap(void); static void fixit_common(void); #define TERMCAP_FILE "/usr/share/misc/termcap" static void installConfigure(void); Boolean checkLabels(Boolean whinge) { Device **devs; Boolean status; Disk *disk; PartInfo *pi; Chunk *c1, *c2; int i; /* Don't allow whinging if noWarn is set */ if (variable_get(VAR_NO_WARN)) whinge = FALSE; status = TRUE; HomeChunk = RootChunk = SwapChunk = NULL; TmpChunk = UsrChunk = VarChunk = NULL; #ifdef __ia64__ EfiChunk = NULL; #endif /* We don't need to worry about root/usr/swap if we're already multiuser */ if (!RunningAsInit) return status; devs = deviceFind(NULL, DEVICE_TYPE_DISK); /* First verify that we have a root device */ for (i = 0; devs[i]; i++) { if (!devs[i]->enabled) continue; disk = (Disk *)devs[i]->private; msgDebug("Scanning disk %s for root filesystem\n", disk->name); if (!disk->chunks) msgFatal("No chunk list found for %s!", disk->name); for (c1 = disk->chunks->part; c1; c1 = c1->next) { #ifdef __ia64__ c2 = c1; #elif defined(__powerpc__) if (c1->type == apple) { for (c2 = c1->part; c2; c2 = c2->next) { #else if (c1->type == freebsd) { for (c2 = c1->part; c2; c2 = c2->next) { #endif pi = (PartInfo *)c2->private_data; if (c2->type == part && c2->subtype != FS_SWAP && pi != NULL) { if (!strcmp(pi->mountpoint, "/")) { if (RootChunk) { if (whinge) msgConfirm("WARNING: You have more than one root device set?!\n" "Using the first one found."); continue; } else { RootChunk = c2; if (isDebug()) msgDebug("Found rootdev at %s!\n", RootChunk->name); } } else if (!strcmp(pi->mountpoint, "/usr")) { if (UsrChunk) { if (whinge) msgConfirm("WARNING: You have more than one /usr filesystem.\n" "Using the first one found."); continue; } else { UsrChunk = c2; if (isDebug()) msgDebug("Found usrdev at %s!\n", UsrChunk->name); } } else if (!strcmp(pi->mountpoint, "/var")) { if (VarChunk) { if (whinge) msgConfirm("WARNING: You have more than one /var filesystem.\n" "Using the first one found."); continue; } else { VarChunk = c2; if (isDebug()) msgDebug("Found vardev at %s!\n", VarChunk->name); } } else if (!strcmp(pi->mountpoint, "/tmp")) { if (TmpChunk) { if (whinge) msgConfirm("WARNING: You have more than one /tmp filesystem.\n" "Using the first one found."); continue; } else { TmpChunk = c2; if (isDebug()) msgDebug("Found tmpdev at %s!\n", TmpChunk->name); } } else if (!strcmp(pi->mountpoint, "/home")) { if (HomeChunk) { if (whinge) msgConfirm("WARNING: You have more than one /home filesystem.\n" "Using the first one found."); continue; } else { HomeChunk = c2; if (isDebug()) msgDebug("Found homedev at %s!\n", HomeChunk->name); } } } #ifndef __ia64__ } } #endif } } /* Now check for swap devices */ for (i = 0; devs[i]; i++) { if (!devs[i]->enabled) continue; disk = (Disk *)devs[i]->private; msgDebug("Scanning disk %s for swap partitions\n", disk->name); if (!disk->chunks) msgFatal("No chunk list found for %s!", disk->name); for (c1 = disk->chunks->part; c1; c1 = c1->next) { #ifdef __ia64__ c2 = c1; #elif defined(__powerpc__) if (c1->type == apple) { for (c2 = c1->part; c2; c2 = c2->next) { #else if (c1->type == freebsd) { for (c2 = c1->part; c2; c2 = c2->next) { #endif if (c2->type == part && c2->subtype == FS_SWAP && !SwapChunk) { SwapChunk = c2; if (isDebug()) msgDebug("Found swapdev at %s!\n", SwapChunk->name); break; } #ifndef __ia64__ } } #endif } } #ifdef __ia64__ for (i = 0; devs[i] != NULL; i++) { if (!devs[i]->enabled) continue; disk = (Disk *)devs[i]->private; for (c1 = disk->chunks->part; c1 != NULL; c1 = c1->next) { pi = (PartInfo *)c1->private_data; if (c1->type == efi && pi != NULL && pi->mountpoint[0] == '/') EfiChunk = c1; } } #endif if (!RootChunk && whinge) { msgConfirm("No root device found - you must label a partition as /\n" "in the label editor."); status = FALSE; } if (!SwapChunk && whinge) { if (msgYesNo("No swap devices found - you should create at least one\n" "swap partition. Without swap, the install will fail\n" "if you do not have enough RAM. Continue anyway?")) status = FALSE; } #ifdef __ia64__ if (EfiChunk == NULL && whinge) { if (msgYesNo("No (mounted) EFI system partition found. Is this what you want?")) status = FALSE; } #endif return status; } static int installInitial(void) { static Boolean alreadyDone = FALSE; int status = DITEM_SUCCESS; if (alreadyDone) return DITEM_SUCCESS; if (!variable_get(DISK_LABELLED)) { msgConfirm("You need to assign disk labels before you can proceed with\n" "the installation."); return DITEM_FAILURE; } /* If it's labelled, assume it's also partitioned */ if (!variable_get(DISK_PARTITIONED)) variable_set2(DISK_PARTITIONED, "yes", 0); /* If we refuse to proceed, bail. */ dialog_clear_norefresh(); if (!variable_get(VAR_NO_WARN)) { if (msgYesNo( "Last Chance! Are you SURE you want continue the installation?\n\n" "If you're running this on a disk with data you wish to save\n" "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n" "proceeding!\n\n" "We can take no responsibility for lost disk contents!") != 0) return DITEM_FAILURE; } if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) { msgConfirm("Couldn't make filesystems properly. Aborting."); return DITEM_FAILURE; } if (!copySelf()) { msgConfirm("installInitial: Couldn't clone the boot floppy onto the\n" "root file system. Aborting!"); return DITEM_FAILURE; } if (!Restarting && chroot("/mnt") == -1) { msgConfirm("installInitial: Unable to chroot to %s - this is bad!", "/mnt"); return DITEM_FAILURE; } chdir("/"); variable_set2(RUNNING_ON_ROOT, "yes", 0); /* Configure various files in /etc */ if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE) status = DITEM_FAILURE; if (DITEM_STATUS(configFstab(NULL)) == DITEM_FAILURE) status = DITEM_FAILURE; /* stick a helpful shell over on the 4th VTY */ if (!variable_get(VAR_NO_HOLOSHELL)) systemCreateHoloshell(); alreadyDone = TRUE; return status; } int installFixitHoloShell(dialogMenuItem *self) { FixItMode = 1; systemCreateHoloshell(); FixItMode = 0; return DITEM_SUCCESS; } int installFixitCDROM(dialogMenuItem *self) { struct stat sb; int need_eject; if (!RunningAsInit) return DITEM_SUCCESS; variable_set2(SYSTEM_STATE, "fixit", 0); (void)unlink("/mnt2"); (void)rmdir("/mnt2"); need_eject = 0; CDROMInitQuiet = 1; while (1) { if (need_eject) msgConfirm( "Please insert a FreeBSD live filesystem CD/DVD and press return"); if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS || !DEVICE_INIT(mediaDevice)) { /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */ mediaClose(); if (need_eject && msgYesNo("Unable to mount the disc. Do you want to try again?") != 0) return DITEM_FAILURE; } else if (!file_readable("/dist/rescue/ldconfig")) { mediaClose(); if (need_eject && msgYesNo("Unable to find a FreeBSD live filesystem. Do you want to try again?") != 0) return DITEM_FAILURE; } else break; CDROMInitQuiet = 0; need_eject = 1; } CDROMInitQuiet = 0; /* Since the fixit code expects everything to be in /mnt2, and the CDROM mounting stuff /dist, do * a little kludge dance here.. */ if (symlink("/dist", "/mnt2")) { msgConfirm("Unable to symlink /mnt2 to the disc mount point. Please report this\n" "unexpected failure to freebsd-bugs@FreeBSD.org."); return DITEM_FAILURE; } /* * If /tmp points to /mnt2/tmp from a previous fixit floppy session, it's * not very good for us if we point it to the CDROM now. Rather make it * a directory in the root MFS then. Experienced admins will still be * able to mount their disk's /tmp over this if they need. */ if (lstat("/tmp", &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFLNK) (void)unlink("/tmp"); Mkdir("/tmp"); /* * Since setuid binaries ignore LD_LIBRARY_PATH, we indeed need the * ld.so.hints file. Fortunately, it's fairly small (~ 3 KB). */ if (!file_readable("/var/run/ld.so.hints")) { Mkdir("/var/run"); if (vsystem("/mnt2/rescue/ldconfig -s /mnt2/lib /mnt2/usr/lib")) { msgConfirm("Warning: ldconfig could not create the ld.so hints file.\n" "Dynamic executables from the disc likely won't work."); } } /* Yet more iggly hardcoded pathnames. */ Mkdir("/libexec"); if (!file_readable("/libexec/ld.so") && file_readable("/mnt2/libexec/ld.so")) { if (symlink("/mnt2/libexec/ld.so", "/libexec/ld.so")) msgDebug("Couldn't link to ld.so - not necessarily a problem for ELF\n"); } if (!file_readable("/libexec/ld-elf.so.1")) { if (symlink("/mnt2/libexec/ld-elf.so.1", "/libexec/ld-elf.so.1")) { msgConfirm("Warning: could not create the symlink for ld-elf.so.1\n" "Dynamic executables from the disc likely won't work."); } } /* optional nicety */ if (!file_readable("/usr/bin/vi")) symlink("/mnt2/usr/bin/vi", "/usr/bin/vi"); fixit_common(); mediaClose(); if (need_eject) msgConfirm("Please remove the FreeBSD fixit CDROM/DVD now."); return DITEM_SUCCESS; } int installFixitFloppy(dialogMenuItem *self) { struct ufs_args args; extern char *distWanted; if (!RunningAsInit) return DITEM_SUCCESS; /* Try to open the floppy drive */ if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) { msgConfirm("Unable to set media device to floppy."); mediaClose(); return DITEM_FAILURE; } memset(&args, 0, sizeof(args)); args.fspec = mediaDevice->devname; mediaDevice->private = "/mnt2"; distWanted = NULL; Mkdir("/mnt2"); variable_set2(SYSTEM_STATE, "fixit", 0); while (1) { if (!DEVICE_INIT(mediaDevice)) { if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n" "or unclean filesystem. Do you want to try again?")) return DITEM_FAILURE; } else break; } if (!directory_exists("/tmp")) (void)symlink("/mnt2/tmp", "/tmp"); fixit_common(); mediaClose(); msgConfirm("Please remove the fixit floppy now."); return DITEM_SUCCESS; } /* * The common code for both fixit variants. */ static void fixit_common(void) { pid_t child; int waitstatus; if (!directory_exists("/var/tmp/vi.recover")) { if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) { msgConfirm("Warning: Was unable to create a /var/tmp/vi.recover directory.\n" "vi will kvetch and moan about it as a result but should still\n" "be essentially usable."); } } if (!directory_exists("/bin")) (void)Mkdir("/bin"); (void)symlink("/stand/sh", "/bin/sh"); /* Link the /etc/ files */ if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS) msgConfirm("Unable to create an /etc directory! Things are weird on this floppy.."); else if ((symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) || (symlink("/mnt2/etc/protocols", "/etc/protocols") == -1 && errno != EEXIST) || (symlink("/mnt2/etc/group", "/etc/group") == -1 && errno != EEXIST) || (symlink("/mnt2/etc/services", "/etc/services") == -1 && errno != EEXIST)) msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this.."); if (!file_readable(TERMCAP_FILE)) create_termcap(); if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) systemSuspendDialog(); /* must be before the fork() */ if (!(child = fork())) { int i, fd; struct termios foo; extern int login_tty(int); ioctl(0, TIOCNOTTY, NULL); for (i = getdtablesize(); i >= 0; --i) close(i); if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) fd = open("/dev/console", O_RDWR); else fd = open("/dev/ttyv3", O_RDWR); ioctl(0, TIOCSCTTY, &fd); dup2(0, 1); dup2(0, 2); DebugFD = 2; if (login_tty(fd) == -1) msgDebug("fixit: I can't set the controlling terminal.\n"); signal(SIGTTOU, SIG_IGN); if (tcgetattr(0, &foo) != -1) { foo.c_cc[VERASE] = '\010'; if (tcsetattr(0, TCSANOW, &foo) == -1) msgDebug("fixit shell: Unable to set erase character.\n"); } else msgDebug("fixit shell: Unable to get terminal attributes!\n"); setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:" "/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin", 1); if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) { printf("Waiting for fixit shell to exit.\n" "When you are done, type ``exit'' to exit\n" "the fixit shell and be returned here.\n\n"); fflush(stdout); } else { ioctl(fd, VT_ACTIVATE, 0); } /* use the .profile from the fixit medium */ setenv("HOME", "/mnt2", 1); chdir("/mnt2"); execlp("sh", "-sh", (char *)0); msgDebug("fixit shell: Failed to execute shell!\n"); _exit(1);; } else { if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) { dialog_clear_norefresh(); msgNotify("Waiting for fixit shell to exit. Go to VTY4 now by\n" "typing ALT-F4. When you are done, type ``exit'' to exit\n" "the fixit shell and be returned here.\n"); } (void)waitpid(child, &waitstatus, 0); if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) systemResumeDialog(); else if (OnVTY) { ioctl(0, VT_ACTIVATE, 0); msgInfo(NULL); } } dialog_clear(); } int installExpress(dialogMenuItem *self) { int i; dialog_clear_norefresh(); variable_set2(SYSTEM_STATE, "express", 0); #ifdef WITH_SLICES if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE) return i; #endif if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE) return i; if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) { i |= DITEM_LEAVE_MENU; /* Give user the option of one last configuration spree */ installConfigure(); } return i; } /* Standard mode installation */ int installStandard(dialogMenuItem *self) { int i, tries = 0; Device **devs; variable_set2(SYSTEM_STATE, "standard", 0); dialog_clear_norefresh(); #ifdef WITH_SLICES msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n" "scheme for your hard disk. If you simply wish to devote all disk space\n" "to FreeBSD (overwriting anything else that might be on the disk(s) selected)\n" "then use the (A)ll command to select the default partitioning scheme followed\n" "by a (Q)uit. If you wish to allocate only free space to FreeBSD, move to a\n" "partition marked \"unused\" and use the (C)reate command."); nodisks: if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE) return DITEM_FAILURE; if (diskGetSelectCount(&devs) <= 0 && tries < 3) { msgConfirm("You need to select some disks to operate on! Be sure to use SPACE\n" "instead of RETURN in the disk selection menu when selecting a disk."); ++tries; goto nodisks; } msgConfirm("Now you need to create BSD partitions inside of the fdisk partition(s)\n" "just created. If you have a reasonable amount of disk space (1GB or more)\n" "and don't have any special requirements, simply use the (A)uto command to\n" "allocate space automatically. If you have more specific needs or just don't\n" "care for the layout chosen by (A)uto, press F1 for more information on\n" "manual layout."); #else msgConfirm("First you need to create BSD partitions on the disk which you are\n" "installing to. If you have a reasonable amount of disk space (1GB or more)\n" "and don't have any special requirements, simply use the (A)uto command to\n" "allocate space automatically. If you have more specific needs or just don't\n" "care for the layout chosen by (A)uto, press F1 for more information on\n" "manual layout."); #endif if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE) return DITEM_FAILURE; if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) { dialog_clear(); msgConfirm("Installation completed with some errors. You may wish to\n" "scroll through the debugging messages on VTY1 with the\n" "scroll-lock feature. You can also choose \"No\" at the next\n" "prompt and go back into the installation menus to retry\n" "whichever operations have failed."); return i; } else { dialog_clear(); msgConfirm("Congratulations! You now have FreeBSD installed on your system.\n\n" "We will now move on to the final configuration questions.\n" "For any option you do not wish to configure, simply select\n" "No.\n\n" "If you wish to re-enter this utility after the system is up, you\n" "may do so by typing: /usr/sbin/sysinstall."); } if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) { if (!msgYesNo("Would you like to configure any Ethernet or SLIP/PPP network devices?")) { Device *tmp = tcpDeviceSelect(); if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) if (!DEVICE_INIT(tmp)) msgConfirm("Initialization of %s device failed.", tmp->name); } dialog_clear_norefresh(); } if (!msgNoYes("Do you want this machine to function as a network gateway?")) variable_set2("gateway_enable", "YES", 1); dialog_clear_norefresh(); if (!msgNoYes("Do you want to configure inetd and the network services that it provides?")) configInetd(self); dialog_clear_norefresh(); if (!msgNoYes("Would you like to enable SSH login?")) variable_set2("sshd_enable", "YES", 1); dialog_clear_norefresh(); if (!msgNoYes("Do you want to have anonymous FTP access to this machine?")) configAnonFTP(self); dialog_clear_norefresh(); if (!msgNoYes("Do you want to configure this machine as an NFS server?")) configNFSServer(self); dialog_clear_norefresh(); if (!msgNoYes("Do you want to configure this machine as an NFS client?")) variable_set2("nfs_client_enable", "YES", 1); #ifdef WITH_SYSCONS dialog_clear_norefresh(); if (!msgNoYes("Would you like to customize your system console settings?")) dmenuOpenSimple(&MenuSyscons, FALSE); #endif dialog_clear_norefresh(); if (!msgYesNo("Would you like to set this machine's time zone now?")) systemExecute("tzsetup"); #ifdef WITH_LINUX dialog_clear_norefresh(); if (!msgYesNo("Would you like to enable Linux binary compatibility?")) (void)configLinux(self); #endif #ifdef __alpha__ dialog_clear_norefresh(); if (!msgYesNo("Would you like to enable OSF/1 binary compatibility?")) (void)configOSF1(self); #endif #ifdef WITH_MICE dialog_clear_norefresh(); if (!msgNoYes("Does this system have a PS/2, serial, or bus mouse?")) dmenuOpenSimple(&MenuMouse, FALSE); #endif #ifdef __i386__ if (checkLoaderACPI() != 0) { dialog_clear_norefresh(); if (!msgNoYes("ACPI was disabled during boot.\n" "Would you like to disable it permanently?")) (void)configLoaderACPI(1 /*disable*/); } #endif /* Now would be a good time to checkpoint the configuration data */ configRC_conf(); sync(); dialog_clear_norefresh(); if (!msgYesNo("The FreeBSD package collection is a collection of thousands of ready-to-run\n" "applications, from text editors to games to WEB servers and more. Would you\n" "like to browse the collection now?")) { (void)configPackages(self); } if (!msgYesNo("Would you like to add any initial user accounts to the system?\n" "Adding at least one account for yourself at this stage is suggested\n" "since working as the \"root\" user is dangerous (it is easy to do\n" "things which adversely affect the entire system).")) (void)configUsers(self); msgConfirm("Now you must set the system manager's password.\n" "This is the password you'll use to log in as \"root\"."); if (!systemExecute("passwd root")) variable_set2("root_password", "YES", 0); /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */ /* Give user the option of one last configuration spree */ dialog_clear_norefresh(); installConfigure(); return DITEM_LEAVE_MENU; } /* The version of commit we call from the Install Custom menu */ int installCustomCommit(dialogMenuItem *self) { int i; i = installCommit(self); if (DITEM_STATUS(i) == DITEM_SUCCESS) { /* Give user the option of one last configuration spree */ installConfigure(); return i; } else msgConfirm("The commit operation completed with errors. Not\n" "updating /etc files."); return i; } /* * What happens when we finally decide to going ahead with the installation. * * This is broken into multiple stages so that the user can do a full * installation but come back here again to load more distributions, * perhaps from a different media type. This would allow, for * example, the user to load the majority of the system from CDROM and * then use ftp to load a different dist. */ int installCommit(dialogMenuItem *self) { int i; char *str; dialog_clear_norefresh(); if (!Dists) distConfig(NULL); if (!Dists) { (void)dmenuOpenSimple(&MenuDistributions, FALSE); /* select reasonable defaults if necessary */ if (!Dists) Dists = _DIST_USER; if (!KernelDists) KernelDists = selectKernel(); } if (!mediaVerify()) return DITEM_FAILURE; str = variable_get(SYSTEM_STATE); if (isDebug()) msgDebug("installCommit: System state is `%s'\n", str); /* Installation stuff we wouldn't do to a running system */ if (RunningAsInit && DITEM_STATUS((i = installInitial())) == DITEM_FAILURE) return i; try_media: if (!DEVICE_INIT(mediaDevice)) { if (!msgYesNo("Unable to initialize selected media. Would you like to\n" "adjust your media configuration and try again?")) { mediaDevice = NULL; if (!mediaVerify()) return DITEM_FAILURE; else goto try_media; } else return DITEM_FAILURE; } /* Now go get it all */ i = distExtractAll(self); /* When running as init, *now* it's safe to grab the rc.foo vars */ installEnvironment(); variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install", 0); return i; } static void installConfigure(void) { /* Final menu of last resort */ if (!msgNoYes("Visit the general configuration menu for a chance to set\n" "any last options?")) dmenuOpenSimple(&MenuConfigure, FALSE); configRC_conf(); sync(); } int installFixupBase(dialogMenuItem *self) { FILE *fp; #ifdef __ia64__ const char *efi_mntpt; #endif /* All of this is done only as init, just to be safe */ if (RunningAsInit) { #if defined(__i386__) || defined(__amd64__) if ((fp = fopen("/boot/loader.conf", "a")) != NULL) { if (!OnVTY) { fprintf(fp, "# -- sysinstall generated deltas -- #\n"); fprintf(fp, "console=\"comconsole\"\n"); } fclose(fp); } #endif /* BOGON #2: We leave /etc in a bad state */ chmod("/etc", 0755); /* BOGON #3: No /var/db/mountdtab complains */ Mkdir("/var/db"); creat("/var/db/mountdtab", 0644); /* BOGON #4: /compat created by default in root fs */ Mkdir("/usr/compat"); vsystem("ln -s usr/compat /compat"); /* BOGON #5: aliases database not built for bin */ vsystem("newaliases"); /* BOGON #6: Remove /stand (finally) */ vsystem("rm -rf /stand"); /* Now run all the mtree stuff to fix things up */ vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /"); vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var"); vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr"); #ifdef __ia64__ /* Move /boot to the the EFI partition and make /boot a link to it. */ efi_mntpt = (EfiChunk != NULL) ? ((PartInfo *)EfiChunk->private_data)->mountpoint : NULL; if (efi_mntpt != NULL) { vsystem("if [ ! -L /boot ]; then mv /boot %s; fi", efi_mntpt); vsystem("if [ ! -e /boot ]; then ln -sf %s/boot /boot; fi", efi_mntpt + 1); /* Skip leading '/' */ /* Make sure the kernel knows which partition is the root file system. */ vsystem("echo 'vfs.root.mountfrom=\"ufs:/dev/%s\"' >> /boot/loader.conf", RootChunk->name); } #endif /* Do all the last ugly work-arounds here */ } return DITEM_SUCCESS | DITEM_RESTORE; } int installFixupKernel(dialogMenuItem *self, int dists) { /* All of this is done only as init, just to be safe */ if (RunningAsInit) { /* * Install something as /boot/kernel. Prefer SMP * over generic--this should handle the case where * both SMP and GENERIC are installed (otherwise we * select the one kernel that was installed). * * NB: we assume any existing kernel has been saved * already and the /boot/kernel we remove is empty. */ vsystem("rm -rf /boot/kernel"); #if WITH_SMP if (dists & DIST_KERNEL_SMP) vsystem("mv /boot/SMP /boot/kernel"); else #endif vsystem("mv /boot/GENERIC /boot/kernel"); } return DITEM_SUCCESS | DITEM_RESTORE; } #define QUEUE_YES 1 #define QUEUE_NO 0 static int performNewfs(PartInfo *pi, char *dname, int queue) { char buffer[LINE_MAX]; if (pi->do_newfs) { switch(pi->newfs_type) { case NEWFS_UFS: snprintf(buffer, LINE_MAX, "%s %s %s %s %s", NEWFS_UFS_CMD, pi->newfs_data.newfs_ufs.softupdates ? "-U" : "", pi->newfs_data.newfs_ufs.ufs1 ? "-O1" : "-O2", pi->newfs_data.newfs_ufs.user_options, dname); break; case NEWFS_MSDOS: snprintf(buffer, LINE_MAX, "%s %s", NEWFS_MSDOS_CMD, dname); break; case NEWFS_CUSTOM: snprintf(buffer, LINE_MAX, "%s %s", pi->newfs_data.newfs_custom.command, dname); break; } if (queue == QUEUE_YES) { command_shell_add(pi->mountpoint, buffer); return (0); } else return (vsystem(buffer)); } return (0); } /* Go newfs and/or mount all the filesystems we've been asked to */ int installFilesystems(dialogMenuItem *self) { int i; Disk *disk; Chunk *c1, *c2; Device **devs; PartInfo *root; char dname[80]; Boolean upgrade = FALSE; /* If we've already done this, bail out */ if (!variable_cmp(DISK_LABELLED, "written")) return DITEM_SUCCESS; upgrade = !variable_cmp(SYSTEM_STATE, "upgrade"); if (!checkLabels(TRUE)) return DITEM_FAILURE; root = (RootChunk != NULL) ? (PartInfo *)RootChunk->private_data : NULL; command_clear(); if (SwapChunk && RunningAsInit) { /* As the very first thing, try to get ourselves some swap space */ sprintf(dname, "/dev/%s", SwapChunk->name); if (!Fake && !file_readable(dname)) { msgConfirm("Unable to find device node for %s in /dev!\n" "The creation of filesystems will be aborted.", dname); return DITEM_FAILURE; } if (!Fake) { if (!swapon(dname)) { dialog_clear_norefresh(); msgNotify("Added %s as initial swap device", dname); } else { msgConfirm("WARNING! Unable to swap to %s: %s\n" "This may cause the installation to fail at some point\n" "if you don't have a lot of memory.", dname, strerror(errno)); } } } if (RootChunk && RunningAsInit) { /* Next, create and/or mount the root device */ sprintf(dname, "/dev/%s", RootChunk->name); if (!Fake && !file_readable(dname)) { msgConfirm("Unable to make device node for %s in /dev!\n" "The creation of filesystems will be aborted.", dname); return DITEM_FAILURE | DITEM_RESTORE; } if (strcmp(root->mountpoint, "/")) msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", RootChunk->name, root->mountpoint); if (root->do_newfs && (!upgrade || !msgNoYes("You are upgrading - are you SURE you want to newfs " "the root partition?"))) { int i; dialog_clear_norefresh(); msgNotify("Making a new root filesystem on %s", dname); i = performNewfs(root, dname, QUEUE_NO); if (i) { msgConfirm("Unable to make new root filesystem on %s!\n" "Command returned status %d", dname, i); return DITEM_FAILURE | DITEM_RESTORE; } } else { if (!upgrade) { msgConfirm("Warning: Using existing root partition."); } dialog_clear_norefresh(); msgNotify("Checking integrity of existing %s filesystem.", dname); i = vsystem("fsck_ffs -y %s", dname); if (i) msgConfirm("Warning: fsck returned status of %d for %s.\n" "This partition may be unsafe to use.", i, dname); } /* * If soft updates was enabled in the editor but we didn't newfs, * use tunefs to update the soft updates flag on the file system. */ if (!root->do_newfs && root->newfs_type == NEWFS_UFS && root->newfs_data.newfs_ufs.softupdates) { i = vsystem("tunefs -n enable %s", dname); if (i) msgConfirm("Warning: Unable to enable soft updates" " for root file system on %s", dname); } /* Switch to block device */ sprintf(dname, "/dev/%s", RootChunk->name); if (Mount("/mnt", dname)) { msgConfirm("Unable to mount the root file system on %s! Giving up.", dname); return DITEM_FAILURE | DITEM_RESTORE; } /* Mount devfs for other partitions to mount */ Mkdir("/mnt/dev"); if (!Fake) { struct iovec iov[4]; iov[0].iov_base = "fstype"; iov[0].iov_len = strlen(iov[0].iov_base) + 1; iov[1].iov_base = "devfs"; iov[1].iov_len = strlen(iov[1].iov_base) + 1; iov[2].iov_base = "fspath"; iov[2].iov_len = strlen(iov[2].iov_base) + 1; iov[3].iov_base = "/mnt/dev"; iov[3].iov_len = strlen(iov[3].iov_base) + 1; i = nmount(iov, 4, 0); if (i) { dialog_clear_norefresh(); msgConfirm("Unable to mount DEVFS (error %d)", errno); return DITEM_FAILURE | DITEM_RESTORE; } } } /* Now buzz through the rest of the partitions and mount them too */ devs = deviceFind(NULL, DEVICE_TYPE_DISK); for (i = 0; devs[i]; i++) { if (!devs[i]->enabled) continue; disk = (Disk *)devs[i]->private; if (!disk->chunks) { msgConfirm("No chunk list found for %s!", disk->name); return DITEM_FAILURE | DITEM_RESTORE; } for (c1 = disk->chunks->part; c1; c1 = c1->next) { #ifdef __ia64__ if (c1->type == part) { c2 = c1; { #elif defined(__powerpc__) if (c1->type == apple) { for (c2 = c1->part; c2; c2 = c2->next) { #else if (c1->type == freebsd) { for (c2 = c1->part; c2; c2 = c2->next) { #endif if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { PartInfo *tmp = (PartInfo *)c2->private_data; /* Already did root */ if (c2 == RootChunk) continue; sprintf(dname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name); if (tmp->do_newfs && (!upgrade || !msgNoYes("You are upgrading - are you SURE you" " want to newfs /dev/%s?", c2->name))) performNewfs(tmp, dname, QUEUE_YES); else command_shell_add(tmp->mountpoint, "fsck_ffs -y %s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name); #if 0 if (tmp->soft) command_shell_add(tmp->mountpoint, "tunefs -n enable %s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name); #endif command_func_add(tmp->mountpoint, Mount, c2->name); } else if (c2->type == part && c2->subtype == FS_SWAP) { char fname[80]; int i; if (c2 == SwapChunk) continue; sprintf(fname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name); i = (Fake || swapon(fname)); if (!i) { dialog_clear_norefresh(); msgNotify("Added %s as an additional swap device", fname); } else { msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno)); } } } } else if (c1->type == fat && c1->private_data && (root->do_newfs || upgrade)) { char name[FILENAME_MAX]; sprintf(name, "%s/%s", RunningAsInit ? "/mnt" : "", ((PartInfo *)c1->private_data)->mountpoint); Mkdir(name); } #if defined(__ia64__) else if (c1->type == efi && c1->private_data) { char bootdir[FILENAME_MAX]; PartInfo *pi = (PartInfo *)c1->private_data; char *p; sprintf(dname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c1->name); if (pi->do_newfs && (!upgrade || !msgNoYes("You are upgrading - are you SURE you want to " "newfs /dev/%s?", c1->name))) performNewfs(pi, dname, QUEUE_YES); command_func_add(pi->mountpoint, Mount_msdosfs, c1->name); } #endif } } command_sort(); command_execute(); dialog_clear_norefresh(); return DITEM_SUCCESS | DITEM_RESTORE; } /* Initialize various user-settable values to their defaults */ int installVarDefaults(dialogMenuItem *self) { char *cp, ncpus[10]; /* Set default startup options */ cp = getsysctlbyname("kern.osrelease"); variable_set2(VAR_RELNAME, cp, 0); free(cp); variable_set2(VAR_CPIO_VERBOSITY, "high", 0); - variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE, 0); variable_set2(VAR_INSTALL_ROOT, "/", 0); variable_set2(VAR_INSTALL_CFG, "install.cfg", 0); variable_set2(VAR_SKIP_PCCARD, "NO", 0); cp = getenv("EDITOR"); if (!cp) cp = "/usr/bin/ee"; variable_set2(VAR_EDITOR, cp, 0); variable_set2(VAR_FTP_USER, "ftp", 0); variable_set2(VAR_BROWSER_PACKAGE, "links", 0); variable_set2(VAR_BROWSER_BINARY, "/usr/local/bin/links", 0); variable_set2(VAR_FTP_STATE, "passive", 0); variable_set2(VAR_NFS_SECURE, "NO", -1); variable_set2(VAR_NFS_TCP, "NO", -1); variable_set2(VAR_NFS_V3, "YES", -1); if (OnVTY) variable_set2(VAR_FIXIT_TTY, "standard", 0); else variable_set2(VAR_FIXIT_TTY, "serial", 0); variable_set2(VAR_PKG_TMPDIR, "/var/tmp", 0); variable_set2(VAR_MEDIA_TIMEOUT, itoa(MEDIA_TIMEOUT), 0); if (getpid() != 1) variable_set2(SYSTEM_STATE, "update", 0); else variable_set2(SYSTEM_STATE, "init", 0); variable_set2(VAR_NEWFS_ARGS, "-b 16384 -f 2048", 0); variable_set2(VAR_CONSTERM, "NO", 0); #if (defined(__i386__) && !defined(PC98)) || defined(__amd64__) NCpus = acpi_detect(); if (NCpus == -1) NCpus = biosmptable_detect(); #endif if (NCpus <= 0) NCpus = 1; snprintf(ncpus, sizeof(ncpus), "%u", NCpus); variable_set2(VAR_NCPUS, ncpus, 0); return DITEM_SUCCESS; } /* Load the environment up from various system configuration files */ void installEnvironment(void) { configEnvironmentRC_conf(); if (file_readable("/etc/resolv.conf")) configEnvironmentResolv("/etc/resolv.conf"); } /* Copy the boot floppy contents into /stand */ Boolean copySelf(void) { int i; if (file_readable("/boot.help")) vsystem("cp /boot.help /mnt"); msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem"); i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity()); if (i) { msgConfirm("Copy returned error status of %d!", i); return FALSE; } /* Copy the /etc files into their rightful place */ if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) { msgConfirm("Couldn't copy up the /etc files!"); return TRUE; } return TRUE; } static void create_termcap(void) { FILE *fp; const char *caps[] = { termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r, termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m, termcap_xterm, NULL, }; const char **cp; if (!file_readable(TERMCAP_FILE)) { Mkdir("/usr/share/misc"); fp = fopen(TERMCAP_FILE, "w"); if (!fp) { msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work."); return; } cp = caps; while (*cp) fprintf(fp, "%s\n", *(cp++)); fclose(fp); } } diff --git a/usr.sbin/sysinstall/media.c b/usr.sbin/sysinstall/media.c index c9a74cacafc4..5af902ab204c 100644 --- a/usr.sbin/sysinstall/media.c +++ b/usr.sbin/sysinstall/media.c @@ -1,889 +1,889 @@ /* * The new sysinstall program. * * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * * $FreeBSD$ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * verbatim and that no modifications are made prior to this * point in the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include "sysinstall.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include static Boolean got_intr = FALSE; static Boolean ftp_skip_resolve = FALSE; /* timeout handler */ static void handle_intr(int sig) { msgDebug("User generated interrupt.\n"); got_intr = TRUE; } static int check_for_interrupt(void) { if (got_intr) { got_intr = FALSE; return TRUE; } return FALSE; } static int genericHook(dialogMenuItem *self, DeviceType type) { Device **devs; devs = deviceFind(self->prompt, type); if (devs) mediaDevice = devs[0]; return (devs ? DITEM_LEAVE_MENU : DITEM_FAILURE); } static int cdromHook(dialogMenuItem *self) { return genericHook(self, DEVICE_TYPE_CDROM); } static void kickstart_dns(void) { static Boolean initted = FALSE; int time; char *cp; cp = variable_get(VAR_MEDIA_TIMEOUT); if (!cp) time = MEDIA_TIMEOUT; else time = atoi(cp); if (!time) time = 100; if (!initted) { res_init(); _res.retry = 2; /* 2 times seems a reasonable number to me */ _res.retrans = time / 2; /* so spend half our alloted time on each try */ initted = TRUE; } } char * cpioVerbosity() { char *cp = variable_get(VAR_CPIO_VERBOSITY); if (cp && !strcmp(cp, "high")) return "-v"; else if (cp && !strcmp(cp, "medium")) return "-V"; return ""; } int mediaOpen(void) { if (!mediaDevice || !mediaVerify() || !DEVICE_INIT(mediaDevice)) return DITEM_FAILURE; return DITEM_SUCCESS; } void mediaClose(void) { if (mediaDevice) DEVICE_SHUTDOWN(mediaDevice); mediaDevice = NULL; } /* * Return 1 if we successfully found and set the installation type to * be a CD. */ int mediaSetCDROM(dialogMenuItem *self) { Device **devs; int cnt; mediaClose(); devs = deviceFind(NULL, DEVICE_TYPE_CDROM); cnt = deviceCount(devs); if (!cnt) { if (self) /* Interactive? */ msgConfirm("No CD/DVD devices found! Please check that your system's\n" "configuration is correct and that the CD/DVD drive is of a supported\n" "type. For more information, consult the hardware guide\n" "in the Doc menu."); return DITEM_FAILURE | DITEM_CONTINUE; } else if (cnt > 1) { DMenu *menu; int status; menu = deviceCreateMenu(&MenuMediaCDROM, DEVICE_TYPE_CDROM, cdromHook, NULL); if (!menu) msgFatal("Unable to create CDROM menu! Something is seriously wrong."); status = dmenuOpenSimple(menu, FALSE); free(menu); if (!status) return DITEM_FAILURE; } else mediaDevice = devs[0]; return (mediaDevice ? DITEM_SUCCESS | DITEM_LEAVE_MENU : DITEM_FAILURE); } static int floppyHook(dialogMenuItem *self) { return genericHook(self, DEVICE_TYPE_FLOPPY); } /* * Return 1 if we successfully found and set the installation type to * be a floppy */ int mediaSetFloppy(dialogMenuItem *self) { Device **devs; int cnt; mediaClose(); devs = deviceFind(NULL, DEVICE_TYPE_FLOPPY); cnt = deviceCount(devs); if (!cnt) { msgConfirm("No floppy devices found! Please check that your system's configuration\n" "is correct. For more information, consult the hardware guide in the Doc\n" "menu."); return DITEM_FAILURE | DITEM_CONTINUE; } else if (cnt > 1) { DMenu *menu; int status; menu = deviceCreateMenu(&MenuMediaFloppy, DEVICE_TYPE_FLOPPY, floppyHook, NULL); if (!menu) msgFatal("Unable to create Floppy menu! Something is seriously wrong."); status = dmenuOpenSimple(menu, FALSE); free(menu); if (!status) return DITEM_FAILURE; } else mediaDevice = devs[0]; if (mediaDevice) mediaDevice->private = NULL; return (mediaDevice ? DITEM_LEAVE_MENU : DITEM_FAILURE); } static int DOSHook(dialogMenuItem *self) { return genericHook(self, DEVICE_TYPE_DOS); } /* * Return 1 if we successfully found and set the installation type to * be a DOS partition. */ int mediaSetDOS(dialogMenuItem *self) { Device **devs; int cnt; mediaClose(); devs = deviceFind(NULL, DEVICE_TYPE_DOS); cnt = deviceCount(devs); if (!cnt) { msgConfirm("No DOS primary partitions found! This installation method is unavailable"); return DITEM_FAILURE | DITEM_CONTINUE; } else if (cnt > 1) { DMenu *menu; int status; menu = deviceCreateMenu(&MenuMediaDOS, DEVICE_TYPE_DOS, DOSHook, NULL); if (!menu) msgFatal("Unable to create DOS menu! Something is seriously wrong."); status = dmenuOpenSimple(menu, FALSE); free(menu); if (!status) return DITEM_FAILURE; } else mediaDevice = devs[0]; return (mediaDevice ? DITEM_LEAVE_MENU : DITEM_FAILURE); } static int tapeHook(dialogMenuItem *self) { return genericHook(self, DEVICE_TYPE_TAPE); } /* * Return 1 if we successfully found and set the installation type to * be a tape drive. */ int mediaSetTape(dialogMenuItem *self) { Device **devs; int cnt; mediaClose(); devs = deviceFind(NULL, DEVICE_TYPE_TAPE); cnt = deviceCount(devs); if (!cnt) { msgConfirm("No tape drive devices found! Please check that your system's configuration\n" "is correct. For more information, consult the hardware guide in the Doc\n" "menu."); return DITEM_FAILURE | DITEM_CONTINUE; } else if (cnt > 1) { DMenu *menu; int status; menu = deviceCreateMenu(&MenuMediaTape, DEVICE_TYPE_TAPE, tapeHook, NULL); if (!menu) msgFatal("Unable to create tape drive menu! Something is seriously wrong."); status = dmenuOpenSimple(menu, FALSE); free(menu); if (!status) return DITEM_FAILURE; } else mediaDevice = devs[0]; if (mediaDevice) { char *val; val = msgGetInput("/var/tmp", "Please enter the name of a temporary directory containing\n" "sufficient space for holding the contents of this tape (or\n" "tapes). The contents of this directory will be removed\n" "after installation, so be sure to specify a directory that\n" "can be erased afterwards!\n"); if (!val) mediaDevice = NULL; else mediaDevice->private = strdup(val); } return (mediaDevice ? DITEM_LEAVE_MENU : DITEM_FAILURE); } /* * Return 0 if we successfully found and set the installation type to * be an ftp server */ int mediaSetFTP(dialogMenuItem *self) { static Device ftpDevice; char *cp, hbuf[MAXHOSTNAMELEN], *hostname, *dir; struct addrinfo hints, *res; int af; size_t urllen; extern int FtpPort; static Device *networkDev = NULL; mediaClose(); cp = variable_get(VAR_FTP_PATH); /* If we've been through here before ... */ if (networkDev && cp && msgYesNo("Re-use old FTP site selection values?")) cp = NULL; if (!cp) { if (!dmenuOpenSimple(&MenuMediaFTP, FALSE)) return DITEM_FAILURE; else cp = variable_get(VAR_FTP_PATH); } if (!cp) return DITEM_FAILURE; else if (!strcmp(cp, "other")) { variable_set2(VAR_FTP_PATH, "ftp://", 0); cp = variable_get_value(VAR_FTP_PATH, "Please specify the URL of a FreeBSD distribution on a\n" "remote ftp site. This site must accept either anonymous\n" "ftp or you should have set an ftp username and password\n" "in the Options screen.\n\n" "A URL looks like this: ftp:///\n" "Where is relative to the anonymous ftp directory or the\n" "home directory of the user being logged in as.", 0); if (!cp || !*cp || !strcmp(cp, "ftp://")) { variable_unset(VAR_FTP_PATH); return DITEM_FAILURE; } urllen = strlen(cp); if (urllen >= sizeof(ftpDevice.name)) { msgConfirm("Length of specified URL is %d characters. Allowable maximum is %d.", urllen,sizeof(ftpDevice.name)-1); variable_unset(VAR_FTP_PATH); return DITEM_FAILURE; } } if (strncmp("ftp://", cp, 6)) { msgConfirm("Sorry, %s is an invalid URL!", cp); variable_unset(VAR_FTP_PATH); return DITEM_FAILURE; } SAFE_STRCPY(ftpDevice.name, cp); SAFE_STRCPY(hbuf, cp + 6); hostname = hbuf; if (!networkDev || msgYesNo("You've already done the network configuration once,\n" "would you like to skip over it now?") != 0) { if (networkDev) DEVICE_SHUTDOWN(networkDev); if (!(networkDev = tcpDeviceSelect())) { variable_unset(VAR_FTP_PATH); return DITEM_FAILURE; } } if (!DEVICE_INIT(networkDev)) { if (isDebug()) msgDebug("mediaSetFTP: Net device init failed.\n"); variable_unset(VAR_FTP_PATH); return DITEM_FAILURE; } if (*hostname == '[' && (cp = index(hostname + 1, ']')) != NULL && (*++cp == '\0' || *cp == '/' || *cp == ':')) { ++hostname; *(cp - 1) = '\0'; } else cp = index(hostname, ':'); if (cp != NULL && *cp == ':') { *(cp++) = '\0'; FtpPort = strtol(cp, 0, 0); } else FtpPort = 21; if ((dir = index(cp ? cp : hostname, '/')) != NULL) *(dir++) = '\0'; if (isDebug()) { msgDebug("hostname = `%s'\n", hostname); msgDebug("dir = `%s'\n", dir ? dir : "/"); msgDebug("port # = `%d'\n", FtpPort); } if (!ftp_skip_resolve && variable_get(VAR_NAMESERVER)) { msgNotify("Looking up host %s.", hostname); if (isDebug()) msgDebug("Starting DNS.\n"); kickstart_dns(); if (isDebug()) msgDebug("Looking up hostname, %s, using getaddrinfo(AI_NUMERICHOST).\n", hostname); af = variable_cmp(VAR_IPV6_ENABLE, "YES") ? AF_INET : AF_UNSPEC; memset(&hints, 0, sizeof(hints)); hints.ai_family = af; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; if (getaddrinfo(hostname, NULL, &hints, &res) != 0) { if (isDebug()) msgDebug("Looking up hostname, %s, using getaddrinfo().\n", hostname); hints.ai_flags = AI_PASSIVE; if (getaddrinfo(hostname, NULL, &hints, &res) != 0) { msgConfirm("Cannot resolve hostname `%s'! Are you sure that" " your\nname server, gateway and network interface are" " correctly configured?", hostname); if (networkDev) DEVICE_SHUTDOWN(networkDev); networkDev = NULL; variable_unset(VAR_FTP_PATH); return DITEM_FAILURE; } } freeaddrinfo(res); if (isDebug()) msgDebug("Found DNS entry for %s successfully..\n", hostname); } variable_set2(VAR_FTP_HOST, hostname, 0); variable_set2(VAR_FTP_DIR, dir ? dir : "/", 0); variable_set2(VAR_FTP_PORT, itoa(FtpPort), 0); ftpDevice.type = DEVICE_TYPE_FTP; ftpDevice.init = mediaInitFTP; ftpDevice.get = mediaGetFTP; ftpDevice.shutdown = mediaShutdownFTP; ftpDevice.private = networkDev; mediaDevice = &ftpDevice; return DITEM_SUCCESS | DITEM_LEAVE_MENU | DITEM_RESTORE; } int mediaSetFTPActive(dialogMenuItem *self) { variable_set2(VAR_FTP_STATE, "active", 0); return mediaSetFTP(self); } int mediaSetFTPPassive(dialogMenuItem *self) { variable_set2(VAR_FTP_STATE, "passive", 0); return mediaSetFTP(self); } int mediaSetHTTP(dialogMenuItem *self) { Boolean tmp; int result; char *cp, *idx, hbuf[MAXHOSTNAMELEN], *hostname; int HttpPort; int what = DITEM_RESTORE; tmp = ftp_skip_resolve; ftp_skip_resolve = TRUE; result = mediaSetFTP(self); ftp_skip_resolve = tmp; if (DITEM_STATUS(result) != DITEM_SUCCESS) return result; cp = variable_get_value(VAR_HTTP_PROXY, "Please enter the address of the HTTP proxy in this format:\n" " hostname:port (the ':port' is optional, default is 3128)",0); if (!cp) return DITEM_FAILURE; SAFE_STRCPY(hbuf, cp); hostname = hbuf; if (*hostname == '[' && (idx = index(hostname + 1, ']')) != NULL && (*++idx == '\0' || *idx == ':')) { ++hostname; *(idx - 1) = '\0'; } else idx = index(hostname, ':'); if (idx == NULL || *idx != ':') HttpPort = 3128; /* try this as default */ else { *(idx++) = '\0'; HttpPort = strtol(idx, 0, 0); } variable_set2(VAR_HTTP_HOST, hostname, 0); variable_set2(VAR_HTTP_PORT, itoa(HttpPort), 0); if (isDebug()) { msgDebug("VAR_FTP_PATH : %s\n",variable_get(VAR_FTP_PATH)); msgDebug("VAR_HTTP_HOST, _PORT: %s:%s\n",variable_get(VAR_HTTP_HOST), variable_get(VAR_HTTP_PORT)); } /* mediaDevice has been set by mediaSetFTP(), overwrite partly: */ mediaDevice->type = DEVICE_TYPE_HTTP; mediaDevice->init = mediaInitHTTP; mediaDevice->get = mediaGetHTTP; mediaDevice->shutdown = dummyShutdown; return DITEM_SUCCESS | DITEM_LEAVE_MENU | what; } int mediaSetUFS(dialogMenuItem *self) { static Device ufsDevice; struct statfs st; char *cp; mediaClose(); cp = variable_get_value(VAR_UFS_PATH, "Enter a fully qualified pathname for the directory\n" "containing the FreeBSD distribution files:", 0); if (!cp) return DITEM_FAILURE; /* If they gave us a CDROM or something, try and pick a better name */ if (statfs(cp, &st)) strcpy(ufsDevice.name, "ufs"); else strcpy(ufsDevice.name, st.f_fstypename); ufsDevice.type = DEVICE_TYPE_UFS; ufsDevice.init = dummyInit; ufsDevice.get = mediaGetUFS; ufsDevice.shutdown = dummyShutdown; ufsDevice.private = strdup(cp); mediaDevice = &ufsDevice; return DITEM_LEAVE_MENU; } int mediaSetNFS(dialogMenuItem *self) { static Device nfsDevice; static Device *networkDev = NULL; char *cp, *idx; char hostname[MAXPATHLEN]; size_t pathlen; mediaClose(); cp = variable_get_value(VAR_NFS_PATH, "Please enter the full NFS file specification for the remote\n" "host and directory containing the FreeBSD distribution files.\n" "This should be in the format: hostname:/some/freebsd/dir", 0); if (!cp) return DITEM_FAILURE; SAFE_STRCPY(hostname, cp); if (!(idx = index(hostname, ':'))) { msgConfirm("Invalid NFS path specification. Must be of the form:\n" "host:/full/pathname/to/FreeBSD/distdir"); return DITEM_FAILURE; } pathlen = strlen(hostname); if (pathlen >= sizeof(nfsDevice.name)) { msgConfirm("Length of specified NFS path is %d characters. Allowable maximum is %d.", pathlen,sizeof(nfsDevice.name)-1); variable_unset(VAR_NFS_PATH); return DITEM_FAILURE; } SAFE_STRCPY(nfsDevice.name, hostname); *idx = '\0'; if (!networkDev || msgYesNo("You've already done the network configuration once,\n" "would you like to skip over it now?") != 0) { if (networkDev) DEVICE_SHUTDOWN(networkDev); if (!(networkDev = tcpDeviceSelect())) return DITEM_FAILURE; } if (!DEVICE_INIT(networkDev)) { if (isDebug()) msgDebug("mediaSetNFS: Net device init failed\n"); } if (variable_get(VAR_NAMESERVER)) { kickstart_dns(); if ((inet_addr(hostname) == INADDR_NONE) && (gethostbyname(hostname) == NULL)) { msgConfirm("Cannot resolve hostname `%s'! Are you sure that your\n" "name server, gateway and network interface are correctly configured?", hostname); if (networkDev) DEVICE_SHUTDOWN(networkDev); networkDev = NULL; variable_unset(VAR_NFS_PATH); return DITEM_FAILURE; } else { if (isDebug()) msgDebug("Found DNS entry for %s successfully..\n", hostname); } } variable_set2(VAR_NFS_HOST, hostname, 0); nfsDevice.type = DEVICE_TYPE_NFS; nfsDevice.init = mediaInitNFS; nfsDevice.get = mediaGetNFS; nfsDevice.shutdown = mediaShutdownNFS; nfsDevice.private = networkDev; mediaDevice = &nfsDevice; return DITEM_LEAVE_MENU; } Boolean mediaExtractDistBegin(char *dir, int *fd, int *zpid, int *cpid) { int i, pfd[2],qfd[2]; if (!dir) dir = "/"; Mkdir(dir); chdir(dir); pipe(pfd); pipe(qfd); *zpid = fork(); if (!*zpid) { char *unzipper = RunningAsInit ? "/stand/" UNZIPPER : "/usr/bin/" UNZIPPER; dup2(qfd[0], 0); close(qfd[0]); dup2(pfd[1], 1); close(pfd[1]); if (DebugFD != -1) dup2(DebugFD, 2); else { close(2); open("/dev/null", O_WRONLY); } close(qfd[1]); close(pfd[0]); i = execl(unzipper, unzipper, (char *)0); if (isDebug()) msgDebug("%s command returns %d status\n", unzipper, i); exit(i); } *fd = qfd[1]; close(qfd[0]); *cpid = fork(); if (!*cpid) { char *cpio = RunningAsInit ? "/stand/cpio" : "/usr/bin/cpio"; dup2(pfd[0], 0); close(pfd[0]); close(pfd[1]); close(qfd[1]); if (DebugFD != -1) { dup2(DebugFD, 1); dup2(DebugFD, 2); } else { close(1); open("/dev/null", O_WRONLY); dup2(1, 2); } if (strlen(cpioVerbosity())) - i = execl(cpio, cpio, "-idum", cpioVerbosity(), "--block-size", mediaTapeBlocksize(), (char *)0); + i = execl(cpio, cpio, "-idum", cpioVerbosity(), (char *)0); else - i = execl(cpio, cpio, "-idum", "--block-size", mediaTapeBlocksize(), (char *)0); + i = execl(cpio, cpio, "-idum", (char *)0); if (isDebug()) msgDebug("%s command returns %d status\n", cpio, i); exit(i); } close(pfd[0]); close(pfd[1]); return TRUE; } Boolean mediaExtractDistEnd(int zpid, int cpid) { int i,j; i = waitpid(zpid, &j, 0); /* Don't check exit status - gunzip seems to return a bogus one! */ if (i < 0) { if (isDebug()) msgDebug("wait for %s returned status of %d!\n", UNZIPPER, i); return FALSE; } i = waitpid(cpid, &j, 0); if (i < 0 || WEXITSTATUS(j)) { if (isDebug()) msgDebug("cpio returned error status of %d!\n", WEXITSTATUS(j)); return FALSE; } return TRUE; } Boolean mediaExtractDist(char *dir, char *dist, FILE *fp) { int i, j, total, seconds, zpid, cpid, pfd[2], qfd[2]; char buf[BUFSIZ]; struct timeval start, stop; struct sigaction new, old; if (!dir) dir = "/"; Mkdir(dir); chdir(dir); pipe(pfd); /* read end */ pipe(qfd); /* write end */ zpid = fork(); if (!zpid) { char *unzipper = RunningAsInit ? "/stand/" UNZIPPER : "/usr/bin/" UNZIPPER; fclose(fp); close(qfd[1]); dup2(qfd[0], 0); close(qfd[0]); close(pfd[0]); dup2(pfd[1], 1); close(pfd[1]); if (DebugFD != -1) dup2(DebugFD, 2); else { close(2); open("/dev/null", O_WRONLY); } i = execl(unzipper, unzipper, (char *)0); if (isDebug()) msgDebug("%s command returns %d status\n", unzipper, i); exit(i); } cpid = fork(); if (!cpid) { char *cpio = RunningAsInit ? "/stand/cpio" : "/usr/bin/cpio"; close(pfd[1]); dup2(pfd[0], 0); close(pfd[0]); close (qfd[0]); close(qfd[1]); fclose(fp); if (DebugFD != -1) { dup2(DebugFD, 1); dup2(DebugFD, 2); } else { dup2(open("/dev/null", O_WRONLY), 1); dup2(1, 2); } if (strlen(cpioVerbosity())) - i = execl(cpio, cpio, "-idum", cpioVerbosity(), "--block-size", mediaTapeBlocksize(), (char *)0); + i = execl(cpio, cpio, "-idum", cpioVerbosity(), (char *)0); else - i = execl(cpio, cpio, "-idum", "--block-size", mediaTapeBlocksize(), (char *)0); + i = execl(cpio, cpio, "-idum", "--block-size", (char *)0); if (isDebug()) msgDebug("%s command returns %d status\n", cpio, i); exit(i); } close(pfd[0]); close(pfd[1]); close(qfd[0]); total = 0; (void)gettimeofday(&start, (struct timezone *)0); /* Make ^C abort the current transfer rather than the whole show */ new.sa_handler = handle_intr; new.sa_flags = 0; (void)sigemptyset(&new.sa_mask); sigaction(SIGINT, &new, &old); while ((i = fread(buf, 1, BUFSIZ, fp)) > 0) { if (check_for_interrupt()) { msgConfirm("Failure to read from media: User interrupt."); break; } if (write(qfd[1], buf, i) != i) { msgConfirm("Write error on transfer to cpio process, try of %d bytes.", i); break; } else { (void)gettimeofday(&stop, (struct timezone *)0); stop.tv_sec = stop.tv_sec - start.tv_sec; stop.tv_usec = stop.tv_usec - start.tv_usec; if (stop.tv_usec < 0) stop.tv_sec--, stop.tv_usec += 1000000; seconds = stop.tv_sec + (stop.tv_usec / 1000000.0); if (!seconds) seconds = 1; total += i; msgInfo("%10d bytes read from %s dist @ %.1f KB/sec.", total, dist, (total / seconds) / 1024.0); } } sigaction(SIGINT, &old, NULL); /* restore sigint */ close(qfd[1]); i = waitpid(zpid, &j, 0); /* Don't check exit status - gunzip seems to return a bogus one! */ if (i < 0) { if (isDebug()) msgDebug("wait for %s returned status of %d!\n", UNZIPPER, i); return FALSE; } i = waitpid(cpid, &j, 0); if (i < 0 || WEXITSTATUS(j)) { if (isDebug()) msgDebug("cpio returned error status of %d!\n", WEXITSTATUS(j)); return FALSE; } return TRUE; } int mediaGetType(dialogMenuItem *self) { return ((dmenuOpenSimple(&MenuMedia, FALSE) && mediaDevice) ? DITEM_SUCCESS : DITEM_FAILURE); } /* Return TRUE if all the media variables are set up correctly */ Boolean mediaVerify(void) { if (!mediaDevice) return (DITEM_STATUS(mediaGetType(NULL)) == DITEM_SUCCESS); return TRUE; } /* Set the FTP username and password fields */ int mediaSetFTPUserPass(dialogMenuItem *self) { char *pass; if (variable_get_value(VAR_FTP_USER, "Please enter the username you wish to login as:", 0)) { DialogInputAttrs |= DITEM_NO_ECHO; pass = variable_get_value(VAR_FTP_PASS, "Please enter the password for this user:", 0); DialogInputAttrs &= ~DITEM_NO_ECHO; } else pass = NULL; return (pass ? DITEM_SUCCESS : DITEM_FAILURE); } /* Set CPIO verbosity level */ int mediaSetCPIOVerbosity(dialogMenuItem *self) { char *cp = variable_get(VAR_CPIO_VERBOSITY); if (!cp) { msgConfirm("CPIO Verbosity is not set to anything!"); return DITEM_FAILURE; } else { if (!strcmp(cp, "low")) variable_set2(VAR_CPIO_VERBOSITY, "medium", 0); else if (!strcmp(cp, "medium")) variable_set2(VAR_CPIO_VERBOSITY, "high", 0); else /* must be "high" - wrap around */ variable_set2(VAR_CPIO_VERBOSITY, "low", 0); } return DITEM_SUCCESS; } /* A generic open which follows a well-known "path" of places to look */ FILE * mediaGenericGet(char *base, const char *file) { char buf[PATH_MAX]; snprintf(buf, PATH_MAX, "%s/%s", base, file); if (file_readable(buf)) return fopen(buf, "r"); snprintf(buf, PATH_MAX, "%s/FreeBSD/%s", base, file); if (file_readable(buf)) return fopen(buf, "r"); snprintf(buf, PATH_MAX, "%s/releases/%s", base, file); if (file_readable(buf)) return fopen(buf, "r"); snprintf(buf, PATH_MAX, "%s/%s/%s", base, variable_get(VAR_RELNAME), file); if (file_readable(buf)) return fopen(buf, "r"); snprintf(buf, PATH_MAX, "%s/releases/%s/%s", base, variable_get(VAR_RELNAME), file); return fopen(buf, "r"); } diff --git a/usr.sbin/sysinstall/options.c b/usr.sbin/sysinstall/options.c index 04876d622b17..8634c69754e6 100644 --- a/usr.sbin/sysinstall/options.c +++ b/usr.sbin/sysinstall/options.c @@ -1,341 +1,338 @@ /* * The new sysinstall program. * * This is probably the last attempt in the `sysinstall' line, the next * generation being slated for what's essentially a complete rewrite. * * $FreeBSD$ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * verbatim and that no modifications are made prior to this * point in the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include "sysinstall.h" #include #include #include int fixitTtyWhich(dialogMenuItem *); static char * varCheck(Option *opt) { char *cp = NULL; if (opt->aux) cp = variable_get((char *)opt->aux); if (!cp) return "NO"; return cp; } /* Show our little logo */ static char * resetLogo(Option *opt) { return "[RESET!]"; } static char * mediaCheck(Option *opt) { if (mediaDevice) { switch(mediaDevice->type) { case DEVICE_TYPE_UFS: case DEVICE_TYPE_DISK: return "File system"; case DEVICE_TYPE_FLOPPY: return "Floppy"; case DEVICE_TYPE_FTP: return "FTP"; case DEVICE_TYPE_CDROM: return "CDROM"; case DEVICE_TYPE_TAPE: return "Tape"; case DEVICE_TYPE_DOS: return "DOS"; case DEVICE_TYPE_NFS: return "NFS"; case DEVICE_TYPE_NONE: case DEVICE_TYPE_NETWORK: case DEVICE_TYPE_ANY: default: return ""; } } return ""; } -#define TAPE_PROMPT "Please enter the tape block size in 512 byte blocks:" #define NEWFS_PROMPT "Please enter newfs(8) parameters:" #define RELNAME_PROMPT "Please specify the release you wish to load or\n\"any\" for a generic release install:" #define BPKG_PROMPT "Please specify the name of the HTML browser package:" #define BBIN_PROMPT "Please specify a full pathname to the HTML browser binary:" #define EDITOR_PROMPT "Please specify the name of the text editor you wish to use:" #define PKG_PROMPT "Please specify a temporary directory with lots of free space:" #define INSTROOT_PROMPT "Please specify a root directory if installing somewhere other than /" #define TIMEOUT_PROMPT "Please specify the number of seconds to wait for slow media:" static Option Options[] = { { "NFS Secure", "NFS server talks only on a secure port", OPT_IS_VAR, NULL, VAR_NFS_SECURE, varCheck }, { "NFS Slow", "User is using a slow PC or ethernet card", OPT_IS_VAR, NULL, VAR_SLOW_ETHER, varCheck }, { "NFS TCP", "Use TCP protocol for NFS", OPT_IS_VAR, NULL, VAR_NFS_TCP, varCheck }, { "NFS version 3", "Use NFS version 3", OPT_IS_VAR, NULL, VAR_NFS_V3, varCheck }, { "Debugging", "Emit extra debugging output on VTY2 (ALT-F2)", OPT_IS_VAR, NULL, VAR_DEBUG, varCheck }, { "No Warnings", "Don't Warn the user when a setting seems incorrect", OPT_IS_VAR, NULL, VAR_NO_WARN, varCheck }, { "Yes to All", "Assume \"Yes\" answers to all non-critical dialogs", OPT_IS_VAR, NULL, VAR_NO_CONFIRM, varCheck }, { "DHCP", "Attempt automatic DHCP configuration of interfaces", OPT_IS_VAR, NULL, VAR_TRY_DHCP, varCheck }, { "IPv6", "Attempt IPv6 configuration of interfaces", OPT_IS_VAR, NULL, VAR_TRY_RTSOL, varCheck }, { "Skip PCCARD", "Skip PC Card probing, do not use PC Card devices for installation", OPT_IS_VAR, NULL, VAR_SKIP_PCCARD, varCheck }, { "FTP username", "Username and password to use instead of anonymous", OPT_IS_FUNC, mediaSetFTPUserPass, VAR_FTP_USER, varCheck }, { "Editor", "Which text editor to use during installation", OPT_IS_VAR, EDITOR_PROMPT, VAR_EDITOR, varCheck }, -{ "Tape Blocksize", "Tape media block size in 512 byte blocks", - OPT_IS_VAR, TAPE_PROMPT, VAR_TAPE_BLOCKSIZE, varCheck }, { "Extract Detail", "How verbosely to display file name information during extractions", OPT_IS_FUNC, mediaSetCPIOVerbosity, VAR_CPIO_VERBOSITY, varCheck }, { "Release Name", "Which release to attempt to load from installation media", OPT_IS_VAR, RELNAME_PROMPT, VAR_RELNAME, varCheck }, { "Install Root", "Which directory to unpack distributions or packages relative to", OPT_IS_VAR, INSTROOT_PROMPT, VAR_INSTALL_ROOT, varCheck }, { "Browser package", "This is the browser package that will be used for viewing HTML docs", OPT_IS_VAR, BPKG_PROMPT, VAR_BROWSER_PACKAGE, varCheck }, { "Browser Exec", "This is the path to the main binary of the browser package", OPT_IS_VAR, BBIN_PROMPT, VAR_BROWSER_BINARY, varCheck }, { "Media Type", "The current installation media type.", OPT_IS_FUNC, mediaGetType, VAR_MEDIA_TYPE, mediaCheck }, { "Media Timeout", "Timeout value in seconds for slow media.", OPT_IS_VAR, TIMEOUT_PROMPT, VAR_MEDIA_TIMEOUT, varCheck }, { "Package Temp", "The directory where package temporary files should go", OPT_IS_VAR, PKG_PROMPT, VAR_PKG_TMPDIR, varCheck }, { "Newfs Args", "Default parameters for newfs(8)", OPT_IS_VAR, NEWFS_PROMPT, VAR_NEWFS_ARGS, varCheck }, { "Fixit Console", "Which tty to use for the Fixit action.", OPT_IS_FUNC, fixitTtyWhich, VAR_FIXIT_TTY, varCheck }, { "Re-scan Devices", "Re-run sysinstall's initial device probe", OPT_IS_FUNC, deviceRescan, NULL, NULL }, { "Use Defaults", "Reset all values to startup defaults", OPT_IS_FUNC, installVarDefaults, NULL, resetLogo }, { NULL, NULL, 0, NULL, NULL, NULL }, }; #define OPT_START_ROW 4 #define OPT_END_ROW 19 #define OPT_NAME_COL 0 #define OPT_VALUE_COL 16 #define GROUP_OFFSET 40 static char * value_of(Option opt) { static char ival[40]; switch (opt.type) { case OPT_IS_STRING: return (char *)opt.data; case OPT_IS_INT: sprintf(ival, "%lu", (long)opt.data); return ival; case OPT_IS_FUNC: case OPT_IS_VAR: if (opt.check) return opt.check(&opt); else return "<*>"; } return ""; } static int fire(Option opt) { int status = 0; if (opt.type == OPT_IS_FUNC) { int (*cp)(char *) = opt.data, rcode; rcode = cp(NULL); status = 1; } else if (opt.type == OPT_IS_VAR) { if (opt.data) { (void)variable_get_value(opt.aux, opt.data, -1); status = 1; } else if (variable_get(opt.aux)) { if (!variable_cmp(opt.aux, "YES")) variable_set2(opt.aux, "NO", -1); else variable_set2(opt.aux, "YES", -1); } else variable_set2(opt.aux, "YES", 0); } if (opt.check) opt.check(&opt); refresh(); return status; } int optionsEditor(dialogMenuItem *self) { int i, optcol, optrow, key; static int currOpt = 0; WINDOW *w = savescr(); dialog_clear(); clear(); while (1) { /* Whap up the header */ attrset(A_REVERSE); mvaddstr(0, 0, "Options Editor"); attrset(A_NORMAL); for (i = 0; i < 2; i++) { mvaddstr(OPT_START_ROW - 2, OPT_NAME_COL + (i * GROUP_OFFSET), "Name"); mvaddstr(OPT_START_ROW - 1, OPT_NAME_COL + (i * GROUP_OFFSET), "----"); mvaddstr(OPT_START_ROW - 2, OPT_VALUE_COL + (i * GROUP_OFFSET), "Value"); mvaddstr(OPT_START_ROW - 1, OPT_VALUE_COL + (i * GROUP_OFFSET), "-----"); } /* And the footer */ mvprintw(OPT_END_ROW + 1, 0, "Use SPACE to select/toggle an option, arrow keys to move,"); mvprintw(OPT_END_ROW + 2, 0, "? or F1 for more help. When you're done, type Q to Quit."); optrow = OPT_START_ROW; optcol = OPT_NAME_COL; for (i = 0; Options[i].name; i++) { /* Names are painted somewhat gratuitously each time, but it's easier this way */ mvprintw(optrow, OPT_NAME_COL + optcol, Options[i].name); if (currOpt == i) attrset(ATTR_SELECTED); mvprintw(optrow++, OPT_VALUE_COL + optcol, value_of(Options[i])); if (currOpt == i) attrset(A_NORMAL); if (optrow == OPT_END_ROW) { optrow = OPT_START_ROW; optcol += GROUP_OFFSET; } clrtoeol(); } attrset(ATTR_TITLE); mvaddstr(OPT_END_ROW + 4, 0, Options[currOpt].desc); attrset(A_NORMAL); clrtoeol(); move(0, 14); refresh(); /* Start the edit loop */ key = toupper(getch()); switch (key) { case KEY_F(1): case '?': systemDisplayHelp("options"); clear(); break; case '\020': /* ^P */ case KEY_UP: if (currOpt) --currOpt; else for (currOpt = 0; Options[currOpt + 1].name; currOpt++); continue; case '\016': /* ^N */ case KEY_DOWN: if (Options[currOpt + 1].name) ++currOpt; else currOpt = 0; continue; case KEY_HOME: currOpt = 0; continue; case KEY_END: while (Options[currOpt + 1].name) ++currOpt; continue; case ' ': if (fire(Options[currOpt])) clear(); continue; case '\033': /* ESC */ case 'Q': clear(); dialog_clear(); restorescr(w); return DITEM_SUCCESS | DITEM_CONTINUE; default: beep(); } } /* NOTREACHED */ return DITEM_SUCCESS; } int fixitTtyWhich(dialogMenuItem *self) { char *cp = variable_get(VAR_FIXIT_TTY); if (!cp) { msgConfirm("The Fix-it TTY setting is not set to anything!"); return DITEM_FAILURE; } else { if (!strcmp(cp, "standard")) variable_set2(VAR_FIXIT_TTY, "serial", 0); else /* must be "serial" - wrap around */ variable_set2(VAR_FIXIT_TTY, "standard", 0); } return DITEM_SUCCESS; } diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index 2805c87146f1..f0966f4673e6 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -1,907 +1,904 @@ /* * The new sysinstall program. * * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * verbatim and that no modifications are made prior to this * point in the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _SYSINSTALL_H_INCLUDE #define _SYSINSTALL_H_INCLUDE #include #include #include #include #include #include #include #include #include #include "ui_objects.h" #include "dir.h" #include "colors.h" #include "dist.h" /*** Defines ***/ #if defined(__i386__) || defined(__alpha__) || defined(__amd64__) #define WITH_SYSCONS #define WITH_MICE #endif #if defined(__i386__) || defined(__amd64__) #define WITH_SLICES #endif #if defined(__i386__) #define WITH_LINUX #endif /* device limits */ #define DEV_NAME_MAX 128 /* The maximum length of a device name */ #define DEV_MAX 100 /* The maximum number of devices we'll deal with */ #define INTERFACE_MAX 50 /* Maximum number of network interfaces we'll deal with */ #define IO_ERROR -2 /* Status code for I/O error rather than normal EOF */ /* Number of seconds to wait for data to come off even the slowest media */ #define MEDIA_TIMEOUT 300 /* * I make some pretty gross assumptions about having a max of 50 chunks * total - 8 slices and 42 partitions. I can't easily display many more * than that on the screen at once! * * For 2.1 I'll revisit this and try to make it more dynamic, but since * this will catch 99.99% of all possible cases, I'm not too worried. */ #define MAX_CHUNKS 40 /* Internal environment variable names */ #define DISK_PARTITIONED "_diskPartitioned" #define DISK_LABELLED "_diskLabelled" #define DISK_SELECTED "_diskSelected" #define SYSTEM_STATE "_systemState" #define RUNNING_ON_ROOT "_runningOnRoot" #define TCP_CONFIGURED "_tcpConfigured" /* Ones that can be tweaked from config files */ #define VAR_BLANKTIME "blanktime" #define VAR_BOOTMGR "bootManager" #define VAR_BROWSER_BINARY "browserBinary" #define VAR_BROWSER_PACKAGE "browserPackage" #define VAR_COUNTRY "country" #define VAR_CPIO_VERBOSITY "cpioVerbose" #define VAR_DEBUG "debug" #define VAR_DESKSTYLE "_deskStyle" #define VAR_DISK "disk" #define VAR_DISKINTERACTIVE "diskInteractive" #define VAR_DISTS "dists" #define VAR_DIST_MAIN "distMain" #define VAR_DIST_SRC "distSRC" #define VAR_DIST_X11 "distX11" #define VAR_DIST_KERNEL "distKernel" #define VAR_DEDICATE_DISK "dedicateDisk" #define VAR_DOMAINNAME "domainname" #define VAR_EDITOR "editor" #define VAR_EXTRAS "ifconfig_" #define VAR_COMMAND "command" #define VAR_CONFIG_FILE "configFile" #define VAR_FIXIT_TTY "fixitTty" #define VAR_FTP_DIR "ftpDirectory" #define VAR_FTP_PASS "ftpPass" #define VAR_FTP_PATH "_ftpPath" #define VAR_FTP_PORT "ftpPort" #define VAR_FTP_STATE "ftpState" #define VAR_FTP_USER "ftpUser" #define VAR_FTP_HOST "ftpHost" #define VAR_HTTP_PATH "_httpPath" #define VAR_HTTP_PROXY "httpProxy" #define VAR_HTTP_PORT "httpPort" #define VAR_HTTP_HOST "httpHost" #define VAR_HTTP_FTP_MODE "httpFtpMode" #define VAR_GATEWAY "defaultrouter" #define VAR_GEOMETRY "geometry" #define VAR_HOSTNAME "hostname" #define VAR_IFCONFIG "ifconfig_" #define VAR_INSTALL_CFG "installConfig" #define VAR_INSTALL_ROOT "installRoot" #define VAR_IPADDR "ipaddr" #define VAR_IPV6_ENABLE "ipv6_enable" #define VAR_IPV6ADDR "ipv6addr" #define VAR_KERN_SECURELEVEL "kern_securelevel" #define VAR_KEYMAP "keymap" #define VAR_LABEL "label" #define VAR_LABEL_COUNT "labelCount" #define VAR_LINUX_ENABLE "linux_enable" #define VAR_MEDIA_TYPE "mediaType" #define VAR_MEDIA_TIMEOUT "MEDIA_TIMEOUT" #define VAR_MOUSED "moused_enable" #define VAR_MOUSED_FLAGS "moused_flags" #define VAR_MOUSED_PORT "moused_port" #define VAR_MOUSED_TYPE "moused_type" #define VAR_NAMESERVER "nameserver" #define VAR_NCPUS "ncpus" #define VAR_NETINTERACTIVE "netInteractive" #define VAR_NETMASK "netmask" #define VAR_NETWORK_DEVICE "netDev" #define VAR_NEWFS_ARGS "newfsArgs" #define VAR_NFS_PATH "nfs" #define VAR_NFS_HOST "nfsHost" #define VAR_NFS_V3 "nfs_use_v3" #define VAR_NFS_TCP "nfs_use_tcp" #define VAR_NFS_SECURE "nfs_reserved_port_only" #define VAR_NFS_SERVER "nfs_server_enable" #define VAR_NO_CONFIRM "noConfirm" #define VAR_NO_ERROR "noError" #define VAR_NO_HOLOSHELL "noHoloShell" #define VAR_NO_INET6 "noInet6" #define VAR_NO_WARN "noWarn" #define VAR_NO_USR "noUsr" #define VAR_NO_TMP "noTmp" #define VAR_NO_HOME "noHome" #define VAR_NONINTERACTIVE "nonInteractive" #define VAR_NOVELL "novell" #define VAR_OSF1_ENABLE "osf1_enable" #define VAR_RPCBIND_ENABLE "rpcbind_enable" #define VAR_NTPDATE_FLAGS "ntpdate_flags" #define VAR_PACKAGE "package" #define VAR_PARTITION "partition" #define VAR_PCNFSD "pcnfsd" #define VAR_PKG_TMPDIR "PKG_TMPDIR" #define VAR_PORTS_PATH "ports" #define VAR_PPP_ENABLE "ppp_enable" #define VAR_PPP_PROFILE "ppp_profile" #define VAR_RELNAME "releaseName" #define VAR_ROOT_SIZE "rootSize" #define VAR_ROUTER "router" #define VAR_ROUTER_ENABLE "router_enable" #define VAR_ROUTERFLAGS "router_flags" #define VAR_SENDMAIL_ENABLE "sendmail_enable" #define VAR_SERIAL_SPEED "serialSpeed" #define VAR_SLOW_ETHER "slowEthernetCard" #define VAR_SWAP_SIZE "swapSize" -#define VAR_TAPE_BLOCKSIZE "tapeBlocksize" #define VAR_TRY_DHCP "tryDHCP" #define VAR_TRY_RTSOL "tryRTSOL" #define VAR_SKIP_PCCARD "skipPCCARD" #define VAR_UFS_PATH "ufs" #define VAR_USR_SIZE "usrSize" #define VAR_VAR_SIZE "varSize" #define VAR_TMP_SIZE "tmpSize" #define VAR_HOME_SIZE "homeSize" #define VAR_XORG_CONFIG "_xorgconfig" #define VAR_TERM "TERM" #define VAR_CONSTERM "_consterm" #ifdef PC98 #define DEFAULT_COUNTRY "jp" #else #define DEFAULT_COUNTRY "us" #endif -#define DEFAULT_TAPE_BLOCKSIZE "20" /* One MB worth of blocks */ #define ONE_MEG 2048 #define ONE_GIG (ONE_MEG * 1024) /* Which selection attributes to use */ #define ATTR_SELECTED (ColorDisplay ? item_selected_attr : item_attr) #define ATTR_TITLE button_active_attr /* Handy strncpy() macro */ #define SAFE_STRCPY(to, from) sstrncpy((to), (from), sizeof (to) - 1) /*** Types ***/ typedef int Boolean; typedef struct disk Disk; typedef struct chunk Chunk; /* Bitfields for menu options */ #define DMENU_NORMAL_TYPE 0x1 /* Normal dialog menu */ #define DMENU_RADIO_TYPE 0x2 /* Radio dialog menu */ #define DMENU_CHECKLIST_TYPE 0x4 /* Multiple choice menu */ #define DMENU_SELECTION_RETURNS 0x8 /* Immediate return on item selection */ typedef struct _dmenu { int type; /* What sort of menu we are */ char *title; /* Our title */ char *prompt; /* Our prompt */ char *helpline; /* Line of help at bottom */ char *helpfile; /* Help file for "F1" */ #if (__STDC_VERSION__ >= 199901L) || (__GNUC__ >= 3) dialogMenuItem items[]; /* Array of menu items */ #elif __GNUC__ dialogMenuItem items[0]; /* Array of menu items */ #else #error "Create hack for C89 and K&R compilers." #endif } DMenu; /* An rc.conf variable */ typedef struct _variable { struct _variable *next; char *name; char *value; int dirty; } Variable; #define NO_ECHO_OBJ(type) ((type) | (DITEM_NO_ECHO << 16)) #define TYPE_OF_OBJ(type) ((type) & 0xff) #define ATTR_OF_OBJ(type) ((type) >> 16) /* A screen layout structure */ typedef struct _layout { int y; /* x & Y co-ordinates */ int x; int len; /* The size of the dialog on the screen */ int maxlen; /* How much the user can type in ... */ char *prompt; /* The string for the prompt */ char *help; /* The display for the help line */ void *var; /* The var to set when this changes */ int type; /* The type of the dialog to create */ void *obj; /* The obj pointer returned by libdialog */ } Layout; /* Layout array terminator. */ #define LAYOUT_END { 0, 0, 0, 0, NULL, NULL, NULL, 0, NULL } typedef enum { DEVICE_TYPE_NONE, DEVICE_TYPE_DISK, DEVICE_TYPE_FLOPPY, DEVICE_TYPE_FTP, DEVICE_TYPE_NETWORK, DEVICE_TYPE_CDROM, DEVICE_TYPE_TAPE, DEVICE_TYPE_DOS, DEVICE_TYPE_UFS, DEVICE_TYPE_NFS, DEVICE_TYPE_ANY, DEVICE_TYPE_HTTP, } DeviceType; /* CDROM mount codes */ #define CD_UNMOUNTED 0 #define CD_ALREADY_MOUNTED 1 #define CD_WE_MOUNTED_IT 2 /* A "device" from sysinstall's point of view */ typedef struct _device { char name[DEV_NAME_MAX]; char *description; char *devname; DeviceType type; Boolean enabled; Boolean (*init)(struct _device *dev); FILE * (*get)(struct _device *dev, char *file, Boolean probe); void (*shutdown)(struct _device *dev); void *private; unsigned int flags; unsigned int volume; } Device; /* Some internal representations of partitions */ typedef enum { PART_NONE, PART_SLICE, PART_SWAP, PART_FILESYSTEM, PART_FAT, PART_EFI } PartType; #define NEWFS_UFS_CMD "newfs" #define NEWFS_MSDOS_CMD "newfs_msdos" enum newfs_type { NEWFS_UFS, NEWFS_MSDOS, NEWFS_CUSTOM }; #define NEWFS_UFS_STRING "UFS" #define NEWFS_MSDOS_STRING "FAT" #define NEWFS_CUSTOM_STRING "CST" /* The longest set of custom command line arguments we'll pass. */ #define NEWFS_CMD_ARGS_MAX 256 typedef struct _part_info { char mountpoint[FILENAME_MAX]; /* Is invocation of newfs desired? */ Boolean do_newfs; enum newfs_type newfs_type; union { struct { char user_options[NEWFS_CMD_ARGS_MAX]; Boolean acls; /* unused */ Boolean multilabel; /* unused */ Boolean softupdates; Boolean ufs1; } newfs_ufs; struct { /* unused */ } newfs_msdos; struct { char command[NEWFS_CMD_ARGS_MAX]; } newfs_custom; } newfs_data; } PartInfo; /* An option */ typedef struct _opt { char *name; char *desc; enum { OPT_IS_STRING, OPT_IS_INT, OPT_IS_FUNC, OPT_IS_VAR } type; void *data; void *aux; char *(*check)(struct _opt *); } Option; /* Weird index nodey things we use for keeping track of package information */ typedef enum { PACKAGE, PLACE } node_type; /* Types of nodes */ typedef struct _pkgnode { /* A node in the reconstructed hierarchy */ struct _pkgnode *next; /* My next sibling */ node_type type; /* What am I? */ char *name; /* My name */ char *desc; /* My description (Hook) */ struct _pkgnode *kids; /* My little children */ void *data; /* A place to hang my data */ } PkgNode; typedef PkgNode *PkgNodePtr; /* A single package */ typedef struct _indexEntry { /* A single entry in an INDEX file */ char *name; /* name */ char *path; /* full path to port */ char *prefix; /* port prefix */ char *comment; /* one line description */ char *descrfile; /* path to description file */ char *deps; /* packages this depends on */ int depc; /* how many depend on me */ int installed; /* indicates if it is installed */ char *maintainer; /* maintainer */ unsigned int volume; /* Volume of package */ } IndexEntry; typedef IndexEntry *IndexEntryPtr; typedef int (*commandFunc)(char *key, void *data); #define HOSTNAME_FIELD_LEN 128 #define IPADDR_FIELD_LEN 16 #define EXTRAS_FIELD_LEN 128 /* This is the structure that Network devices carry around in their private, erm, structures */ typedef struct _devPriv { int use_rtsol; int use_dhcp; char ipaddr[IPADDR_FIELD_LEN]; char netmask[IPADDR_FIELD_LEN]; char extras[EXTRAS_FIELD_LEN]; } DevInfo; /*** Externs ***/ extern jmp_buf BailOut; /* Used to get the heck out */ extern int CDROMInitQuiet; /* Don't whine if mount(2) fails */ extern int DebugFD; /* Where diagnostic output goes */ extern Boolean Fake; /* Don't actually modify anything - testing */ extern Boolean Restarting; /* Are we restarting sysinstall? */ extern Boolean SystemWasInstalled; /* Did we install it? */ extern Boolean RunningAsInit; /* Are we running stand-alone? */ extern Boolean DialogActive; /* Is the dialog() stuff up? */ extern Boolean ColorDisplay; /* Are we on a color display? */ extern Boolean OnVTY; /* On a syscons VTY? */ extern Variable *VarHead; /* The head of the variable chain */ extern Device *mediaDevice; /* Where we're getting our distribution from */ extern unsigned int Dists; /* Which distributions we want */ extern unsigned int SrcDists; /* Which src distributions we want */ extern unsigned int XOrgDists; /* Which X.Org dists we want */ extern unsigned int KernelDists; /* Which kernel dists we want */ extern int BootMgr; /* Which boot manager to use */ extern int StatusLine; /* Where to print our status messages */ extern DMenu MenuCountry; /* Country menu */ extern DMenu MenuInitial; /* Initial installation menu */ extern DMenu MenuFixit; /* Fixit repair menu */ #if defined(__i386__) || defined(__amd64__) #ifdef PC98 extern DMenu MenuIPLType; /* Type of IPL to write on the disk */ #else extern DMenu MenuMBRType; /* Type of MBR to write on the disk */ #endif #endif extern DMenu MenuConfigure; /* Final configuration menu */ extern DMenu MenuDocumentation; /* Documentation menu */ extern DMenu MenuFTPOptions; /* FTP Installation options */ extern DMenu MenuIndex; /* Index menu */ extern DMenu MenuOptions; /* Installation options */ extern DMenu MenuOptionsLanguage; /* Language options menu */ extern DMenu MenuKLD; /* Prototype KLD menu */ extern DMenu MenuMedia; /* Media type menu */ #ifdef WITH_MICE extern DMenu MenuMouse; /* Mouse type menu */ #endif extern DMenu MenuMediaCDROM; /* CDROM media menu */ extern DMenu MenuMediaDOS; /* DOS media menu */ extern DMenu MenuMediaFloppy; /* Floppy media menu */ extern DMenu MenuMediaFTP; /* FTP media menu */ extern DMenu MenuMediaTape; /* Tape media menu */ extern DMenu MenuNetworkDevice; /* Network device menu */ extern DMenu MenuNTP; /* NTP time server menu */ extern DMenu MenuSecurity; /* System security options menu */ extern DMenu MenuSecurelevel; /* Securelevel menu */ extern DMenu MenuStartup; /* Startup services menu */ #ifdef WITH_SYSCONS extern DMenu MenuSyscons; /* System console configuration menu */ extern DMenu MenuSysconsFont; /* System console font configuration menu */ extern DMenu MenuSysconsKeymap; /* System console keymap configuration menu */ extern DMenu MenuSysconsKeyrate; /* System console keyrate configuration menu */ extern DMenu MenuSysconsSaver; /* System console saver configuration menu */ extern DMenu MenuSysconsScrnmap; /* System console screenmap configuration menu */ extern DMenu MenuSysconsTtys; /* System console terminal type menu */ #endif extern DMenu MenuNetworking; /* Network configuration menu */ extern DMenu MenuMTA; /* MTA selection menu */ extern DMenu MenuInstallCustom; /* Custom Installation menu */ extern DMenu MenuDistributions; /* Distribution menu */ extern DMenu MenuDiskDevices; /* Disk type devices */ extern DMenu MenuSubDistributions; /* Custom distribution menu */ extern DMenu MenuSrcDistributions; /* Source distribution menu */ extern DMenu MenuKernelDistributions;/* Kernel distribution menu */ extern DMenu MenuHTMLDoc; /* HTML Documentation menu */ extern DMenu MenuUsermgmt; /* User management menu */ extern DMenu MenuFixit; /* Fixit floppy/CDROM/shell menu */ extern int FixItMode; /* FixItMode starts shell on current device (ie Serial port) */ extern const char * StartName; /* Which name we were started as */ extern const char * ProgName; /* Program's proper name */ extern int NCpus; /* # cpus on machine */ /* Important chunks. */ extern Chunk *HomeChunk; extern Chunk *RootChunk; extern Chunk *SwapChunk; extern Chunk *TmpChunk; extern Chunk *UsrChunk; extern Chunk *VarChunk; #ifdef __ia64__ extern Chunk *EfiChunk; #endif /* Stuff from libdialog which isn't properly declared outside */ extern void display_helpfile(void); extern void display_helpline(WINDOW *w, int y, int width); /*** Prototypes ***/ /* acpi.c */ extern int acpi_detect(void); /* anonFTP.c */ extern int configAnonFTP(dialogMenuItem *self); /* cdrom.c */ extern Boolean mediaInitCDROM(Device *dev); extern FILE *mediaGetCDROM(Device *dev, char *file, Boolean probe); extern void mediaShutdownCDROM(Device *dev); /* command.c */ extern void command_clear(void); extern void command_sort(void); extern void command_execute(void); extern void command_shell_add(char *key, char *fmt, ...) __printflike(2, 3); extern void command_func_add(char *key, commandFunc func, void *data); /* config.c */ extern void configEnvironmentRC_conf(void); extern void configEnvironmentResolv(char *config); extern void configRC_conf(void); extern int configFstab(dialogMenuItem *self); extern int configRC(dialogMenuItem *self); extern int configResolv(dialogMenuItem *self); extern int configPackages(dialogMenuItem *self); extern int configSaver(dialogMenuItem *self); extern int configSaverTimeout(dialogMenuItem *self); #ifdef WITH_LINUX extern int configLinux(dialogMenuItem *self); #endif extern int configNTP(dialogMenuItem *self); #ifdef __alpha__ extern int configOSF1(dialogMenuItem *self); #endif extern int configCountry(dialogMenuItem *self); extern int configUsers(dialogMenuItem *self); extern int configRouter(dialogMenuItem *self); extern int configPCNFSD(dialogMenuItem *self); extern int configInetd(dialogMenuItem *self); extern int configNFSServer(dialogMenuItem *self); extern int configMTAPostfix(dialogMenuItem *self); extern int configMTAExim(dialogMenuItem *self); extern int configRpcBind(dialogMenuItem *self); extern int configWriteRC_conf(dialogMenuItem *self); extern int configSecurelevel(dialogMenuItem *self); extern int configSecurelevelDisabled(dialogMenuItem *self); extern int configSecurelevelSecure(dialogMenuItem *self); extern int configSecurelevelHighlySecure(dialogMenuItem *self); extern int configSecurelevelNetworkSecure(dialogMenuItem *self); extern int configEtcTtys(dialogMenuItem *self); #ifdef __i386__ extern int checkLoaderACPI(void); extern int configLoaderACPI(int); #endif /* devices.c */ extern DMenu *deviceCreateMenu(DMenu *menu, DeviceType type, int (*hook)(dialogMenuItem *d), int (*check)(dialogMenuItem *d)); extern void deviceGetAll(void); extern void deviceReset(void); extern void deviceRescan(void); extern Device **deviceFind(char *name, DeviceType type); extern Device **deviceFindDescr(char *name, char *desc, DeviceType class); extern int deviceCount(Device **devs); extern Device *new_device(char *name); extern Device *deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled, Boolean (*init)(Device *mediadev), FILE * (*get)(Device *dev, char *file, Boolean probe), void (*shutDown)(Device *mediadev), void *private); extern Boolean dummyInit(Device *dev); extern FILE *dummyGet(Device *dev, char *dist, Boolean probe); extern void dummyShutdown(Device *dev); /* dhcp.c */ extern int dhcpParseLeases(char *file, char *hostname, char *domain, char *nameserver, char *ipaddr, char *gateway, char *netmask); /* disks.c */ #ifdef WITH_SLICES extern void diskPartition(Device *dev); extern int diskPartitionEditor(dialogMenuItem *self); #endif extern int diskPartitionWrite(dialogMenuItem *self); extern int diskGetSelectCount(Device ***devs); /* dispatch.c */ extern int dispatchCommand(char *command); extern int dispatch_load_floppy(dialogMenuItem *self); extern int dispatch_load_file_int(int); extern int dispatch_load_file(dialogMenuItem *self); /* dist.c */ extern int distReset(dialogMenuItem *self); extern int distConfig(dialogMenuItem *self); extern int distSetCustom(dialogMenuItem *self); extern int distUnsetCustom(dialogMenuItem *self); extern int distSetDeveloper(dialogMenuItem *self); extern int distSetXDeveloper(dialogMenuItem *self); extern int distSetKernDeveloper(dialogMenuItem *self); extern int distSetXKernDeveloper(dialogMenuItem *self); extern int distSetUser(dialogMenuItem *self); extern int distSetXUser(dialogMenuItem *self); extern int distSetMinimum(dialogMenuItem *self); extern int distSetEverything(dialogMenuItem *self); extern int distSetSrc(dialogMenuItem *self); extern int distSetKernel(dialogMenuItem *self); extern int distExtractAll(dialogMenuItem *self); extern int selectKernel(void); /* dmenu.c */ extern int dmenuDisplayFile(dialogMenuItem *tmp); extern int dmenuSubmenu(dialogMenuItem *tmp); extern int dmenuSystemCommand(dialogMenuItem *tmp); extern int dmenuSystemCommandBox(dialogMenuItem *tmp); extern int dmenuExit(dialogMenuItem *tmp); extern int dmenuISetVariable(dialogMenuItem *tmp); extern int dmenuSetVariable(dialogMenuItem *tmp); extern int dmenuSetCountryVariable(dialogMenuItem *tmp); extern int dmenuSetKmapVariable(dialogMenuItem *tmp); extern int dmenuSetVariables(dialogMenuItem *tmp); extern int dmenuToggleVariable(dialogMenuItem *tmp); extern int dmenuSetFlag(dialogMenuItem *tmp); extern int dmenuSetValue(dialogMenuItem *tmp); extern int dmenuFindItem(DMenu *menu, const char *prompt, const char *title, void *data); extern void dmenuSetDefaultIndex(DMenu *menu, int *choice, int *scroll, int *curr, int *max); extern int dmenuSetDefaultItem(DMenu *menu, const char *prompt, const char *title, void *data, int *choice, int *scroll, int *curr, int *max); extern Boolean dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons); extern Boolean dmenuOpenSimple(DMenu *menu, Boolean buttons); extern int dmenuVarCheck(dialogMenuItem *item); extern int dmenuVarsCheck(dialogMenuItem *item); extern int dmenuFlagCheck(dialogMenuItem *item); extern int dmenuRadioCheck(dialogMenuItem *item); /* doc.c */ extern int docBrowser(dialogMenuItem *self); extern int docShowDocument(dialogMenuItem *self); /* dos.c */ extern Boolean mediaCloseDOS(Device *dev, FILE *fp); extern Boolean mediaInitDOS(Device *dev); extern FILE *mediaGetDOS(Device *dev, char *file, Boolean probe); extern void mediaShutdownDOS(Device *dev); /* floppy.c */ extern int getRootFloppy(void); extern Boolean mediaInitFloppy(Device *dev); extern FILE *mediaGetFloppy(Device *dev, char *file, Boolean probe); extern void mediaShutdownFloppy(Device *dev); /* ftp_strat.c */ extern Boolean mediaCloseFTP(Device *dev, FILE *fp); extern Boolean mediaInitFTP(Device *dev); extern FILE *mediaGetFTP(Device *dev, char *file, Boolean probe); extern void mediaShutdownFTP(Device *dev); /* http.c */ extern Boolean mediaInitHTTP(Device *dev); extern FILE *mediaGetHTTP(Device *dev, char *file, Boolean probe); /* globals.c */ extern void globalsInit(void); /* index.c */ int index_read(FILE *fp, PkgNodePtr papa); int index_menu(PkgNodePtr root, PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll); void index_init(PkgNodePtr top, PkgNodePtr plist); void index_node_free(PkgNodePtr top, PkgNodePtr plist); void index_sort(PkgNodePtr top); void index_print(PkgNodePtr top, int level); int index_extract(Device *dev, PkgNodePtr top, PkgNodePtr who, Boolean depended); int index_initialize(char *path); PkgNodePtr index_search(PkgNodePtr top, char *str, PkgNodePtr *tp); /* install.c */ extern Boolean checkLabels(Boolean whinge); extern int installCommit(dialogMenuItem *self); extern int installCustomCommit(dialogMenuItem *self); extern int installExpress(dialogMenuItem *self); extern int installStandard(dialogMenuItem *self); extern int installFixitHoloShell(dialogMenuItem *self); extern int installFixitCDROM(dialogMenuItem *self); extern int installFixitFloppy(dialogMenuItem *self); extern int installFixupBase(dialogMenuItem *self); extern int installFixupKernel(dialogMenuItem *self, int dists); extern int installUpgrade(dialogMenuItem *self); extern int installFilesystems(dialogMenuItem *self); extern int installVarDefaults(dialogMenuItem *self); extern void installEnvironment(void); extern Boolean copySelf(void); /* kget.c */ extern int kget(char *out); /* keymap.c */ extern int keymapMenuSelect(dialogMenuItem *self); extern int loadKeymap(const char *lang); /* label.c */ extern int diskLabelEditor(dialogMenuItem *self); extern int diskLabelCommit(dialogMenuItem *self); /* makedevs.c (auto-generated) */ extern const char termcap_ansi[]; extern const char termcap_vt100[]; extern const char termcap_cons25w[]; extern const char termcap_cons25[]; extern const char termcap_cons25_m[]; extern const char termcap_cons25r[]; extern const char termcap_cons25r_m[]; extern const char termcap_cons25l1[]; extern const char termcap_cons25l1_m[]; extern const char termcap_xterm[]; extern const u_char font_iso_8x16[]; extern const u_char font_cp850_8x16[]; extern const u_char font_cp866_8x16[]; extern const u_char koi8_r2cp866[]; extern u_char default_scrnmap[]; /* media.c */ extern char *cpioVerbosity(void); extern int mediaOpen(void); extern void mediaClose(void); extern int mediaTimeout(void); extern int mediaSetCDROM(dialogMenuItem *self); extern int mediaSetFloppy(dialogMenuItem *self); extern int mediaSetDOS(dialogMenuItem *self); extern int mediaSetTape(dialogMenuItem *self); extern int mediaSetFTP(dialogMenuItem *self); extern int mediaSetFTPActive(dialogMenuItem *self); extern int mediaSetFTPPassive(dialogMenuItem *self); extern int mediaSetHTTP(dialogMenuItem *self); extern int mediaSetUFS(dialogMenuItem *self); extern int mediaSetNFS(dialogMenuItem *self); extern int mediaSetFTPUserPass(dialogMenuItem *self); extern int mediaSetCPIOVerbosity(dialogMenuItem *self); extern int mediaGetType(dialogMenuItem *self); extern Boolean mediaExtractDist(char *dir, char *dist, FILE *fp); extern Boolean mediaExtractDistBegin(char *dir, int *fd, int *zpid, int *cpic); extern Boolean mediaExtractDistEnd(int zpid, int cpid); extern Boolean mediaVerify(void); extern FILE *mediaGenericGet(char *base, const char *file); /* misc.c */ extern Boolean file_readable(char *fname); extern Boolean file_executable(char *fname); extern Boolean directory_exists(const char *dirname); extern char *root_bias(char *path); extern char *itoa(int value); extern char *string_concat(char *p1, char *p2); extern char *string_concat3(char *p1, char *p2, char *p3); extern char *string_prune(char *str); extern char *string_skipwhite(char *str); extern char *string_copy(char *s1, char *s2); extern char *pathBaseName(const char *path); extern void safe_free(void *ptr); extern void *safe_malloc(size_t size); extern void *safe_realloc(void *orig, size_t size); extern dialogMenuItem *item_add(dialogMenuItem *list, char *prompt, char *title, int (*checked)(dialogMenuItem *self), int (*fire)(dialogMenuItem *self), void (*selected)(dialogMenuItem *self, int is_selected), void *data, int *aux, int *curr, int *max); extern void items_free(dialogMenuItem *list, int *curr, int *max); extern int Mkdir(char *); extern int Mkdir_command(char *key, void *data); extern int Mount(char *, void *data); extern int Mount_msdosfs(char *mountp, void *devname); extern WINDOW *openLayoutDialog(char *helpfile, char *title, int x, int y, int width, int height); extern ComposeObj *initLayoutDialog(WINDOW *win, Layout *layout, int x, int y, int *max); extern int layoutDialogLoop(WINDOW *win, Layout *layout, ComposeObj **obj, int *n, int max, int *cbutton, int *cancel); extern WINDOW *savescr(void); extern void restorescr(WINDOW *w); extern char *sstrncpy(char *dst, const char *src, int size); extern char *getsysctlbyname(const char *sysctlname); /* modules.c */ extern void driverFloppyCheck(void); extern void moduleInitialize(void); extern int kldBrowser(dialogMenuItem *self); /* mouse.c */ extern int mousedTest(dialogMenuItem *self); extern int mousedDisable(dialogMenuItem *self); extern int setMouseFlags(dialogMenuItem *self); /* mptable.c */ extern int biosmptable_detect(void); /* msg.c */ extern Boolean isDebug(void); extern void msgInfo(char *fmt, ...) __printf0like(1, 2); extern void msgYap(char *fmt, ...) __printflike(1, 2); extern void msgWarn(char *fmt, ...) __printflike(1, 2); extern void msgDebug(char *fmt, ...) __printflike(1, 2); extern void msgError(char *fmt, ...) __printflike(1, 2); extern void msgFatal(char *fmt, ...) __printflike(1, 2); extern void msgConfirm(char *fmt, ...) __printflike(1, 2); extern void msgNotify(char *fmt, ...) __printflike(1, 2); extern void msgWeHaveOutput(char *fmt, ...) __printflike(1, 2); extern int msgYesNo(char *fmt, ...) __printflike(1, 2); extern int msgNoYes(char *fmt, ...) __printflike(1, 2); extern char *msgGetInput(char *buf, char *fmt, ...) __printflike(2, 3); extern int msgSimpleConfirm(char *); extern int msgSimpleNotify(char *); /* network.c */ extern Boolean mediaInitNetwork(Device *dev); extern void mediaShutdownNetwork(Device *dev); /* nfs.c */ extern Boolean mediaInitNFS(Device *dev); extern FILE *mediaGetNFS(Device *dev, char *file, Boolean probe); extern void mediaShutdownNFS(Device *dev); /* options.c */ extern int optionsEditor(dialogMenuItem *self); /* package.c */ extern int packageAdd(dialogMenuItem *self); extern int package_add(char *name); extern int package_extract(Device *dev, char *name, Boolean depended); extern Boolean package_installed(char *name); /* pccard.c */ extern void pccardInitialize(void); /* system.c */ extern void systemInitialize(int argc, char **argv); extern void systemShutdown(int status); extern int execExecute(char *cmd, char *name); extern int systemExecute(char *cmd); extern void systemSuspendDialog(void); extern void systemResumeDialog(void); extern int systemDisplayHelp(char *file); extern char *systemHelpFile(char *file, char *buf); extern void systemChangeFont(const u_char font[]); extern void systemChangeLang(char *lang); extern void systemChangeTerminal(char *color, const u_char c_termcap[], char *mono, const u_char m_termcap[]); extern void systemChangeScreenmap(const u_char newmap[]); extern void systemCreateHoloshell(void); extern int vsystem(char *fmt, ...) __printflike(1, 2); /* tape.c */ -extern char *mediaTapeBlocksize(void); extern Boolean mediaInitTape(Device *dev); extern FILE *mediaGetTape(Device *dev, char *file, Boolean probe); extern void mediaShutdownTape(Device *dev); /* tcpip.c */ extern int tcpOpenDialog(Device *dev); extern int tcpMenuSelect(dialogMenuItem *self); extern Device *tcpDeviceSelect(void); /* termcap.c */ extern int set_termcap(void); /* ttys.c */ extern void configTtys(void); /* ufs.c */ extern void mediaShutdownUFS(Device *dev); extern Boolean mediaInitUFS(Device *dev); extern FILE *mediaGetUFS(Device *dev, char *file, Boolean probe); /* user.c */ extern int userAddGroup(dialogMenuItem *self); extern int userAddUser(dialogMenuItem *self); /* variable.c */ extern void variable_set(char *var, int dirty); extern void variable_set2(char *name, char *value, int dirty); extern char *variable_get(char *var); extern int variable_cmp(char *var, char *value); extern void variable_unset(char *var); extern char *variable_get_value(char *var, char *prompt, int dirty); extern int variable_check(char *data); extern int variable_check2(char *data); extern int dump_variables(dialogMenuItem *self); extern void free_variables(void); extern void pvariable_set(char *var); extern char *pvariable_get(char *var); /* wizard.c */ extern void slice_wizard(Disk *d); /* * Macros. Please find a better place for us! */ #define DEVICE_INIT(d) ((d) != NULL ? (d)->init((d)) : (Boolean)0) #define DEVICE_GET(d, b, f) ((d) != NULL ? (d)->get((d), (b), (f)) : NULL) #define DEVICE_SHUTDOWN(d) ((d) != NULL ? (d)->shutdown((d)) : (void)0) #ifdef USE_GZIP #define UNZIPPER "gunzip" #else #define UNZIPPER "bunzip2" #endif #endif /* _SYSINSTALL_H_INCLUDE */ diff --git a/usr.sbin/sysinstall/tape.c b/usr.sbin/sysinstall/tape.c index fd73da568e85..d5631d0f9be2 100644 --- a/usr.sbin/sysinstall/tape.c +++ b/usr.sbin/sysinstall/tape.c @@ -1,127 +1,119 @@ /* * The new sysinstall program. * * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * * $FreeBSD$ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * verbatim and that no modifications are made prior to this * point in the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ /* These routines deal with getting things off of tape media */ #include "sysinstall.h" #include #include static Boolean tapeInitted; -char * -mediaTapeBlocksize(void) -{ - char *cp = variable_get(VAR_TAPE_BLOCKSIZE); - - return cp ? cp : DEFAULT_TAPE_BLOCKSIZE; -} - Boolean mediaInitTape(Device *dev) { /* This is REALLY gross, but we need to do the init later in get due to the fact * that media is initialized BEFORE a filesystem is mounted now. */ return TRUE; } FILE * mediaGetTape(Device *dev, char *file, Boolean probe) { char buf[PATH_MAX]; FILE *fp; int i; if (!tapeInitted) { WINDOW *w = savescr(); msgDebug("Tape init routine called for %s (private dir is %s)\n", dev->name, (char *)dev->private); Mkdir(dev->private); if (chdir(dev->private)) { msgConfirm("Unable to CD to %s before extracting tape!\n" "Tape media is not selected and thus cannot be installed from.", (char *)dev->private); return (FILE *)IO_ERROR; } /* We know the tape is already in the drive, so go for it */ msgNotify("First extracting distributions from %s...", dev->description); if (!strcmp(dev->name, "rft0")) - i = vsystem("ft | cpio -idum %s --block-size %s", cpioVerbosity(), mediaTapeBlocksize()); + i = vsystem("ft | cpio -idum %s", cpioVerbosity()); else - i = vsystem("cpio -idum %s --block-size %s -I %s", cpioVerbosity(), mediaTapeBlocksize(), dev->devname); + i = vsystem("cpio -idum %s -I %s", cpioVerbosity(), dev->devname); if (!i) { tapeInitted = TRUE; msgDebug("Tape initialized successfully.\n"); } else { msgConfirm("Tape extract command failed with status %d!\n" "Unable to use tape media.", i); restorescr(w); return (FILE *)IO_ERROR; } restorescr(w); } sprintf(buf, "%s/%s", (char *)dev->private, file); if (isDebug()) msgDebug("Request for %s from tape (looking in %s)\n", file, buf); if (file_readable(buf)) fp = fopen(buf, "r"); else { sprintf(buf, "%s/releases/%s", (char *)dev->private, file); fp = fopen(buf, "r"); } /* Nuke the files behind us to save space */ if (fp) unlink(buf); return fp; } void mediaShutdownTape(Device *dev) { if (!tapeInitted) return; if (file_readable((char *)dev->private)) { msgDebug("Cleaning up results of tape extract in %s..\n", (char *)dev->private); (void)vsystem("rm -rf %s", (char *)dev->private); } tapeInitted = FALSE; }