Bernhard Reutner-Fischer | d9cf7ac | 2006-04-12 18:39:58 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 2 | /* |
Bernhard Reutner-Fischer | d9cf7ac | 2006-04-12 18:39:58 +0000 | [diff] [blame] | 3 | * dpkg-deb packs, unpacks and provides information about Debian archives. |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 4 | * |
Bernhard Reutner-Fischer | d9cf7ac | 2006-04-12 18:39:58 +0000 | [diff] [blame] | 5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 6 | */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 7 | #include <fcntl.h> |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 8 | #include <stdlib.h> |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 9 | #include <string.h> |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 10 | #include <unistd.h> |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 11 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 12 | #include "unarchive.h" |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 13 | #include "busybox.h" |
| 14 | |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 15 | #define DPKG_DEB_OPT_CONTENTS 1 |
| 16 | #define DPKG_DEB_OPT_CONTROL 2 |
| 17 | #define DPKG_DEB_OPT_FIELD 4 |
| 18 | #define DPKG_DEB_OPT_EXTRACT 8 |
| 19 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16 |
| 20 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 21 | int dpkg_deb_main(int argc, char **argv) |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 22 | { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 23 | archive_handle_t *ar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 24 | archive_handle_t *tar_archive; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 25 | llist_t *control_tar_llist = NULL; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 26 | unsigned long opt; |
| 27 | char *extract_dir = NULL; |
| 28 | short argcount = 1; |
| 29 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 30 | /* Setup the tar archive handle */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 31 | tar_archive = init_handle(); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 32 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 33 | /* 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] | 34 | ar_archive = init_handle(); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 35 | ar_archive->sub_archive = tar_archive; |
| 36 | ar_archive->filter = filter_accept_list_reassign; |
| 37 | |
| 38 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 39 | ar_archive->accept = llist_add_to(NULL, "data.tar.gz"); |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 40 | control_tar_llist = llist_add_to(NULL, "control.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
| 43 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 44 | 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] | 45 | 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] | 46 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 47 | |
"Vladimir N. Oleynik" | f704b27 | 2005-10-14 09:56:52 +0000 | [diff] [blame] | 48 | bb_opt_complementally = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 49 | opt = bb_getopt_ulflags(argc, argv, "cefXx"); |
| 50 | |
| 51 | if (opt & DPKG_DEB_OPT_CONTENTS) { |
| 52 | tar_archive->action_header = header_verbose_list; |
| 53 | } |
| 54 | if (opt & DPKG_DEB_OPT_CONTROL) { |
| 55 | ar_archive->accept = control_tar_llist; |
| 56 | tar_archive->action_data = data_extract_all; |
| 57 | if (optind + 1 == argc) { |
| 58 | extract_dir = "./DEBIAN"; |
| 59 | } else { |
| 60 | argcount++; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 63 | if (opt & DPKG_DEB_OPT_FIELD) { |
| 64 | /* Print the entire control file |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 65 | * it should accept a second argument which specifies a |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 66 | * specific field to print */ |
| 67 | ar_archive->accept = control_tar_llist; |
Bernhard Reutner-Fischer | 0b42a6a | 2005-10-07 11:34:50 +0000 | [diff] [blame] | 68 | tar_archive->accept = llist_add_to(NULL, "./control"); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 69 | tar_archive->filter = filter_accept_list; |
| 70 | tar_archive->action_data = data_extract_to_stdout; |
| 71 | } |
| 72 | if (opt & DPKG_DEB_OPT_EXTRACT) { |
| 73 | tar_archive->action_header = header_list; |
| 74 | } |
| 75 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { |
| 76 | tar_archive->action_data = data_extract_all; |
| 77 | argcount = 2; |
| 78 | } |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 79 | |
"Vladimir N. Oleynik" | 27421a1 | 2005-09-05 14:46:07 +0000 | [diff] [blame] | 80 | if ((optind + argcount) != argc) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 81 | bb_show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 82 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 83 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 84 | 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] | 85 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 86 | /* Workout where to extract the files */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 87 | /* 2nd argument is a dir name */ |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 88 | if (argv[optind]) { |
| 89 | extract_dir = argv[optind]; |
| 90 | } |
| 91 | if (extract_dir) { |
| 92 | mkdir(extract_dir, 0777); |
Bernhard Reutner-Fischer | d9cf7ac | 2006-04-12 18:39:58 +0000 | [diff] [blame] | 93 | chdir(extract_dir); /* error check? */ |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 94 | } |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 95 | unpack_ar_archive(ar_archive); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 96 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 97 | /* Cleanup */ |
| 98 | close (ar_archive->src_fd); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 99 | |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 100 | return(EXIT_SUCCESS); |
| 101 | } |