Home | History | Annotate | Line # | Download | only in sysinst
configmenu.c revision 1.2.4.2
      1  1.2.4.2       snj /* $NetBSD: configmenu.c,v 1.2.4.2 2015/05/14 07:58:49 snj Exp $ */
      2      1.1  dholland 
      3      1.1  dholland /*-
      4      1.1  dholland  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      5      1.1  dholland  * All rights reserved.
      6      1.1  dholland  *
      7      1.1  dholland  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  dholland  * by Jeffrey C. Rizzo
      9      1.1  dholland  *
     10      1.1  dholland  * Redistribution and use in source and binary forms, with or without
     11      1.1  dholland  * modification, are permitted provided that the following conditions
     12      1.1  dholland  * are met:
     13      1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     14      1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     15      1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  dholland  *    documentation and/or other materials provided with the distribution.
     18      1.1  dholland  *
     19      1.1  dholland  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1  dholland  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1  dholland  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1  dholland  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1  dholland  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1  dholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1  dholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1  dholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1  dholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1  dholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1  dholland  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1  dholland  */
     31      1.1  dholland 
     32      1.1  dholland /* configmenu.c -- post-installation system configuration menu. */
     33      1.1  dholland 
     34      1.1  dholland #include <stdio.h>
     35      1.1  dholland #include <curses.h>
     36      1.1  dholland #include <unistd.h>
     37      1.2    martin #include <errno.h>
     38      1.1  dholland #include "defs.h"
     39      1.1  dholland #include "msg_defs.h"
     40      1.1  dholland #include "menu_defs.h"
     41      1.1  dholland 
     42      1.1  dholland 
     43      1.1  dholland static int set_network(struct menudesc*, void *);
     44      1.1  dholland static int set_timezone_menu(struct menudesc *, void *);
     45      1.1  dholland static int set_root_shell(struct menudesc *, void *);
     46      1.1  dholland static int change_root_password(struct menudesc *, void *);
     47      1.1  dholland static int add_new_user(struct menudesc *, void *);
     48      1.1  dholland static int set_binpkg(struct menudesc *, void *);
     49      1.1  dholland static int set_pkgsrc(struct menudesc *, void *);
     50      1.1  dholland static void config_list_init(void);
     51      1.1  dholland static void get_rootsh(void);
     52      1.1  dholland static int toggle_rcvar(struct menudesc *, void *);
     53      1.1  dholland static void configmenu_hdr(struct menudesc *, void *);
     54      1.1  dholland static int check_root_password(void);
     55      1.1  dholland 
     56      1.1  dholland char pkgpath[STRSIZE];
     57      1.1  dholland char pkgsrcpath[STRSIZE];
     58      1.1  dholland 
     59      1.1  dholland extern const char *tz_default;
     60      1.1  dholland 
     61      1.1  dholland enum {
     62      1.1  dholland 	CONFIGOPT_NETCONF,
     63      1.1  dholland 	CONFIGOPT_TZ,
     64      1.1  dholland 	CONFIGOPT_ROOTSH,
     65      1.1  dholland 	CONFIGOPT_ROOTPW,
     66      1.1  dholland 	CONFIGOPT_BINPKG,
     67      1.1  dholland 	CONFIGOPT_PKGSRC,
     68      1.1  dholland 	CONFIGOPT_SSHD,
     69      1.1  dholland 	CONFIGOPT_NTPD,
     70      1.1  dholland 	CONFIGOPT_NTPDATE,
     71      1.1  dholland 	CONFIGOPT_MDNSD,
     72      1.2    martin 	CONFIGOPT_XDM,
     73      1.2    martin 	CONFIGOPT_CGD,
     74      1.2    martin 	CONFIGOPT_LVM,
     75      1.2    martin 	CONFIGOPT_RAIDFRAME,
     76      1.1  dholland 	CONFIGOPT_ADDUSER,
     77      1.1  dholland 	CONFIGOPT_LAST
     78      1.1  dholland };
     79      1.1  dholland 
     80      1.1  dholland typedef struct configinfo {
     81      1.1  dholland 	const char	*optname;
     82      1.1  dholland 	uint		opt;
     83      1.1  dholland 	const char	*rcvar;
     84      1.1  dholland 	int		(*action)(struct menudesc *, void *);
     85      1.1  dholland 	const char	*setting;
     86      1.1  dholland } configinfo;
     87      1.1  dholland 
     88      1.1  dholland 
     89      1.1  dholland configinfo config_list[] = {
     90      1.1  dholland 	{MSG_Configure_network, CONFIGOPT_NETCONF, NULL, set_network, MSG_configure},
     91      1.1  dholland 	{MSG_timezone, CONFIGOPT_TZ, NULL, set_timezone_menu, NULL},
     92      1.1  dholland 	{MSG_Root_shell, CONFIGOPT_ROOTSH, NULL, set_root_shell, NULL},
     93      1.1  dholland 	{MSG_change_rootpw, CONFIGOPT_ROOTPW, NULL, change_root_password, MSG_change},
     94      1.2    martin 	{MSG_enable_binpkg, CONFIGOPT_BINPKG, NULL, set_binpkg, MSG_install},
     95      1.1  dholland 	{MSG_get_pkgsrc, CONFIGOPT_PKGSRC, NULL, set_pkgsrc, MSG_install},
     96      1.1  dholland 	{MSG_enable_sshd, CONFIGOPT_SSHD, "sshd", toggle_rcvar, NULL},
     97      1.1  dholland 	{MSG_enable_ntpd, CONFIGOPT_NTPD, "ntpd", toggle_rcvar, NULL},
     98      1.1  dholland 	{MSG_run_ntpdate, CONFIGOPT_NTPDATE, "ntpdate", toggle_rcvar, NULL},
     99      1.1  dholland 	{MSG_enable_mdnsd, CONFIGOPT_MDNSD, "mdnsd", toggle_rcvar, NULL},
    100      1.2    martin 	{MSG_enable_xdm, CONFIGOPT_XDM, "xdm", toggle_rcvar, NULL},
    101      1.2    martin 	{MSG_enable_cgd, CONFIGOPT_CGD, "cgd", toggle_rcvar, NULL},
    102      1.2    martin 	{MSG_enable_lvm, CONFIGOPT_LVM, "lvm", toggle_rcvar, NULL},
    103      1.2    martin 	{MSG_enable_raid, CONFIGOPT_RAIDFRAME, "raidframe", toggle_rcvar, NULL},
    104      1.1  dholland 	{MSG_add_a_user, CONFIGOPT_ADDUSER, NULL, add_new_user, ""},
    105      1.1  dholland 	{NULL,		CONFIGOPT_LAST,	NULL, NULL, NULL}
    106      1.1  dholland };
    107      1.1  dholland 
    108      1.1  dholland static void
    109      1.1  dholland config_list_init(void)
    110      1.1  dholland {
    111      1.1  dholland 	int i;
    112      1.1  dholland 
    113      1.1  dholland 	for (i=0; i < CONFIGOPT_LAST; i++) {
    114      1.1  dholland 		switch (i) {
    115      1.1  dholland 		case CONFIGOPT_TZ:
    116      1.1  dholland 			get_tz_default();
    117      1.1  dholland 			config_list[CONFIGOPT_TZ].setting = tz_default;
    118      1.1  dholland 			break;
    119      1.1  dholland 		case CONFIGOPT_ROOTSH:
    120      1.1  dholland 			get_rootsh();
    121      1.1  dholland 			break;
    122      1.1  dholland 		case CONFIGOPT_ROOTPW:
    123      1.1  dholland 			if (check_root_password())
    124      1.1  dholland 				config_list[i].setting = MSG_password_set;
    125      1.1  dholland 			else
    126      1.1  dholland 				config_list[i].setting = MSG_empty;
    127      1.1  dholland 			break;
    128      1.1  dholland 		default:
    129      1.1  dholland 			if (config_list[i].rcvar != NULL) {
    130      1.1  dholland 				if (check_rcvar(config_list[i].rcvar))
    131      1.1  dholland 					config_list[i].setting = MSG_YES;
    132      1.1  dholland 				else
    133      1.1  dholland 					config_list[i].setting = MSG_NO;
    134      1.1  dholland 			}
    135      1.1  dholland 			break;
    136      1.1  dholland 		}
    137      1.1  dholland 	}
    138      1.1  dholland }
    139      1.1  dholland 
    140      1.1  dholland static void
    141      1.1  dholland get_rootsh(void)
    142      1.1  dholland {
    143      1.1  dholland 	static char *buf = NULL;
    144      1.1  dholland 
    145      1.1  dholland 	if (buf != NULL)
    146      1.1  dholland 		free(buf);
    147      1.1  dholland 
    148      1.1  dholland 	if (target_already_root())
    149      1.1  dholland 		collect(T_OUTPUT, &buf,
    150      1.1  dholland 		    "/usr/bin/awk -F: '$1==\"root\" { print $NF; exit }'"
    151      1.1  dholland 		    " /etc/passwd");
    152      1.1  dholland 	else
    153      1.1  dholland 		collect(T_OUTPUT, &buf,
    154      1.1  dholland 		    "chroot %s /usr/bin/awk -F: '$1==\"root\" { print $NF; exit }'"
    155      1.1  dholland 		    " /etc/passwd",target_prefix());
    156      1.1  dholland 
    157      1.1  dholland 	config_list[CONFIGOPT_ROOTSH].setting = (const char *)buf;
    158      1.1  dholland }
    159      1.1  dholland 
    160      1.1  dholland static void
    161      1.1  dholland set_config(menudesc *menu, int opt, void *arg)
    162      1.1  dholland {
    163      1.1  dholland 	configinfo	**configp = arg;
    164      1.1  dholland 	configinfo	*config = configp[opt];
    165      1.1  dholland 	const char	*optname, *setting;
    166      1.1  dholland 
    167      1.1  dholland 	optname = config->optname;
    168      1.1  dholland 	setting = msg_string(config->setting);
    169      1.1  dholland 
    170      1.1  dholland 	wprintw(menu->mw, "%-50s %-10s", msg_string(optname), setting);
    171      1.1  dholland }
    172      1.1  dholland 
    173      1.1  dholland static int
    174      1.1  dholland init_config_menu(configinfo *conf, menu_ent *me, configinfo **ce)
    175      1.1  dholland {
    176      1.1  dholland 	int	opt;
    177      1.1  dholland 	int	configopts;
    178      1.1  dholland 
    179      1.1  dholland 	for (configopts = 0; ; conf++) {
    180      1.1  dholland 		opt = conf->opt;
    181      1.1  dholland 		if (opt == CONFIGOPT_LAST)
    182      1.1  dholland 			break;
    183      1.1  dholland 		*ce = conf;
    184      1.1  dholland 		me->opt_menu = OPT_NOMENU;
    185      1.1  dholland 		me->opt_flags = 0;
    186      1.1  dholland 		me->opt_name = NULL;  /* NULL so set_config will draw */
    187      1.1  dholland 		me->opt_action = conf->action;
    188      1.1  dholland 		configopts++;
    189      1.1  dholland 		ce++;
    190      1.1  dholland 		me++;
    191      1.1  dholland 	}
    192      1.1  dholland 
    193      1.1  dholland 	return configopts;
    194      1.1  dholland }
    195      1.1  dholland 
    196      1.1  dholland static int
    197      1.1  dholland /*ARGSUSED*/
    198      1.1  dholland set_timezone_menu(struct menudesc *menu, void *arg)
    199      1.1  dholland {
    200      1.1  dholland 	configinfo **confp = arg;
    201      1.1  dholland 	set_timezone();
    202      1.1  dholland 	get_tz_default();
    203      1.1  dholland 	confp[menu->cursel]->setting = tz_default;
    204      1.1  dholland 	return 0;
    205      1.1  dholland }
    206      1.1  dholland 
    207      1.1  dholland static int
    208      1.1  dholland set_root_shell(struct menudesc *menu, void *arg)
    209      1.1  dholland {
    210      1.1  dholland 	configinfo **confp = arg;
    211      1.1  dholland 
    212      1.1  dholland 	process_menu(MENU_rootsh, &confp[menu->cursel]->setting);
    213      1.2    martin 	if (run_program(RUN_PROGRESS | RUN_CHROOT,
    214      1.2    martin 		"chpass -s %s root", confp[menu->cursel]->setting) != 0)
    215      1.2    martin 		confp[menu->cursel]->setting = MSG_failed;
    216      1.1  dholland 	return 0;
    217      1.1  dholland }
    218      1.1  dholland 
    219      1.1  dholland static int
    220      1.1  dholland set_network(struct menudesc *menu, void *arg)
    221      1.1  dholland {
    222      1.1  dholland 	network_up = 0;
    223      1.1  dholland 	if (config_network())
    224      1.1  dholland 		mnt_net_config();
    225      1.1  dholland 	return 0;
    226      1.1  dholland }
    227      1.1  dholland 
    228      1.1  dholland static int
    229      1.1  dholland check_root_password(void)
    230      1.1  dholland {
    231      1.1  dholland 	char *buf;
    232      1.1  dholland 	int rval;
    233      1.1  dholland 
    234      1.1  dholland 	if (target_already_root())
    235      1.1  dholland 		collect(T_OUTPUT, &buf, "getent passwd root | cut -d: -f2");
    236      1.1  dholland 	else
    237      1.1  dholland 		collect(T_OUTPUT, &buf, "chroot %s getent passwd root | "
    238      1.1  dholland 		    "chroot %s cut -d: -f2",
    239      1.1  dholland 		    target_prefix(), target_prefix());
    240      1.1  dholland 
    241      1.1  dholland 	if (logfp)
    242      1.1  dholland 		fprintf(logfp,"buf %s strlen(buf) %zu\n", buf, strlen(buf));
    243      1.1  dholland 
    244      1.1  dholland 	if (strlen(buf) <= 1)  /* newline */
    245      1.1  dholland 		rval = 0;
    246      1.1  dholland 	else
    247      1.1  dholland 		rval = 1;
    248      1.1  dholland 	free(buf);
    249      1.1  dholland 	return rval;
    250      1.1  dholland }
    251      1.1  dholland 
    252      1.1  dholland static int
    253      1.1  dholland add_new_user(struct menudesc *menu, void *arg)
    254      1.1  dholland {
    255  1.2.4.1    martin 	char username[STRSIZE] = "";
    256      1.1  dholland 	int inwheel=0;
    257      1.1  dholland 
    258      1.1  dholland 	msg_prompt(MSG_addusername, NULL, username, sizeof username -1);
    259  1.2.4.1    martin 	if (strlen(username) == 0)
    260  1.2.4.1    martin 		return 0;
    261  1.2.4.2       snj 	inwheel = ask_yesno(MSG_addusertowheel);
    262      1.1  dholland 	ushell = "/bin/csh";
    263      1.1  dholland 	process_menu(MENU_usersh, NULL);
    264      1.1  dholland 	if (inwheel)
    265      1.1  dholland 		run_program(RUN_PROGRESS | RUN_CHROOT,
    266      1.1  dholland 		    "/usr/sbin/useradd -m -s %s -G wheel %s",
    267      1.1  dholland 		    ushell, username);
    268      1.1  dholland 	else
    269      1.1  dholland 		run_program(RUN_PROGRESS | RUN_CHROOT,
    270      1.1  dholland 		    "/usr/sbin/useradd -m -s %s %s", ushell, username);
    271      1.1  dholland 	run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    272      1.1  dholland 	    "passwd -l %s", username);
    273      1.1  dholland 	return 0;
    274      1.1  dholland }
    275      1.1  dholland 
    276      1.1  dholland static int
    277      1.1  dholland change_root_password(struct menudesc *menu, void *arg)
    278      1.1  dholland {
    279      1.1  dholland 	configinfo **confp = arg;
    280      1.1  dholland 
    281      1.1  dholland 	msg_display(MSG_rootpw);
    282  1.2.4.2       snj 	if (ask_yesno(NULL)) {
    283      1.2    martin 		if (run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    284      1.2    martin 			"passwd -l root") == 0)
    285      1.2    martin 			confp[menu->cursel]->setting = MSG_password_set;
    286      1.2    martin 		else
    287      1.2    martin 			confp[menu->cursel]->setting = MSG_failed;
    288      1.2    martin 	}
    289      1.1  dholland 	return 0;
    290      1.1  dholland }
    291      1.1  dholland 
    292      1.1  dholland static int
    293      1.1  dholland set_binpkg(struct menudesc *menu, void *arg)
    294      1.1  dholland {
    295      1.1  dholland 	configinfo **confp = arg;
    296      1.2    martin 	char additional_pkgs[STRSIZE] = {0};
    297      1.1  dholland 	char pattern[STRSIZE];
    298      1.2    martin 	int allok = 0;
    299  1.2.4.2       snj 	arg_rv parm;
    300      1.1  dholland 
    301      1.2    martin 	do {
    302  1.2.4.2       snj 		parm.rv = -1;
    303  1.2.4.2       snj 		parm.arg = additional_pkgs;
    304  1.2.4.2       snj 		process_menu(MENU_binpkg, &parm);
    305  1.2.4.2       snj 		if (parm.rv == SET_SKIP) {
    306      1.2    martin 			confp[menu->cursel]->setting = MSG_abandoned;
    307      1.2    martin 			return 0;
    308      1.2    martin 		}
    309      1.2    martin 
    310      1.2    martin 		make_url(pkgpath, &pkg, pkg_dir);
    311      1.2    martin 		if (run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    312      1.2    martin 			"pkg_add %s/pkgin", pkgpath) == 0) {
    313      1.2    martin 			allok = 1;
    314      1.2    martin 		}
    315      1.2    martin 	} while (allok == 0);
    316      1.1  dholland 
    317      1.1  dholland 	/* configure pkgin to use $pkgpath as a repository */
    318      1.1  dholland 	snprintf(pattern, STRSIZE, "s,^[^#].*$,%s,", pkgpath);
    319      1.1  dholland 	replace("/usr/pkg/etc/pkgin/repositories.conf", pattern);
    320      1.1  dholland 
    321      1.1  dholland 	run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    322      1.1  dholland 		"/usr/pkg/bin/pkgin -y update");
    323      1.1  dholland 
    324      1.2    martin 	if (strlen(additional_pkgs) > 0)
    325      1.2    martin 		run_program(RUN_DISPLAY | RUN_PROGRESS | RUN_CHROOT,
    326      1.2    martin 		"/usr/pkg/bin/pkgin -y install %s", additional_pkgs);
    327      1.2    martin 
    328      1.1  dholland 	msg_display(MSG_binpkg_installed);
    329      1.1  dholland 	process_menu(MENU_ok, NULL);
    330      1.2    martin 
    331      1.1  dholland 	confp[menu->cursel]->setting = MSG_DONE;
    332      1.1  dholland 	return 0;
    333      1.1  dholland }
    334      1.1  dholland 
    335      1.1  dholland static int
    336      1.1  dholland set_pkgsrc(struct menudesc *menu, void *arg)
    337      1.1  dholland {
    338      1.1  dholland 	configinfo **confp = arg;
    339      1.1  dholland 	distinfo dist;
    340      1.1  dholland 
    341      1.1  dholland 	dist.name = "pkgsrc";
    342      1.1  dholland 	dist.set = SET_PKGSRC;
    343      1.1  dholland 	dist.desc = "source for 3rd-party packages";
    344      1.1  dholland 	dist.marker_file = NULL;
    345      1.1  dholland 
    346      1.1  dholland 	int status = SET_RETRY;
    347      1.1  dholland 
    348      1.1  dholland 	do {
    349      1.1  dholland 		status = get_pkgsrc();
    350      1.1  dholland 		if (status == SET_OK) {
    351      1.1  dholland 			status = extract_file(&dist, 0);
    352      1.1  dholland 			continue;
    353      1.1  dholland 		} else if (status == SET_SKIP) {
    354      1.1  dholland 			confp[menu->cursel]->setting = MSG_abandoned;
    355      1.1  dholland 			return 0;
    356      1.1  dholland 		}
    357  1.2.4.2       snj 		if (!ask_yesno(MSG_retry_pkgsrc_network)) {
    358      1.1  dholland 			confp[menu->cursel]->setting = MSG_abandoned;
    359      1.1  dholland 			return 1;
    360      1.1  dholland 		}
    361      1.1  dholland 	}
    362      1.1  dholland 	while (status == SET_RETRY);
    363      1.2    martin 
    364      1.1  dholland 	confp[menu->cursel]->setting = MSG_DONE;
    365      1.1  dholland 	return 0;
    366      1.1  dholland }
    367      1.1  dholland 
    368      1.1  dholland static int
    369      1.1  dholland toggle_rcvar(struct menudesc *menu, void *arg)
    370      1.1  dholland {
    371      1.1  dholland 	configinfo **confp = arg;
    372      1.1  dholland 	int s;
    373      1.1  dholland 	const char *setting, *varname;
    374      1.1  dholland 	char pattern[STRSIZE];
    375      1.1  dholland 	char buf[STRSIZE];
    376      1.1  dholland 	char *cp;
    377      1.1  dholland 	int found = 0;
    378      1.1  dholland 	FILE *fp;
    379      1.1  dholland 
    380      1.1  dholland 	varname = confp[menu->cursel]->rcvar;
    381      1.1  dholland 
    382      1.1  dholland 	s = check_rcvar(varname);
    383      1.1  dholland 
    384      1.1  dholland 	/* we're toggling, so invert the sense */
    385      1.1  dholland 	if (s) {
    386      1.1  dholland 		confp[menu->cursel]->setting = MSG_NO;
    387      1.1  dholland 		setting = "NO";
    388      1.1  dholland 	} else {
    389      1.1  dholland 		confp[menu->cursel]->setting = MSG_YES;
    390      1.1  dholland 		setting = "YES";
    391      1.1  dholland 	}
    392      1.1  dholland 
    393      1.1  dholland 	if (!(fp = fopen(target_expand("/etc/rc.conf"), "r"))) {
    394      1.2    martin 		msg_display(MSG_openfail, target_expand("/etc/rc.conf"), strerror(errno));
    395      1.1  dholland 		process_menu(MENU_ok, NULL);
    396      1.2    martin 		return 0;
    397      1.1  dholland 	}
    398      1.1  dholland 
    399      1.1  dholland 	while (fgets(buf, sizeof buf, fp) != NULL) {
    400      1.1  dholland 		cp = buf + strspn(buf, " \t"); /* Skip initial spaces */
    401      1.1  dholland 		if (strncmp(cp, varname, strlen(varname)) == 0) {
    402      1.1  dholland 			cp += strlen(varname);
    403      1.1  dholland 			if (*cp != '=')
    404      1.1  dholland 				continue;
    405      1.1  dholland 			buf[strlen(buf) - 1] = 0;
    406      1.1  dholland 			snprintf(pattern, sizeof pattern,
    407      1.1  dholland 					"s,^%s$,%s=%s,",
    408      1.1  dholland 					buf, varname, setting);
    409      1.1  dholland 			found = 1;
    410      1.1  dholland 			break;
    411      1.1  dholland 		}
    412      1.1  dholland 	}
    413      1.1  dholland 
    414      1.1  dholland 	fclose(fp);
    415      1.1  dholland 
    416      1.1  dholland 	if (!found) {
    417      1.1  dholland 		add_rc_conf("%s=%s\n", varname, setting);
    418      1.1  dholland 		if (logfp) {
    419      1.1  dholland 			fprintf(logfp, "adding %s=%s\n", varname, setting);
    420      1.1  dholland 			fflush(logfp);
    421      1.1  dholland 		}
    422      1.1  dholland 	} else {
    423      1.1  dholland 		if (logfp) {
    424      1.1  dholland 			fprintf(logfp, "replacement pattern is %s\n", pattern);
    425      1.1  dholland 			fflush(logfp);
    426      1.1  dholland 		}
    427      1.1  dholland 		replace("/etc/rc.conf", pattern);
    428      1.1  dholland 	}
    429      1.1  dholland 
    430      1.1  dholland 	return 0;
    431      1.1  dholland }
    432      1.1  dholland 
    433      1.1  dholland static void
    434      1.1  dholland configmenu_hdr(struct menudesc *menu, void *arg)
    435      1.1  dholland {
    436      1.1  dholland 	msg_display(MSG_configmenu);
    437      1.1  dholland }
    438      1.1  dholland 
    439      1.1  dholland void
    440      1.1  dholland do_configmenu()
    441      1.1  dholland {
    442      1.1  dholland 	int		menu_no;
    443      1.1  dholland 	int		opts;
    444      1.1  dholland 	menu_ent	me[CONFIGOPT_LAST];
    445      1.1  dholland 	configinfo	*ce[CONFIGOPT_LAST];
    446      1.1  dholland 
    447      1.1  dholland 	/* if the target isn't mounted already, figure it out. */
    448      1.1  dholland 	if (target_mounted() == 0) {
    449      1.2    martin 		partman_go = 0;
    450      1.1  dholland 		if (find_disks(msg_string(MSG_configure_prior)) < 0)
    451      1.1  dholland 			return;
    452      1.1  dholland 
    453      1.1  dholland 		if (mount_disks() != 0)
    454      1.1  dholland 			return;
    455      1.1  dholland 	}
    456      1.1  dholland 
    457      1.1  dholland 	config_list_init();
    458      1.1  dholland 	make_url(pkgpath, &pkg, pkg_dir);
    459      1.1  dholland 	opts = init_config_menu(config_list, me, ce);
    460      1.1  dholland 
    461      1.2    martin 	wrefresh(curscr);
    462      1.2    martin 	wmove(stdscr, 0, 0);
    463      1.2    martin 	wclear(stdscr);
    464      1.2    martin 	wrefresh(stdscr);
    465      1.2    martin 
    466      1.1  dholland 	menu_no = new_menu(NULL, me, opts, 0, -4, 0, 70,
    467      1.1  dholland 		MC_SCROLL | MC_NOBOX | MC_DFLTEXIT,
    468      1.1  dholland 		configmenu_hdr, set_config, NULL, "XXX Help String",
    469      1.1  dholland 		MSG_doneconfig);
    470      1.1  dholland 
    471      1.1  dholland 	process_menu(menu_no, ce);
    472      1.1  dholland 	free_menu(menu_no);
    473      1.1  dholland }
    474