summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-11-12 04:55:40 +0000
committerjkh <jkh@FreeBSD.org>1995-11-12 04:55:40 +0000
commit9109257a8a8ad0586cdffb23f0a57867e8346d57 (patch)
treece93b1d4f10c4f035a65aa2e14c6eba70aa2a8f8 /usr.sbin
parent4b9555d70cffed7161182736b4955899d3daa55a (diff)
downloadFreeBSD-src-9109257a8a8ad0586cdffb23f0a57867e8346d57.zip
FreeBSD-src-9109257a8a8ad0586cdffb23f0a57867e8346d57.tar.gz
Bring my pkg_install improvements forward from 2.1.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_install/add/main.c52
-rw-r--r--usr.sbin/pkg_install/add/perform.c41
-rw-r--r--usr.sbin/pkg_install/delete/perform.c15
-rw-r--r--usr.sbin/pkg_install/lib/file.c79
-rw-r--r--usr.sbin/pkg_install/lib/plist.c36
5 files changed, 117 insertions, 106 deletions
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c
index 750121f..26e5e30 100644
--- a/usr.sbin/pkg_install/add/main.c
+++ b/usr.sbin/pkg_install/add/main.c
@@ -1,5 +1,5 @@
#ifndef lint
-static char *rcsid = "$Id: main.c,v 1.7.4.2 1995/10/14 19:11:01 jkh Exp $";
+static char *rcsid = "$Id: main.c,v 1.8 1995/10/25 15:37:47 jkh Exp $";
#endif
/*
@@ -23,6 +23,7 @@ static char *rcsid = "$Id: main.c,v 1.7.4.2 1995/10/14 19:11:01 jkh Exp $";
*
*/
+#include <sys/param.h>
#include "lib.h"
#include "add.h"
@@ -41,15 +42,19 @@ char *Directory = NULL;
char FirstPen[FILENAME_MAX];
add_mode_t AddMode = NORMAL;
+#define MAX_PKGS 20
+char pkgnames[MAX_PKGS][MAXPATHLEN];
+char *pkgs[MAX_PKGS];
+
int
main(int argc, char **argv)
{
int ch, err;
- char **pkgs, **start;
- char *prog_name = argv[0];
+ char **start;
+ char *prog_name = argv[0], *cp;
- pkgs = start = argv;
- while ((ch = getopt(argc, argv, Options)) != EOF)
+ start = argv;
+ while ((ch = getopt(argc, argv, Options)) != EOF) {
switch(ch) {
case 'v':
Verbose = TRUE;
@@ -94,23 +99,40 @@ main(int argc, char **argv)
usage(prog_name, NULL);
break;
}
-
+ }
argc -= optind;
argv += optind;
- /* Get all the remaining package names, if any */
- while (*argv)
- *pkgs++ = *argv++;
+ if (argc > MAX_PKGS) {
+ whinge("Too many packages (max %d).", MAX_PKGS);
+ return(1);
+ }
+ if (AddMode != SLAVE) {
+ for (ch = 0; ch < MAX_PKGS; pkgs[ch++] = NULL) ;
+
+ /* Get all the remaining package names, if any */
+ for (ch = 0; *argv; ch++, argv++) {
+ if (isURL(*argv)) /* preserve URLs */
+ pkgs[ch] = strcpy(pkgnames[ch], *argv);
+ else { /* expand all pathnames to fullnames */
+ if (fexists(*argv)) /* refers to a file directly */
+ pkgs[ch] = realpath(*argv, pkgnames[ch]);
+ else { /* look for the file in the expected places */
+ if (!(cp = fileFindByPath(NULL, *argv)))
+ whinge("Can't find package '%s'.", *argv);
+ else
+ pkgs[ch] = strcpy(pkgnames[ch], cp);
+ }
+ }
+ }
+ }
/* If no packages, yelp */
- *pkgs = NULL;
- if (pkgs == start && AddMode != SLAVE)
+ else if (!ch)
usage(prog_name, "Missing package name(s)");
- else if (start[1] && AddMode == MASTER)
+ else if (ch > 1 && AddMode == MASTER)
usage(prog_name, "Only one package name may be specified with master mode");
- else if (pkgs != start && AddMode == SLAVE)
- whinge("Package names ignored in slave mode.");
- if ((err = pkg_perform(start)) != NULL) {
+ if ((err = pkg_perform(pkgs)) != NULL) {
if (Verbose)
fprintf(stderr, "%d package addition(s) failed.\n", err);
return err;
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c
index a6ee117..156de99 100644
--- a/usr.sbin/pkg_install/add/perform.c
+++ b/usr.sbin/pkg_install/add/perform.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: perform.c,v 1.30 1995/10/25 15:37:49 jkh Exp $";
+static const char *rcsid = "$Id: perform.c,v 1.31 1995/10/31 20:30:15 jkh Exp $";
#endif
/*
@@ -107,21 +107,7 @@ pkg_do(char *pkg)
fclose(cfile);
}
else {
- if (pkg[0] == '/') /* full pathname? */
- strcpy(pkg_fullname, pkg);
- else {
- char cwd[FILENAME_MAX];
- sprintf(pkg_fullname, "%s/%s", getwd(cwd),pkg);
- }
- if (!fexists(pkg_fullname)) {
- cp = fileFindByPath(NULL, pkg);
-
- if (!cp) {
- whinge("Can't find package `%s'.", pkg);
- return 1;
- }
- strcpy(pkg_fullname, cp);
- }
+ strcpy(pkg_fullname,pkg); /* copy for sanity's sake, could remove pkg_fullname */
if (stat(pkg_fullname, &sb) == FAIL) {
whinge("Can't stat package file '%s'.", pkg_fullname);
goto bomb;
@@ -174,7 +160,7 @@ pkg_do(char *pkg)
* compress an average of 75%, so multiply by 4 for good measure.
*/
- if (min_free(where_to) < sb.st_size * 4) {
+ if (min_free(playpen) < sb.st_size * 4) {
whinge("Projected size of %d exceeds available free space.\n"
"Please set your PKG_TMPDIR variable to point to a location with more\n"
"free space and try again.", sb.st_size * 4);
@@ -236,7 +222,7 @@ pkg_do(char *pkg)
if (!Fake && vsystem("pkg_info -e %s", p->name)) {
char path[FILENAME_MAX], *cp = NULL;
- if (!Fake && !isURL(pkg)) {
+ if (!Fake && !isURL(pkg) && !getenv("PKG_ADD_BASE")) {
snprintf(path, FILENAME_MAX, "%s/%s.tgz", Home, p->name);
if (fexists(path))
cp = path;
@@ -255,14 +241,19 @@ pkg_do(char *pkg)
else if (!Fake && (cp = fileGetURL(pkg, p->name)) != NULL) {
if (Verbose)
printf("Finished loading %s over FTP.\n", p->name);
- if (!Fake && (!fexists("+CONTENTS") || vsystem("(pwd; cat +CONTENTS) | pkg_add %s-S"),
- Verbose ? "-v " : "")) {
- whinge("Autoload of dependency `%s' failed%s", p->name, Force ? " (proceeding anyway)" : "!");
- if (!Force)
- ++code;
+ if (!Fake) {
+ if (!fexists("+CONTENTS"))
+ whinge("Autoloaded package %s has no +CONTENTS file?", p->name);
+ else
+ if (vsystem("(pwd; cat +CONTENTS) | pkg_add %s-S", Verbose ? "-v " : "")) {
+ whinge("pkg_add of dependency `%s' failed%s",
+ p->name, Force ? " (proceeding anyway)" : "!");
+ if (!Force)
+ ++code;
+ }
+ else if (Verbose)
+ printf("\t`%s' loaded successfully.\n", p->name);
}
- else if (Verbose)
- printf("\t`%s' loaded successfully.\n", p->name);
/* Nuke the temporary playpen */
leave_playpen(cp);
}
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c
index 6449fd4..fefe6e8 100644
--- a/usr.sbin/pkg_install/delete/perform.c
+++ b/usr.sbin/pkg_install/delete/perform.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: perform.c,v 1.6 1994/12/06 00:51:40 jkh Exp $";
+static const char *rcsid = "$Id: perform.c,v 1.7.4.1 1995/11/10 06:44:47 jkh Exp $";
#endif
/*
@@ -120,10 +120,15 @@ pkg_do(char *pkg)
}
if (chdir(home) == FAIL)
barf("Toto! This doesn't look like Kansas anymore!");
- if (!Fake && delete_package(FALSE, CleanDirs, &Plist) != FAIL &&
- vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
- whinge("Couldn't remove log entry in %s, de-install failed.", LogDir);
- return 1;
+ if (!Fake) {
+ /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */
+ if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
+ warn("Couldn't entirely delete package (perhaps the packing list is\n"
+ "incorrectly specified?)\n");
+ if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
+ whinge("Couldn't remove log entry in %s, de-install failed.", LogDir);
+ return 1;
+ }
}
for (p = Plist.head; p ; p = p->next) {
if (p->type != PLIST_PKGDEP)
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index ce17e97..ac98530 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: file.c,v 1.17 1995/10/25 15:38:32 jkh Exp $";
+static const char *rcsid = "$Id: file.c,v 1.18 1995/10/31 20:30:18 jkh Exp $";
#endif
/*
@@ -174,7 +174,7 @@ fileGetURL(char *base, char *spec)
{
char host[HOSTNAME_MAX], file[FILENAME_MAX], dir[FILENAME_MAX];
char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp, *tmp;
- char fname[511];
+ char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
struct passwd *pw;
FTP_t ftp;
@@ -182,39 +182,40 @@ fileGetURL(char *base, char *spec)
int fd, fd2, i, len = 0;
char ch;
time_t start, stop;
+ char *hint;
rp = NULL;
+ /* Special tip that sysinstall left for us */
+ hint = getenv("PKG_ADD_BASE");
if (!isURL(spec)) {
int len;
- if (!base)
+ if (!base && !hint)
return NULL;
/* We've been given an existing URL (that's known-good) and now we need
to construct a composite one out of that and the basename we were
handed as a dependency. */
- strncpy(fname, base, 511);
- fname[511] = '\0';
- cp = strrchr(fname, '/');
- if (cp) {
- *cp = '\0'; /* Eliminate the filename portion */
- len = strlen(fname);
- /* Special case for the all category */
- if (len > 3 && !strcmp(cp - 3, "All"))
- sprintf(cp, "/%s", spec);
- else {
- /* Replace category with All */
- if ((cp = strrchr(fname, '/')) != NULL) {
- strcat(cp + 1, "All/");
- strcat(cp + 4, spec);
- }
- else {
- strcat(fname, "All/");
- strcat(fname, spec);
- }
+ if (base) {
+ strcpy(fname, base);
+ /* Advance back two slashes to get to the root of the package hierarchy */
+ cp = strrchr(fname, '/');
+ if (cp) {
+ *cp = '\0'; /* chop name */
+ cp = strrchr(fname, '/');
+ }
+ if (cp) {
+ *(cp + 1) = '\0';
+ strcat(cp, "All/");
+ strcat(cp, spec);
}
+ else
+ return NULL;
+ }
+ else {
+ /* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
+ strcpy(fname, hint);
+ strcat(fname, spec);
}
- else
- return NULL;
}
else
strcpy(fname, spec);
@@ -298,7 +299,6 @@ fileFindByPath(char *base, char *fname)
{
static char tmp[FILENAME_MAX];
char *cp;
- int len;
if (fexists(fname) && isfile(fname)) {
strcpy(tmp, fname);
@@ -306,28 +306,19 @@ fileFindByPath(char *base, char *fname)
}
if (base) {
strcpy(tmp, base);
- cp = strchr(tmp, '/');
- len = strlen(tmp);
+ cp = strrchr(fname, '/');
if (cp) {
- /* Special case for the all category */
- if (len > 3 && !strncmp(cp - 3, "All/", 4))
- strcat(cp + 1, fname);
- else {
- *cp = '\0';
- /* Replace category with All */
- if ((cp = strrchr(tmp, '/')) != NULL) {
- strcat(cp + 1, "All/");
- strcat(cp, fname);
- }
- else {
- strcat(tmp, "All/");
- strcat(tmp, fname);
- }
- }
+ *cp = '\0'; /* chop name */
+ cp = strrchr(fname, '/');
+ }
+ if (cp) {
+ *(cp + 1) = '\0';
+ strcat(cp, "All/");
+ strcat(cp, fname);
+ if (fexists(tmp))
+ return tmp;
}
- if (fexists(tmp))
- return tmp;
}
cp = getenv("PKG_PATH");
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index bc497ad..132c6e1 100644
--- a/usr.sbin/pkg_install/lib/plist.c
+++ b/usr.sbin/pkg_install/lib/plist.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: plist.c,v 1.13 1995/05/30 03:50:07 rgrimes Exp $";
+static const char *rcsid = "$Id: plist.c,v 1.14 1995/07/28 01:50:35 ache Exp $";
#endif
/*
@@ -287,18 +287,15 @@ write_plist(Package *pkg, FILE *fp)
break;
case PLIST_CHMOD:
- fprintf(fp, "%cmode %s\n", CMD_CHAR,
- plist->name ? plist->name : "");
+ fprintf(fp, "%cmode %s\n", CMD_CHAR, plist->name ? plist->name : "");
break;
case PLIST_CHOWN:
- fprintf(fp, "%cowner %s\n", CMD_CHAR,
- plist->name ? plist->name : "");
+ fprintf(fp, "%cowner %s\n", CMD_CHAR, plist->name ? plist->name : "");
break;
case PLIST_CHGRP:
- fprintf(fp, "%cgroup %s\n", CMD_CHAR,
- plist->name ? plist->name : "");
+ fprintf(fp, "%cgroup %s\n", CMD_CHAR, plist->name ? plist->name : "");
break;
case PLIST_COMMENT:
@@ -355,6 +352,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
char *Where = ".", *last_file = "";
Boolean fail = SUCCESS;
+ if (!p)
+ return FAIL;
while (p) {
if (p->type == PLIST_CWD) {
Where = p->name;
@@ -378,14 +377,18 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
char full_name[FILENAME_MAX];
sprintf(full_name, "%s/%s", Where, p->name);
- if (Verbose)
- printf("Delete%s %s\n",
- p->type == PLIST_FILE ? "" : " directory", full_name);
-
- if (!Fake && delete_hierarchy(full_name, ign_err,
- p->type == PLIST_DIR_RM ? FALSE : nukedirs)) {
- whinge("Unable to completely remove file '%s'", full_name);
- fail = FAIL;
+ if (isdir(full_name) && p->type == PLIST_FILE) {
+ warn("Attempting to delete directory `%s' as a file\n"
+ "This packing list is incorrect - ignoring delete request.\n", full_name);
+ }
+ else {
+ if (Verbose)
+ printf("Delete %s %s\n", !isdir(full_name) ? "file" : " directory", full_name);
+
+ if (!Fake && delete_hierarchy(full_name, ign_err, p->type == PLIST_DIR_RM ? FALSE : nukedirs)) {
+ whinge("Unable to completely remove file '%s'", full_name);
+ fail = FAIL;
+ }
}
last_file = p->name;
}
@@ -411,8 +414,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
cp1 = cp2 = dir;
if (!fexists(dir)) {
if (!ign_err)
- whinge("%s `%s' doesn't really exist.",
- isdir(dir) ? "Directory" : "File", dir);
+ whinge("%s `%s' doesn't really exist.", isdir(dir) ? "Directory" : "File", dir);
} else if (nukedirs) {
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
return 1;
OpenPOWER on IntegriCloud