1 /* vi: set sw=4 ts=4: */
3 * dpkg-deb packs, unpacks and provides information about Debian archives.
5 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb))
9 //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
11 //usage:#define dpkg_deb_trivial_usage
12 //usage: "[-cefxX] FILE [argument"
13 //usage:#define dpkg_deb_full_usage "\n\n"
14 //usage: "Perform actions on Debian packages (.debs)\n"
15 //usage: "\n -c List contents of filesystem tree"
16 //usage: "\n -e Extract control files to [argument] directory"
17 //usage: "\n -f Display control field name starting with [argument]"
18 //usage: "\n -x Extract packages filesystem tree to directory"
19 //usage: "\n -X Verbose extract"
21 //usage:#define dpkg_deb_example_usage
22 //usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
25 #include "bb_archive.h"
27 #define DPKG_DEB_OPT_CONTENTS 1
28 #define DPKG_DEB_OPT_CONTROL 2
29 #define DPKG_DEB_OPT_FIELD 4
30 #define DPKG_DEB_OPT_EXTRACT 8
31 #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
33 int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34 int dpkg_deb_main(int argc, char **argv)
36 archive_handle_t *ar_archive;
37 archive_handle_t *tar_archive;
38 llist_t *control_tar_llist = NULL;
40 const char *extract_dir;
43 /* Setup the tar archive handle */
44 tar_archive = init_handle();
46 /* Setup an ar archive handle that refers to the gzip sub archive */
47 ar_archive = init_handle();
48 ar_archive->dpkg__sub_archive = tar_archive;
49 ar_archive->filter = filter_accept_list_reassign;
51 #if ENABLE_FEATURE_SEAMLESS_GZ
52 llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
53 llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
55 #if ENABLE_FEATURE_SEAMLESS_BZ2
56 llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2");
57 llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
59 #if ENABLE_FEATURE_SEAMLESS_LZMA
60 llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
61 llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
64 opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
65 opt = getopt32(argv, "cefXx");
69 if (opt & DPKG_DEB_OPT_CONTENTS) {
70 tar_archive->action_header = header_verbose_list;
74 if (opt & DPKG_DEB_OPT_CONTROL) {
75 ar_archive->accept = control_tar_llist;
76 tar_archive->action_data = data_extract_all;
78 extract_dir = "./DEBIAN";
83 if (opt & DPKG_DEB_OPT_FIELD) {
84 /* Print the entire control file
85 * it should accept a second argument which specifies a
86 * specific field to print */
87 ar_archive->accept = control_tar_llist;
88 llist_add_to(&(tar_archive->accept), (char*)"./control");
89 tar_archive->filter = filter_accept_list;
90 tar_archive->action_data = data_extract_to_stdout;
92 if (opt & DPKG_DEB_OPT_EXTRACT) {
93 tar_archive->action_header = header_list;
95 if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
96 tar_archive->action_data = data_extract_all;
100 if (need_args != argc) {
104 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
106 /* Work out where to extract the files */
107 /* 2nd argument is a dir name */
109 extract_dir = argv[1];
112 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
117 unpack_ar_archive(ar_archive);
120 if (ENABLE_FEATURE_CLEAN_UP)
121 close(ar_archive->src_fd);