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