Browse Source

Changes to allow user to use tasksel to install required and important

packages
tags/debian_version_1_0-8
Randolph Chung 22 years ago
parent
commit
13d481c40f
6 changed files with 159 additions and 72 deletions
  1. +1
    -1
      Makefile
  2. +29
    -14
      data.c
  3. +11
    -1
      data.h
  4. +17
    -0
      debian/changelog
  5. +1
    -1
      debian/rules
  6. +100
    -55
      tasksel.c

+ 1
- 1
Makefile View File

@@ -1,7 +1,7 @@
PROGRAM = tasksel
VERSION=\"1.0\"
CC = gcc
CFLAGS = -g -Wall -Os
CFLAGS = -g -Wall #-Os
DEFS = -DVERSION=$(VERSION) -DPACKAGE=\"$(PROGRAM)\" -DLOCALEDIR=\"/usr/share/locale\" #-DDEBUG
LIBS = -lslang #-lccmalloc -ldl
OBJS = tasksel.o slangui.o data.o util.o strutl.o


+ 29
- 14
data.c View File

@@ -1,4 +1,4 @@
/* $Id: data.c,v 1.7 2000/01/16 02:55:30 tausq Exp $ */
/* $Id: data.c,v 1.8 2000/02/06 22:12:32 tausq Exp $ */
/* data.c - encapsulates functions for reading a package listing like dpkg's available file
* Internally, packages are stored in a binary tree format to faciliate search operations
*/
@@ -19,6 +19,7 @@
#define RECOMMENDSFIELD "Recommends: "
#define SUGGESTSFIELD "Suggests: "
#define DESCRIPTIONFIELD "Description: "
#define PRIORITYFIELD "Priority: "
#define STATUSFIELD "Status: "
#define AVAILABLEFILE "/var/lib/dpkg/available"
#define STATUSFILE "/var/lib/dpkg/status"
@@ -118,9 +119,10 @@ static const char *filterdescription(const char *descin)
}

