2 * dpkg-deb - construction and deconstruction of *.deb archives
3 * main.c - main program
5 * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2006-2014 Guillem Jover <guillem@debian.org>
8 * This is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 #include <sys/types.h>
39 #include <dpkg/macros.h>
40 #include <dpkg/i18n.h>
41 #include <dpkg/dpkg.h>
42 #include <dpkg/dpkg-db.h>
43 #include <dpkg/compress.h>
44 #include <dpkg/options.h>
48 const char *showformat
= "${Package}\t${Version}\n";
50 static void DPKG_ATTR_NORET
51 printversion(const struct cmdinfo
*cip
, const char *value
)
53 printf(_("Debian '%s' package archive backend version %s.\n"),
54 BACKEND
, PACKAGE_RELEASE
);
56 "This is free software; see the GNU General Public License version 2 or\n"
57 "later for copying conditions. There is NO warranty.\n"));
59 m_output(stdout
, _("<standard output>"));
64 static void DPKG_ATTR_NORET
65 usage(const struct cmdinfo
*cip
, const char *value
)
68 "Usage: %s [<option>...] <command>\n"
73 " -b|--build <directory> [<deb>] Build an archive.\n"
74 " -c|--contents <deb> List contents.\n"
75 " -I|--info <deb> [<cfile>...] Show info to stdout.\n"
76 " -W|--show <deb> Show information on package(s)\n"
77 " -f|--field <deb> [<cfield>...] Show field(s) to stdout.\n"
78 " -e|--control <deb> [<directory>] Extract control info.\n"
79 " -x|--extract <deb> <directory> Extract files.\n"
80 " -X|--vextract <deb> <directory> Extract & list files.\n"
81 " -R|--raw-extract <deb> <directory>\n"
82 " Extract control info and files.\n"
83 " --ctrl-tarfile <deb> Output control tarfile.\n"
84 " --fsys-tarfile <deb> Output filesystem tarfile.\n"
88 " -?, --help Show this help message.\n"
89 " --version Show the version.\n"
93 "<deb> is the filename of a Debian format archive.\n"
94 "<cfile> is the name of an administrative file component.\n"
95 "<cfield> is the name of a field in the main 'control' file.\n"
100 " -v, --verbose Enable verbose output.\n"
101 " -D, --debug Enable debugging output.\n"
102 " --showformat=<format> Use alternative format for --show.\n"
103 " --deb-format=<format> Select archive format.\n"
104 " Allowed values: 0.939000, 2.0 (default).\n"
105 " --nocheck Suppress control file check (build bad\n"
107 " --root-owner-group Forces the owner and groups to root.\n"
108 " --[no-]uniform-compression Use the compression params on all members.\n"
109 " -z# Set the compression level when building.\n"
110 " -Z<type> Set the compression type used when building.\n"
111 " Allowed types: gzip, xz, none.\n"
112 " -S<strategy> Set the compression strategy when building.\n"
113 " Allowed values: none; extreme (xz);\n"
114 " filtered, huffman, rle, fixed (gzip).\n"
119 " A format is a string that will be output for each package. The format\n"
120 " can include the standard escape sequences \\n (newline), \\r (carriage\n"
121 " return) or \\\\ (plain backslash). Package information can be included\n"
122 " by inserting variable references to package fields using the ${var[;width]}\n"
123 " syntax. Fields will be right-aligned unless the width is negative in which\n"
124 " case left alignment will be used.\n"));
128 "Use 'dpkg' to install and remove packages from your system, or\n"
129 "'apt' or 'aptitude' for user-friendly package management. Packages\n"
130 "unpacked using 'dpkg-deb --extract' will be incorrectly installed !\n"));
132 m_output(stdout
, _("<standard output>"));
137 static const char printforhelp
[] =
138 N_("Type dpkg-deb --help for help about manipulating *.deb files;\n"
139 "Type dpkg --help for help about installing and deinstalling packages.");
144 int opt_root_owner_group
= 0;
145 int opt_uniform_compression
= 1;
147 struct deb_version deb_format
= DEB_VERSION(2, 0);
150 set_deb_format(const struct cmdinfo
*cip
, const char *value
)
154 err
= deb_version_parse(&deb_format
, value
);
156 badusage(_("invalid deb format version: %s"), err
);
158 if ((deb_format
.major
== 2 && deb_format
.minor
== 0) ||
159 (deb_format
.major
== 0 && deb_format
.minor
== 939000))
162 badusage(_("unknown deb format version: %s"), value
);
165 struct compress_params compress_params
= {
166 .type
= DPKG_DEB_DEFAULT_COMPRESSOR
,
167 .strategy
= COMPRESSOR_STRATEGY_NONE
,
172 set_compress_level(const struct cmdinfo
*cip
, const char *value
)
176 level
= dpkg_options_parse_arg_int(cip
, value
);
177 if (level
< 0 || level
> 9)
178 badusage(_("invalid compression level for -%c: %ld"), cip
->oshort
, level
);
180 compress_params
.level
= level
;
184 set_compress_strategy(const struct cmdinfo
*cip
, const char *value
)
186 compress_params
.strategy
= compressor_get_strategy(value
);
187 if (compress_params
.strategy
== COMPRESSOR_STRATEGY_UNKNOWN
)
188 badusage(_("unknown compression strategy '%s'!"), value
);
192 set_compress_type(const struct cmdinfo
*cip
, const char *value
)
194 compress_params
.type
= compressor_find_by_name(value
);
195 if (compress_params
.type
== COMPRESSOR_TYPE_UNKNOWN
)
196 badusage(_("unknown compression type '%s'!"), value
);
197 if (compress_params
.type
== COMPRESSOR_TYPE_LZMA
)
198 badusage(_("obsolete compression type '%s'; use xz instead"), value
);
199 if (compress_params
.type
== COMPRESSOR_TYPE_BZIP2
)
200 badusage(_("obsolete compression type '%s'; use xz or gzip instead"), value
);
203 static const struct cmdinfo cmdinfos
[]= {
204 ACTION("build", 'b', 0, do_build
),
205 ACTION("contents", 'c', 0, do_contents
),
206 ACTION("control", 'e', 0, do_control
),
207 ACTION("info", 'I', 0, do_info
),
208 ACTION("field", 'f', 0, do_field
),
209 ACTION("extract", 'x', 0, do_extract
),
210 ACTION("vextract", 'X', 0, do_vextract
),
211 ACTION("raw-extract", 'R', 0, do_raw_extract
),
212 ACTION("ctrl-tarfile", 0, 0, do_ctrltarfile
),
213 ACTION("fsys-tarfile", 0, 0, do_fsystarfile
),
214 ACTION("show", 'W', 0, do_showinfo
),
216 { "deb-format", 0, 1, NULL
, NULL
, set_deb_format
},
217 { "debug", 'D', 0, &debugflag
, NULL
, NULL
, 1 },
218 { "verbose", 'v', 0, &opt_verbose
, NULL
, NULL
, 1 },
219 { "nocheck", 0, 0, &nocheckflag
, NULL
, NULL
, 1 },
220 { "root-owner-group", 0, 0, &opt_root_owner_group
, NULL
, NULL
, 1 },
221 { "uniform-compression", 0, 0, &opt_uniform_compression
, NULL
, NULL
, 1 },
222 { "no-uniform-compression", 0, 0, &opt_uniform_compression
, NULL
, NULL
, 0 },
223 { NULL
, 'z', 1, NULL
, NULL
, set_compress_level
},
224 { NULL
, 'Z', 1, NULL
, NULL
, set_compress_type
},
225 { NULL
, 'S', 1, NULL
, NULL
, set_compress_strategy
},
226 { "showformat", 0, 1, NULL
, &showformat
, NULL
},
227 { "help", '?', 0, NULL
, NULL
, usage
},
228 { "version", 0, 0, NULL
, NULL
, printversion
},
229 { NULL
, 0, 0, NULL
, NULL
, NULL
}
232 int main(int argc
, const char *const *argv
) {
233 struct dpkg_error err
;
236 dpkg_locales_init(PACKAGE
);
237 dpkg_program_init(BACKEND
);
238 dpkg_options_parse(&argv
, cmdinfos
, printforhelp
);
240 if (!cipaction
) badusage(_("need an action option"));
242 if (!compressor_check_params(&compress_params
, &err
))
243 badusage(_("invalid compressor parameters: %s"), err
.str
);
245 if (opt_uniform_compression
&&
246 (compress_params
.type
!= COMPRESSOR_TYPE_NONE
&&
247 compress_params
.type
!= COMPRESSOR_TYPE_GZIP
&&
248 compress_params
.type
!= COMPRESSOR_TYPE_XZ
))
249 badusage(_("unsupported compression type '%s' with uniform compression"),
250 compressor_get_name(compress_params
.type
));
252 ret
= cipaction
->action(argv
);