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

[RFC] Add support for shells in the graphical installer



Hi!

It feels quite strange to look back at the past year and realize that
first task I really decided to tackle in the debian-installer might be
done with this mail…  The experience has been pretty intense and thanks
for the ride! :)

The attached patchset adds support for shells in the graphical
installer: "Execute a shell" in menu, and rescue-mode shells can now be
used in the graphical installer.

Main changes:
 * A new source package is introduced, cdebconf-terminal, which builds
   cdebconf-gtk-terminal.  It contains the "terminal" plugin for the
   GTK+ frontend.
 * A new script, start-shell, is added to di-utils-shell.  This script
   either uses debconf-disconnect (old style) or a newly introduced
   template using the new "terminal" type.  In order to reduce the
   memory footprint, start-shell tries to anna-install
   cdebconf-gtk-terminal when the plugin is not available.
 * di-utils-shell.postinst, rescue.d/shell and rescue.d/initrd-shell all
   uses start-shell.

The result is quite nice, and the user experience is very similar
between the different frontends.  The impact on the current code by
these changes are really low and they should be seen as strong candidate
for inclusion in Lenny.

cdebconf-gtk-terminal requires three new udebs on top of itself:
 * ttf-dejavu-mono-udeb containing DejaVu monospaced font.
   349kB compressed, 624kB installed
   (might surely be reduced if Davide take a look at it.)
   http://people.debian.org/~lunar/ttf-dejavu_2.25-1_add_mono-udeb.diff.gz
 * libvte9-udeb containing the VteTerminal widget used by the
   plugin.
   315kB compressed, 688kB installed
   http://people.debian.org/~lunar/vte_0.16.14-1_enable_udeb.diff.gz
 * libncurses5-udeb needed by libvte.
   80k compressed, 172k installed
   http://people.debian.org/~lunar/ncurses_5.6+20080614-1_enable_udeb.diff.gz

This patch adds 6 new translatable debconf templates.  They worth a
review, for sure. :)

I can't provide a test image right now as I am lacking the necessary
network connectivity.  I will try to provide one as soon as possible.
If there is no strong objections after a first round of testing, I would
like to ask for the changes outside d-i without waiting too much.

As all this work as been done offline, the changelogs probably miss a
"Closes" or two.

