1996-03-01 09:57:52 +08:00
|
|
|
#include <alloca.h>
|
1996-01-06 02:12:55 +08:00
|
|
|
#include <fcntl.h>
|
1996-01-23 05:12:55 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1996-01-09 03:21:55 +08:00
|
|
|
#include <unistd.h>
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-02-28 01:37:06 +08:00
|
|
|
#include "ftp.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
#include "install.h"
|
|
|
|
#include "lib/rpmlib.h"
|
1996-01-09 03:21:55 +08:00
|
|
|
#include "messages.h"
|
1996-02-15 04:56:22 +08:00
|
|
|
#include "query.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-01-23 05:12:55 +08:00
|
|
|
static int hashesPrinted = 0;
|
|
|
|
|
|
|
|
static void printHash(const unsigned long amount, const unsigned long total);
|
|
|
|
static void printPercent(const unsigned long amount, const unsigned long total);
|
1996-03-01 09:57:52 +08:00
|
|
|
static int getFtpURL(char * prefix, char * hostAndFile);
|
1996-01-23 05:12:55 +08:00
|
|
|
|
|
|
|
static void printHash(const unsigned long amount, const unsigned long total) {
|
|
|
|
int hashesNeeded;
|
|
|
|
|
|
|
|
if (hashesPrinted != 50) {
|
1996-03-13 11:51:56 +08:00
|
|
|
hashesNeeded = 50 * (total ? (((float) amount) / total) : 1);
|
1996-01-23 05:12:55 +08:00
|
|
|
while (hashesNeeded > hashesPrinted) {
|
|
|
|
printf("#");
|
|
|
|
hashesPrinted++;
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
hashesPrinted = hashesNeeded;
|
|
|
|
|
|
|
|
if (hashesPrinted == 50)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printPercent(const unsigned long amount, const unsigned long total)
|
|
|
|
{
|
1996-03-13 11:51:56 +08:00
|
|
|
printf("%%%% %f\n", (total
|
|
|
|
? ((float) ((((float) amount) / total) * 100))
|
|
|
|
: 100.0));
|
1996-02-15 07:21:02 +08:00
|
|
|
fflush(stdout);
|
1996-01-23 05:12:55 +08:00
|
|
|
}
|
|
|
|
|
1996-04-03 11:46:41 +08:00
|
|
|
int doInstall(char * prefix, char * arg, int installFlags, int interfaceFlags) {
|
1996-01-09 03:21:55 +08:00
|
|
|
rpmdb db;
|
|
|
|
int fd;
|
|
|
|
int mode, rc;
|
1996-01-23 05:12:55 +08:00
|
|
|
char * chptr;
|
|
|
|
notifyFunction fn;
|
1996-02-25 07:46:09 +08:00
|
|
|
char * printFormat = NULL;
|
1996-01-09 03:21:55 +08:00
|
|
|
|
1996-01-23 05:12:55 +08:00
|
|
|
hashesPrinted = 0;
|
|
|
|
|
|
|
|
if (installFlags & INSTALL_TEST)
|
1996-01-09 03:21:55 +08:00
|
|
|
mode = O_RDONLY;
|
|
|
|
else
|
1996-02-15 08:10:15 +08:00
|
|
|
mode = O_RDWR;
|
1996-01-23 05:12:55 +08:00
|
|
|
|
|
|
|
if (interfaceFlags & RPMINSTALL_PERCENT)
|
|
|
|
fn = printPercent;
|
|
|
|
else if (interfaceFlags & RPMINSTALL_HASH)
|
|
|
|
fn = printHash;
|
|
|
|
else
|
|
|
|
fn = NULL;
|
1996-01-09 03:21:55 +08:00
|
|
|
|
1996-02-19 12:50:15 +08:00
|
|
|
if (rpmdbOpen(prefix, &db, mode | O_CREAT, 0644)) {
|
1996-02-15 08:10:15 +08:00
|
|
|
fprintf(stderr, "error: cannot open %s/var/lib/rpm/packages.rpm\n",
|
|
|
|
prefix);
|
|
|
|
exit(1);
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
message(MESS_DEBUG, "installing %s\n", arg);
|
1996-02-28 01:37:06 +08:00
|
|
|
|
|
|
|
if (!strncmp(arg, "ftp://", 6)) {
|
|
|
|
if (isVerbose()) {
|
|
|
|
printf("Retrieving %s\n", arg);
|
|
|
|
}
|
1996-03-01 09:57:52 +08:00
|
|
|
fd = getFtpURL(prefix, arg + 6);
|
1996-02-28 01:37:06 +08:00
|
|
|
if (fd < 0) {
|
1996-03-29 09:19:10 +08:00
|
|
|
fprintf(stderr, "error: ftp of %s failed - %s\n", arg,
|
|
|
|
ftpStrerror(fd));
|
1996-04-03 11:46:41 +08:00
|
|
|
return 1;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fd = open(arg, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
rpmdbClose(db);
|
|
|
|
fprintf(stderr, "error: cannot open %s\n", arg);
|
1996-04-03 11:46:41 +08:00
|
|
|
return 1;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
1996-01-23 05:12:55 +08:00
|
|
|
if (interfaceFlags & RPMINSTALL_PERCENT)
|
1996-02-25 07:46:09 +08:00
|
|
|
printFormat = "%%f %s:%s:%s\n";
|
1996-01-23 05:12:55 +08:00
|
|
|
else if (isVerbose() && (interfaceFlags & RPMINSTALL_HASH)) {
|
|
|
|
chptr = strrchr(arg, '/');
|
|
|
|
if (!chptr)
|
|
|
|
chptr = arg;
|
|
|
|
else
|
|
|
|
chptr++;
|
|
|
|
|
1996-02-25 07:46:09 +08:00
|
|
|
printFormat = "%-28s";
|
1996-01-23 05:12:55 +08:00
|
|
|
} else if (isVerbose())
|
|
|
|
printf("Installing %s\n", arg);
|
|
|
|
|
1996-02-25 07:46:09 +08:00
|
|
|
rc = rpmInstallPackage(prefix, db, fd, installFlags, fn, printFormat);
|
1996-01-09 03:21:55 +08:00
|
|
|
if (rc == 1) {
|
1996-04-06 01:35:45 +08:00
|
|
|
fprintf(stderr, "error: %s does not appear to be a RPM package\n", arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc) {
|
1996-01-14 06:02:24 +08:00
|
|
|
fprintf(stderr, "error: %s cannot be installed\n", arg);
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
rpmdbClose(db);
|
1996-04-03 11:46:41 +08:00
|
|
|
|
|
|
|
return rc;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1996-04-16 06:21:21 +08:00
|
|
|
void doUninstall(char * prefix, char * arg, int flags, int uninstallFlags) {
|
1996-01-06 02:12:55 +08:00
|
|
|
rpmdb db;
|
|
|
|
dbIndexSet matches;
|
|
|
|
int i;
|
1996-01-09 03:21:55 +08:00
|
|
|
int mode;
|
1996-02-15 04:56:22 +08:00
|
|
|
int rc;
|
|
|
|
int count;
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-04-16 06:21:21 +08:00
|
|
|
if (flags & UNINSTALL_TEST)
|
1996-01-09 03:21:55 +08:00
|
|
|
mode = O_RDONLY;
|
|
|
|
else
|
|
|
|
mode = O_RDWR | O_EXCL;
|
|
|
|
|
1996-02-19 12:50:15 +08:00
|
|
|
if (rpmdbOpen(prefix, &db, mode, 0644)) {
|
1996-01-06 02:12:55 +08:00
|
|
|
fprintf(stderr, "cannot open %s/var/lib/rpm/packages.rpm\n", prefix);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1996-02-15 04:56:22 +08:00
|
|
|
rc = findPackageByLabel(db, arg, &matches);
|
|
|
|
if (rc == 1)
|
1996-01-06 02:12:55 +08:00
|
|
|
fprintf(stderr, "package %s is not installed\n", arg);
|
1996-02-15 04:56:22 +08:00
|
|
|
else if (rc == 2)
|
|
|
|
fprintf(stderr, "error searching for package %s\n", arg);
|
|
|
|
else {
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < matches.count; i++)
|
|
|
|
if (matches.recs[i].recOffset) count++;
|
|
|
|
|
|
|
|
if (count > 1) {
|
1996-01-06 02:12:55 +08:00
|
|
|
fprintf(stderr, "\"%s\" specifies multiple packages\n", arg);
|
|
|
|
}
|
1996-01-06 08:05:14 +08:00
|
|
|
else {
|
|
|
|
for (i = 0; i < matches.count; i++) {
|
1996-02-15 04:56:22 +08:00
|
|
|
if (matches.recs[i].recOffset) {
|
|
|
|
message(MESS_DEBUG, "uninstalling record number %d\n",
|
|
|
|
matches.recs[i].recOffset);
|
|
|
|
rpmRemovePackage(prefix, db, matches.recs[i].recOffset,
|
1996-05-23 03:27:16 +08:00
|
|
|
0, flags & UNINSTALL_TEST);
|
1996-02-15 04:56:22 +08:00
|
|
|
}
|
1996-01-06 08:05:14 +08:00
|
|
|
}
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
freeDBIndexRecord(matches);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmdbClose(db);
|
|
|
|
}
|
1996-02-15 04:09:14 +08:00
|
|
|
|
|
|
|
int doSourceInstall(char * prefix, char * arg, char ** specFile) {
|
|
|
|
int fd;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
fd = open(arg, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "error: cannot open %s\n", arg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVerbose())
|
|
|
|
printf("Installing %s\n", arg);
|
|
|
|
|
|
|
|
rc = rpmInstallSourcePackage(prefix, fd, specFile);
|
|
|
|
if (rc == 1) {
|
|
|
|
fprintf(stderr, "error: %s cannot be installed\n", arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
1996-02-28 01:37:06 +08:00
|
|
|
|
1996-03-01 09:57:52 +08:00
|
|
|
static int getFtpURL(char * prefix, char * hostAndFile) {
|
1996-02-28 01:37:06 +08:00
|
|
|
char * buf;
|
|
|
|
char * chptr;
|
|
|
|
int ftpconn;
|
|
|
|
int fd;
|
1996-03-29 09:19:10 +08:00
|
|
|
int rc;
|
|
|
|
|
1996-02-28 01:37:06 +08:00
|
|
|
char * tmp;
|
|
|
|
|
|
|
|
message(MESS_DEBUG, "getting %s via anonymous ftp\n", hostAndFile);
|
|
|
|
|
|
|
|
buf = alloca(strlen(hostAndFile) + 1);
|
|
|
|
strcpy(buf, hostAndFile);
|
|
|
|
|
|
|
|
chptr = buf;
|
|
|
|
while (*chptr && (*chptr != '/')) chptr++;
|
|
|
|
if (!*chptr) return -1;
|
|
|
|
|
|
|
|
*chptr = '\0';
|
|
|
|
|
|
|
|
ftpconn = ftpOpen(buf, NULL, NULL);
|
1996-03-29 09:19:10 +08:00
|
|
|
if (ftpconn < 0) return ftpconn;
|
1996-02-28 01:37:06 +08:00
|
|
|
|
|
|
|
*chptr = '/';
|
|
|
|
|
1996-03-01 09:57:52 +08:00
|
|
|
tmp = alloca(strlen(prefix) + 60);
|
1996-03-13 11:51:56 +08:00
|
|
|
sprintf(tmp, "%s/var/tmp/rpm.ftp.%d", prefix, getpid());
|
1996-02-28 01:37:06 +08:00
|
|
|
fd = creat(tmp, 0600);
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
unlink(tmp);
|
|
|
|
ftpClose(ftpconn);
|
1996-03-29 09:19:10 +08:00
|
|
|
return FTPERR_UNKNOWN;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
1996-03-29 09:19:10 +08:00
|
|
|
if ((rc = ftpGetFile(ftpconn, chptr, fd))) {
|
1996-02-28 01:37:06 +08:00
|
|
|
unlink(tmp);
|
|
|
|
close(fd);
|
|
|
|
ftpClose(ftpconn);
|
1996-03-29 09:19:10 +08:00
|
|
|
return rc;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ftpClose(ftpconn);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
fd = open(tmp, O_RDONLY);
|
|
|
|
|
|
|
|
unlink(tmp);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|