1996-06-08 02:31:31 +08:00
|
|
|
/* The very final packaging steps */
|
1995-12-21 06:49:40 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
1996-06-08 02:31:31 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
1995-12-21 06:49:40 +08:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
1996-06-08 02:31:31 +08:00
|
|
|
#include <signal.h>
|
1995-12-21 06:49:40 +08:00
|
|
|
#include <fcntl.h>
|
1996-06-08 02:31:31 +08:00
|
|
|
#include <string.h>
|
1996-06-19 01:07:21 +08:00
|
|
|
#include <errno.h>
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-06-08 02:31:31 +08:00
|
|
|
#include "pack.h"
|
1995-12-21 06:49:40 +08:00
|
|
|
#include "header.h"
|
1996-06-08 02:31:31 +08:00
|
|
|
#include "spec.h"
|
1995-12-21 06:49:40 +08:00
|
|
|
#include "specP.h"
|
1996-06-08 02:31:31 +08:00
|
|
|
#include "signature.h"
|
1995-12-21 06:49:40 +08:00
|
|
|
#include "rpmerr.h"
|
1995-12-28 03:45:36 +08:00
|
|
|
#include "rpmlead.h"
|
|
|
|
#include "rpmlib.h"
|
1995-12-21 06:49:40 +08:00
|
|
|
#include "misc.h"
|
1996-06-08 02:31:31 +08:00
|
|
|
#include "stringbuf.h"
|
|
|
|
#include "names.h"
|
|
|
|
#include "files.h"
|
|
|
|
#include "reqprov.h"
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
static int writeMagic(int fd, char *name, unsigned short type,
|
|
|
|
unsigned short sigtype);
|
1996-06-28 01:21:31 +08:00
|
|
|
static int cpio_gzip(int fd, char *tempdir, char *writePtr, int *archiveSize);
|
1996-06-08 02:31:31 +08:00
|
|
|
static int generateRPM(char *name, /* name-version-release */
|
1996-06-28 01:21:31 +08:00
|
|
|
char *filename, /* output filename */
|
1996-06-08 02:31:31 +08:00
|
|
|
int type, /* source or binary */
|
|
|
|
Header header, /* the header */
|
|
|
|
char *stempdir, /* directory containing sources */
|
1996-06-28 01:21:31 +08:00
|
|
|
char *fileList, /* list of files for cpio */
|
1996-06-08 02:31:31 +08:00
|
|
|
char *passPhrase);
|
|
|
|
|
|
|
|
|
|
|
|
static int generateRPM(char *name, /* name-version-release */
|
1996-06-28 01:21:31 +08:00
|
|
|
char *filename, /* output filename */
|
1996-06-08 02:31:31 +08:00
|
|
|
int type, /* source or binary */
|
|
|
|
Header header, /* the header */
|
|
|
|
char *stempdir, /* directory containing sources */
|
1996-06-28 01:21:31 +08:00
|
|
|
char *fileList, /* list of files for cpio */
|
1996-06-08 02:31:31 +08:00
|
|
|
char *passPhrase)
|
1996-02-19 10:24:47 +08:00
|
|
|
{
|
|
|
|
unsigned short sigtype;
|
1996-02-20 07:00:16 +08:00
|
|
|
char *sigtarget, *archiveTemp;
|
|
|
|
int fd, ifd, count, archiveSize;
|
|
|
|
unsigned char buffer[8192];
|
1996-02-19 10:24:47 +08:00
|
|
|
|
|
|
|
/* Figure out the signature type */
|
|
|
|
if ((sigtype = sigLookupType()) == RPMSIG_BAD) {
|
|
|
|
error(RPMERR_BADSIGTYPE, "Bad signature type in rpmrc");
|
|
|
|
return RPMERR_BADSIGTYPE;
|
|
|
|
}
|
|
|
|
|
1996-02-20 07:00:16 +08:00
|
|
|
/* Write the archive to a temp file so we can get the size */
|
1996-03-29 09:26:20 +08:00
|
|
|
archiveTemp = tempnam("/var/tmp", "rpmbuild");
|
1996-03-30 04:06:02 +08:00
|
|
|
if ((fd = open(archiveTemp, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
|
|
|
|
fprintf(stderr, "Could not open %s\n", archiveTemp);
|
|
|
|
return 1;
|
|
|
|
}
|
1996-06-28 01:21:31 +08:00
|
|
|
if (cpio_gzip(fd, stempdir, fileList, &archiveSize)) {
|
1996-02-22 09:35:34 +08:00
|
|
|
close(fd);
|
|
|
|
unlink(archiveTemp);
|
1996-02-20 07:00:16 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
/* Add the archive size to the Header */
|
|
|
|
addEntry(header, RPMTAG_ARCHIVESIZE, INT32_TYPE, &archiveSize, 1);
|
|
|
|
|
|
|
|
/* Now write the header and append the archive */
|
1996-03-29 09:26:20 +08:00
|
|
|
sigtarget = tempnam("/var/tmp", "rpmbuild");
|
1996-03-30 04:06:02 +08:00
|
|
|
if ((fd = open(sigtarget, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
|
|
|
|
fprintf(stderr, "Could not open %s\n", sigtarget);
|
|
|
|
unlink(archiveTemp);
|
|
|
|
return 1;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
writeHeader(fd, header);
|
1996-02-20 07:00:16 +08:00
|
|
|
ifd = open(archiveTemp, O_RDONLY, 0644);
|
|
|
|
while ((count = read(ifd, buffer, sizeof(buffer))) > 0) {
|
1996-02-22 23:34:27 +08:00
|
|
|
if (count == -1) {
|
|
|
|
perror("Couldn't read archiveTemp");
|
1996-02-22 23:46:54 +08:00
|
|
|
close(fd);
|
|
|
|
close(ifd);
|
|
|
|
unlink(archiveTemp);
|
|
|
|
unlink(sigtarget);
|
|
|
|
return 1;
|
1996-02-22 23:34:27 +08:00
|
|
|
}
|
|
|
|
if (write(fd, buffer, count) < 0) {
|
|
|
|
perror("Couldn't write package to temp file");
|
1996-02-22 23:46:54 +08:00
|
|
|
close(fd);
|
|
|
|
close(ifd);
|
|
|
|
unlink(archiveTemp);
|
|
|
|
unlink(sigtarget);
|
|
|
|
return 1;
|
1996-02-22 23:34:27 +08:00
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
1996-02-20 07:00:16 +08:00
|
|
|
close(ifd);
|
1996-02-19 10:24:47 +08:00
|
|
|
close(fd);
|
1996-02-20 07:00:16 +08:00
|
|
|
unlink(archiveTemp);
|
1996-02-19 10:24:47 +08:00
|
|
|
|
|
|
|
/* Now write the lead */
|
1996-03-30 04:06:02 +08:00
|
|
|
if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
|
|
|
|
fprintf(stderr, "Could not open %s\n", filename);
|
|
|
|
unlink(sigtarget);
|
|
|
|
unlink(filename);
|
|
|
|
return 1;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
if (writeMagic(fd, name, type, sigtype)) {
|
1996-02-22 09:35:34 +08:00
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
|
|
|
unlink(filename);
|
1996-02-19 10:24:47 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate the signature */
|
|
|
|
message(MESS_VERBOSE, "Generating signature: %d\n", sigtype);
|
|
|
|
fflush(stdout);
|
1996-02-22 09:35:34 +08:00
|
|
|
if (makeSignature(sigtarget, sigtype, fd, passPhrase)) {
|
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
|
|
|
unlink(filename);
|
|
|
|
return 1;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
|
|
|
|
/* Append the header and archive */
|
|
|
|
ifd = open(sigtarget, O_RDONLY);
|
1996-02-20 07:00:16 +08:00
|
|
|
while ((count = read(ifd, buffer, sizeof(buffer))) > 0) {
|
1996-02-22 23:34:27 +08:00
|
|
|
if (count == -1) {
|
|
|
|
perror("Couldn't read sigtarget");
|
1996-02-22 23:46:54 +08:00
|
|
|
close(ifd);
|
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
|
|
|
unlink(filename);
|
|
|
|
return 1;
|
1996-02-22 23:34:27 +08:00
|
|
|
}
|
|
|
|
if (write(fd, buffer, count) < 0) {
|
|
|
|
perror("Couldn't write package");
|
1996-02-22 23:46:54 +08:00
|
|
|
close(ifd);
|
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
|
|
|
unlink(filename);
|
|
|
|
return 1;
|
1996-02-22 23:34:27 +08:00
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
close(ifd);
|
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
1996-06-28 01:21:31 +08:00
|
|
|
|
|
|
|
message(MESS_VERBOSE, "Wrote: %s\n", filename);
|
1996-02-19 10:24:47 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int writeMagic(int fd, char *name,
|
|
|
|
unsigned short type,
|
|
|
|
unsigned short sigtype)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1995-12-28 03:45:36 +08:00
|
|
|
struct rpmlead lead;
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
/* There are the Major and Minor numbers */
|
1996-06-28 02:27:18 +08:00
|
|
|
lead.major = 3;
|
1995-12-28 03:45:36 +08:00
|
|
|
lead.minor = 0;
|
1996-01-05 11:13:40 +08:00
|
|
|
lead.type = type;
|
|
|
|
lead.archnum = getArchNum();
|
|
|
|
lead.osnum = getOsNum();
|
1996-02-19 10:24:47 +08:00
|
|
|
lead.signature_type = sigtype;
|
1995-12-28 03:45:36 +08:00
|
|
|
strncpy(lead.name, name, sizeof(lead.name));
|
|
|
|
|
1996-01-05 11:13:40 +08:00
|
|
|
writeLead(fd, &lead);
|
1995-12-21 06:49:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
static int cpio_gzip(int fd, char *tempdir, char *writePtr, int *archiveSize)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1996-02-29 08:55:31 +08:00
|
|
|
int cpioPID, gzipPID;
|
|
|
|
int cpioDead, gzipDead;
|
|
|
|
int toCpio[2];
|
|
|
|
int fromCpio[2];
|
|
|
|
int toGzip[2];
|
|
|
|
|
1996-02-21 07:31:59 +08:00
|
|
|
int writeBytesLeft, bytesWritten;
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
int bytes;
|
|
|
|
unsigned char buf[8192];
|
|
|
|
|
|
|
|
int status;
|
|
|
|
void *oldhandler;
|
|
|
|
|
1996-02-20 07:00:16 +08:00
|
|
|
*archiveSize = 0;
|
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
pipe(toCpio);
|
|
|
|
pipe(fromCpio);
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-02-20 07:00:16 +08:00
|
|
|
oldhandler = signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
/* CPIO */
|
1995-12-21 06:49:40 +08:00
|
|
|
if (!(cpioPID = fork())) {
|
|
|
|
close(0);
|
|
|
|
close(1);
|
1996-02-29 08:55:31 +08:00
|
|
|
close(toCpio[1]);
|
|
|
|
close(fromCpio[0]);
|
1995-12-21 06:49:40 +08:00
|
|
|
close(fd);
|
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
dup2(toCpio[0], 0); /* Make stdin the in pipe */
|
|
|
|
dup2(fromCpio[1], 1); /* Make stdout the out pipe */
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-01-08 15:07:35 +08:00
|
|
|
if (tempdir) {
|
|
|
|
chdir(tempdir);
|
|
|
|
} else if (getVar(RPMVAR_ROOT)) {
|
1995-12-28 00:52:14 +08:00
|
|
|
if (chdir(getVar(RPMVAR_ROOT))) {
|
|
|
|
error(RPMERR_EXEC, "Couldn't chdir to %s",
|
|
|
|
getVar(RPMVAR_ROOT));
|
|
|
|
exit(RPMERR_EXEC);
|
|
|
|
}
|
|
|
|
} else {
|
1996-06-28 01:21:31 +08:00
|
|
|
/* This is important! */
|
1995-12-28 00:52:14 +08:00
|
|
|
chdir("/");
|
|
|
|
}
|
|
|
|
|
1996-01-08 15:07:35 +08:00
|
|
|
execlp("cpio", "cpio",
|
|
|
|
(isVerbose()) ? "-ov" : "-o",
|
|
|
|
(tempdir) ? "-LH" : "-H",
|
|
|
|
"crc", NULL);
|
1995-12-21 06:49:40 +08:00
|
|
|
error(RPMERR_EXEC, "Couldn't exec cpio");
|
|
|
|
exit(RPMERR_EXEC);
|
|
|
|
}
|
|
|
|
if (cpioPID < 0) {
|
1996-02-29 08:55:31 +08:00
|
|
|
error(RPMERR_FORK, "Couldn't fork cpio");
|
1995-12-21 06:49:40 +08:00
|
|
|
return RPMERR_FORK;
|
|
|
|
}
|
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
pipe(toGzip);
|
|
|
|
|
|
|
|
/* GZIP */
|
|
|
|
if (!(gzipPID = fork())) {
|
|
|
|
close(0);
|
|
|
|
close(1);
|
|
|
|
close(toGzip[1]);
|
|
|
|
close(toCpio[0]);
|
|
|
|
close(toCpio[1]);
|
|
|
|
close(fromCpio[0]);
|
|
|
|
close(fromCpio[1]);
|
|
|
|
|
|
|
|
dup2(toGzip[0], 0); /* Make stdin the in pipe */
|
|
|
|
dup2(fd, 1); /* Make stdout the passed-in fd */
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
execlp("gzip", "gzip", "-c9fn", NULL);
|
|
|
|
error(RPMERR_EXEC, "Couldn't exec gzip");
|
|
|
|
exit(RPMERR_EXEC);
|
|
|
|
}
|
|
|
|
if (gzipPID < 0) {
|
|
|
|
error(RPMERR_FORK, "Couldn't fork gzip");
|
|
|
|
return RPMERR_FORK;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(toCpio[0]);
|
|
|
|
close(fromCpio[1]);
|
|
|
|
close(toGzip[0]);
|
|
|
|
|
|
|
|
/* It is OK to block writing to gzip. But it is not OK */
|
|
|
|
/* to block reading or writing from/to cpio. */
|
|
|
|
fcntl(fromCpio[0], F_SETFL, O_NONBLOCK);
|
|
|
|
fcntl(toCpio[1], F_SETFL, O_NONBLOCK);
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
writeBytesLeft = strlen(writePtr);
|
|
|
|
|
1996-02-20 07:00:16 +08:00
|
|
|
cpioDead = 0;
|
1996-02-29 08:55:31 +08:00
|
|
|
gzipDead = 0;
|
1996-02-20 07:00:16 +08:00
|
|
|
do {
|
|
|
|
if (waitpid(cpioPID, &status, WNOHANG)) {
|
|
|
|
cpioDead = 1;
|
|
|
|
}
|
1996-02-29 08:55:31 +08:00
|
|
|
if (waitpid(gzipPID, &status, WNOHANG)) {
|
|
|
|
gzipDead = 1;
|
|
|
|
}
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
/* Write some stuff to the cpio process if possible */
|
1996-02-21 07:31:59 +08:00
|
|
|
if (writeBytesLeft) {
|
|
|
|
if ((bytesWritten =
|
1996-02-29 08:55:31 +08:00
|
|
|
write(toCpio[1], writePtr,
|
1996-02-21 07:31:59 +08:00
|
|
|
(1024<writeBytesLeft) ? 1024 : writeBytesLeft)) < 0) {
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
perror("Damn!");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
bytesWritten = 0;
|
|
|
|
}
|
|
|
|
writeBytesLeft -= bytesWritten;
|
|
|
|
writePtr += bytesWritten;
|
1996-02-20 07:00:16 +08:00
|
|
|
} else {
|
1996-02-29 08:55:31 +08:00
|
|
|
close(toCpio[1]);
|
1996-02-20 07:00:16 +08:00
|
|
|
}
|
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
/* Read any data from cpio, write it to gzip */
|
|
|
|
bytes = read(fromCpio[0], buf, sizeof(buf));
|
1996-02-20 07:00:16 +08:00
|
|
|
while (bytes > 0) {
|
|
|
|
*archiveSize += bytes;
|
1996-02-29 08:55:31 +08:00
|
|
|
write(toGzip[1], buf, bytes);
|
|
|
|
bytes = read(fromCpio[0], buf, sizeof(buf));
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
/* while cpio is running, or we are writing to gzip */
|
|
|
|
/* terminate if gzip dies on us in the middle */
|
|
|
|
} while (((!cpioDead) || bytes) && (!gzipDead));
|
1996-02-20 07:00:16 +08:00
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
if (gzipDead) {
|
|
|
|
error(RPMERR_GZIP, "gzip died");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(toGzip[1]); /* Terminates the gzip process */
|
|
|
|
close(toCpio[1]);
|
|
|
|
close(fromCpio[0]);
|
1996-02-20 07:00:16 +08:00
|
|
|
|
|
|
|
signal(SIGPIPE, oldhandler);
|
1996-02-29 08:55:31 +08:00
|
|
|
|
|
|
|
if (writeBytesLeft) {
|
|
|
|
error(RPMERR_CPIO, "failed to write all data to cpio");
|
|
|
|
return 1;
|
|
|
|
}
|
1995-12-21 06:49:40 +08:00
|
|
|
waitpid(cpioPID, &status, 0);
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
|
|
|
error(RPMERR_CPIO, "cpio failed");
|
|
|
|
return 1;
|
|
|
|
}
|
1996-02-29 08:55:31 +08:00
|
|
|
waitpid(gzipPID, &status, 0);
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
|
|
|
error(RPMERR_GZIP, "gzip failed");
|
|
|
|
return 1;
|
|
|
|
}
|
1995-12-21 06:49:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-12 15:31:41 +08:00
|
|
|
|
1996-02-21 00:00:04 +08:00
|
|
|
int packageBinaries(Spec s, char *passPhrase)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
|
|
|
char name[1024];
|
1996-02-22 01:19:17 +08:00
|
|
|
char *nametmp;
|
1995-12-21 06:49:40 +08:00
|
|
|
char filename[1024];
|
1996-01-18 02:17:50 +08:00
|
|
|
char sourcerpm[1024];
|
1996-01-08 15:07:35 +08:00
|
|
|
char *icon;
|
|
|
|
int iconFD;
|
|
|
|
struct stat statbuf;
|
1995-12-21 06:49:40 +08:00
|
|
|
struct PackageRec *pr;
|
|
|
|
Header outHeader;
|
|
|
|
HeaderIterator headerIter;
|
|
|
|
int_32 tag, type, c;
|
|
|
|
void *ptr;
|
|
|
|
char *version;
|
|
|
|
char *release;
|
1996-02-19 10:24:47 +08:00
|
|
|
char *vendor;
|
|
|
|
char *dist;
|
1996-02-21 01:55:15 +08:00
|
|
|
char *packageVersion, *packageRelease;
|
1996-01-10 07:41:35 +08:00
|
|
|
int size;
|
1996-06-28 01:21:31 +08:00
|
|
|
StringBuf cpioFileList;
|
|
|
|
char **farray, *file;
|
|
|
|
int count;
|
1996-02-19 10:24:47 +08:00
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
if (!getEntry(s->packages->header, RPMTAG_VERSION, NULL,
|
|
|
|
(void *) &version, NULL)) {
|
|
|
|
error(RPMERR_BADSPEC, "No version field");
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
if (!getEntry(s->packages->header, RPMTAG_RELEASE, NULL,
|
|
|
|
(void *) &release, NULL)) {
|
|
|
|
error(RPMERR_BADSPEC, "No release field");
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
sprintf(sourcerpm, "%s-%s-%s.%ssrc.rpm", s->name, version, release,
|
|
|
|
(s->numNoPatch + s->numNoSource) ? "no" : "");
|
1996-01-13 07:46:47 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
vendor = NULL;
|
|
|
|
if (!isEntry(s->packages->header, RPMTAG_VENDOR)) {
|
|
|
|
vendor = getVar(RPMVAR_VENDOR);
|
|
|
|
}
|
|
|
|
dist = NULL;
|
|
|
|
if (!isEntry(s->packages->header, RPMTAG_DISTRIBUTION)) {
|
|
|
|
dist = getVar(RPMVAR_DISTRIBUTION);
|
|
|
|
}
|
1996-07-02 05:37:18 +08:00
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
/* Look through for each package */
|
|
|
|
pr = s->packages;
|
|
|
|
while (pr) {
|
1996-02-19 10:24:47 +08:00
|
|
|
/* A file count of -1 means no package */
|
1995-12-21 06:49:40 +08:00
|
|
|
if (pr->files == -1) {
|
|
|
|
pr = pr->next;
|
|
|
|
continue;
|
|
|
|
}
|
1996-02-21 01:55:15 +08:00
|
|
|
|
|
|
|
/* Handle subpackage version/release overrides */
|
|
|
|
if (!getEntry(pr->header, RPMTAG_VERSION, NULL,
|
|
|
|
(void *) &packageVersion, NULL)) {
|
|
|
|
packageVersion = version;
|
|
|
|
}
|
|
|
|
if (!getEntry(pr->header, RPMTAG_RELEASE, NULL,
|
|
|
|
(void *) &packageRelease, NULL)) {
|
|
|
|
packageRelease = release;
|
|
|
|
}
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/* Figure out the name of this package */
|
1996-02-22 01:19:17 +08:00
|
|
|
if (!getEntry(pr->header, RPMTAG_NAME, NULL, (void *)&nametmp, NULL)) {
|
|
|
|
error(RPMERR_INTERNAL, "Package has no name!");
|
|
|
|
return RPMERR_INTERNAL;
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|
1996-02-22 01:19:17 +08:00
|
|
|
sprintf(name, "%s-%s-%s", nametmp, packageVersion, packageRelease);
|
1996-02-19 10:24:47 +08:00
|
|
|
|
1996-02-21 07:31:59 +08:00
|
|
|
message(MESS_VERBOSE, "Binary Packaging: %s\n", name);
|
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/**** Generate the Header ****/
|
1995-12-21 06:49:40 +08:00
|
|
|
|
|
|
|
/* Here's the plan: copy the package's header, */
|
|
|
|
/* then add entries from the primary header */
|
|
|
|
/* that don't already exist. */
|
|
|
|
outHeader = copyHeader(pr->header);
|
|
|
|
headerIter = initIterator(s->packages->header);
|
|
|
|
while (nextIterator(headerIter, &tag, &type, &ptr, &c)) {
|
|
|
|
/* Some tags we don't copy */
|
|
|
|
switch (tag) {
|
|
|
|
case RPMTAG_PREIN:
|
|
|
|
case RPMTAG_POSTIN:
|
|
|
|
case RPMTAG_PREUN:
|
|
|
|
case RPMTAG_POSTUN:
|
|
|
|
continue;
|
|
|
|
break; /* Shouldn't need this */
|
|
|
|
default:
|
|
|
|
if (! isEntry(outHeader, tag)) {
|
|
|
|
addEntry(outHeader, tag, type, ptr, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
freeIterator(headerIter);
|
|
|
|
|
|
|
|
/* Add some final entries to the header */
|
1996-07-02 05:37:18 +08:00
|
|
|
addEntry(outHeader, RPMTAG_OS, STRING_TYPE, getOsName(), 1);
|
|
|
|
addEntry(outHeader, RPMTAG_ARCH, STRING_TYPE, getArchName(), 1);
|
1996-06-08 02:31:31 +08:00
|
|
|
addEntry(outHeader, RPMTAG_BUILDTIME, INT32_TYPE, getBuildTime(), 1);
|
1996-01-12 15:31:41 +08:00
|
|
|
addEntry(outHeader, RPMTAG_BUILDHOST, STRING_TYPE, buildHost(), 1);
|
1996-01-13 07:46:47 +08:00
|
|
|
addEntry(outHeader, RPMTAG_SOURCERPM, STRING_TYPE, sourcerpm, 1);
|
1996-01-08 15:07:35 +08:00
|
|
|
if (pr->icon) {
|
|
|
|
sprintf(filename, "%s/%s", getVar(RPMVAR_SOURCEDIR), pr->icon);
|
|
|
|
stat(filename, &statbuf);
|
|
|
|
icon = malloc(statbuf.st_size);
|
|
|
|
iconFD = open(filename, O_RDONLY, 0644);
|
|
|
|
read(iconFD, icon, statbuf.st_size);
|
|
|
|
close(iconFD);
|
1996-01-10 07:41:35 +08:00
|
|
|
if (! strncmp(icon, "GIF", 3)) {
|
|
|
|
addEntry(outHeader, RPMTAG_GIF, BIN_TYPE,
|
|
|
|
icon, statbuf.st_size);
|
|
|
|
} else if (! strncmp(icon, "/* XPM", 6)) {
|
|
|
|
addEntry(outHeader, RPMTAG_XPM, BIN_TYPE,
|
|
|
|
icon, statbuf.st_size);
|
|
|
|
} else {
|
1996-02-15 00:56:02 +08:00
|
|
|
error(RPMERR_BADSPEC, "Unknown icon type");
|
|
|
|
return 1;
|
1996-01-10 07:41:35 +08:00
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
free(icon);
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
if (vendor) {
|
|
|
|
addEntry(outHeader, RPMTAG_VENDOR, STRING_TYPE, vendor, 1);
|
|
|
|
}
|
|
|
|
if (dist) {
|
|
|
|
addEntry(outHeader, RPMTAG_DISTRIBUTION, STRING_TYPE, dist, 1);
|
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/**** Process the file list ****/
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-05-08 02:49:33 +08:00
|
|
|
if (process_filelist(outHeader, pr, pr->filelist, &size, nametmp,
|
1996-02-21 01:55:15 +08:00
|
|
|
packageVersion, packageRelease, RPMLEAD_BINARY)) {
|
1995-12-21 06:49:40 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-05-08 02:49:33 +08:00
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
if (!getEntry(outHeader, RPMTAG_FILENAMES, NULL, (void **) &farray,
|
|
|
|
&count)) {
|
|
|
|
/* count may already be 0, but this is safer */
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpioFileList = newStringBuf();
|
|
|
|
while (count--) {
|
|
|
|
file = *farray++;
|
1996-06-29 05:13:13 +08:00
|
|
|
while (*file == '/') {
|
|
|
|
file++; /* Skip leading "/" */
|
|
|
|
}
|
1996-06-28 01:21:31 +08:00
|
|
|
appendLineStringBuf(cpioFileList, file);
|
|
|
|
}
|
|
|
|
|
1996-06-08 02:31:31 +08:00
|
|
|
/* Generate any automatic require/provide entries */
|
|
|
|
/* Then add the whole thing to the header */
|
|
|
|
generateAutoReqProv(outHeader, pr);
|
|
|
|
processReqProv(outHeader, pr);
|
1996-05-08 02:49:33 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/* And add the final Header entry */
|
|
|
|
addEntry(outHeader, RPMTAG_SIZE, INT32_TYPE, &size, 1);
|
|
|
|
|
|
|
|
/**** Make the RPM ****/
|
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
/* Make the output RPM filename */
|
|
|
|
sprintf(filename, "%s/%s/%s.%s.rpm", getVar(RPMVAR_RPMDIR),
|
1996-07-02 05:37:18 +08:00
|
|
|
getBooleanVar(RPMVAR_ARCHSENSITIVE) ? getArchName() : "",
|
|
|
|
name, getArchName());
|
1996-06-28 01:21:31 +08:00
|
|
|
|
|
|
|
if (generateRPM(name, filename, RPMLEAD_BINARY, outHeader, NULL,
|
|
|
|
getStringBuf(cpioFileList), passPhrase)) {
|
1996-02-22 09:35:34 +08:00
|
|
|
/* Build failed */
|
|
|
|
return 1;
|
|
|
|
}
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
freeStringBuf(cpioFileList);
|
1995-12-21 06:49:40 +08:00
|
|
|
freeHeader(outHeader);
|
|
|
|
pr = pr->next;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-08 15:07:35 +08:00
|
|
|
/**************** SOURCE PACKAGING ************************/
|
|
|
|
|
1996-02-21 00:00:04 +08:00
|
|
|
int packageSource(Spec s, char *passPhrase)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1996-01-08 15:07:35 +08:00
|
|
|
struct sources *source;
|
|
|
|
struct PackageRec *package;
|
|
|
|
char *tempdir;
|
1996-06-28 01:21:31 +08:00
|
|
|
char src[1024], dest[1024], fullname[1024], filename[1024];
|
1996-01-08 15:07:35 +08:00
|
|
|
char *version;
|
|
|
|
char *release;
|
1996-02-19 10:24:47 +08:00
|
|
|
char *vendor;
|
|
|
|
char *dist;
|
1996-06-28 01:21:31 +08:00
|
|
|
char *p;
|
1996-01-08 15:07:35 +08:00
|
|
|
Header outHeader;
|
|
|
|
StringBuf filelist;
|
1996-06-28 01:21:31 +08:00
|
|
|
StringBuf cpioFileList;
|
1996-01-10 07:41:35 +08:00
|
|
|
int size;
|
1996-01-18 02:17:50 +08:00
|
|
|
char **sources;
|
|
|
|
char **patches;
|
|
|
|
int scount, pcount;
|
1996-06-28 01:21:31 +08:00
|
|
|
int skipi;
|
|
|
|
int_32 *skip;
|
1996-01-08 15:07:35 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/**** Create links for all the sources ****/
|
|
|
|
|
1996-03-29 09:26:20 +08:00
|
|
|
tempdir = tempnam("/var/tmp", "rpmbuild");
|
1996-01-08 15:07:35 +08:00
|
|
|
mkdir(tempdir, 0700);
|
|
|
|
|
1996-06-28 01:21:31 +08:00
|
|
|
filelist = newStringBuf(); /* List in the header */
|
|
|
|
cpioFileList = newStringBuf(); /* List for cpio */
|
1996-01-18 02:17:50 +08:00
|
|
|
|
1996-02-17 01:37:53 +08:00
|
|
|
sources = malloc((s->numSources+1) * sizeof(char *));
|
|
|
|
patches = malloc((s->numPatches+1) * sizeof(char *));
|
1996-01-08 15:07:35 +08:00
|
|
|
|
|
|
|
/* Link in the spec file and all the sources */
|
1996-06-28 01:21:31 +08:00
|
|
|
p = strrchr(s->specfile, '/');
|
|
|
|
sprintf(dest, "%s%s", tempdir, p);
|
1996-01-08 15:07:35 +08:00
|
|
|
symlink(s->specfile, dest);
|
|
|
|
appendLineStringBuf(filelist, dest);
|
1996-06-28 01:21:31 +08:00
|
|
|
appendLineStringBuf(cpioFileList, p+1);
|
1996-01-08 15:07:35 +08:00
|
|
|
source = s->sources;
|
1996-01-18 02:17:50 +08:00
|
|
|
scount = 0;
|
|
|
|
pcount = 0;
|
1996-01-08 15:07:35 +08:00
|
|
|
while (source) {
|
1996-06-28 01:21:31 +08:00
|
|
|
if (source->ispatch) {
|
|
|
|
skipi = s->numNoPatch - 1;
|
|
|
|
skip = s->noPatch;
|
|
|
|
} else {
|
|
|
|
skipi = s->numNoSource - 1;
|
|
|
|
skip = s->noSource;
|
|
|
|
}
|
|
|
|
while (skipi >= 0) {
|
|
|
|
if (skip[skipi] == source->num) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
skip--;
|
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
sprintf(src, "%s/%s", getVar(RPMVAR_SOURCEDIR), source->source);
|
|
|
|
sprintf(dest, "%s/%s", tempdir, source->source);
|
1996-06-28 01:21:31 +08:00
|
|
|
if (skipi < 0) {
|
|
|
|
symlink(src, dest);
|
|
|
|
appendLineStringBuf(cpioFileList, source->source);
|
|
|
|
} else {
|
|
|
|
message(MESS_VERBOSE, "Skipping source/patch (%d): %s\n",
|
|
|
|
source->num, source->source);
|
|
|
|
}
|
|
|
|
appendLineStringBuf(filelist, src);
|
1996-01-18 02:17:50 +08:00
|
|
|
if (source->ispatch) {
|
|
|
|
patches[pcount++] = source->fullSource;
|
|
|
|
} else {
|
|
|
|
sources[scount++] = source->fullSource;
|
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
source = source->next;
|
|
|
|
}
|
|
|
|
/* ... and icons */
|
|
|
|
package = s->packages;
|
|
|
|
while (package) {
|
|
|
|
if (package->icon) {
|
|
|
|
sprintf(src, "%s/%s", getVar(RPMVAR_SOURCEDIR), package->icon);
|
1996-01-29 11:33:06 +08:00
|
|
|
sprintf(dest, "%s/%s", tempdir, package->icon);
|
1996-01-08 15:07:35 +08:00
|
|
|
appendLineStringBuf(filelist, dest);
|
1996-06-28 01:21:31 +08:00
|
|
|
appendLineStringBuf(cpioFileList, package->icon);
|
1996-01-08 15:07:35 +08:00
|
|
|
symlink(src, dest);
|
|
|
|
}
|
|
|
|
package = package->next;
|
|
|
|
}
|
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/**** Generate the Header ****/
|
1996-01-08 15:07:35 +08:00
|
|
|
|
|
|
|
if (!getEntry(s->packages->header, RPMTAG_VERSION, NULL,
|
|
|
|
(void *) &version, NULL)) {
|
|
|
|
error(RPMERR_BADSPEC, "No version field");
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
if (!getEntry(s->packages->header, RPMTAG_RELEASE, NULL,
|
|
|
|
(void *) &release, NULL)) {
|
|
|
|
error(RPMERR_BADSPEC, "No release field");
|
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
outHeader = copyHeader(s->packages->header);
|
1996-07-02 05:37:18 +08:00
|
|
|
addEntry(outHeader, RPMTAG_OS, STRING_TYPE, getOsName(), 1);
|
|
|
|
addEntry(outHeader, RPMTAG_ARCH, STRING_TYPE, getArchName(), 1);
|
1996-06-08 02:31:31 +08:00
|
|
|
addEntry(outHeader, RPMTAG_BUILDTIME, INT32_TYPE, getBuildTime(), 1);
|
1996-01-12 15:31:41 +08:00
|
|
|
addEntry(outHeader, RPMTAG_BUILDHOST, STRING_TYPE, buildHost(), 1);
|
1996-02-15 00:56:02 +08:00
|
|
|
if (scount)
|
|
|
|
addEntry(outHeader, RPMTAG_SOURCE, STRING_ARRAY_TYPE, sources, scount);
|
|
|
|
if (pcount)
|
|
|
|
addEntry(outHeader, RPMTAG_PATCH, STRING_ARRAY_TYPE, patches, pcount);
|
1996-06-28 01:21:31 +08:00
|
|
|
if (s->numNoSource) {
|
|
|
|
addEntry(outHeader, RPMTAG_NOSOURCE, INT32_TYPE, s->noSource,
|
|
|
|
s->numNoSource);
|
|
|
|
}
|
|
|
|
if (s->numNoPatch) {
|
|
|
|
addEntry(outHeader, RPMTAG_NOPATCH, INT32_TYPE, s->noPatch,
|
|
|
|
s->numNoPatch);
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
if (!isEntry(s->packages->header, RPMTAG_VENDOR)) {
|
|
|
|
if ((vendor = getVar(RPMVAR_VENDOR))) {
|
|
|
|
addEntry(outHeader, RPMTAG_VENDOR, STRING_TYPE, vendor, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isEntry(s->packages->header, RPMTAG_DISTRIBUTION)) {
|
|
|
|
if ((dist = getVar(RPMVAR_DISTRIBUTION))) {
|
|
|
|
addEntry(outHeader, RPMTAG_DISTRIBUTION, STRING_TYPE, dist, 1);
|
|
|
|
}
|
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/* Process the file list */
|
1996-05-08 02:49:33 +08:00
|
|
|
if (process_filelist(outHeader, NULL, filelist, &size,
|
1996-01-29 11:33:06 +08:00
|
|
|
s->name, version, release, RPMLEAD_SOURCE)) {
|
1996-01-08 15:07:35 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-06-28 01:21:31 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/* And add the final Header entry */
|
1996-01-10 07:41:35 +08:00
|
|
|
addEntry(outHeader, RPMTAG_SIZE, INT32_TYPE, &size, 1);
|
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/**** Make the RPM ****/
|
1996-01-08 15:07:35 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
sprintf(fullname, "%s-%s-%s", s->name, version, release);
|
1996-06-28 01:21:31 +08:00
|
|
|
sprintf(filename, "%s/%s.%ssrc.rpm", getVar(RPMVAR_SRPMDIR), fullname,
|
|
|
|
(s->numNoPatch + s->numNoSource) ? "no" : "");
|
1996-02-21 07:31:59 +08:00
|
|
|
message(MESS_VERBOSE, "Source Packaging: %s\n", fullname);
|
1996-06-28 01:21:31 +08:00
|
|
|
|
|
|
|
if (generateRPM(fullname, filename, RPMLEAD_SOURCE, outHeader,
|
|
|
|
tempdir, getStringBuf(cpioFileList), passPhrase)) {
|
1996-02-22 09:35:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/**** Now clean up ****/
|
1996-01-08 15:07:35 +08:00
|
|
|
|
|
|
|
freeStringBuf(filelist);
|
1996-06-28 01:21:31 +08:00
|
|
|
freeStringBuf(cpioFileList);
|
1996-01-08 15:07:35 +08:00
|
|
|
|
|
|
|
source = s->sources;
|
|
|
|
while (source) {
|
|
|
|
sprintf(dest, "%s/%s", tempdir, source->source);
|
|
|
|
unlink(dest);
|
|
|
|
source = source->next;
|
|
|
|
}
|
|
|
|
package = s->packages;
|
|
|
|
while (package) {
|
|
|
|
if (package->icon) {
|
1996-01-29 11:33:06 +08:00
|
|
|
sprintf(dest, "%s/%s", tempdir, package->icon);
|
1996-01-08 15:07:35 +08:00
|
|
|
unlink(dest);
|
|
|
|
}
|
|
|
|
package = package->next;
|
|
|
|
}
|
1996-01-29 11:33:06 +08:00
|
|
|
sprintf(dest, "%s%s", tempdir, strrchr(s->specfile, '/'));
|
|
|
|
unlink(dest);
|
1996-01-08 15:07:35 +08:00
|
|
|
rmdir(tempdir);
|
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|