2000-08-28 03:18:25 +08:00
|
|
|
/** \ingroup rpmbuild
|
|
|
|
* \file build/parseScript.c
|
2000-01-25 04:02:32 +08:00
|
|
|
* Parse install-time script section from spec file.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2008-02-03 22:24:07 +08:00
|
|
|
#include <rpm/header.h>
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmlog.h>
|
1998-07-31 06:09:42 +08:00
|
|
|
|
2007-11-23 18:37:54 +08:00
|
|
|
#include "rpmio/rpmlua.h"
|
2010-03-11 18:06:49 +08:00
|
|
|
#include "lib/rpmscript.h" /* script flags */
|
2010-08-25 20:41:09 +08:00
|
|
|
#include "build/rpmbuild_internal.h"
|
|
|
|
#include "build/rpmbuild_misc.h"
|
2004-03-17 05:58:25 +08:00
|
|
|
|
2008-01-30 23:05:29 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
2016-11-11 18:59:50 +08:00
|
|
|
#define SKIPSPACE(s) { while (*(s) && risspace(*(s))) (s)++; }
|
2008-01-30 23:05:29 +08:00
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-06-04 21:55:58 +08:00
|
|
|
static int addTriggerIndex(Package pkg, const char *file,
|
2014-07-02 19:26:49 +08:00
|
|
|
const char *script, const char *prog, rpmscriptFlags flags,
|
2015-05-04 22:29:46 +08:00
|
|
|
rpmTagVal tag, uint32_t priority)
|
1999-04-02 06:26:44 +08:00
|
|
|
{
|
2001-06-04 21:55:58 +08:00
|
|
|
struct TriggerFileEntry *tfe;
|
2014-07-02 19:26:49 +08:00
|
|
|
struct TriggerFileEntry *list;
|
1999-04-02 06:26:44 +08:00
|
|
|
struct TriggerFileEntry *last = NULL;
|
|
|
|
int index = 0;
|
2014-07-02 19:26:49 +08:00
|
|
|
struct TriggerFileEntry **tfp;
|
|
|
|
|
|
|
|
if (tag == RPMTAG_FILETRIGGERSCRIPTS) {
|
|
|
|
tfp = &pkg->fileTriggerFiles;
|
|
|
|
} else if (tag == RPMTAG_TRANSFILETRIGGERSCRIPTS) {
|
|
|
|
tfp = &pkg->transFileTriggerFiles;
|
|
|
|
} else {
|
|
|
|
tfp = &pkg->triggerFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = *tfp;
|
1999-04-02 06:26:44 +08:00
|
|
|
|
|
|
|
while (list) {
|
|
|
|
last = list;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
2001-09-25 05:53:14 +08:00
|
|
|
if (last)
|
1999-04-02 06:26:44 +08:00
|
|
|
index = last->index + 1;
|
|
|
|
|
2001-09-25 05:53:14 +08:00
|
|
|
tfe = xcalloc(1, sizeof(*tfe));
|
1999-04-02 06:26:44 +08:00
|
|
|
|
2001-06-04 21:55:58 +08:00
|
|
|
tfe->fileName = (file) ? xstrdup(file) : NULL;
|
|
|
|
tfe->script = (script && *script != '\0') ? xstrdup(script) : NULL;
|
|
|
|
tfe->prog = xstrdup(prog);
|
2010-03-11 18:06:49 +08:00
|
|
|
tfe->flags = flags;
|
2001-06-04 21:55:58 +08:00
|
|
|
tfe->index = index;
|
2015-05-04 22:29:46 +08:00
|
|
|
tfe->priority = priority;
|
2001-06-04 21:55:58 +08:00
|
|
|
tfe->next = NULL;
|
1999-04-02 06:26:44 +08:00
|
|
|
|
2001-09-25 05:53:14 +08:00
|
|
|
if (last)
|
2001-06-04 21:55:58 +08:00
|
|
|
last->next = tfe;
|
2001-09-25 05:53:14 +08:00
|
|
|
else
|
2014-07-02 19:26:49 +08:00
|
|
|
*tfp = tfe;
|
1999-04-02 06:26:44 +08:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
/* %trigger is a strange combination of %pre and Requires: behavior */
|
|
|
|
/* We can handle it by parsing the args before "--" in parseScript. */
|
1999-06-17 23:44:47 +08:00
|
|
|
/* We then pass the remaining arguments to parseRCPOT, along with */
|
1998-03-21 06:38:00 +08:00
|
|
|
/* an index we just determined. */
|
|
|
|
|
2007-09-21 20:23:02 +08:00
|
|
|
int parseScript(rpmSpec spec, int parsePart)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
|
|
|
/* There are a few options to scripts: */
|
|
|
|
/* <pkg> */
|
|
|
|
/* -n <pkg> */
|
|
|
|
/* -p <sh> */
|
|
|
|
/* -p "<sh> <args>..." */
|
|
|
|
/* -f <file> */
|
|
|
|
|
2010-10-28 16:47:29 +08:00
|
|
|
const char *p;
|
1999-10-28 07:18:10 +08:00
|
|
|
const char **progArgv = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
int progArgc;
|
2007-12-14 21:17:59 +08:00
|
|
|
const char *partname = NULL;
|
2010-10-22 18:46:14 +08:00
|
|
|
rpmTagVal reqtag = 0;
|
|
|
|
rpmTagVal tag = 0;
|
2008-01-30 22:04:40 +08:00
|
|
|
rpmsenseFlags tagflags = 0;
|
2010-10-22 18:46:14 +08:00
|
|
|
rpmTagVal progtag = 0;
|
|
|
|
rpmTagVal flagtag = 0;
|
2010-03-11 18:06:49 +08:00
|
|
|
rpmscriptFlags scriptFlags = 0;
|
1998-01-13 05:31:29 +08:00
|
|
|
int flag = PART_SUBNAME;
|
|
|
|
Package pkg;
|
2000-11-12 19:11:49 +08:00
|
|
|
StringBuf sb = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
int nextPart;
|
1998-03-21 06:38:00 +08:00
|
|
|
int index;
|
2008-05-05 16:53:48 +08:00
|
|
|
char * reqargs = NULL;
|
1998-03-05 00:51:06 +08:00
|
|
|
|
2008-05-05 15:56:55 +08:00
|
|
|
int res = PART_ERROR; /* assume failure */
|
1998-01-13 05:31:29 +08:00
|
|
|
int rc, argc;
|
1998-04-03 02:31:12 +08:00
|
|
|
int arg;
|
1999-10-28 07:18:10 +08:00
|
|
|
const char **argv = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
poptContext optCon = NULL;
|
2008-12-09 19:47:50 +08:00
|
|
|
const char *name = NULL;
|
|
|
|
const char *prog = "/bin/sh";
|
|
|
|
const char *file = NULL;
|
2015-05-04 22:29:46 +08:00
|
|
|
int priority = 1000000;
|
2008-12-09 19:47:50 +08:00
|
|
|
struct poptOption optionsTable[] = {
|
|
|
|
{ NULL, 'p', POPT_ARG_STRING, &prog, 'p', NULL, NULL},
|
|
|
|
{ NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
|
|
|
|
{ NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL},
|
2011-09-12 18:26:42 +08:00
|
|
|
{ NULL, 'e', POPT_BIT_SET, &scriptFlags, RPMSCRIPT_FLAG_EXPAND,
|
|
|
|
NULL, NULL},
|
|
|
|
{ NULL, 'q', POPT_BIT_SET, &scriptFlags, RPMSCRIPT_FLAG_QFORMAT,
|
|
|
|
NULL, NULL},
|
2015-11-25 17:08:29 +08:00
|
|
|
{ NULL, 'P', POPT_ARG_INT, &priority, 'P', NULL, NULL},
|
2008-12-09 19:47:50 +08:00
|
|
|
{ 0, 0, 0, 0, 0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
switch (parsePart) {
|
|
|
|
case PART_PRE:
|
|
|
|
tag = RPMTAG_PREIN;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = RPMSENSE_SCRIPT_PRE;
|
1998-01-13 05:31:29 +08:00
|
|
|
progtag = RPMTAG_PREINPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_PREINFLAGS;
|
1998-01-13 05:31:29 +08:00
|
|
|
partname = "%pre";
|
|
|
|
break;
|
|
|
|
case PART_POST:
|
|
|
|
tag = RPMTAG_POSTIN;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = RPMSENSE_SCRIPT_POST;
|
1998-01-13 05:31:29 +08:00
|
|
|
progtag = RPMTAG_POSTINPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_POSTINFLAGS;
|
1998-01-13 05:31:29 +08:00
|
|
|
partname = "%post";
|
|
|
|
break;
|
|
|
|
case PART_PREUN:
|
|
|
|
tag = RPMTAG_PREUN;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = RPMSENSE_SCRIPT_PREUN;
|
1998-01-13 05:31:29 +08:00
|
|
|
progtag = RPMTAG_PREUNPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_PREUNFLAGS;
|
1998-01-13 05:31:29 +08:00
|
|
|
partname = "%preun";
|
|
|
|
break;
|
|
|
|
case PART_POSTUN:
|
|
|
|
tag = RPMTAG_POSTUN;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = RPMSENSE_SCRIPT_POSTUN;
|
1998-01-13 05:31:29 +08:00
|
|
|
progtag = RPMTAG_POSTUNPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_POSTUNFLAGS;
|
1998-01-13 05:31:29 +08:00
|
|
|
partname = "%postun";
|
|
|
|
break;
|
2004-03-17 05:58:25 +08:00
|
|
|
case PART_PRETRANS:
|
|
|
|
tag = RPMTAG_PRETRANS;
|
2010-03-29 13:58:27 +08:00
|
|
|
tagflags = RPMSENSE_PRETRANS;
|
2004-03-17 05:58:25 +08:00
|
|
|
progtag = RPMTAG_PRETRANSPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_PRETRANSFLAGS;
|
2004-03-17 05:58:25 +08:00
|
|
|
partname = "%pretrans";
|
|
|
|
break;
|
|
|
|
case PART_POSTTRANS:
|
|
|
|
tag = RPMTAG_POSTTRANS;
|
2011-01-25 21:27:28 +08:00
|
|
|
tagflags = RPMSENSE_POSTTRANS;
|
2004-03-17 05:58:25 +08:00
|
|
|
progtag = RPMTAG_POSTTRANSPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_POSTTRANSFLAGS;
|
2004-03-17 05:58:25 +08:00
|
|
|
partname = "%posttrans";
|
|
|
|
break;
|
1998-01-13 05:31:29 +08:00
|
|
|
case PART_VERIFYSCRIPT:
|
1999-04-21 03:17:23 +08:00
|
|
|
tag = RPMTAG_VERIFYSCRIPT;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = RPMSENSE_SCRIPT_VERIFY;
|
1998-01-13 05:31:29 +08:00
|
|
|
progtag = RPMTAG_VERIFYSCRIPTPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_VERIFYSCRIPTFLAGS;
|
1998-01-13 05:31:29 +08:00
|
|
|
partname = "%verifyscript";
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
2008-01-09 17:11:49 +08:00
|
|
|
case PART_TRIGGERPREIN:
|
|
|
|
tag = RPMTAG_TRIGGERSCRIPTS;
|
|
|
|
tagflags = 0;
|
|
|
|
reqtag = RPMTAG_TRIGGERPREIN;
|
|
|
|
progtag = RPMTAG_TRIGGERSCRIPTPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_TRIGGERSCRIPTFLAGS;
|
2008-01-09 17:11:49 +08:00
|
|
|
partname = "%triggerprein";
|
|
|
|
break;
|
1998-03-21 06:38:00 +08:00
|
|
|
case PART_TRIGGERIN:
|
|
|
|
tag = RPMTAG_TRIGGERSCRIPTS;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = 0;
|
1998-03-21 06:38:00 +08:00
|
|
|
reqtag = RPMTAG_TRIGGERIN;
|
|
|
|
progtag = RPMTAG_TRIGGERSCRIPTPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_TRIGGERSCRIPTFLAGS;
|
1998-04-02 00:02:05 +08:00
|
|
|
partname = "%triggerin";
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
|
|
|
case PART_TRIGGERUN:
|
|
|
|
tag = RPMTAG_TRIGGERSCRIPTS;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = 0;
|
1998-03-21 06:38:00 +08:00
|
|
|
reqtag = RPMTAG_TRIGGERUN;
|
|
|
|
progtag = RPMTAG_TRIGGERSCRIPTPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_TRIGGERSCRIPTFLAGS;
|
1998-03-21 06:38:00 +08:00
|
|
|
partname = "%triggerun";
|
|
|
|
break;
|
1998-04-02 00:02:05 +08:00
|
|
|
case PART_TRIGGERPOSTUN:
|
|
|
|
tag = RPMTAG_TRIGGERSCRIPTS;
|
2000-11-12 19:11:49 +08:00
|
|
|
tagflags = 0;
|
1998-04-02 00:02:05 +08:00
|
|
|
reqtag = RPMTAG_TRIGGERPOSTUN;
|
|
|
|
progtag = RPMTAG_TRIGGERSCRIPTPROG;
|
2010-03-11 18:06:49 +08:00
|
|
|
flagtag = RPMTAG_TRIGGERSCRIPTFLAGS;
|
1998-04-02 00:02:05 +08:00
|
|
|
partname = "%triggerpostun";
|
|
|
|
break;
|
2014-07-02 19:26:49 +08:00
|
|
|
case PART_FILETRIGGERIN:
|
|
|
|
tag = RPMTAG_FILETRIGGERSCRIPTS;
|
|
|
|
tagflags = 0;
|
|
|
|
reqtag = RPMTAG_FILETRIGGERIN;
|
|
|
|
progtag = RPMTAG_FILETRIGGERSCRIPTPROG;
|
|
|
|
flagtag = RPMTAG_FILETRIGGERSCRIPTFLAGS;
|
|
|
|
partname = "%filetriggerin";
|
|
|
|
break;
|
|
|
|
case PART_FILETRIGGERUN:
|
|
|
|
tag = RPMTAG_FILETRIGGERSCRIPTS;
|
|
|
|
tagflags = 0;
|
|
|
|
reqtag = RPMTAG_FILETRIGGERUN;
|
|
|
|
progtag = RPMTAG_FILETRIGGERSCRIPTPROG;
|
|
|
|
flagtag = RPMTAG_FILETRIGGERSCRIPTFLAGS;
|
|
|
|
partname = "%filetriggerun";
|
|
|
|
break;
|
|
|
|
case PART_FILETRIGGERPOSTUN:
|
|
|
|
tag = RPMTAG_FILETRIGGERSCRIPTS;
|
|
|
|
tagflags = 0;
|
|
|
|
reqtag = RPMTAG_FILETRIGGERPOSTUN;
|
|
|
|
progtag = RPMTAG_FILETRIGGERSCRIPTPROG;
|
|
|
|
flagtag = RPMTAG_FILETRIGGERSCRIPTFLAGS;
|
|
|
|
partname = "%filetriggerpostun";
|
|
|
|
break;
|
|
|
|
case PART_TRANSFILETRIGGERIN:
|
|
|
|
tag = RPMTAG_TRANSFILETRIGGERSCRIPTS;
|
|
|
|
tagflags = 0;
|
|
|
|
reqtag = RPMTAG_TRANSFILETRIGGERIN;
|
|
|
|
progtag = RPMTAG_TRANSFILETRIGGERSCRIPTPROG;
|
|
|
|
flagtag = RPMTAG_TRANSFILETRIGGERSCRIPTFLAGS;
|
|
|
|
partname = "%transfiletriggerin";
|
|
|
|
break;
|
|
|
|
case PART_TRANSFILETRIGGERUN:
|
|
|
|
tag = RPMTAG_TRANSFILETRIGGERSCRIPTS;
|
|
|
|
tagflags = 0;
|
|
|
|
reqtag = RPMTAG_TRANSFILETRIGGERUN;
|
|
|
|
progtag = RPMTAG_TRANSFILETRIGGERSCRIPTPROG;
|
|
|
|
flagtag = RPMTAG_TRANSFILETRIGGERSCRIPTFLAGS;
|
|
|
|
partname = "%transfiletriggerun";
|
|
|
|
break;
|
|
|
|
case PART_TRANSFILETRIGGERPOSTUN:
|
|
|
|
tag = RPMTAG_TRANSFILETRIGGERSCRIPTS;
|
|
|
|
tagflags = 0;
|
|
|
|
reqtag = RPMTAG_TRANSFILETRIGGERPOSTUN;
|
|
|
|
progtag = RPMTAG_TRANSFILETRIGGERSCRIPTPROG;
|
|
|
|
flagtag = RPMTAG_TRANSFILETRIGGERSCRIPTFLAGS;
|
|
|
|
partname = "%transfiletriggerpostun";
|
|
|
|
break;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2014-07-02 19:26:49 +08:00
|
|
|
if (tag == RPMTAG_TRIGGERSCRIPTS || tag == RPMTAG_FILETRIGGERSCRIPTS ||
|
|
|
|
tag == RPMTAG_TRANSFILETRIGGERSCRIPTS) {
|
2016-11-11 18:44:06 +08:00
|
|
|
/* break line into two at the -- separator */
|
2016-11-11 18:59:50 +08:00
|
|
|
char *sep, *s = spec->line;
|
2016-11-10 22:44:36 +08:00
|
|
|
while ((s = strstr(s, "--")) != NULL) {
|
2016-11-11 18:44:06 +08:00
|
|
|
s += 2;
|
|
|
|
if (risblank(*(s-3)) && risblank(*s))
|
2016-11-10 22:44:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-11-11 18:44:06 +08:00
|
|
|
if (s == NULL) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: triggers must have --: %s\n"),
|
1998-03-21 06:38:00 +08:00
|
|
|
spec->lineNum, spec->line);
|
2016-11-11 18:44:06 +08:00
|
|
|
goto exit;
|
1998-03-21 06:38:00 +08:00
|
|
|
}
|
2016-11-11 18:44:06 +08:00
|
|
|
|
2016-11-11 18:59:50 +08:00
|
|
|
sep = s;
|
|
|
|
SKIPSPACE(s);
|
|
|
|
if (*s == '\0') {
|
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: missing trigger condition: %s\n"),
|
|
|
|
spec->lineNum, spec->line);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sep = '\0';
|
2016-11-11 18:44:06 +08:00
|
|
|
reqargs = xstrdup(s);
|
1998-03-21 06:38:00 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Error parsing %s: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, partname, poptStrerror(rc));
|
2008-05-05 16:53:48 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
|
|
|
|
while ((arg = poptGetNextOpt(optCon)) > 0) {
|
2001-01-04 10:24:14 +08:00
|
|
|
switch (arg) {
|
|
|
|
case 'p':
|
2004-03-17 05:58:25 +08:00
|
|
|
if (prog[0] == '<') {
|
|
|
|
if (prog[strlen(prog)-1] != '>') {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR,
|
2004-03-17 05:58:25 +08:00
|
|
|
_("line %d: internal script must end "
|
|
|
|
"with \'>\': %s\n"), spec->lineNum, prog);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
} else if (prog[0] != '/') {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("line %d: script program must begin "
|
2001-01-16 07:09:42 +08:00
|
|
|
"with \'/\': %s\n"), spec->lineNum, prog);
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
2007-09-12 05:03:27 +08:00
|
|
|
break;
|
2001-01-04 10:24:14 +08:00
|
|
|
case 'n':
|
1998-01-13 05:31:29 +08:00
|
|
|
flag = PART_NAME;
|
2007-09-12 05:03:27 +08:00
|
|
|
break;
|
2015-05-04 22:29:46 +08:00
|
|
|
case 'P':
|
|
|
|
if (tag != RPMTAG_TRIGGERSCRIPTS &&
|
|
|
|
tag != RPMTAG_FILETRIGGERSCRIPTS &&
|
|
|
|
tag != RPMTAG_TRANSFILETRIGGERSCRIPTS) {
|
|
|
|
|
|
|
|
rpmlog(RPMLOG_ERR,
|
|
|
|
_("line %d: Priorities are allowed only for file "
|
|
|
|
"triggers : %s\n"), spec->lineNum, prog);
|
|
|
|
goto exit;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-04 22:29:46 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (arg < -1) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
|
|
|
spec->line);
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1998-03-21 06:38:00 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (poptPeekArg(optCon)) {
|
1999-10-28 07:18:10 +08:00
|
|
|
if (name == NULL)
|
1998-01-13 05:31:29 +08:00
|
|
|
name = poptGetArg(optCon);
|
|
|
|
if (poptPeekArg(optCon)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
spec->line);
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 20:26:03 +08:00
|
|
|
if (lookupPackage(spec, name, flag, &pkg))
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
if (tag != RPMTAG_TRIGGERSCRIPTS) {
|
|
|
|
if (headerIsEntry(pkg->header, progtag)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Second %s\n"),
|
1998-03-21 06:38:00 +08:00
|
|
|
spec->lineNum, partname);
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
1998-03-21 06:38:00 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((rc = poptParseArgvString(prog, &progArgc, &progArgv))) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Error parsing %s: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, partname, poptStrerror(rc));
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
2001-01-04 10:24:14 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
sb = newStringBuf();
|
1998-05-21 01:05:26 +08:00
|
|
|
if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
nextPart = PART_NONE;
|
2008-05-05 15:56:55 +08:00
|
|
|
} else if (rc < 0) {
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
} else {
|
|
|
|
while (! (nextPart = isPart(spec->line))) {
|
1998-01-14 11:32:44 +08:00
|
|
|
appendStringBuf(sb, spec->line);
|
1998-05-21 01:05:26 +08:00
|
|
|
if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
nextPart = PART_NONE;
|
|
|
|
break;
|
2008-05-05 15:56:55 +08:00
|
|
|
} else if (rc < 0) {
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
2008-05-05 15:56:55 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stripTrailingBlanksStringBuf(sb);
|
|
|
|
p = getStringBuf(sb);
|
|
|
|
|
2007-05-16 21:16:45 +08:00
|
|
|
#ifdef WITH_LUA
|
2009-08-31 16:08:05 +08:00
|
|
|
if (rstreq(progArgv[0], "<lua>")) {
|
2004-03-25 03:47:11 +08:00
|
|
|
rpmlua lua = NULL; /* Global state. */
|
2004-03-17 05:58:25 +08:00
|
|
|
if (rpmluaCheckScript(lua, p, partname) != RPMRC_OK) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2013-04-15 19:08:24 +08:00
|
|
|
(void) rpmlibNeedsFeature(pkg, "BuiltinLuaScripts", "4.2.2-1");
|
2007-05-16 21:16:45 +08:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (progArgv[0][0] == '<') {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR,
|
2004-03-17 05:58:25 +08:00
|
|
|
_("line %d: unsupported internal script: %s\n"),
|
|
|
|
spec->lineNum, progArgv[0]);
|
|
|
|
goto exit;
|
|
|
|
} else {
|
2013-04-15 20:23:37 +08:00
|
|
|
(void) addReqProv(pkg, RPMTAG_REQUIRENAME,
|
2004-10-10 02:23:00 +08:00
|
|
|
progArgv[0], NULL, (tagflags | RPMSENSE_INTERP), 0);
|
2004-03-17 05:58:25 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2010-03-11 18:06:49 +08:00
|
|
|
if (scriptFlags) {
|
2013-04-15 19:08:24 +08:00
|
|
|
rpmlibNeedsFeature(pkg, "ScriptletExpansion", "4.9.0-1");
|
2010-03-11 18:06:49 +08:00
|
|
|
}
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
/* Trigger script insertion is always delayed in order to */
|
|
|
|
/* get the index right. */
|
2014-07-02 19:26:49 +08:00
|
|
|
if (tag == RPMTAG_TRIGGERSCRIPTS || tag == RPMTAG_FILETRIGGERSCRIPTS ||
|
|
|
|
tag == RPMTAG_TRANSFILETRIGGERSCRIPTS) {
|
2016-11-11 19:42:47 +08:00
|
|
|
if (tag != RPMTAG_TRIGGERSCRIPTS && *reqargs != '/') {
|
|
|
|
rpmlog(RPMLOG_ERR,
|
|
|
|
_("line %d: file trigger condition must begin with '/': %s"),
|
|
|
|
spec->lineNum, reqargs);
|
|
|
|
goto exit;
|
|
|
|
}
|
2011-09-12 16:36:27 +08:00
|
|
|
if (progArgc > 1) {
|
|
|
|
rpmlog(RPMLOG_ERR,
|
|
|
|
_("line %d: interpreter arguments not allowed in triggers: %s\n"),
|
|
|
|
spec->lineNum, prog);
|
|
|
|
goto exit;
|
|
|
|
}
|
1998-03-21 06:38:00 +08:00
|
|
|
/* Add file/index/prog triple to the trigger file list */
|
2015-05-04 22:29:46 +08:00
|
|
|
index = addTriggerIndex(pkg, file, p, progArgv[0], scriptFlags, tag,
|
|
|
|
priority);
|
1998-03-21 06:38:00 +08:00
|
|
|
|
|
|
|
/* Generate the trigger tags */
|
2017-02-25 19:28:16 +08:00
|
|
|
if (parseRCPOT(spec, pkg, reqargs, reqtag, index, tagflags, addReqProvPkg, NULL))
|
2000-11-12 19:11:49 +08:00
|
|
|
goto exit;
|
1998-03-21 06:38:00 +08:00
|
|
|
} else {
|
2008-06-18 18:13:22 +08:00
|
|
|
struct rpmtd_s td;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Ancient rpm uses STRING, not STRING_ARRAY type here. Construct
|
|
|
|
* the td manually and preserve legacy compat for now...
|
|
|
|
*/
|
|
|
|
rpmtdReset(&td);
|
|
|
|
td.tag = progtag;
|
|
|
|
td.count = progArgc;
|
2008-06-18 21:14:36 +08:00
|
|
|
if (progArgc == 1) {
|
|
|
|
td.data = (void *) *progArgv;
|
2008-06-18 18:13:22 +08:00
|
|
|
td.type = RPM_STRING_TYPE;
|
2008-06-18 21:14:36 +08:00
|
|
|
} else {
|
2013-04-15 19:08:24 +08:00
|
|
|
(void) rpmlibNeedsFeature(pkg,
|
2001-06-16 02:53:06 +08:00
|
|
|
"ScriptletInterpreterArgs", "4.0.3-1");
|
2008-06-18 21:14:36 +08:00
|
|
|
td.data = progArgv;
|
2008-06-18 18:13:22 +08:00
|
|
|
td.type = RPM_STRING_ARRAY_TYPE;
|
2001-06-16 02:53:06 +08:00
|
|
|
}
|
2008-06-18 18:13:22 +08:00
|
|
|
headerPut(pkg->header, &td, HEADERPUT_DEFAULT);
|
2001-01-04 10:24:14 +08:00
|
|
|
|
2008-06-18 18:13:22 +08:00
|
|
|
if (*p != '\0') {
|
2008-06-19 20:47:04 +08:00
|
|
|
headerPutString(pkg->header, tag, p);
|
2008-06-18 18:13:22 +08:00
|
|
|
}
|
2010-03-11 18:06:49 +08:00
|
|
|
if (scriptFlags) {
|
|
|
|
headerPutUint32(pkg->header, flagtag, &scriptFlags, 1);
|
|
|
|
}
|
2000-11-12 19:11:49 +08:00
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
if (file) {
|
|
|
|
switch (parsePart) {
|
|
|
|
case PART_PRE:
|
1999-09-21 11:22:53 +08:00
|
|
|
pkg->preInFile = xstrdup(file);
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
|
|
|
case PART_POST:
|
1999-09-21 11:22:53 +08:00
|
|
|
pkg->postInFile = xstrdup(file);
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
|
|
|
case PART_PREUN:
|
1999-09-21 11:22:53 +08:00
|
|
|
pkg->preUnFile = xstrdup(file);
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
|
|
|
case PART_POSTUN:
|
1999-09-21 11:22:53 +08:00
|
|
|
pkg->postUnFile = xstrdup(file);
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
2004-03-17 05:58:25 +08:00
|
|
|
case PART_PRETRANS:
|
|
|
|
pkg->preTransFile = xstrdup(file);
|
|
|
|
break;
|
|
|
|
case PART_POSTTRANS:
|
|
|
|
pkg->postTransFile = xstrdup(file);
|
|
|
|
break;
|
1998-03-21 06:38:00 +08:00
|
|
|
case PART_VERIFYSCRIPT:
|
1999-09-21 11:22:53 +08:00
|
|
|
pkg->verifyFile = xstrdup(file);
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
2008-05-05 15:56:55 +08:00
|
|
|
res = nextPart;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-11-12 19:11:49 +08:00
|
|
|
exit:
|
2008-05-05 16:53:48 +08:00
|
|
|
free(reqargs);
|
2011-05-27 19:10:51 +08:00
|
|
|
freeStringBuf(sb);
|
|
|
|
free(progArgv);
|
|
|
|
free(argv);
|
|
|
|
poptFreeContext(optCon);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2008-05-05 15:56:55 +08:00
|
|
|
return res;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|