Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 1 | /* |
| 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 McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 18 | #include <string.h> |
Glenn L McGrath | d22e560 | 2001-04-11 02:12:08 +0000 | [diff] [blame] | 19 | #include <getopt.h> |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 20 | #include "busybox.h" |
| 21 | |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 22 | extern int dpkg_deb_main(int argc, char **argv) |
| 23 | { |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 24 | char *prefix = NULL; |
| 25 | char *filename = NULL; |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 26 | char *output_buffer = NULL; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 27 | int opt = 0; |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 28 | int arg_type = 0; |
Glenn L McGrath | 2e6d3cf | 2001-06-24 12:36:54 +0000 | [diff] [blame] | 29 | int deb_extract_funct = extract_create_leading_dirs | extract_unconditional; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 30 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 31 | const int arg_type_prefix = 1; |
| 32 | const int arg_type_field = 2; |
| 33 | const int arg_type_filename = 4; |
| 34 | // const int arg_type_un_ar_gz = 8; |
| 35 | |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 36 | while ((opt = getopt(argc, argv, "ceftXxI")) != -1) { |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 37 | switch (opt) { |
| 38 | case 'c': |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 39 | deb_extract_funct |= extract_data_tar_gz; |
| 40 | deb_extract_funct |= extract_verbose_list; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 41 | break; |
| 42 | case 'e': |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 43 | arg_type = arg_type_prefix; |
| 44 | deb_extract_funct |= extract_control_tar_gz; |
| 45 | deb_extract_funct |= extract_all_to_fs; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 46 | break; |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 47 | case 'f': |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 48 | arg_type = arg_type_field; |
| 49 | deb_extract_funct |= extract_control_tar_gz; |
| 50 | deb_extract_funct |= extract_one_to_buffer; |
| 51 | filename = xstrdup("./control"); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 52 | break; |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 53 | case 't': /* --fsys-tarfile, i just made up this short name */ |
| 54 | /* Integrate the functionality needed with some code from ar.c */ |
| 55 | error_msg_and_die("Option disabled"); |
| 56 | // arg_type = arg_type_un_ar_gz; |
Glenn L McGrath | 3e2ab88 | 2001-04-12 13:49:09 +0000 | [diff] [blame] | 57 | break; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 58 | case 'X': |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 59 | arg_type = arg_type_prefix; |
| 60 | deb_extract_funct |= extract_data_tar_gz; |
| 61 | deb_extract_funct |= extract_all_to_fs; |
| 62 | deb_extract_funct |= extract_list; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 63 | case 'x': |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 64 | arg_type = arg_type_prefix; |
| 65 | deb_extract_funct |= extract_data_tar_gz; |
| 66 | deb_extract_funct |= extract_all_to_fs; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 67 | break; |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 68 | case 'I': |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 69 | arg_type = arg_type_filename; |
| 70 | deb_extract_funct |= extract_control_tar_gz; |
| 71 | deb_extract_funct |= extract_one_to_buffer; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 72 | break; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 73 | default: |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame] | 74 | show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 78 | if (optind == argc) { |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame] | 79 | show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 80 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 81 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 82 | /* Workout where to extract the files */ |
| 83 | if (arg_type == arg_type_prefix) { |
| 84 | /* argument is a dir name */ |
| 85 | if ((optind + 1) == argc ) { |
| 86 | prefix = xstrdup("./DEBIAN/"); |
| 87 | } else { |
| 88 | prefix = (char *) xmalloc(strlen(argv[optind + 1]) + 2); |
| 89 | strcpy(prefix, argv[optind + 1]); |
| 90 | /* Make sure the directory has a trailing '/' */ |
| 91 | if (last_char_is(prefix, '/') == NULL) { |
| 92 | strcat(prefix, "/"); |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 93 | } |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 94 | } |
Glenn L McGrath | 8f5b63e | 2001-06-22 09:22:06 +0000 | [diff] [blame] | 95 | mkdir(prefix, 0777); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 96 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 97 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 98 | if (arg_type == arg_type_filename) { |
| 99 | if ((optind + 1) != argc) { |
| 100 | filename = xstrdup(argv[optind + 1]); |
| 101 | } else { |
| 102 | error_msg_and_die("-I currently requires a filename to be specified"); |
| 103 | } |
| 104 | } |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 105 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 106 | output_buffer = deb_extract(argv[optind], stdout, deb_extract_funct, prefix, filename); |
| 107 | |
| 108 | if ((arg_type == arg_type_filename) && (output_buffer != NULL)) { |
| 109 | puts(output_buffer); |
| 110 | } |
| 111 | else if (arg_type == arg_type_field) { |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 112 | char *field = NULL; |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 113 | int field_start = 0; |
| 114 | |
| 115 | while ((field = read_package_field(&output_buffer[field_start])) != NULL) { |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 116 | field_start += (strlen(field) + 1); |
| 117 | if (strstr(field, argv[optind + 1]) == field) { |
| 118 | puts(field + strlen(argv[optind + 1]) + 2); |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 119 | } |
| 120 | free(field); |
| 121 | } |
| 122 | } |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 123 | |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 124 | return(EXIT_SUCCESS); |
| 125 | } |