main.c 7.8 KB

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