[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * dpkg-deb packs, unpacks and provides information about Debian archives.
|
---|
| 4 | *
|
---|
[2725] | 5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[821] | 6 | */
|
---|
[3232] | 7 |
|
---|
[3621] | 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 |
|
---|
| 30 | //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb))
|
---|
| 31 | //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
---|
| 32 |
|
---|
[3232] | 33 | //usage:#define dpkg_deb_trivial_usage
|
---|
[3621] | 34 | //usage: "[-cefxX] FILE [argument]"
|
---|
[3232] | 35 | //usage:#define dpkg_deb_full_usage "\n\n"
|
---|
| 36 | //usage: "Perform actions on Debian packages (.debs)\n"
|
---|
| 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 |
|
---|
[1765] | 46 | #include "libbb.h"
|
---|
[3232] | 47 | #include "bb_archive.h"
|
---|
[821] | 48 |
|
---|
[2725] | 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
|
---|
[821] | 54 |
|
---|
[2725] | 55 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
[821] | 56 | int dpkg_deb_main(int argc, char **argv)
|
---|
| 57 | {
|
---|
| 58 | archive_handle_t *ar_archive;
|
---|
| 59 | archive_handle_t *tar_archive;
|
---|
| 60 | llist_t *control_tar_llist = NULL;
|
---|
[1765] | 61 | unsigned opt;
|
---|
[2725] | 62 | const char *extract_dir;
|
---|
| 63 | int need_args;
|
---|
[821] | 64 |
|
---|
| 65 | /* Setup the tar archive handle */
|
---|
| 66 | tar_archive = init_handle();
|
---|
| 67 |
|
---|
| 68 | /* Setup an ar archive handle that refers to the gzip sub archive */
|
---|
| 69 | ar_archive = init_handle();
|
---|
[2725] | 70 | ar_archive->dpkg__sub_archive = tar_archive;
|
---|
[821] | 71 | ar_archive->filter = filter_accept_list_reassign;
|
---|
| 72 |
|
---|
[3621] | 73 | llist_add_to(&ar_archive->accept, (char*)"data.tar");
|
---|
| 74 | llist_add_to(&control_tar_llist, (char*)"control.tar");
|
---|
[2725] | 75 | #if ENABLE_FEATURE_SEAMLESS_GZ
|
---|
| 76 | llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
|
---|
[1765] | 77 | llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
---|
[821] | 78 | #endif
|
---|
[2725] | 79 | #if ENABLE_FEATURE_SEAMLESS_BZ2
|
---|
| 80 | llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2");
|
---|
[1765] | 81 | llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
---|
[821] | 82 | #endif
|
---|
[2725] | 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
|
---|
[3621] | 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
|
---|
[821] | 91 |
|
---|
[2725] | 92 | opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
---|
[1765] | 93 | opt = getopt32(argv, "cefXx");
|
---|
[2725] | 94 | argv += optind;
|
---|
| 95 | argc -= optind;
|
---|
[821] | 96 |
|
---|
| 97 | if (opt & DPKG_DEB_OPT_CONTENTS) {
|
---|
| 98 | tar_archive->action_header = header_verbose_list;
|
---|
| 99 | }
|
---|
[2725] | 100 | extract_dir = NULL;
|
---|
| 101 | need_args = 1;
|
---|
[821] | 102 | if (opt & DPKG_DEB_OPT_CONTROL) {
|
---|
| 103 | ar_archive->accept = control_tar_llist;
|
---|
| 104 | tar_archive->action_data = data_extract_all;
|
---|
[2725] | 105 | if (1 == argc) {
|
---|
[821] | 106 | extract_dir = "./DEBIAN";
|
---|
| 107 | } else {
|
---|
[2725] | 108 | need_args++;
|
---|
[821] | 109 | }
|
---|
| 110 | }
|
---|
| 111 | if (opt & DPKG_DEB_OPT_FIELD) {
|
---|
| 112 | /* Print the entire control file
|
---|
| 113 | * it should accept a second argument which specifies a
|
---|
| 114 | * specific field to print */
|
---|
| 115 | ar_archive->accept = control_tar_llist;
|
---|
[1765] | 116 | llist_add_to(&(tar_archive->accept), (char*)"./control");
|
---|
[821] | 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;
|
---|
[2725] | 125 | need_args = 2;
|
---|
[821] | 126 | }
|
---|
| 127 |
|
---|
[2725] | 128 | if (need_args != argc) {
|
---|
[821] | 129 | bb_show_usage();
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[2725] | 132 | tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
|
---|
[821] | 133 |
|
---|
[2725] | 134 | /* Work out where to extract the files */
|
---|
[821] | 135 | /* 2nd argument is a dir name */
|
---|
[2725] | 136 | if (argv[1]) {
|
---|
| 137 | extract_dir = argv[1];
|
---|
[821] | 138 | }
|
---|
| 139 | if (extract_dir) {
|
---|
| 140 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
|
---|
[1765] | 141 | xchdir(extract_dir);
|
---|
[821] | 142 | }
|
---|
[2725] | 143 |
|
---|
| 144 | /* Do it */
|
---|
[821] | 145 | unpack_ar_archive(ar_archive);
|
---|
| 146 |
|
---|
| 147 | /* Cleanup */
|
---|
[2725] | 148 | if (ENABLE_FEATURE_CLEAN_UP)
|
---|
| 149 | close(ar_archive->src_fd);
|
---|
[821] | 150 |
|
---|
[1765] | 151 | return EXIT_SUCCESS;
|
---|
[821] | 152 | }
|
---|