Imported Upstream version 4.14.1
[platform/upstream/rpm.git] / lib / poptI.c
1 /** \ingroup rpmcli
2  * \file lib/poptI.c
3  *  Popt tables for install modes.
4  */
5
6 #include "system.h"
7
8 #include <rpm/rpmcli.h>
9
10 #include "debug.h"
11
12 struct rpmInstallArguments_s rpmIArgs = {
13     0,                  /* transFlags */
14     0,                  /* probFilter */
15     0,                  /* installInterfaceFlags */
16     0,                  /* numRelocations */
17     0,                  /* noDeps */
18     0,                  /* incldocs */
19     NULL,               /* relocations */
20     NULL,               /* prefix */
21 };
22
23 #define POPT_RELOCATE           -1021
24 #define POPT_EXCLUDEPATH        -1022
25
26 RPM_GNUC_NORETURN
27 static void argerror(const char * desc)
28 {
29     fprintf(stderr, _("%s: %s\n"), xgetprogname(), desc);
30     exit(EXIT_FAILURE);
31 }
32
33 /**
34  */
35 static void installArgCallback( poptContext con,
36                 enum poptCallbackReason reason,
37                 const struct poptOption * opt, const char * arg,
38                 const void * data)
39 {
40     struct rpmInstallArguments_s * ia = &rpmIArgs;
41
42     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
43     if (opt->arg == NULL)
44     switch (opt->val) {
45
46     case 'i':
47         ia->installInterfaceFlags |= INSTALL_INSTALL;
48         break;
49
50     case POPT_EXCLUDEPATH:
51         if (arg == NULL || *arg != '/') 
52             argerror(_("exclude paths must begin with a /"));
53         ia->relocations = xrealloc(ia->relocations, 
54                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
55         ia->relocations[ia->numRelocations].oldPath = xstrdup(arg);
56         ia->relocations[ia->numRelocations].newPath = NULL;
57         ia->numRelocations++;
58         break;
59     case POPT_RELOCATE:
60       { char * oldPath = NULL;
61         char * newPath = NULL;
62         
63         if (arg == NULL || *arg != '/') 
64             argerror(_("relocations must begin with a /"));
65         oldPath = xstrdup(arg);
66         if (!(newPath = strchr(oldPath, '=')))
67             argerror(_("relocations must contain a ="));
68         *newPath++ = '\0';
69         if (*newPath != '/') 
70             argerror(_("relocations must have a / following the ="));
71         ia->relocations = xrealloc(ia->relocations, 
72                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
73         ia->relocations[ia->numRelocations].oldPath = oldPath;
74         ia->relocations[ia->numRelocations].newPath = newPath;
75         ia->numRelocations++;
76       } break;
77
78     case RPMCLI_POPT_NODEPS:
79         ia->noDeps = 1;
80         break;
81
82     case RPMCLI_POPT_NOFILEDIGEST:
83         ia->transFlags |= RPMTRANS_FLAG_NOFILEDIGEST;
84         break;
85
86     case RPMCLI_POPT_NOCONTEXTS:
87         ia->transFlags |= RPMTRANS_FLAG_NOCONTEXTS;
88         break;
89
90     case RPMCLI_POPT_NOCAPS:
91         ia->transFlags |= RPMTRANS_FLAG_NOCAPS;
92         break;
93
94     case RPMCLI_POPT_FORCE:
95         ia->probFilter |=
96                 ( RPMPROB_FILTER_REPLACEPKG
97                 | RPMPROB_FILTER_REPLACEOLDFILES
98                 | RPMPROB_FILTER_REPLACENEWFILES
99                 | RPMPROB_FILTER_OLDPACKAGE );
100         break;
101
102     case RPMCLI_POPT_NOSCRIPTS:
103         ia->transFlags |= (_noTransScripts | _noTransTriggers);
104         break;
105
106     }
107 }
108
109 /**
110  */
111 struct poptOption rpmInstallPoptTable[] = {
112 /* FIX: cast? */
113  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
114         installArgCallback, 0, NULL, NULL },
115
116  { "allfiles", '\0', POPT_BIT_SET,
117         &rpmIArgs.transFlags, RPMTRANS_FLAG_ALLFILES,
118   N_("install all files, even configurations which might otherwise be skipped"),
119         NULL},
120  { "allmatches", '\0', POPT_BIT_SET,
121         &rpmIArgs.installInterfaceFlags, UNINSTALL_ALLMATCHES,
122         N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
123         NULL},
124
125  { "badreloc", '\0', POPT_BIT_SET,
126         &rpmIArgs.probFilter, RPMPROB_FILTER_FORCERELOCATE,
127         N_("relocate files in non-relocatable package"), NULL},
128
129  { "deploops", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
130         &rpmIArgs.transFlags, RPMTRANS_FLAG_DEPLOOPS,
131         N_("print dependency loops as warning"), NULL},
132
133  { "erase", 'e', POPT_BIT_SET,
134         &rpmIArgs.installInterfaceFlags, INSTALL_ERASE,
135         N_("erase (uninstall) package"), N_("<package>+") },
136  { "excludeconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
137         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONFIGS,
138         N_("do not install configuration files"), NULL},
139  { "excludedocs", '\0', POPT_BIT_SET,
140         &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
141         N_("do not install documentation"), NULL},
142  { "excludepath", '\0', POPT_ARG_STRING, 0, POPT_EXCLUDEPATH,
143         N_("skip files with leading component <path> "),
144         N_("<path>") },
145
146  { "force", '\0', 0, NULL, RPMCLI_POPT_FORCE,
147         N_("short hand for --replacepkgs --replacefiles"), NULL},
148
149  { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
150         (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL),
151         N_("upgrade package(s) if already installed"),
152         N_("<packagefile>+") },
153  { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
154         N_("print hash marks as package installs (good with -v)"), NULL},
155  { "ignorearch", '\0', POPT_BIT_SET,
156         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREARCH,
157         N_("don't verify package architecture"), NULL},
158  { "ignoreos", '\0', POPT_BIT_SET,
159         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREOS,
160         N_("don't verify package operating system"), NULL},
161  { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
162         (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES),
163         N_("don't check disk space before installing"), NULL},
164  { "includedocs", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.incldocs, 0,
165         N_("install documentation"), NULL},
166
167  { "install", 'i', 0, NULL, 'i',
168         N_("install package(s)"), N_("<packagefile>+") },
169
170  { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
171         N_("update the database, but do not modify the filesystem"), NULL},
172
173  { "noconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
174         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONFIGS,
175         N_("do not install configuration files"), NULL},
176  { "nodeps", '\0', 0, NULL, RPMCLI_POPT_NODEPS,
177         N_("do not verify package dependencies"), NULL },
178  { "nodocs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
179         &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
180         N_("do not install documentation"), NULL},
181
182  { "nofiledigest", '\0', 0, NULL, RPMCLI_POPT_NOFILEDIGEST,
183         N_("don't verify digest of files"), NULL },
184  { "nomd5", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOFILEDIGEST,
185         N_("don't verify digest of files (obsolete)"), NULL },
186  { "nocontexts", '\0',0,  NULL, RPMCLI_POPT_NOCONTEXTS,
187         N_("don't install file security contexts"), NULL},
188  { "nocaps", '\0',0,  NULL, RPMCLI_POPT_NOCAPS,
189         N_("don't install file capabilities"), NULL},
190
191  { "noorder", '\0', POPT_BIT_SET,
192         &rpmIArgs.installInterfaceFlags, INSTALL_NOORDER,
193         N_("do not reorder package installation to satisfy dependencies"),
194         NULL},
195
196  { "noscripts", '\0', 0, NULL, RPMCLI_POPT_NOSCRIPTS,
197         N_("do not execute package scriptlet(s)"), NULL },
198
199  { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
200         RPMTRANS_FLAG_NOPRE,
201         N_("do not execute %%pre scriptlet (if any)"), NULL },
202  { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
203         RPMTRANS_FLAG_NOPOST,
204         N_("do not execute %%post scriptlet (if any)"), NULL },
205  { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
206         RPMTRANS_FLAG_NOPREUN,
207         N_("do not execute %%preun scriptlet (if any)"), NULL },
208  { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
209         RPMTRANS_FLAG_NOPOSTUN,
210         N_("do not execute %%postun scriptlet (if any)"), NULL },
211  { "nopretrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
212         RPMTRANS_FLAG_NOPRETRANS,
213         N_("do not execute %%pretrans scriptlet (if any)"), NULL },
214  { "noposttrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
215         RPMTRANS_FLAG_NOPOSTTRANS,
216         N_("do not execute %%posttrans scriptlet (if any)"), NULL },
217
218  { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, _noTransTriggers,
219         N_("do not execute any scriptlet(s) triggered by this package"), NULL},
220  { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
221         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPREIN,
222         N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
223  { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
224         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERIN,
225         N_("do not execute any %%triggerin scriptlet(s)"), NULL},
226  { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
227         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERUN,
228         N_("do not execute any %%triggerun scriptlet(s)"), NULL},
229  { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
230         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPOSTUN,
231         N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
232
233  { "oldpackage", '\0', POPT_BIT_SET,
234         &rpmIArgs.probFilter, RPMPROB_FILTER_OLDPACKAGE,
235         N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
236         NULL},
237  { "percent", '\0', POPT_BIT_SET,
238         &rpmIArgs.installInterfaceFlags, INSTALL_PERCENT,
239         N_("print percentages as package installs"), NULL},
240  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.prefix, 0,
241         N_("relocate the package to <dir>, if relocatable"),
242         N_("<dir>") },
243  { "relocate", '\0', POPT_ARG_STRING, 0, POPT_RELOCATE,
244         N_("relocate files from path <old> to <new>"),
245         N_("<old>=<new>") },
246  { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
247         (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
248         N_("ignore file conflicts between packages"), NULL},
249  { "replacepkgs", '\0', POPT_BIT_SET,
250         &rpmIArgs.probFilter, RPMPROB_FILTER_REPLACEPKG,
251         N_("reinstall if the package is already present"), NULL},
252  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
253         N_("don't install, but tell if it would work or not"), NULL},
254  { "upgrade", 'U', POPT_BIT_SET,
255         &rpmIArgs.installInterfaceFlags, (INSTALL_UPGRADE|INSTALL_INSTALL),
256         N_("upgrade package(s)"),
257         N_("<packagefile>+") },
258  { "reinstall", '\0', POPT_BIT_SET,
259         &rpmIArgs.installInterfaceFlags, (INSTALL_REINSTALL|INSTALL_INSTALL),
260         N_("reinstall package(s)"),
261         N_("<packagefile>+") },
262
263    POPT_TABLEEND
264 };