]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/sysinstall/main.c
This commit was generated by cvs2svn to compensate for changes in r170242,
[FreeBSD/FreeBSD.git] / usr.sbin / sysinstall / main.c
1 /*
2  * The new sysinstall program.
3  *
4  * This is probably the last attempt in the `sysinstall' line, the next
5  * generation being slated for what's 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 <sys/signal.h>
39 #include <sys/fcntl.h>
40
41 const char *StartName;          /* Initial contents of argv[0] */
42
43 static void
44 screech(int sig)
45 {
46     msgDebug("\007Signal %d caught!  That's bad!\n", sig);
47     longjmp(BailOut, sig);
48 }
49
50 int
51 main(int argc, char **argv)
52 {
53     int choice, scroll, curr, max, status;
54     char titlestr[80], *arch, *osrel, *ostype;
55     
56     /* Record name to be able to restart */
57     StartName = argv[0];
58
59     /* Catch fatal signals and complain about them if running as init */
60     if (getpid() == 1) {
61         signal(SIGBUS, screech);
62         signal(SIGSEGV, screech);
63     }
64     signal(SIGPIPE, SIG_IGN);
65
66     /* We don't work too well when running as non-root anymore */
67     if (geteuid() != 0) {
68         fprintf(stderr, "Error: This utility should only be run as root.\n");
69         return 1;
70     }
71
72 #ifdef PC98
73     {
74         /* XXX */
75         char *p = getenv("TERM");
76         if (p && strcmp(p, "cons25") == 0)
77             putenv("TERM=cons25w");
78     }
79 #endif
80
81     /* Set up whatever things need setting up */
82     systemInitialize(argc, argv);
83
84     /* Set default flag and variable values */
85     installVarDefaults(NULL);
86     /* only when multi-user is it reasonable to do this here */
87     if (!RunningAsInit)
88         installEnvironment();
89
90     if (argc > 1 && !strcmp(argv[1], "-fake")) {
91         variable_set2(VAR_DEBUG, "YES", 0);
92         Fake = TRUE;
93         msgConfirm("I'll be just faking it from here on out, OK?");
94     }
95     if (argc > 1 && !strcmp(argv[1], "-restart"))
96         Restarting = TRUE;
97
98     /* Try to preserve our scroll-back buffer */
99     if (OnVTY) {
100         for (curr = 0; curr < 25; curr++)
101             putchar('\n');
102     }
103     /* Move stderr aside */
104     if (DebugFD)
105         dup2(DebugFD, 2);
106
107     /* Initialize driver modules, if we haven't already done so (ie,
108        the user hit Ctrl-C -> Restart. */
109     if (!pvariable_get("modulesInitialize")) {
110         moduleInitialize();
111         pvariable_set("modulesInitialize=1");
112     }
113
114     /* Initialize PC Card, if we haven't already done so. */
115 #ifdef PCCARD_ARCH
116     if (!variable_cmp(VAR_SKIP_PCCARD, "YES") &&
117       variable_get(VAR_SKIP_PCCARD)!=1 &&
118        !pvariable_get("pccardInitialize")) {
119         pccardInitialize();
120         pvariable_set("pccardInitialize=1");
121     }
122 #endif
123
124     /* Probe for all relevant devices on the system */
125     deviceGetAll();
126
127     /* Prompt for the driver floppy if appropriate. */
128     if (!pvariable_get("driverFloppyCheck")) {
129         driverFloppyCheck();
130         pvariable_set("driverFloppyCheck=1");
131     }
132
133     /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
134     if (!RunningAsInit) {
135         int i, start_arg;
136
137         if (!strstr(argv[0], "sysinstall"))
138             start_arg = 0;
139         else if (Fake || Restarting)
140             start_arg = 2;
141         else
142             start_arg = 1;
143         for (i = start_arg; i < argc; i++) {
144             if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS)
145                 systemShutdown(1);
146         }
147         if (argc > start_arg)
148             systemShutdown(0);
149     }
150     else
151         dispatch_load_file_int(TRUE);
152
153     status = setjmp(BailOut);
154     if (status) {
155         msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n"
156                    "down.  If you can reproduce the problem, please turn Debug on\n"
157                    "in the Options menu for the extra information it provides\n"
158                    "in debugging problems like this.", status);
159         systemShutdown(status);
160     }
161
162     /* Get user's country and keymap */
163     if (RunningAsInit)
164         configCountry(NULL);
165
166     /* Add FreeBSD version info to the menu title */
167     arch = getsysctlbyname("hw.machine_arch");
168     osrel = getsysctlbyname("kern.osrelease");
169     ostype = getsysctlbyname("kern.ostype");
170     snprintf(titlestr, sizeof(titlestr), "%s/%s %s - %s", ostype, arch,
171              osrel, MenuInitial.title);
172     free(arch);
173     free(osrel);
174     free(ostype);
175     MenuInitial.title = titlestr;
176
177     /* Begin user dialog at outer menu */
178     dialog_clear();
179     while (1) {
180         choice = scroll = curr = max = 0;
181         dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE);
182         if (getpid() != 1
183 #if defined(__alpha__) || defined(__sparc64__)
184             || !msgNoYes("Are you sure you wish to exit?  The system will halt.")
185 #else
186             || !msgNoYes("Are you sure you wish to exit?  The system will reboot\n"
187                          "(be sure to remove any floppies/CDs/DVDs from the drives).")
188 #endif
189             )
190             break;
191     }
192
193     /* Say goodnight, Gracie */
194     systemShutdown(0);
195
196     return 0; /* We should never get here */
197 }