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