Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License as published by |
| 4 | * the Free Software Foundation; either version 2 of the License, or |
| 5 | * (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU Library General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 15 | */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 16 | #include <fcntl.h> |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 18 | #include <string.h> |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 19 | #include <unistd.h> |
Glenn L McGrath | d22e560 | 2001-04-11 02:12:08 +0000 | [diff] [blame] | 20 | #include <getopt.h> |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 21 | #include "unarchive.h" |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 22 | #include "busybox.h" |
| 23 | |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 24 | extern int dpkg_deb_main(int argc, char **argv) |
| 25 | { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 26 | archive_handle_t *ar_archive; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 27 | archive_handle_t *tar_archive; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 28 | int opt = 0; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 29 | #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 30 | llist_t *control_tar_llist = NULL; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 31 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 32 | |
| 33 | /* Setup the tar archive handle */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 34 | tar_archive = init_handle(); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 35 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 36 | /* Setup an ar archive handle that refers to the gzip sub archive */ |
| 37 | ar_archive = init_handle(); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 38 | ar_archive->sub_archive = tar_archive; |
| 39 | ar_archive->filter = filter_accept_list_reassign; |
| 40 | |
| 41 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 42 | ar_archive->accept = llist_add_to(NULL, "data.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 43 | # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 44 | control_tar_llist = llist_add_to(NULL, "control.tar.gz"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 45 | # endif |
| 46 | #endif |
| 47 | |
| 48 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 49 | ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 50 | # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 51 | control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2"); |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 52 | # endif |
| 53 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 54 | |
| 55 | #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY |
| 56 | while ((opt = getopt(argc, argv, "cefXx")) != -1) { |
| 57 | #else |
| 58 | while ((opt = getopt(argc, argv, "x")) != -1) { |
| 59 | #endif |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 60 | switch (opt) { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 61 | #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 62 | case 'c': |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 63 | tar_archive->action_header = header_verbose_list; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 64 | break; |
| 65 | case 'e': |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 66 | ar_archive->accept = control_tar_llist; |
| 67 | tar_archive->action_data = data_extract_all; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 68 | break; |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 69 | case 'f': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 70 | /* Print the entire control file |
| 71 | * it should accept a second argument which specifies a |
| 72 | * specific field to print */ |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 73 | ar_archive->accept = control_tar_llist; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 74 | tar_archive->accept = llist_add_to(NULL, "./control");; |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 75 | tar_archive->filter = filter_accept_list; |
| 76 | tar_archive->action_data = data_extract_to_stdout; |
Glenn L McGrath | 3e2ab88 | 2001-04-12 13:49:09 +0000 | [diff] [blame] | 77 | break; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 78 | case 'X': |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 79 | tar_archive->action_header = header_list; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 80 | #endif |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 81 | case 'x': |
Glenn L McGrath | 18bbca1 | 2002-11-05 01:52:23 +0000 | [diff] [blame] | 82 | tar_archive->action_data = data_extract_all; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 83 | break; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 84 | default: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 85 | bb_show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 89 | if (optind + 2 < argc) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 90 | bb_show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 91 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 92 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 93 | tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 94 | |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 95 | /* Workout where to extract the files */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 96 | /* 2nd argument is a dir name */ |
| 97 | mkdir(argv[optind], 0777); |
| 98 | chdir(argv[optind]); |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 99 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 100 | unpack_ar_archive(ar_archive); |
Glenn L McGrath | 9aff903 | 2001-06-13 07:26:39 +0000 | [diff] [blame] | 101 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 102 | /* Cleanup */ |
| 103 | close (ar_archive->src_fd); |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 104 | |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 105 | return(EXIT_SUCCESS); |
| 106 | } |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 107 | |