Home | History | Annotate | Line # | Download | only in sysinst
main.c revision 1.7.8.1
      1  1.7.8.1  pgoyette /*	$NetBSD: main.c,v 1.7.8.1 2018/09/30 01:46:01 pgoyette Exp $	*/
      2      1.1  dholland 
      3      1.1  dholland /*
      4      1.1  dholland  * Copyright 1997 Piermont Information Systems Inc.
      5      1.1  dholland  * All rights reserved.
      6      1.1  dholland  *
      7      1.1  dholland  * Written by Philip A. Nelson for Piermont Information Systems Inc.
      8      1.1  dholland  *
      9      1.1  dholland  * Redistribution and use in source and binary forms, with or without
     10      1.1  dholland  * modification, are permitted provided that the following conditions
     11      1.1  dholland  * are met:
     12      1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     13      1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     14      1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     16      1.1  dholland  *    documentation and/or other materials provided with the distribution.
     17      1.1  dholland  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
     18      1.1  dholland  *    or promote products derived from this software without specific prior
     19      1.1  dholland  *    written permission.
     20      1.1  dholland  *
     21      1.1  dholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
     22      1.1  dholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23      1.1  dholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24      1.1  dholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
     25      1.1  dholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26      1.1  dholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27      1.1  dholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28      1.1  dholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29      1.1  dholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30      1.1  dholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31      1.1  dholland  * THE POSSIBILITY OF SUCH DAMAGE.
     32      1.1  dholland  *
     33      1.1  dholland  */
     34      1.1  dholland 
     35      1.1  dholland /* main sysinst program. */
     36      1.1  dholland 
     37      1.1  dholland #include <sys/types.h>
     38      1.1  dholland #include <sys/stat.h>
     39      1.3    martin #include <sys/syslimits.h>
     40      1.1  dholland #include <sys/uio.h>
     41      1.1  dholland #include <stdio.h>
     42      1.1  dholland #include <signal.h>
     43      1.1  dholland #include <curses.h>
     44      1.1  dholland #include <unistd.h>
     45      1.1  dholland #include <fcntl.h>
     46      1.1  dholland #include <dirent.h>
     47      1.1  dholland #include <locale.h>
     48      1.1  dholland 
     49      1.1  dholland #include "defs.h"
     50      1.1  dholland #include "md.h"
     51      1.1  dholland #include "msg_defs.h"
     52      1.1  dholland #include "menu_defs.h"
     53      1.1  dholland #include "txtwalk.h"
     54      1.1  dholland 
     55      1.1  dholland static void select_language(void);
     56      1.1  dholland __dead static void usage(void);
     57      1.1  dholland __dead static void miscsighandler(int);
     58      1.1  dholland static void ttysighandler(int);
     59      1.1  dholland static void cleanup(void);
     60      1.1  dholland static void process_f_flag(char *);
     61      1.1  dholland 
     62      1.1  dholland static int exit_cleanly = 0;	/* Did we finish nicely? */
     63      1.1  dholland FILE *logfp;			/* log file */
     64      1.1  dholland FILE *script;			/* script file */
     65      1.1  dholland 
     66      1.1  dholland #ifdef DEBUG
     67      1.1  dholland extern int log_flip(void);
     68      1.1  dholland #endif
     69      1.1  dholland 
     70      1.2    martin /* Definion for colors */
     71      1.2    martin 
     72      1.2    martin struct {
     73      1.2    martin 	unsigned int bg;
     74      1.2    martin 	unsigned int fg;
     75      1.2    martin } clr_arg;
     76      1.2    martin 
     77      1.1  dholland /* String defaults and stuff for processing the -f file argument. */
     78      1.1  dholland 
     79      1.2    martin static char bsddiskname[DISKNAME_SIZE]; /* default name for fist selected disk */
     80      1.2    martin 
     81      1.1  dholland struct f_arg {
     82      1.1  dholland 	const char *name;
     83      1.1  dholland 	const char *dflt;
     84      1.1  dholland 	char *var;
     85      1.1  dholland 	int size;
     86      1.1  dholland };
     87      1.1  dholland 
     88      1.1  dholland static const struct f_arg fflagopts[] = {
     89      1.1  dholland 	{"release", REL, rel, sizeof rel},
     90      1.1  dholland 	{"machine", MACH, machine, sizeof machine},
     91      1.1  dholland 	{"xfer dir", "/usr/INSTALL", xfer_dir, sizeof xfer_dir},
     92      1.1  dholland 	{"ext dir", "", ext_dir_bin, sizeof ext_dir_bin},
     93      1.1  dholland 	{"ext src dir", "", ext_dir_src, sizeof ext_dir_src},
     94  1.7.8.1  pgoyette 	{"ftp host", SYSINST_FTP_HOST, ftp.xfer_host[XFER_FTP], sizeof ftp.xfer_host[XFER_FTP]},
     95  1.7.8.1  pgoyette 	{"http host", SYSINST_HTTP_HOST, ftp.xfer_host[XFER_HTTP], sizeof ftp.xfer_host[XFER_HTTP]},
     96      1.1  dholland 	{"ftp dir", SYSINST_FTP_DIR, ftp.dir, sizeof ftp.dir},
     97      1.1  dholland 	{"ftp prefix", "/" MACH "/binary/sets", set_dir_bin, sizeof set_dir_bin},
     98      1.1  dholland 	{"ftp src prefix", "/source/sets", set_dir_src, sizeof set_dir_src},
     99      1.1  dholland 	{"ftp user", "ftp", ftp.user, sizeof ftp.user},
    100      1.1  dholland 	{"ftp pass", "", ftp.pass, sizeof ftp.pass},
    101      1.1  dholland 	{"ftp proxy", "", ftp.proxy, sizeof ftp.proxy},
    102      1.1  dholland 	{"nfs host", "", nfs_host, sizeof nfs_host},
    103      1.1  dholland 	{"nfs dir", "/bsd/release", nfs_dir, sizeof nfs_dir},
    104      1.1  dholland 	{"cd dev", 0, cdrom_dev, sizeof cdrom_dev}, /* default filled in init */
    105      1.1  dholland 	{"fd dev", "/dev/fd0a", fd_dev, sizeof fd_dev},
    106      1.1  dholland 	{"local dev", "", localfs_dev, sizeof localfs_dev},
    107      1.1  dholland 	{"local fs", "ffs", localfs_fs, sizeof localfs_fs},
    108      1.1  dholland 	{"local dir", "release", localfs_dir, sizeof localfs_dir},
    109      1.1  dholland 	{"targetroot mount", "/targetroot", targetroot_mnt, sizeof targetroot_mnt},
    110      1.1  dholland 	{"dist postfix", ".tgz", dist_postfix, sizeof dist_postfix},
    111      1.1  dholland 	{"diskname", "mydisk", bsddiskname, sizeof bsddiskname},
    112  1.7.8.1  pgoyette 	{"pkg host", SYSINST_PKG_HOST, pkg.xfer_host[XFER_FTP], sizeof pkg.xfer_host[XFER_FTP]},
    113  1.7.8.1  pgoyette 	{"pkg http host", SYSINST_PKG_HTTP_HOST, pkg.xfer_host[XFER_HTTP], sizeof pkg.xfer_host[XFER_HTTP]},
    114      1.1  dholland 	{"pkg dir", SYSINST_PKG_DIR, pkg.dir, sizeof pkg.dir},
    115  1.7.8.1  pgoyette 	{"pkg prefix", "/" MACH "/" PKG_SUBDIR "/All", pkg_dir, sizeof pkg_dir},
    116      1.1  dholland 	{"pkg user", "ftp", pkg.user, sizeof pkg.user},
    117      1.1  dholland 	{"pkg pass", "", pkg.pass, sizeof pkg.pass},
    118      1.1  dholland 	{"pkg proxy", "", pkg.proxy, sizeof pkg.proxy},
    119  1.7.8.1  pgoyette 	{"pkgsrc host", SYSINST_PKGSRC_HOST, pkgsrc.xfer_host[XFER_FTP], sizeof pkgsrc.xfer_host[XFER_FTP]},
    120  1.7.8.1  pgoyette 	{"pkgsrc http host", SYSINST_PKGSRC_HTTP_HOST, pkgsrc.xfer_host[XFER_HTTP], sizeof pkgsrc.xfer_host[XFER_HTTP]},
    121      1.1  dholland 	{"pkgsrc dir", "", pkgsrc.dir, sizeof pkgsrc.dir},
    122      1.1  dholland 	{"pkgsrc prefix", "pub/pkgsrc/stable", pkgsrc_dir, sizeof pkgsrc_dir},
    123      1.1  dholland 	{"pkgsrc user", "ftp", pkgsrc.user, sizeof pkgsrc.user},
    124      1.1  dholland 	{"pkgsrc pass", "", pkgsrc.pass, sizeof pkgsrc.pass},
    125      1.1  dholland 	{"pkgsrc proxy", "", pkgsrc.proxy, sizeof pkgsrc.proxy},
    126      1.1  dholland 
    127      1.1  dholland 	{NULL, NULL, NULL, 0}
    128      1.1  dholland };
    129      1.1  dholland 
    130      1.1  dholland static void
    131      1.1  dholland init(void)
    132      1.1  dholland {
    133      1.1  dholland 	const struct f_arg *arg;
    134      1.2    martin 
    135      1.1  dholland 	sizemult = 1;
    136      1.2    martin 	multname = msg_string(MSG_secname);
    137      1.1  dholland 	tmp_ramdisk_size = 0;
    138      1.1  dholland 	clean_xfer_dir = 0;
    139      1.1  dholland 	mnt2_mounted = 0;
    140      1.1  dholland 	fd_type = "msdos";
    141      1.2    martin 	layoutkind = LY_SETNEW;
    142      1.2    martin 
    143      1.2    martin 	pm_head = (struct pm_head_t) SLIST_HEAD_INITIALIZER(pm_head);
    144      1.2    martin 	SLIST_INIT(&pm_head);
    145      1.2    martin 	pm_new = malloc (sizeof (pm_devs_t));
    146      1.2    martin 	memset(pm_new, 0, sizeof *pm_new);
    147      1.1  dholland 
    148      1.1  dholland 	for (arg = fflagopts; arg->name != NULL; arg++) {
    149      1.1  dholland 		if (arg->var == cdrom_dev)
    150      1.1  dholland 			strlcpy(arg->var, get_default_cdrom(), arg->size);
    151      1.1  dholland 		else
    152      1.1  dholland 			strlcpy(arg->var, arg->dflt, arg->size);
    153      1.1  dholland 	}
    154      1.2    martin 	strlcpy(pm_new->bsddiskname, bsddiskname, sizeof pm_new->bsddiskname);
    155  1.7.8.1  pgoyette 	pkg.xfer = pkgsrc.xfer = XFER_HTTP;
    156      1.2    martin 
    157      1.2    martin 	clr_arg.bg=COLOR_BLUE;
    158      1.2    martin 	clr_arg.fg=COLOR_WHITE;
    159      1.1  dholland }
    160      1.1  dholland 
    161      1.1  dholland __weakref_visible void prelim_menu(void)
    162      1.1  dholland     __weak_reference(md_prelim_menu);
    163      1.1  dholland 
    164      1.1  dholland int
    165      1.1  dholland main(int argc, char **argv)
    166      1.1  dholland {
    167      1.1  dholland 	int ch;
    168      1.1  dholland 
    169      1.1  dholland 	init();
    170      1.1  dholland #ifdef DEBUG
    171      1.1  dholland 	log_flip();
    172      1.1  dholland #endif
    173      1.2    martin 
    174      1.1  dholland 	/* Check for TERM ... */
    175      1.1  dholland 	if (!getenv("TERM")) {
    176      1.1  dholland 		(void)fprintf(stderr,
    177      1.1  dholland 			 "sysinst: environment variable TERM not set.\n");
    178      1.1  dholland 		exit(4);
    179      1.1  dholland 	}
    180      1.1  dholland 
    181      1.1  dholland 	/* argv processing */
    182  1.7.8.1  pgoyette 	while ((ch = getopt(argc, argv, "Dr:f:C:"
    183  1.7.8.1  pgoyette #ifndef NO_PARTMAN
    184  1.7.8.1  pgoyette 	    "p"
    185  1.7.8.1  pgoyette #endif
    186  1.7.8.1  pgoyette 	    )) != -1)
    187      1.1  dholland 		switch(ch) {
    188      1.1  dholland 		case 'D':	/* set to get past certain errors in testing */
    189      1.1  dholland 			debug = 1;
    190      1.1  dholland 			break;
    191      1.1  dholland 		case 'r':
    192      1.1  dholland 			/* Release name other than compiled in release. */
    193      1.1  dholland 			strncpy(rel, optarg, sizeof rel);
    194      1.1  dholland 			break;
    195      1.1  dholland 		case 'f':
    196      1.1  dholland 			/* Definition file to read. */
    197      1.1  dholland 			process_f_flag(optarg);
    198      1.1  dholland 			break;
    199      1.2    martin 		case 'C':
    200      1.2    martin 			/* Define colors */
    201      1.2    martin 			sscanf(optarg, "%u:%u", &clr_arg.bg, &clr_arg.fg);
    202      1.2    martin 			break;
    203  1.7.8.1  pgoyette #ifndef NO_PARTMAN
    204      1.2    martin 		case 'p':
    205      1.2    martin 			/* Partition tool */
    206      1.2    martin 			partman_go = 1;
    207      1.2    martin 			break;
    208  1.7.8.1  pgoyette #endif
    209      1.1  dholland 		case '?':
    210      1.1  dholland 		default:
    211      1.1  dholland 			usage();
    212      1.1  dholland 		}
    213      1.1  dholland 
    214      1.1  dholland 	md_init();
    215      1.1  dholland 
    216      1.1  dholland 	/* initialize message window */
    217      1.1  dholland 	if (menu_init()) {
    218      1.1  dholland 		__menu_initerror();
    219      1.1  dholland 		exit(4);
    220      1.1  dholland 	}
    221      1.1  dholland 
    222      1.1  dholland 	/*
    223      1.1  dholland 	 * Put 'messages' in a window that has a one-character border
    224      1.1  dholland 	 * on the real screen.
    225      1.1  dholland 	 */
    226      1.2    martin 	mainwin = newwin(getmaxy(stdscr) - 2, getmaxx(stdscr) - 2, 1, 1);
    227      1.2    martin 	if (mainwin == NULL) {
    228      1.1  dholland 		(void)fprintf(stderr,
    229      1.1  dholland 			 "sysinst: screen too small\n");
    230      1.1  dholland 		exit(1);
    231      1.1  dholland 	}
    232      1.1  dholland 	if (has_colors()) {
    233      1.2    martin 		start_color();
    234      1.2    martin 		do_coloring(clr_arg.fg,clr_arg.bg);
    235      1.2    martin 	} else {
    236      1.2    martin 		remove_color_options();
    237      1.1  dholland 	}
    238      1.2    martin 	msg_window(mainwin);
    239      1.1  dholland 
    240      1.1  dholland 	/* Watch for signals and clean up */
    241      1.1  dholland 	(void)atexit(cleanup);
    242      1.1  dholland 	(void)signal(SIGINT, ttysighandler);
    243      1.1  dholland 	(void)signal(SIGQUIT, ttysighandler);
    244      1.1  dholland 	(void)signal(SIGHUP, miscsighandler);
    245      1.1  dholland 
    246      1.1  dholland 	/* redraw screen */
    247      1.1  dholland 	touchwin(stdscr);
    248      1.1  dholland 	refresh();
    249      1.1  dholland 
    250      1.1  dholland 	/* Ensure we have mountpoint for target filesystems */
    251      1.1  dholland 	mkdir(targetroot_mnt, S_IRWXU| S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH);
    252      1.1  dholland 
    253      1.1  dholland 	select_language();
    254      1.1  dholland 	get_kb_encoding();
    255      1.1  dholland 
    256      1.1  dholland #ifdef __weak_reference
    257      1.1  dholland 	/* if md wants to ask anything before we start, do it now */
    258      1.1  dholland 	if (prelim_menu != 0)
    259      1.1  dholland 		prelim_menu();
    260      1.1  dholland #endif
    261      1.1  dholland 
    262      1.1  dholland 	/* Menu processing */
    263      1.2    martin 	if (partman_go)
    264      1.2    martin 		partman();
    265      1.2    martin 	else
    266      1.2    martin 		process_menu(MENU_netbsd, NULL);
    267      1.1  dholland 
    268      1.1  dholland 	exit_cleanly = 1;
    269      1.1  dholland 	return 0;
    270      1.1  dholland }
    271      1.1  dholland 
    272      1.1  dholland static int
    273      1.1  dholland set_language(menudesc *m, void *arg)
    274      1.1  dholland {
    275      1.1  dholland 	char **fnames = arg;
    276      1.1  dholland 
    277      1.1  dholland 	msg_file(fnames[m->cursel]);
    278      1.1  dholland 	return 1;
    279      1.1  dholland }
    280      1.1  dholland 
    281      1.1  dholland static void
    282      1.1  dholland select_language(void)
    283      1.1  dholland {
    284      1.1  dholland 	DIR *dir;
    285      1.1  dholland 	struct dirent *dirent;
    286      1.1  dholland 	char **lang_msg, **fnames;
    287      1.3    martin 	char prefix[PATH_MAX], fname[PATH_MAX];
    288      1.1  dholland 	int max_lang = 16, num_lang = 0;
    289      1.1  dholland 	const char *cp;
    290      1.1  dholland 	menu_ent *opt = 0;
    291      1.1  dholland 	int lang_menu = -1;
    292      1.1  dholland 	int lang;
    293      1.1  dholland 
    294      1.3    martin #ifdef CATALOG_DIR
    295      1.3    martin 	strcpy(prefix, CATALOG_DIR "/");
    296      1.3    martin 	dir = opendir(CATALOG_DIR);
    297      1.3    martin 	if (!dir) {
    298      1.3    martin 		strcpy(prefix, "./");
    299      1.3    martin 		dir = opendir(".");
    300      1.3    martin 	}
    301      1.3    martin #else
    302      1.1  dholland 	dir = opendir(".");
    303      1.3    martin 	strcpy(prefix, "./");
    304      1.3    martin #endif
    305      1.1  dholland 	if (!dir)
    306      1.1  dholland 		return;
    307      1.1  dholland 
    308      1.1  dholland 	lang_msg = malloc(max_lang * sizeof *lang_msg);
    309      1.1  dholland 	fnames = malloc(max_lang * sizeof *fnames);
    310      1.1  dholland 	if (!lang_msg || !fnames)
    311      1.1  dholland 		goto done;
    312      1.1  dholland 
    313      1.1  dholland 	lang_msg[0] = strdup(msg_string(MSG_sysinst_message_language));
    314      1.1  dholland 	fnames[0] = 0;
    315      1.1  dholland 	num_lang = 1;
    316      1.1  dholland 
    317      1.1  dholland 	while ((dirent = readdir(dir)) != 0) {
    318      1.1  dholland 		if (memcmp(dirent->d_name, "sysinstmsgs.", 12))
    319      1.1  dholland 			continue;
    320      1.3    martin 		strcpy(fname, prefix);
    321      1.3    martin 		strcat(fname, dirent->d_name);
    322      1.3    martin 		if (msg_file(fname))
    323      1.1  dholland 			continue;
    324      1.1  dholland 		cp = msg_string(MSG_sysinst_message_language);
    325      1.1  dholland 		if (!strcmp(cp, lang_msg[0]))
    326      1.1  dholland 			continue;
    327      1.1  dholland 		if (num_lang == max_lang) {
    328      1.1  dholland 			char **new;
    329      1.1  dholland 			max_lang *= 2;
    330      1.1  dholland 			new = realloc(lang_msg, max_lang * sizeof *lang_msg);
    331      1.1  dholland 			if (!new)
    332      1.1  dholland 				break;
    333      1.1  dholland 			lang_msg = new;
    334      1.1  dholland 			new = realloc(fnames, max_lang * sizeof *fnames);
    335      1.1  dholland 			if (!new)
    336      1.1  dholland 				break;
    337      1.1  dholland 			fnames = new;
    338      1.1  dholland 		}
    339      1.3    martin 		fnames[num_lang] = strdup(fname);
    340      1.1  dholland 		lang_msg[num_lang++] = strdup(cp);
    341      1.1  dholland 	}
    342      1.1  dholland 	msg_file(0);
    343      1.1  dholland 	closedir(dir);
    344      1.1  dholland 	dir = 0;
    345      1.1  dholland 
    346      1.1  dholland 	if (num_lang == 1)
    347      1.1  dholland 		goto done;
    348      1.1  dholland 
    349      1.1  dholland 	opt = calloc(num_lang, sizeof *opt);
    350      1.1  dholland 	if (!opt)
    351      1.1  dholland 		goto done;
    352      1.1  dholland 
    353      1.1  dholland 	for (lang = 0; lang < num_lang; lang++) {
    354      1.1  dholland 		opt[lang].opt_name = lang_msg[lang];
    355      1.1  dholland 		opt[lang].opt_menu = OPT_NOMENU;
    356      1.1  dholland 		opt[lang].opt_action = set_language;
    357      1.1  dholland 	}
    358      1.1  dholland 
    359      1.1  dholland 	lang_menu = new_menu(NULL, opt, num_lang, -1, 12, 0, 0, MC_NOEXITOPT,
    360      1.1  dholland 		NULL, NULL, NULL, NULL, NULL);
    361      1.1  dholland 
    362      1.1  dholland 	if (lang_menu != -1) {
    363      1.1  dholland 		msg_display(MSG_hello);
    364      1.1  dholland 		process_menu(lang_menu, fnames);
    365      1.1  dholland 	}
    366      1.1  dholland 
    367      1.1  dholland     done:
    368      1.1  dholland 	if (dir)
    369      1.1  dholland 		closedir(dir);
    370      1.1  dholland 	if (lang_menu != -1)
    371      1.1  dholland 		free_menu(lang_menu);
    372      1.1  dholland 	free(opt);
    373      1.1  dholland 	while (num_lang) {
    374      1.1  dholland 		free(lang_msg[--num_lang]);
    375      1.1  dholland 		free(fnames[num_lang]);
    376      1.1  dholland 	}
    377      1.1  dholland 	free(lang_msg);
    378      1.1  dholland 	free(fnames);
    379      1.1  dholland 
    380      1.1  dholland 	/* set locale according to selected language */
    381      1.1  dholland 	cp = msg_string(MSG_sysinst_message_locale);
    382      1.1  dholland 	if (cp) {
    383      1.1  dholland 		setlocale(LC_CTYPE, cp);
    384      1.1  dholland 		setenv("LC_CTYPE", cp, 1);
    385      1.1  dholland 	}
    386      1.1  dholland }
    387      1.1  dholland 
    388      1.1  dholland #ifndef md_may_remove_boot_medium
    389      1.1  dholland #define md_may_remove_boot_medium()	(boot_media_still_needed()<=0)
    390      1.1  dholland #endif
    391      1.1  dholland 
    392      1.1  dholland /* toplevel menu handler ... */
    393      1.1  dholland void
    394      1.1  dholland toplevel(void)
    395      1.1  dholland {
    396      1.2    martin 	/*
    397      1.2    martin 	 * Undo any stateful side-effects of previous menu choices.
    398      1.2    martin 	 * XXX must be idempotent, since we get run each time the main
    399      1.2    martin 	 *     menu is displayed.
    400      1.2    martin 	 */
    401      1.4    martin 	char *home = getenv("HOME");
    402      1.4    martin 	if (home != NULL)
    403      1.5    martin 		if (chdir(home) != 0)
    404      1.5    martin 			(void)chdir("/");
    405      1.2    martin 	unwind_mounts();
    406      1.1  dholland 
    407      1.1  dholland 	/* Display banner message in (english, francais, deutsch..) */
    408      1.1  dholland 	msg_display(MSG_hello);
    409      1.1  dholland 	msg_display_add(MSG_md_hello);
    410      1.1  dholland 	if (md_may_remove_boot_medium())
    411      1.1  dholland 		msg_display_add(MSG_md_may_remove_boot_medium);
    412      1.1  dholland 	msg_display_add(MSG_thanks);
    413      1.1  dholland }
    414      1.1  dholland 
    415      1.1  dholland 
    416      1.1  dholland /* The usage ... */
    417      1.1  dholland 
    418      1.1  dholland static void
    419      1.1  dholland usage(void)
    420      1.1  dholland {
    421      1.1  dholland 
    422      1.1  dholland 	(void)fprintf(stderr, "%s", msg_string(MSG_usage));
    423      1.1  dholland 	exit(1);
    424      1.1  dholland }
    425      1.1  dholland 
    426      1.1  dholland /* ARGSUSED */
    427      1.1  dholland static void
    428      1.1  dholland miscsighandler(int signo)
    429      1.1  dholland {
    430      1.1  dholland 
    431      1.1  dholland 	/*
    432      1.1  dholland 	 * we need to cleanup(), but it was already scheduled with atexit(),
    433      1.1  dholland 	 * so it'll be invoked on exit().
    434      1.1  dholland 	 */
    435      1.1  dholland 	exit(1);
    436      1.1  dholland }
    437      1.1  dholland 
    438      1.1  dholland static void
    439      1.1  dholland ttysighandler(int signo)
    440      1.1  dholland {
    441      1.1  dholland 
    442      1.1  dholland 	/*
    443      1.1  dholland 	 * if we want to ignore a TTY signal (SIGINT or SIGQUIT), then we
    444      1.1  dholland 	 * just return.  If we want to forward a TTY signal, we forward it
    445      1.1  dholland 	 * to the specified process group.
    446      1.1  dholland 	 *
    447      1.1  dholland 	 * This functionality is used when setting up and displaying child
    448      1.1  dholland 	 * output so that the child gets the signal and presumably dies,
    449      1.1  dholland 	 * but sysinst continues.  We use this rather than actually ignoring
    450      1.1  dholland 	 * the signals, because that will be be passed on to a child
    451      1.1  dholland 	 * through fork/exec, whereas special handlers get reset on exec..
    452      1.1  dholland 	 */
    453      1.1  dholland 	if (ttysig_ignore)
    454      1.1  dholland 		return;
    455      1.1  dholland 	if (ttysig_forward) {
    456      1.1  dholland 		killpg(ttysig_forward, signo);
    457      1.1  dholland 		return;
    458      1.1  dholland 	}
    459      1.1  dholland 
    460      1.1  dholland 	/*
    461      1.1  dholland 	 * we need to cleanup(), but it was already scheduled with atexit(),
    462      1.1  dholland 	 * so it'll be invoked on exit().
    463      1.1  dholland 	 */
    464      1.1  dholland 	exit(1);
    465      1.1  dholland }
    466      1.1  dholland 
    467      1.1  dholland static void
    468      1.1  dholland cleanup(void)
    469      1.1  dholland {
    470      1.1  dholland 	time_t tloc;
    471      1.1  dholland 
    472      1.1  dholland 	(void)time(&tloc);
    473      1.1  dholland 
    474      1.1  dholland #if 0
    475      1.1  dholland 	restore_etc();
    476      1.1  dholland #endif
    477      1.1  dholland 	/* Ensure we aren't inside the target tree */
    478      1.1  dholland 	chdir(getenv("HOME"));
    479      1.1  dholland 	unwind_mounts();
    480      1.1  dholland 	umount_mnt2();
    481      1.1  dholland 
    482      1.1  dholland 	endwin();
    483      1.1  dholland 
    484      1.1  dholland 	if (logfp) {
    485      1.6  christos 		fprintf(logfp, "Log ended at: %s\n", safectime(&tloc));
    486      1.1  dholland 		fflush(logfp);
    487      1.1  dholland 		fclose(logfp);
    488      1.1  dholland 		logfp = NULL;
    489      1.1  dholland 	}
    490      1.1  dholland 	if (script) {
    491      1.6  christos 		fprintf(script, "# Script ended at: %s\n", safectime(&tloc));
    492      1.1  dholland 		fflush(script);
    493      1.1  dholland 		fclose(script);
    494      1.1  dholland 		script = NULL;
    495      1.1  dholland 	}
    496      1.1  dholland 
    497      1.1  dholland 	if (!exit_cleanly)
    498      1.1  dholland 		fprintf(stderr, "\n\nsysinst terminated.\n");
    499      1.1  dholland }
    500      1.1  dholland 
    501      1.1  dholland 
    502      1.1  dholland /* process function ... */
    503      1.1  dholland 
    504      1.1  dholland void
    505      1.1  dholland process_f_flag(char *f_name)
    506      1.1  dholland {
    507      1.1  dholland 	char buffer[STRSIZE];
    508      1.1  dholland 	int len;
    509      1.1  dholland 	const struct f_arg *arg;
    510      1.1  dholland 	FILE *fp;
    511      1.1  dholland 	char *cp, *cp1;
    512      1.1  dholland 
    513      1.1  dholland 	/* open the file */
    514      1.1  dholland 	fp = fopen(f_name, "r");
    515      1.1  dholland 	if (fp == NULL) {
    516      1.1  dholland 		fprintf(stderr, msg_string(MSG_config_open_error), f_name);
    517      1.1  dholland 		exit(1);
    518      1.1  dholland 	}
    519      1.1  dholland 
    520      1.1  dholland 	while (fgets(buffer, sizeof buffer, fp) != NULL) {
    521      1.1  dholland 		cp = buffer + strspn(buffer, " \t");
    522      1.1  dholland 		if (strchr("#\r\n", *cp) != NULL)
    523      1.1  dholland 			continue;
    524      1.1  dholland 		for (arg = fflagopts; arg->name != NULL; arg++) {
    525      1.1  dholland 			len = strlen(arg->name);
    526      1.1  dholland 			if (memcmp(cp, arg->name, len) != 0)
    527      1.1  dholland 				continue;
    528      1.1  dholland 			cp1 = cp + len;
    529      1.1  dholland 			cp1 += strspn(cp1, " \t");
    530      1.1  dholland 			if (*cp1++ != '=')
    531      1.1  dholland 				continue;
    532      1.1  dholland 			cp1 += strspn(cp1, " \t");
    533      1.1  dholland 			len = strcspn(cp1, " \n\r\t");
    534      1.1  dholland 			cp1[len] = 0;
    535      1.1  dholland 			strlcpy(arg->var, cp1, arg->size);
    536      1.1  dholland 			break;
    537      1.1  dholland 		}
    538      1.1  dholland 	}
    539      1.2    martin 	strlcpy(pm_new->bsddiskname, bsddiskname, sizeof pm_new->bsddiskname);
    540      1.1  dholland 
    541      1.1  dholland 	fclose(fp);
    542      1.1  dholland }
    543