From 77e462a7c0018f3b32fa973f39217e06c918e0e2 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Fri, 15 Aug 2003 00:03:23 +0000 Subject: -S basedir, simpler to use than -s. Sets prefix logic better, so that it doesn't interfere with existing @cwd in packing lists. tests by naddy@ --- usr.sbin/pkg_install/create/create.h | 3 ++- usr.sbin/pkg_install/create/main.c | 13 ++++++++---- usr.sbin/pkg_install/create/perform.c | 36 +++++++++++++++++++++++++------- usr.sbin/pkg_install/create/pkg_create.1 | 7 ++++++- usr.sbin/pkg_install/create/pl.c | 12 ++++++++--- 5 files changed, 54 insertions(+), 17 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h index 60ab22286ee..df48334bae7 100644 --- a/usr.sbin/pkg_install/create/create.h +++ b/usr.sbin/pkg_install/create/create.h @@ -1,4 +1,4 @@ -/* $OpenBSD: create.h,v 1.3 1998/10/13 23:09:50 marc Exp $ */ +/* $OpenBSD: create.h,v 1.4 2003/08/15 00:03:22 espie Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -36,6 +36,7 @@ extern char *ExcludeFrom; extern char *Mtree; extern char *Pkgdeps; extern char *Pkgcfl; +extern char *BaseDir; extern char PlayPen[]; extern size_t PlayPenSize; extern int Dereference; diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c index b53249de09e..7d943066380 100644 --- a/usr.sbin/pkg_install/create/main.c +++ b/usr.sbin/pkg_install/create/main.c @@ -1,7 +1,7 @@ -/* $OpenBSD: main.c,v 1.12 2003/07/04 17:31:19 avsm Exp $ */ +/* $OpenBSD: main.c,v 1.13 2003/08/15 00:03:22 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: main.c,v 1.12 2003/07/04 17:31:19 avsm Exp $"; +static const char rcsid[] = "$OpenBSD: main.c,v 1.13 2003/08/15 00:03:22 espie Exp $"; #endif /* @@ -19,7 +19,7 @@ static const char rcsid[] = "$OpenBSD: main.c,v 1.12 2003/07/04 17:31:19 avsm Ex #include "lib.h" #include "create.h" -static char Options[] = "Ohvf:p:P:C:c:d:i:k:r:t:X:D:m:s:"; +static char Options[] = "Ohvf:p:P:C:c:d:i:k:r:t:X:D:m:s:S:"; char *Prefix = NULL; char *Comment = NULL; @@ -34,6 +34,7 @@ char *ExcludeFrom = NULL; char *Mtree = NULL; char *Pkgdeps = NULL; char *Pkgcfl = NULL; +char *BaseDir = NULL; char PlayPen[FILENAME_MAX]; size_t PlayPenSize = sizeof(PlayPen); int Dereference = 0; @@ -66,6 +67,10 @@ main(int argc, char **argv) SrcDir = optarg; break; + case 'S': + BaseDir = optarg; + break; + case 'f': Contents = optarg; break; @@ -158,6 +163,6 @@ usage() "usage: pkg_create [-Ohv] [-P dpkgs] [-C cpkgs] [-p prefix] [-f contents]", " [-i iscript] [-k dscript] [-r rscript] [-t template]", " [-X excludefile] [-D displayfile] [-m mtreefile]", -" -c comment -d description -f packlist pkg-name"); +" -c comment -d description -f packlist -S basedir pkg-name"); exit(1); } diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index f2fe165a944..79f1316fd37 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,7 +1,7 @@ -/* $OpenBSD: perform.c,v 1.15 2003/07/04 17:31:19 avsm Exp $ */ +/* $OpenBSD: perform.c,v 1.16 2003/08/15 00:03:22 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: perform.c,v 1.15 2003/07/04 17:31:19 avsm Exp $"; +static const char rcsid[] = "$OpenBSD: perform.c,v 1.16 2003/08/15 00:03:22 espie Exp $"; #endif /* @@ -78,6 +78,8 @@ pkg_perform(char **pkgs) else suffix = "tgz"; + if (Prefix) + add_plist(&plist, PLIST_CWD, Prefix); /* If a SrcDir override is set, add it now */ if (SrcDir) { if (Verbose && !PlistOnly) @@ -120,11 +122,6 @@ pkg_perform(char **pkgs) /* Slurp in the packing list */ read_plist(&plist, pkg_in); - /* Prefix should override the packing list */ - if (Prefix) { - delete_plist(&plist, FALSE, PLIST_CWD, NULL); - add_plist_top(&plist, PLIST_CWD, Prefix); - } /* * Run down the list and see if we've named it, if not stick in a name * at the top. @@ -297,7 +294,17 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist) fclose(flist); flist = 0; args[nargs++] = "-C"; - args[nargs++] = p->name; + if (BaseDir) { + size_t size = strlen(BaseDir)+2+strlen(p->name); + args[nargs] = malloc(size); + if (!args[nargs]) { + cleanup(0); + errx(2, "can't get Cwd space"); + } + snprintf(args[nargs], size, "%s/%s", BaseDir, p->name); + nargs++; + } else + args[nargs++] = p->name; } else if (p->type == PLIST_IGNORE) p = p->next; @@ -308,6 +315,13 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist) /* fork/exec tar to create the package */ + if (Verbose) { + printf("Running \""); + for (i = 0; i < nargs; i++) { + printf("%s ", args[i]); + } + printf("\"\n"); + } pid = fork(); if ( pid < 0 ) err(2, "failed to fork"); @@ -320,6 +334,12 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist) wait(&ret); for (i = 0; i < current; i++) unlink(tempfile[i]); + if (BaseDir) { + for (i = 0; i < nargs-1; i++) { + if (!strcmp(args[i], "-C")) + free(args[++i]); + } + } /* assume either signal or bad exit is enough for us */ if (ret) { cleanup(0); diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 index 9e727489769..408247686d3 100644 --- a/usr.sbin/pkg_install/create/pkg_create.1 +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pkg_create.1,v 1.26 2003/06/26 18:00:40 jmc Exp $ +.\" $OpenBSD: pkg_create.1,v 1.27 2003/08/15 00:03:22 espie Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -41,6 +41,7 @@ .Op Fl k Ar dscript .Op Fl r Ar rscript .Op Fl s Ar fake-prefix +.Op Fl S Ar fake-base .Op Fl t Ar template .Op Fl X Ar excludefile .Op Fl D Ar displayfile @@ -153,6 +154,10 @@ Set .Ar fake-prefix as the real initial directory to start from in selecting files for the package. +.It Fl S Ar fake-base +Set +.Ar fake-base +as the prefix to prepend to any file to select for the package. .It Fl k Ar dscript Set .Ar dscript diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c index ba5f4d7da94..dceede79efb 100644 --- a/usr.sbin/pkg_install/create/pl.c +++ b/usr.sbin/pkg_install/create/pl.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pl.c,v 1.10 2003/08/12 06:54:03 espie Exp $ */ +/* $OpenBSD: pl.c,v 1.11 2003/08/15 00:03:22 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: pl.c,v 1.10 2003/08/12 06:54:03 espie Exp $"; +static const char rcsid[] = "$OpenBSD: pl.c,v 1.11 2003/08/15 00:03:22 espie Exp $"; #endif /* @@ -59,7 +59,13 @@ check_list(char *home, package_t *pkg) p = p->next; break; case PLIST_FILE: - (void) snprintf(name, sizeof(name), "%s/%s", there ? there : cwd, p->name); + if (BaseDir) + (void) snprintf(name, sizeof(name), + "%s/%s/%s", BaseDir, there ? there : cwd, + p->name); + else + (void) snprintf(name, sizeof(name), + "%s/%s", there ? there : cwd, p->name); if ((cp = MD5File(name, buf)) != NULL) { tmp = new_plist_entry(); tmp->name = copy_string(strconcat("MD5:", cp)); -- cgit v1.2.3