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" |
Denys Vlasenko | ce3a98a | 2016-12-23 13:52:53 +0100 | [diff] [blame] | 10 | //config: default y |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 11 | //config: select FEATURE_SEAMLESS_GZ |
| 12 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 13 | //config: dpkg-deb unpacks and provides information about Debian archives. |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 14 | //config: |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 15 | //config: This implementation of dpkg-deb cannot pack archives. |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 16 | //config: |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 17 | //config: Unless you have a specific application which requires dpkg-deb, |
| 18 | //config: say N here. |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 19 | |
Denys Vlasenko | 36184a4 | 2013-11-14 09:54:24 +0100 | [diff] [blame] | 20 | //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) |
Denys Vlasenko | 6747bda | 2016-11-27 03:57:08 +0100 | [diff] [blame] | 21 | |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 22 | //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o |
| 23 | |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 24 | //usage:#define dpkg_deb_trivial_usage |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 25 | //usage: "[-cefxX] FILE [DIR]" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 26 | //usage:#define dpkg_deb_full_usage "\n\n" |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 27 | //usage: "Perform actions on Debian packages (.deb)\n" |
| 28 | //usage: "\n -c List files" |
| 29 | //usage: "\n -f Print control fields" |
| 30 | //usage: "\n -e Extract control files to DIR (default: ./DEBIAN)" |
| 31 | //usage: "\n -x Extract files to DIR (no default)" |
| 32 | //usage: "\n -X Verbose -x" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 33 | //usage: |
| 34 | //usage:#define dpkg_deb_example_usage |
| 35 | //usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n" |
| 36 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 37 | #include "libbb.h" |
Denys Vlasenko | d184a72 | 2011-09-22 12:45:14 +0200 | [diff] [blame] | 38 | #include "bb_archive.h" |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 39 | |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 40 | #define DPKG_DEB_OPT_CONTENTS 1 |
| 41 | #define DPKG_DEB_OPT_CONTROL 2 |
| 42 | #define DPKG_DEB_OPT_FIELD 4 |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 43 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 8 |
| 44 | #define DPKG_DEB_OPT_EXTRACT 16 |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 45 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 46 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 47 | int dpkg_deb_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 48 | { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 49 | archive_handle_t *ar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 50 | archive_handle_t *tar_archive; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 51 | llist_t *control_tar_llist = NULL; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 52 | unsigned opt; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 53 | const char *extract_dir; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 54 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 55 | /* Setup the tar archive handle */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 56 | tar_archive = init_handle(); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 57 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 58 | /* 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] | 59 | ar_archive = init_handle(); |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 60 | ar_archive->dpkg__sub_archive = tar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 61 | ar_archive->filter = filter_accept_list_reassign; |
| 62 | |
Denys Vlasenko | 08f9ffc | 2015-01-30 15:15:38 +0100 | [diff] [blame] | 63 | llist_add_to(&ar_archive->accept, (char*)"data.tar"); |
| 64 | llist_add_to(&control_tar_llist, (char*)"control.tar"); |
Denis Vlasenko | e9ad84d | 2008-08-05 13:10:34 +0000 | [diff] [blame] | 65 | #if ENABLE_FEATURE_SEAMLESS_GZ |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 66 | llist_add_to(&ar_archive->accept, (char*)"data.tar.gz"); |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 67 | llist_add_to(&control_tar_llist, (char*)"control.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 68 | #endif |
Denis Vlasenko | e9ad84d | 2008-08-05 13:10:34 +0000 | [diff] [blame] | 69 | #if ENABLE_FEATURE_SEAMLESS_BZ2 |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 70 | llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2"); |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 71 | llist_add_to(&control_tar_llist, (char*)"control.tar.bz2"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 72 | #endif |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 73 | #if ENABLE_FEATURE_SEAMLESS_LZMA |
| 74 | llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma"); |
| 75 | llist_add_to(&control_tar_llist, (char*)"control.tar.lzma"); |
| 76 | #endif |
Denys Vlasenko | 08f9ffc | 2015-01-30 15:15:38 +0100 | [diff] [blame] | 77 | #if ENABLE_FEATURE_SEAMLESS_XZ |
| 78 | llist_add_to(&ar_archive->accept, (char*)"data.tar.xz"); |
| 79 | llist_add_to(&control_tar_llist, (char*)"control.tar.xz"); |
| 80 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 81 | |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 82 | /* Must have 1 or 2 args */ |
Denys Vlasenko | 22542ec | 2017-08-08 21:55:02 +0200 | [diff] [blame^] | 83 | opt = getopt32(argv, "^" "cefXx" |
| 84 | "\0" "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX" |
| 85 | ); |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 86 | argv += optind; |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 87 | //argc -= optind; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 88 | |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 89 | extract_dir = argv[1]; |
| 90 | if (opt & DPKG_DEB_OPT_CONTENTS) { // -c |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 91 | tar_archive->action_header = header_verbose_list; |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 92 | if (extract_dir) |
| 93 | bb_show_usage(); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 94 | } |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 95 | if (opt & DPKG_DEB_OPT_FIELD) { // -f |
| 96 | /* Print the entire control file */ |
| 97 | //TODO: standard tool accepts an optional list of fields to print |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 98 | ar_archive->accept = control_tar_llist; |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 99 | llist_add_to(&(tar_archive->accept), (char*)"./control"); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 100 | tar_archive->filter = filter_accept_list; |
| 101 | tar_archive->action_data = data_extract_to_stdout; |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 102 | if (extract_dir) |
| 103 | bb_show_usage(); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 104 | } |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 105 | if (opt & DPKG_DEB_OPT_CONTROL) { // -e |
| 106 | ar_archive->accept = control_tar_llist; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 107 | tar_archive->action_data = data_extract_all; |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 108 | if (!extract_dir) |
| 109 | extract_dir = "./DEBIAN"; |
| 110 | } |
| 111 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { // -Xx |
| 112 | if (opt & DPKG_DEB_OPT_EXTRACT_VERBOSE) |
| 113 | tar_archive->action_header = header_list; |
| 114 | tar_archive->action_data = data_extract_all; |
| 115 | if (!extract_dir) |
| 116 | bb_show_usage(); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 117 | } |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 118 | |
Denys Vlasenko | 351ab82 | 2016-11-27 04:48:53 +0100 | [diff] [blame] | 119 | /* Standard tool supports "-" */ |
| 120 | tar_archive->src_fd = ar_archive->src_fd = xopen_stdin(argv[0]); |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 121 | |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 122 | if (extract_dir) { |
Bernhard Reutner-Fischer | 44e216f | 2006-06-10 11:29:44 +0000 | [diff] [blame] | 123 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 124 | xchdir(extract_dir); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 125 | } |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 126 | |
| 127 | /* Do it */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 128 | unpack_ar_archive(ar_archive); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 129 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 130 | /* Cleanup */ |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 131 | if (ENABLE_FEATURE_CLEAN_UP) |
| 132 | close(ar_archive->src_fd); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 133 | |
Denis Vlasenko | 079f8af | 2006-11-27 16:49:31 +0000 | [diff] [blame] | 134 | return EXIT_SUCCESS; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 135 | } |