blob: 020a68a903e203ff0e2d295bf3d35db5bbb8391b [file] [log] [blame]
Eric Andersen807bda42001-07-07 08:13:02 +00001#include <ctype.h>
Glenn L McGrath0e757a22001-04-08 05:27:18 +00002#include <dirent.h>
3#include <getopt.h>
Glenn L McGrathc9005752001-02-10 02:05:24 +00004#include <stdio.h>
5#include <string.h>
6#include <stdlib.h>
7#include <search.h>
8#include <errno.h>
9#include <fcntl.h>
10#include <unistd.h>
11#include <utime.h>
12#include <sys/types.h>
13#include <sys/stat.h>
Glenn L McGrath649968c2001-02-10 14:26:48 +000014
Glenn L McGrathc9005752001-02-10 02:05:24 +000015#include "busybox.h"
16
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
Glenn L McGrathc9005752001-02-10 02:05:24 +0000120
121static char **depends_split(const char *dependsstr)
122{
123 static char *dependsvec[DEPENDSMAX];
124 char *p;
125 int i = 0;
126
127 dependsvec[0] = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000128 if (dependsstr == 0) {
129 goto end;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000130 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000131
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000132 p = xstrdup(dependsstr);
Glenn L McGrath63106462001-02-11 01:40:23 +0000133 while (*p != 0 && *p != '\n') {
134 if (*p != ' ') {
135 if (*p == ',') {
136 *p = 0;
137 dependsvec[++i] = 0;
138 } else {
139 if (dependsvec[i] == 0) {
140 dependsvec[i] = p;
141 }
142 }
143 } else {
144 *p = 0; /* eat the space... */
145 }
146 p++;
147 }
148 *p = 0;
149
150end:
Glenn L McGrathc9005752001-02-10 02:05:24 +0000151 dependsvec[i+1] = 0;
152 return dependsvec;
153}
154
Glenn L McGrath63106462001-02-11 01:40:23 +0000155/* Topological sort algorithm:
156 * ordered is the output list, pkgs is the dependency graph, pkg is
157 * the current node
158 *
159 * recursively add all the adjacent nodes to the ordered list, marking
160 * each one as visited along the way
161 *
162 * yes, this algorithm looks a bit odd when all the params have the
163 * same type :-)
164 */
Glenn L McGrath649968c2001-02-10 14:26:48 +0000165static void depends_sort_visit(package_t **ordered, package_t *pkgs,
166 package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000167{
Glenn L McGrathc9005752001-02-10 02:05:24 +0000168 unsigned short i;
169
170 /* mark node as processing */
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000171 pkg->color = color_grey;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000172
173 /* visit each not-yet-visited node */
174 for (i = 0; i < pkg->requiredcount; i++)
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000175 if (pkg->requiredfor[i]->color == color_white)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000176 depends_sort_visit(ordered, pkgs, pkg->requiredfor[i]);
177
178#if 0
179 /* add it to the list */
Eric Andersenb50d7072001-02-15 19:50:11 +0000180 newnode = (struct package_t *)xmalloc(sizeof(struct package_t));
Glenn L McGrathc9005752001-02-10 02:05:24 +0000181 /* make a shallow copy */
182 *newnode = *pkg;
183 newnode->next = *ordered;
184 *ordered = newnode;
185#endif
Glenn L McGrath63106462001-02-11 01:40:23 +0000186
Glenn L McGrathc9005752001-02-10 02:05:24 +0000187 pkg->next = *ordered;
188 *ordered = pkg;
189
190 /* mark node as done */
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000191 pkg->color = color_black;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000192}
193
Glenn L McGrath649968c2001-02-10 14:26:48 +0000194static package_t *depends_sort(package_t *pkgs)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000195{
196 /* TODO: it needs to break cycles in the to-be-installed package
197 * graph... */
Glenn L McGrath649968c2001-02-10 14:26:48 +0000198 package_t *ordered = NULL;
199 package_t *pkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000200
Glenn L McGrath63106462001-02-11 01:40:23 +0000201 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrathaf8c65d2001-02-10 03:19:51 +0000202 pkg->color = color_white;
Glenn L McGrath63106462001-02-11 01:40:23 +0000203 }
204 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
205 if (pkg->color == color_white) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000206 depends_sort_visit(&ordered, pkgs, pkg);
Glenn L McGrath63106462001-02-11 01:40:23 +0000207 }
208 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000209
210 /* Leaks the old list... return the new one... */
211 return ordered;
212}
213
214
215/* resolve package dependencies --
216 * for each package in the list of packages to be installed, we parse its
217 * dependency info to determine if the dependent packages are either
218 * already installed, or are scheduled to be installed. If both tests fail
219 * than bail.
220 *
221 * The algorithm here is O(n^2*m) where n = number of packages to be
222 * installed and m is the # of dependencies per package. Not a terribly
223 * efficient algorithm, but given that at any one time you are unlikely
224 * to install a very large number of packages it doesn't really matter
225 */
Glenn L McGrath649968c2001-02-10 14:26:48 +0000226static package_t *depends_resolve(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000227{
Glenn L McGrath649968c2001-02-10 14:26:48 +0000228 package_t *pkg, *chk;
229 package_t dependpkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000230 char **dependsvec;
231 int i;
232 void *found;
233
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000234 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000235 dependsvec = depends_split(pkg->depends);
236 i = 0;
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000237 while (dependsvec[i] != 0) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000238 /* Check for dependencies; first look for installed packages */
239 dependpkg.package = dependsvec[i];
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000240 if (((found = tfind(&dependpkg, &status, package_compare)) == 0) ||
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000241 ((chk = *(package_t **)found) && (chk->state_flag & state_flag_ok) &&
242 (chk->state_status & state_status_installed))) {
Glenn L McGrath63106462001-02-11 01:40:23 +0000243
Glenn L McGrathc9005752001-02-10 02:05:24 +0000244 /* if it fails, we look through the list of packages we are going to
245 * install */
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000246 for (chk = pkgs; chk != 0; chk = chk->next) {
Glenn L McGrath63106462001-02-11 01:40:23 +0000247 if (strcmp(chk->package, dependsvec[i]) == 0 || (chk->provides &&
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000248 strncmp(chk->provides, dependsvec[i], strlen(dependsvec[i])) == 0)) {
249 if (chk->requiredcount >= DEPENDSMAX) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000250 error_msg("Too many dependencies for %s", chk->package);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000251 return 0;
252 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000253 if (chk != pkg) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000254 chk->requiredfor[chk->requiredcount++] = pkg;
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000255 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000256 break;
257 }
258 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000259 if (chk == 0) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000260 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 +0000261 return 0;
262 }
263 }
264 i++;
265 }
266 }
267
268 return depends_sort(pkgs);
269}
270#endif
271
272/* Status file handling routines
273 *
274 * This is a fairly minimalistic implementation. there are two main functions
275 * that are supported:
276 *
277 * 1) reading the entire status file:
278 * the status file is read into memory as a binary-tree, with just the
279 * package and status info preserved
280 *
281 * 2) merging the status file
282 * control info from (new) packages is merged into the status file,
283 * replacing any pre-existing entries. when a merge happens, status info
284 * read using the status_read function is written back to the status file
285 */
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000286static unsigned char status_parse(const char *line, const char **status_words)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000287{
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000288 unsigned char status_num;
289 int i = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000290
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000291 while (status_words[i] != 0) {
292 if (strncmp(line, status_words[i], strlen(status_words[i])) == 0) {
293 status_num = (char)i;
294 return(status_num);
Glenn L McGrath63106462001-02-11 01:40:23 +0000295 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000296 i++;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000297 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000298 /* parse error */
299 error_msg("Invalid status word");
300 return(0);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000301}
302
303/*
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000304 * Read the buffered control file and parse it,
Glenn L McGrathc9005752001-02-10 02:05:24 +0000305 * filling parsed fields into the package structure
306 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000307static int fill_package_struct(package_t *package, const char *package_buffer)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000308{
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000309 char *field = NULL;
310 int field_start = 0;
311 int field_length = 0;
Glenn L McGrathae1c7042001-04-16 10:26:46 +0000312
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000313 while ((field = read_package_field(&package_buffer[field_start])) != NULL) {
314 field_length = strlen(field);
315 field_start += (field_length + 1);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000316
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000317 if (strlen(field) == 0) {
318 printf("empty line: *this shouldnt happen i dont think*\n");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000319 break;
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000320 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000321
322 /* these are common to both installed and uninstalled packages */
323 if (strstr(field, "Package: ") == field) {
324 package->package = strdup(field + 9);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000325 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000326 else if (strstr(field, "Depends: ") == field) {
327 package->depends = strdup(field + 9);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000328 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000329 else if (strstr(field, "Provides: ") == field) {
330 package->provides = strdup(field + 10);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000331 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000332 /* This is specific to the Debian Installer. Ifdef? */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000333 else if (strstr(field, "installer-menu-item: ") == field) {
334 package->installer_menu_item = atoi(field + 21);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000335 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000336 else if (strstr(field, "Description: ") == field) {
337 package->description = strdup(field + 13);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000338 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000339 else if (strstr(field, "Priority: ") == field) {
340 package->priority = strdup(field + 10);
341 }
342 else if (strstr(field, "Section: ") == field) {
343 package->section = strdup(field + 9);
344 }
345 else if (strstr(field, "Installed-Size: ") == field) {
346 package->installed_size = strdup(field + 16);
347 }
348 else if (strstr(field, "Maintainer: ") == field) {
349 package->maintainer = strdup(field + 12);
350 }
351 else if (strstr(field, "Version: ") == field) {
352 package->version = strdup(field + 9);
353 }
354 else if (strstr(field, "Suggests: ") == field) {
355 package->suggests = strdup(field + 10);
356 }
357 else if (strstr(field, "Recommends: ") == field) {
358 package->recommends = strdup(field + 12);
359 }
360/* else if (strstr(field, "Conffiles: ") == field) {
361 package->conffiles = read_block(file);
362 package->conffiles = xcalloc(1, 1);
363 while ((field = strtok(NULL, "\n")) != NULL) {
364 package->long_description = xrealloc(package->conffiles,
365 strlen(package->conffiles) + strlen(field) + 1);
366 strcat(package->conffiles, field);
367 }
368 }
369*/
370 /* These are only in available file */
371 else if (strstr(field, "Architecture: ") == field) {
372 package->architecture = strdup(field + 14);
373 }
374 else if (strstr(field, "Filename: ") == field) {
375 package->filename = strdup(field + 10);
376 }
377 else if (strstr(field, "MD5sum ") == field) {
378 package->md5sum = strdup(field + 7);
379 }
380
381 /* This is only needed for status file */
382 if (strstr(field, "Status: ") == field) {
383 char *word_pointer;
384
385 word_pointer = strchr(field, ' ') + 1;
386 package->state_want = status_parse(word_pointer, state_words_want);
387 word_pointer = strchr(word_pointer, ' ') + 1;
388 package->state_flag = status_parse(word_pointer, state_words_flag);
389 word_pointer = strchr(word_pointer, ' ') + 1;
390 package->state_status = status_parse(word_pointer, state_words_status);
391 } else {
392 package->state_want = status_parse("purge", state_words_want);
393 package->state_flag = status_parse("ok", state_words_flag);
394 package->state_status = status_parse("not-installed", state_words_status);
395 }
396
397 free(field);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000398 }
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000399 return EXIT_SUCCESS;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000400}
401
Glenn L McGrathae1c7042001-04-16 10:26:46 +0000402extern void write_package(FILE *out_file, package_t *pkg)
403{
404 if (pkg->package) {
405 fprintf(out_file, "Package: %s\n", pkg->package);
406 }
407 if ((pkg->state_want != 0) || (pkg->state_flag != 0)|| (pkg->state_status != 0)) {
408 fprintf(out_file, "Status: %s %s %s\n",
409 state_words_want[pkg->state_want - 1],
410 state_words_flag[pkg->state_flag - 1],
411 state_words_status[pkg->state_status - 1]);
412 }
413 if (pkg->depends) {
414 fprintf(out_file, "Depends: %s\n", pkg->depends);
415 }
416 if (pkg->provides) {
417 fprintf(out_file, "Provides: %s\n", pkg->provides);
418 }
419 if (pkg->priority) {
420 fprintf(out_file, "Priority: %s\n", pkg->priority);
421 }
422 if (pkg->section) {
423 fprintf(out_file, "Section: %s\n", pkg->section);
424 }
425 if (pkg->section) {
426 fprintf(out_file, "Installed-Size: %s\n", pkg->installed_size);
427 }
428 if (pkg->maintainer) {
429 fprintf(out_file, "Maintainer: %s\n", pkg->maintainer);
430 }
431 if (pkg->source) {
432 fprintf(out_file, "Source: %s\n", pkg->source);
433 }
434 if (pkg->version) {
435 fprintf(out_file, "Version: %s\n", pkg->version);
436 }
437 if (pkg->pre_depends) {
438 fprintf(out_file, "Pre-depends: %s\n", pkg->pre_depends);
439 }
440 if (pkg->replaces) {
441 fprintf(out_file, "Replaces: %s\n", pkg->replaces);
442 }
443 if (pkg->recommends) {
444 fprintf(out_file, "Recommends: %s\n", pkg->recommends);
445 }
446 if (pkg->suggests) {
447 fprintf(out_file, "Suggests: %s\n", pkg->suggests);
448 }
449 if (pkg->conflicts) {
450 fprintf(out_file, "Conflicts: %s\n", pkg->conflicts);
451 }
452 if (pkg->conffiles) {
453 fprintf(out_file, "Conf-files: %s\n", pkg->conffiles);
454 }
455 if (pkg->architecture) {
456 fprintf(out_file, "Architecture: %s\n", pkg->architecture);
457 }
458 if (pkg->filename) {
459 fprintf(out_file, "Filename: %s\n", pkg->filename);
460 }
461 if (pkg->md5sum) {
462 fprintf(out_file, "MD5sum: %s\n", pkg->md5sum);
463 }
464 if (pkg->installer_menu_item) {
465 fprintf(out_file, "installer-main-menu %d\n", pkg->installer_menu_item);
466 }
467 if (pkg->description) {
468 fprintf(out_file, "Description: %s\n", pkg->description);
469 }
470 fputc('\n', out_file);
471 pkg = pkg->next;
472}
473
Glenn L McGrath649968c2001-02-10 14:26:48 +0000474static void *status_read(void)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000475{
476 FILE *f;
477 void *status = 0;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000478 package_t *m = 0, *p = 0, *t = 0;
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000479 char *package_control_buffer = NULL;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000480
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000481 if (getenv(udpkg_quiet) == NULL) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000482 printf("(Reading database...)\n");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000483 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000484
Eric Andersene5dfced2001-04-09 22:48:12 +0000485 if ((f = wfopen(statusfile, "r")) == NULL) {
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000486 return(NULL);
487 }
488
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000489 while ( (package_control_buffer = fgets_str(f, "\n\n")) != NULL) {
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000490 m = (package_t *)xcalloc(1, sizeof(package_t));
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000491 fill_package_struct(m, package_control_buffer);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000492 if (m->package) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000493 /*
494 * If there is an item in the tree by this name,
495 * it must be a virtual package; insert real
496 * package in preference.
497 */
498 tdelete(m, &status, package_compare);
499 tsearch(m, &status, package_compare);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000500 if (m->provides) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000501 /*
502 * A "Provides" triggers the insertion
503 * of a pseudo package into the status
504 * binary-tree.
505 */
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000506 p = (package_t *)xcalloc(1, sizeof(package_t));
507 p->package = xstrdup(m->provides);
Glenn L McGrath649968c2001-02-10 14:26:48 +0000508 t = *(package_t **)tsearch(p, &status, package_compare);
Glenn L McGrath63106462001-02-11 01:40:23 +0000509 if (t != p) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000510 free(p->package);
511 free(p);
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000512 } else {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000513 /*
514 * Pseudo package status is the
515 * same as the status of the
516 * package providing it
517 * FIXME: (not quite right, if 2
518 * packages of different statuses
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000519 * provide it).
520 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000521 t->state_want = m->state_want;
522 t->state_flag = m->state_flag;
523 t->state_status = m->state_status;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000524 }
525 }
526 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000527 else {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000528 free(m);
529 }
530 }
531 fclose(f);
532 return status;
533}
534
Glenn L McGrath649968c2001-02-10 14:26:48 +0000535static int status_merge(void *status, package_t *pkgs)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000536{
537 FILE *fin, *fout;
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000538 char *line = NULL;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000539 package_t *pkg = 0, *statpkg = 0;
540 package_t locpkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000541
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000542 if ((fout = wfopen(new_statusfile, "w")) == NULL) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000543 return 0;
544 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000545 if (getenv(udpkg_quiet) == NULL) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000546 printf("(Updating database...)\n");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000547 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000548
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000549 /*
550 * Dont use wfopen here, handle errors ourself
551 */
552 if ((fin = fopen(statusfile, "r")) != NULL) {
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000553 while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
Eric Andersenc1bdffe2001-04-26 15:56:47 +0000554 chomp(line); /* trim newline */
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000555 /* If we see a package header, find out if it's a package
556 * that we have processed. if so, we skip that block for
557 * now (write it at the end).
558 *
559 * we also look at packages in the status cache and update
560 * their status fields
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000561 */
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000562 if (strstr(line, "Package: ") == line) {
563 for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
564 pkg->package) != 0; pkg = pkg->next) ;
Glenn L McGrath63106462001-02-11 01:40:23 +0000565
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000566 locpkg.package = line + 9;
567 statpkg = tfind(&locpkg, &status, package_compare);
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000568
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000569 /* note: statpkg should be non-zero, unless the status
570 * file was changed while we are processing (no locking
571 * is currently done...
572 */
573 if (statpkg != 0) {
574 statpkg = *(package_t **)statpkg;
575 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000576 }
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000577 if (pkg != 0) {
578 continue;
579 }
580 if (strstr(line, "Status: ") == line && statpkg != 0) {
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000581 snprintf(line, sizeof(line), "Status: %s %s %s",
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000582 state_words_want[statpkg->state_want - 1],
583 state_words_flag[statpkg->state_flag - 1],
584 state_words_status[statpkg->state_status - 1]);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000585 }
Eric Andersene5dfced2001-04-09 22:48:12 +0000586 fprintf(fout, "%s\n", line);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000587 }
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000588 fclose(fin);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000589 }
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000590 free(line);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000591
592 // Print out packages we processed.
593 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrathae1c7042001-04-16 10:26:46 +0000594 write_package(fout, pkg);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000595 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000596 fclose(fout);
597
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000598 /*
599 * Its ok if renaming statusfile fails becasue it doesnt exist
600 */
601 if (rename(statusfile, bak_statusfile) == -1) {
602 struct stat stat_buf;
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000603 if (stat(statusfile, &stat_buf) == 0) {
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000604 error_msg("Couldnt create backup status file");
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000605 return(EXIT_FAILURE);
606 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000607 error_msg("No status file found, creating new one");
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000608 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000609
Glenn L McGrath13e9c7a2001-04-08 07:18:08 +0000610 if (rename(new_statusfile, statusfile) == -1) {
611 error_msg("Couldnt create status file");
612 return(EXIT_FAILURE);
613 }
614 return(EXIT_SUCCESS);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000615}
616
Glenn L McGrathc9005752001-02-10 02:05:24 +0000617static int is_file(const char *fn)
618{
619 struct stat statbuf;
620
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000621 if (stat(fn, &statbuf) < 0) {
622 return 0;
623 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000624 return S_ISREG(statbuf.st_mode);
625}
626
Glenn L McGrath649968c2001-02-10 14:26:48 +0000627static int dpkg_doconfigure(package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000628{
629 int r;
630 char postinst[1024];
631 char buf[1024];
Glenn L McGrath63106462001-02-11 01:40:23 +0000632
Glenn L McGrathc9005752001-02-10 02:05:24 +0000633 DPRINTF("Configuring %s\n", pkg->package);
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000634 pkg->state_status = 0;
Glenn L McGrath510f0dd2001-02-10 14:53:08 +0000635 snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package);
Glenn L McGrath63106462001-02-11 01:40:23 +0000636
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000637 if (is_file(postinst)) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000638 snprintf(buf, sizeof(buf), "%s configure", postinst);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000639 if ((r = do_system(buf)) != 0) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000640 error_msg("postinst exited with status %d\n", r);
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000641 pkg->state_status = state_status_halfconfigured;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000642 return 1;
643 }
644 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000645 pkg->state_status = state_status_installed;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000646
647 return 0;
648}
649
Glenn L McGrath649968c2001-02-10 14:26:48 +0000650static int dpkg_dounpack(package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000651{
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000652 FILE *out_stream;
653 char *info_prefix;
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000654 int status = TRUE;
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000655 int r = 0;
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 */
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000660 deb_extract(pkg->filename, stdout, (extract_data_tar_gz | extract_all_to_fs), "/", NULL);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000661
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000662 /* extract the control files */
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000663 info_prefix = (char *) malloc(strlen(pkg->package) + strlen(infodir) + 2 + 5 + 1);
664 sprintf(info_prefix, "%s/%s.", infodir, pkg->package);
Glenn L McGrath59e50f62001-07-11 03:30:11 +0000665 deb_extract(pkg->filename, stdout, (extract_control_tar_gz | extract_all_to_fs), info_prefix, NULL);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000666
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000667 /* Create the list file */
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000668 strcat(info_prefix, "list");
669 out_stream = wfopen(info_prefix, "w");
Glenn L McGrath59e50f62001-07-11 03:30:11 +0000670 deb_extract(pkg->filename, out_stream, (extract_data_tar_gz | extract_list), NULL, NULL);
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000671 fclose(out_stream);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000672
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000673 pkg->state_want = state_want_install;
674 pkg->state_flag = state_flag_ok;
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000675
676 if (status == TRUE) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000677 pkg->state_status = state_status_unpacked;
Glenn L McGrath63106462001-02-11 01:40:23 +0000678 } else {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000679 pkg->state_status = state_status_halfinstalled;
Glenn L McGrath63106462001-02-11 01:40:23 +0000680 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000681
Glenn L McGrathc9005752001-02-10 02:05:24 +0000682 return r;
683}
684
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000685/*
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000686 * Extract and parse the control file from control.tar.gz
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000687 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000688static int dpkg_read_control(package_t *pkg)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000689{
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000690 FILE *pkg_file;
691 char *control_buffer = NULL;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000692
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000693 if ((pkg_file = wfopen(pkg->filename, "r")) == NULL) {
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000694 return EXIT_FAILURE;
Glenn L McGrath63106462001-02-11 01:40:23 +0000695 }
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000696 control_buffer = deb_extract(pkg->filename, stdout, (extract_control_tar_gz | extract_one_to_buffer), NULL, "./control");
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000697 fill_package_struct(pkg, control_buffer);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000698 return EXIT_SUCCESS;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000699}
700
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000701static int dpkg_unpack(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000702{
703 int r = 0;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000704 package_t *pkg;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000705
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000706 for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000707 dpkg_read_control(pkg);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000708 if ((r = dpkg_dounpack(pkg)) != 0 ) {
709 break;
710 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000711 }
712 status_merge(status, pkgs);
Glenn L McGrath63106462001-02-11 01:40:23 +0000713
Glenn L McGrathc9005752001-02-10 02:05:24 +0000714 return r;
715}
716
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000717static int dpkg_configure(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000718{
719 int r = 0;
720 void *found;
Glenn L McGrath649968c2001-02-10 14:26:48 +0000721 package_t *pkg;
Glenn L McGrath63106462001-02-11 01:40:23 +0000722
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000723 for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000724 found = tfind(pkg, &status, package_compare);
Glenn L McGrath63106462001-02-11 01:40:23 +0000725
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000726 if (found == 0) {
Eric Andersene5dfced2001-04-09 22:48:12 +0000727 error_msg("Trying to configure %s, but it is not installed", pkg->package);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000728 r = 1;
Glenn L McGrath63106462001-02-11 01:40:23 +0000729 }
730 /* configure the package listed in the status file;
731 * not pkg, as we have info only for the latter
732 */
733 else {
Glenn L McGrath649968c2001-02-10 14:26:48 +0000734 r = dpkg_doconfigure(*(package_t **)found);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000735 }
736 }
737 status_merge(status, 0);
Glenn L McGrath63106462001-02-11 01:40:23 +0000738
Glenn L McGrathc9005752001-02-10 02:05:24 +0000739 return r;
740}
741
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000742static int dpkg_install(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000743{
Glenn L McGrath649968c2001-02-10 14:26:48 +0000744 package_t *p, *ordered = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000745
Glenn L McGrathc9005752001-02-10 02:05:24 +0000746 /* Stage 1: parse all the control information */
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000747 for (p = pkgs; p != 0; p = p->next) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000748 dpkg_read_control(p);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000749 }
750
Glenn L McGrathc9005752001-02-10 02:05:24 +0000751 /* Stage 2: resolve dependencies */
752#ifdef DODEPENDS
753 ordered = depends_resolve(pkgs, status);
754#else
755 ordered = pkgs;
756#endif
757
758 /* Stage 3: install */
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000759 for (p = ordered; p != 0; p = p->next) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000760 p->state_want = state_want_install;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000761
762 /* for now the flag is always set to ok... this is probably
763 * not what we want
764 */
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000765 p->state_flag = state_flag_ok;
Glenn L McGrathc9005752001-02-10 02:05:24 +0000766
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000767 DPRINTF("Installing %s\n", p->package);
768 if (dpkg_dounpack(p) != 0) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000769 perror_msg(p->filename);
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000770 }
Glenn L McGrath305fdfa2001-04-08 13:27:39 +0000771
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000772 if (dpkg_doconfigure(p) != 0) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000773 perror_msg(p->filename);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000774 }
775 }
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000776
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000777 if (ordered != 0) {
Glenn L McGrathc9005752001-02-10 02:05:24 +0000778 status_merge(status, pkgs);
Glenn L McGrath0c9d77c2001-02-11 00:17:22 +0000779 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000780
Glenn L McGrathc9005752001-02-10 02:05:24 +0000781 return 0;
782}
783
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000784/*
785 * Not implemented yet
786 *
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000787static int dpkg_remove(package_t *pkgs, void *status)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000788{
Glenn L McGrath649968c2001-02-10 14:26:48 +0000789 package_t *p;
Glenn L McGrath63106462001-02-11 01:40:23 +0000790
Glenn L McGrathc9005752001-02-10 02:05:24 +0000791 for (p = pkgs; p != 0; p = p->next)
792 {
793 }
794 status_merge(status, 0);
Glenn L McGrath63106462001-02-11 01:40:23 +0000795
Glenn L McGrathc9005752001-02-10 02:05:24 +0000796 return 0;
797}
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000798*/
Glenn L McGrathc9005752001-02-10 02:05:24 +0000799
Glenn L McGrath649968c2001-02-10 14:26:48 +0000800extern int dpkg_main(int argc, char **argv)
Glenn L McGrathc9005752001-02-10 02:05:24 +0000801{
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000802 const int arg_install = 1;
803 const int arg_unpack = 2;
804 const int arg_configure = 4;
805
Glenn L McGrath649968c2001-02-10 14:26:48 +0000806 package_t *p, *packages = NULL;
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000807 void *status = NULL;
Eric Andersen5a9d4412001-05-24 14:16:28 +0000808 int opt = 0;
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000809 int optflag = 0;
Glenn L McGrath63106462001-02-11 01:40:23 +0000810
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000811 while ((opt = getopt(argc, argv, "iruc")) != -1) {
812 switch (opt) {
813 case 'i':
814 optflag |= arg_install;
815 break;
816 case 'u':
817 optflag |= arg_unpack;
818 break;
819 case 'c':
820 optflag |= arg_configure;
821 break;
822 default:
823 show_usage();
824 }
Glenn L McGrathc9005752001-02-10 02:05:24 +0000825 }
Glenn L McGrath63106462001-02-11 01:40:23 +0000826
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000827 while (optind < argc) {
828 p = (package_t *) xcalloc(1, sizeof(package_t));
829 if (optflag & arg_configure) {
830 p->package = xstrdup(argv[optind]);
831 } else {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000832 p->filename = xstrdup(argv[optind]);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000833 }
834 p->next = packages;
835 packages = p;
836
837 optind++;
838 }
839
Eric Andersen24982c52001-06-25 19:31:48 +0000840 make_directory((char *)infodir, S_IRWXU, FILEUTILS_RECUR);
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000841
Glenn L McGrath3af1f882001-02-12 11:33:09 +0000842 status = status_read();
843
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000844 if (optflag & arg_install) {
845 return dpkg_install(packages, status);
Glenn L McGrathc9005752001-02-10 02:05:24 +0000846 }
Glenn L McGrath0e757a22001-04-08 05:27:18 +0000847 else if (optflag & arg_unpack) {
848 return dpkg_unpack(packages, status);
849 }
850 else if (optflag & arg_configure) {
851 return dpkg_configure(packages, status);
852 }
853 return(EXIT_FAILURE);
Eric Andersen67991cf2001-02-14 21:23:06 +0000854}