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