blob: 2d7383fd7988f62b2844ca8d27312dc8bed80b24 [file] [log] [blame]
Glenn L McGrath58a40852001-01-02 23:49:26 +00001/*
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 McGrath7ca04f32002-09-25 02:47:48 +000016#include <fcntl.h>
Glenn L McGrath58a40852001-01-02 23:49:26 +000017#include <stdlib.h>
Glenn L McGrath33431eb2001-04-16 04:52:19 +000018#include <string.h>
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000019#include <unistd.h>
Glenn L McGrathd22e5602001-04-11 02:12:08 +000020#include <getopt.h>
Glenn L McGrathef0eab52001-10-25 14:49:48 +000021#include "unarchive.h"
Glenn L McGrath58a40852001-01-02 23:49:26 +000022#include "busybox.h"
23
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000024extern int dpkg_deb_main(int argc, char **argv)
25{
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000026 archive_handle_t *ar_archive;
Glenn L McGrath18bbca12002-11-05 01:52:23 +000027 archive_handle_t *tar_archive;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000028 int opt = 0;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000029#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
Glenn L McGrath66125c82002-12-08 00:54:33 +000030 llist_t *control_tar_llist = NULL;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000031#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000032
33 /* Setup the tar archive handle */
Glenn L McGrath18bbca12002-11-05 01:52:23 +000034 tar_archive = init_handle();
Glenn L McGrath9aff9032001-06-13 07:26:39 +000035
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000036 /* Setup an ar archive handle that refers to the gzip sub archive */
37 ar_archive = init_handle();
Glenn L McGrath18bbca12002-11-05 01:52:23 +000038 ar_archive->sub_archive = tar_archive;
39 ar_archive->filter = filter_accept_list_reassign;
40
41#ifdef CONFIG_FEATURE_DEB_TAR_GZ
Glenn L McGrath66125c82002-12-08 00:54:33 +000042 ar_archive->accept = llist_add_to(NULL, "data.tar.gz");
Glenn L McGrath18bbca12002-11-05 01:52:23 +000043# ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
Glenn L McGrath66125c82002-12-08 00:54:33 +000044 control_tar_llist = llist_add_to(NULL, "control.tar.gz");
Glenn L McGrath18bbca12002-11-05 01:52:23 +000045# endif
46#endif
47
48#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
Glenn L McGrath66125c82002-12-08 00:54:33 +000049 ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2");
Glenn L McGrath18bbca12002-11-05 01:52:23 +000050# ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
Glenn L McGrath66125c82002-12-08 00:54:33 +000051 control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2");
Glenn L McGrath18bbca12002-11-05 01:52:23 +000052# endif
53#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000054
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 McGrath58a40852001-01-02 23:49:26 +000060 switch (opt) {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000061#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
Glenn L McGrath58a40852001-01-02 23:49:26 +000062 case 'c':
Glenn L McGrath18bbca12002-11-05 01:52:23 +000063 tar_archive->action_header = header_verbose_list;
Glenn L McGrath58a40852001-01-02 23:49:26 +000064 break;
65 case 'e':
Glenn L McGrath18bbca12002-11-05 01:52:23 +000066 ar_archive->accept = control_tar_llist;
67 tar_archive->action_data = data_extract_all;
Glenn L McGrath58a40852001-01-02 23:49:26 +000068 break;
Glenn L McGrath445fb952001-04-13 04:02:57 +000069 case 'f':
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000070 /* Print the entire control file
71 * it should accept a second argument which specifies a
72 * specific field to print */
Glenn L McGrath18bbca12002-11-05 01:52:23 +000073 ar_archive->accept = control_tar_llist;
Glenn L McGrath66125c82002-12-08 00:54:33 +000074 tar_archive->accept = llist_add_to(NULL, "./control");;
Glenn L McGrath18bbca12002-11-05 01:52:23 +000075 tar_archive->filter = filter_accept_list;
76 tar_archive->action_data = data_extract_to_stdout;
Glenn L McGrath3e2ab882001-04-12 13:49:09 +000077 break;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000078 case 'X':
Glenn L McGrath18bbca12002-11-05 01:52:23 +000079 tar_archive->action_header = header_list;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000080#endif
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000081 case 'x':
Glenn L McGrath18bbca12002-11-05 01:52:23 +000082 tar_archive->action_data = data_extract_all;
Glenn L McGrath58a40852001-01-02 23:49:26 +000083 break;
Glenn L McGrath58a40852001-01-02 23:49:26 +000084 default:
Manuel Novoa III cad53642003-03-19 09:13:01 +000085 bb_show_usage();
Glenn L McGrath58a40852001-01-02 23:49:26 +000086 }
87 }
88
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000089 if (optind + 2 < argc) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000090 bb_show_usage();
Glenn L McGrath58a40852001-01-02 23:49:26 +000091 }
Glenn L McGrath6785b512001-04-12 11:48:02 +000092
Manuel Novoa III cad53642003-03-19 09:13:01 +000093 tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000094
Glenn L McGrath9aff9032001-06-13 07:26:39 +000095 /* Workout where to extract the files */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000096 /* 2nd argument is a dir name */
97 mkdir(argv[optind], 0777);
98 chdir(argv[optind]);
Glenn L McGrath6785b512001-04-12 11:48:02 +000099
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000100 unpack_ar_archive(ar_archive);
Glenn L McGrath9aff9032001-06-13 07:26:39 +0000101
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000102 /* Cleanup */
103 close (ar_archive->src_fd);
Glenn L McGrath445fb952001-04-13 04:02:57 +0000104
Glenn L McGrath58a40852001-01-02 23:49:26 +0000105 return(EXIT_SUCCESS);
106}
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000107