Cheers,
-- 
Jérémy Bobbio                        .''`. 
lunar@debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
commit 67a8e6b7a46ceae376833e537c731099c6749d5f
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Sun Jul 6 20:54:58 2008 +0000

    Add cdebconf-terminal package
    
    cdebconf-terminal builds a plugin for the GTK+ frontend adding the
    possibility to display terminals as debconf questions.
    
    This will allow shells to be started inside the graphical installer like
    the other frontends.
    
    As the terminal widget is provided by VTE, the package depends on
    libvte9-udeb.  It also depends on ttf-dejavu-mono-udeb to display properly
    monospaced fonts.
---
 packages/cdebconf-terminal/Makefile.in             |   51 ++++
 packages/cdebconf-terminal/configure.ac            |   31 +++
 .../debian/cdebconf-gtk-terminal.install           |    1 +
 .../debian/cdebconf-gtk-terminal.templates         |    3 +
 packages/cdebconf-terminal/debian/changelog        |    5 +
 packages/cdebconf-terminal/debian/compat           |    1 +
 packages/cdebconf-terminal/debian/control          |   19 ++
 packages/cdebconf-terminal/debian/copyright        |   30 +++
 packages/cdebconf-terminal/debian/po/POTFILES.in   |    1 +
 packages/cdebconf-terminal/debian/po/templates.pot |   23 ++
 packages/cdebconf-terminal/debian/rules            |   78 ++++++
 packages/cdebconf-terminal/gtk-plugin-terminal.c   |  270 ++++++++++++++++++++
 12 files changed, 513 insertions(+), 0 deletions(-)

diff --git a/packages/cdebconf-terminal/Makefile.in b/packages/cdebconf-terminal/Makefile.in
new file mode 100644
index 0000000..9d156b6
--- /dev/null
+++ b/packages/cdebconf-terminal/Makefile.in
@@ -0,0 +1,51 @@
+prefix=@prefix@
+etcdir=@sysconfdir@
+bindir=${prefix}/bin
+sbindir=${prefix}/sbin
+libdir=${prefix}/lib
+moddir=${libdir}/cdebconf/frontend
+sharedir=${prefix}/share/debconf
+mandir=${prefix}/share/man
+incdir=${prefix}/include/cdebconf
+
+PACKAGE=@PACKAGE@
+CC=@CC@
+CFLAGS=@CFLAGS@ -I.
+LDFLAGS=@LDFLAGS@
+GTK_CFLAGS=@GTK_CFLAGS@
+GTK_LIBS=@GTK_LIBS@
+
+CFLAGS += -funsigned-char -fstrict-aliasing -Wall -W -Werror -Wundef \
+	-Wwrite-strings -Wsign-compare -Wno-unused-parameter -Winit-self \
+	-Wpointer-arith -Wredundant-decls -Wno-format-zero-length \
+	-Wmissing-prototypes -Wmissing-format-attribute
+
+FRONTENDS=@FRONTENDS@
+PLUGIN_MODULES=$(addsuffix -plugin-$(PACKAGE).so,$(FRONTENDS))
+
+all: $(PLUGIN_MODULES)
+
+install: $(PLUGIN_MODULES)
+	for p in $(PLUGIN_MODULES); do \
+		install -m755 -d $(DESTDIR)/$(moddir)/$${p%%-*} ; \
+		install -m644 $$p $(DESTDIR)/$(moddir)/$${p%%-*}/$${p#*-} ; \
+	done
+
+gtk-plugin-$(PACKAGE).so: gtk-plugin-$(PACKAGE).opic
+	$(CC) $(LDFLAGS) -shared -o $@ $^ $(GTK_LIBS) -lvte
+
+clean:
+	rm -f $(PLUGIN_MODULES)
+	rm -f *.opic
+
+distclean: clean
+	rm -f config.log config.status
+	rm -f Makefile
+
+gtk-%.opic: gtk-%.c
+	@echo "Compiling $< to $@"
+	$(CC) $(CFLAGS) $(GTK_CFLAGS) -fPIC -o $@ -c $<
+
+%.opic: %.c
+	@echo "Compiling $< to $@"
+	$(CC) $(CFLAGS) -fPIC -o $@ -c $<
diff --git a/packages/cdebconf-terminal/configure.ac b/packages/cdebconf-terminal/configure.ac
new file mode 100644
index 0000000..2297f0f
--- /dev/null
+++ b/packages/cdebconf-terminal/configure.ac
@@ -0,0 +1,31 @@
+AC_INIT
+
+PACKAGE=terminal
+AC_DEFINE_UNQUOTED(PACKAGE,"$PACKAGE")
+
+AC_PROG_MAKE_SET
+AC_PROG_CC
+
+dnl Enable debugging?
+AC_ARG_WITH(debug,[  --without-debug         turn off debugging?])
+if test "$with_debug" == "yes"; then
+  AC_DEFINE(DODEBUG)
+  CFLAGS="$CFLAGS -g -D_DEBUG_"
+fi
+
+FRONTENDS=""
+
+PKG_CHECK_MODULES(GTK, [gtk+-directfb-2.0],
+ FRONTENDS="$FRONTENDS gtk",
+ echo "*** Cannot build GTK+ plugin ***")
+
+PKG_CHECK_MODULES(VTE, [vte])
+
+AC_SUBST(GTK_CFLAGS)
+AC_SUBST(GTK_LIBS)
+AC_SUBST(VTE_CFLAGS)
+AC_SUBST(FRONTENDS)
+AC_SUBST(PACKAGE)
+
+AC_OUTPUT(Makefile)
+
diff --git a/packages/cdebconf-terminal/debian/cdebconf-gtk-terminal.install b/packages/cdebconf-terminal/debian/cdebconf-gtk-terminal.install
new file mode 100644
index 0000000..3a7472e
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/cdebconf-gtk-terminal.install
@@ -0,0 +1 @@
+usr/lib/cdebconf/frontend/gtk
diff --git a/packages/cdebconf-terminal/debian/cdebconf-gtk-terminal.templates b/packages/cdebconf-terminal/debian/cdebconf-gtk-terminal.templates
new file mode 100644
index 0000000..ff6f91c
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/cdebconf-gtk-terminal.templates
@@ -0,0 +1,3 @@
+Template: debconf/terminal/gtk/child-exit
+Type: text
+_Description: Shell process has exited.
diff --git a/packages/cdebconf-terminal/debian/changelog b/packages/cdebconf-terminal/debian/changelog
new file mode 100644
index 0000000..51d6255
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/changelog
@@ -0,0 +1,5 @@
+cdebconf-terminal (0.1) UNRELEASED; urgency=low
+
+  * Initial release.
+
+ -- Jérémy Bobbio <lunar@debian.org>  Sun, 06 Jul 2008 20:49:52 +0000
diff --git a/packages/cdebconf-terminal/debian/compat b/packages/cdebconf-terminal/debian/compat
new file mode 100644
index 0000000..b8626c4
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/compat
@@ -0,0 +1 @@
+4
diff --git a/packages/cdebconf-terminal/debian/control b/packages/cdebconf-terminal/debian/control
new file mode 100644
index 0000000..217807a
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/control
@@ -0,0 +1,19 @@
+Source: cdebconf-terminal
+Priority: extra
+Section: debian-installer
+Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
+Uploaders: Jérémy Bobbio <lunar@debian.org>
+Build-Depends: debhelper (>= 4.2), libdebconfclient0-dev (>= 0.130), libgtk-directfb-2.0-dev, libvte-dev (>> 0.16.14-1)
+Standards-Version: 3.8.0
+Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/cdebconf-terminal
+
+Package: cdebconf-gtk-terminal
+Architecture: any
+Section: debian-installer
+Depends: cdebconf-gtk-udeb, ttf-dejavu-mono-udeb, ${shlibs:Depends}
+Provides: cdebconf-entropy
+XC-Package-Type: udeb
+Description: cdebconf gtk plugin dislaying a terminal
+ cdebconf plugin to display a terminal inside the debian-installer graphical
+ frontend.
+
diff --git a/packages/cdebconf-terminal/debian/copyright b/packages/cdebconf-terminal/debian/copyright
new file mode 100644
index 0000000..48794a7
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/copyright
@@ -0,0 +1,30 @@
+cdebconf-entropy is Copyright 2008 Jérémy Bobbio <lunar@debian.org>
+
+Makefile.in, configure.ac and debian/rules were initially written by
+Tollef Fog Heen <tfheen@debian.org> for cdebconf-keystep. They were
+downloaded as part of cdebconf-keystep_0.3.tar.gz from
+http://ubuntu.cn99.com/ubuntu/pool/main/c/cdebconf-keystep/cdebconf-keystep_0.3.tar.gz
+
+License:
+
+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 AUTHORS 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 AUTHOR 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.
+
diff --git a/packages/cdebconf-terminal/debian/po/POTFILES.in b/packages/cdebconf-terminal/debian/po/POTFILES.in
new file mode 100644
index 0000000..a7b5184
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/po/POTFILES.in
@@ -0,0 +1 @@
+[type: gettext/rfc822deb] cdebconf-gtk-terminal.templates
diff --git a/packages/cdebconf-terminal/debian/po/templates.pot b/packages/cdebconf-terminal/debian/po/templates.pot
new file mode 100644
index 0000000..50e657f
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/po/templates.pot
@@ -0,0 +1,23 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: cdebconf-terminal@packages.debian.org\n"
+"POT-Creation-Date: 2008-07-08 13:02+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Type: text
+#. Description
+#: ../cdebconf-gtk-terminal.templates:1001
+msgid "Shell process has exited."
+msgstr ""
diff --git a/packages/cdebconf-terminal/debian/rules b/packages/cdebconf-terminal/debian/rules
new file mode 100755
index 0000000..f7f6957
--- /dev/null
+++ b/packages/cdebconf-terminal/debian/rules
@@ -0,0 +1,78 @@
+#! /usr/bin/make -f
+# -*- makefile -*-
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+	CFLAGS += -O0
+else
+	CFLAGS += -O2
+endif
+
+ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
+	confflags += --build $(DEB_HOST_GNU_TYPE)
+else
+	confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
+endif
+
+config.status: configure
+	dh_testdir
+	CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,syms" ./configure $(confflags) --prefix=/usr
+
+build: build-stamp
+build-stamp:  config.status
+	dh_testdir
+	$(MAKE)
+	touch build-stamp
+
+clean:
+	dh_testdir
+	dh_testroot
+	rm -f build-stamp
+
+	[ ! -f Makefile ] || $(MAKE) distclean
+ifneq "$(wildcard /usr/share/misc/config.sub)" ""
+	cp -f /usr/share/misc/config.sub config.sub
+endif
+ifneq "$(wildcard /usr/share/misc/config.guess)" ""
+	cp -f /usr/share/misc/config.guess config.guess
+endif
+	dh_clean
+
+install: build
+	dh_testdir
+	dh_testroot
+	dh_clean -k
+	dh_installdirs
+	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+	dh_testdir
+	dh_testroot
+	dh_installchangelogs
+	dh_installdocs
+	dh_installdebconf
+	dh_install --sourcedir=debian/tmp
+	dh_link
+	dh_strip
+	dh_compress
+	dh_fixperms
+	dh_installdeb
+	dh_shlibdeps
+	dh_gencontrol
+	dh_md5sums
+	dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
diff --git a/packages/cdebconf-terminal/gtk-plugin-terminal.c b/packages/cdebconf-terminal/gtk-plugin-terminal.c
new file mode 100644
index 0000000..23eddf6
--- /dev/null
+++ b/packages/cdebconf-terminal/gtk-plugin-terminal.c
@@ -0,0 +1,270 @@
+/*
+ * cdebconf gtk plugin to display a terminal
+ *
+ * Copyright © 2008 Jérémy Bobbio <lunar@debian.org>
+ * See debian/copyright for license.
+ *
+ */
+
+#include <cdebconf/frontend.h>
+#include <cdebconf/cdebconf_gtk.h>
+
+#include <gtk/gtk.h>
+#include <vte/vte.h>
+#include <string.h>
+
+extern char ** environ;
+
+#define DEFAULT_COMMAND_LINE "/bin/sh"
+
+/* Here's the plugin! */
+int cdebconf_gtk_handler_terminal(struct frontend * fe,
+                                  struct question * question,
+                                  GtkWidget * question_box);
+
+struct terminal {
+    struct frontend * fe;
+    GtkWidget * continue_button;
+    VteTerminal * terminal;
+    char * command;
+    char ** argv;
+    char ** environ;
+};
+
+static void destroy_terminal(struct terminal * terminal_data)
+{
+    if (NULL != terminal_data->command) {
+        g_free(terminal_data->command);
+    }
+    if (NULL != terminal_data->argv) {
+        g_strfreev(terminal_data->argv);
+    }
+    if (NULL != terminal_data->environ) {
+        g_strfreev(terminal_data->environ);
+    }
+    if (NULL != terminal_data->terminal) {
+        g_object_unref(G_OBJECT(terminal_data->terminal));
+    }
+    if (NULL != terminal_data->continue_button) {
+        g_object_unref(G_OBJECT(terminal_data->continue_button));
+    }
+    g_free(terminal_data);
+}
+
+static void cleanup(GtkWidget * widget, struct terminal * terminal_data)
+{
+    destroy_terminal(terminal_data);
+}
+
+static void handle_continue(GtkWidget * button,
+                            struct terminal * terminal_data)
+{
+    cdebconf_gtk_set_answer_ok(terminal_data->fe);
+}
+
+static void handle_child_exit(GtkWidget * button,
+                              struct terminal * terminal_data)
+{
+    char * child_exit_text;
+
+    child_exit_text = cdebconf_gtk_get_text(
+        terminal_data->fe, "debconf/terminal/gtk/child-exit",
+        "Shell process has exited.");
+    vte_terminal_feed(terminal_data->terminal, "\n\n", 2 /* length */);
+    vte_terminal_feed(terminal_data->terminal, child_exit_text,
+                      strlen(child_exit_text));
+    g_free(child_exit_text);
+
+    gtk_widget_set_sensitive(terminal_data->continue_button, TRUE);
+    GTK_WIDGET_SET_FLAGS(terminal_data->continue_button, GTK_CAN_FOCUS);
+    gtk_widget_grab_focus(GTK_WIDGET(terminal_data->continue_button));
+    gtk_widget_grab_default(GTK_WIDGET(terminal_data->continue_button));
+}
+
+static struct terminal * init_terminal(struct frontend * fe,
+                                       struct question * question)
+{
+    struct terminal * terminal_data;
+
+    if (NULL == (terminal_data = g_malloc0(sizeof (struct terminal)))) {
+        g_critical("g_malloc0 failed.");
+        return NULL;
+    }
+    terminal_data->fe = fe;
+
+    return terminal_data;
+}
+
+static gboolean init_command(struct terminal * terminal_data,
+                             struct question * question)
+{
+    const char * command_line;
+
+    command_line = question_get_variable(question, "COMMAND_LINE");
+    if (NULL == command_line) {
+        command_line = DEFAULT_COMMAND_LINE;
+    }
+    terminal_data->argv = g_strsplit_set(
+        command_line, " \t\n" /* default IFS */,
+        4096 /* max number of arguments */
+        /* XXX: replace with the correct system macro */);
+    if (NULL == terminal_data->argv) {
+        g_critical("g_strsplit_set failed.");
+        return FALSE;
+    }
+    terminal_data->command = g_strdup(terminal_data->argv[0]);
+    if (NULL == terminal_data->command) {
+        g_critical("g_strplit_set failed.");
+        return FALSE;
+    }
+    return TRUE;
+}
+
+static GtkWidget * create_widgets(struct terminal * terminal_data)
+{
+    GtkWidget * hbox;
+    VteTerminal * terminal;
+    GtkWidget * scrollbar;
+    GtkWidget * continue_button;
+
+    continue_button = cdebconf_gtk_create_continue_button(terminal_data->fe);
+    if (NULL == continue_button) {
+        g_critical("cdebconf_gtk_create_continue_button failed.");
+        return NULL;
+    }
+    GTK_WIDGET_UNSET_FLAGS(continue_button, GTK_CAN_FOCUS);
+    gtk_widget_set_sensitive(continue_button, FALSE);
+    g_signal_connect(continue_button, "clicked", G_CALLBACK(handle_continue),
+                     terminal_data);
+    g_object_ref(G_OBJECT(continue_button));
+    terminal_data->continue_button = continue_button;
+
+    g_setenv("VTE_BACKEND", "pango", TRUE /* overwrite */);
+    if (NULL == (terminal = VTE_TERMINAL(vte_terminal_new()))) {
+        g_critical("vte_terminal_new failed.");
+        return NULL;
+    }
+    vte_terminal_set_font_from_string(terminal, "monospace");
+    g_signal_connect(terminal, "destroy", G_CALLBACK(cleanup), terminal_data);
+    g_signal_connect(terminal, "child-exited", G_CALLBACK(handle_child_exit),
+                     terminal_data);
+    g_signal_connect(terminal, "realize", G_CALLBACK(gtk_widget_grab_focus),
+                     NULL);
+    g_object_ref(terminal);
+    terminal_data->terminal = terminal;
+
+    hbox = gtk_hbox_new(FALSE /* not homogeneous */, 0 /* no spacing */);
+    if (NULL == hbox) {
+        g_critical("gtk_hbox_new failed.");
+        return NULL;
+    }
+    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(terminal), TRUE /* expand */,
+                       TRUE /* fill */, 0 /* no padding */);
+
+    scrollbar = gtk_vscrollbar_new(terminal->adjustment);
+    if (NULL == scrollbar) {
+        g_critical("gtk_vscrollbar_new failed.");
+        return NULL;
+    }
+    gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE /* don't expand */,
+                       FALSE /* don't fill */, 0 /* no padding */);
+    return hbox;
+}
+
+static void set_nothing(struct question * question, void * dummy)
+{
+    /* terminal questions do not put anything in the database */
+    return;
+}
+
+static gboolean prepare_environ(struct terminal * terminal_data)
+{
+    guint orig_index;
+    guint new_index;
+    const char * src;
+
+    terminal_data->environ = g_malloc0(
+        sizeof (char *) * g_strv_length(environ));
+    if (NULL == terminal_data->environ) {
+        g_critical("g_malloc0 failed.");
+        return FALSE;
+    }
+    new_index = 0;
+    for (orig_index = 0; NULL != environ[orig_index]; orig_index++) {
+        if (g_str_has_prefix(environ[orig_index], "DEBIAN_HAS_FRONTEND=")) {
+            src = "DEBIAN_HAS_FRONTEND=";
+        } else if (g_str_has_prefix(environ[orig_index], "DEBIAN_FRONTEND=")) {
+            src = "DEBIAN_FRONTEND=newt";
+        } else {
+            src = environ[orig_index];
+        }
+        if (NULL == (terminal_data->environ[new_index] = g_strdup(src))) {
+            g_critical("g_strdup failed.");
+            return FALSE;
+        }
+        new_index++;
+    }
+    return TRUE;
+}
+
+static gboolean start_command(struct terminal * terminal_data)
+{
+    pid_t pid;
+
+    pid = vte_terminal_fork_command(
+        terminal_data->terminal, terminal_data->command,
+        terminal_data->argv, terminal_data->environ, "/",
+        FALSE /* no lastlog */, FALSE /* no utmp */, FALSE /* no wtmp */);
+    if (0 == pid) {
+        g_critical("vte_terminal_fork_command failed.");
+        return FALSE;
+    }
+    return TRUE;
+}
+
+int cdebconf_gtk_handler_terminal(struct frontend * fe,
+                                  struct question * question,
+                                  GtkWidget * question_box)
+{
+    struct terminal * terminal_data;
+    GtkWidget * widget;
+
+    if (!IS_QUESTION_SINGLE(question)) {
+        g_critical("entropy plugin does not work alongside other questions.");
+        return DC_NOTOK;
+    }
+    if (NULL == (terminal_data = init_terminal(fe, question))) {
+        g_critical("init_terminal failed.");
+        return DC_NOTOK;
+    }
+    if (NULL == (widget = create_widgets(terminal_data))) {
+        g_critical("create_widgets failed.");
+        goto failed;
+    }
+    if (!init_command(terminal_data, question)) {
+        g_critical("init_command failed.");
+        goto failed;
+    }
+    if (!prepare_environ(terminal_data)) {
+        g_critical("prepare_environ failed.");
+        goto failed;
+    }
+    if (!start_command(terminal_data)) {
+        g_critical("start_command failed.");
+        goto failed;
+    }
+
+    cdebconf_gtk_add_common_layout(fe, question, question_box, widget);
+
+    cdebconf_gtk_register_setter(fe, SETTER_FUNCTION(set_nothing), question,
+                                 NULL);
+
+    return DC_OK;
+
+failed:
+    destroy_terminal(terminal_data);
+    return DC_NOTOK;
+}
+
+/* vim: et sw=4 si
+ */

commit f47d87b2c29da219d5cd3ab6d7bb86ae385e62ba
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Sun Jul 6 21:42:28 2008 +0000

    Add tests in cdebconf for the terminal plugin
---
 packages/cdebconf/debian/changelog            |    3 +++
 packages/cdebconf/src/test/terminal.config    |   17 +++++++++++++++++
 packages/cdebconf/src/test/terminal.templates |    7 +++++++
 3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/packages/cdebconf/debian/changelog b/packages/cdebconf/debian/changelog
index 432d0a3..99a352d 100644
--- a/packages/cdebconf/debian/changelog
+++ b/packages/cdebconf/debian/changelog
@@ -15,6 +15,9 @@ cdebconf (0.132) UNRELEASED; urgency=low
     and add support for a dark theme in the text frontend if used with
     "linux" or "bterm" consoles. Closes: #488494.
 
+  [ Jérémy Bobbio ]
+  * Add tests for the new terminal plugin.
+
  -- Frans Pop <fjp@debian.org>  Sun, 29 Jun 2008 18:17:47 +0200
 
 cdebconf (0.131) unstable; urgency=low
diff --git a/packages/cdebconf/src/test/terminal.config b/packages/cdebconf/src/test/terminal.config
new file mode 100755
index 0000000..42cb83d
--- /dev/null
+++ b/packages/cdebconf/src/test/terminal.config
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+. ../client/confmodule
+
+db_capb
+echo "capb: $RET"
+if ! echo "$RET" | grep -w plugin-terminal; then
+        echo "terminal plugin not available"
+        exit 1
+fi
+
+db_subst test/terminal COMMAND_LINE /bin/sh -x
+db_fset test/terminal seen false
+db_input high test/terminal
+db_go
+
+echo "$RET"
diff --git a/packages/cdebconf/src/test/terminal.templates b/packages/cdebconf/src/test/terminal.templates
new file mode 100644
index 0000000..0330cb5
--- /dev/null
+++ b/packages/cdebconf/src/test/terminal.templates
@@ -0,0 +1,7 @@
+Template: test/terminal
+Type: terminal
+Description: Feel free to rescue your system.
+
+Template: debconf/terminal/gtk/child-exit
+Type: text
+Description: Shell process has exited.

commit e68db4ad921e7ccd692574077831fd126aa51487
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Sun Jul 6 23:15:13 2008 +0000

    Add start-shell in di-utils-shell
    
    di-utils-shell now ships a new script, start-shell, which will either use
    debconf-disconnect or the new cdebconf terminal plugin.
    
    di-utils-shell.postinst has been updated to use this new script.
---
 packages/debian-installer-utils/debian/changelog   |    7 +++
 .../debian/di-utils-shell.install                  |    1 +
 .../debian/di-utils-shell.isinstallable            |    5 --
 .../debian/di-utils-shell.postinst                 |    2 +-
 .../debian/di-utils-shell.templates                |   28 ++++++++++
 packages/debian-installer-utils/debian/rules       |    2 +-
 packages/debian-installer-utils/start-shell        |   56 ++++++++++++++++++++
 7 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/packages/debian-installer-utils/debian/changelog b/packages/debian-installer-utils/debian/changelog
index 660bb47..c2fc88e 100644
--- a/packages/debian-installer-utils/debian/changelog
+++ b/packages/debian-installer-utils/debian/changelog
@@ -1,7 +1,14 @@
 debian-installer-utils (1.60) UNRELEASED; urgency=low
 
+  [ Joey Hess ]
   * Use new "mountmedia floppy" command instead of mountfloppy.
 
+  [ Jérémy Bobbio ]
+  * Ship start-shell in di-utils-shell.  It allows a shell to be started
+    either with debconf-disconnect or with the terminal plugin for the GTK+
+    frontend.
+  * Use start-shell in di-utils-shell.postinst.
+
  -- Joey Hess <joeyh@debian.org>  Fri, 20 Jun 2008 15:40:04 -0400
 
 debian-installer-utils (1.59) unstable; urgency=low
diff --git a/packages/debian-installer-utils/debian/di-utils-shell.install b/packages/debian-installer-utils/debian/di-utils-shell.install
new file mode 100644
index 0000000..fa32586
--- /dev/null
+++ b/packages/debian-installer-utils/debian/di-utils-shell.install
@@ -0,0 +1 @@
+start-shell bin
diff --git a/packages/debian-installer-utils/debian/di-utils-shell.isinstallable b/packages/debian-installer-utils/debian/di-utils-shell.isinstallable
deleted file mode 100755
index 52cf82b..0000000
--- a/packages/debian-installer-utils/debian/di-utils-shell.isinstallable
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-if [ "$DEBIAN_FRONTEND" = gtk ]; then
-	exit 1
-fi
-exit 0
diff --git a/packages/debian-installer-utils/debian/di-utils-shell.postinst b/packages/debian-installer-utils/debian/di-utils-shell.postinst
index 6fbfad6..203bab7 100644
--- a/packages/debian-installer-utils/debian/di-utils-shell.postinst
+++ b/packages/debian-installer-utils/debian/di-utils-shell.postinst
@@ -6,4 +6,4 @@ db_capb backup
 db_input high di-utils-shell/do-shell
 db_go || exit 10
 
-debconf-disconnect /bin/sh || true
+start-shell di-utils-shell/do-shell /bin/sh || true
diff --git a/packages/debian-installer-utils/debian/di-utils-shell.templates b/packages/debian-installer-utils/debian/di-utils-shell.templates
index d84a942..4ff8c49 100644
--- a/packages/debian-installer-utils/debian/di-utils-shell.templates
+++ b/packages/debian-installer-utils/debian/di-utils-shell.templates
@@ -11,6 +11,34 @@ _Description: Interactive shell
  .
  Use the "exit" command to return to the installation menu.
 
+Template: di-utils-shell/shell-plugin
+Type: terminal
+# :sl2:
+_Description: ${TITLE}
+
+Template: di-utils-shell/shell-plugin-default-title
+Type: text
+# :sl2:
+_Description: Interactive shell
+
+Template: di-utils-shell/terminal-plugin-unavailable
+Type: error
+# :sl2:
+_Description: Terminal plugin unavailable
+ This build of the debian-installer requires the terminal plugin in
+ order to display a shell. Unfortunately, this plugin is currently
+ unavailable.
+ .
+ It should be available after reaching the "Loading additional components"
+ installation step.
+ .
+ ${WORKAROUND}
+
+Template: di-utils-shell/workaround-gtk
+Type: text
+# :sl2:
+_Description: In the meantime, a shell is still accessible by pressing Ctrl+Alt+F2.  Use Alt+F5 to get back to the installer.
+
 Template: debian-installer/di-utils-shell/title
 Type: text
 #  Main menu item
diff --git a/packages/debian-installer-utils/debian/rules b/packages/debian-installer-utils/debian/rules
index 49cda69..70ed8f2 100755
--- a/packages/debian-installer-utils/debian/rules
+++ b/packages/debian-installer-utils/debian/rules
@@ -22,6 +22,7 @@ binary-indep: build
 	dh_testdir
 	dh_testroot
 	dh_clean -k
+	dh_install -i
 	dh_installdebconf -i
 	dh_compress -i
 	dh_fixperms -i
@@ -31,7 +32,6 @@ binary-indep: build
 		cp -pL $$file debian/di-utils-terminfo/$$file; \
 		chmod 644 debian/di-utils-terminfo/$$file; \
 	done
-	cp debian/di-utils-shell.isinstallable debian/di-utils-shell/DEBIAN/isinstallable
 	dh_installdeb -i
 	dh_gencontrol -i
 	dh_builddeb -i
diff --git a/packages/debian-installer-utils/start-shell b/packages/debian-installer-utils/start-shell
new file mode 100755
index 0000000..0ef2dac
--- /dev/null
+++ b/packages/debian-installer-utils/start-shell
@@ -0,0 +1,56 @@
+#! /bin/sh -e
+
+. /usr/share/debconf/confmodule
+
+TITLE_TEMPLATE="$1"
+shift
+COMMAND_LINE="$@"
+
+have_terminal_plugin () {
+	db_capb
+	set -- $RET
+	for cap; do
+		if [ "$cap" = plugin-terminal ]; then
+			return 0
+		fi
+	done
+	return 1
+}
+
+show_unavailable_message () {
+	local workaround_template
+
+	workaround_template=di-utils-shell/workaround-$DEBIAN_FRONTEND
+	if ! db_metaget $workaround_template description; then
+		RET=""
+	fi
+	db_subst di-utils-shell/terminal-plugin-unavailable WORKAROUND "$RET"
+	db_fset di-utils-shell/terminal-plugin-unavailable seen false
+	db_input critical di-utils-shell/terminal-plugin-unavailable
+	db_go || true
+	db_capb backup
+}
+
+case $DEBIAN_FRONTEND in
+    text|newt)
+	debconf-disconnect $COMMAND_LINE || true
+	;;
+    *)
+	if ! have_terminal_plugin; then
+		anna-install cdebconf-$DEBIAN_FRONTEND-terminal
+		if ! have_terminal_plugin; then
+			show_unavailable_message
+			exit 1
+		fi
+	fi
+	if ! db_metaget $TITLE_TEMPLATE description; then
+		db_metaget di-utils-shell/shell-plugin-default-title description
+	fi
+	db_subst di-utils-shell/shell-plugin TITLE "$RET"
+	db_subst di-utils-shell/shell-plugin COMMAND_LINE $COMMAND_LINE
+	db_fset di-utils-shell/shell-plugin seen false
+	db_input critical di-utils-shell/shell-plugin
+	db_go || true
+	db_capb backup
+	;;
+esac

commit fbfbd0cb3341647d820fb6ab54e8e801def78e3e
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Sun Jul 6 22:03:19 2008 +0000

    Use start-shell in rescue-mode
    
    rescue-mode now uses start-shell from di-utils-shell (>= 1.60).  This
    means that shells are now available in all installer frontends.
---
 packages/rescue/debian/changelog             |    8 ++++++++
 packages/rescue/debian/control               |    2 +-
 packages/rescue/debian/rescue-mode.templates |   10 ++++++++++
 packages/rescue/rescue.d/_numbers            |    2 --
 packages/rescue/rescue.d/initrd-shell        |    2 +-
 packages/rescue/rescue.d/initrd-shell.tst    |    2 --
 packages/rescue/rescue.d/shell               |    3 ++-
 packages/rescue/rescue.d/shell.tst           |    2 --
 8 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/packages/rescue/debian/changelog b/packages/rescue/debian/changelog
index 5133fd2..29694a6 100644
--- a/packages/rescue/debian/changelog
+++ b/packages/rescue/debian/changelog
@@ -1,3 +1,11 @@
+rescue (1.16) UNRELEASED; urgency=low
+
+  [ Jérémy Bobbio ]
+  * Use start-shell from di-utils-shell (>= 1.60) to start rescue shells.
+    This enables using shells in the graphical installer.
+
+ -- Jérémy Bobbio <lunar@debian.org>  Sun, 06 Jul 2008 22:49:27 +0000
+
 rescue (1.15) unstable; urgency=low
 
   [ Updated translations ]
diff --git a/packages/rescue/debian/control b/packages/rescue/debian/control
index 2ce24c2..c4270f6 100644
--- a/packages/rescue/debian/control
+++ b/packages/rescue/debian/control
@@ -10,7 +10,7 @@ Package: rescue-check
 Architecture: all
 Priority: standard
 XC-Package-Type: udeb
-Depends: cdebconf-udeb (>= 0.75), main-menu (>= 1.03), di-utils (>= 1.18)
+Depends: cdebconf-udeb (>= 0.75), main-menu (>= 1.03), di-utils (>= 1.18), di-utils-shell (>= 1.60) 
 Description: enter d-i rescue mode if requested
 
 Package: rescue-mode
diff --git a/packages/rescue/debian/rescue-mode.templates b/packages/rescue/debian/rescue-mode.templates
index cfa7add..fca8ad2 100644
--- a/packages/rescue/debian/rescue-mode.templates
+++ b/packages/rescue/debian/rescue-mode.templates
@@ -86,6 +86,11 @@ Type: error
 _Description: No shell found in /target
  No usable shell was found on your root file system (${DEVICE}).
 
+Template: rescue/shell/title
+Type: text
+# :sl2:
+_Description: Interactive shell on ${DEVICE}
+
 Template: rescue/initrd-shell/intro
 Type: text
 # :sl2:
@@ -96,6 +101,11 @@ _Description: Executing a shell
  "chroot /target". If you need any other file systems (such as a separate
  "/usr"), you will have to mount those yourself.
 
+Template: rescue/initrd-shell/title
+Type: text
+# :sl2:
+_Description: Interactive shell in the installer environment
+
 Template: rescue/passphrase
 Type: password
 # :sl2:
diff --git a/packages/rescue/rescue.d/_numbers b/packages/rescue/rescue.d/_numbers
index 6d05bd4..ce04a2d 100644
--- a/packages/rescue/rescue.d/_numbers
+++ b/packages/rescue/rescue.d/_numbers
@@ -1,6 +1,4 @@
 10 shell
-10 shell.tst
 15 initrd-shell
-15 initrd-shell.tst
 98 change-root
 99 reboot
diff --git a/packages/rescue/rescue.d/initrd-shell b/packages/rescue/rescue.d/initrd-shell
index 545585a..fe72c2f 100755
--- a/packages/rescue/rescue.d/initrd-shell
+++ b/packages/rescue/rescue.d/initrd-shell
@@ -1,2 +1,2 @@
 #! /bin/sh
-debconf-disconnect /bin/sh -i
+start-shell rescue/initrd-shell/title /bin/sh -i
diff --git a/packages/rescue/rescue.d/initrd-shell.tst b/packages/rescue/rescue.d/initrd-shell.tst
deleted file mode 100755
index 46269b2..0000000
--- a/packages/rescue/rescue.d/initrd-shell.tst
+++ /dev/null
@@ -1,2 +0,0 @@
-#! /bin/sh -e
-[ "$DEBIAN_FRONTEND" != gtk ]
diff --git a/packages/rescue/rescue.d/shell b/packages/rescue/rescue.d/shell
index af125cf..ae67c82 100755
--- a/packages/rescue/rescue.d/shell
+++ b/packages/rescue/rescue.d/shell
@@ -7,7 +7,8 @@ chroot_has () {
 }
 
 chroot_run () {
-	debconf-disconnect chroot /target "$@"
+	db_subst rescue/shell/title DEVICE "$RESCUE_ROOTDEV"
+	start-shell rescue/shell/title chroot /target "$@"
 }
 
 # Work out a sensible $PATH with respect to /target.
diff --git a/packages/rescue/rescue.d/shell.tst b/packages/rescue/rescue.d/shell.tst
deleted file mode 100755
index 46269b2..0000000
--- a/packages/rescue/rescue.d/shell.tst
+++ /dev/null
@@ -1,2 +0,0 @@
-#! /bin/sh -e
-[ "$DEBIAN_FRONTEND" != gtk ]

Attachment: signature.asc
Description: Digital signature


Reply to: