diff options
Diffstat (limited to 'usr.sbin/pkg_install/create')
-rw-r--r-- | usr.sbin/pkg_install/create/create.h | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/main.c | 20 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 16 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/pl.c | 133 |
4 files changed, 162 insertions, 11 deletions
diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h index d45c177..e0ee4cc 100644 --- a/usr.sbin/pkg_install/create/create.h +++ b/usr.sbin/pkg_install/create/create.h @@ -1,4 +1,4 @@ -/* $Id: create.h,v 1.4 1993/09/12 20:45:28 jkh Exp $ */ +/* $Id: create.h,v 1.5 1994/05/19 18:27:38 alm Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -26,12 +26,14 @@ extern char *Prefix; extern char *Comment; extern char *Desc; +extern char *Display; extern char *Install; extern char *DeInstall; extern char *Contents; extern char *Require; extern char *PlayPen; extern char *ExcludeFrom; +extern char *Mtree; extern int Dereference; void check_list(char *, Package *); diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c index e7805ca..623d7d1 100644 --- a/usr.sbin/pkg_install/create/main.c +++ b/usr.sbin/pkg_install/create/main.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: main.c,v 1.6 1994/04/16 21:50:53 jkh Exp $"; +static const char *rcsid = "$Id: main.c,v 1.7 1994/05/19 18:27:40 alm Exp $"; #endif /* @@ -16,17 +16,19 @@ static const char *rcsid = "$Id: main.c,v 1.6 1994/04/16 21:50:53 jkh Exp $"; #include "lib.h" #include "create.h" -static char Options[] = "YNhvf:p:c:d:i:k:r:t:X:"; +static char Options[] = "YNhvf:p:c:d:i:k:r:t:X:D:m:"; char *Prefix = NULL; char *Comment = NULL; char *Desc = NULL; +char *Display = NULL; char *Install = NULL; char *DeInstall = NULL; char *Contents = NULL; char *Require = NULL; char *PlayPen = NULL; char *ExcludeFrom = NULL; +char *Mtree = NULL; int Dereference = 0; int @@ -91,6 +93,14 @@ main(int argc, char **argv) Dereference = 1; break; + case 'D': + Display = optarg; + break; + + case 'm': + Mtree = optarg; + break; + case '?': default: usage(prog_name, NULL); @@ -140,11 +150,15 @@ usage(const char *name, const char *fmt, ...) fprintf(stderr, "-f file get list of files from file (- for stdin)\n"); fprintf(stderr, "-h follow symbolic links\n"); fprintf(stderr, "-i script install script\n"); - fprintf(stderr, "-p arg install prefix will be arg\n"); fprintf(stderr, "-k script de-install script\n"); + fprintf(stderr, "-D file install notice\n"); + fprintf(stderr, "-m file mtree spec for directories\n"); + fprintf(stderr, "-p prefix install prefix will be arg\n"); fprintf(stderr, "-r script pre/post requirements script\n"); fprintf(stderr, "-t temp use temp as template for mktemp()\n"); fprintf(stderr, "-X file exclude files listed in file\n"); fprintf(stderr, "-v verbose\n"); + fprintf(stderr, "-Y assume `yes' answer to all questions\n"); + fprintf(stderr, "-N assume `no' answer to all questions\n"); exit(1); } diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index 36d6d5f..6d15ef8 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: perform.c,v 1.12 1994/10/14 05:55:46 jkh Exp $"; +static const char *rcsid = "$Id: perform.c,v 1.13 1994/11/17 10:54:11 jkh Exp $"; #endif /* @@ -84,6 +84,8 @@ pkg_perform(char **pkgs) /* Make first "real contents" pass over it */ check_list(home, &plist); + (void) umask(022); /* make sure gen'ed directories, files don't have + group or other write bits. */ copy_plist(home, &plist); mark_plist(&plist); @@ -111,6 +113,18 @@ pkg_perform(char **pkgs) add_plist(&plist, PLIST_IGNORE, NULL); add_plist(&plist, PLIST_FILE, REQUIRE_FNAME); } + if (Display) { + copy_file(home, Display, DISPLAY_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, DISPLAY_FNAME); + add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME); + } + if (Mtree) { + copy_file(home, Mtree, MTREE_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, MTREE_FNAME); + add_plist(&plist, PLIST_MTREE, MTREE_FNAME); + } /* Run through the list again, picking up extra "local" items */ check_list(".", &plist); diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c index 0d87779..f50bd8f 100644 --- a/usr.sbin/pkg_install/create/pl.c +++ b/usr.sbin/pkg_install/create/pl.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: pl.c,v 1.4 1994/08/29 16:31:38 adam Exp $"; +static const char *rcsid = "$Id: pl.c,v 1.5 1994/11/17 10:35:04 jkh Exp $"; #endif /* @@ -24,6 +24,7 @@ static const char *rcsid = "$Id: pl.c,v 1.4 1994/08/29 16:31:38 adam Exp $"; #include "lib.h" #include "create.h" +#include <errno.h> /* Check a list for files that require preconversion */ void @@ -59,6 +60,35 @@ check_list(char *home, Package *pkg) } } +static int +trylink(const char *from, const char *to) +{ + if (link(from, to) == 0) + return 0; + if (errno == ENOENT) { + /* try making the container directory */ + char *cp = strrchr(to, '/'); + if (cp) + vsystem("mkdir -p %.*s", cp - to, + to); + return link(from, to); + } + return -1; +} + +#define STARTSTRING "tar cf -" +#define TOOBIG(str) strlen(str) + 6 + strlen(home) + where_count > maxargs +#define PUSHOUT() /* push out string */ \ + if (where_count > sizeof(STARTSTRING)-1) { \ + strcat(where_args, "|tar xpf -"); \ + if (system(where_args)) \ + barf("can't invoke tar pipeline"); \ + memset(where_args, 0, maxargs); \ + last_chdir = NULL; \ + strcpy(where_args, STARTSTRING); \ + where_count = sizeof(STARTSTRING)-1; \ + } + /* * Copy unmarked files in packing list to playpen - marked files * have already been copied in an earlier pass through the list. @@ -68,7 +98,30 @@ copy_plist(char *home, Package *plist) { PackingList p = plist->head; char *where = home; - char *there = NULL; + char *there = NULL, *mythere; + char *where_args, *last_chdir, *root = "/"; + int maxargs, where_count = 0, add_count; + struct stat stb; + dev_t curdir; + + maxargs = sysconf(_SC_ARG_MAX); + maxargs -= 64; /* some slop for the tar cmd text, + and sh -c */ + where_args = malloc(maxargs); + if (!where_args) + barf("can't get argument list space"); + + memset(where_args, 0, maxargs); + strcpy(where_args, STARTSTRING); + where_count = sizeof(STARTSTRING)-1; + last_chdir = 0; + + if (stat(".", &stb) == 0) + curdir = stb.st_dev; + else + curdir = (dev_t) -1; /* It's ok if this is a valid dev_t; + this is just a hint for an + optimization. */ while (p) { if (p->type == PLIST_CWD) @@ -80,16 +133,84 @@ copy_plist(char *home, Package *plist) else if (p->type == PLIST_FILE && !p->marked) { char fn[FILENAME_MAX]; + /* First, look for it in the "home" dir */ sprintf(fn, "%s/%s", home, p->name); - if (fexists(fn)) - copy_hierarchy(home, p->name, FALSE); + if (fexists(fn)) { + if (lstat(fn, &stb) == 0 && stb.st_dev == curdir && + S_ISREG(stb.st_mode)) { + /* if we can link it to the playpen, that avoids a copy + and saves time. */ + if (p->name[0] != '/') { + /* don't link abspn stuff--it doesn't come from + local dir! */ + if (trylink(fn, p->name) == 0) { + p = p->next; + continue; + } + } + } + if (TOOBIG(fn)) { + PUSHOUT(); + } + if (p->name[0] == '/') { + add_count = snprintf(&where_args[where_count], + maxargs - where_count, + " %s %s", + last_chdir == root ? "" : "-C /", + p->name); + last_chdir = root; + } else { + add_count = snprintf(&where_args[where_count], + maxargs - where_count, + " %s%s %s", + last_chdir == home ? "" : "-C ", + last_chdir == home ? "" : home, + p->name); + last_chdir = home; + } + if (add_count > maxargs - where_count) + barf("oops, miscounted strings!"); + where_count += add_count; + } /* * Otherwise, try along the actual extraction path.. */ - else - copy_hierarchy(there ? there : where, p->name, FALSE); + else { + if (p->name[0] == '/') + mythere = root; + else mythere = there; + sprintf(fn, "%s/%s", mythere ? mythere : where, p->name); + if (lstat(fn, &stb) == 0 && stb.st_dev == curdir && + S_ISREG(stb.st_mode)) { + /* if we can link it to the playpen, that avoids a copy + and saves time. */ + if (trylink(fn, p->name) == 0) { + p = p->next; + continue; + } + } + if (TOOBIG(p->name)) { + PUSHOUT(); + } + if (last_chdir == (mythere ? mythere : where)) + add_count = snprintf(&where_args[where_count], + maxargs - where_count, + " %s", p->name); + else + add_count = snprintf(&where_args[where_count], + maxargs - where_count, + " -C %s %s", + mythere ? mythere : where, + p->name); + if (add_count > maxargs - where_count) + barf("oops, miscounted strings!"); + where_count += add_count; + last_chdir = (mythere ? mythere : where); + } } p = p->next; } + PUSHOUT(); + free(where_args); } |