1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "rpmbuild.h"
|
|
|
|
|
1999-04-02 06:26:44 +08:00
|
|
|
static int addTriggerIndex(Package pkg, char *file, char *script, char *prog)
|
|
|
|
{
|
|
|
|
struct TriggerFileEntry *new;
|
|
|
|
struct TriggerFileEntry *list = pkg->triggerFiles;
|
|
|
|
struct TriggerFileEntry *last = NULL;
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
last = list;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last) {
|
|
|
|
index = last->index + 1;
|
|
|
|
}
|
|
|
|
|
1999-09-21 11:22:53 +08:00
|
|
|
new = xmalloc(sizeof(*new));
|
1999-04-02 06:26:44 +08:00
|
|
|
|
1999-09-21 11:22:53 +08:00
|
|
|
new->fileName = (file) ? xstrdup(file) : NULL;
|
|
|
|
new->script = (*script) ? xstrdup(script) : NULL;
|
|
|
|
new->prog = xstrdup(prog);
|
1999-04-02 06:26:44 +08:00
|
|
|
new->index = index;
|
|
|
|
new->next = NULL;
|
|
|
|
|
|
|
|
if (last) {
|
|
|
|
last->next = new;
|
|
|
|
} else {
|
|
|
|
pkg->triggerFiles = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
/* these have to be global because of stupid compilers */
|
1999-10-05 03:40:03 +08:00
|
|
|
/*@observer@*/ /*@null@*/ static char *name;
|
|
|
|
/*@observer@*/ /*@null@*/ static char *prog;
|
|
|
|
/*@observer@*/ /*@null@*/ static char *file;
|
1998-03-05 00:51:06 +08:00
|
|
|
static struct poptOption optionsTable[] = {
|
1998-11-20 03:10:23 +08:00
|
|
|
{ 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},
|
|
|
|
{ 0, 0, 0, 0, 0, NULL, NULL}
|
1998-03-05 00:51:06 +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. */
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int parseScript(Spec spec, int parsePart)
|
|
|
|
{
|
|
|
|
/* There are a few options to scripts: */
|
|
|
|
/* <pkg> */
|
|
|
|
/* -n <pkg> */
|
|
|
|
/* -p <sh> */
|
|
|
|
/* -p "<sh> <args>..." */
|
|
|
|
/* -f <file> */
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
char **progArgv = NULL;
|
|
|
|
int progArgc;
|
|
|
|
char *partname = NULL;
|
1998-03-21 06:38:00 +08:00
|
|
|
int reqtag = 0;
|
1998-01-13 05:31:29 +08:00
|
|
|
int tag = 0;
|
|
|
|
int progtag = 0;
|
|
|
|
int flag = PART_SUBNAME;
|
|
|
|
Package pkg;
|
|
|
|
StringBuf sb;
|
|
|
|
int nextPart;
|
1998-03-21 06:38:00 +08:00
|
|
|
int index;
|
|
|
|
char reqargs[BUFSIZ];
|
1998-03-05 00:51:06 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int rc, argc;
|
1998-04-03 02:31:12 +08:00
|
|
|
int arg;
|
|
|
|
char **argv = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
poptContext optCon = NULL;
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
name = NULL;
|
|
|
|
prog = "/bin/sh";
|
|
|
|
file = NULL;
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
switch (parsePart) {
|
|
|
|
case PART_PRE:
|
|
|
|
tag = RPMTAG_PREIN;
|
|
|
|
progtag = RPMTAG_PREINPROG;
|
|
|
|
partname = "%pre";
|
|
|
|
break;
|
|
|
|
case PART_POST:
|
|
|
|
tag = RPMTAG_POSTIN;
|
|
|
|
progtag = RPMTAG_POSTINPROG;
|
|
|
|
partname = "%post";
|
|
|
|
break;
|
|
|
|
case PART_PREUN:
|
|
|
|
tag = RPMTAG_PREUN;
|
|
|
|
progtag = RPMTAG_PREUNPROG;
|
|
|
|
partname = "%preun";
|
|
|
|
break;
|
|
|
|
case PART_POSTUN:
|
|
|
|
tag = RPMTAG_POSTUN;
|
|
|
|
progtag = RPMTAG_POSTUNPROG;
|
|
|
|
partname = "%postun";
|
|
|
|
break;
|
|
|
|
case PART_VERIFYSCRIPT:
|
1999-04-21 03:17:23 +08:00
|
|
|
tag = RPMTAG_VERIFYSCRIPT;
|
1998-01-13 05:31:29 +08:00
|
|
|
progtag = RPMTAG_VERIFYSCRIPTPROG;
|
|
|
|
partname = "%verifyscript";
|
1998-03-21 06:38:00 +08:00
|
|
|
break;
|
|
|
|
case PART_TRIGGERIN:
|
|
|
|
tag = RPMTAG_TRIGGERSCRIPTS;
|
|
|
|
reqtag = RPMTAG_TRIGGERIN;
|
|
|
|
progtag = RPMTAG_TRIGGERSCRIPTPROG;
|
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;
|
|
|
|
reqtag = RPMTAG_TRIGGERUN;
|
|
|
|
progtag = RPMTAG_TRIGGERSCRIPTPROG;
|
|
|
|
partname = "%triggerun";
|
|
|
|
break;
|
1998-04-02 00:02:05 +08:00
|
|
|
case PART_TRIGGERPOSTUN:
|
|
|
|
tag = RPMTAG_TRIGGERSCRIPTS;
|
|
|
|
reqtag = RPMTAG_TRIGGERPOSTUN;
|
|
|
|
progtag = RPMTAG_TRIGGERSCRIPTPROG;
|
|
|
|
partname = "%triggerpostun";
|
|
|
|
break;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
if (tag == RPMTAG_TRIGGERSCRIPTS) {
|
|
|
|
/* break line into two */
|
|
|
|
p = strstr(spec->line, "--");
|
|
|
|
if (!p) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: triggers must have --: %s"),
|
1998-03-21 06:38:00 +08:00
|
|
|
spec->lineNum, spec->line);
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
strcpy(reqargs, p + 2);
|
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %s: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, partname, poptStrerror(rc));
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
|
|
|
|
while ((arg = poptGetNextOpt(optCon)) > 0) {
|
|
|
|
if (arg == 'p') {
|
|
|
|
if (prog[0] != '/') {
|
|
|
|
rpmError(RPMERR_BADSPEC,
|
1998-09-28 06:03:52 +08:00
|
|
|
_("line %d: script program must begin "
|
|
|
|
"with \'/\': %s"), spec->lineNum, prog);
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
} else if (arg == 'n') {
|
|
|
|
flag = PART_NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg < -1) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
|
|
|
spec->line);
|
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
1998-03-21 06:38:00 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (poptPeekArg(optCon)) {
|
|
|
|
if (! name) {
|
|
|
|
name = poptGetArg(optCon);
|
|
|
|
}
|
|
|
|
if (poptPeekArg(optCon)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
spec->line);
|
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookupPackage(spec, name, flag, &pkg)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, spec->line);
|
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
if (tag != RPMTAG_TRIGGERSCRIPTS) {
|
|
|
|
if (headerIsEntry(pkg->header, progtag)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Second %s"),
|
1998-03-21 06:38:00 +08:00
|
|
|
spec->lineNum, partname);
|
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((rc = poptParseArgvString(prog, &progArgc, &progArgv))) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %s: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, partname, poptStrerror(rc));
|
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
} else {
|
1998-05-21 01:05:26 +08:00
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
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;
|
|
|
|
}
|
1998-05-21 01:05:26 +08:00
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stripTrailingBlanksStringBuf(sb);
|
|
|
|
p = getStringBuf(sb);
|
|
|
|
|
1999-01-27 05:57:57 +08:00
|
|
|
addReqProv(spec, pkg->header, RPMSENSE_PREREQ, prog, NULL, 0);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
/* Trigger script insertion is always delayed in order to */
|
|
|
|
/* get the index right. */
|
|
|
|
if (tag == RPMTAG_TRIGGERSCRIPTS) {
|
|
|
|
/* Add file/index/prog triple to the trigger file list */
|
|
|
|
index = addTriggerIndex(pkg, file, p, prog);
|
|
|
|
|
|
|
|
/* Generate the trigger tags */
|
1999-06-17 23:44:47 +08:00
|
|
|
if ((rc = parseRCPOT(spec, pkg, reqargs, reqtag, index))) {
|
1998-03-21 06:38:00 +08:00
|
|
|
freeStringBuf(sb);
|
|
|
|
FREE(progArgv);
|
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
headerAddEntry(pkg->header, progtag, RPM_STRING_TYPE, prog, 1);
|
|
|
|
if (*p) {
|
|
|
|
headerAddEntry(pkg->header, tag, RPM_STRING_TYPE, p, 1);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
freeStringBuf(sb);
|
|
|
|
FREE(progArgv);
|
|
|
|
FREE(argv);
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
|
|
|
|
return nextPart;
|
|
|
|
}
|