diff options
| author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1995-08-30 07:50:02 +0000 |
|---|---|---|
| committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1995-08-30 07:50:02 +0000 |
| commit | 3882688cee4ce55e06eba49dc887286a96e6bf20 (patch) | |
| tree | 28b5fe1178b4fa5256008c82a6de1a495509a92b /usr.sbin/pkg_install | |
| parent | 4a053744bd0e5312ab87f7619310da9a2520293c (diff) | |
Notes
Diffstat (limited to 'usr.sbin/pkg_install')
| -rw-r--r-- | usr.sbin/pkg_install/add/Makefile | 3 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 21 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/pkg_add.1 | 14 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/Makefile | 3 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/Makefile | 3 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/info/Makefile | 3 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/info/perform.c | 4 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/info/show.c | 14 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/Makefile | 2 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 107 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 5 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/msg.c | 4 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 55 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 4 |
14 files changed, 130 insertions, 112 deletions
diff --git a/usr.sbin/pkg_install/add/Makefile b/usr.sbin/pkg_install/add/Makefile index e4bd6764e94f..e0fdcffb3101 100644 --- a/usr.sbin/pkg_install/add/Makefile +++ b/usr.sbin/pkg_install/add/Makefile @@ -2,9 +2,6 @@ PROG= pkg_add CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -LDADD+= -lftp -DPADD+= ${LIBFTP} - .if exists(${.CURDIR}/../lib/obj) LDADD+= -L${.CURDIR}/../lib/obj -linstall DPADD+= ${.CURDIR}/../lib/obj/libinstall.a diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 575fef6f935e..8fc3cfc0bd54 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.25.2.2 1995/06/10 09:04:13 jkh Exp $"; +static const char *rcsid = "$Id: perform.c,v 1.29 1995/08/17 00:35:41 jkh Exp $"; #endif /* @@ -117,7 +117,12 @@ pkg_do(char *pkg) strcpy(pkg_fullname, tmp); } } - Home = make_playpen(PlayPen, 0); + if (stat(pkg_fullname, &sb) == FAIL) { + whinge("Can't stat package file '%s'.", pkg_fullname); + goto bomb; + } + Home = make_playpen(PlayPen, sb.st_size * 4); + where_to = PlayPen; sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); if (unpack(pkg_fullname, extract_contents)) { whinge("Unable to extract table of contents file from `%s' - not a package?.", pkg_fullname); @@ -164,22 +169,16 @@ pkg_do(char *pkg) goto bomb; } } - else - where_to = PlayPen; + /* * Apply a crude heuristic to see how much space the package will * take up once it's unpacked. I've noticed that most packages * compress an average of 75%, so multiply by 4 for good measure. */ - if (stat(pkg_fullname, &sb) == FAIL) { - whinge("Can't stat package file '%s'.", pkg_fullname); - goto bomb; - } if (min_free(where_to) < sb.st_size * 4) { - whinge("Projected size of %d exceeds free space in %s.", - sb.st_size * 4, where_to); - whinge("Not extracting %s, sorry!", pkg_fullname); + whinge("Projected size of %d exceeds available free space.\nPlease set your PKG_TMPDIR variable to point to a location with more\nfree space and try again.", sb.st_size * 4); + whinge("Not extracting %s\ninto %s, sorry!", pkg_fullname, where_to); goto bomb; } diff --git a/usr.sbin/pkg_install/add/pkg_add.1 b/usr.sbin/pkg_install/add/pkg_add.1 index da4d1b7e3839..e136279ec041 100644 --- a/usr.sbin/pkg_install/add/pkg_add.1 +++ b/usr.sbin/pkg_install/add/pkg_add.1 @@ -116,7 +116,7 @@ as the input to .Xr mktemp 3 when creating a ``staging area.'' By default, this is the string -.Pa /tmp/instmp.XXXXXX , +.Pa /var/tmp/instmp.XXXXXX , but it may be necessary to override it in the situation where space in your .Pa /tmp @@ -173,6 +173,18 @@ URL pointing at a file available on an ftp site. Thus you may extract files directly from their anonymous ftp locations (e.g. .Nm ftp://ftp.freebsd.org/pub/FreeBSD/packages/shells/bash-1.14.4.tgz). +Note: If you wish to use +.B passive mode +ftp in such transfers, set +the variable +.B FTP_PASSIVE_MODE +to some value in your environment. Otherwise, the more standard +ACTIVE mode may be used. If +.Nm +consistently fails to fetch a package from a site known to work, +it may be because you have a firewall that demands the usage of +.B passive mode +ftp. .Sh TECHNICAL DETAILS .Nm is fairly simple. It extracts each packages' "packing list" diff --git a/usr.sbin/pkg_install/create/Makefile b/usr.sbin/pkg_install/create/Makefile index fcaada091bc1..ff33874a11f7 100644 --- a/usr.sbin/pkg_install/create/Makefile +++ b/usr.sbin/pkg_install/create/Makefile @@ -2,9 +2,6 @@ PROG= pkg_create CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -LDADD+= -lftp -DPADD+= ${LIBFTP} - .if exists(${.CURDIR}/../lib/obj) LDADD+= -L${.CURDIR}/../lib/obj -linstall DPADD+= ${.CURDIR}/../lib/obj/libinstall.a diff --git a/usr.sbin/pkg_install/delete/Makefile b/usr.sbin/pkg_install/delete/Makefile index 08a67eea1c6f..0c50a2aa98bd 100644 --- a/usr.sbin/pkg_install/delete/Makefile +++ b/usr.sbin/pkg_install/delete/Makefile @@ -1,9 +1,6 @@ PROG= pkg_delete CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -LDADD+= -lftp -DPADD+= ${LIBFTP} - .if exists(${.CURDIR}/../lib/obj) LDADD+= -L${.CURDIR}/../lib/obj -linstall DPADD+= ${.CURDIR}/../lib/obj/libinstall.a diff --git a/usr.sbin/pkg_install/info/Makefile b/usr.sbin/pkg_install/info/Makefile index bdfd5e060a31..3542e8d7411a 100644 --- a/usr.sbin/pkg_install/info/Makefile +++ b/usr.sbin/pkg_install/info/Makefile @@ -1,9 +1,6 @@ PROG= pkg_info CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -LDADD+= -lftp -DPADD+= ${LIBFTP} - .if exists(${.CURDIR}/../lib/obj) LDADD+= -L${.CURDIR}/../lib/obj -linstall DPADD+= ${.CURDIR}/../lib/obj/libinstall.a diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index 9a93253a841a..a4e81b89c507 100644 --- a/usr.sbin/pkg_install/info/perform.c +++ b/usr.sbin/pkg_install/info/perform.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: perform.c,v 1.15 1995/05/10 23:00:06 jkh Exp $"; +static const char *rcsid = "$Id: perform.c,v 1.17 1995/07/30 01:44:38 ache Exp $"; #endif /* @@ -91,7 +91,7 @@ pkg_do(char *pkg) isTMP = TRUE; } } - else if (fexists(pkg)) { + else if (fexists(pkg) && isfile(pkg)) { int len; if (*pkg != '/') { diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c index b1c29b3d1ca5..a4999790d13d 100644 --- a/usr.sbin/pkg_install/info/show.c +++ b/usr.sbin/pkg_install/info/show.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: show.c,v 1.5 1995/01/05 01:10:13 swallace Exp $"; +static const char *rcsid = "$Id: show.c,v 1.7 1995/07/30 01:08:34 ache Exp $"; #endif /* @@ -35,13 +35,13 @@ show_file(char *title, char *fname) if (!Quiet) printf("%s%s", InfoPrefix, title); fp = fopen(fname, "r"); - if (!fp) { - whinge("show_file: Can't open '%s' for reading.", fname); - return; + if (!fp) + printf("ERROR: show_file: Can't open '%s' for reading!\n", fname); + else { + while (n = fread(line, 1, 1024, fp)) + fwrite(line, 1, n, stdout); + fclose(fp); } - while (n = fread(line, 1, 1024, fp)) - fwrite(line, 1, n, stdout); - fclose(fp); printf("\n"); /* just in case */ } diff --git a/usr.sbin/pkg_install/lib/Makefile b/usr.sbin/pkg_install/lib/Makefile index 3876b109c3a7..223a33d3ebae 100644 --- a/usr.sbin/pkg_install/lib/Makefile +++ b/usr.sbin/pkg_install/lib/Makefile @@ -1,5 +1,5 @@ LIB= install -SRCS= file.c msg.c plist.c str.c exec.c global.c pen.c +SRCS= file.c ftp.c msg.c plist.c str.c exec.c global.c pen.c CFLAGS+= ${DEBUG} NOPROFILE= yes NOPIC= yes diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 29d969c59de1..6a81a8c3026c 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.9 1995/05/10 23:00:16 jkh Exp $"; +static const char *rcsid = "$Id: file.c,v 1.16 1995/08/01 09:49:27 jkh Exp $"; #endif /* @@ -23,14 +23,16 @@ static const char *rcsid = "$Id: file.c,v 1.9 1995/05/10 23:00:16 jkh Exp $"; */ #include "lib.h" -#include <FtpLibrary.h> +#include "ftp.h" #include <pwd.h> +#include <time.h> /* Quick check to see if a file exists */ Boolean fexists(char *fname) { - if (!access(fname, F_OK)) + struct stat dummy; + if (!lstat(fname, &dummy)) return TRUE; return FALSE; } @@ -70,6 +72,15 @@ isemptydir(char *fname) return FALSE; } +Boolean +isfile(char *fname) +{ + struct stat sb; + if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) + return TRUE; + return FALSE; +} + /* Check to see if file is a file and is empty. If nonexistent or not a file, say "it's empty", otherwise return TRUE if zero sized. */ Boolean @@ -151,52 +162,27 @@ fileURLFilename(char *fname, char *where, int max) return fname; } -/* - * Callback functions for fileGetURL - GetIO is called on I/O requests - * and GetAbort when the transfer aborts. - */ - -/* Something they can use to keep track of the action */ -Boolean connectionAborted = FALSE; - -static int -_fileGetIO(FTP *ftp, int n, char *s ) -{ - printf("In IO: %s\n", s); - return 0; -} - -static int -_fileGetAbort(FTP *ftp, int n, char *s ) -{ - /* No access or not found, exclude network or host unreachable */ - if (abs(n) == 550 && FtpBadReply550(s)) { - connectionAborted = TRUE; - return 1; - } - return 0; -} - #define HOSTNAME_MAX 64 - /* - * Try and fetch a file by URL, returning the name of the local - * copy if fetched successfully. + * Try and fetch a file by URL, returning the fd of open + * file if fetched successfully. */ char * fileGetURL(char *fname) { - static char out[FILENAME_MAX]; - char *cp; char host[HOSTNAME_MAX], file[FILENAME_MAX], dir[FILENAME_MAX]; - char pword[HOSTNAME_MAX + 40], *uname; + char pword[HOSTNAME_MAX + 40], *uname, *cp; + static char tmpl[40]; struct passwd *pw; - FTP *ftp; - int i; + FTP_t ftp; + int fd, fd2, i, len = 0; + char ch; + time_t start, stop; if (!isURL(fname)) return NULL; + ftp = FtpInit(); cp = fileURLHost(fname, host, HOSTNAME_MAX); if (!*cp) { whinge("URL `%s' has bad host part!", fname); @@ -209,10 +195,6 @@ fileGetURL(char *fname) return NULL; } - FtpSetErrorHandler(&FtpInit, _fileGetAbort); - FtpSetFlag(&FtpInit, FTP_REST); - FtpSetTimeout(&FtpInit, 60); /* XXX this may be too short */ - /* Maybe change to ftp if this doesn't work */ uname = "anonymous"; @@ -227,26 +209,43 @@ fileGetURL(char *fname) if (Verbose) printf("Trying to fetch %s from %s.\n", file, host); - FtpLogin(&ftp, host, uname, pword, NULL); + FtpOpen(ftp, host, uname, pword); + if (getenv("FTP_PASSIVE_MODE")) + FtpPassive(ftp, TRUE); strcpy(dir, file); for (i = strlen(dir); i && dir[i] != '/'; i--); dir[i] = '\0'; - if (dir[0]) + if (dir[0]) { + if (Verbose) printf("FTP: chdir to %s\n", dir); FtpChdir(ftp, dir); - FtpBinary(ftp); - + } + FtpBinary(ftp, TRUE); + if (Verbose) printf("FTP: trying to get %s\n", basename_of(file)); + fd = FtpGet(ftp, basename_of(file)); + if (fd < 0) + return NULL; if ((cp = getenv("PKG_TMPDIR")) != NULL) - sprintf(out, "%s/instpkg-XXXXXX.tgz", cp); + sprintf(tmpl, "%s/instpkg-XXXXXX.tgz", cp); else - strcpy(out, "/var/tmp/instpkg-XXXXXX.tgz"); - - FtpGet(ftp, basename_of(file), out); - FtpBye(ftp); - if (connectionAborted) + strcpy(tmpl, "/var/tmp/instpkg-XXXXXX.tgz"); + fd2 = mkstemp(tmpl); + if (fd2 < 0) { + whinge("Unable to create a temporary file for ftp: %s", tmpl); return NULL; - return out; + } + if (Verbose) printf("FTP: Trying to copy from ftp connection to temporary: %s\n", tmpl); + (void)time(&start); + while (read(fd, &ch, 1) == 1) { + ++len; + write(fd2, &ch, 1); + } + (void)time(&stop); + if (Verbose) printf("FTP: Read %d bytes from connection, %d elapsed seconds.\n%FTP: Average transfer rate: %d bytes/second.\n", len, stop - start, len / ((stop - start) + 1)); + FtpEOF(ftp); + FtpClose(ftp); + return tmpl; } char * @@ -255,7 +254,7 @@ fileFindByPath(char *fname) static char tmp[FILENAME_MAX]; char *cp; - if (fexists(fname)) { + if (fexists(fname) && isfile(fname)) { strcpy(tmp, fname); return tmp; } @@ -264,7 +263,7 @@ fileFindByPath(char *fname) char *cp2 = strsep(&cp, ":"); snprintf(tmp, FILENAME_MAX, "%s/%s.tgz", cp2 ? cp2 : cp, fname); - if (fexists(tmp)) + if (fexists(tmp) && isfile(fname)) return tmp; } return NULL; diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 61be709490e2..59f662a73f90 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $Id: lib.h,v 1.15 1995/04/22 13:58:43 jkh Exp $ */ +/* $Id: lib.h,v 1.18 1995/08/26 10:15:12 jkh Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -109,7 +109,7 @@ void cleanup(int); char *make_playpen(char *, size_t); void leave_playpen(void); char *where_playpen(void); -long min_free(char *); +size_t min_free(char *); /* String */ char *get_dash_string(char **); @@ -122,6 +122,7 @@ char *basename_of(char *); /* File */ Boolean fexists(char *); Boolean isdir(char *); +Boolean isfile(char *); Boolean isempty(char *); Boolean isURL(char *); char *fileGetURL(char *); diff --git a/usr.sbin/pkg_install/lib/msg.c b/usr.sbin/pkg_install/lib/msg.c index 460183e8a86e..edbce5f86ab9 100644 --- a/usr.sbin/pkg_install/lib/msg.c +++ b/usr.sbin/pkg_install/lib/msg.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: msg.c,v 1.4 1994/06/01 05:14:19 asami Exp $"; +static const char *rcsid = "$Id: msg.c,v 1.6 1995/08/26 10:15:15 jkh Exp $"; #endif /* @@ -99,5 +99,3 @@ y_or_n(Boolean def, const char *msg, ...) fclose(tty) ; return (ch == 'Y') ? TRUE : FALSE; } - - diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 37f36ce2ab93..bc03ef7b55ba 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: pen.c,v 1.12 1995/04/22 13:58:44 jkh Exp $"; +static const char *rcsid = "$Id: pen.c,v 1.18 1995/08/28 14:47:30 jkh Exp $"; #endif /* @@ -30,6 +30,28 @@ static const char *rcsid = "$Id: pen.c,v 1.12 1995/04/22 13:58:44 jkh Exp $"; /* For keeping track of where we are */ static char Cwd[FILENAME_MAX]; static char Pen[FILENAME_MAX]; +extern char *PlayPen; + +/* Find a good place to play. */ +static char * +find_play_pen(size_t sz) +{ + char *cp; + struct stat sb; + + if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) + sprintf(Pen, "%s/instmp.XXXXXX", cp); + else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) + sprintf(Pen, "%s/instmp.XXXXXX", cp); + else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz) + strcpy(Pen, "/var/tmp/instmp.XXXXXX"); + else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz) + strcpy(Pen, "/tmp/instmp.XXXXXX"); + else if ((stat("/usr/tmp", &sb) == SUCCESS | mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz) + strcpy(Pen, "/usr/tmp/instmp.XXXXXX"); + else barf("Can't find enough temporary space to extract the files, please set\nyour PKG_TMPDIR environment variable to a location with at least %d bytes\nfree.", sz); + return Pen; +} /* * Make a temporary directory to play in and chdir() to it, returning @@ -38,31 +60,30 @@ static char Pen[FILENAME_MAX]; char * make_playpen(char *pen, size_t sz) { - if (!pen) { - char *cp; - - if ((cp = getenv("PKG_TMPDIR")) != NULL) - sprintf(Pen, "%s/instmp.XXXXXX", cp); - else - strcpy(Pen, "/var/tmp/instmp.XXXXXX"); - } - else + if (!pen) + PlayPen = find_play_pen(sz); + else { strcpy(Pen, pen); + PlayPen = Pen; + } if (!getcwd(Cwd, FILENAME_MAX)) upchuck("getcwd"); if (!mktemp(Pen)) barf("Can't mktemp '%s'.", Pen); if (mkdir(Pen, 0755) == FAIL) barf("Can't mkdir '%s'.", Pen); - if (Verbose) { - if (!sz) - fprintf(stderr, "Free temp space: %d bytes\n", min_free(Pen)); - else - fprintf(stderr, "Projected package size: %d bytes, free temp space: %d bytes\n", (int)sz, min_free(Pen)); + if (Verbose) + { + if (sz) + fprintf(stderr, "Projected package size: %d bytes, +free temp space: %d bytes in %s\n", (int)sz, min_free(Pen), Pen); } if (min_free(Pen) < sz) { rmdir(Pen); - barf("Not enough free space to create `%s'.\nPlease set your PKG_TMPDIR environment variable to a location with more space and\ntry the command again.", Pen); + barf("Not enough free space to create `%s'.\nPlease set your PKG_TMPDIR +environment variable to a location with more space and\ntry the command +again.", Pen); + PlayPen = NULL; } if (chdir(Pen) == FAIL) barf("Can't chdir to '%s'.", Pen); @@ -97,7 +118,7 @@ where_playpen(void) return NULL; } -long +size_t min_free(char *tmpdir) { struct statfs buf; diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index cb6e4b7f50e4..36a016ccd751 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.12 1995/04/22 07:41:02 jkh Exp $"; +static const char *rcsid = "$Id: plist.c,v 1.14 1995/07/28 01:50:35 ache Exp $"; #endif /* @@ -359,7 +359,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) if (p->type == PLIST_CWD) { Where = p->name; if (Verbose) - printf("Change working directory to %s\n", CMD_CHAR, Where); + printf("Change working directory to %s\n", Where); } else if (p->type == PLIST_UNEXEC) { char cmd[FILENAME_MAX]; |
