svn commit: r189754 - head/usr.sbin/sysinstall

Greg Lehey grog at FreeBSD.org
Thu Mar 12 20:51:42 PDT 2009


Author: grog
Date: Fri Mar 13 03:51:41 2009
New Revision: 189754
URL: http://svn.freebsd.org/changeset/base/189754

Log:
  Add menus to read install.cfg from any disk device sysinstall can see
  (eg USB key, CD) rather than just floppy.
  
  Handle \r\n line termination in a cfg file.
  
  Add keeprcconf variable.
  
  Submitted by: Daniel O'Connor

Modified:
  head/usr.sbin/sysinstall/config.c
  head/usr.sbin/sysinstall/dispatch.c
  head/usr.sbin/sysinstall/menus.c
  head/usr.sbin/sysinstall/modules.c
  head/usr.sbin/sysinstall/sysinstall.8
  head/usr.sbin/sysinstall/sysinstall.h

Modified: head/usr.sbin/sysinstall/config.c
==============================================================================
--- head/usr.sbin/sysinstall/config.c	Fri Mar 13 03:00:38 2009	(r189753)
+++ head/usr.sbin/sysinstall/config.c	Fri Mar 13 03:51:41 2009	(r189754)
@@ -428,8 +428,12 @@ configRC_conf(void)
 	while(fgets(line, sizeof(line), rcOld)) {
 	    if(line[0] == '#' || variable_check2(line) != 0)
 		fprintf(rcSite, "%s", line);
-	    else
-		fprintf(rcSite, "#REMOVED: %s", line);
+	    else {
+		if (variable_get(VAR_KEEPRCCONF) != NULL)
+		    fprintf(rcSite, "%s", line);
+		else
+		    fprintf(rcSite, "#REMOVED: %s", line);
+	    }
 	}
 	fclose(rcOld);
     } else if (write_header) {

Modified: head/usr.sbin/sysinstall/dispatch.c
==============================================================================
--- head/usr.sbin/sysinstall/dispatch.c	Fri Mar 13 03:00:38 2009	(r189753)
+++ head/usr.sbin/sysinstall/dispatch.c	Fri Mar 13 03:51:41 2009	(r189754)
@@ -47,6 +47,7 @@ static int dispatch_systemExecute(dialog
 static int dispatch_msgConfirm(dialogMenuItem *unused);
 static int dispatch_mediaOpen(dialogMenuItem *unused);
 static int dispatch_mediaClose(dialogMenuItem *unused);
+static int cfgModuleFire(dialogMenuItem *self);
 
 static struct _word {
     char *name;
@@ -90,6 +91,7 @@ static struct _word {
     { "installVarDefaults",	installVarDefaults	},
     { "loadConfig",		dispatch_load_file	},
     { "loadFloppyConfig",	dispatch_load_floppy	},
+    { "loadCDROMConfig",	dispatch_load_cdrom	},
     { "mediaOpen",		dispatch_mediaOpen	},
     { "mediaClose",		dispatch_mediaClose	},
     { "mediaSetCDROM",		mediaSetCDROM		},
@@ -242,8 +244,9 @@ dispatchCommand(char *str)
 	msgConfirm("Null or zero-length string passed to dispatchCommand");
 	return DITEM_FAILURE;
     }
-    /* If it's got a newline, trim it */
-    if ((cp = index(str, '\n')) != NULL)
+
+    /* Fixup DOS abuse */
+    if ((cp = index(str, '\r')) != NULL)
 	*cp = '\0';
 
     /* If it's got a `=' sign in there, assume it's a variable setting */
@@ -294,9 +297,12 @@ dispatch_load_fp(FILE *fp)
     INITQUE(*head);
 
     while (fgets(buf, sizeof buf, fp)) {
-
-	if ((cp = strchr(buf, '\n')) != NULL)
+	/* Fix up DOS abuse */
+	if ((cp = index(buf, '\r')) != NULL)
 	    *cp = '\0';
+	/* If it's got a new line, trim it */
+       if ((cp = index(buf, '\n')) != NULL)
+            *cp = '\0';
 	if (*buf == '\0' || *buf == '#')
 	    continue;
 
@@ -326,7 +332,7 @@ dispatch_execute(qelement *head)
 
     while (!EMPTYQUE(*head)) {
 	item = (command_buffer *) head->q_forw;
-	
+
 	if (DITEM_STATUS(dispatchCommand(item->string)) != DITEM_SUCCESS) {
 	    msgConfirm("Command `%s' failed - rest of script aborted.\n",
 		       item->string);
@@ -401,8 +407,7 @@ dispatch_load_floppy(dialogMenuItem *sel
 
     mediaClose();
     cp = variable_get_value(VAR_INSTALL_CFG,
-			    "Specify the name of a configuration file\n"
-			    "residing on a MSDOS or UFS floppy.", 0);
+			    "Specify the name of a configuration file", 0);
     if (!cp || !*cp) {
 	variable_unset(VAR_INSTALL_CFG);
 	what |= DITEM_FAILURE;
@@ -443,3 +448,189 @@ dispatch_load_floppy(dialogMenuItem *sel
     return what;
 }
 
+int
+dispatch_load_cdrom(dialogMenuItem *self)
+{
+    int             what = DITEM_SUCCESS;
+    extern char    *distWanted;
+    char           *cp;
+    FILE           *fp;
+    qelement	   *list;
+
+    mediaClose();
+    cp = variable_get_value(VAR_INSTALL_CFG,
+			    "Specify the name of a configuration file\n"
+			    "residing on the CDROM.", 0);
+    if (!cp || !*cp) {
+	variable_unset(VAR_INSTALL_CFG);
+	what |= DITEM_FAILURE;
+	return what;
+    }
+
+    distWanted = cp;
+    /* Try to open the floppy drive */
+    if (DITEM_STATUS(mediaSetCDROM(NULL)) == DITEM_FAILURE) {
+	msgConfirm("Unable to set media device to CDROM.");
+	what |= DITEM_FAILURE;
+	mediaClose();
+	return what;
+    }
+
+    if (!DEVICE_INIT(mediaDevice)) {
+	msgConfirm("Unable to CDROM filesystem.");
+	what |= DITEM_FAILURE;
+	mediaClose();
+	return what;
+    }
+
+    fp = DEVICE_GET(mediaDevice, cp, TRUE);
+    if (fp) {
+	list = dispatch_load_fp(fp);
+	fclose(fp);
+	mediaClose();
+
+	what |= dispatch_execute(list);
+    }
+    else {
+	if (!variable_get(VAR_NO_ERROR))
+	    msgConfirm("Configuration file '%s' not found.", cp);
+	variable_unset(VAR_INSTALL_CFG);
+	what |= DITEM_FAILURE;
+	mediaClose();
+    }
+    return what;
+}
+
+/*
+ * Create a menu based on available disk devices
+ */
+int
+dispatch_load_menu(dialogMenuItem *self)
+{
+    DMenu	*menu;
+    Device	**devlist;
+    char	*err;
+    int		what, i, j, msize, count;
+    DeviceType	dtypes[] = {DEVICE_TYPE_FLOPPY, DEVICE_TYPE_CDROM, DEVICE_TYPE_DOS, DEVICE_TYPE_UFS};
+
+    fprintf(stderr, "dispatch_load_menu called\n");
+
+    msize = sizeof(DMenu) + (sizeof(dialogMenuItem) * 2);
+    count = 0;
+    err = NULL;
+    what = DITEM_SUCCESS;
+
+    if ((menu = malloc(msize)) == NULL) {
+	err = "Failed to allocate memory for menu";
+	goto errout;
+    }
+
+    bcopy(&MenuConfig, menu, sizeof(DMenu));
+
+    bzero(&menu->items[count], sizeof(menu->items[0]));
+    menu->items[count].prompt = strdup("X Exit");
+    menu->items[count].title = strdup("Exit this menu (returning to previous)");
+    menu->items[count].fire = dmenuExit;
+    count++;
+
+    for (i = 0; i < sizeof(dtypes) / sizeof(dtypes[0]); i++) {
+	if ((devlist = deviceFind(NULL, dtypes[i])) == NULL) {
+	    fprintf(stderr, "No devices found for type %d\n", dtypes[i]);
+	    continue;
+	}
+
+	for (j = 0; devlist[j] != NULL; j++) {
+	    fprintf(stderr, "device type %d device name %s\n", dtypes[i], devlist[j]->name);
+	    msize += sizeof(dialogMenuItem);
+	    if ((menu = realloc(menu, msize)) == NULL) {
+		err = "Failed to allocate memory for menu item";
+		goto errout;
+	    }
+
+	    bzero(&menu->items[count], sizeof(menu->items[0]));
+	    menu->items[count].fire = cfgModuleFire;
+
+	    menu->items[count].prompt = strdup(devlist[j]->name);
+	    menu->items[count].title = strdup(devlist[j]->description);
+	    /* XXX: dialog(3) sucks */
+	    menu->items[count].aux = (long)devlist[j];
+	    count++;
+	}
+    }
+
+    menu->items[count].prompt = NULL;
+    menu->items[count].title = NULL;
+
+    dmenuOpenSimple(menu, FALSE);
+
+  errout:
+    for (i = 0; i < count; i++) {
+	free(menu->items[i].prompt);
+	free(menu->items[i].title);
+    }
+
+    free(menu);
+
+    if (err != NULL) {
+	what |= DITEM_FAILURE;
+	if (!variable_get(VAR_NO_ERROR))
+	    msgConfirm(err);
+    }
+
+    return (what);
+
+}
+
+static int
+cfgModuleFire(dialogMenuItem *self) {
+    Device	*d;
+    FILE	*fp;
+    int		what = DITEM_SUCCESS;
+    extern char *distWanted;
+    qelement	*list;
+    char	*cp;
+
+    d = (Device *)self->aux;
+
+    msgDebug("cfgModuleFire: User selected %s (%s)\n", self->prompt, d->devname);
+
+    mediaClose();
+
+    cp = variable_get_value(VAR_INSTALL_CFG,
+			    "Specify the name of a configuration file", 0);
+    if (!cp || !*cp) {
+	variable_unset(VAR_INSTALL_CFG);
+	what |= DITEM_FAILURE;
+	return what;
+    }
+
+    distWanted = cp;
+
+    mediaDevice = d;
+    if (!DEVICE_INIT(mediaDevice)) {
+	msgConfirm("Unable to mount filesystem.");
+	what |= DITEM_FAILURE;
+	mediaClose();
+	return what;
+    }
+    msgDebug("getting fp for %s\n", cp);
+
+    fp = DEVICE_GET(mediaDevice, cp, TRUE);
+    if (fp) {
+	msgDebug("opened OK, processing..\n");
+
+	list = dispatch_load_fp(fp);
+	fclose(fp);
+	mediaClose();
+
+	what |= dispatch_execute(list);
+    } else {
+	if (!variable_get(VAR_NO_ERROR))
+	    msgConfirm("Configuration file '%s' not found.", cp);
+	variable_unset(VAR_INSTALL_CFG);
+	what |= DITEM_FAILURE;
+	mediaClose();
+    }
+
+    return(what);
+ }

Modified: head/usr.sbin/sysinstall/menus.c
==============================================================================
--- head/usr.sbin/sysinstall/menus.c	Fri Mar 13 03:00:38 2009	(r189753)
+++ head/usr.sbin/sysinstall/menus.c	Fri Mar 13 03:51:41 2009	(r189754)
@@ -152,7 +152,9 @@ DMenu MenuIndex = {
       { " Console settings",	"Customize system console behavior.",	NULL, dmenuSubmenu, NULL, &MenuSyscons },
 #endif
       { " Configure",		"The system configuration menu.",	NULL, dmenuSubmenu, NULL, &MenuConfigure },
-      { " Defaults, Load",	"Load default settings.",		NULL, dispatch_load_floppy },
+      { " Defaults, Load (FDD)","Load default settings from floppy.",	NULL, dispatch_load_floppy },
+      { " Defaults, Load (CD)",	"Load default settings from CDROM.",	NULL, dispatch_load_cdrom },
+      { " Defaults, Load",	"Load default settings (all devices).",	NULL, dispatch_load_menu },
 #ifdef WITH_MICE
       { " Device, Mouse",	"The mouse configuration menu.",	NULL, dmenuSubmenu, NULL, &MenuMouse },
 #endif
@@ -256,7 +258,7 @@ DMenu MenuInitial = {
       { "Options",	"View/Set various installation options",	NULL, optionsEditor },
       { "Fixit",	"Repair mode with CDROM/DVD/floppy or start shell",	NULL, dmenuSubmenu, NULL, &MenuFixit },
       { "Upgrade",	"Upgrade an existing system",			NULL, installUpgrade },
-      { "Load Config","Load default install configuration",		NULL, dispatch_load_floppy },
+      { "Load Config..","Load default install configuration",		NULL, dispatch_load_menu },
       { "Index",	"Glossary of functions",			NULL, dmenuSubmenu, NULL, &MenuIndex },
       { NULL } },
 };
@@ -818,6 +820,17 @@ DMenu MenuKLD = {
     { { NULL } },
 };
 
+/* Prototype config file load menu */
+DMenu MenuConfig = {
+    DMENU_NORMAL_TYPE,
+    "Config Menu",
+    "Please select the device to load your configuration file from.\n"
+    "Note that a USB key will show up as daNs1.",
+    NULL,
+    NULL,
+    { { NULL } },
+};
+
 /* The media selection menu */
 DMenu MenuMedia = {
     DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,

Modified: head/usr.sbin/sysinstall/modules.c
==============================================================================
--- head/usr.sbin/sysinstall/modules.c	Fri Mar 13 03:00:38 2009	(r189753)
+++ head/usr.sbin/sysinstall/modules.c	Fri Mar 13 03:51:41 2009	(r189754)
@@ -132,17 +132,13 @@ kldBrowser(dialogMenuItem *self)
     err = NULL;
     
     if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) {
-	msgConfirm("Unable to set media device to floppy.");
-	what |= DITEM_FAILURE;
-	mediaClose();
-	return what;
+	err = "Unable to set media device to floppy.";
+	goto errout;
     }
 
     if (!DEVICE_INIT(mediaDevice)) {
-	msgConfirm("Unable to mount floppy filesystem.");
-	what |= DITEM_FAILURE;
-	mediaClose();
-	return what;
+	err = "Unable to mount floppy filesystem.";
+	goto errout;
     }
 
     msize = sizeof(DMenu) + (sizeof(dialogMenuItem) * 2);
@@ -191,11 +187,10 @@ kldBrowser(dialogMenuItem *self)
     
     dmenuOpenSimple(menu, FALSE);
     
-    mediaClose();
-
     deviceRescan();
     
   errout:    
+    mediaClose();
     for (i = 0; i < count; i++)
 	free(menu->items[i].prompt);
     

Modified: head/usr.sbin/sysinstall/sysinstall.8
==============================================================================
--- head/usr.sbin/sysinstall/sysinstall.8	Fri Mar 13 03:00:38 2009	(r189753)
+++ head/usr.sbin/sysinstall/sysinstall.8	Fri Mar 13 03:51:41 2009	(r189754)
@@ -534,7 +534,16 @@ functions.
 .Pp
 .Sy Variables :
 None
-.It installExpress
+.It installConfigure
+Commit any rc.conf changes to disk.
+.Pp
+.Sy Variables :
+.Bl -tag -width indent
+.It keeprcconf
+Preserve existing rc.conf parameters.
+This is useful if you have a post-install script which modifies rc.conf.
+.El
+ .It installExpress
 Start an "express" installation, asking few questions of
 the user.
 .Pp
@@ -894,3 +903,6 @@ for these tasks.
 .Pp
 This utility is a prototype which lasted several years past
 its expiration date and is greatly in need of death.
+.Pp
+There are a (great) number of undocumented variables.
+UTSL.

Modified: head/usr.sbin/sysinstall/sysinstall.h
==============================================================================
--- head/usr.sbin/sysinstall/sysinstall.h	Fri Mar 13 03:00:38 2009	(r189753)
+++ head/usr.sbin/sysinstall/sysinstall.h	Fri Mar 13 03:51:41 2009	(r189754)
@@ -191,6 +191,7 @@
 #define VAR_HOME_SIZE			"homeSize"
 #define VAR_TERM			"TERM"
 #define VAR_CONSTERM                    "_consterm"
+#define VAR_KEEPRCCONF			"keeprcconf"
 
 #ifdef PC98
 #define DEFAULT_COUNTRY		"jp"
@@ -433,6 +434,7 @@ extern DMenu		MenuIndex;		/* Index menu	
 extern DMenu		MenuOptions;		/* Installation options				*/
 extern DMenu		MenuOptionsLanguage;	/* Language options menu			*/
 extern DMenu		MenuKLD;		/* Prototype KLD menu				*/
+extern DMenu		MenuConfig;		/* Prototype config menu				*/
 extern DMenu		MenuMedia;		/* Media type menu				*/
 #ifdef WITH_MICE
 extern DMenu		MenuMouse;		/* Mouse type menu				*/
@@ -577,8 +579,10 @@ extern int	diskGetSelectCount(Device ***
 /* dispatch.c */
 extern int	dispatchCommand(char *command);
 extern int	dispatch_load_floppy(dialogMenuItem *self);
+extern int	dispatch_load_cdrom(dialogMenuItem *self);
 extern int	dispatch_load_file_int(int);
 extern int	dispatch_load_file(dialogMenuItem *self);
+extern int	dispatch_load_menu(dialogMenuItem *self);
 
 
 /* dist.c */


More information about the svn-src-all mailing list