]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - usr.sbin/sysinstall/install.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / usr.sbin / sysinstall / install.c
1 /*
2  * The new sysinstall program.
3  *
4  * This is probably the last program in the `sysinstall' line - the next
5  * generation being essentially a complete rewrite.
6  *
7  * $FreeBSD$
8  *
9  * Copyright (c) 1995
10  *      Jordan Hubbard.  All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer,
17  *    verbatim and that no modifications are made prior to this
18  *    point in the file.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36
37 #include "sysinstall.h"
38 #include <ctype.h>
39 #include <sys/consio.h>
40 #include <sys/disklabel.h>
41 #include <sys/errno.h>
42 #include <sys/ioctl.h>
43 #include <sys/fcntl.h>
44 #include <sys/wait.h>
45 #include <sys/uio.h>
46 #include <sys/param.h>
47 #define MSDOSFS
48 #include <sys/mount.h>
49 #include <ufs/ufs/ufsmount.h>
50 #include <fs/msdosfs/msdosfsmount.h>
51 #undef MSDOSFS
52 #include <sys/stat.h>
53 #include <sys/sysctl.h>
54 #include <libdisk.h>
55 #include <limits.h>
56 #include <unistd.h>
57 #include <termios.h>
58
59 /* Hack for rsaref package add, which displays interactive license.
60  * Used by package.c
61  */
62 int _interactiveHack;
63 int FixItMode = 0;
64 int NCpus;
65
66 static void     create_termcap(void);
67 static void     fixit_common(void);
68
69 #define TERMCAP_FILE    "/usr/share/misc/termcap"
70
71 static void     installConfigure(void);
72
73 Boolean
74 checkLabels(Boolean whinge)
75 {
76     Device **devs;
77     Boolean status;
78     Disk *disk;
79     PartInfo *pi;
80     Chunk *c1, *c2;
81     int i;
82
83     /* Don't allow whinging if noWarn is set */
84     if (variable_get(VAR_NO_WARN))
85         whinge = FALSE;
86
87     status = TRUE;
88     HomeChunk = RootChunk = SwapChunk = NULL;
89     TmpChunk = UsrChunk = VarChunk = NULL;
90 #ifdef __ia64__
91     EfiChunk = NULL;
92 #endif
93
94     /* We don't need to worry about root/usr/swap if we're already multiuser */
95     if (!RunningAsInit)
96         return status;
97
98     devs = deviceFind(NULL, DEVICE_TYPE_DISK);
99     /* First verify that we have a root device */
100     for (i = 0; devs[i]; i++) {
101         if (!devs[i]->enabled)
102             continue;
103         disk = (Disk *)devs[i]->private;
104         msgDebug("Scanning disk %s for root filesystem\n", disk->name);
105         if (!disk->chunks)
106             msgFatal("No chunk list found for %s!", disk->name);
107         for (c1 = disk->chunks->part; c1; c1 = c1->next) {
108 #ifdef __ia64__
109             c2 = c1;
110 #elif defined(__powerpc__)
111             if (c1->type == apple) {
112                 for (c2 = c1->part; c2; c2 = c2->next) {
113 #else
114             if (c1->type == freebsd) {
115                 for (c2 = c1->part; c2; c2 = c2->next) {
116 #endif
117
118                     pi = (PartInfo *)c2->private_data;
119                     if (c2->type == part && c2->subtype != FS_SWAP && pi != NULL) {
120                         if (!strcmp(pi->mountpoint, "/")) {
121                             if (RootChunk) {
122                                 if (whinge)
123                                     msgConfirm("WARNING:  You have more than one root device set?!\n"
124                                                "Using the first one found.");
125                                 continue;
126                             }
127                             else {
128                                 RootChunk = c2;
129                                 if (isDebug())
130                                     msgDebug("Found rootdev at %s!\n", RootChunk->name);
131                             }
132                         }
133                         else if (!strcmp(pi->mountpoint, "/usr")) {
134                             if (UsrChunk) {
135                                 if (whinge)
136                                     msgConfirm("WARNING:  You have more than one /usr filesystem.\n"
137                                                "Using the first one found.");
138                                 continue;
139                             }
140                             else {
141                                 UsrChunk = c2;
142                                 if (isDebug())
143                                     msgDebug("Found usrdev at %s!\n", UsrChunk->name);
144                             }
145                         }
146                         else if (!strcmp(pi->mountpoint, "/var")) {
147                             if (VarChunk) {
148                                 if (whinge)
149                                     msgConfirm("WARNING:  You have more than one /var filesystem.\n"
150                                                "Using the first one found.");
151                                 continue;
152                             }
153                             else {
154                                 VarChunk = c2;
155                                 if (isDebug())
156                                     msgDebug("Found vardev at %s!\n", VarChunk->name);
157                             }
158                         } else if (!strcmp(pi->mountpoint, "/tmp")) {
159                             if (TmpChunk) {
160                                 if (whinge)
161                                     msgConfirm("WARNING:  You have more than one /tmp filesystem.\n"
162                                                "Using the first one found.");
163                                 continue;
164                             }
165                             else {
166                                 TmpChunk = c2;
167                                 if (isDebug())
168                                     msgDebug("Found tmpdev at %s!\n", TmpChunk->name);
169                             }
170                         } else if (!strcmp(pi->mountpoint, "/home")) {
171                             if (HomeChunk) {
172                                 if (whinge)
173                                     msgConfirm("WARNING:  You have more than one /home filesystem.\n"
174                                                "Using the first one found.");
175                                 continue;
176                             }
177                             else {
178                                 HomeChunk = c2;
179                                 if (isDebug())
180                                     msgDebug("Found homedev at %s!\n", HomeChunk->name);
181                             }
182                         }
183                     }
184 #ifndef __ia64__
185                 }
186             }
187 #endif
188         }
189     }
190
191     /* Now check for swap devices */
192     for (i = 0; devs[i]; i++) {
193         if (!devs[i]->enabled)
194             continue;
195         disk = (Disk *)devs[i]->private;
196         msgDebug("Scanning disk %s for swap partitions\n", disk->name);
197         if (!disk->chunks)
198             msgFatal("No chunk list found for %s!", disk->name);
199         for (c1 = disk->chunks->part; c1; c1 = c1->next) {
200
201 #ifdef __ia64__
202             c2 = c1;
203 #elif defined(__powerpc__)
204             if (c1->type == apple) {
205                 for (c2 = c1->part; c2; c2 = c2->next) {
206 #else
207             if (c1->type == freebsd) {
208                 for (c2 = c1->part; c2; c2 = c2->next) {
209 #endif
210                     if (c2->type == part && c2->subtype == FS_SWAP && !SwapChunk) {
211                         SwapChunk = c2;
212                         if (isDebug())
213                             msgDebug("Found swapdev at %s!\n", SwapChunk->name);
214                         break;
215                     }
216 #ifndef __ia64__
217                 }
218             }
219 #endif
220         }
221     }
222
223 #ifdef __ia64__
224     for (i = 0; devs[i] != NULL; i++) {
225         if (!devs[i]->enabled)
226             continue;
227         disk = (Disk *)devs[i]->private;
228         for (c1 = disk->chunks->part; c1 != NULL; c1 = c1->next) {
229                 pi = (PartInfo *)c1->private_data;
230             if (c1->type == efi && pi != NULL && pi->mountpoint[0] == '/')
231                 EfiChunk = c1;
232         }
233     }
234 #endif
235
236     if (!RootChunk && whinge) {
237         msgConfirm("No root device found - you must label a partition as /\n"
238                    "in the label editor.");
239         status = FALSE;
240     }
241     if (!SwapChunk && whinge) {
242         if (msgYesNo("No swap devices found - you should create at least one\n"
243                      "swap partition.  Without swap, the install will fail\n"
244                      "if you do not have enough RAM.  Continue anyway?"))
245             status = FALSE;
246     }
247 #ifdef __ia64__
248     if (EfiChunk == NULL && whinge) {
249         if (msgYesNo("No (mounted) EFI system partition found. Is this what you want?"))
250             status = FALSE;
251     }
252 #endif
253     return status;
254 }
255
256 static int
257 installInitial(void)
258 {
259     static Boolean alreadyDone = FALSE;
260     int status = DITEM_SUCCESS;
261
262     if (alreadyDone)
263         return DITEM_SUCCESS;
264
265     if (!variable_get(DISK_LABELLED)) {
266         msgConfirm("You need to assign disk labels before you can proceed with\n"
267                    "the installation.");
268         return DITEM_FAILURE;
269     }
270     /* If it's labelled, assume it's also partitioned */
271     if (!variable_get(DISK_PARTITIONED))
272         variable_set2(DISK_PARTITIONED, "yes", 0);
273
274     /* If we refuse to proceed, bail. */
275     dialog_clear_norefresh();
276     if (!variable_get(VAR_NO_WARN)) {
277         if (msgYesNo(
278             "Last Chance!  Are you SURE you want continue the installation?\n\n"
279             "If you're running this on a disk with data you wish to save\n"
280             "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n"
281             "proceeding!\n\n"
282             "We can take no responsibility for lost disk contents!") != 0)
283         return DITEM_FAILURE;
284     }
285
286     if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) {
287         msgConfirm("Couldn't make filesystems properly.  Aborting.");
288         return DITEM_FAILURE;
289     }
290
291     if (!copySelf()) {
292         msgConfirm("installInitial: Couldn't clone the boot floppy onto the\n"
293                    "root file system.  Aborting!");
294         return DITEM_FAILURE;
295     }
296
297     if (!Restarting && chroot("/mnt") == -1) {
298         msgConfirm("installInitial: Unable to chroot to %s - this is bad!",
299                    "/mnt");
300         return DITEM_FAILURE;
301     }
302
303     chdir("/");
304     variable_set2(RUNNING_ON_ROOT, "yes", 0);
305
306     /* Configure various files in /etc */
307     if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE)
308         status = DITEM_FAILURE;
309     if (DITEM_STATUS(configFstab(NULL)) == DITEM_FAILURE)
310         status = DITEM_FAILURE;
311
312     /* stick a helpful shell over on the 4th VTY */
313     if (!variable_get(VAR_NO_HOLOSHELL))
314         systemCreateHoloshell();
315
316     alreadyDone = TRUE;
317     return status;
318 }
319
320 int
321 installFixitHoloShell(dialogMenuItem *self)
322 {
323     FixItMode = 1;
324     systemCreateHoloshell();
325     FixItMode = 0;
326     return DITEM_SUCCESS;
327 }
328
329 int
330 installFixitCDROM(dialogMenuItem *self)
331 {
332     struct stat sb;
333     int need_eject;
334
335     if (!RunningAsInit)
336         return DITEM_SUCCESS;
337
338     variable_set2(SYSTEM_STATE, "fixit", 0);
339     (void)unlink("/mnt2");
340     (void)rmdir("/mnt2");
341
342     need_eject = 0;
343     CDROMInitQuiet = 1;
344     while (1) {
345         if (need_eject)
346             msgConfirm(
347         "Please insert a FreeBSD live filesystem CD/DVD and press return");
348         if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS
349             || !DEVICE_INIT(mediaDevice)) {
350             /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */
351             mediaClose();
352             if (need_eject && msgYesNo("Unable to mount the disc. Do you want to try again?") != 0)
353                 return DITEM_FAILURE;
354         } else if (!file_readable("/dist/rescue/ldconfig")) {
355                 mediaClose();
356                 if (need_eject &&
357                     msgYesNo("Unable to find a FreeBSD live filesystem. Do you want to try again?") != 0)
358                     return DITEM_FAILURE;
359         } else
360             break;
361         CDROMInitQuiet = 0;
362         need_eject = 1;
363     }
364     CDROMInitQuiet = 0;
365
366     /* Since the fixit code expects everything to be in /mnt2, and the CDROM mounting stuff /dist, do
367      * a little kludge dance here..
368      */
369     if (symlink("/dist", "/mnt2")) {
370         msgConfirm("Unable to symlink /mnt2 to the disc mount point.  Please report this\n"
371                    "unexpected failure to freebsd-bugs@FreeBSD.org.");
372         return DITEM_FAILURE;
373     }
374
375     /*
376      * If /tmp points to /mnt2/tmp from a previous fixit floppy session, it's
377      * not very good for us if we point it to the CDROM now.  Rather make it
378      * a directory in the root MFS then.  Experienced admins will still be
379      * able to mount their disk's /tmp over this if they need.
380      */
381     if (lstat("/tmp", &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFLNK)
382         (void)unlink("/tmp");
383     Mkdir("/tmp");
384
385     /*
386      * Since setuid binaries ignore LD_LIBRARY_PATH, we indeed need the
387      * ld.so.hints file.  Fortunately, it's fairly small (~ 3 KB).
388      */
389     if (!file_readable("/var/run/ld.so.hints")) {
390         Mkdir("/var/run");
391         if (vsystem("/mnt2/rescue/ldconfig -s /mnt2/lib /mnt2/usr/lib")) {
392             msgConfirm("Warning: ldconfig could not create the ld.so hints file.\n"
393                        "Dynamic executables from the disc likely won't work.");
394         }
395     }
396
397     /* Yet more iggly hardcoded pathnames. */
398     Mkdir("/libexec");
399     if (!file_readable("/libexec/ld.so") && file_readable("/mnt2/libexec/ld.so")) {
400         if (symlink("/mnt2/libexec/ld.so", "/libexec/ld.so"))
401             msgDebug("Couldn't link to ld.so - not necessarily a problem for ELF\n");
402     }
403     if (!file_readable("/libexec/ld-elf.so.1")) {
404         if (symlink("/mnt2/libexec/ld-elf.so.1", "/libexec/ld-elf.so.1")) {
405             msgConfirm("Warning: could not create the symlink for ld-elf.so.1\n"
406                        "Dynamic executables from the disc likely won't work.");
407         }
408     }
409     /* optional nicety */
410     if (!file_readable("/usr/bin/vi"))
411         symlink("/mnt2/usr/bin/vi", "/usr/bin/vi");
412     fixit_common();
413     mediaClose();
414     if (need_eject)
415         msgConfirm("Please remove the FreeBSD fixit CDROM/DVD now.");
416     return DITEM_SUCCESS;
417 }
418
419 int
420 installFixitFloppy(dialogMenuItem *self)
421 {
422     struct ufs_args args;
423     extern char *distWanted;
424
425     if (!RunningAsInit)
426         return DITEM_SUCCESS;
427
428     /* Try to open the floppy drive */
429     if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) {
430         msgConfirm("Unable to set media device to floppy.");
431         mediaClose();
432         return DITEM_FAILURE;
433     }
434
435     memset(&args, 0, sizeof(args));
436     args.fspec = mediaDevice->devname;
437     mediaDevice->private = "/mnt2";
438     distWanted = NULL;
439     Mkdir("/mnt2");
440
441     variable_set2(SYSTEM_STATE, "fixit", 0);
442
443     while (1) {
444         if (!DEVICE_INIT(mediaDevice)) {
445             if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n"
446                          "or unclean filesystem.  Do you want to try again?"))
447                 return DITEM_FAILURE;
448         }
449         else
450             break;
451     }
452     if (!directory_exists("/tmp"))
453         (void)symlink("/mnt2/tmp", "/tmp");
454     fixit_common();
455     mediaClose();
456     msgConfirm("Please remove the fixit floppy now.");
457     return DITEM_SUCCESS;
458 }
459
460 /*
461  * The common code for both fixit variants.
462  */
463 static void
464 fixit_common(void)
465 {
466     pid_t child;
467     int waitstatus;
468
469     if (!directory_exists("/var/tmp/vi.recover")) {
470         if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) {
471             msgConfirm("Warning:  Was unable to create a /var/tmp/vi.recover directory.\n"
472                        "vi will kvetch and moan about it as a result but should still\n"
473                        "be essentially usable.");
474         }
475     }
476     if (!directory_exists("/bin"))
477         (void)Mkdir("/bin");
478     (void)symlink("/stand/sh", "/bin/sh");
479     /* Link the /etc/ files */
480     if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS)
481         msgConfirm("Unable to create an /etc directory!  Things are weird on this floppy..");
482     else if ((symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) ||
483              (symlink("/mnt2/etc/protocols", "/etc/protocols") == -1 && errno != EEXIST) ||
484              (symlink("/mnt2/etc/group", "/etc/group") == -1 && errno != EEXIST) ||
485              (symlink("/mnt2/etc/services", "/etc/services") == -1 && errno != EEXIST))
486         msgConfirm("Couldn't symlink the /etc/ files!  I'm not sure I like this..");
487     if (!file_readable(TERMCAP_FILE))
488         create_termcap();
489     if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 
490         systemSuspendDialog();  /* must be before the fork() */
491     if (!(child = fork())) {
492         int i, fd;
493         struct termios foo;
494         extern int login_tty(int);
495
496         ioctl(0, TIOCNOTTY, NULL);
497         for (i = getdtablesize(); i >= 0; --i)
498             close(i);
499
500         if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 
501             fd = open("/dev/console", O_RDWR);
502         else
503             fd = open("/dev/ttyv3", O_RDWR);
504         ioctl(0, TIOCSCTTY, &fd);
505         dup2(0, 1);
506         dup2(0, 2);
507         DebugFD = 2;
508         if (login_tty(fd) == -1)
509             msgDebug("fixit: I can't set the controlling terminal.\n");
510
511         signal(SIGTTOU, SIG_IGN);
512         if (tcgetattr(0, &foo) != -1) {
513             foo.c_cc[VERASE] = '\010';
514             if (tcsetattr(0, TCSANOW, &foo) == -1)
515                 msgDebug("fixit shell: Unable to set erase character.\n");
516         }
517         else
518             msgDebug("fixit shell: Unable to get terminal attributes!\n");
519         setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:"
520                "/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin", 1);
521         if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) {
522             printf("Waiting for fixit shell to exit.\n"
523                 "When you are done, type ``exit'' to exit\n"
524                 "the fixit shell and be returned here.\n\n");
525             fflush(stdout);
526         } else {
527             ioctl(fd, VT_ACTIVATE, 0);
528         }
529
530         /* use the .profile from the fixit medium */
531         setenv("HOME", "/mnt2", 1);
532         chdir("/mnt2");
533         execlp("sh", "-sh", (char *)0);
534         msgDebug("fixit shell: Failed to execute shell!\n");
535         _exit(1);;
536     }
537     else {
538         if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
539             dialog_clear_norefresh();
540             msgNotify("Waiting for fixit shell to exit.  Go to VTY4 now by\n"
541                 "typing ALT-F4.  When you are done, type ``exit'' to exit\n"
542                 "the fixit shell and be returned here.\n");
543         }
544         (void)waitpid(child, &waitstatus, 0);
545         if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
546             systemResumeDialog();
547         else if (OnVTY) {
548             ioctl(0, VT_ACTIVATE, 0);
549             msgInfo(NULL);
550         }
551     }
552     dialog_clear();
553 }
554
555
556 int
557 installExpress(dialogMenuItem *self)
558 {
559     int i;
560
561     dialog_clear_norefresh();
562     variable_set2(SYSTEM_STATE, "express", 0);
563 #ifdef WITH_SLICES
564     if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE)
565         return i;
566 #endif
567     
568     if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE)
569         return i;
570
571     if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) {
572         i |= DITEM_LEAVE_MENU;
573
574         /* Give user the option of one last configuration spree */
575         installConfigure();
576     }
577     return i;
578 }
579
580 /* Standard mode installation */
581 int
582 installStandard(dialogMenuItem *self)
583 {
584     int i, tries = 0;
585     Device **devs;
586
587     variable_set2(SYSTEM_STATE, "standard", 0);
588     dialog_clear_norefresh();
589 #ifdef WITH_SLICES
590     msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n"
591                "scheme for your hard disk.  If you simply wish to devote all disk space\n"
592                "to FreeBSD (overwriting anything else that might be on the disk(s) selected)\n"
593                "then use the (A)ll command to select the default partitioning scheme followed\n"
594                "by a (Q)uit.  If you wish to allocate only free space to FreeBSD, move to a\n"
595                "partition marked \"unused\" and use the (C)reate command.");
596
597 nodisks:
598     if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE)
599         return DITEM_FAILURE;
600
601     if (diskGetSelectCount(&devs) <= 0 && tries < 3) {
602         msgConfirm("You need to select some disks to operate on!  Be sure to use SPACE\n"
603                    "instead of RETURN in the disk selection menu when selecting a disk.");
604         ++tries;
605         goto nodisks;
606     }
607
608     msgConfirm("Now you need to create BSD partitions inside of the fdisk partition(s)\n"
609                "just created.  If you have a reasonable amount of disk space (1GB or more)\n"
610                "and don't have any special requirements, simply use the (A)uto command to\n"
611                "allocate space automatically.  If you have more specific needs or just don't\n"
612                "care for the layout chosen by (A)uto, press F1 for more information on\n"
613                "manual layout.");
614 #else
615     msgConfirm("First you need to create BSD partitions on the disk which you are\n"
616                "installing to.  If you have a reasonable amount of disk space (1GB or more)\n"
617                "and don't have any special requirements, simply use the (A)uto command to\n"
618                "allocate space automatically.  If you have more specific needs or just don't\n"
619                "care for the layout chosen by (A)uto, press F1 for more information on\n"
620                "manual layout.");
621 #endif
622
623     if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE)
624         return DITEM_FAILURE;
625
626     if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) {
627         dialog_clear();
628         msgConfirm("Installation completed with some errors.  You may wish to\n"
629                    "scroll through the debugging messages on VTY1 with the\n"
630                    "scroll-lock feature.  You can also choose \"No\" at the next\n"
631                    "prompt and go back into the installation menus to retry\n"
632                    "whichever operations have failed.");
633         return i;
634
635     }
636     else {
637         dialog_clear();
638         msgConfirm("Congratulations!  You now have FreeBSD installed on your system.\n\n"
639                    "We will now move on to the final configuration questions.\n"
640                    "For any option you do not wish to configure, simply select\n"
641                    "No.\n\n"
642                    "If you wish to re-enter this utility after the system is up, you\n"
643                    "may do so by typing: /usr/sbin/sysinstall.");
644     }
645     if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) {
646         if (!msgYesNo("Would you like to configure any Ethernet or SLIP/PPP network devices?")) {
647             Device *tmp = tcpDeviceSelect();
648
649             if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name))
650                 if (!DEVICE_INIT(tmp))
651                     msgConfirm("Initialization of %s device failed.", tmp->name);
652         }
653         dialog_clear_norefresh();
654     }
655
656     if (!msgNoYes("Do you want this machine to function as a network gateway?"))
657         variable_set2("gateway_enable", "YES", 1);
658
659     dialog_clear_norefresh();
660     if (!msgNoYes("Do you want to configure inetd and the network services that it provides?"))
661         configInetd(self);
662
663     dialog_clear_norefresh();
664     if (!msgNoYes("Would you like to enable SSH login?"))
665         variable_set2("sshd_enable", "YES", 1);
666
667     dialog_clear_norefresh();
668     if (!msgNoYes("Do you want to have anonymous FTP access to this machine?"))
669         configAnonFTP(self);
670
671     dialog_clear_norefresh();
672     if (!msgNoYes("Do you want to configure this machine as an NFS server?"))
673         configNFSServer(self);
674
675     dialog_clear_norefresh();
676     if (!msgNoYes("Do you want to configure this machine as an NFS client?"))
677         variable_set2("nfs_client_enable", "YES", 1);
678
679 #ifdef WITH_SYSCONS
680     dialog_clear_norefresh();
681     if (!msgNoYes("Would you like to customize your system console settings?"))
682         dmenuOpenSimple(&MenuSyscons, FALSE);
683 #endif
684
685     dialog_clear_norefresh();
686     if (!msgYesNo("Would you like to set this machine's time zone now?"))
687         systemExecute("tzsetup");
688
689 #ifdef WITH_LINUX
690     dialog_clear_norefresh();
691     if (!msgYesNo("Would you like to enable Linux binary compatibility?"))
692         (void)configLinux(self);
693 #endif
694
695 #ifdef __alpha__
696     dialog_clear_norefresh();
697     if (!msgYesNo("Would you like to enable OSF/1 binary compatibility?"))
698         (void)configOSF1(self);
699 #endif
700
701 #ifdef WITH_MICE
702     dialog_clear_norefresh();
703     if (!msgNoYes("Does this system have a PS/2, serial, or bus mouse?"))
704         dmenuOpenSimple(&MenuMouse, FALSE);
705 #endif
706
707 #ifdef __i386__
708     if (checkLoaderACPI() != 0) {
709         dialog_clear_norefresh();
710         if (!msgNoYes("ACPI was disabled during boot.\n"
711                       "Would you like to disable it permanently?"))
712                 (void)configLoaderACPI(1 /*disable*/);
713     }
714 #endif
715
716     /* Now would be a good time to checkpoint the configuration data */
717     configRC_conf();
718     sync();
719
720     dialog_clear_norefresh();
721     if (!msgYesNo("The FreeBSD package collection is a collection of thousands of ready-to-run\n"
722                   "applications, from text editors to games to WEB servers and more.  Would you\n"
723                   "like to browse the collection now?")) {
724         (void)configPackages(self);
725     }
726
727     if (!msgYesNo("Would you like to add any initial user accounts to the system?\n"
728                   "Adding at least one account for yourself at this stage is suggested\n"
729                   "since working as the \"root\" user is dangerous (it is easy to do\n"
730                   "things which adversely affect the entire system)."))
731         (void)configUsers(self);
732
733     msgConfirm("Now you must set the system manager's password.\n"
734                "This is the password you'll use to log in as \"root\".");
735     if (!systemExecute("passwd root"))
736         variable_set2("root_password", "YES", 0);
737
738     /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */
739
740     /* Give user the option of one last configuration spree */
741     dialog_clear_norefresh();
742     installConfigure();
743     return DITEM_LEAVE_MENU;
744 }
745
746 /* The version of commit we call from the Install Custom menu */
747 int
748 installCustomCommit(dialogMenuItem *self)
749 {
750     int i;
751
752     i = installCommit(self);
753     if (DITEM_STATUS(i) == DITEM_SUCCESS) {
754         /* Give user the option of one last configuration spree */
755         installConfigure();
756         return i;
757     }
758     else
759         msgConfirm("The commit operation completed with errors.  Not\n"
760                    "updating /etc files.");
761     return i;
762 }
763
764 /*
765  * What happens when we finally decide to going ahead with the installation.
766  *
767  * This is broken into multiple stages so that the user can do a full
768  * installation but come back here again to load more distributions,
769  * perhaps from a different media type.  This would allow, for
770  * example, the user to load the majority of the system from CDROM and
771  * then use ftp to load a different dist.
772  */
773 int
774 installCommit(dialogMenuItem *self)
775 {
776     int i;
777     char *str;
778
779     dialog_clear_norefresh();
780     if (!Dists)
781         distConfig(NULL);
782
783     if (!Dists) {
784         (void)dmenuOpenSimple(&MenuDistributions, FALSE);
785         /* select reasonable defaults if necessary */
786         if (!Dists)
787             Dists = _DIST_USER;
788         if (!KernelDists)
789             KernelDists = selectKernel();
790     }
791
792     if (!mediaVerify())
793         return DITEM_FAILURE;
794
795     str = variable_get(SYSTEM_STATE);
796     if (isDebug())
797         msgDebug("installCommit: System state is `%s'\n", str);
798
799     /* Installation stuff we wouldn't do to a running system */
800     if (RunningAsInit && DITEM_STATUS((i = installInitial())) == DITEM_FAILURE)
801         return i;
802
803 try_media:
804     if (!DEVICE_INIT(mediaDevice)) {
805         if (!msgYesNo("Unable to initialize selected media. Would you like to\n"
806                       "adjust your media configuration and try again?")) {
807             mediaDevice = NULL;
808             if (!mediaVerify())
809                 return DITEM_FAILURE;
810             else
811                 goto try_media;
812         }
813         else
814             return DITEM_FAILURE;
815     }
816
817     /* Now go get it all */
818     i = distExtractAll(self);
819
820     /* When running as init, *now* it's safe to grab the rc.foo vars */
821     installEnvironment();
822
823     variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install", 0);
824
825     return i;
826 }
827
828 static void
829 installConfigure(void)
830 {
831     /* Final menu of last resort */
832     if (!msgNoYes("Visit the general configuration menu for a chance to set\n"
833                   "any last options?"))
834         dmenuOpenSimple(&MenuConfigure, FALSE);
835     configRC_conf();
836     sync();
837 }
838
839 int
840 installFixupBase(dialogMenuItem *self)
841 {
842     FILE *fp;
843 #ifdef __ia64__
844     const char *efi_mntpt;
845 #endif
846
847     /* All of this is done only as init, just to be safe */
848     if (RunningAsInit) {
849 #if defined(__i386__) || defined(__amd64__)
850         if ((fp = fopen("/boot/loader.conf", "a")) != NULL) {
851             if (!OnVTY) {
852                 fprintf(fp, "# -- sysinstall generated deltas -- #\n");
853                 fprintf(fp, "console=\"comconsole\"\n");
854             }
855             fclose(fp);
856         }
857 #endif
858         
859         /* BOGON #2: We leave /etc in a bad state */
860         chmod("/etc", 0755);
861         
862         /* BOGON #3: No /var/db/mountdtab complains */
863         Mkdir("/var/db");
864         creat("/var/db/mountdtab", 0644);
865         
866         /* BOGON #4: /compat created by default in root fs */
867         Mkdir("/usr/compat");
868         vsystem("ln -s usr/compat /compat");
869
870         /* BOGON #5: aliases database not built for bin */
871         vsystem("newaliases");
872
873         /* BOGON #6: Remove /stand (finally) */
874         vsystem("rm -rf /stand");
875
876         /* Now run all the mtree stuff to fix things up */
877         vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /");
878         vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var");
879         vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr");
880
881 #ifdef __ia64__
882         /* Move /boot to the the EFI partition and make /boot a link to it. */
883         efi_mntpt = (EfiChunk != NULL) ? ((PartInfo *)EfiChunk->private_data)->mountpoint : NULL;
884         if (efi_mntpt != NULL) {
885                 vsystem("if [ ! -L /boot ]; then mv /boot %s; fi", efi_mntpt);
886                 vsystem("if [ ! -e /boot ]; then ln -sf %s/boot /boot; fi",
887                     efi_mntpt + 1);     /* Skip leading '/' */
888                 /* Make sure the kernel knows which partition is the root file system. */
889                 vsystem("echo 'vfs.root.mountfrom=\"ufs:/dev/%s\"' >> /boot/loader.conf", RootChunk->name);
890         }
891 #endif
892
893         /* Do all the last ugly work-arounds here */
894     }
895     return DITEM_SUCCESS | DITEM_RESTORE;
896 }
897
898 int
899 installFixupKernel(dialogMenuItem *self, int dists)
900 {
901
902     /* All of this is done only as init, just to be safe */
903     if (RunningAsInit) {
904         /*
905          * Install something as /boot/kernel.  Prefer SMP
906          * over generic--this should handle the case where
907          * both SMP and GENERIC are installed (otherwise we
908          * select the one kernel that was installed).
909          *
910          * NB: we assume any existing kernel has been saved
911          *     already and the /boot/kernel we remove is empty.
912          */
913         vsystem("rm -rf /boot/kernel");
914 #if WITH_SMP
915         if (dists & DIST_KERNEL_SMP)
916                 vsystem("mv /boot/SMP /boot/kernel");
917         else
918 #endif
919                 vsystem("mv /boot/GENERIC /boot/kernel");
920     }
921     return DITEM_SUCCESS | DITEM_RESTORE;
922 }
923
924 #define QUEUE_YES       1
925 #define QUEUE_NO        0
926 static int
927 performNewfs(PartInfo *pi, char *dname, int queue)
928 {
929         char buffer[LINE_MAX];
930
931         if (pi->do_newfs) {
932                 switch(pi->newfs_type) {
933                 case NEWFS_UFS:
934                         snprintf(buffer, LINE_MAX, "%s %s %s %s %s",
935                             NEWFS_UFS_CMD,
936                             pi->newfs_data.newfs_ufs.softupdates ?  "-U" : "",
937                             pi->newfs_data.newfs_ufs.ufs1 ? "-O1" : "-O2",
938                             pi->newfs_data.newfs_ufs.user_options,
939                             dname);
940                         break;
941
942                 case NEWFS_MSDOS:
943                         snprintf(buffer, LINE_MAX, "%s %s", NEWFS_MSDOS_CMD,
944                             dname);
945                         break;
946
947                 case NEWFS_CUSTOM:
948                         snprintf(buffer, LINE_MAX, "%s %s",
949                             pi->newfs_data.newfs_custom.command, dname);
950                         break;
951                 }
952
953                 if (queue == QUEUE_YES) {
954                         command_shell_add(pi->mountpoint, buffer);
955                         return (0);
956                 } else
957                         return (vsystem(buffer));
958         }
959         return (0);
960 }
961
962 /* Go newfs and/or mount all the filesystems we've been asked to */
963 int
964 installFilesystems(dialogMenuItem *self)
965 {
966     int i;
967     Disk *disk;
968     Chunk *c1, *c2;
969     Device **devs;
970     PartInfo *root;
971     char dname[80];
972     Boolean upgrade = FALSE;
973
974     /* If we've already done this, bail out */
975     if (!variable_cmp(DISK_LABELLED, "written"))
976         return DITEM_SUCCESS;
977
978     upgrade = !variable_cmp(SYSTEM_STATE, "upgrade");
979     if (!checkLabels(TRUE))
980         return DITEM_FAILURE;
981
982     root = (RootChunk != NULL) ? (PartInfo *)RootChunk->private_data : NULL;
983
984     command_clear();
985     if (SwapChunk && RunningAsInit) {
986         /* As the very first thing, try to get ourselves some swap space */
987         sprintf(dname, "/dev/%s", SwapChunk->name);
988         if (!Fake && !file_readable(dname)) {
989             msgConfirm("Unable to find device node for %s in /dev!\n"
990                        "The creation of filesystems will be aborted.", dname);
991             return DITEM_FAILURE;
992         }
993
994         if (!Fake) {
995             if (!swapon(dname)) {
996                 dialog_clear_norefresh();
997                 msgNotify("Added %s as initial swap device", dname);
998             }
999             else {
1000                 msgConfirm("WARNING!  Unable to swap to %s: %s\n"
1001                            "This may cause the installation to fail at some point\n"
1002                            "if you don't have a lot of memory.", dname, strerror(errno));
1003             }
1004         }
1005     }
1006
1007     if (RootChunk && RunningAsInit) {
1008         /* Next, create and/or mount the root device */
1009         sprintf(dname, "/dev/%s", RootChunk->name);
1010         if (!Fake && !file_readable(dname)) {
1011             msgConfirm("Unable to make device node for %s in /dev!\n"
1012                        "The creation of filesystems will be aborted.", dname);
1013             return DITEM_FAILURE | DITEM_RESTORE;
1014         }
1015         if (strcmp(root->mountpoint, "/"))
1016             msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", RootChunk->name, root->mountpoint);
1017
1018         if (root->do_newfs && (!upgrade ||
1019             !msgNoYes("You are upgrading - are you SURE you want to newfs "
1020             "the root partition?"))) {
1021             int i;
1022
1023             dialog_clear_norefresh();
1024             msgNotify("Making a new root filesystem on %s", dname);
1025             i = performNewfs(root, dname, QUEUE_NO);
1026             if (i) {
1027                 msgConfirm("Unable to make new root filesystem on %s!\n"
1028                            "Command returned status %d", dname, i);
1029                 return DITEM_FAILURE | DITEM_RESTORE;
1030             }
1031         }
1032         else {
1033             if (!upgrade) {
1034                 msgConfirm("Warning:  Using existing root partition.");
1035             }
1036             dialog_clear_norefresh();
1037             msgNotify("Checking integrity of existing %s filesystem.", dname);
1038             i = vsystem("fsck_ffs -y %s", dname);
1039             if (i)
1040                 msgConfirm("Warning: fsck returned status of %d for %s.\n"
1041                            "This partition may be unsafe to use.", i, dname);
1042         }
1043
1044         /*
1045          * If soft updates was enabled in the editor but we didn't newfs,
1046          * use tunefs to update the soft updates flag on the file system.
1047          */
1048         if (!root->do_newfs && root->newfs_type == NEWFS_UFS &&
1049             root->newfs_data.newfs_ufs.softupdates) {
1050                 i = vsystem("tunefs -n enable %s", dname);
1051                 if (i)
1052                         msgConfirm("Warning: Unable to enable soft updates"
1053                             " for root file system on %s", dname);
1054         }
1055
1056         /* Switch to block device */
1057         sprintf(dname, "/dev/%s", RootChunk->name);
1058         if (Mount("/mnt", dname)) {
1059             msgConfirm("Unable to mount the root file system on %s!  Giving up.", dname);
1060             return DITEM_FAILURE | DITEM_RESTORE;
1061         }
1062
1063         /* Mount devfs for other partitions to mount */
1064         Mkdir("/mnt/dev");
1065         if (!Fake) {
1066             struct iovec iov[4];
1067
1068             iov[0].iov_base = "fstype";
1069             iov[0].iov_len = strlen(iov[0].iov_base) + 1;
1070             iov[1].iov_base = "devfs";
1071             iov[1].iov_len = strlen(iov[1].iov_base) + 1;
1072             iov[2].iov_base = "fspath";
1073             iov[2].iov_len = strlen(iov[2].iov_base) + 1;
1074             iov[3].iov_base = "/mnt/dev";
1075             iov[3].iov_len = strlen(iov[3].iov_base) + 1;
1076             i = nmount(iov, 4, 0);
1077
1078             if (i) {
1079                 dialog_clear_norefresh();
1080                 msgConfirm("Unable to mount DEVFS (error %d)", errno);
1081                 return DITEM_FAILURE | DITEM_RESTORE;
1082             }
1083         }
1084     }
1085
1086     /* Now buzz through the rest of the partitions and mount them too */
1087     devs = deviceFind(NULL, DEVICE_TYPE_DISK);
1088     for (i = 0; devs[i]; i++) {
1089         if (!devs[i]->enabled)
1090             continue;
1091
1092         disk = (Disk *)devs[i]->private;
1093         if (!disk->chunks) {
1094             msgConfirm("No chunk list found for %s!", disk->name);
1095             return DITEM_FAILURE | DITEM_RESTORE;
1096         }
1097         for (c1 = disk->chunks->part; c1; c1 = c1->next) {
1098 #ifdef __ia64__
1099         if (c1->type == part) {
1100                 c2 = c1;
1101                 {
1102 #elif defined(__powerpc__)
1103             if (c1->type == apple) {
1104                 for (c2 = c1->part; c2; c2 = c2->next) {
1105 #else
1106             if (c1->type == freebsd) {
1107                 for (c2 = c1->part; c2; c2 = c2->next) {
1108 #endif
1109                     if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) {
1110                         PartInfo *tmp = (PartInfo *)c2->private_data;
1111
1112                         /* Already did root */
1113                         if (c2 == RootChunk)
1114                             continue;
1115
1116                         sprintf(dname, "%s/dev/%s",
1117                             RunningAsInit ? "/mnt" : "", c2->name);
1118
1119                         if (tmp->do_newfs && (!upgrade ||
1120                             !msgNoYes("You are upgrading - are you SURE you"
1121                             " want to newfs /dev/%s?", c2->name)))
1122                                 performNewfs(tmp, dname, QUEUE_YES);
1123                         else
1124                             command_shell_add(tmp->mountpoint,
1125                                 "fsck_ffs -y %s/dev/%s", RunningAsInit ?
1126                                 "/mnt" : "", c2->name);
1127 #if 0
1128                         if (tmp->soft)
1129                             command_shell_add(tmp->mountpoint,
1130                             "tunefs -n enable %s/dev/%s", RunningAsInit ?
1131                             "/mnt" : "", c2->name);
1132 #endif
1133                         command_func_add(tmp->mountpoint, Mount, c2->name);
1134                     }
1135                     else if (c2->type == part && c2->subtype == FS_SWAP) {
1136                         char fname[80];
1137                         int i;
1138
1139                         if (c2 == SwapChunk)
1140                             continue;
1141                         sprintf(fname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name);
1142                         i = (Fake || swapon(fname));
1143                         if (!i) {
1144                             dialog_clear_norefresh();
1145                             msgNotify("Added %s as an additional swap device", fname);
1146                         }
1147                         else {
1148                             msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno));
1149                         }
1150                     }
1151                 }
1152             }
1153             else if (c1->type == fat && c1->private_data &&
1154                 (root->do_newfs || upgrade)) {
1155                 char name[FILENAME_MAX];
1156
1157                 sprintf(name, "%s/%s", RunningAsInit ? "/mnt" : "", ((PartInfo *)c1->private_data)->mountpoint);
1158                 Mkdir(name);
1159             }
1160 #if defined(__ia64__)
1161             else if (c1->type == efi && c1->private_data) {
1162                 char bootdir[FILENAME_MAX];
1163                 PartInfo *pi = (PartInfo *)c1->private_data;
1164                 char *p;
1165
1166                 sprintf(dname, "%s/dev/%s", RunningAsInit ? "/mnt" : "",
1167                     c1->name);
1168
1169                 if (pi->do_newfs && (!upgrade ||
1170                     !msgNoYes("You are upgrading - are you SURE you want to "
1171                     "newfs /dev/%s?", c1->name)))
1172                         performNewfs(pi, dname, QUEUE_YES);
1173
1174                 command_func_add(pi->mountpoint, Mount_msdosfs, c1->name);
1175             }
1176 #endif
1177         }
1178     }
1179
1180     command_sort();
1181     command_execute();
1182     dialog_clear_norefresh();
1183     return DITEM_SUCCESS | DITEM_RESTORE;
1184 }
1185
1186 /* Initialize various user-settable values to their defaults */
1187 int
1188 installVarDefaults(dialogMenuItem *self)
1189 {
1190     char *cp, ncpus[10];
1191
1192     /* Set default startup options */
1193     cp = getsysctlbyname("kern.osrelease");
1194     variable_set2(VAR_RELNAME,                  cp, 0);
1195     free(cp);
1196     variable_set2(VAR_CPIO_VERBOSITY,           "high", 0);
1197     variable_set2(VAR_TAPE_BLOCKSIZE,           DEFAULT_TAPE_BLOCKSIZE, 0);
1198     variable_set2(VAR_INSTALL_ROOT,             "/", 0);
1199     variable_set2(VAR_INSTALL_CFG,              "install.cfg", 0);
1200     variable_set2(VAR_SKIP_PCCARD,              "NO", 0);
1201     cp = getenv("EDITOR");
1202     if (!cp)
1203         cp = "/usr/bin/ee";
1204     variable_set2(VAR_EDITOR,                   cp, 0);
1205     variable_set2(VAR_FTP_USER,                 "ftp", 0);
1206     variable_set2(VAR_BROWSER_PACKAGE,          "links", 0);
1207     variable_set2(VAR_BROWSER_BINARY,           "/usr/local/bin/links", 0);
1208     variable_set2(VAR_FTP_STATE,                "passive", 0);
1209     variable_set2(VAR_NFS_SECURE,               "NO", -1);
1210     variable_set2(VAR_NFS_TCP,                  "NO", -1);
1211     variable_set2(VAR_NFS_V3,                   "YES", -1);
1212     if (OnVTY)
1213             variable_set2(VAR_FIXIT_TTY,                "standard", 0);
1214     else
1215             variable_set2(VAR_FIXIT_TTY,                "serial", 0);
1216     variable_set2(VAR_PKG_TMPDIR,               "/var/tmp", 0);
1217     variable_set2(VAR_MEDIA_TIMEOUT,            itoa(MEDIA_TIMEOUT), 0);
1218     if (getpid() != 1)
1219         variable_set2(SYSTEM_STATE,             "update", 0);
1220     else
1221         variable_set2(SYSTEM_STATE,             "init", 0);
1222     variable_set2(VAR_NEWFS_ARGS,               "-b 16384 -f 2048", 0);
1223     variable_set2(VAR_CONSTERM,                 "NO", 0);
1224 #if (defined(__i386__) && !defined(PC98)) || defined(__amd64__)
1225     NCpus = acpi_detect();
1226     if (NCpus == -1)
1227         NCpus = biosmptable_detect();
1228 #endif
1229     if (NCpus <= 0)
1230         NCpus = 1;
1231     snprintf(ncpus, sizeof(ncpus), "%u", NCpus);
1232     variable_set2(VAR_NCPUS,                    ncpus, 0);
1233     return DITEM_SUCCESS;
1234 }
1235
1236 /* Load the environment up from various system configuration files */
1237 void
1238 installEnvironment(void)
1239 {
1240     configEnvironmentRC_conf();
1241     if (file_readable("/etc/resolv.conf"))
1242         configEnvironmentResolv("/etc/resolv.conf");
1243 }
1244
1245 /* Copy the boot floppy contents into /stand */
1246 Boolean
1247 copySelf(void)
1248 {
1249     int i;
1250
1251     if (file_readable("/boot.help"))
1252         vsystem("cp /boot.help /mnt");
1253     msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem");
1254     i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity());
1255     if (i) {
1256         msgConfirm("Copy returned error status of %d!", i);
1257         return FALSE;
1258     }
1259
1260     /* Copy the /etc files into their rightful place */
1261     if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) {
1262         msgConfirm("Couldn't copy up the /etc files!");
1263         return TRUE;
1264     }
1265     return TRUE;
1266 }
1267
1268 static void
1269 create_termcap(void)
1270 {
1271     FILE *fp;
1272
1273     const char *caps[] = {
1274         termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r,
1275         termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m,
1276         termcap_xterm, NULL,
1277     };
1278     const char **cp;
1279
1280     if (!file_readable(TERMCAP_FILE)) {
1281         Mkdir("/usr/share/misc");
1282         fp = fopen(TERMCAP_FILE, "w");
1283         if (!fp) {
1284             msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work.");
1285             return;
1286         }
1287         cp = caps;
1288         while (*cp)
1289             fprintf(fp, "%s\n", *(cp++));
1290         fclose(fp);
1291     }
1292 }