main.c 7.5 KB

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