2 const char *__progname;
4 #include <rpm/rpmcli.h>
5 #include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */
6 #include <rpm/rpmlog.h>
14 #if defined(IAM_RPMQ) || defined(IAM_RPMV)
20 MODE_QUERY = (1 << 0),
21 MODE_VERIFY = (1 << 3),
22 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
24 MODE_INSTALL = (1 << 1),
25 MODE_ERASE = (1 << 2),
26 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
31 #define MODES_FOR_NODEPS (MODES_IE | MODE_VERIFY)
32 #define MODES_FOR_TEST (MODES_IE)
36 /* the structure describing the options we take and the defaults */
37 static struct poptOption optionsTable[] = {
40 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0,
41 N_("Query/Verify package selection options:"),
45 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
46 N_("Query options (with -q or --query):"),
50 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
51 N_("Verify options (with -V or --verify):"),
56 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
57 N_("Install/Upgrade/Erase options:"),
59 #endif /* IAM_RPMEIU */
61 { "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, &quiet, 0, NULL, NULL},
63 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
64 N_("Common options for all rpm modes and executables:"),
72 int main(int argc, char *argv[])
75 enum modes bigMode = MODE_UNKNOWN;
77 #if defined(IAM_RPMQV)
78 QVA_t qva = &rpmQVKArgs;
82 struct rpmInstallArguments_s * ia = &rpmIArgs;
91 optCon = rpmcliInit(argc, argv, optionsTable);
93 /* Set the major mode based on argv[0] */
95 if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY;
96 if (rstreq(__progname, "rpmverify")) bigMode = MODE_VERIFY;
99 #if defined(IAM_RPMQV)
100 /* Jumpstart option from argv[0] if necessary. */
102 case MODE_QUERY: qva->qva_mode = 'q'; break;
103 case MODE_VERIFY: qva->qva_mode = 'V'; break;
113 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
114 switch (qva->qva_mode) {
115 case 'q': bigMode = MODE_QUERY; break;
116 case 'V': bigMode = MODE_VERIFY; break;
119 if (qva->qva_sourceCount) {
120 if (qva->qva_sourceCount > 1)
121 argerror(_("one type of query/verify may be performed at a "
124 if (qva->qva_flags && (bigMode & ~MODES_QV))
125 argerror(_("unexpected query flags"));
127 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
128 argerror(_("unexpected query format"));
130 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
131 argerror(_("unexpected query source"));
133 #endif /* IAM_RPMQV */
136 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
137 { int iflags = (ia->installInterfaceFlags &
138 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
139 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
142 argerror(_("only one major mode may be specified"));
144 bigMode = MODE_INSTALL;
146 bigMode = MODE_ERASE;
148 #endif /* IAM_RPMEIU */
150 #if defined(IAM_RPMEIU)
151 if (!( bigMode == MODE_INSTALL ) &&
152 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE)))
153 argerror(_("only installation and upgrading may be forced"));
154 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
155 argerror(_("files may only be relocated during package installation"));
157 if (ia->relocations && ia->prefix)
158 argerror(_("cannot use --prefix with --relocate or --excludepath"));
160 if (bigMode != MODE_INSTALL && ia->relocations)
161 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
163 if (bigMode != MODE_INSTALL && ia->prefix)
164 argerror(_("--prefix may only be used when installing new packages"));
166 if (ia->prefix && ia->prefix[0] != '/')
167 argerror(_("arguments to --prefix must begin with a /"));
169 if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_HASH))
170 argerror(_("--hash (-h) may only be specified during package "
171 "installation and erasure"));
173 if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_PERCENT))
174 argerror(_("--percent may only be specified during package "
175 "installation and erasure"));
177 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
178 argerror(_("--replacepkgs may only be specified during package "
181 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
182 argerror(_("--excludedocs may only be specified during package "
185 if (bigMode != MODE_INSTALL && ia->incldocs)
186 argerror(_("--includedocs may only be specified during package "
189 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
190 argerror(_("only one of --excludedocs and --includedocs may be "
193 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
194 argerror(_("--ignorearch may only be specified during package "
197 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
198 argerror(_("--ignoreos may only be specified during package "
201 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
202 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
203 argerror(_("--ignoresize may only be specified during package "
206 if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
207 argerror(_("--allmatches may only be specified during package "
210 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
211 argerror(_("--allfiles may only be specified during package "
214 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
215 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
216 argerror(_("--justdb may only be specified during package "
217 "installation and erasure"));
219 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
220 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
221 argerror(_("script disabling options may only be specified during "
222 "package installation and erasure"));
224 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
225 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
226 argerror(_("trigger disabling options may only be specified during "
227 "package installation and erasure"));
229 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
230 argerror(_("--nodeps may only be specified during package "
231 "installation, erasure, and verification"));
233 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
234 argerror(_("--test may only be specified during package installation "
236 #endif /* IAM_RPMEIU */
238 if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
239 argerror(_("arguments to --root (-r) must begin with a /"));
243 rpmSetVerbosity(RPMLOG_WARNING);
245 if (rpmcliPipeOutput && initPipe())
249 (void) rpmtsSetRootDir(ts, rpmcliRootDir);
253 if (ia->noDeps) ia->installInterfaceFlags |= UNINSTALL_NODEPS;
255 if (!poptPeekArg(optCon)) {
256 argerror(_("no packages given for erase"));
258 ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon));
264 /* RPMTRANS_FLAG_KEEPOBSOLETE */
267 if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
269 } else if (rpmExpandNumeric("%{_excludedocs}"))
270 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
273 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
275 /* we've already ensured !(!ia->prefix && !ia->relocations) */
277 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
278 ia->relocations[0].oldPath = NULL; /* special case magic */
279 ia->relocations[0].newPath = ia->prefix;
280 ia->relocations[1].oldPath = NULL;
281 ia->relocations[1].newPath = NULL;
282 } else if (ia->relocations) {
283 ia->relocations = xrealloc(ia->relocations,
284 sizeof(*ia->relocations) * (ia->numRelocations + 1));
285 ia->relocations[ia->numRelocations].oldPath = NULL;
286 ia->relocations[ia->numRelocations].newPath = NULL;
289 if (!poptPeekArg(optCon)) {
290 argerror(_("no packages given for install"));
292 /* FIX: ia->relocations[0].newPath undefined */
293 ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon));
297 #endif /* IAM_RPMEIU */
301 if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
302 argerror(_("no arguments given for query"));
304 ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
308 { rpmVerifyFlags verifyFlags = VERIFY_ALL;
310 verifyFlags &= ~qva->qva_flags;
311 qva->qva_flags = (rpmQueryFlags) verifyFlags;
313 if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
314 argerror(_("no arguments given for verify"));
315 ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
317 #endif /* IAM_RPMQV */
319 #if !defined(IAM_RPMQV)
323 #if !defined(IAM_RPMEIU)
328 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
329 printUsage(optCon, stderr, 0);
340 free(qva->qva_queryFormat);
344 if (ia->relocations != NULL) {
345 for (i = 0; i < ia->numRelocations; i++)
346 free(ia->relocations[i].oldPath);
347 free(ia->relocations);