2001-04-08 10:57:18 +05:30
|
|
|
#include <dirent.h>
|
|
|
|
#include <getopt.h>
|
2001-02-10 07:35:24 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <search.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <utime.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-02-10 19:56:48 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
#include "busybox.h"
|
|
|
|
|
2001-03-14 07:01:11 +05:30
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
#define DEPENDSMAX 64 /* maximum number of depends we can handle */
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
/* Should we do full dependency checking? */
|
2001-04-16 15:56:46 +05:30
|
|
|
//#define DODEPENDS 0
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
/* Should we do debugging? */
|
2001-04-16 15:56:46 +05:30
|
|
|
//#define DODEBUG 0
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
#ifdef DODEBUG
|
|
|
|
#define SYSTEM(x) do_system(x)
|
|
|
|
#define DPRINTF(fmt,args...) fprintf(stderr, fmt, ##args)
|
|
|
|
#else
|
|
|
|
#define SYSTEM(x) system(x)
|
|
|
|
#define DPRINTF(fmt,args...) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
/* from dpkg-deb.c */
|
2001-04-11 07:42:08 +05:30
|
|
|
|
2001-02-11 07:10:23 +05:30
|
|
|
static const char statusfile[] = "/var/lib/dpkg/status.udeb";
|
|
|
|
static const char new_statusfile[] = "/var/lib/dpkg/status.udeb.new";
|
|
|
|
static const char bak_statusfile[] = "/var/lib/dpkg/status.udeb.bak";
|
|
|
|
|
2001-02-10 20:23:08 +05:30
|
|
|
static const char infodir[] = "/var/lib/dpkg/info/";
|
|
|
|
static const char udpkg_quiet[] = "UDPKG_QUIET";
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-04-08 18:57:39 +05:30
|
|
|
//static const int status_want_unknown = 1;
|
2001-04-16 10:22:19 +05:30
|
|
|
static const int state_want_install = 2;
|
|
|
|
//static const int state_want_hold = 3;
|
|
|
|
//static const int state_want_deinstall = 4;
|
|
|
|
//static const int state_want_purge = 5;
|
|
|
|
|
|
|
|
static const int state_flag_ok = 1;
|
|
|
|
//static const int state_flag_reinstreq = 2;
|
|
|
|
//static const int state_flag_hold = 3;
|
|
|
|
//static const int state_flag_holdreinstreq = 4;
|
|
|
|
|
|
|
|
//static const int state_statusnoninstalled = 1;
|
|
|
|
static const int state_status_unpacked = 2;
|
|
|
|
static const int state_status_halfconfigured = 3;
|
|
|
|
static const int state_status_installed = 4;
|
|
|
|
static const int state_status_halfinstalled = 5;
|
|
|
|
//static const int state_statusconfigfiles = 6;
|
|
|
|
//static const int state_statuspostinstfailed = 7;
|
|
|
|
//static const int state_statusremovalfailed = 8;
|
|
|
|
|
|
|
|
static const char *state_words_want[] = { "unknown", "install", "hold", "deinstall", "purge", 0 };
|
|
|
|
static const char *state_words_flag[] = { "ok", "reinstreq", "hold", "hold-reinstreq", 0 };
|
|
|
|
static const char *state_words_status[] = { "not-installed", "unpacked", "half-configured", "installed",
|
2001-04-08 18:57:39 +05:30
|
|
|
"half-installed", "config-files", "post-inst-failed", "removal-failed", 0 };
|
2001-02-10 08:49:51 +05:30
|
|
|
|
2001-03-10 02:54:12 +05:30
|
|
|
static const int color_white = 0;
|
|
|
|
static const int color_grey = 1;
|
|
|
|
static const int color_black = 2;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
/* data structures */
|
2001-02-10 19:56:48 +05:30
|
|
|
typedef struct package_s {
|
2001-04-16 10:22:19 +05:30
|
|
|
char *filename;
|
2001-02-10 07:35:24 +05:30
|
|
|
char *package;
|
2001-04-16 10:22:19 +05:30
|
|
|
unsigned char state_want;
|
|
|
|
unsigned char state_flag;
|
|
|
|
unsigned char state_status;
|
2001-02-10 07:35:24 +05:30
|
|
|
char *depends;
|
|
|
|
char *provides;
|
|
|
|
char *description;
|
2001-04-16 10:22:19 +05:30
|
|
|
char *priority;
|
|
|
|
char *section;
|
|
|
|
char *installed_size;
|
|
|
|
char *maintainer;
|
|
|
|
char *source;
|
|
|
|
char *version;
|
|
|
|
char *pre_depends;
|
|
|
|
char *replaces;
|
|
|
|
char *recommends;
|
|
|
|
char *suggests;
|
|
|
|
char *conflicts;
|
|
|
|
char *conffiles;
|
|
|
|
char *long_description;
|
|
|
|
char *architecture;
|
|
|
|
char *md5sum;
|
2001-02-10 07:35:24 +05:30
|
|
|
int installer_menu_item;
|
|
|
|
char color; /* for topo-sort */
|
2001-02-10 19:56:48 +05:30
|
|
|
struct package_s *requiredfor[DEPENDSMAX];
|
2001-02-10 07:35:24 +05:30
|
|
|
unsigned short requiredcount;
|
2001-02-10 19:56:48 +05:30
|
|
|
struct package_s *next;
|
|
|
|
} package_t;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-11 07:10:23 +05:30
|
|
|
#ifdef DODEBUG
|
|
|
|
static int do_system(const char *cmd)
|
|
|
|
{
|
|
|
|
DPRINTF("cmd is %s\n", cmd);
|
|
|
|
return system(cmd);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define do_system(cmd) system(cmd)
|
|
|
|
#endif
|
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
static int package_compare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
return strcmp(((package_t *)p1)->package,
|
|
|
|
((package_t *)p2)->package);
|
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
#ifdef DODEPENDS
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
static char **depends_split(const char *dependsstr)
|
|
|
|
{
|
|
|
|
static char *dependsvec[DEPENDSMAX];
|
|
|
|
char *p;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
dependsvec[0] = 0;
|
2001-02-11 07:10:23 +05:30
|
|
|
if (dependsstr == 0) {
|
|
|
|
goto end;
|
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
p = xstrdup(dependsstr);
|
2001-02-11 07:10:23 +05:30
|
|
|
while (*p != 0 && *p != '\n') {
|
|
|
|
if (*p != ' ') {
|
|
|
|
if (*p == ',') {
|
|
|
|
*p = 0;
|
|
|
|
dependsvec[++i] = 0;
|
2001-02-11 05:47:22 +05:30
|
|
|
} else {
|
2001-02-11 07:10:23 +05:30
|
|
|
if (dependsvec[i] == 0) {
|
|
|
|
dependsvec[i] = p;
|
|
|
|
}
|
2001-02-11 05:47:22 +05:30
|
|
|
}
|
2001-02-11 07:10:23 +05:30
|
|
|
} else {
|
|
|
|
*p = 0; /* eat the space... */
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-02-11 07:10:23 +05:30
|
|
|
p++;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-02-11 07:10:23 +05:30
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
end:
|
2001-02-10 07:35:24 +05:30
|
|
|
dependsvec[i+1] = 0;
|
|
|
|
return dependsvec;
|
|
|
|
}
|
|
|
|
|
2001-02-11 07:10:23 +05:30
|
|
|
/* Topological sort algorithm:
|
|
|
|
* ordered is the output list, pkgs is the dependency graph, pkg is
|
|
|
|
* the current node
|
|
|
|
*
|
|
|
|
* recursively add all the adjacent nodes to the ordered list, marking
|
|
|
|
* each one as visited along the way
|
|
|
|
*
|
|
|
|
* yes, this algorithm looks a bit odd when all the params have the
|
|
|
|
* same type :-)
|
|
|
|
*/
|
2001-02-10 19:56:48 +05:30
|
|
|
static void depends_sort_visit(package_t **ordered, package_t *pkgs,
|
|
|
|
package_t *pkg)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
|
|
|
unsigned short i;
|
|
|
|
|
|
|
|
/* mark node as processing */
|
2001-02-10 08:49:51 +05:30
|
|
|
pkg->color = color_grey;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
/* visit each not-yet-visited node */
|
|
|
|
for (i = 0; i < pkg->requiredcount; i++)
|
2001-02-10 08:49:51 +05:30
|
|
|
if (pkg->requiredfor[i]->color == color_white)
|
2001-02-10 07:35:24 +05:30
|
|
|
depends_sort_visit(ordered, pkgs, pkg->requiredfor[i]);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* add it to the list */
|
2001-02-16 01:20:11 +05:30
|
|
|
newnode = (struct package_t *)xmalloc(sizeof(struct package_t));
|
2001-02-10 07:35:24 +05:30
|
|
|
/* make a shallow copy */
|
|
|
|
*newnode = *pkg;
|
|
|
|
newnode->next = *ordered;
|
|
|
|
*ordered = newnode;
|
|
|
|
#endif
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
pkg->next = *ordered;
|
|
|
|
*ordered = pkg;
|
|
|
|
|
|
|
|
/* mark node as done */
|
2001-02-10 08:49:51 +05:30
|
|
|
pkg->color = color_black;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
static package_t *depends_sort(package_t *pkgs)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
|
|
|
/* TODO: it needs to break cycles in the to-be-installed package
|
|
|
|
* graph... */
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *ordered = NULL;
|
|
|
|
package_t *pkg;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-11 07:10:23 +05:30
|
|
|
for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
|
2001-02-10 08:49:51 +05:30
|
|
|
pkg->color = color_white;
|
2001-02-11 07:10:23 +05:30
|
|
|
}
|
|
|
|
for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
|
|
|
|
if (pkg->color == color_white) {
|
2001-02-10 07:35:24 +05:30
|
|
|
depends_sort_visit(&ordered, pkgs, pkg);
|
2001-02-11 07:10:23 +05:30
|
|
|
}
|
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
/* Leaks the old list... return the new one... */
|
|
|
|
return ordered;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* resolve package dependencies --
|
|
|
|
* for each package in the list of packages to be installed, we parse its
|
|
|
|
* dependency info to determine if the dependent packages are either
|
|
|
|
* already installed, or are scheduled to be installed. If both tests fail
|
|
|
|
* than bail.
|
|
|
|
*
|
|
|
|
* The algorithm here is O(n^2*m) where n = number of packages to be
|
|
|
|
* installed and m is the # of dependencies per package. Not a terribly
|
|
|
|
* efficient algorithm, but given that at any one time you are unlikely
|
|
|
|
* to install a very large number of packages it doesn't really matter
|
|
|
|
*/
|
2001-02-10 19:56:48 +05:30
|
|
|
static package_t *depends_resolve(package_t *pkgs, void *status)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *pkg, *chk;
|
|
|
|
package_t dependpkg;
|
2001-02-10 07:35:24 +05:30
|
|
|
char **dependsvec;
|
|
|
|
int i;
|
|
|
|
void *found;
|
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
|
2001-02-10 07:35:24 +05:30
|
|
|
dependsvec = depends_split(pkg->depends);
|
|
|
|
i = 0;
|
2001-02-11 05:47:22 +05:30
|
|
|
while (dependsvec[i] != 0) {
|
2001-02-10 07:35:24 +05:30
|
|
|
/* Check for dependencies; first look for installed packages */
|
|
|
|
dependpkg.package = dependsvec[i];
|
2001-04-08 18:57:39 +05:30
|
|
|
if (((found = tfind(&dependpkg, &status, package_compare)) == 0) ||
|
2001-04-16 10:22:19 +05:30
|
|
|
((chk = *(package_t **)found) && (chk->state_flag & state_flag_ok) &&
|
|
|
|
(chk->state_status & state_status_installed))) {
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
/* if it fails, we look through the list of packages we are going to
|
|
|
|
* install */
|
2001-02-11 05:47:22 +05:30
|
|
|
for (chk = pkgs; chk != 0; chk = chk->next) {
|
2001-02-11 07:10:23 +05:30
|
|
|
if (strcmp(chk->package, dependsvec[i]) == 0 || (chk->provides &&
|
2001-02-11 05:47:22 +05:30
|
|
|
strncmp(chk->provides, dependsvec[i], strlen(dependsvec[i])) == 0)) {
|
|
|
|
if (chk->requiredcount >= DEPENDSMAX) {
|
2001-04-10 04:18:12 +05:30
|
|
|
error_msg("Too many dependencies for %s", chk->package);
|
2001-02-10 07:35:24 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2001-02-11 05:47:22 +05:30
|
|
|
if (chk != pkg) {
|
2001-02-10 07:35:24 +05:30
|
|
|
chk->requiredfor[chk->requiredcount++] = pkg;
|
2001-02-11 05:47:22 +05:30
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-02-11 05:47:22 +05:30
|
|
|
if (chk == 0) {
|
2001-04-10 04:18:12 +05:30
|
|
|
error_msg("%s depends on %s, but it is not going to be installed", pkg->package, dependsvec[i]);
|
2001-02-10 07:35:24 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return depends_sort(pkgs);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Status file handling routines
|
|
|
|
*
|
|
|
|
* This is a fairly minimalistic implementation. there are two main functions
|
|
|
|
* that are supported:
|
|
|
|
*
|
|
|
|
* 1) reading the entire status file:
|
|
|
|
* the status file is read into memory as a binary-tree, with just the
|
|
|
|
* package and status info preserved
|
|
|
|
*
|
|
|
|
* 2) merging the status file
|
|
|
|
* control info from (new) packages is merged into the status file,
|
|
|
|
* replacing any pre-existing entries. when a merge happens, status info
|
|
|
|
* read using the status_read function is written back to the status file
|
|
|
|
*/
|
2001-04-08 18:57:39 +05:30
|
|
|
static unsigned char status_parse(const char *line, const char **status_words)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-04-08 18:57:39 +05:30
|
|
|
unsigned char status_num;
|
|
|
|
int i = 0;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-04-08 18:57:39 +05:30
|
|
|
while (status_words[i] != 0) {
|
|
|
|
if (strncmp(line, status_words[i], strlen(status_words[i])) == 0) {
|
|
|
|
status_num = (char)i;
|
|
|
|
return(status_num);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-04-08 18:57:39 +05:30
|
|
|
i++;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-04-08 18:57:39 +05:30
|
|
|
/* parse error */
|
|
|
|
error_msg("Invalid status word");
|
|
|
|
return(0);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-04-16 10:22:19 +05:30
|
|
|
* Read the buffered control file and parse it,
|
2001-02-10 07:35:24 +05:30
|
|
|
* filling parsed fields into the package structure
|
|
|
|
*/
|
2001-04-16 10:22:19 +05:30
|
|
|
static int fill_package_struct(package_t *package, const char *package_buffer)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-04-16 10:22:19 +05:30
|
|
|
char *field = NULL;
|
|
|
|
int field_start = 0;
|
|
|
|
int field_length = 0;
|
2001-04-16 15:56:46 +05:30
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
while ((field = read_package_field(&package_buffer[field_start])) != NULL) {
|
|
|
|
field_length = strlen(field);
|
|
|
|
field_start += (field_length + 1);
|
|
|
|
|
|
|
|
if (strlen(field) == 0) {
|
|
|
|
printf("empty line: *this shouldnt happen i dont think*\n");
|
2001-02-11 05:47:22 +05:30
|
|
|
break;
|
2001-04-08 18:57:39 +05:30
|
|
|
}
|
2001-04-16 10:22:19 +05:30
|
|
|
|
|
|
|
/* these are common to both installed and uninstalled packages */
|
|
|
|
if (strstr(field, "Package: ") == field) {
|
|
|
|
package->package = strdup(field + 9);
|
2001-04-08 18:57:39 +05:30
|
|
|
}
|
2001-04-16 10:22:19 +05:30
|
|
|
else if (strstr(field, "Depends: ") == field) {
|
|
|
|
package->depends = strdup(field + 9);
|
2001-04-08 18:57:39 +05:30
|
|
|
}
|
2001-04-16 10:22:19 +05:30
|
|
|
else if (strstr(field, "Provides: ") == field) {
|
|
|
|
package->provides = strdup(field + 10);
|
2001-04-08 18:57:39 +05:30
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
/* This is specific to the Debian Installer. Ifdef? */
|
2001-04-16 10:22:19 +05:30
|
|
|
else if (strstr(field, "installer-menu-item: ") == field) {
|
|
|
|
package->installer_menu_item = atoi(field + 21);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "Description: ") == field) {
|
|
|
|
package->description = strdup(field + 13);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "Priority: ") == field) {
|
|
|
|
package->priority = strdup(field + 10);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "Section: ") == field) {
|
|
|
|
package->section = strdup(field + 9);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "Installed-Size: ") == field) {
|
|
|
|
package->installed_size = strdup(field + 16);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "Maintainer: ") == field) {
|
|
|
|
package->maintainer = strdup(field + 12);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "Version: ") == field) {
|
|
|
|
package->version = strdup(field + 9);
|
2001-04-08 18:57:39 +05:30
|
|
|
}
|
2001-04-16 10:22:19 +05:30
|
|
|
else if (strstr(field, "Suggests: ") == field) {
|
|
|
|
package->suggests = strdup(field + 10);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-04-16 10:22:19 +05:30
|
|
|
else if (strstr(field, "Recommends: ") == field) {
|
|
|
|
package->recommends = strdup(field + 12);
|
|
|
|
}
|
|
|
|
/* else if (strstr(field, "Conffiles: ") == field) {
|
|
|
|
package->conffiles = read_block(file);
|
|
|
|
package->conffiles = xcalloc(1, 1);
|
|
|
|
while ((field = strtok(NULL, "\n")) != NULL) {
|
|
|
|
package->long_description = xrealloc(package->conffiles,
|
|
|
|
strlen(package->conffiles) + strlen(field) + 1);
|
|
|
|
strcat(package->conffiles, field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/* These are only in available file */
|
|
|
|
else if (strstr(field, "Architecture: ") == field) {
|
|
|
|
package->architecture = strdup(field + 14);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "Filename: ") == field) {
|
|
|
|
package->filename = strdup(field + 10);
|
|
|
|
}
|
|
|
|
else if (strstr(field, "MD5sum ") == field) {
|
|
|
|
package->md5sum = strdup(field + 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is only needed for status file */
|
|
|
|
if (strstr(field, "Status: ") == field) {
|
|
|
|
char *word_pointer;
|
|
|
|
|
|
|
|
word_pointer = strchr(field, ' ') + 1;
|
|
|
|
package->state_want = status_parse(word_pointer, state_words_want);
|
|
|
|
word_pointer = strchr(word_pointer, ' ') + 1;
|
|
|
|
package->state_flag = status_parse(word_pointer, state_words_flag);
|
|
|
|
word_pointer = strchr(word_pointer, ' ') + 1;
|
|
|
|
package->state_status = status_parse(word_pointer, state_words_status);
|
|
|
|
} else {
|
|
|
|
package->state_want = status_parse("purge", state_words_want);
|
|
|
|
package->state_flag = status_parse("ok", state_words_flag);
|
|
|
|
package->state_status = status_parse("not-installed", state_words_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(field);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-02-12 17:03:09 +05:30
|
|
|
return EXIT_SUCCESS;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
|
2001-04-16 15:56:46 +05:30
|
|
|
extern void write_package(FILE *out_file, package_t *pkg)
|
|
|
|
{
|
|
|
|
if (pkg->package) {
|
|
|
|
fprintf(out_file, "Package: %s\n", pkg->package);
|
|
|
|
}
|
|
|
|
if ((pkg->state_want != 0) || (pkg->state_flag != 0)|| (pkg->state_status != 0)) {
|
|
|
|
fprintf(out_file, "Status: %s %s %s\n",
|
|
|
|
state_words_want[pkg->state_want - 1],
|
|
|
|
state_words_flag[pkg->state_flag - 1],
|
|
|
|
state_words_status[pkg->state_status - 1]);
|
|
|
|
}
|
|
|
|
if (pkg->depends) {
|
|
|
|
fprintf(out_file, "Depends: %s\n", pkg->depends);
|
|
|
|
}
|
|
|
|
if (pkg->provides) {
|
|
|
|
fprintf(out_file, "Provides: %s\n", pkg->provides);
|
|
|
|
}
|
|
|
|
if (pkg->priority) {
|
|
|
|
fprintf(out_file, "Priority: %s\n", pkg->priority);
|
|
|
|
}
|
|
|
|
if (pkg->section) {
|
|
|
|
fprintf(out_file, "Section: %s\n", pkg->section);
|
|
|
|
}
|
|
|
|
if (pkg->section) {
|
|
|
|
fprintf(out_file, "Installed-Size: %s\n", pkg->installed_size);
|
|
|
|
}
|
|
|
|
if (pkg->maintainer) {
|
|
|
|
fprintf(out_file, "Maintainer: %s\n", pkg->maintainer);
|
|
|
|
}
|
|
|
|
if (pkg->source) {
|
|
|
|
fprintf(out_file, "Source: %s\n", pkg->source);
|
|
|
|
}
|
|
|
|
if (pkg->version) {
|
|
|
|
fprintf(out_file, "Version: %s\n", pkg->version);
|
|
|
|
}
|
|
|
|
if (pkg->pre_depends) {
|
|
|
|
fprintf(out_file, "Pre-depends: %s\n", pkg->pre_depends);
|
|
|
|
}
|
|
|
|
if (pkg->replaces) {
|
|
|
|
fprintf(out_file, "Replaces: %s\n", pkg->replaces);
|
|
|
|
}
|
|
|
|
if (pkg->recommends) {
|
|
|
|
fprintf(out_file, "Recommends: %s\n", pkg->recommends);
|
|
|
|
}
|
|
|
|
if (pkg->suggests) {
|
|
|
|
fprintf(out_file, "Suggests: %s\n", pkg->suggests);
|
|
|
|
}
|
|
|
|
if (pkg->conflicts) {
|
|
|
|
fprintf(out_file, "Conflicts: %s\n", pkg->conflicts);
|
|
|
|
}
|
|
|
|
if (pkg->conffiles) {
|
|
|
|
fprintf(out_file, "Conf-files: %s\n", pkg->conffiles);
|
|
|
|
}
|
|
|
|
if (pkg->architecture) {
|
|
|
|
fprintf(out_file, "Architecture: %s\n", pkg->architecture);
|
|
|
|
}
|
|
|
|
if (pkg->filename) {
|
|
|
|
fprintf(out_file, "Filename: %s\n", pkg->filename);
|
|
|
|
}
|
|
|
|
if (pkg->md5sum) {
|
|
|
|
fprintf(out_file, "MD5sum: %s\n", pkg->md5sum);
|
|
|
|
}
|
|
|
|
if (pkg->installer_menu_item) {
|
|
|
|
fprintf(out_file, "installer-main-menu %d\n", pkg->installer_menu_item);
|
|
|
|
}
|
|
|
|
if (pkg->description) {
|
|
|
|
fprintf(out_file, "Description: %s\n", pkg->description);
|
|
|
|
}
|
|
|
|
fputc('\n', out_file);
|
|
|
|
pkg = pkg->next;
|
|
|
|
}
|
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
static void *status_read(void)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
void *status = 0;
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *m = 0, *p = 0, *t = 0;
|
2001-04-16 10:22:19 +05:30
|
|
|
char *package_control_buffer = NULL;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
if (getenv(udpkg_quiet) == NULL) {
|
2001-02-10 07:35:24 +05:30
|
|
|
printf("(Reading database...)\n");
|
2001-02-11 05:47:22 +05:30
|
|
|
}
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-04-10 04:18:12 +05:30
|
|
|
if ((f = wfopen(statusfile, "r")) == NULL) {
|
2001-04-08 18:57:39 +05:30
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
while ( (package_control_buffer = read_text_file_to_buffer(f)) != NULL) {
|
2001-04-08 10:57:18 +05:30
|
|
|
m = (package_t *)xcalloc(1, sizeof(package_t));
|
2001-04-16 10:22:19 +05:30
|
|
|
fill_package_struct(m, package_control_buffer);
|
2001-02-11 05:47:22 +05:30
|
|
|
if (m->package) {
|
2001-02-10 07:35:24 +05:30
|
|
|
/*
|
|
|
|
* If there is an item in the tree by this name,
|
|
|
|
* it must be a virtual package; insert real
|
|
|
|
* package in preference.
|
|
|
|
*/
|
|
|
|
tdelete(m, &status, package_compare);
|
|
|
|
tsearch(m, &status, package_compare);
|
2001-02-11 05:47:22 +05:30
|
|
|
if (m->provides) {
|
2001-02-10 07:35:24 +05:30
|
|
|
/*
|
|
|
|
* A "Provides" triggers the insertion
|
|
|
|
* of a pseudo package into the status
|
|
|
|
* binary-tree.
|
|
|
|
*/
|
2001-04-08 10:57:18 +05:30
|
|
|
p = (package_t *)xcalloc(1, sizeof(package_t));
|
|
|
|
p->package = xstrdup(m->provides);
|
2001-02-10 19:56:48 +05:30
|
|
|
t = *(package_t **)tsearch(p, &status, package_compare);
|
2001-02-11 07:10:23 +05:30
|
|
|
if (t != p) {
|
2001-02-10 07:35:24 +05:30
|
|
|
free(p->package);
|
|
|
|
free(p);
|
2001-04-08 18:57:39 +05:30
|
|
|
} else {
|
2001-02-10 07:35:24 +05:30
|
|
|
/*
|
|
|
|
* Pseudo package status is the
|
|
|
|
* same as the status of the
|
|
|
|
* package providing it
|
|
|
|
* FIXME: (not quite right, if 2
|
|
|
|
* packages of different statuses
|
2001-04-08 18:57:39 +05:30
|
|
|
* provide it).
|
|
|
|
*/
|
2001-04-16 10:22:19 +05:30
|
|
|
t->state_want = m->state_want;
|
|
|
|
t->state_flag = m->state_flag;
|
|
|
|
t->state_status = m->state_status;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-11 05:47:22 +05:30
|
|
|
else {
|
2001-02-10 07:35:24 +05:30
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
static int status_merge(void *status, package_t *pkgs)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
|
|
|
FILE *fin, *fout;
|
2001-04-08 10:57:18 +05:30
|
|
|
char *line = NULL;
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *pkg = 0, *statpkg = 0;
|
|
|
|
package_t locpkg;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
if ((fout = wfopen(new_statusfile, "w")) == NULL) {
|
2001-02-10 07:35:24 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2001-02-11 05:47:22 +05:30
|
|
|
if (getenv(udpkg_quiet) == NULL) {
|
2001-02-10 07:35:24 +05:30
|
|
|
printf("(Updating database...)\n");
|
2001-02-11 05:47:22 +05:30
|
|
|
}
|
2001-04-08 18:57:39 +05:30
|
|
|
|
2001-04-08 12:48:08 +05:30
|
|
|
/*
|
|
|
|
* Dont use wfopen here, handle errors ourself
|
|
|
|
*/
|
|
|
|
if ((fin = fopen(statusfile, "r")) != NULL) {
|
2001-04-08 10:57:18 +05:30
|
|
|
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
|
2001-04-26 21:26:47 +05:30
|
|
|
chomp(line); /* trim newline */
|
2001-04-08 10:57:18 +05:30
|
|
|
/* If we see a package header, find out if it's a package
|
|
|
|
* that we have processed. if so, we skip that block for
|
|
|
|
* now (write it at the end).
|
|
|
|
*
|
|
|
|
* we also look at packages in the status cache and update
|
|
|
|
* their status fields
|
2001-04-08 12:48:08 +05:30
|
|
|
*/
|
2001-04-08 10:57:18 +05:30
|
|
|
if (strstr(line, "Package: ") == line) {
|
|
|
|
for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
|
|
|
|
pkg->package) != 0; pkg = pkg->next) ;
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
locpkg.package = line + 9;
|
|
|
|
statpkg = tfind(&locpkg, &status, package_compare);
|
2001-04-08 12:48:08 +05:30
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
/* note: statpkg should be non-zero, unless the status
|
|
|
|
* file was changed while we are processing (no locking
|
|
|
|
* is currently done...
|
|
|
|
*/
|
|
|
|
if (statpkg != 0) {
|
|
|
|
statpkg = *(package_t **)statpkg;
|
|
|
|
}
|
2001-02-11 05:47:22 +05:30
|
|
|
}
|
2001-04-08 10:57:18 +05:30
|
|
|
if (pkg != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strstr(line, "Status: ") == line && statpkg != 0) {
|
2001-04-08 18:57:39 +05:30
|
|
|
snprintf(line, sizeof(line), "Status: %s %s %s",
|
2001-04-16 10:22:19 +05:30
|
|
|
state_words_want[statpkg->state_want - 1],
|
|
|
|
state_words_flag[statpkg->state_flag - 1],
|
|
|
|
state_words_status[statpkg->state_status - 1]);
|
2001-04-08 10:57:18 +05:30
|
|
|
}
|
2001-04-10 04:18:12 +05:30
|
|
|
fprintf(fout, "%s\n", line);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-04-08 12:48:08 +05:30
|
|
|
fclose(fin);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-02-11 05:47:22 +05:30
|
|
|
free(line);
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
// Print out packages we processed.
|
|
|
|
for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
|
2001-04-16 15:56:46 +05:30
|
|
|
write_package(fout, pkg);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
fclose(fout);
|
|
|
|
|
2001-04-08 12:48:08 +05:30
|
|
|
/*
|
|
|
|
* Its ok if renaming statusfile fails becasue it doesnt exist
|
|
|
|
*/
|
|
|
|
if (rename(statusfile, bak_statusfile) == -1) {
|
|
|
|
struct stat stat_buf;
|
|
|
|
if (stat(statusfile, &stat_buf) == 0) {
|
2001-04-08 18:57:39 +05:30
|
|
|
error_msg("Couldnt create backup status file");
|
2001-04-08 12:48:08 +05:30
|
|
|
return(EXIT_FAILURE);
|
|
|
|
}
|
2001-04-08 18:57:39 +05:30
|
|
|
error_msg("No status file found, creating new one");
|
2001-02-11 05:47:22 +05:30
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-04-08 12:48:08 +05:30
|
|
|
if (rename(new_statusfile, statusfile) == -1) {
|
|
|
|
error_msg("Couldnt create status file");
|
|
|
|
return(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
return(EXIT_SUCCESS);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int is_file(const char *fn)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
if (stat(fn, &statbuf) < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
return S_ISREG(statbuf.st_mode);
|
|
|
|
}
|
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
static int dpkg_doconfigure(package_t *pkg)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
|
|
|
int r;
|
|
|
|
char postinst[1024];
|
|
|
|
char buf[1024];
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
DPRINTF("Configuring %s\n", pkg->package);
|
2001-04-16 10:22:19 +05:30
|
|
|
pkg->state_status = 0;
|
2001-02-10 20:23:08 +05:30
|
|
|
snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package);
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
if (is_file(postinst)) {
|
2001-02-10 07:35:24 +05:30
|
|
|
snprintf(buf, sizeof(buf), "%s configure", postinst);
|
2001-02-11 05:47:22 +05:30
|
|
|
if ((r = do_system(buf)) != 0) {
|
2001-04-10 04:18:12 +05:30
|
|
|
error_msg("postinst exited with status %d\n", r);
|
2001-04-16 10:22:19 +05:30
|
|
|
pkg->state_status = state_status_halfconfigured;
|
2001-02-10 07:35:24 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2001-04-16 10:22:19 +05:30
|
|
|
pkg->state_status = state_status_installed;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
static int dpkg_dounpack(package_t *pkg)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-04-16 10:22:19 +05:30
|
|
|
int r = 0;
|
2001-04-08 18:57:39 +05:30
|
|
|
int status = TRUE;
|
2001-04-16 10:22:19 +05:30
|
|
|
char *lst_path;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
DPRINTF("Unpacking %s\n", pkg->package);
|
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
/* extract the data file */
|
|
|
|
deb_extract(pkg->filename, extract_extract, "/", NULL);
|
2001-02-12 17:03:09 +05:30
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
/* extract the control files */
|
|
|
|
deb_extract(pkg->filename, extract_control, infodir, pkg->package);
|
2001-04-08 10:57:18 +05:30
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
/* Create the list file */
|
|
|
|
lst_path = xmalloc(strlen(infodir) + strlen(pkg->package) + 6);
|
|
|
|
strcpy(lst_path, infodir);
|
|
|
|
strcat(lst_path, pkg->package);
|
|
|
|
strcat(lst_path, ".list");
|
|
|
|
deb_extract(pkg->filename, extract_contents_to_file, lst_path, NULL);
|
2001-02-12 17:03:09 +05:30
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
pkg->state_want = state_want_install;
|
|
|
|
pkg->state_flag = state_flag_ok;
|
2001-04-08 18:57:39 +05:30
|
|
|
|
|
|
|
if (status == TRUE) {
|
2001-04-16 10:22:19 +05:30
|
|
|
pkg->state_status = state_status_unpacked;
|
2001-02-11 07:10:23 +05:30
|
|
|
} else {
|
2001-04-16 10:22:19 +05:30
|
|
|
pkg->state_status = state_status_halfinstalled;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-04-08 18:57:39 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
/*
|
2001-04-16 10:22:19 +05:30
|
|
|
* Extract and parse the control file from control.tar.gz
|
2001-02-12 17:03:09 +05:30
|
|
|
*/
|
2001-04-16 10:22:19 +05:30
|
|
|
static int dpkg_read_control(package_t *pkg)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-04-16 10:22:19 +05:30
|
|
|
FILE *pkg_file;
|
|
|
|
char *control_buffer = NULL;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-04-16 10:22:19 +05:30
|
|
|
if ((pkg_file = wfopen(pkg->filename, "r")) == NULL) {
|
2001-02-12 17:03:09 +05:30
|
|
|
return EXIT_FAILURE;
|
2001-02-11 07:10:23 +05:30
|
|
|
}
|
2001-04-16 10:22:19 +05:30
|
|
|
control_buffer = deb_extract(pkg->filename, extract_field, NULL, NULL);
|
|
|
|
fill_package_struct(pkg, control_buffer);
|
2001-02-12 17:03:09 +05:30
|
|
|
return EXIT_SUCCESS;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
static int dpkg_unpack(package_t *pkgs, void *status)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
|
|
|
int r = 0;
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *pkg;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
|
2001-04-16 10:22:19 +05:30
|
|
|
dpkg_read_control(pkg);
|
2001-02-12 17:03:09 +05:30
|
|
|
if ((r = dpkg_dounpack(pkg)) != 0 ) {
|
|
|
|
break;
|
|
|
|
}
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
status_merge(status, pkgs);
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
static int dpkg_configure(package_t *pkgs, void *status)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
void *found;
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *pkg;
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next) {
|
2001-02-10 07:35:24 +05:30
|
|
|
found = tfind(pkg, &status, package_compare);
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
if (found == 0) {
|
2001-04-10 04:18:12 +05:30
|
|
|
error_msg("Trying to configure %s, but it is not installed", pkg->package);
|
2001-02-10 07:35:24 +05:30
|
|
|
r = 1;
|
2001-02-11 07:10:23 +05:30
|
|
|
}
|
|
|
|
/* configure the package listed in the status file;
|
|
|
|
* not pkg, as we have info only for the latter
|
|
|
|
*/
|
|
|
|
else {
|
2001-02-10 19:56:48 +05:30
|
|
|
r = dpkg_doconfigure(*(package_t **)found);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
status_merge(status, 0);
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
static int dpkg_install(package_t *pkgs, void *status)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *p, *ordered = 0;
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
/* Stage 1: parse all the control information */
|
2001-02-12 17:03:09 +05:30
|
|
|
for (p = pkgs; p != 0; p = p->next) {
|
2001-04-16 10:22:19 +05:30
|
|
|
dpkg_read_control(p);
|
2001-02-12 17:03:09 +05:30
|
|
|
}
|
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
/* Stage 2: resolve dependencies */
|
|
|
|
#ifdef DODEPENDS
|
|
|
|
ordered = depends_resolve(pkgs, status);
|
|
|
|
#else
|
|
|
|
ordered = pkgs;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Stage 3: install */
|
2001-02-11 05:47:22 +05:30
|
|
|
for (p = ordered; p != 0; p = p->next) {
|
2001-04-16 10:22:19 +05:30
|
|
|
p->state_want = state_want_install;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
|
|
|
/* for now the flag is always set to ok... this is probably
|
|
|
|
* not what we want
|
|
|
|
*/
|
2001-04-16 10:22:19 +05:30
|
|
|
p->state_flag = state_flag_ok;
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
DPRINTF("Installing %s\n", p->package);
|
|
|
|
if (dpkg_dounpack(p) != 0) {
|
2001-04-16 10:22:19 +05:30
|
|
|
perror_msg(p->filename);
|
2001-02-12 17:03:09 +05:30
|
|
|
}
|
2001-04-08 18:57:39 +05:30
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
if (dpkg_doconfigure(p) != 0) {
|
2001-04-16 10:22:19 +05:30
|
|
|
perror_msg(p->filename);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
|
|
|
}
|
2001-04-08 10:57:18 +05:30
|
|
|
|
2001-02-11 05:47:22 +05:30
|
|
|
if (ordered != 0) {
|
2001-02-10 07:35:24 +05:30
|
|
|
status_merge(status, pkgs);
|
2001-02-11 05:47:22 +05:30
|
|
|
}
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
/*
|
|
|
|
* Not implemented yet
|
|
|
|
*
|
2001-02-12 17:03:09 +05:30
|
|
|
static int dpkg_remove(package_t *pkgs, void *status)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *p;
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
for (p = pkgs; p != 0; p = p->next)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
status_merge(status, 0);
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-02-10 07:35:24 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2001-04-08 10:57:18 +05:30
|
|
|
*/
|
2001-02-10 07:35:24 +05:30
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
extern int dpkg_main(int argc, char **argv)
|
2001-02-10 07:35:24 +05:30
|
|
|
{
|
2001-04-08 10:57:18 +05:30
|
|
|
const int arg_install = 1;
|
|
|
|
const int arg_unpack = 2;
|
|
|
|
const int arg_configure = 4;
|
|
|
|
|
2001-02-10 19:56:48 +05:30
|
|
|
package_t *p, *packages = NULL;
|
2001-02-12 17:03:09 +05:30
|
|
|
void *status = NULL;
|
2001-05-24 19:46:28 +05:30
|
|
|
int opt = 0;
|
2001-04-08 10:57:18 +05:30
|
|
|
int optflag = 0;
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
while ((opt = getopt(argc, argv, "iruc")) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'i':
|
|
|
|
optflag |= arg_install;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
optflag |= arg_unpack;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
optflag |= arg_configure;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
show_usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (optind < argc) {
|
|
|
|
p = (package_t *) xcalloc(1, sizeof(package_t));
|
|
|
|
if (optflag & arg_configure) {
|
|
|
|
p->package = xstrdup(argv[optind]);
|
2001-02-11 05:47:22 +05:30
|
|
|
} else {
|
2001-04-16 10:22:19 +05:30
|
|
|
p->filename = xstrdup(argv[optind]);
|
2001-04-08 10:57:18 +05:30
|
|
|
}
|
|
|
|
p->next = packages;
|
|
|
|
packages = p;
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
optind++;
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-02-11 07:10:23 +05:30
|
|
|
|
2001-04-08 12:53:53 +05:30
|
|
|
create_path(infodir, S_IRWXU);
|
2001-04-08 10:57:18 +05:30
|
|
|
|
2001-02-12 17:03:09 +05:30
|
|
|
status = status_read();
|
|
|
|
|
2001-04-08 10:57:18 +05:30
|
|
|
if (optflag & arg_install) {
|
|
|
|
return dpkg_install(packages, status);
|
|
|
|
}
|
|
|
|
else if (optflag & arg_unpack) {
|
|
|
|
return dpkg_unpack(packages, status);
|
|
|
|
}
|
|
|
|
else if (optflag & arg_configure) {
|
|
|
|
return dpkg_configure(packages, status);
|
2001-02-10 07:35:24 +05:30
|
|
|
}
|
2001-04-08 10:57:18 +05:30
|
|
|
return(EXIT_FAILURE);
|
2001-02-15 02:53:06 +05:30
|
|
|
}
|