3
0

dpkg_deb.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. *
  16. */
  17. #include <fcntl.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <unistd.h>
  21. #include "unarchive.h"
  22. #include "busybox.h"
  23. #define DPKG_DEB_OPT_CONTENTS 1
  24. #define DPKG_DEB_OPT_CONTROL 2
  25. #define DPKG_DEB_OPT_FIELD 4
  26. #define DPKG_DEB_OPT_EXTRACT 8
  27. #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
  28. int dpkg_deb_main(int argc, char **argv)
  29. {
  30. archive_handle_t *ar_archive;
  31. archive_handle_t *tar_archive;
  32. llist_t *control_tar_llist = NULL;
  33. unsigned long opt;
  34. char *extract_dir = NULL;
  35. short argcount = 1;
  36. /* Setup the tar archive handle */
  37. tar_archive = init_handle();
  38. /* Setup an ar archive handle that refers to the gzip sub archive */
  39. ar_archive = init_handle();
  40. ar_archive->sub_archive = tar_archive;
  41. ar_archive->filter = filter_accept_list_reassign;
  42. #ifdef CONFIG_FEATURE_DEB_TAR_GZ
  43. ar_archive->accept = llist_add_to(NULL, "data.tar.gz");
  44. control_tar_llist = llist_add_to(NULL, "control.tar.gz");
  45. #endif
  46. #ifdef CONFIG_FEATURE_DEB_TAR_BZ2
  47. ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2");
  48. control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2");
  49. #endif
  50. bb_opt_complementally = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
  51. opt = bb_getopt_ulflags(argc, argv, "cefXx");
  52. if (opt & DPKG_DEB_OPT_CONTENTS) {
  53. tar_archive->action_header = header_verbose_list;
  54. }
  55. if (opt & DPKG_DEB_OPT_CONTROL) {
  56. ar_archive->accept = control_tar_llist;
  57. tar_archive->action_data = data_extract_all;
  58. if (optind + 1 == argc) {
  59. extract_dir = "./DEBIAN";
  60. } else {
  61. argcount++;
  62. }
  63. }
  64. if (opt & DPKG_DEB_OPT_FIELD) {
  65. /* Print the entire control file
  66. * it should accept a second argument which specifies a
  67. * specific field to print */
  68. ar_archive->accept = control_tar_llist;
  69. tar_archive->accept = llist_add_to(NULL, "./control");
  70. tar_archive->filter = filter_accept_list;
  71. tar_archive->action_data = data_extract_to_stdout;
  72. }
  73. if (opt & DPKG_DEB_OPT_EXTRACT) {
  74. tar_archive->action_header = header_list;
  75. }
  76. if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
  77. tar_archive->action_data = data_extract_all;
  78. argcount = 2;
  79. }
  80. if ((optind + argcount) != argc) {
  81. bb_show_usage();
  82. }
  83. tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY);
  84. /* Workout where to extract the files */
  85. /* 2nd argument is a dir name */
  86. if (argv[optind]) {
  87. extract_dir = argv[optind];
  88. }
  89. if (extract_dir) {
  90. mkdir(extract_dir, 0777);
  91. chdir(extract_dir);
  92. }
  93. unpack_ar_archive(ar_archive);
  94. /* Cleanup */
  95. close (ar_archive->src_fd);
  96. return(EXIT_SUCCESS);
  97. }