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. |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 15 | * |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 16 | */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 17 | #include <fcntl.h> |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 18 | #include <stdlib.h> |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 19 | #include <string.h> |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 20 | #include <unistd.h> |
Glenn L McGrath | d22e560 | 2001-04-11 02:12:08 +0000 | [diff] [blame] | 21 | #include <getopt.h> |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 22 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 23 | #include "unarchive.h" |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 24 | #include "busybox.h" |
| 25 | |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 26 | #define DPKG_DEB_OPT_CONTENTS 1 |
| 27 | #define DPKG_DEB_OPT_CONTROL 2 |
| 28 | #define DPKG_DEB_OPT_FIELD 4 |
| 29 | #define DPKG_DEB_OPT_EXTRACT 8 |
| 30 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16 |
| 31 | |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 32 | extern int dpkg_deb_main(int argc, char **argv) |
| 33 | { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 34 | archive_handle_t *ar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 35 | archive_handle_t *tar_archive; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 36 | llist_t *control_tar_llist = NULL; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 37 | unsigned long opt; |
| 38 | char *extract_dir = NULL; |
| 39 | short argcount = 1; |
| 40 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 41 | /* Setup the tar archive handle */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 42 | tar_archive = init_handle(); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 43 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 44 | /* Setup an ar archive handle that refers to the gzip sub archive */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 45 | ar_archive = init_handle(); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 46 | ar_archive->sub_archive = tar_archive; |
| 47 | ar_archive->filter = filter_accept_list_reassign; |
| 48 | |
| 49 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 50 | ar_archive->accept = llist_add_to(NULL, "data.tar.gz"); |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 51 | control_tar_llist = llist_add_to(NULL, "control.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 52 | #endif |
| 53 | |
| 54 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 55 | ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2"); |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 56 | control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 57 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 58 | |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 59 | bb_opt_complementaly = "c~efXx:e~cfXx:f~ceXx:X~cefx:x~cefX"; |
| 60 | opt = bb_getopt_ulflags(argc, argv, "cefXx"); |
| 61 | |
| 62 | if (opt & DPKG_DEB_OPT_CONTENTS) { |
| 63 | tar_archive->action_header = header_verbose_list; |
| 64 | } |
| 65 | if (opt & DPKG_DEB_OPT_CONTROL) { |
| 66 | ar_archive->accept = control_tar_llist; |
| 67 | tar_archive->action_data = data_extract_all; |
| 68 | if (optind + 1 == argc) { |
| 69 | extract_dir = "./DEBIAN"; |
| 70 | } else { |
| 71 | argcount++; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 74 | if (opt & DPKG_DEB_OPT_FIELD) { |
| 75 | /* Print the entire control file |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 76 | * it should accept a second argument which specifies a |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 77 | * specific field to print */ |
| 78 | ar_archive->accept = control_tar_llist; |
| 79 | tar_archive->accept = llist_add_to(NULL, "./control");; |
| 80 | tar_archive->filter = filter_accept_list; |
| 81 | tar_archive->action_data = data_extract_to_stdout; |
| 82 | } |
| 83 | if (opt & DPKG_DEB_OPT_EXTRACT) { |
| 84 | tar_archive->action_header = header_list; |
| 85 | } |
| 86 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { |
| 87 | tar_archive->action_data = data_extract_all; |
| 88 | argcount = 2; |
| 89 | } |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 90 | |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 91 | if ((optind + argcount != argc) || (opt & 0x80000000UL)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 92 | bb_show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 93 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 94 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 95 | tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 96 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 97 | /* Workout where to extract the files */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 98 | /* 2nd argument is a dir name */ |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 99 | if (argv[optind]) { |
| 100 | extract_dir = argv[optind]; |
| 101 | } |
| 102 | if (extract_dir) { |
| 103 | mkdir(extract_dir, 0777); |
| 104 | chdir(extract_dir); |
| 105 | } |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 106 | unpack_ar_archive(ar_archive); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 107 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 108 | /* Cleanup */ |
| 109 | close (ar_archive->src_fd); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 110 | |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 111 | return(EXIT_SUCCESS); |
| 112 | } |