Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/sysinst Implement a post-install configuration...



details:   https://anonhg.NetBSD.org/src/rev/db7d12ddb2d3
branches:  trunk
changeset: 778625:db7d12ddb2d3
user:      riz <riz%NetBSD.org@localhost>
date:      Fri Apr 06 23:48:53 2012 +0000

description:
Implement a post-install configuration menu, as proposed on tech-install.
Enables the user to configure a few additional items, including using
pkgin to manage binary packages, in a post-install menu which replaces
the series of questions (Do you want to set a root password? etc).

This is by no means a perfect solution, nor should it discourage anyone
from working on more sweeping changes to sysinst.

Some bug fixes, and .de translation provided by Julian Fagir.

XXX .es, .fr and .pl translations still needed.  Please help!

diffstat:

 distrib/utils/sysinst/Makefile.inc |    4 +-
 distrib/utils/sysinst/checkrc.c    |  113 ++++++++++
 distrib/utils/sysinst/configmenu.c |  416 +++++++++++++++++++++++++++++++++++++
 distrib/utils/sysinst/defs.h       |   48 +++-
 distrib/utils/sysinst/install.c    |    7 +-
 distrib/utils/sysinst/main.c       |   15 +-
 distrib/utils/sysinst/menus.mi     |   85 +++++++-
 distrib/utils/sysinst/msg.mi.de    |   63 +++++-
 distrib/utils/sysinst/msg.mi.en    |   60 +++++-
 distrib/utils/sysinst/msg.mi.es    |   58 +++++-
 distrib/utils/sysinst/msg.mi.fr    |   58 +++++-
 distrib/utils/sysinst/msg.mi.pl    |   58 +++++-
 distrib/utils/sysinst/net.c        |  115 +++++++--
 distrib/utils/sysinst/target.c     |   10 +-
 distrib/utils/sysinst/util.c       |  168 +++++++++++---
 15 files changed, 1187 insertions(+), 91 deletions(-)

diffs (truncated from 1679 to 300 lines):

diff -r bd266a7b588a -r db7d12ddb2d3 distrib/utils/sysinst/Makefile.inc
--- a/distrib/utils/sysinst/Makefile.inc        Fri Apr 06 22:50:39 2012 +0000
+++ b/distrib/utils/sysinst/Makefile.inc        Fri Apr 06 23:48:53 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.58 2012/01/08 21:20:40 riz Exp $
+#      $NetBSD: Makefile.inc,v 1.59 2012/04/06 23:48:53 riz Exp $
 #
 # Makefile for sysinst
 
@@ -13,7 +13,7 @@
 
 SRCS+= menu_defs.c msg_defs.c main.c install.c upgrade.c \
        txtwalk.c run.c factor.c net.c disks.c disks_lfs.c util.c geom.c \
-       label.c target.c md.c sizemultname.c
+       label.c target.c md.c sizemultname.c configmenu.c checkrc.c
 
 SRCS+= ${MD_OPTIONS:MAOUT2ELF:S/AOUT2ELF/aout2elf.c/}
 SRCS+= ${MENUS_MD:Mmenus.mbr:S/menus.mbr/mbr.c/}
