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 | * |
Bernhard Reutner-Fischer | d9cf7ac | 2006-04-12 18:39:58 +0000 | [diff] [blame] | 5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 6 | */ |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 7 | #include "busybox.h" |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 8 | #include "unarchive.h" |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 9 | |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 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 |
| 15 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 16 | int dpkg_deb_main(int argc, char **argv); |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 17 | int dpkg_deb_main(int argc, char **argv) |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 18 | { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 19 | archive_handle_t *ar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 20 | archive_handle_t *tar_archive; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 21 | llist_t *control_tar_llist = NULL; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 22 | unsigned opt; |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 23 | const char *extract_dir = NULL; |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 24 | short argcount = 1; |
| 25 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 26 | /* Setup the tar archive handle */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 27 | tar_archive = init_handle(); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 28 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 29 | /* 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] | 30 | ar_archive = init_handle(); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 31 | ar_archive->sub_archive = tar_archive; |
| 32 | ar_archive->filter = filter_accept_list_reassign; |
| 33 | |
| 34 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 35 | llist_add_to(&(ar_archive->accept), (char*)"data.tar.gz"); |
| 36 | llist_add_to(&control_tar_llist, (char*)"control.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 40 | llist_add_to(&(ar_archive->accept), (char*)"data.tar.bz2"); |
| 41 | llist_add_to(&control_tar_llist, (char*)"control.tar.bz2"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 42 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 43 | |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 44 | opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; |
| 45 | opt = getopt32(argc, argv, "cefXx"); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 46 | |
| 47 | if (opt & DPKG_DEB_OPT_CONTENTS) { |
| 48 | tar_archive->action_header = header_verbose_list; |
| 49 | } |
| 50 | if (opt & DPKG_DEB_OPT_CONTROL) { |
| 51 | ar_archive->accept = control_tar_llist; |
| 52 | tar_archive->action_data = data_extract_all; |
| 53 | if (optind + 1 == argc) { |
| 54 | extract_dir = "./DEBIAN"; |
| 55 | } else { |
| 56 | argcount++; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 57 | } |
| 58 | } |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 59 | if (opt & DPKG_DEB_OPT_FIELD) { |
| 60 | /* Print the entire control file |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 61 | * it should accept a second argument which specifies a |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 62 | * specific field to print */ |
| 63 | ar_archive->accept = control_tar_llist; |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 64 | llist_add_to(&(tar_archive->accept), (char*)"./control"); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 65 | tar_archive->filter = filter_accept_list; |
| 66 | tar_archive->action_data = data_extract_to_stdout; |
| 67 | } |
| 68 | if (opt & DPKG_DEB_OPT_EXTRACT) { |
| 69 | tar_archive->action_header = header_list; |
| 70 | } |
| 71 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { |
| 72 | tar_archive->action_data = data_extract_all; |
| 73 | argcount = 2; |
| 74 | } |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 75 | |
"Vladimir N. Oleynik" | 27421a1 | 2005-09-05 14:46:07 +0000 | [diff] [blame] | 76 | if ((optind + argcount) != argc) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 77 | bb_show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 78 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 79 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 80 | tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 81 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 82 | /* Workout where to extract the files */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 83 | /* 2nd argument is a dir name */ |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 84 | if (argv[optind]) { |
| 85 | extract_dir = argv[optind]; |
| 86 | } |
| 87 | if (extract_dir) { |
Bernhard Reutner-Fischer | 44e216f | 2006-06-10 11:29:44 +0000 | [diff] [blame] | 88 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 89 | xchdir(extract_dir); |
Glenn L McGrath | 1f28b90 | 2004-01-07 09:24:06 +0000 | [diff] [blame] | 90 | } |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 91 | unpack_ar_archive(ar_archive); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 92 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 93 | /* Cleanup */ |
Denis Vlasenko | 079f8af | 2006-11-27 16:49:31 +0000 | [diff] [blame] | 94 | close(ar_archive->src_fd); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 95 | |
Denis Vlasenko | 079f8af | 2006-11-27 16:49:31 +0000 | [diff] [blame] | 96 | return EXIT_SUCCESS; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 97 | } |