main.c revision 15091
176195Sbrian/*
276195Sbrian * The new sysinstall program.
376358Sbrian *
476358Sbrian * This is probably the last attempt in the `sysinstall' line, the next
576358Sbrian * generation being slated for what's essentially a complete rewrite.
676195Sbrian *
776195Sbrian * $Id: main.c,v 1.15 1995/12/07 10:33:55 peter Exp $
876195Sbrian *
976195Sbrian * Copyright (c) 1995
1076195Sbrian *	Jordan Hubbard.  All rights reserved.
1176195Sbrian *
1276195Sbrian * Redistribution and use in source and binary forms, with or without
1376195Sbrian * modification, are permitted provided that the following conditions
1476195Sbrian * are met:
1576195Sbrian * 1. Redistributions of source code must retain the above copyright
1676195Sbrian *    notice, this list of conditions and the following disclaimer,
1776195Sbrian *    verbatim and that no modifications are made prior to this
1876195Sbrian *    point in the file.
1976195Sbrian * 2. Redistributions in binary form must reproduce the above copyright
2076195Sbrian *    notice, this list of conditions and the following disclaimer in the
2176195Sbrian *    documentation and/or other materials provided with the distribution.
2276195Sbrian * 3. All advertising materials mentioning features or use of this software
2376195Sbrian *    must display the following acknowledgement:
2476195Sbrian *	This product includes software developed by Jordan Hubbard
2576195Sbrian *	for the FreeBSD Project.
2676195Sbrian * 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
2776195Sbrian *    endorse or promote products derived from this software without specific
2876195Sbrian *    prior written permission.
2976195Sbrian *
3076195Sbrian * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
3176195Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3276195Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3376195Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
3476195Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3576195Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3676195Sbrian * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
3776195Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3876195Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3976195Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4076195Sbrian * SUCH DAMAGE.
4176195Sbrian *
4276195Sbrian */
4376195Sbrian
4476195Sbrian#include "sysinstall.h"
4576195Sbrian#include <stdio.h>
4676195Sbrian#include <sys/signal.h>
4776195Sbrian
4876195Sbrianstatic void
4976195Sbrianscreech(int sig)
5076195Sbrian{
5176195Sbrian    fprintf(stderr, "\007Fatal signal %d caught!  I'm dead..\n", sig);
5276195Sbrian    pause();
5376195Sbrian}
5476195Sbrian
5576195Sbrianint
5676195Sbrianmain(int argc, char **argv)
5776195Sbrian{
5876195Sbrian    int choice, scroll, curr, max;
5976195Sbrian
6076195Sbrian    /* Catch fatal signals and complain about them if running as init */
6176195Sbrian    if (getpid() == 1) {
6276195Sbrian	signal(SIGBUS, screech);
6376195Sbrian	signal(SIGSEGV, screech);
6476195Sbrian    }
6576195Sbrian
6676195Sbrian    /* We don't work too well when running as non-root anymore */
6776195Sbrian    if (geteuid() != 0) {
6876195Sbrian	fprintf(stderr, "Error: This utility should only be run as root.\n");
6976195Sbrian	return 1;
7076195Sbrian    }
7176195Sbrian
7276195Sbrian    /* Set up whatever things need setting up */
7376195Sbrian    systemInitialize(argc, argv);
7476195Sbrian
7576195Sbrian    /* Try to preserve our scroll-back buffer */
7676195Sbrian    if (OnVTY)
7776195Sbrian	for (curr = 0; curr < 25; curr++)
7876195Sbrian	    putchar('\n');
7976195Sbrian
8076195Sbrian    /* Probe for all relevant devices on the system */
8176195Sbrian    deviceGetAll();
8276195Sbrian
8376195Sbrian    /* Set default flag and variable values */
8476195Sbrian    installVarDefaults(NULL);
8576195Sbrian
8676195Sbrian    /* Begin user dialog at outer menu */
8776195Sbrian    while (1) {
8876195Sbrian	choice = scroll = curr = max = 0;
8976195Sbrian	dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max);
9076195Sbrian	if (getpid() != 1 || !msgYesNo("Are you sure you wish to exit?  The system will reboot\n"
9176195Sbrian				       "(be sure to remove any floppies from the drives)."))
9276358Sbrian	    break;
9376195Sbrian    }
9476195Sbrian
9576358Sbrian    /* Say goodnight, Gracie */
9676195Sbrian    systemShutdown();
9776195Sbrian
9876195Sbrian    /* If we're running as init, we should never get here */
9976195Sbrian    return 0;
10076195Sbrian}
10176195Sbrian