2006-04-13 02:39:58 +08:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2001-01-03 07:49:26 +08:00
|
|
|
/*
|
2006-04-13 02:39:58 +08:00
|
|
|
* dpkg-deb packs, unpacks and provides information about Debian archives.
|
2004-01-07 17:24:06 +08:00
|
|
|
*
|
2006-04-13 02:39:58 +08:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2001-01-03 07:49:26 +08:00
|
|
|
*/
|
2007-05-27 03:00:18 +08:00
|
|
|
#include "libbb.h"
|
2006-08-03 23:41:12 +08:00
|
|
|
#include "unarchive.h"
|
2001-01-03 07:49:26 +08:00
|
|
|
|
2004-01-07 17:24:06 +08:00
|
|
|
#define DPKG_DEB_OPT_CONTENTS 1
|
|
|
|
#define DPKG_DEB_OPT_CONTROL 2
|
|
|
|
#define DPKG_DEB_OPT_FIELD 4
|
|
|
|
#define DPKG_DEB_OPT_EXTRACT 8
|
|
|
|
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
|
|
|
|
2007-10-11 18:05:36 +08:00
|
|
|
int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2006-03-07 04:47:33 +08:00
|
|
|
int dpkg_deb_main(int argc, char **argv)
|
2001-02-11 11:32:41 +08:00
|
|
|
{
|
2002-09-25 10:47:48 +08:00
|
|
|
archive_handle_t *ar_archive;
|
2002-11-05 09:52:23 +08:00
|
|
|
archive_handle_t *tar_archive;
|
2002-12-08 08:54:33 +08:00
|
|
|
llist_t *control_tar_llist = NULL;
|
2006-10-04 05:00:06 +08:00
|
|
|
unsigned opt;
|
2008-07-11 07:06:00 +08:00
|
|
|
const char *extract_dir;
|
|
|
|
int need_args;
|
2004-01-07 17:24:06 +08:00
|
|
|
|
2002-09-25 10:47:48 +08:00
|
|
|
/* Setup the tar archive handle */
|
2002-11-05 09:52:23 +08:00
|
|
|
tar_archive = init_handle();
|
2001-06-13 15:26:39 +08:00
|
|
|
|
2004-03-15 16:29:22 +08:00
|
|
|
/* Setup an ar archive handle that refers to the gzip sub archive */
|
2002-09-25 10:47:48 +08:00
|
|
|
ar_archive = init_handle();
|
2002-11-05 09:52:23 +08:00
|
|
|
ar_archive->sub_archive = tar_archive;
|
|
|
|
ar_archive->filter = filter_accept_list_reassign;
|
|
|
|
|
2008-08-05 21:10:34 +08:00
|
|
|
#if ENABLE_FEATURE_SEAMLESS_GZ
|
2007-01-30 06:51:25 +08:00
|
|
|
llist_add_to(&(ar_archive->accept), (char*)"data.tar.gz");
|
|
|
|
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
2002-11-05 09:52:23 +08:00
|
|
|
#endif
|
|
|
|
|
2008-08-05 21:10:34 +08:00
|
|
|
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
2007-01-30 06:51:25 +08:00
|
|
|
llist_add_to(&(ar_archive->accept), (char*)"data.tar.bz2");
|
|
|
|
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
2002-11-05 09:52:23 +08:00
|
|
|
#endif
|
2002-09-25 10:47:48 +08:00
|
|
|
|
2007-11-10 09:32:18 +08:00
|
|
|
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
2007-08-18 23:32:12 +08:00
|
|
|
opt = getopt32(argv, "cefXx");
|
2008-07-11 07:06:00 +08:00
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
2004-01-07 17:24:06 +08:00
|
|
|
|
|
|
|
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
|
|
|
tar_archive->action_header = header_verbose_list;
|
|
|
|
}
|
2008-07-11 07:06:00 +08:00
|
|
|
extract_dir = NULL;
|
|
|
|
need_args = 1;
|
2004-01-07 17:24:06 +08:00
|
|
|
if (opt & DPKG_DEB_OPT_CONTROL) {
|
|
|
|
ar_archive->accept = control_tar_llist;
|
|
|
|
tar_archive->action_data = data_extract_all;
|
2008-07-11 07:06:00 +08:00
|
|
|
if (1 == argc) {
|
2004-01-07 17:24:06 +08:00
|
|
|
extract_dir = "./DEBIAN";
|
|
|
|
} else {
|
2008-07-11 07:06:00 +08:00
|
|
|
need_args++;
|
2001-01-03 07:49:26 +08:00
|
|
|
}
|
|
|
|
}
|
2004-01-07 17:24:06 +08:00
|
|
|
if (opt & DPKG_DEB_OPT_FIELD) {
|
|
|
|
/* Print the entire control file
|
2004-03-15 16:29:22 +08:00
|
|
|
* it should accept a second argument which specifies a
|
2004-01-07 17:24:06 +08:00
|
|
|
* specific field to print */
|
|
|
|
ar_archive->accept = control_tar_llist;
|
2007-01-30 06:51:25 +08:00
|
|
|
llist_add_to(&(tar_archive->accept), (char*)"./control");
|
2004-01-07 17:24:06 +08:00
|
|
|
tar_archive->filter = filter_accept_list;
|
|
|
|
tar_archive->action_data = data_extract_to_stdout;
|
|
|
|
}
|
|
|
|
if (opt & DPKG_DEB_OPT_EXTRACT) {
|
|
|
|
tar_archive->action_header = header_list;
|
|
|
|
}
|
|
|
|
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
|
|
|
|
tar_archive->action_data = data_extract_all;
|
2008-07-11 07:06:00 +08:00
|
|
|
need_args = 2;
|
2004-01-07 17:24:06 +08:00
|
|
|
}
|
2001-01-03 07:49:26 +08:00
|
|
|
|
2008-07-11 07:06:00 +08:00
|
|
|
if (need_args != argc) {
|
2003-03-19 17:13:01 +08:00
|
|
|
bb_show_usage();
|
2001-01-03 07:49:26 +08:00
|
|
|
}
|
2001-04-12 19:48:02 +08:00
|
|
|
|
2008-07-11 07:06:00 +08:00
|
|
|
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
|
2002-09-25 10:47:48 +08:00
|
|
|
|
2008-07-11 07:06:00 +08:00
|
|
|
/* Work out where to extract the files */
|
2002-09-25 10:47:48 +08:00
|
|
|
/* 2nd argument is a dir name */
|
2008-07-11 07:06:00 +08:00
|
|
|
if (argv[1]) {
|
|
|
|
extract_dir = argv[1];
|
2004-01-07 17:24:06 +08:00
|
|
|
}
|
|
|
|
if (extract_dir) {
|
2006-06-10 19:29:44 +08:00
|
|
|
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
|
2006-08-03 23:41:12 +08:00
|
|
|
xchdir(extract_dir);
|
2004-01-07 17:24:06 +08:00
|
|
|
}
|
2008-07-11 07:06:00 +08:00
|
|
|
|
|
|
|
/* Do it */
|
2002-09-25 10:47:48 +08:00
|
|
|
unpack_ar_archive(ar_archive);
|
2001-06-13 15:26:39 +08:00
|
|
|
|
2002-09-25 10:47:48 +08:00
|
|
|
/* Cleanup */
|
2008-07-11 07:06:00 +08:00
|
|
|
if (ENABLE_FEATURE_CLEAN_UP)
|
|
|
|
close(ar_archive->src_fd);
|
2001-04-13 12:02:57 +08:00
|
|
|
|
2006-11-28 00:49:31 +08:00
|
|
|
return EXIT_SUCCESS;
|
2001-01-03 07:49:26 +08:00
|
|
|
}
|