static void addpackage(struct packages_t *pkgs,
const char *name, const char *dependsdesc, const char *recommendsdesc,
const char *suggestsdesc, const char *shortdesc, const char *longdesc,
const int istask)
const char *name, const char *dependsdesc,
const char *recommendsdesc, const char *suggestsdesc,
const char *shortdesc, const char *longdesc,
const priority_t priority, const int istask)
{
/* Adds package to the package list binary tree */
struct package_t *node = NEW(struct package_t);
@@ -155,6 +157,7 @@ static void addpackage(struct packages_t *pkgs,
node->shortdesc = STRDUP(shortdesc);
node->longdesc = STRDUP(longdesc);
node->priority = priority;

if (dependsdesc) node->dependscount = splitlinkdesc(dependsdesc, &node->depends);
if (recommendsdesc) node->recommendscount = splitlinkdesc(recommendsdesc, &node->recommends);
@@ -168,8 +171,8 @@ static void addpackage(struct packages_t *pkgs,
/* public functions */
struct package_t *packages_find(const struct packages_t *pkgs, const char *name)
{
/* Given a package name, returns a pointer to the appropriate package_t structure
* or NULL if none is found */
/* Given a package name, returns a pointer to the appropriate package_t
* structure or NULL if none is found */
struct package_t pkg;
void *result;
@@ -187,10 +190,6 @@ struct package_t **packages_enumerate(const struct packages_t *packages)
/* Converts the packages binary tree into a array. Do not modify the returned array! It
* is a static variable managed by this module */
if (_packages_enumbuf != NULL) {
FREE(_packages_enumbuf);
}
_packages_enumbuf = MALLOC(sizeof(struct package_t *) * packages->count);
if (_packages_enumbuf == NULL)
DIE("Cannot allocate memory for enumeration buffer");
@@ -203,11 +202,13 @@ struct package_t **packages_enumerate(const struct packages_t *packages)

void packages_readlist(struct packages_t *taskpkgs, struct packages_t *pkgs)
{
/* Populates internal data structures with information for an available file */
/* Populates internal data structures with information from an available
* file */
FILE *f;
char buf[BUF_SIZE];
char *name, *shortdesc, *longdesc;
char *dependsdesc, *recommendsdesc, *suggestsdesc;
char *dependsdesc, *recommendsdesc, *suggestsdesc, *prioritydesc;
priority_t priority;
VERIFY(taskpkgs != NULL); VERIFY(pkgs != NULL);
@@ -222,6 +223,7 @@ void packages_readlist(struct packages_t *taskpkgs, struct packages_t *pkgs)
if (MATCHFIELD(buf, PACKAGEFIELD)) {
/*DPRINTF("Package = %s\n", FIELDDATA(buf, PACKAGEFIELD)); */
name = shortdesc = longdesc = dependsdesc = recommendsdesc = suggestsdesc = NULL;
priority = PRIORITY_UNKNOWN;
name = STRDUP(FIELDDATA(buf, PACKAGEFIELD));
VERIFY(name != NULL);
@@ -241,6 +243,19 @@ void packages_readlist(struct packages_t *taskpkgs, struct packages_t *pkgs)
} else if (MATCHFIELD(buf, SUGGESTSFIELD)) {
suggestsdesc = STRDUP(FIELDDATA(buf, SUGGESTSFIELD));
VERIFY(suggestsdesc != NULL);
} else if (MATCHFIELD(buf, PRIORITYFIELD)) {
prioritydesc = FIELDDATA(buf, PRIORITYFIELD);
if (strcmp(prioritydesc, "required") == 0) {
priority = PRIORITY_REQUIRED;
} else if (strcmp(prioritydesc, "important") == 0) {
priority = PRIORITY_IMPORTANT;
} else if (strcmp(prioritydesc, "standard") == 0) {
priority = PRIORITY_STANDARD;
} else if (strcmp(prioritydesc, "optional") == 0) {
priority = PRIORITY_OPTIONAL;
} else if (strcmp(prioritydesc, "extra") == 0) {
priority = PRIORITY_EXTRA;
}
} else if (MATCHFIELD(buf, DESCRIPTIONFIELD)) {
shortdesc = STRDUP(FIELDDATA(buf, DESCRIPTIONFIELD));
VERIFY(shortdesc != NULL);
@@ -261,10 +276,10 @@ void packages_readlist(struct packages_t *taskpkgs, struct packages_t *pkgs)
}

addpackage(pkgs, name, NULL, NULL, NULL, shortdesc,
NULL, 0);
NULL, priority, 0);
if (strncmp(name, "task-", 5) == 0)
addpackage(taskpkgs, name, dependsdesc, recommendsdesc, suggestsdesc,
filterdescription(shortdesc), longdesc, 1);
filterdescription(shortdesc), longdesc, priority, 1);
if (name != NULL) FREE(name);
if (dependsdesc != NULL) FREE(dependsdesc);


+ 11
- 1
data.h View File

@@ -1,7 +1,16 @@
/* $Id: data.h,v 1.3 2000/01/07 22:45:09 joeyh Exp $ */
/* $Id: data.h,v 1.4 2000/02/06 22:12:32 tausq Exp $ */
#ifndef _DATA_H
#define _DATA_H

typedef enum {
PRIORITY_UNKNOWN = 0,
PRIORITY_REQUIRED,
PRIORITY_IMPORTANT,
PRIORITY_STANDARD,
PRIORITY_OPTIONAL,
PRIORITY_EXTRA
} priority_t;

struct package_t {
char *name;
char *prettyname;
@@ -13,6 +22,7 @@ struct package_t {
char **recommends;
int suggestscount;
char **suggests;
priority_t priority;
int selected;
};



+ 17
- 0
debian/changelog View File

@@ -1,3 +1,20 @@
tasksel (1.0-7) frozen unstable; urgency=low

* Adds -r, -i switches for installing required and important packages
* Adds -n option for non-interactive runs (for use with -r or -i)
* Make data.c read priority settings; made packages_enumerate
reentrant

-- Randolph Chung <tausq@debian.org> Sun, 6 Feb 2000 15:08:43 -0700

tasksel (1.0-6) frozen unstable; urgency=low

* Fixed some really stupid bugs
* removed cvs build target from debian/rules (closes: #55621) [RC]
* fixed -q option to properly queue package installs

-- Randolph Chung <tausq@debian.org> Wed, 19 Jan 2000 21:19:11 -0700

tasksel (1.0-5) frozen unstable; urgency=low

* Adds option to queue installs instead of running them immediately (-q)


+ 1
- 1
debian/rules View File

@@ -16,7 +16,7 @@ commit-stamp:
cvs commit
touch commit-stamp

build: commit build-stamp
build: build-stamp
build-stamp:
dh_testdir



+ 100
- 55
tasksel.c View File

@@ -1,4 +1,4 @@
/* $Id: tasksel.c,v 1.4 2000/01/16 07:33:08 tausq Exp $ */
/* $Id: tasksel.c,v 1.5 2000/02/06 22:12:32 tausq Exp $ */
#include "tasksel.h"

#include <stdio.h>
@@ -29,17 +29,85 @@ void help(void)
{
fprintf(stderr, "tasksel [-t]\n");
fprintf(stderr, "\t%s\n", _("-t -- test mode; don't actually run apt-get on exit"));
fprintf(stderr, "\t%s\n\n", _("-q -- queue installs; do not install packages with apt-get;\n\t\tjust queue them in dpkg"));
fprintf(stderr, "\t%s\n", _("-q -- queue installs; do not install packages with apt-get;\n\t\tjust queue them in dpkg"));
fprintf(stderr, "\t%s\n", _("-r -- install all required-priority packages"));
fprintf(stderr, "\t%s\n", _("-i -- install all important-priority packages"));
fprintf(stderr, "\t%s\n\n", _("-n -- don't show UI; use with -r or -i usually"));
exit(0);
}

int doinstall(struct package_t **taskpkglist, int taskpkgcount,
struct package_t **pkglist, int pkgcount,
unsigned char queueinstalls, unsigned char testmode)
{
int i, c = 0;
FILE *todpkg;
char buf[8192];

if (queueinstalls) {
if (testmode)
todpkg = stdout;
else
todpkg = popen("dpkg --set-selections", "w");
if (!todpkg) PERROR("Cannot send output to dpkg");
for (i = 0; i < pkgcount; i++) {
if (pkglist[i]->selected > 0) {
fprintf(todpkg, "%s install\n", pkglist[i]->name);
c++;
}
}
for (i = 0; i < taskpkgcount; i++) {
if (taskpkglist[i]->selected > 0) {
fprintf(todpkg, "%s install\n", taskpkglist[i]->name);
c++;
}
}
if (!testmode) pclose(todpkg);

if (c == 0) {
fprintf(stderr, "No packages selected\n");
return 1;
}
} else {
sprintf(buf, "apt-get install ");
for (i = 0; i < pkgcount; i++) {
if (pkglist[i]->selected > 0) {
/* TODO check buffer overflow; not likely, but still... */
strcat(buf, pkglist[i]->name);
strcat(buf, " ");
c++;
}
}
for (i = 0; i < taskpkgcount; i++) {
if (taskpkglist[i]->selected > 0) {
/* TODO check buffer overflow; not likely, but still... */
strcat(buf, taskpkglist[i]->name);
strcat(buf, " ");
c++;
}
}

if (c > 0) {
if (testmode == 1)
printf("%s\n", buf);
else
system(buf);
} else {
fprintf(stderr, "No packages selected\n");
return 1;
}
}
return 0;
}

int main(int argc, char * const argv[])
{
int i, c, r, testmode = 0, queueinstalls = 0;
int i, c, r = 0;
unsigned char testmode = 0, queueinstalls = 0, installreqd = 0;
unsigned char installimp = 0, noninteractive = 0;
struct packages_t taskpkgs, packages;
struct package_t **pkglist;
char buf[2048];
FILE *todpkg;
struct package_t **pkglist, **taskpkglist;
signal(SIGWINCH, signalhandler);
@@ -48,12 +116,15 @@ int main(int argc, char * const argv[])
textdomain(PACKAGE);
while (1) {
c = getopt(argc, argv, "tq");
c = getopt(argc, argv, "tqrin");
if (c == -1) break;

switch (c) {
case 't': testmode = 1; break;
case 'q': queueinstalls = 1; break;
case 'r': installreqd = 1; break;
case 'i': installimp = 1; break;
case 'n': noninteractive = 1; break;
default: help();
}
}
@@ -65,57 +136,31 @@ int main(int argc, char * const argv[])
return 255;
}
ui_init(argc, argv, &taskpkgs, &packages);
ui_drawscreen();
r = ui_eventloop();
ui_shutdown();

pkglist = packages_enumerate(&taskpkgs);

c = 0;
if (r == 0) {
if (queueinstalls) {
if (testmode)
todpkg = stdout;
else
todpkg = popen("dpkg", "w");
if (!todpkg) PERROR("Cannot send output to dpkg");
for (i = 0; i < taskpkgs.count; i++) {
if (pkglist[i]->selected > 0) {
fprintf(todpkg, "%s install\n", pkglist[i]->name);
c++;
}
}
if (!testmode) pclose(todpkg);

if (c == 0) {
fprintf(stderr, "No packages selected\n");
r = 1;
}
} else {
sprintf(buf, "apt-get install ");
for (i = 0; i < taskpkgs.count; i++) {
if (pkglist[i]->selected > 0) {
/* TODO check buffer overflow; not likely, but still... */
strcat(buf, pkglist[i]->name);
strcat(buf, " ");
c++;
}
}
if (noninteractive == 0) {
ui_init(argc, argv, &taskpkgs, &packages);
ui_drawscreen();
r = ui_eventloop();
ui_shutdown();
}
taskpkglist = packages_enumerate(&taskpkgs);
pkglist = packages_enumerate(&packages);

if (c > 0) {
if (testmode == 1)
printf("%s\n", buf);
else
system(buf);
} else {
fprintf(stderr, "No packages selected\n");
r = 1;
}
if (installreqd || installimp) {
for (i = 0; i < packages.count; i++) {
if (installreqd && pkglist[i]->priority == PRIORITY_REQUIRED)
pkglist[i]->selected = 1;
if (installimp && pkglist[i]->priority == PRIORITY_IMPORTANT)
pkglist[i]->selected = 1;
}
}

if (r == 0) r = doinstall(taskpkglist, taskpkgs.count,
pkglist,
(installreqd || installimp ? packages.count
: 0),
queueinstalls, testmode);

packages_free(&taskpkgs, &packages);
return r;


Loading…
Cancel
Save