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 | |
| 8 | //usage:#define dpkg_deb_trivial_usage |
| 9 | //usage: "[-cefxX] FILE [argument" |
| 10 | //usage:#define dpkg_deb_full_usage "\n\n" |
| 11 | //usage: "Perform actions on Debian packages (.debs)\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 12 | //usage: "\n -c List contents of filesystem tree" |
| 13 | //usage: "\n -e Extract control files to [argument] directory" |
| 14 | //usage: "\n -f Display control field name starting with [argument]" |
| 15 | //usage: "\n -x Extract packages filesystem tree to directory" |
| 16 | //usage: "\n -X Verbose extract" |
| 17 | //usage: |
| 18 | //usage:#define dpkg_deb_example_usage |
| 19 | //usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n" |
| 20 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 21 | #include "libbb.h" |
Denys Vlasenko | d184a72 | 2011-09-22 12:45:14 +0200 | [diff] [blame] | 22 | #include "bb_archive.h" |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 23 | |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 24 | #define DPKG_DEB_OPT_CONTENTS 1 |
| 25 | #define DPKG_DEB_OPT_CONTROL 2 |
| 26 | #define DPKG_DEB_OPT_FIELD 4 |
| 27 | #define DPKG_DEB_OPT_EXTRACT 8 |
| 28 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16 |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 29 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 30 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 31 | int dpkg_deb_main(int argc, char **argv) |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 32 | { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 33 | archive_handle_t *ar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 34 | archive_handle_t *tar_archive; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 35 | llist_t *control_tar_llist = NULL; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 36 | unsigned opt; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 37 | const char *extract_dir; |
| 38 | int need_args; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 39 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 40 | /* Setup the tar archive handle */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 41 | tar_archive = init_handle(); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 42 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 43 | /* 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] | 44 | ar_archive = init_handle(); |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 45 | ar_archive->dpkg__sub_archive = tar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 46 | ar_archive->filter = filter_accept_list_reassign; |
| 47 | |
Denis Vlasenko | e9ad84d | 2008-08-05 13:10:34 +0000 | [diff] [blame] | 48 | #if ENABLE_FEATURE_SEAMLESS_GZ |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 49 | llist_add_to(&ar_archive->accept, (char*)"data.tar.gz"); |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 50 | llist_add_to(&control_tar_llist, (char*)"control.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 51 | #endif |
Denis Vlasenko | e9ad84d | 2008-08-05 13:10:34 +0000 | [diff] [blame] | 52 | #if ENABLE_FEATURE_SEAMLESS_BZ2 |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 53 | llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2"); |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 54 | llist_add_to(&control_tar_llist, (char*)"control.tar.bz2"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 55 | #endif |
Pascal Bellard | c62f229 | 2010-06-07 01:20:41 +0200 | [diff] [blame] | 56 | #if ENABLE_FEATURE_SEAMLESS_LZMA |
| 57 | llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma"); |
| 58 | llist_add_to(&control_tar_llist, (char*)"control.tar.lzma"); |
| 59 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 60 | |
Denis Vlasenko | e7fca51 | 2007-11-10 01:32:18 +0000 | [diff] [blame] | 61 | opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 62 | opt = getopt32(argv, "cefXx"); |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 63 | argv += optind; |
| 64 | argc -= optind; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 65 | |
| 66 | if (opt & DPKG_DEB_OPT_CONTENTS) { |
| 67 | tar_archive->action_header = header_verbose_list; |
| 68 | } |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 69 | extract_dir = NULL; |
| 70 | need_args = 1; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 71 | if (opt & DPKG_DEB_OPT_CONTROL) { |
| 72 | ar_archive->accept = control_tar_llist; |
| 73 | tar_archive->action_data = data_extract_all; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 74 | if (1 == argc) { |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 75 | extract_dir = "./DEBIAN"; |
| 76 | } else { |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 77 | need_args++; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 80 | if (opt & DPKG_DEB_OPT_FIELD) { |
| 81 | /* Print the entire control file |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 82 | * it should accept a second argument which specifies a |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 83 | * specific field to print */ |
| 84 | ar_archive->accept = control_tar_llist; |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 85 | llist_add_to(&(tar_archive->accept), (char*)"./control"); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 86 | tar_archive->filter = filter_accept_list; |
| 87 | tar_archive->action_data = data_extract_to_stdout; |
| 88 | } |
| 89 | if (opt & DPKG_DEB_OPT_EXTRACT) { |
| 90 | tar_archive->action_header = header_list; |
| 91 | } |
| 92 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { |
| 93 | tar_archive->action_data = data_extract_all; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 94 | need_args = 2; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 95 | } |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 96 | |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 97 | if (need_args != argc) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 98 | bb_show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 99 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 100 | |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 101 | tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 102 | |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 103 | /* Work out where to extract the files */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 104 | /* 2nd argument is a dir name */ |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 105 | if (argv[1]) { |
| 106 | extract_dir = argv[1]; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 107 | } |
| 108 | if (extract_dir) { |
Bernhard Reutner-Fischer | 44e216f | 2006-06-10 11:29:44 +0000 | [diff] [blame] | 109 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 110 | xchdir(extract_dir); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 111 | } |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 112 | |
| 113 | /* Do it */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 114 | unpack_ar_archive(ar_archive); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 115 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 116 | /* Cleanup */ |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 117 | if (ENABLE_FEATURE_CLEAN_UP) |
| 118 | close(ar_archive->src_fd); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 119 | |
Denis Vlasenko | 079f8af | 2006-11-27 16:49:31 +0000 | [diff] [blame] | 120 | return EXIT_SUCCESS; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 121 | } |