main.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * dpkg-deb - construction and deconstruction of *.deb archives
  3. * main.c - main program
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <signal.h>
  26. #include <sys/stat.h>
  27. #include <sys/types.h>
  28. #include <sys/wait.h>
  29. #include <errno.h>
  30. #include <unistd.h>
  31. #include <dirent.h>
  32. #include <limits.h>
  33. #include <ctype.h>
  34. #include <assert.h>
  35. #include <dpkg.h>
  36. #include <dpkg-db.h>
  37. #include <myopt.h>
  38. #include "dpkg-deb.h"
  39. const char* showformat = "${Package}\t${Version}\n";
  40. void
  41. printversion(void)
  42. {
  43. if (printf(_("Debian `%s' package archive backend version %s.\n"),
  44. BACKEND, DPKG_VERSION_ARCH) < 0) werr("stdout");
  45. if (printf(_("This is free software; see the GNU General Public License version 2 or\n"
  46. "later for copying conditions. There is NO warranty.\n"
  47. "See %s --license for copyright and license details.\n"),
  48. BACKEND) < 0) werr("stdout");
  49. }
  50. void
  51. usage(void)
  52. {
  53. if (printf(_(
  54. "Usage: %s [<option> ...] <command>\n"
  55. "\n"), BACKEND) < 0) werr("stdout");
  56. if (printf(_(
  57. "Commands:\n"
  58. " -b|--build <directory> [<deb>] Build an archive.\n"
  59. " -c|--contents <deb> List contents.\n"
  60. " -I|--info <deb> [<cfile> ...] Show info to stdout.\n"
  61. " -W|--show <deb> Show information on package(s)\n"
  62. " -f|--field <deb> [<cfield> ...] Show field(s) to stdout.\n"
  63. " -e|--control <deb> [<directory>] Extract control info.\n"
  64. " -x|--extract <deb> <directory> Extract files.\n"
  65. " -X|--vextract <deb> <directory> Extract & list files.\n"
  66. " --fsys-tarfile <deb> Output filesystem tarfile.\n"
  67. "\n")) < 0) werr("stdout");
  68. if (printf(_(
  69. " -h|--help Show this help message.\n"
  70. " --version Show the version.\n"
  71. " --license|--licence Show the copyright licensing terms.\n"
  72. "\n")) < 0) werr("stdout");
  73. if (printf(_(
  74. "<deb> is the filename of a Debian format archive.\n"
  75. "<cfile> is the name of an administrative file component.\n"
  76. "<cfield> is the name of a field in the main `control' file.\n"
  77. "\n")) < 0) werr("stdout");
  78. if (printf(_(
  79. "Options:\n"
  80. " --showformat=<format> Use alternative format for --show.\n"
  81. " -D Enable debugging output.\n"
  82. " --old, --new Select archive format.\n"
  83. " --nocheck Suppress control file check (build bad\n"
  84. " packages).\n"
  85. " -z# Set the compression level when building.\n"
  86. " -Z<type> Set the compression type used when building.\n"
  87. " Allowed values: gzip, bzip2, lzma, none.\n"
  88. "\n")) < 0) werr("stdout");
  89. if (printf(_(
  90. "Format syntax:\n"
  91. " A format is a string that will be output for each package. The format\n"
  92. " can include the standard escape sequences \\n (newline), \\r (carriage\n"
  93. " return) or \\\\ (plain backslash). Package information can be included\n"
  94. " by inserting variable references to package fields using the ${var[;width]}\n"
  95. " syntax. Fields will be right-aligned unless the width is negative in which\n"
  96. " case left alignment will be used.\n")) < 0) werr("stdout");
  97. if (printf(_(
  98. "\n"
  99. "Use `dpkg' to install and remove packages from your system, or\n"
  100. "`dselect' or `aptitude' for user-friendly package management. Packages\n"
  101. "unpacked using `dpkg-deb --extract' will be incorrectly installed !\n")) < 0)
  102. werr("stdout");
  103. }
  104. const char thisname[]= BACKEND;
  105. const char printforhelp[]=
  106. N_("Type dpkg-deb --help for help about manipulating *.deb files;\n"
  107. "Type dpkg --help for help about installing and deinstalling packages.");
  108. int debugflag=0, nocheckflag=0, oldformatflag=BUILDOLDPKGFORMAT;
  109. const char* compression=NULL;
  110. enum compress_type compress_type = compress_type_gzip;
  111. const struct cmdinfo *cipaction = NULL;
  112. dofunction *action = NULL;
  113. static void setaction(const struct cmdinfo *cip, const char *value);
  114. static void setcompresstype(const struct cmdinfo *cip, const char *value);
  115. static dofunction *const dofunctions[]= {
  116. do_build,
  117. do_contents,
  118. do_control,
  119. do_info,
  120. do_field,
  121. do_extract,
  122. do_vextract,
  123. do_fsystarfile,
  124. do_showinfo
  125. };
  126. /* NB: the entries using setaction must appear first and be in the
  127. * same order as dofunctions:
  128. */
  129. static const struct cmdinfo cmdinfos[]= {
  130. { "build", 'b', 0, NULL, NULL, setaction },
  131. { "contents", 'c', 0, NULL, NULL, setaction },
  132. { "control", 'e', 0, NULL, NULL, setaction },
  133. { "info", 'I', 0, NULL, NULL, setaction },
  134. { "field", 'f', 0, NULL, NULL, setaction },
  135. { "extract", 'x', 0, NULL, NULL, setaction },
  136. { "vextract", 'X', 0, NULL, NULL, setaction },
  137. { "fsys-tarfile", 0, 0, NULL, NULL, setaction },
  138. { "show", 'W', 0, NULL, NULL, setaction },
  139. { "new", 0, 0, &oldformatflag, NULL, NULL, 0 },
  140. { "old", 0, 0, &oldformatflag, NULL, NULL, 1 },
  141. { "debug", 'D', 0, &debugflag, NULL, NULL, 1 },
  142. { "nocheck", 0, 0, &nocheckflag, NULL, NULL, 1 },
  143. { "compression", 'z', 1, NULL, &compression, NULL, 1 },
  144. { "compress_type", 'Z', 1, NULL, NULL, setcompresstype },
  145. { "showformat", 0, 1, NULL, &showformat, NULL },
  146. { "help", 'h', 0, NULL, NULL, helponly },
  147. { "version", 0, 0, NULL, NULL, versiononly },
  148. /* UK spelling. */
  149. { "licence", 0, 0, NULL, NULL, showcopyright },
  150. /* US spelling. */
  151. { "license", 0, 0, NULL, NULL, showcopyright },
  152. { NULL, 0, 0, NULL, NULL, NULL }
  153. };
  154. static void setaction(const struct cmdinfo *cip, const char *value) {
  155. if (cipaction)
  156. badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),
  157. cip->oshort, cip->olong, cipaction->oshort, cipaction->olong);
  158. cipaction= cip;
  159. assert((int)(cip-cmdinfos) < (int)(sizeof(dofunctions)*sizeof(dofunction*)));
  160. action= dofunctions[cip-cmdinfos];
  161. }
  162. static void setcompresstype(const struct cmdinfo *cip, const char *value) {
  163. if (!strcmp(value, "gzip"))
  164. compress_type = compress_type_gzip;
  165. else if (!strcmp(value, "bzip2"))
  166. compress_type = compress_type_bzip2;
  167. else if (!strcmp(value, "lzma"))
  168. compress_type = compress_type_lzma;
  169. else if (!strcmp(value, "none"))
  170. compress_type = compress_type_cat;
  171. else
  172. ohshit(_("unknown compression type `%s'!"), value);
  173. }
  174. int main(int argc, const char *const *argv) {
  175. jmp_buf ejbuf;
  176. setlocale(LC_NUMERIC, "POSIX");
  177. standard_startup(&ejbuf, argc, &argv, NULL, NULL, cmdinfos);
  178. if (!cipaction) badusage(_("need an action option"));
  179. unsetenv("GZIP");
  180. action(argv);
  181. standard_shutdown(NULL);
  182. exit(0);
  183. }
  184. /* vi: sw=2
  185. */