Do not try to chflags() a symbolic link when copying an underlying filesytem
[dragonfly.git] / release / 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: src/release/sysinstall/main.c,v 1.57.2.9 2002/07/03 00:05:02 jhb Exp $
8  * $DragonFly: src/release/sysinstall/Attic/main.c,v 1.2 2003/06/17 04:27:21 dillon Exp $
9  *
10  * Copyright (c) 1995
11  *      Jordan Hubbard.  All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer,
18  *    verbatim and that no modifications are made prior to this
19  *    point in the file.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  *
24  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  */
37
38 #include "sysinstall.h"
39 #include <sys/signal.h>
40 #include <sys/fcntl.h>
41
42 const char *StartName;          /* Initial contents of argv[0] */
43
44 static void
45 screech(int sig)
46 {
47     msgDebug("\007Signal %d caught!  That's bad!\n", sig);
48     longjmp(BailOut, sig);
49 }
50
51 int
52 main(int argc, char **argv)
53 {
54     int choice, scroll, curr, max, status;
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 */
108     if (!Restarting)
109             moduleInitialize();
110
111     /* Initialize PC-card */
112 #ifdef PCCARD_ARCH
113     if (!Restarting)
114             pccardInitialize();
115 #endif
116
117     /* Initialize USB */
118     if (!Restarting)
119             usbInitialize();
120
121     /* Probe for all relevant devices on the system */
122     deviceGetAll();
123
124     /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
125     if (!RunningAsInit) {
126         int i, start_arg;
127
128         if (!strstr(argv[0], "sysinstall"))
129             start_arg = 0;
130         else if (Fake || Restarting)
131             start_arg = 2;
132         else
133             start_arg = 1;
134         for (i = start_arg; i < argc; i++) {
135             if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS)
136                 systemShutdown(1);
137         }
138         if (argc > start_arg)
139             systemShutdown(0);
140     }
141     else
142         dispatch_load_file_int(TRUE);
143
144     status = setjmp(BailOut);
145     if (status) {
146         msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n"
147                    "down.  If you can reproduce the problem, please turn Debug on\n"
148                    "in the Options menu for the extra information it provides\n"
149                    "in debugging problems like this.", status);
150         systemShutdown(status);
151     }
152
153     /* Begin user dialog at outer menu */
154     dialog_clear();
155     while (1) {
156         choice = scroll = curr = max = 0;
157         dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE);
158         if (getpid() != 1
159 #ifdef __alpha__
160             || !msgNoYes("Are you sure you wish to exit?  The system will halt.")
161 #else
162             || !msgNoYes("Are you sure you wish to exit?  The system will reboot\n"
163                          "(be sure to remove any floppies/CDs/DVDs from the drives).")
164 #endif
165             )
166             break;
167     }
168
169     /* Say goodnight, Gracie */
170     systemShutdown(0);
171
172     return 0; /* We should never get here */
173 }