blob: 29692f7d71b07fdbd524a42e5a33194bc57dc107 [file] [log] [blame]
Glenn L McGrath58a40852001-01-02 23:49:26 +00001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
Glenn L McGrath58a40852001-01-02 23:49:26 +000017#include <stdlib.h>
Glenn L McGrath33431eb2001-04-16 04:52:19 +000018#include <string.h>
Glenn L McGrathd22e5602001-04-11 02:12:08 +000019#include <getopt.h>
Glenn L McGrathef0eab52001-10-25 14:49:48 +000020#include "unarchive.h"
Glenn L McGrath58a40852001-01-02 23:49:26 +000021#include "busybox.h"
22
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000023extern int dpkg_deb_main(int argc, char **argv)
24{
Glenn L McGrath9aff9032001-06-13 07:26:39 +000025 char *prefix = NULL;
26 char *filename = NULL;
Glenn L McGrath33431eb2001-04-16 04:52:19 +000027 char *output_buffer = NULL;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000028 int opt = 0;
Glenn L McGrath9aff9032001-06-13 07:26:39 +000029 int arg_type = 0;
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000030 int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;
Glenn L McGrath58a40852001-01-02 23:49:26 +000031
Glenn L McGrath9aff9032001-06-13 07:26:39 +000032 const int arg_type_prefix = 1;
33 const int arg_type_field = 2;
34 const int arg_type_filename = 4;
35// const int arg_type_un_ar_gz = 8;
36
Glenn L McGrath445fb952001-04-13 04:02:57 +000037 while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
Glenn L McGrath58a40852001-01-02 23:49:26 +000038 switch (opt) {
39 case 'c':
Glenn L McGrath9aff9032001-06-13 07:26:39 +000040 deb_extract_funct |= extract_data_tar_gz;
41 deb_extract_funct |= extract_verbose_list;
Glenn L McGrath58a40852001-01-02 23:49:26 +000042 break;
43 case 'e':
Glenn L McGrath9aff9032001-06-13 07:26:39 +000044 arg_type = arg_type_prefix;
45 deb_extract_funct |= extract_control_tar_gz;
46 deb_extract_funct |= extract_all_to_fs;
Glenn L McGrath58a40852001-01-02 23:49:26 +000047 break;
Glenn L McGrath445fb952001-04-13 04:02:57 +000048 case 'f':
Glenn L McGrath9aff9032001-06-13 07:26:39 +000049 arg_type = arg_type_field;
50 deb_extract_funct |= extract_control_tar_gz;
51 deb_extract_funct |= extract_one_to_buffer;
52 filename = xstrdup("./control");
Glenn L McGrath445fb952001-04-13 04:02:57 +000053 break;
Glenn L McGrath9aff9032001-06-13 07:26:39 +000054 case 't': /* --fsys-tarfile, i just made up this short name */
55 /* Integrate the functionality needed with some code from ar.c */
56 error_msg_and_die("Option disabled");
57// arg_type = arg_type_un_ar_gz;
Glenn L McGrath3e2ab882001-04-12 13:49:09 +000058 break;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000059 case 'X':
Glenn L McGrath9aff9032001-06-13 07:26:39 +000060 arg_type = arg_type_prefix;
61 deb_extract_funct |= extract_data_tar_gz;
62 deb_extract_funct |= extract_all_to_fs;
63 deb_extract_funct |= extract_list;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000064 case 'x':
Glenn L McGrath9aff9032001-06-13 07:26:39 +000065 arg_type = arg_type_prefix;
66 deb_extract_funct |= extract_data_tar_gz;
67 deb_extract_funct |= extract_all_to_fs;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000068 break;
Glenn L McGrath445fb952001-04-13 04:02:57 +000069 case 'I':
Glenn L McGrath9aff9032001-06-13 07:26:39 +000070 arg_type = arg_type_filename;
71 deb_extract_funct |= extract_control_tar_gz;
72 deb_extract_funct |= extract_one_to_buffer;
Glenn L McGrath58a40852001-01-02 23:49:26 +000073 break;
Glenn L McGrath58a40852001-01-02 23:49:26 +000074 default:
Eric Andersen67991cf2001-02-14 21:23:06 +000075 show_usage();
Glenn L McGrath58a40852001-01-02 23:49:26 +000076 }
77 }
78
Glenn L McGrath6785b512001-04-12 11:48:02 +000079 if (optind == argc) {
Eric Andersen67991cf2001-02-14 21:23:06 +000080 show_usage();
Glenn L McGrath58a40852001-01-02 23:49:26 +000081 }
Glenn L McGrath6785b512001-04-12 11:48:02 +000082
Glenn L McGrath9aff9032001-06-13 07:26:39 +000083 /* Workout where to extract the files */
84 if (arg_type == arg_type_prefix) {
85 /* argument is a dir name */
86 if ((optind + 1) == argc ) {
87 prefix = xstrdup("./DEBIAN/");
88 } else {
89 prefix = (char *) xmalloc(strlen(argv[optind + 1]) + 2);
90 strcpy(prefix, argv[optind + 1]);
91 /* Make sure the directory has a trailing '/' */
92 if (last_char_is(prefix, '/') == NULL) {
93 strcat(prefix, "/");
Glenn L McGrath359c1062001-04-12 10:19:08 +000094 }
Glenn L McGrath9aff9032001-06-13 07:26:39 +000095 }
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000096 mkdir(prefix, 0777);
Glenn L McGrath58a40852001-01-02 23:49:26 +000097 }
Glenn L McGrath6785b512001-04-12 11:48:02 +000098
Glenn L McGrath9aff9032001-06-13 07:26:39 +000099 if (arg_type == arg_type_filename) {
100 if ((optind + 1) != argc) {
101 filename = xstrdup(argv[optind + 1]);
102 } else {
103 error_msg_and_die("-I currently requires a filename to be specified");
104 }
105 }
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000106
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000107 output_buffer = deb_extract(argv[optind], stdout, deb_extract_funct, prefix, filename);
108
109 if ((arg_type == arg_type_filename) && (output_buffer != NULL)) {
110 puts(output_buffer);
111 }
112 else if (arg_type == arg_type_field) {
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000113 char *field = NULL;
Glenn L McGrathc3fbec72001-07-18 15:47:21 +0000114 char *name;
115 char *value;
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000116 int field_start = 0;
117
Glenn L McGrathc3fbec72001-07-18 15:47:21 +0000118 while (1) {
119 field_start += read_package_field(&output_buffer[field_start], &name, &value);
120 if (name == NULL) {
121 break;
122 }
123 if (strcmp(name, argv[optind + 1]) == 0) {
124 puts(value);
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000125 }
126 free(field);
127 }
128 }
Glenn L McGrath445fb952001-04-13 04:02:57 +0000129
Glenn L McGrath58a40852001-01-02 23:49:26 +0000130 return(EXIT_SUCCESS);
131}