main.c 7.9 KB

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