diff -r bd266a7b588a -r db7d12ddb2d3 distrib/utils/sysinst/checkrc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/utils/sysinst/checkrc.c   Fri Apr 06 23:48:53 2012 +0000
@@ -0,0 +1,113 @@
+/* $NetBSD: checkrc.c,v 1.1 2012/04/06 23:48:53 riz Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jeffrey C. Rizzo
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 THE FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/* checkrc.c -- Create a script on the target to check the state of
+ * its rc.conf variables. */
+
+#include <curses.h>
+#include <err.h>
+#include <stdio.h>
+#include "defs.h"
+#include "msg_defs.h"
+#include "menu_defs.h"
+
+#define RC_CHECK_SCRIPT "/tmp/checkrc.sh"
+
+static int create_script(const char *, int);
+static int check(const char *, int);
+
+char *rcconf = NULL;
+
+enum {
+       CHECK_CONF,
+       CHECK_DEFAULT
+};
+
+static int
+create_script(const char *varname, int filetocheck)
+{
+       FILE    *fp;
+       
+       if ((fp = fopen(target_expand(RC_CHECK_SCRIPT), "w")) == NULL) {
+               if (logfp)
+                       fprintf(logfp,"Could not open %s for writing",
+                           target_expand(RC_CHECK_SCRIPT));
+               warn("Could not open %s for writing",
+                   target_expand(RC_CHECK_SCRIPT));
+               return 1;
+       }
+
+       if (filetocheck == CHECK_DEFAULT)
+               fprintf(fp, "#!/bin/sh\n. /etc/defaults/rc.conf\n"
+                   ". /etc/rc.subr\n");
+       else
+               fprintf(fp, "#!/bin/sh\n. /etc/rc.conf\n. /etc/rc.subr\n");
+       fprintf(fp, "if checkyesno %s\nthen\necho YES\nelse\necho NO\nfi\n",
+           varname);
+
+       fclose(fp);
+       return 0;
+}
+
+static int
+check(const char *varname, int filetocheck)
+{
+       char *buf;
+
+       create_script(varname, filetocheck);
+
+       collect(T_OUTPUT, &buf, "chroot %s /bin/sh %s 2>&1", target_prefix(),
+           RC_CHECK_SCRIPT);
+
+       unlink(target_expand(RC_CHECK_SCRIPT));
+
+       if (logfp) {
+               fprintf(logfp,"var %s is %s\n", varname, buf);
+               fflush(logfp);
+       }
+
+       if (strncmp(buf, "YES", strlen("YES")) == 0)
+               return 1;
+       else
+               return 0;
+}
+
+int
+check_rcvar(const char *varname)
+{
+       return check(varname, CHECK_CONF);
+}
+
+int
+check_rcdefault(const char *varname)
+{
+       return check(varname, CHECK_DEFAULT);
+}
diff -r bd266a7b588a -r db7d12ddb2d3 distrib/utils/sysinst/configmenu.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/utils/sysinst/configmenu.c        Fri Apr 06 23:48:53 2012 +0000
@@ -0,0 +1,416 @@
+/* $NetBSD: configmenu.c,v 1.1 2012/04/06 23:48:53 riz Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jeffrey C. Rizzo
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 THE FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/* configmenu.c -- post-installation system configuration menu. */
+
+#include <stdio.h>
+#include <curses.h>
+#include <unistd.h>
+#include "defs.h"
+#include "msg_defs.h"
+#include "menu_defs.h"
+
+
+static int set_network(struct menudesc*, void *);
+static int set_timezone_menu(struct menudesc *, void *);
+static int set_root_shell(struct menudesc *, void *);
+static int change_root_password(struct menudesc *, void *);
+static int set_binpkg(struct menudesc *, void *);
+static int set_pkgsrc(struct menudesc *, void *);
+static void config_list_init(void);
+static void get_rootsh(void);
+static int toggle_rcvar(struct menudesc *, void *);
+static void configmenu_hdr(struct menudesc *, void *);
+static int check_root_password(void);
+
+char pkgpath[STRSIZE];
+char pkgsrcpath[STRSIZE];
+
+extern const char *tz_default;
+
+enum {
+       CONFIGOPT_NETCONF,
+       CONFIGOPT_TZ,
+       CONFIGOPT_ROOTSH,
+       CONFIGOPT_ROOTPW,
+       CONFIGOPT_BINPKG,
+       CONFIGOPT_PKGSRC,
+       CONFIGOPT_SSHD,
+       CONFIGOPT_NTPD,
+       CONFIGOPT_NTPDATE,
+       CONFIGOPT_MDNSD,
+       CONFIGOPT_LAST
+};
+
+typedef struct configinfo {
+       const char      *optname;
+       uint            opt;
+       const char      *rcvar;
+       int             (*action)(struct menudesc *, void *);
+       const char      *setting;
+} configinfo;
+
+
+configinfo config_list[] = {
+       {MSG_Configure_network, CONFIGOPT_NETCONF, NULL, set_network, MSG_configure},
+       {MSG_timezone, CONFIGOPT_TZ, NULL, set_timezone_menu, NULL},
+       {MSG_Root_shell, CONFIGOPT_ROOTSH, NULL, set_root_shell, NULL},
+       {MSG_change_rootpw, CONFIGOPT_ROOTPW, NULL, change_root_password, MSG_change},
+       {MSG_enable_binpkg, CONFIGOPT_BINPKG, NULL, set_binpkg, MSG_configure},
+       {MSG_get_pkgsrc, CONFIGOPT_PKGSRC, NULL, set_pkgsrc, MSG_install},
+       {MSG_enable_sshd, CONFIGOPT_SSHD, "sshd", toggle_rcvar, NULL},
+       {MSG_enable_ntpd, CONFIGOPT_NTPD, "ntpd", toggle_rcvar, NULL},
+       {MSG_run_ntpdate, CONFIGOPT_NTPDATE, "ntpdate", toggle_rcvar, NULL},
+       {MSG_enable_mdnsd, CONFIGOPT_MDNSD, "mdnsd", toggle_rcvar, NULL},
+       {NULL,          CONFIGOPT_LAST, NULL, NULL, NULL}
+};
+
+static void
+config_list_init(void)
+{
+       int i;
+
+       for (i=0; i < CONFIGOPT_LAST; i++) {
+               switch (i) {
+               case CONFIGOPT_TZ:
+                       get_tz_default();
+                       config_list[CONFIGOPT_TZ].setting = tz_default;
+                       break;
+               case CONFIGOPT_ROOTSH:
+                       get_rootsh();
+                       break;
+               case CONFIGOPT_ROOTPW:
+                       if (check_root_password())
+                               config_list[i].setting = MSG_password_set;
+                       else
+                               config_list[i].setting = MSG_empty;
+                       break;
+               default:
+                       if (config_list[i].rcvar != NULL) {
+                               if (check_rcvar(config_list[i].rcvar))
+                                       config_list[i].setting = MSG_YES;
+                               else
+                                       config_list[i].setting = MSG_NO;
+                       }
+                       break;
+               }
+       }
+}
+
+static void
+get_rootsh(void)
+{
+       static char *buf = NULL;
+
+       if (buf != NULL)
+               free(buf);
+
+       collect(T_OUTPUT, &buf,
+           "chroot %s /usr/bin/awk -F: '$1==\"root\" { print $NF; exit }'"
+           " /etc/passwd",target_prefix());
+
+       config_list[CONFIGOPT_ROOTSH].setting = (const char *)buf;
+}
+
+static void
+set_config(menudesc *menu, int opt, void *arg)
+{
+       configinfo      **configp = arg;
+       configinfo      *config = configp[opt];
+       const char      *optname, *setting;
+
+       optname = config->optname;
+       setting = msg_string(config->setting);
+
+       wprintw(menu->mw, "%-50s %-10s", msg_string(optname), setting);
+}
+
+static int
+init_config_menu(configinfo *conf, menu_ent *me, configinfo **ce)
+{
+       int     opt;
+       int     configopts;
+



Home | Main Index | Thread Index | Old Index