main.c 7.9 KB

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