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

Re: deb-cfmgr: Debian conffile prompting tool.



On 26 Mar 2000 11:56:31 -0500, Wichert Akkerman wrote:
> I don't mind if people add a frontend on top of dpkg for this as long as
> the interface to dpkg is clean and simple and it can always work without
> a frontend..

As a first draft, realizing that the documentation is missing, how
does the folloing patch look. It provides a new dpkg option, 
--conffile-prompt-command, that executes a program with the canonical
name and the current file name of a conffile as arguments. If the exit
code of that program is 0, the file is kept. If it's 1, the file is
replaced, otherwise the current prompting code is run.

The new code only executes when the option is given on the command
line.

This is against the version of dpkg in woody, as I couldn't get the
cvs version to compile. 

Hm... also, I probably should replace that snprintf with something
else before this gets any closer to release.

-- 
Tom Rothamel --------- http://onegeek.org/~tom/ ------- Using GNU/Linux
	    Writing from home, just outside Northport, NY.
              The Moon is Waning Gibbous (62% of Full).

diff -u -r dpkg-1.6.11/main/configure.c dpkg-1.6.11-tom/main/configure.c
--- dpkg-1.6.11/main/configure.c	Fri Dec 24 16:55:37 1999
+++ dpkg-1.6.11-tom/main/configure.c	Sun Mar 26 13:38:40 2000
@@ -212,6 +212,38 @@
       debug(dbg_conff,
             "deferred_configure `%s' (= `%s') useredited=%d distedited=%d what=%o",
             conff->name, cdr.buf, useredited, distedited, what);
+
+      /* If a conffile-prompt-command was specified, we use that in
+       * rather than prompting the user. (We fall through to prompt if the
+       * command fails or there is some other error.)
+       */
+
+      if (conffile_prompt_command && (what & cfof_prompt)) {
+	char cmd[2048];
+	int rv;
+	
+	fprintf(stderr, _("\nConfiguration file `%s'"), conff->name);
+	if (strcmp(conff->name,cdr.buf))
+	  fprintf(stderr,_(" (actually `%s')"),cdr.buf);
+
+	snprintf(cmd, 2048, "%s %s %s", conffile_prompt_command, conff->name,
+		 cdr.buf);
+	
+	fprintf(stderr, _("\nExecuting conffile prompt command '%s'.\n"), cmd);
+	rv = system(cmd);
+
+	if (rv == 0) {
+	  fprintf(stderr, _("Chose to keep the file.\n"));
+	  what = cfo_keep;
+	} else if (rv == 1) {
+	  fprintf(stderr, _("Chose to replace the file.\n"));
+	  what = cfo_install;
+	} else {
+	  fprintf(stderr, _("Invalid exit code %d. Prompting the user for a choice.\n"), rv);
+	  /* Actually, by not setting what, we'll reach the code below. */
+	}	  
+      }
+
       
       /* When prompting we check for some of the force options. There are
        * several cases in which these occur.
diff -u -r dpkg-1.6.11/main/main.c dpkg-1.6.11-tom/main/main.c
--- dpkg-1.6.11/main/main.c	Sun Jan 16 18:15:48 2000
+++ dpkg-1.6.11-tom/main/main.c	Sun Mar 26 12:34:06 2000
@@ -141,6 +141,8 @@
 const char *instdir= "";
 struct packageinlist *ignoredependss=0;
 
+char *conffile_prompt_command = NULL;
+
 static const struct forceinfo {
   const char *name;
   int *opt;
@@ -364,6 +366,7 @@
   { "abort-after",        0,   1,  &errabort,      0,  setinteger,    0              },
   { "admindir",           0,   1,  0, &admindir,       0                             },
   { "instdir",            0,   1,  0, &instdir,        0                             },
+  { "conffile-prompt-command", 0, 1, 0, &conffile_prompt_command,     0              },  
   { "ignore-depends",     0,   1,  0, 0,               ignoredepends                 },
   { "force",              0,   2,  0, 0,               setforce,      1              },
   { "refuse",             0,   2,  0, 0,               setforce,      0              },
diff -u -r dpkg-1.6.11/main/main.h dpkg-1.6.11-tom/main/main.h
--- dpkg-1.6.11/main/main.h	Sat Oct 23 17:15:31 1999
+++ dpkg-1.6.11-tom/main/main.h	Sun Mar 26 13:17:01 2000
@@ -85,6 +85,8 @@
 extern int fc_autoselect, fc_badpath, fc_overwritediverted, fc_architecture;
 extern int fc_nonroot, fc_overwritedir, fc_conff_new, fc_conff_miss;
 extern int fc_conff_old, fc_conff_def;
+
+extern char *conffile_prompt_command;
 
 extern int errabort;
 extern const char *admindir;


Reply to: