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 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 6 | */ |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 7 | |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 8 | //config:config DPKG_DEB |
| 9 | //config: bool "dpkg_deb" |
| 10 | //config: default n |
| 11 | //config: select FEATURE_SEAMLESS_GZ |
| 12 | //config: help |
| 13 | //config: dpkg-deb unpacks and provides information about Debian archives. |
| 14 | //config: |
| 15 | //config: This implementation of dpkg-deb cannot pack archives. |
| 16 | //config: |
| 17 | //config: Unless you have a specific application which requires dpkg-deb, |
| 18 | //config: say N here. |
| 19 | //config: |
| 20 | //config:config FEATURE_DPKG_DEB_EXTRACT_ONLY |
| 21 | //config: bool "Extract only (-x)" |
| 22 | //config: default n |
| 23 | //config: depends on DPKG_DEB |
| 24 | //config: help |
| 25 | //config: This reduces dpkg-deb to the equivalent of |
| 26 | //config: "ar -p <deb> data.tar.gz | tar -zx". However it saves space as none |
| 27 | //config: of the extra dpkg-deb, ar or tar options are needed, they are linked |
| 28 | //config: to internally. |
| 29 | |
Denys Vlasenko | 36184a4 | 2013-11-14 09:54:24 +0100 | [diff] [blame] | 30 | //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 31 | //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o |
| 32 | |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 33 | //usage:#define dpkg_deb_trivial_usage |
Daniel Borca | df0d2cd | 2013-11-28 12:38:25 +0100 | [diff] [blame] | 34 | //usage: "[-cefxX] FILE [argument]" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 35 | //usage:#define dpkg_deb_full_usage "\n\n" |
| 36 | //usage: "Perform actions on Debian packages (.debs)\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 37 | //usage: "\n -c List contents of filesystem tree" |
| 38 | //usage: "\n -e Extract control files to [argument] directory" |
| 39 | //usage: "\n -f Display control field name starting with [argument]" |
| 40 | //usage: "\n -x Extract packages filesystem tree to directory" |
| 41 | //usage: "\n -X Verbose extract" |
| 42 | //usage: |
| 43 | //usage:#define dpkg_deb_example_usage |
| 44 | //usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n" |
| 45 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 46 | #include "libbb.h" |
Denys Vlasenko | d184a72 | 2011-09-22 12:45:14 +0200 | [diff] [blame] | 47 | #include "bb_archive.h" |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 48 | |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 49 | #define DPKG_DEB_OPT_CONTENTS 1 |
| 50 | #define DPKG_DEB_OPT_CONTROL 2 |
| 51 | #define DPKG_DEB_OPT_FIELD 4 |
| 52 | #define DPKG_DEB_OPT_EXTRACT 8 |
| 53 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16 |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 54 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 55 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 56 | int dpkg_deb_main(int argc, char **argv) |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 57 | { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 58 | archive_handle_t *ar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 59 | archive_handle_t *tar_archive; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 60 | llist_t *control_tar_llist = NULL; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 61 | unsigned opt; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 62 | const char *extract_dir; |
| 63 | int need_args; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 64 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 65 | /* Setup the tar archive handle */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 66 | tar_archive = init_handle(); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 67 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 68 | /* 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] | 69 | ar_archive = init_handle(); |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 70 | ar_archive->dpkg__sub_archive = tar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 71 | ar_archive->filter = filter_accept_list_reassign; |
| 72 | |
Denys Vlasenko | 08f9ffc | 2015-01-30 15:15:38 +0100 | [diff] [blame] | 73 | llist_add_to(&ar_archive->accept, (char*)"data.tar"); |
| 74 | llist_add_to(&control_tar_llist, (char*)"control.tar"); |
Denis Vlasenko | e9ad84d | 2008-08-05 13:10:34 +0000 | [diff] [blame] | 75 | #if ENABLE_FEATURE_SEAMLESS_GZ |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 76 | llist_add_to(&ar_archive->accept, (char*)"data.tar.gz"); |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 77 | llist_add_to(&control_tar_llist, (char*)"control.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 78 | #endif |
Denis Vlasenko | e9ad84d | 2008-08-05 13:10:34 +0000 | [diff] [blame] | 79 | #if ENABLE_FEATURE_SEAMLESS_BZ2 |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 80 | llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2"); |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 81 | llist_add_to(&control_tar_llist, (char*)"control.tar.bz2"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 82 | #endif |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 83 | #if ENABLE_FEATURE_SEAMLESS_LZMA |
| 84 | llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma"); |
| 85 | llist_add_to(&control_tar_llist, (char*)"control.tar.lzma"); |
| 86 | #endif |
Denys Vlasenko | 08f9ffc | 2015-01-30 15:15:38 +0100 | [diff] [blame] | 87 | #if ENABLE_FEATURE_SEAMLESS_XZ |
| 88 | llist_add_to(&ar_archive->accept, (char*)"data.tar.xz"); |
| 89 | llist_add_to(&control_tar_llist, (char*)"control.tar.xz"); |
| 90 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 91 | |
Denis Vlasenko | e7fca51 | 2007-11-10 01:32:18 +0000 | [diff] [blame] | 92 | opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 93 | opt = getopt32(argv, "cefXx"); |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 94 | argv += optind; |
| 95 | argc -= optind; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 96 | |
| 97 | if (opt & DPKG_DEB_OPT_CONTENTS) { |
| 98 | tar_archive->action_header = header_verbose_list; |
| 99 | } |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 100 | extract_dir = NULL; |
| 101 | need_args = 1; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 102 | if (opt & DPKG_DEB_OPT_CONTROL) { |
| 103 | ar_archive->accept = control_tar_llist; |
| 104 | tar_archive->action_data = data_extract_all; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 105 | if (1 == argc) { |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 106 | extract_dir = "./DEBIAN"; |
| 107 | } else { |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 108 | need_args++; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 111 | if (opt & DPKG_DEB_OPT_FIELD) { |
| 112 | /* Print the entire control file |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 113 | * it should accept a second argument which specifies a |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 114 | * specific field to print */ |
| 115 | ar_archive->accept = control_tar_llist; |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 116 | llist_add_to(&(tar_archive->accept), (char*)"./control"); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 117 | tar_archive->filter = filter_accept_list; |
| 118 | tar_archive->action_data = data_extract_to_stdout; |
| 119 | } |
| 120 | if (opt & DPKG_DEB_OPT_EXTRACT) { |
| 121 | tar_archive->action_header = header_list; |
| 122 | } |
| 123 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { |
| 124 | tar_archive->action_data = data_extract_all; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 125 | need_args = 2; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 126 | } |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 127 | |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 128 | if (need_args != argc) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 129 | bb_show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 130 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 131 | |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 132 | tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 133 | |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 134 | /* Work out where to extract the files */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 135 | /* 2nd argument is a dir name */ |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 136 | if (argv[1]) { |
| 137 | extract_dir = argv[1]; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 138 | } |
| 139 | if (extract_dir) { |
Bernhard Reutner-Fischer | 44e216f | 2006-06-10 11:29:44 +0000 | [diff] [blame] | 140 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 141 | xchdir(extract_dir); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 142 | } |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 143 | |
| 144 | /* Do it */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 145 | unpack_ar_archive(ar_archive); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 146 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 147 | /* Cleanup */ |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 148 | if (ENABLE_FEATURE_CLEAN_UP) |
| 149 | close(ar_archive->src_fd); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 150 | |
Denis Vlasenko | 079f8af | 2006-11-27 16:49:31 +0000 | [diff] [blame] | 151 | return EXIT_SUCCESS; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 152 | } |