blob: 18742e8f63ce1afff6c8a18464879948c3f7f7e0 [file] [log] [blame]
Glenn L McGrath0e757a22001-04-08 05:27:18 +00001#include <dirent.h>
2#include <getopt.h>
Glenn L McGrathc9005752001-02-10 02:05:24 +00003#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6#include <search.h>
7#include <errno.h>
8#include <fcntl.h>
9#include <unistd.h>
10#include <utime.h>
11#include <sys/types.h>
12#include <sys/stat.h>
Glenn L McGrath649968c2001-02-10 14:26:48 +000013
Glenn L McGrathc9005752001-02-10 02:05:24 +000014#include "busybox.h"
15
Eric Andersen3c0b4252001-03-14 01:31:11 +000016
Glenn L McGrath3af1f882001-02-12 11:33:09 +000017#define DEPENDSMAX 64 /* maximum number of depends we can handle */
Glenn L McGrathc9005752001-02-10 02:05:24 +000018
Glenn L McGrath3af1f882001-02-12 11:33:09 +000019/* Should we do full dependency checking? */
Glenn L McGrathae1c7042001-04-16 10:26:46 +000020//#define DODEPENDS 0
Glenn L McGrathc9005752001-02-10 02:05:24 +000021
Glenn L McGrath3af1f882001-02-12 11:33:09 +000022/* Should we do debugging? */
Glenn L McGrathae1c7042001-04-16 10:26:46 +000023//#define DODEBUG 0
Glenn L McGrathc9005752001-02-10 02:05:24 +000024
25#ifdef DODEBUG
Glenn L McGrathc9005752001-02-10 02:05:24 +000026#define SYSTEM(x) do_system(x)
27#define DPRINTF(fmt,args...) fprintf(stderr, fmt, ##args)
28#else
Glenn L McGrathc9005752001-02-10 02:05:24 +000029#define SYSTEM(x) system(x)
30#define DPRINTF(fmt,args...) /* nothing */
31#endif
32
Glenn L McGrath3af1f882001-02-12 11:33:09 +000033/* from dpkg-deb.c */
Glenn L McGrathd22e5602001-04-11 02:12:08 +000034
Glenn L McGrath63106462001-02-11 01:40:23 +000035static const char statusfile[] = "/var/lib/dpkg/status.udeb";
36static const char new_statusfile[] = "/var/lib/dpkg/status.udeb.new";
37static const char bak_statusfile[] = "/var/lib/dpkg/status.udeb.bak";
38
Glenn L McGrath510f0dd2001-02-10 14:53:08 +000039static const char infodir[] = "/var/lib/dpkg/info/";
40static const char udpkg_quiet[] = "UDPKG_QUIET";
Glenn L McGrathc9005752001-02-10 02:05:24 +000041
Glenn L McGrath305fdfa2001-04-08 13:27:39 +000042//static const int status_want_unknown = 1;
Glenn L McGrath33431eb2001-04-16 04:52:19 +000043static const int state_want_install = 2;
44//static const int state_want_hold = 3;
45//static const int state_want_deinstall = 4;
46//static const int state_want_purge = 5;
Glenn L McGrathc9005752001-02-10 02:05:24 +000047
Glenn L McGrath33431eb2001-04-16 04:52:19 +000048static const int state_flag_ok = 1;
49//static const int state_flag_reinstreq = 2;
50//static const int state_flag_hold = 3;
51//static const int state_flag_holdreinstreq = 4;
Glenn L McGrathc9005752001-02-10 02:05:24 +000052
Glenn L McGrath33431eb2001-04-16 04:52:19 +000053//static const int state_statusnoninstalled = 1;
54static const int state_status_unpacked = 2;
55static const int state_status_halfconfigured = 3;
56static const int state_status_installed = 4;
57static const int state_status_halfinstalled = 5;
58//static const int state_statusconfigfiles = 6;
59//static const int state_statuspostinstfailed = 7;
60//static const int state_statusremovalfailed = 8;
Glenn L McGrathc9005752001-02-10 02:05:24 +000061
Glenn L McGrath33431eb2001-04-16 04:52:19 +000062static const char *state_words_want[] = { "unknown", "install", "hold", "deinstall", "purge", 0 };
63static const char *state_words_flag[] = { "ok", "reinstreq", "hold", "hold-reinstreq", 0 };
64static const char *state_words_status[] = { "not-installed", "unpacked", "half-configured", "installed",
Glenn L McGrath305fdfa2001-04-08 13:27:39 +000065 "half-installed", "config-files", "post-inst-failed", "removal-failed", 0 };
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +000066
Eric Andersen3e6ff902001-03-09 21:24:12 +000067static const int color_white = 0;
68static const int color_grey = 1;
69static const int color_black = 2;
Glenn L McGrathc9005752001-02-10 02:05:24 +000070
Glenn L McGrath33431eb2001-04-16 04:52:19 +000071/* data structures */
Glenn L McGrath649968c2001-02-10 14:26:48 +000072typedef struct package_s {
Glenn L McGrath33431eb2001-04-16 04:52:19 +000073 char *filename;
Glenn L McGrathc9005752001-02-10 02:05:24 +000074 char *package;
Glenn L McGrath33431eb2001-04-16 04:52:19 +000075 unsigned char state_want;
76 unsigned char state_flag;
77 unsigned char state_status;
Glenn L McGrathc9005752001-02-10 02:05:24 +000078 char *depends;
79 char *provides;
80 char *description;
Glenn L McGrath33431eb2001-04-16 04:52:19 +000081 char *priority;
82 char *section;
83 char *installed_size;
84 char *maintainer;
85 char *source;
86 char *version;
87 char *pre_depends;
88 char *replaces;
89 char *recommends;
90 char *suggests;
91 char *conflicts;
92 char *conffiles;
93 char *long_description;
94 char *architecture;
95 char *md5sum;
Glenn L McGrathc9005752001-02-10 02:05:24 +000096 int installer_menu_item;
Glenn L McGrathc9005752001-02-10 02:05:24 +000097 char color; /* for topo-sort */
Glenn L McGrath649968c2001-02-10 14:26:48 +000098 struct package_s *requiredfor[DEPENDSMAX];
Glenn L McGrathc9005752001-02-10 02:05:24 +000099 unsigned short requiredcount;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000100 struct package_s *next;
101} package_t;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000102
Glenn L McGrath63106462001-02-11 01:40:23 +0000103#ifdef DODEBUG
104static int do_system(const char *cmd)
105{
106 DPRINTF("cmd is %s\n", cmd);
107 return system(cmd);
108}
109#else
110#define do_system(cmd) system(cmd)
111#endif
112
Glenn L McGrath649968c2001-02-10 14:26:48 +0000113static int package_compare(const void *p1, const void *p2)
114{
115 return strcmp(((package_t *)p1)->package,
116 ((package_t *)p2)->package);
117}
Glenn L McGrathc9005752001-02-10 02:05:24 +0000118
119#ifdef DODEPENDS
120#include <ctype.h>
121
122static char **depends_split(const char *dependsstr)
123{
124 static char *dependsvec[DEPENDSMAX];
125 char *p;
126 int i = 0;
127
128 dependsvec[0] = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000129 if (dependsstr == 0) {
130 goto end;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000131 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000132
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000133 p = xstrdup(dependsstr);
Glenn L McGrath63106462001-02-11 01:40:23 +0000134 while (*p != 0 && *p != '\n') {
135 if (*p != ' ') {
136 if (*p == ',') {
137 *p = 0;
138 dependsvec[++i] = 0;
139 } else {
140 if (dependsvec[i] == 0) {
141 dependsvec[i] = p;
142 }
143 }
144 } else {
145 *p = 0; /* eat the space... */
146 }
147 p++;
148 }
149 *p = 0;
150
151end:
Glenn L McGrathc9005752001-02-10 02:05:24 +0000152 dependsvec[i+1] = 0;
153 return dependsvec;
154}
155
Glenn L McGrath63106462001-02-11 01:40:23 +0000156/* Topological sort algorithm:
157 * ordered is the output list, pkgs is the dependency graph, pkg is
158 * the current node
159 *
160 * recursively add all the adjacent nodes to the ordered list, marking
161 * each one as visited along the way
162 *
163 * yes, this algorithm looks a bit odd when all the params have the
164 * same type :-)
165 */
Glenn L McGrath649968c2001-02-10 14:26:48 +0000166static void depends_sort_visit(package_t **ordered, package_t *pkgs,
167 package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000168{
Glenn L McGrathc9005752001-02-10 02:05:24 +0000169 unsigned short i;
170
171 /* mark node as processing */
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000172 pkg->color = color_grey;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000173
174 /* visit each not-yet-visited node */
175 for (i = 0; i < pkg->requiredcount; i++)
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000176 if (pkg->requiredfor[i]->color == color_white)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000177 depends_sort_visit(ordered, pkgs, pkg->requiredfor[i]);
178
179#if 0
180 /* add it to the list */
Eric Andersenb50d7072001-02-15 19:50:11 +0000181 newnode = (struct package_t *)xmalloc(sizeof(struct package_t));
Glenn L McGrathc9005752001-02-10 02:05:24 +0000182 /* make a shallow copy */
183 *newnode = *pkg;
184 newnode->next = *ordered;
185 *ordered = newnode;
186#endif
Glenn L McGrath63106462001-02-11 01:40:23 +0000187
Glenn L McGrathc9005752001-02-10 02:05:24 +0000188 pkg->next = *ordered;
189 *ordered = pkg;
190
191 /* mark node as done */
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000192 pkg->color = color_black;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000193}
194
Glenn L McGrath649968c2001-02-10 14:26:48 +0000195static package_t *depends_sort(package_t *pkgs)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000196{
197 /* TODO: it needs to break cycles in the to-be-installed package
198 * graph... */
Glenn L McGrath649968c2001-02-10 14:26:48 +0000199 package_t *ordered = NULL;
200 package_t *pkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000201
Glenn L McGrath63106462001-02-11 01:40:23 +0000202 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000203 pkg->color = color_white;
Glenn L McGrath63106462001-02-11 01:40:23 +0000204 }
205 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
206 if (pkg->color == color_white) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000207 depends_sort_visit(&ordered, pkgs, pkg);
Glenn L McGrath63106462001-02-11 01:40:23 +0000208 }
209 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000210
211 /* Leaks the old list... return the new one... */
212 return ordered;
213}
214
215
216/* resolve package dependencies --
217 * for each package in the list of packages to be installed, we parse its
218 * dependency info to determine if the dependent packages are either
219 * already installed, or are scheduled to be installed. If both tests fail
220 * than bail.
221 *
222 * The algorithm here is O(n^2*m) where n = number of packages to be
223 * installed and m is the # of dependencies per package. Not a terribly
224 * efficient algorithm, but given that at any one time you are unlikely
225 * to install a very large number of packages it doesn't really matter
226 */
Glenn L McGrath649968c2001-02-10 14:26:48 +0000227static package_t *depends_resolve(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000228{
Glenn L McGrath649968c2001-02-10 14:26:48 +0000229 package_t *pkg, *chk;
230 package_t dependpkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000231 char **dependsvec;
232 int i;
233 void *found;
234
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000235 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000236 dependsvec = depends_split(pkg->depends);
237 i = 0;
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000238 while (dependsvec[i] != 0) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000239 /* Check for dependencies; first look for installed packages */
240 dependpkg.package = dependsvec[i];
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000241 if (((found = tfind(&dependpkg, &status, package_compare)) == 0) ||
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000242 ((chk = *(package_t **)found) && (chk->state_flag & state_flag_ok) &&
243 (chk->state_status & state_status_installed))) {
Glenn L McGrath63106462001-02-11 01:40:23 +0000244
Glenn L McGrathc9005752001-02-10 02:05:24 +0000245 /* if it fails, we look through the list of packages we are going to
246 * install */
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000247 for (chk = pkgs; chk != 0; chk = chk->next) {
Glenn L McGrath63106462001-02-11 01:40:23 +0000248 if (strcmp(chk->package, dependsvec[i]) == 0 || (chk->provides &&
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000249 strncmp(chk->provides, dependsvec[i], strlen(dependsvec[i])) == 0)) {
250 if (chk->requiredcount >= DEPENDSMAX) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000251 error_msg("Too many dependencies for %s", chk->package);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000252 return 0;
253 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000254 if (chk != pkg) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000255 chk->requiredfor[chk->requiredcount++] = pkg;
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000256 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000257 break;
258 }
259 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000260 if (chk == 0) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000261 error_msg("%s depends on %s, but it is not going to be installed", pkg->package, dependsvec[i]);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000262 return 0;
263 }
264 }
265 i++;
266 }
267 }
268
269 return depends_sort(pkgs);
270}
271#endif
272
273/* Status file handling routines
274 *
275 * This is a fairly minimalistic implementation. there are two main functions
276 * that are supported:
277 *
278 * 1) reading the entire status file:
279 * the status file is read into memory as a binary-tree, with just the
280 * package and status info preserved
281 *
282 * 2) merging the status file
283 * control info from (new) packages is merged into the status file,
284 * replacing any pre-existing entries. when a merge happens, status info
285 * read using the status_read function is written back to the status file
286 */
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000287static unsigned char status_parse(const char *line, const char **status_words)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000288{
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000289 unsigned char status_num;
290 int i = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000291
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000292 while (status_words[i] != 0) {
293 if (strncmp(line, status_words[i], strlen(status_words[i])) == 0) {
294 status_num = (char)i;
295 return(status_num);
Glenn L McGrath63106462001-02-11 01:40:23 +0000296 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000297 i++;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000298 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000299 /* parse error */
300 error_msg("Invalid status word");
301 return(0);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000302}
303
304/*
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000305 * Read the buffered control file and parse it,
Glenn L McGrathc9005752001-02-10 02:05:24 +0000306 * filling parsed fields into the package structure
307 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000308static int fill_package_struct(package_t *package, const char *package_buffer)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000309{
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000310 char *field = NULL;
311 int field_start = 0;
312 int field_length = 0;
Glenn L McGrathae1c7042001-04-16 10:26:46 +0000313
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000314 while ((field = read_package_field(&package_buffer[field_start])) != NULL) {
315 field_length = strlen(field);
316 field_start += (field_length + 1);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000317
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000318 if (strlen(field) == 0) {
319 printf("empty line: *this shouldnt happen i dont think*\n");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000320 break;
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000321 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000322
323 /* these are common to both installed and uninstalled packages */
324 if (strstr(field, "Package: ") == field) {
325 package->package = strdup(field + 9);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000326 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000327 else if (strstr(field, "Depends: ") == field) {
328 package->depends = strdup(field + 9);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000329 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000330 else if (strstr(field, "Provides: ") == field) {
331 package->provides = strdup(field + 10);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000332 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000333 /* This is specific to the Debian Installer. Ifdef? */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000334 else if (strstr(field, "installer-menu-item: ") == field) {
335 package->installer_menu_item = atoi(field + 21);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000336 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000337 else if (strstr(field, "Description: ") == field) {
338 package->description = strdup(field + 13);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000339 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000340 else if (strstr(field, "Priority: ") == field) {
341 package->priority = strdup(field + 10);
342 }
343 else if (strstr(field, "Section: ") == field) {
344 package->section = strdup(field + 9);
345 }
346 else if (strstr(field, "Installed-Size: ") == field) {
347 package->installed_size = strdup(field + 16);
348 }
349 else if (strstr(field, "Maintainer: ") == field) {
350 package->maintainer = strdup(field + 12);
351 }
352 else if (strstr(field, "Version: ") == field) {
353 package->version = strdup(field + 9);
354 }
355 else if (strstr(field, "Suggests: ") == field) {
356 package->suggests = strdup(field + 10);
357 }
358 else if (strstr(field, "Recommends: ") == field) {
359 package->recommends = strdup(field + 12);
360 }
361/* else if (strstr(field, "Conffiles: ") == field) {
362 package->conffiles = read_block(file);
363 package->conffiles = xcalloc(1, 1);
364 while ((field = strtok(NULL, "\n")) != NULL) {
365 package->long_description = xrealloc(package->conffiles,
366 strlen(package->conffiles) + strlen(field) + 1);
367 strcat(package->conffiles, field);
368 }
369 }
370*/
371 /* These are only in available file */
372 else if (strstr(field, "Architecture: ") == field) {
373 package->architecture = strdup(field + 14);
374 }
375 else if (strstr(field, "Filename: ") == field) {
376 package->filename = strdup(field + 10);
377 }
378 else if (strstr(field, "MD5sum ") == field) {
379 package->md5sum = strdup(field + 7);
380 }
381
382 /* This is only needed for status file */
383 if (strstr(field, "Status: ") == field) {
384 char *word_pointer;
385
386 word_pointer = strchr(field, ' ') + 1;
387 package->state_want = status_parse(word_pointer, state_words_want);
388 word_pointer = strchr(word_pointer, ' ') + 1;
389 package->state_flag = status_parse(word_pointer, state_words_flag);
390 word_pointer = strchr(word_pointer, ' ') + 1;
391 package->state_status = status_parse(word_pointer, state_words_status);
392 } else {
393 package->state_want = status_parse("purge", state_words_want);
394 package->state_flag = status_parse("ok", state_words_flag);
395 package->state_status = status_parse("not-installed", state_words_status);
396 }
397
398 free(field);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000399 }
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000400 return EXIT_SUCCESS;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000401}
402
Glenn L McGrathae1c7042001-04-16 10:26:46 +0000403extern void write_package(FILE *out_file, package_t *pkg)
404{
405 if (pkg->package) {
406 fprintf(out_file, "Package: %s\n", pkg->package);
407 }
408 if ((pkg->state_want != 0) || (pkg->state_flag != 0)|| (pkg->state_status != 0)) {
409 fprintf(out_file, "Status: %s %s %s\n",
410 state_words_want[pkg->state_want - 1],
411 state_words_flag[pkg->state_flag - 1],
412 state_words_status[pkg->state_status - 1]);
413 }
414 if (pkg->depends) {
415 fprintf(out_file, "Depends: %s\n", pkg->depends);
416 }
417 if (pkg->provides) {
418 fprintf(out_file, "Provides: %s\n", pkg->provides);
419 }
420 if (pkg->priority) {
421 fprintf(out_file, "Priority: %s\n", pkg->priority);
422 }
423 if (pkg->section) {
424 fprintf(out_file, "Section: %s\n", pkg->section);
425 }
426 if (pkg->section) {
427 fprintf(out_file, "Installed-Size: %s\n", pkg->installed_size);
428 }
429 if (pkg->maintainer) {
430 fprintf(out_file, "Maintainer: %s\n", pkg->maintainer);
431 }
432 if (pkg->source) {
433 fprintf(out_file, "Source: %s\n", pkg->source);
434 }
435 if (pkg->version) {
436 fprintf(out_file, "Version: %s\n", pkg->version);
437 }
438 if (pkg->pre_depends) {
439 fprintf(out_file, "Pre-depends: %s\n", pkg->pre_depends);
440 }
441 if (pkg->replaces) {
442 fprintf(out_file, "Replaces: %s\n", pkg->replaces);
443 }
444 if (pkg->recommends) {
445 fprintf(out_file, "Recommends: %s\n", pkg->recommends);
446 }
447 if (pkg->suggests) {
448 fprintf(out_file, "Suggests: %s\n", pkg->suggests);
449 }
450 if (pkg->conflicts) {
451 fprintf(out_file, "Conflicts: %s\n", pkg->conflicts);
452 }
453 if (pkg->conffiles) {
454 fprintf(out_file, "Conf-files: %s\n", pkg->conffiles);
455 }
456 if (pkg->architecture) {
457 fprintf(out_file, "Architecture: %s\n", pkg->architecture);
458 }
459 if (pkg->filename) {
460 fprintf(out_file, "Filename: %s\n", pkg->filename);
461 }
462 if (pkg->md5sum) {
463 fprintf(out_file, "MD5sum: %s\n", pkg->md5sum);
464 }
465 if (pkg->installer_menu_item) {
466 fprintf(out_file, "installer-main-menu %d\n", pkg->installer_menu_item);
467 }
468 if (pkg->description) {
469 fprintf(out_file, "Description: %s\n", pkg->description);
470 }
471 fputc('\n', out_file);
472 pkg = pkg->next;
473}
474
Glenn L McGrath649968c2001-02-10 14:26:48 +0000475static void *status_read(void)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000476{
477 FILE *f;
478 void *status = 0;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000479 package_t *m = 0, *p = 0, *t = 0;
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000480 char *package_control_buffer = NULL;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000481
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000482 if (getenv(udpkg_quiet) == NULL) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000483 printf("(Reading database...)\n");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000484 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000485
Eric Andersene5dfced2001-04-09 22:48:12 +0000486 if ((f = wfopen(statusfile, "r")) == NULL) {
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000487 return(NULL);
488 }
489
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000490 while ( (package_control_buffer = read_text_file_to_buffer(f)) != NULL) {
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000491 m = (package_t *)xcalloc(1, sizeof(package_t));
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000492 fill_package_struct(m, package_control_buffer);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000493 if (m->package) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000494 /*
495 * If there is an item in the tree by this name,
496 * it must be a virtual package; insert real
497 * package in preference.
498 */
499 tdelete(m, &status, package_compare);
500 tsearch(m, &status, package_compare);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000501 if (m->provides) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000502 /*
503 * A "Provides" triggers the insertion
504 * of a pseudo package into the status
505 * binary-tree.
506 */
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000507 p = (package_t *)xcalloc(1, sizeof(package_t));
508 p->package = xstrdup(m->provides);
Glenn L McGrath649968c2001-02-10 14:26:48 +0000509 t = *(package_t **)tsearch(p, &status, package_compare);
Glenn L McGrath63106462001-02-11 01:40:23 +0000510 if (t != p) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000511 free(p->package);
512 free(p);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000513 } else {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000514 /*
515 * Pseudo package status is the
516 * same as the status of the
517 * package providing it
518 * FIXME: (not quite right, if 2
519 * packages of different statuses
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000520 * provide it).
521 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000522 t->state_want = m->state_want;
523 t->state_flag = m->state_flag;
524 t->state_status = m->state_status;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000525 }
526 }
527 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000528 else {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000529 free(m);
530 }
531 }
532 fclose(f);
533 return status;
534}
535
Glenn L McGrath649968c2001-02-10 14:26:48 +0000536static int status_merge(void *status, package_t *pkgs)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000537{
538 FILE *fin, *fout;
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000539 char *line = NULL;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000540 package_t *pkg = 0, *statpkg = 0;
541 package_t locpkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000542
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000543 if ((fout = wfopen(new_statusfile, "w")) == NULL) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000544 return 0;
545 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000546 if (getenv(udpkg_quiet) == NULL) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000547 printf("(Updating database...)\n");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000548 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000549
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000550 /*
551 * Dont use wfopen here, handle errors ourself
552 */
553 if ((fin = fopen(statusfile, "r")) != NULL) {
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000554 while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
Eric Andersenc1bdffe2001-04-26 15:56:47 +0000555 chomp(line); /* trim newline */
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000556 /* If we see a package header, find out if it's a package
557 * that we have processed. if so, we skip that block for
558 * now (write it at the end).
559 *
560 * we also look at packages in the status cache and update
561 * their status fields
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000562 */
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000563 if (strstr(line, "Package: ") == line) {
564 for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
565 pkg->package) != 0; pkg = pkg->next) ;
Glenn L McGrath63106462001-02-11 01:40:23 +0000566
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000567 locpkg.package = line + 9;
568 statpkg = tfind(&locpkg, &status, package_compare);
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000569
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000570 /* note: statpkg should be non-zero, unless the status
571 * file was changed while we are processing (no locking
572 * is currently done...
573 */
574 if (statpkg != 0) {
575 statpkg = *(package_t **)statpkg;
576 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000577 }
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000578 if (pkg != 0) {
579 continue;
580 }
581 if (strstr(line, "Status: ") == line && statpkg != 0) {
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000582 snprintf(line, sizeof(line), "Status: %s %s %s",
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000583 state_words_want[statpkg->state_want - 1],
584 state_words_flag[statpkg->state_flag - 1],
585 state_words_status[statpkg->state_status - 1]);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000586 }
Eric Andersene5dfced2001-04-09 22:48:12 +0000587 fprintf(fout, "%s\n", line);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000588 }
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000589 fclose(fin);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000590 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000591 free(line);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000592
593 // Print out packages we processed.
594 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrathae1c7042001-04-16 10:26:46 +0000595 write_package(fout, pkg);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000596 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000597 fclose(fout);
598
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000599 /*
600 * Its ok if renaming statusfile fails becasue it doesnt exist
601 */
602 if (rename(statusfile, bak_statusfile) == -1) {
603 struct stat stat_buf;
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000604 if (stat(statusfile, &stat_buf) == 0) {
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000605 error_msg("Couldnt create backup status file");
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000606 return(EXIT_FAILURE);
607 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000608 error_msg("No status file found, creating new one");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000609 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000610
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000611 if (rename(new_statusfile, statusfile) == -1) {
612 error_msg("Couldnt create status file");
613 return(EXIT_FAILURE);
614 }
615 return(EXIT_SUCCESS);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000616}
617
Glenn L McGrathc9005752001-02-10 02:05:24 +0000618static int is_file(const char *fn)
619{
620 struct stat statbuf;
621
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000622 if (stat(fn, &statbuf) < 0) {
623 return 0;
624 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000625 return S_ISREG(statbuf.st_mode);
626}
627
Glenn L McGrath649968c2001-02-10 14:26:48 +0000628static int dpkg_doconfigure(package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000629{
630 int r;
631 char postinst[1024];
632 char buf[1024];
Glenn L McGrath63106462001-02-11 01:40:23 +0000633
Glenn L McGrathc9005752001-02-10 02:05:24 +0000634 DPRINTF("Configuring %s\n", pkg->package);
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000635 pkg->state_status = 0;
Glenn L McGrath510f0dd2001-02-10 14:53:08 +0000636 snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package);
Glenn L McGrath63106462001-02-11 01:40:23 +0000637
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000638 if (is_file(postinst)) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000639 snprintf(buf, sizeof(buf), "%s configure", postinst);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000640 if ((r = do_system(buf)) != 0) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000641 error_msg("postinst exited with status %d\n", r);
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000642 pkg->state_status = state_status_halfconfigured;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000643 return 1;
644 }
645 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000646 pkg->state_status = state_status_installed;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000647
648 return 0;
649}
650
Glenn L McGrath649968c2001-02-10 14:26:48 +0000651static int dpkg_dounpack(package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000652{
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000653 int r = 0;
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000654 int status = TRUE;
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000655 char *lst_path;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000656
657 DPRINTF("Unpacking %s\n", pkg->package);
658
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000659 /* extract the data file */
660 deb_extract(pkg->filename, extract_extract, "/", NULL);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000661
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000662 /* extract the control files */
663 deb_extract(pkg->filename, extract_control, infodir, pkg->package);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000664
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000665 /* Create the list file */
666 lst_path = xmalloc(strlen(infodir) + strlen(pkg->package) + 6);
667 strcpy(lst_path, infodir);
668 strcat(lst_path, pkg->package);
669 strcat(lst_path, ".list");
670 deb_extract(pkg->filename, extract_contents_to_file, lst_path, NULL);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000671
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000672 pkg->state_want = state_want_install;
673 pkg->state_flag = state_flag_ok;
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000674
675 if (status == TRUE) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000676 pkg->state_status = state_status_unpacked;
Glenn L McGrath63106462001-02-11 01:40:23 +0000677 } else {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000678 pkg->state_status = state_status_halfinstalled;
Glenn L McGrath63106462001-02-11 01:40:23 +0000679 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000680
Glenn L McGrathc9005752001-02-10 02:05:24 +0000681 return r;
682}
683
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000684/*
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000685 * Extract and parse the control file from control.tar.gz
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000686 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000687static int dpkg_read_control(package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000688{
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000689 FILE *pkg_file;
690 char *control_buffer = NULL;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000691
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000692 if ((pkg_file = wfopen(pkg->filename, "r")) == NULL) {
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000693 return EXIT_FAILURE;
Glenn L McGrath63106462001-02-11 01:40:23 +0000694 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000695 control_buffer = deb_extract(pkg->filename, extract_field, NULL, NULL);
696 fill_package_struct(pkg, control_buffer);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000697 return EXIT_SUCCESS;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000698}
699
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000700static int dpkg_unpack(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000701{
702 int r = 0;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000703 package_t *pkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000704
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000705 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000706 dpkg_read_control(pkg);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000707 if ((r = dpkg_dounpack(pkg)) != 0 ) {
708 break;
709 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000710 }
711 status_merge(status, pkgs);
Glenn L McGrath63106462001-02-11 01:40:23 +0000712
Glenn L McGrathc9005752001-02-10 02:05:24 +0000713 return r;
714}
715
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000716static int dpkg_configure(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000717{
718 int r = 0;
719 void *found;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000720 package_t *pkg;
Glenn L McGrath63106462001-02-11 01:40:23 +0000721
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000722 for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000723 found = tfind(pkg, &status, package_compare);
Glenn L McGrath63106462001-02-11 01:40:23 +0000724
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000725 if (found == 0) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000726 error_msg("Trying to configure %s, but it is not installed", pkg->package);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000727 r = 1;
Glenn L McGrath63106462001-02-11 01:40:23 +0000728 }
729 /* configure the package listed in the status file;
730 * not pkg, as we have info only for the latter
731 */
732 else {
Glenn L McGrath649968c2001-02-10 14:26:48 +0000733 r = dpkg_doconfigure(*(package_t **)found);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000734 }
735 }
736 status_merge(status, 0);
Glenn L McGrath63106462001-02-11 01:40:23 +0000737
Glenn L McGrathc9005752001-02-10 02:05:24 +0000738 return r;
739}
740
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000741static int dpkg_install(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000742{
Glenn L McGrath649968c2001-02-10 14:26:48 +0000743 package_t *p, *ordered = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000744
Glenn L McGrathc9005752001-02-10 02:05:24 +0000745 /* Stage 1: parse all the control information */
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000746 for (p = pkgs; p != 0; p = p->next) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000747 dpkg_read_control(p);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000748 }
749
Glenn L McGrathc9005752001-02-10 02:05:24 +0000750 /* Stage 2: resolve dependencies */
751#ifdef DODEPENDS
752 ordered = depends_resolve(pkgs, status);
753#else
754 ordered = pkgs;
755#endif
756
757 /* Stage 3: install */
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000758 for (p = ordered; p != 0; p = p->next) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000759 p->state_want = state_want_install;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000760
761 /* for now the flag is always set to ok... this is probably
762 * not what we want
763 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000764 p->state_flag = state_flag_ok;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000765
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000766 DPRINTF("Installing %s\n", p->package);
767 if (dpkg_dounpack(p) != 0) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000768 perror_msg(p->filename);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000769 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000770
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000771 if (dpkg_doconfigure(p) != 0) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000772 perror_msg(p->filename);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000773 }
774 }
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000775
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000776 if (ordered != 0) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000777 status_merge(status, pkgs);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000778 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000779
Glenn L McGrathc9005752001-02-10 02:05:24 +0000780 return 0;
781}
782
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000783/*
784 * Not implemented yet
785 *
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000786static int dpkg_remove(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000787{
Glenn L McGrath649968c2001-02-10 14:26:48 +0000788 package_t *p;
Glenn L McGrath63106462001-02-11 01:40:23 +0000789
Glenn L McGrathc9005752001-02-10 02:05:24 +0000790 for (p = pkgs; p != 0; p = p->next)
791 {
792 }
793 status_merge(status, 0);
Glenn L McGrath63106462001-02-11 01:40:23 +0000794
Glenn L McGrathc9005752001-02-10 02:05:24 +0000795 return 0;
796}
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000797*/
Glenn L McGrathc9005752001-02-10 02:05:24 +0000798
Glenn L McGrath649968c2001-02-10 14:26:48 +0000799extern int dpkg_main(int argc, char **argv)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000800{
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000801 const int arg_install = 1;
802 const int arg_unpack = 2;
803 const int arg_configure = 4;
804
Glenn L McGrath649968c2001-02-10 14:26:48 +0000805 package_t *p, *packages = NULL;
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000806 void *status = NULL;
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000807 char opt = 0;
808 int optflag = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000809
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000810 while ((opt = getopt(argc, argv, "iruc")) != -1) {
811 switch (opt) {
812 case 'i':
813 optflag |= arg_install;
814 break;
815 case 'u':
816 optflag |= arg_unpack;
817 break;
818 case 'c':
819 optflag |= arg_configure;
820 break;
821 default:
822 show_usage();
823 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000824 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000825
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000826 while (optind < argc) {
827 p = (package_t *) xcalloc(1, sizeof(package_t));
828 if (optflag & arg_configure) {
829 p->package = xstrdup(argv[optind]);
830 } else {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000831 p->filename = xstrdup(argv[optind]);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000832 }
833 p->next = packages;
834 packages = p;
835
836 optind++;
837 }
838
Glenn L McGrath37849f32001-04-08 07:23:53 +0000839 create_path(infodir, S_IRWXU);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000840
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000841 status = status_read();
842
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000843 if (optflag & arg_install) {
844 return dpkg_install(packages, status);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000845 }
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000846 else if (optflag & arg_unpack) {
847 return dpkg_unpack(packages, status);
848 }
849 else if (optflag & arg_configure) {
850 return dpkg_configure(packages, status);
851 }
852 return(EXIT_FAILURE);
Eric Andersen67991cf2001-02-14 21:23:06 +0000853}