main.c revision 26456
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.45 1997/04/20 16:46:31 jkh 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 longjmp(BailOut, sig); 46} 47 48int 49main(int argc, char **argv) 50{ 51 int choice, scroll, curr, max, status; 52 53 /* Catch fatal signals and complain about them if running as init */ 54 if (getpid() == 1) { 55 signal(SIGBUS, screech); 56 signal(SIGSEGV, screech); 57 } 58 59 /* We don't work too well when running as non-root anymore */ 60 if (geteuid() != 0) { 61 fprintf(stderr, "Error: This utility should only be run as root.\n"); 62 return 1; 63 } 64 65 /* Set up whatever things need setting up */ 66 systemInitialize(argc, argv); 67 68 /* Set default flag and variable values */ 69 installVarDefaults(NULL); 70 installEnvironment(); 71 72 if (argc > 1 && !strcmp(argv[1], "-fake")) { 73 variable_set2(VAR_DEBUG, "YES"); 74 Fake = TRUE; 75 msgConfirm("I'll be just faking it from here on out, OK?"); 76 } 77 78 /* Try to preserve our scroll-back buffer */ 79 if (OnVTY) { 80 for (curr = 0; curr < 25; curr++) 81 putchar('\n'); 82 } 83 /* Move stderr aside */ 84 if (DebugFD) 85 dup2(DebugFD, 2); 86 87 /* Probe for all relevant devices on the system */ 88 deviceGetAll(); 89 90 /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */ 91 if (!RunningAsInit) { 92 int i, start_arg; 93 94 if (!strstr(argv[0], "sysinstall")) 95 start_arg = 0; 96 else if (Fake) 97 start_arg = 2; 98 else 99 start_arg = 1; 100 for (i = start_arg; i < argc; i++) { 101 if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS) 102 systemShutdown(1); 103 } 104 if (argc > start_arg) 105 systemShutdown(0); 106 } 107 else { 108 FILE *fp; 109 char buf[BUFSIZ]; 110 111 fp = fopen("install.cfg", "r"); 112 if (fp) { 113 msgNotify("Loading pre-configuration file"); 114 variable_set2(VAR_NONINTERACTIVE, "YES"); 115 while (fgets(buf, sizeof buf, fp)) { 116 if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) { 117 msgDebug("Command `%s' failed - rest of script aborted.\n", buf); 118 break; 119 } 120 } 121 fclose(fp); 122 variable_unset(VAR_NONINTERACTIVE); 123 } 124 } 125 126 status = setjmp(BailOut); 127 if (status) { 128 msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n" 129 "this thing down! Please report this unfortunate incident\n" 130 "to jkh@FreeBSD.org. If you can reproduce the problem, please\n" 131 "also turn Debug on in the Options menu for the extra information\n" 132 "it provides in debugging problems like this. Thanks!", status); 133 systemShutdown(status); 134 } 135 136 /* Begin user dialog at outer menu */ 137 dialog_clear(); 138 while (1) { 139 choice = scroll = curr = max = 0; 140 dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE); 141 if (getpid() != 1 || !msgYesNo("Are you sure you wish to exit? The system will reboot\n" 142 "(be sure to remove any floppies from the drives).")) 143 break; 144 } 145 146 /* Say goodnight, Gracie */ 147 systemShutdown(0); 148 149 return 0; /* We should never get here */ 150} 151