2002-06-06 13:53:22 +04:00
|
|
|
/* $NetBSD: main.c,v 1.27 2002/06/06 09:53:22 lukem Exp $ */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1999-06-20 10:08:13 +04:00
|
|
|
* This product includes software developed for the NetBSD Project by
|
1997-09-27 03:02:53 +04:00
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* main sysinst program. */
|
|
|
|
|
1998-10-25 22:15:04 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/uio.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <stdio.h>
|
1997-11-21 15:08:06 +03:00
|
|
|
#include <signal.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <curses.h>
|
1997-11-04 04:39:03 +03:00
|
|
|
#include <unistd.h>
|
1998-10-25 22:15:04 +03:00
|
|
|
#include <fcntl.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
#define MAIN
|
|
|
|
#include "defs.h"
|
|
|
|
#include "md.h"
|
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
1998-10-25 22:15:04 +03:00
|
|
|
#include "txtwalk.h"
|
1997-09-27 03:02:53 +04:00
|
|
|
|
2000-12-22 13:12:12 +03:00
|
|
|
int main (int argc, char **argv);
|
|
|
|
static void usage (void);
|
|
|
|
static void miscsighandler (int);
|
|
|
|
static void ttysighandler (int);
|
|
|
|
static void cleanup (void);
|
2002-06-06 13:53:22 +04:00
|
|
|
static void set_defaults (void);
|
2000-12-22 13:12:12 +03:00
|
|
|
static void process_f_flag (char *);
|
1997-12-05 16:38:59 +03:00
|
|
|
|
|
|
|
static int exit_cleanly = 0; /* Did we finish nicely? */
|
1999-01-21 11:02:17 +03:00
|
|
|
int logging; /* are we logging everything? */
|
|
|
|
int scripting; /* are we building a script? */
|
|
|
|
FILE *log; /* log file */
|
|
|
|
FILE *script; /* script file */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1999-03-31 04:44:48 +04:00
|
|
|
#ifdef DEBUG
|
2000-12-22 13:12:12 +03:00
|
|
|
extern int log_flip (void);
|
1999-03-31 04:44:48 +04:00
|
|
|
#endif
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
WINDOW *win;
|
1997-11-04 04:39:03 +03:00
|
|
|
int ch;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
logging = 0; /* shut them off unless turned on by the user */
|
1999-03-31 04:44:48 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
log_flip();
|
|
|
|
#endif
|
1999-01-21 11:02:17 +03:00
|
|
|
scripting = 0;
|
|
|
|
|
1997-11-01 02:00:32 +03:00
|
|
|
/* Check for TERM ... */
|
|
|
|
if (!getenv("TERM")) {
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)fprintf(stderr,
|
1997-11-04 04:39:03 +03:00
|
|
|
"sysinst: environment varible TERM not set.\n");
|
1997-11-01 02:00:32 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1997-11-04 04:39:03 +03:00
|
|
|
/* argv processing */
|
1998-10-25 22:15:04 +03:00
|
|
|
while ((ch = getopt(argc, argv, "r:f:")) != -1)
|
1997-11-04 04:39:03 +03:00
|
|
|
switch(ch) {
|
|
|
|
case 'r':
|
|
|
|
/* Release name other than compiled in release. */
|
1998-06-20 17:05:48 +04:00
|
|
|
strncpy(rel, optarg, SSTRSIZE);
|
1997-11-04 04:39:03 +03:00
|
|
|
break;
|
1998-10-25 22:15:04 +03:00
|
|
|
case 'f':
|
|
|
|
/* Definition file to read. */
|
|
|
|
process_f_flag (optarg);
|
|
|
|
break;
|
1997-11-04 04:39:03 +03:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
2000-10-02 13:26:26 +04:00
|
|
|
|
2002-06-06 13:53:22 +04:00
|
|
|
set_defaults();
|
|
|
|
|
2000-10-02 13:26:26 +04:00
|
|
|
md_init();
|
1997-11-04 04:39:03 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
/* initialize message window */
|
1999-06-19 10:52:22 +04:00
|
|
|
if (menu_init()) {
|
|
|
|
__menu_initerror();
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-17 05:06:47 +03:00
|
|
|
|
1999-06-19 10:52:22 +04:00
|
|
|
/*
|
|
|
|
* XXX the following is bogus. if screen is too small, message
|
|
|
|
* XXX window will be overwritten by menus.
|
|
|
|
*/
|
|
|
|
win = newwin(getmaxy(stdscr) - 2, getmaxx(stdscr) - 2, 1, 1);
|
2001-11-17 05:06:47 +03:00
|
|
|
if (has_colors()) {
|
|
|
|
/*
|
|
|
|
* XXX This color trick should be done so much better,
|
|
|
|
* but is it worth it?
|
|
|
|
*/
|
|
|
|
wbkgd(win, COLOR_PAIR(1));
|
|
|
|
wattrset(win, COLOR_PAIR(1));
|
|
|
|
}
|
1999-06-20 08:17:57 +04:00
|
|
|
if (win == NULL) {
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"sysinst: screen too small\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-06-22 19:04:15 +04:00
|
|
|
if (msg_window(win) != 0) {
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"sysinst: couldn't initialize message window\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1999-06-22 04:43:57 +04:00
|
|
|
/* Watch for signals and clean up */
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)atexit(cleanup);
|
1999-06-22 04:43:57 +04:00
|
|
|
(void)signal(SIGINT, ttysighandler);
|
|
|
|
(void)signal(SIGQUIT, ttysighandler);
|
|
|
|
(void)signal(SIGHUP, miscsighandler);
|
1997-11-21 15:08:06 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
/* Menu processing */
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_netbsd);
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1997-12-05 16:38:59 +03:00
|
|
|
exit_cleanly = 1;
|
|
|
|
exit(0);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-11-04 04:39:03 +03:00
|
|
|
|
1997-12-04 12:05:35 +03:00
|
|
|
/* toplevel menu handler ... */
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
toplevel()
|
1997-12-04 12:05:35 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
2000-05-11 06:23:53 +04:00
|
|
|
/* Display banner message in (english, francais, deutsch..) */
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_hello);
|
2000-12-03 04:54:46 +03:00
|
|
|
msg_display_add(MSG_md_hello);
|
|
|
|
msg_display_add(MSG_thanks);
|
1997-12-04 12:05:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Undo any stateful side-effects of previous menu choices.
|
|
|
|
* XXX must be idempotent, since we get run each time the main
|
|
|
|
* menu is displayed.
|
|
|
|
*/
|
|
|
|
unwind_mounts();
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-04 04:39:03 +03:00
|
|
|
/* The usage ... */
|
|
|
|
|
1997-12-05 16:38:59 +03:00
|
|
|
static void
|
1998-06-20 17:05:48 +04:00
|
|
|
usage()
|
1997-11-04 04:39:03 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
|
|
|
(void)fprintf(stderr, msg_string(MSG_usage));
|
1997-11-04 04:39:03 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
1997-11-21 15:08:06 +03:00
|
|
|
|
|
|
|
/* ARGSUSED */
|
1997-12-05 16:38:59 +03:00
|
|
|
static void
|
1999-06-22 04:43:57 +04:00
|
|
|
miscsighandler(signo)
|
|
|
|
int signo;
|
1997-11-21 15:08:06 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1999-06-18 12:54:28 +04:00
|
|
|
/*
|
|
|
|
* we need to cleanup(), but it was already scheduled with atexit(),
|
|
|
|
* so it'll be invoked on exit().
|
|
|
|
*/
|
1997-11-21 15:08:06 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
1997-12-05 16:38:59 +03:00
|
|
|
|
1999-06-22 04:43:57 +04:00
|
|
|
static void
|
|
|
|
ttysighandler(signo)
|
|
|
|
int signo;
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we want to ignore a TTY signal (SIGINT or SIGQUIT), then we
|
|
|
|
* just return. If we want to forward a TTY signal, we forward it
|
|
|
|
* to the specified process group.
|
|
|
|
*
|
|
|
|
* This functionality is used when setting up and displaying child
|
|
|
|
* output so that the child gets the signal and presumably dies,
|
|
|
|
* but sysinst continues. We use this rather than actually ignoring
|
|
|
|
* the signals, because that will be be passed on to a child
|
|
|
|
* through fork/exec, whereas special handlers get reset on exec..
|
|
|
|
*/
|
|
|
|
if (ttysig_ignore)
|
|
|
|
return;
|
|
|
|
if (ttysig_forward) {
|
|
|
|
killpg(ttysig_forward, signo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we need to cleanup(), but it was already scheduled with atexit(),
|
|
|
|
* so it'll be invoked on exit().
|
|
|
|
*/
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1997-12-05 16:38:59 +03:00
|
|
|
static void
|
1998-06-20 17:05:48 +04:00
|
|
|
cleanup()
|
1997-12-05 16:38:59 +03:00
|
|
|
{
|
1999-01-21 11:02:17 +03:00
|
|
|
time_t tloc;
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
(void)time(&tloc);
|
1997-12-05 16:38:59 +03:00
|
|
|
unwind_mounts();
|
2000-10-12 03:47:55 +04:00
|
|
|
run_prog(0, NULL, "/sbin/umount /mnt2");
|
1999-01-21 11:02:17 +03:00
|
|
|
endwin();
|
|
|
|
if (logging) {
|
|
|
|
fprintf(log, "Log ended at: %s\n", asctime(localtime(&tloc)));
|
|
|
|
fflush(log);
|
|
|
|
fclose(log);
|
|
|
|
}
|
|
|
|
if (scripting) {
|
|
|
|
fprintf(script, "# Script ended at: %s\n", asctime(localtime(&tloc)));
|
|
|
|
fflush(script);
|
|
|
|
fclose(script);
|
|
|
|
}
|
|
|
|
|
1997-12-05 16:38:59 +03:00
|
|
|
if (!exit_cleanly)
|
1999-06-18 12:54:28 +04:00
|
|
|
fprintf(stderr, "\n\nsysinst terminated.\n");
|
1997-12-05 16:38:59 +03:00
|
|
|
}
|
1998-10-25 22:15:04 +03:00
|
|
|
|
2002-06-06 13:53:22 +04:00
|
|
|
static void
|
|
|
|
set_defaults(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set defaults for ftp_dir & cdrom_dir, by appending ftp_prefix.
|
|
|
|
* This occurs even when the settings are read in from
|
|
|
|
* "-f definition-file".
|
|
|
|
*
|
|
|
|
* Default values (can be changed in definition-file):
|
|
|
|
* ftp_dir SYSINST_FTP_DIR
|
|
|
|
* SYSINST_FTP_DIR "pub/NetBSD/NetBSD-" + REL + "/" MACH
|
|
|
|
*
|
|
|
|
* cdrom_dir SYSINST_CDROM_DIR
|
|
|
|
# SYSINST_CDROM_DIR "/" + MACH
|
|
|
|
*
|
|
|
|
* ftp_prefix "/binary/sets"
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ftp_dir += ftp_prefix */
|
|
|
|
strncat(ftp_dir, ftp_prefix, STRSIZE - strlen(ftp_dir));
|
|
|
|
|
|
|
|
/* cdrom_dir += ftp_prefix */
|
|
|
|
strncat(cdrom_dir, ftp_prefix, STRSIZE - strlen(cdrom_dir));
|
|
|
|
}
|
|
|
|
|
1998-10-25 22:15:04 +03:00
|
|
|
|
|
|
|
/* Stuff for processing the -f file argument. */
|
|
|
|
|
|
|
|
/* Data definitions ... */
|
|
|
|
|
|
|
|
static char *rel_ptr = rel;
|
|
|
|
static char *machine_ptr = machine;
|
|
|
|
static char *dist_dir_ptr = dist_dir;
|
|
|
|
static char *ext_dir_ptr = ext_dir;
|
|
|
|
static char *ftp_host_ptr = ftp_host;
|
|
|
|
static char *ftp_dir_ptr = ftp_dir;
|
|
|
|
static char *ftp_prefix_ptr = ftp_prefix;
|
|
|
|
static char *ftp_user_ptr = ftp_user;
|
|
|
|
static char *ftp_pass_ptr = ftp_pass;
|
2001-06-07 03:12:48 +04:00
|
|
|
static char *ftp_proxy_ptr = ftp_proxy;
|
1998-10-25 22:15:04 +03:00
|
|
|
static char *nfs_host_ptr = nfs_host;
|
|
|
|
static char *nfs_dir_ptr = nfs_dir;
|
|
|
|
static char *cdrom_dev_ptr = cdrom_dev;
|
|
|
|
static char *cdrom_dir_ptr = cdrom_dir;
|
|
|
|
static char *localfs_dev_ptr = localfs_dev;
|
|
|
|
static char *localfs_fs_ptr = localfs_fs;
|
|
|
|
static char *localfs_dir_ptr = localfs_dir;
|
|
|
|
static char *targetroot_mnt_ptr = targetroot_mnt;
|
|
|
|
static char *distfs_mnt_ptr = distfs_mnt;
|
|
|
|
static char *dist_postfix_ptr = dist_postfix;
|
|
|
|
|
|
|
|
struct lookfor fflagopts[] = {
|
|
|
|
{"release", "release = %s", "a $0", &rel_ptr, 1, SSTRSIZE, NULL},
|
|
|
|
{"machine", "machine = %s", "a $0", &machine_ptr, 1, SSTRSIZE, NULL},
|
|
|
|
{"dist dir", "dist dir = %s", "a $0", &dist_dir_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"ext dir", "ext dir = %s", "a $0", &ext_dir_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"ftp host", "ftp host = %s", "a $0", &ftp_host_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"ftp dir", "ftp dir = %s", "a $0", &ftp_dir_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"ftp prefix", "ftp prefix = %s", "a $0", &ftp_prefix_ptr, 1,
|
|
|
|
STRSIZE, NULL},
|
|
|
|
{"ftp user", "ftp user = %s", "a $0", &ftp_user_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"ftp pass", "ftp pass = %s", "a $0", &ftp_pass_ptr, 1, STRSIZE, NULL},
|
2001-06-07 03:12:48 +04:00
|
|
|
{"ftp proxy", "ftp proxy = %s", "a $0", &ftp_proxy_ptr, 1, STRSIZE,
|
|
|
|
NULL},
|
1998-10-25 22:15:04 +03:00
|
|
|
{"nfs host", "nfs host = %s", "a $0", &nfs_host_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"nfs dir", "ftp dir = %s", "a $0", &nfs_dir_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"cd dev", "cd dev = %s", "a $0", &cdrom_dev_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"cd dir", "cd dir = %s", "a $0", &cdrom_dir_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"local dev", "local dev = %s", "a $0", &localfs_dev_ptr, 1, STRSIZE,
|
|
|
|
NULL},
|
|
|
|
{"local fs", "local fs = %s", "a $0", &localfs_fs_ptr, 1, STRSIZE,
|
|
|
|
NULL},
|
|
|
|
{"local dir", "local dir = %s", "a $0", &localfs_dir_ptr, 1, STRSIZE,
|
|
|
|
NULL},
|
|
|
|
{"targetroot mount", "targetroot mount = %s", "a $0",
|
|
|
|
&targetroot_mnt_ptr, 1, STRSIZE, NULL},
|
|
|
|
{"distfs mount", "distfs mount = %s", "a $0", &distfs_mnt_ptr, 1,
|
|
|
|
STRSIZE, NULL},
|
|
|
|
{"dist postfix", "dist postfix = %s", "a $0", &dist_postfix_ptr, 1,
|
|
|
|
STRSIZE, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* process function ... */
|
|
|
|
|
|
|
|
void process_f_flag (char *f_name)
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
struct stat statinfo;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* stat the file (error reported) */
|
|
|
|
|
|
|
|
if (stat(f_name, &statinfo) < 0) {
|
|
|
|
perror (f_name); /* XXX -- better message? */
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((statinfo.st_mode & S_IFMT) != S_IFREG) {
|
|
|
|
fprintf (stderr, msg_string(MSG_not_regular_file), f_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate buffer (error reported) */
|
|
|
|
buffer = (char *) malloc ((size_t)statinfo.st_size+1);
|
|
|
|
if (buffer == NULL) {
|
|
|
|
fprintf (stderr, msg_string(MSG_out_of_memory));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open the file */
|
|
|
|
fd = open (f_name, O_RDONLY, 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf (stderr, msg_string(MSG_config_open_error), f_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the file */
|
|
|
|
if (read (fd,buffer,(size_t)statinfo.st_size) != (size_t)statinfo.st_size) {
|
|
|
|
fprintf (stderr, msg_string(MSG_config_read_error), f_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
buffer[statinfo.st_size] = 0;
|
|
|
|
|
|
|
|
/* close the file */
|
|
|
|
close (fd);
|
|
|
|
|
|
|
|
/* Walk the buffer */
|
|
|
|
walk (buffer, (size_t)statinfo.st_size, fflagopts,
|
|
|
|
sizeof(fflagopts)/sizeof(struct lookfor));
|
|
|
|
|
|
|
|
/* free the buffer */
|
|
|
|
free (buffer);
|
|
|
|
}
|