main.c revision 24038
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 * $Id: main.c,v 1.43 1997/02/22 14:11:55 peter Exp $
8 *
9 * Copyright (c) 1995
10 *	Jordan Hubbard.  All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer,
17 *    verbatim and that no modifications are made prior to this
18 *    point in the file.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37#include "sysinstall.h"
38#include <sys/signal.h>
39#include <sys/fcntl.h>
40
41static void
42screech(int sig)
43{
44    msgDebug("\007Signal %d caught!  That's bad!\n", sig);
45}
46
47int
48main(int argc, char **argv)
49{
50    int choice, scroll, curr, max;
51
52    /* Catch fatal signals and complain about them if running as init */
53    if (getpid() == 1) {
54	signal(SIGBUS, screech);
55	signal(SIGSEGV, screech);
56    }
57
58    /* We don't work too well when running as non-root anymore */
59    if (geteuid() != 0) {
60	fprintf(stderr, "Error: This utility should only be run as root.\n");
61	return 1;
62    }
63
64    /* Set up whatever things need setting up */
65    systemInitialize(argc, argv);
66
67    /* Set default flag and variable values */
68    installVarDefaults(NULL);
69    installEnvironment();
70
71    if (argc > 1 && !strcmp(argv[1], "-fake")) {
72	variable_set2(VAR_DEBUG, "YES");
73	Fake = TRUE;
74	msgConfirm("I'll be just faking it from here on out, OK?");
75    }
76
77    /* Try to preserve our scroll-back buffer */
78    if (OnVTY) {
79	for (curr = 0; curr < 25; curr++)
80	    putchar('\n');
81    }
82    /* Move stderr aside */
83    if (DebugFD)
84	dup2(DebugFD, 2);
85
86    /* Probe for all relevant devices on the system */
87    deviceGetAll();
88
89    /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
90    if (!RunningAsInit) {
91	int i, start_arg;
92
93	if (!strstr(argv[0], "sysinstall"))
94	    start_arg = 0;
95	else if (Fake)
96	    start_arg = 2;
97	else
98	    start_arg = 1;
99	for (i = start_arg; i < argc; i++) {
100	    if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS)
101		systemShutdown(1);
102	}
103	if (argc > start_arg)
104	    systemShutdown(0);
105    }
106    else {
107	FILE *fp;
108	char buf[BUFSIZ];
109
110	fp = fopen("install.cfg", "r");
111	if (fp) {
112	    msgNotify("Loading pre-configuration file");
113	    while (fgets(buf, sizeof buf, fp)) {
114		if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) {
115		    msgDebug("Command `%s' failed - rest of script aborted.\n", buf);
116		    break;
117		}
118	    }
119	    fclose(fp);
120	}
121    }
122
123    /* Begin user dialog at outer menu */
124    dialog_clear();
125    while (1) {
126	choice = scroll = curr = max = 0;
127	dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE);
128	if (getpid() != 1 || !msgYesNo("Are you sure you wish to exit?  The system will reboot\n"
129				       "(be sure to remove any floppies from the drives)."))
130	    break;
131    }
132
133    /* Say goodnight, Gracie */
134    systemShutdown(0);
135
136    return 0; /* We should never get here */
137}
138