[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 | */
|
---|
[1765] | 7 | #include "libbb.h"
|
---|
[2725] | 8 | #include "archive.h"
|
---|
[821] | 9 |
|
---|
[2725] | 10 | #define DPKG_DEB_OPT_CONTENTS 1
|
---|
| 11 | #define DPKG_DEB_OPT_CONTROL 2
|
---|
| 12 | #define DPKG_DEB_OPT_FIELD 4
|
---|
| 13 | #define DPKG_DEB_OPT_EXTRACT 8
|
---|
| 14 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
---|
[821] | 15 |
|
---|
[2725] | 16 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
[821] | 17 | int dpkg_deb_main(int argc, char **argv)
|
---|
| 18 | {
|
---|
| 19 | archive_handle_t *ar_archive;
|
---|
| 20 | archive_handle_t *tar_archive;
|
---|
| 21 | llist_t *control_tar_llist = NULL;
|
---|
[1765] | 22 | unsigned opt;
|
---|
[2725] | 23 | const char *extract_dir;
|
---|
| 24 | int need_args;
|
---|
[821] | 25 |
|
---|
| 26 | /* Setup the tar archive handle */
|
---|
| 27 | tar_archive = init_handle();
|
---|
| 28 |
|
---|
| 29 | /* Setup an ar archive handle that refers to the gzip sub archive */
|
---|
| 30 | ar_archive = init_handle();
|
---|
[2725] | 31 | ar_archive->dpkg__sub_archive = tar_archive;
|
---|
[821] | 32 | ar_archive->filter = filter_accept_list_reassign;
|
---|
| 33 |
|
---|
[2725] | 34 | #if ENABLE_FEATURE_SEAMLESS_GZ
|
---|
| 35 | llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
|
---|
[1765] | 36 | llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
---|
[821] | 37 | #endif
|
---|
[2725] | 38 | #if ENABLE_FEATURE_SEAMLESS_BZ2
|
---|
| 39 | llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2");
|
---|
[1765] | 40 | llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
---|
[821] | 41 | #endif
|
---|
[2725] | 42 | #if ENABLE_FEATURE_SEAMLESS_LZMA
|
---|
| 43 | llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
|
---|
| 44 | llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
|
---|
| 45 | #endif
|
---|
[821] | 46 |
|
---|
[2725] | 47 | opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
---|
[1765] | 48 | opt = getopt32(argv, "cefXx");
|
---|
[2725] | 49 | argv += optind;
|
---|
| 50 | argc -= optind;
|
---|
[821] | 51 |
|
---|
| 52 | if (opt & DPKG_DEB_OPT_CONTENTS) {
|
---|
| 53 | tar_archive->action_header = header_verbose_list;
|
---|
| 54 | }
|
---|
[2725] | 55 | extract_dir = NULL;
|
---|
| 56 | need_args = 1;
|
---|
[821] | 57 | if (opt & DPKG_DEB_OPT_CONTROL) {
|
---|
| 58 | ar_archive->accept = control_tar_llist;
|
---|
| 59 | tar_archive->action_data = data_extract_all;
|
---|
[2725] | 60 | if (1 == argc) {
|
---|
[821] | 61 | extract_dir = "./DEBIAN";
|
---|
| 62 | } else {
|
---|
[2725] | 63 | need_args++;
|
---|
[821] | 64 | }
|
---|
| 65 | }
|
---|
| 66 | if (opt & DPKG_DEB_OPT_FIELD) {
|
---|
| 67 | /* Print the entire control file
|
---|
| 68 | * it should accept a second argument which specifies a
|
---|
| 69 | * specific field to print */
|
---|
| 70 | ar_archive->accept = control_tar_llist;
|
---|
[1765] | 71 | llist_add_to(&(tar_archive->accept), (char*)"./control");
|
---|
[821] | 72 | tar_archive->filter = filter_accept_list;
|
---|
| 73 | tar_archive->action_data = data_extract_to_stdout;
|
---|
| 74 | }
|
---|
| 75 | if (opt & DPKG_DEB_OPT_EXTRACT) {
|
---|
| 76 | tar_archive->action_header = header_list;
|
---|
| 77 | }
|
---|
| 78 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
|
---|
| 79 | tar_archive->action_data = data_extract_all;
|
---|
[2725] | 80 | need_args = 2;
|
---|
[821] | 81 | }
|
---|
| 82 |
|
---|
[2725] | 83 | if (need_args != argc) {
|
---|
[821] | 84 | bb_show_usage();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[2725] | 87 | tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
|
---|
[821] | 88 |
|
---|
[2725] | 89 | /* Work out where to extract the files */
|
---|
[821] | 90 | /* 2nd argument is a dir name */
|
---|
[2725] | 91 | if (argv[1]) {
|
---|
| 92 | extract_dir = argv[1];
|
---|
[821] | 93 | }
|
---|
| 94 | if (extract_dir) {
|
---|
| 95 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
|
---|
[1765] | 96 | xchdir(extract_dir);
|
---|
[821] | 97 | }
|
---|
[2725] | 98 |
|
---|
| 99 | /* Do it */
|
---|
[821] | 100 | unpack_ar_archive(ar_archive);
|
---|
| 101 |
|
---|
| 102 | /* Cleanup */
|
---|
[2725] | 103 | if (ENABLE_FEATURE_CLEAN_UP)
|
---|
| 104 | close(ar_archive->src_fd);
|
---|
[821] | 105 |
|
---|
[1765] | 106 | return EXIT_SUCCESS;
|
---|
[821] | 107 | }
|
---|