Browse Source

Added Status field parsing, and it is used to determine the default menu

item

debconf_command takes a variable argument list, and I was able to use this
to cut down on the exectuatable size some by only hardcoding MAIN_MENU
once.

The item in the TODO is very important in the long run.

r31
keep-around/c8703c509368e1805e513d61f98a9d17d2cdd9cc
Joey Hess 22 years ago
parent
commit
bf63f87057
  1. 4
      Makefile
  2. 5
      TODO
  3. 11
      debconf.c
  4. 34
      main-menu.c
  5. 10
      main-menu.h
  6. 11
      status
  7. 15
      status.c

4
Makefile

@ -10,5 +10,9 @@ $(BIN): $(OBJS)
demo: $(BIN)
/usr/share/debconf/frontend ./$(BIN)
strip: $(BIN)
strip --remove-section=.comment --remove-section=.note \
--strip-unneeded $(BIN)
clean:
-rm -f $(BIN) $(OBJS) *~

5
TODO

@ -0,0 +1,5 @@
* Does not support translating menu items. Two possibilities:
- Use Description-<LL> even though dpkg doesn't know how to handle it.
- Read in a detached file with menu description and menu ordering info in
it. This may be more flexable anyway.. (It would also allow a single
package to show 2 menu items.)

11
debconf.c

@ -1,9 +1,16 @@
#include "main-menu.h"
#include <stdio.h>
#include <stdarg.h>
int debconf_command (const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
printf("\n");
int debconf_command (char *command) {
printf("%s\n", command);
/* TODO: read result from debconf */
return 1;
}

34
main-menu.c

@ -50,7 +50,8 @@ void main_menu(struct package_t *packages) {
struct package_t **package_list, *p, *head = NULL, *tail = NULL;
int i = 0, num = 0;
void *package_tree = NULL;
char *s, menutext[1024] = "SUBST " MAIN_MENU " MENU ";
char *s, *menudefault = NULL;
char menutext[1024] = "";
/* Make a flat list of the packages, plus a btree for name lookup. */
for (p = packages; p; p = p->next) {
@ -74,25 +75,36 @@ void main_menu(struct package_t *packages) {
}
}
/* Make debconf display it. */
s = menutext + strlen(menutext);
for (p = head; p; p=p->next) {
/*
* Generate list of menu choices for debconf. Also figure out which
* is the default.
*/
s = menutext;
for (p = head; p; p = p->next) {
if (p->installer_menu_item) {
strcpy(s, p->description);
s += strlen(p->description);
*s++ = ',';
*s++ = ' ';
if (! menudefault) {
/* TODO: menutest scripts */
if (p->status == STATUS_UNPACKED) {
menudefault = p->description;
}
}
}
}
/* Trim trailing ", " */
s = s - 2;
*s = 0;
/*
* TODO: save some executable size by not hard coding the MAIN_MENU
* string everwhere
*/
debconf_command("FSET " MAIN_MENU " isdefault true");
debconf_command(menutext);
debconf_command("INPUT medium " MAIN_MENU);
s = menutext;
if (menudefault)
debconf_command("SET %s %s", MAIN_MENU, menudefault);
debconf_command("FSET %s isdefault true", MAIN_MENU);
debconf_command("SUBST %s MENU %s", MAIN_MENU, menutext);
debconf_command("INPUT medium %s", MAIN_MENU);
debconf_command("GO");
}

10
main-menu.h

@ -1,20 +1,26 @@
#define BUFSIZE 4096
#define STATUSFILE "./status"
#define DPKGDIR "./" // "/var/lib/dpkg/"
#define STATUSFILE DPKGDIR "status"
#define DEPENDSMAX 64 /* maximum number of depends we can handle */
#define MAIN_MENU "debian-installer/main-menu"
#define STATUS_UNKNOWN 0
#define STATUS_UNPACKED 1
#define STATUS_INSTALLED 2
/* data structures */
struct package_t {
char *package;
int installer_menu_item;
char *description; /* short only, and only for menu items */
char *depends[DEPENDSMAX];
int status;
int processed;
struct package_t *next;
};
struct package_t *status_read(void);
int package_compare (const void *, const void *);
int debconf_command (char *);
int debconf_command (const char *, ...);

11
status

@ -1,51 +1,62 @@
Package: install-media
Installer-Menu-Item: 1
Status: install ok installed
Depends: retriever
Description: Configure installation media
Package: http-retriever
Status: install ok installed
Depends: network
Provides: retriever
Package: floppy-retreiver
Status: install ok installed
Provides: retriever
Package: network-setup
Provides: network
Status: install ok installed
Installer-Menu-Item: 7
Description: Setup the network manually
Package: network-dhcp
Provides: network
Status: install ok installed
Installer-Menu-Item: 7
Description: Setup the network with DHCP
Package: partitions
Installer-Menu-Item: 3
Status: install ok installed
Depends: disk-driver
Description: Partition disk
Package: disk-driver
Package: format-partitions
Status: install ok installed
Installer-Menu-Item: 2
Depends: partitions, disk-driver
Description: Format and mount partitions
Package: install-base
Installer-Menu-Item: 2
Status: install ok installed
Depends: format-partitions, install-media
Description: Install base system
Package: install-lilo
Installer-Menu-Item: 1
Status: install ok unpacked
Depends: install-base
Description: Install lilo
Package: reboot
Installer-Menu-Item: 5
Status: install ok installed
Description: Reboot the system
Package: rescue-floppy
Installer-Menu-Item: 4
Status: install ok installed
Description: Make a rescue floppy

15
status.c

@ -34,8 +34,23 @@ struct package_t *status_read(void) {
else if (strstr(buf, "Installer-Menu-Item: ") == buf) {
p->installer_menu_item = atoi(buf+21);
}
else if (strstr(buf, "Status: ") == buf) {
if (strstr(buf, " unpacked")) {
p->status = STATUS_UNPACKED;
}
else if (strstr(buf, " installed")) {
p->status = STATUS_INSTALLED;
}
else {
p->status = STATUS_UNKNOWN;
}
}
else if (strstr(buf, "Description: ") == buf) {
/* Short description only. */
/*
* TODO: need to get translated data from
* somewhere, if in a different locale.
*/
p->description = strdup(buf+13);
}
else if (strstr(buf, "Depends: ") == buf) {

Loading…
Cancel
Save