diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h index 33c3db742e1..9450170be82 100644 --- a/usr.sbin/pkg_install/create/create.h +++ b/usr.sbin/pkg_install/create/create.h @@ -23,6 +23,7 @@ #ifndef _INST_CREATE_H_INCLUDE #define _INST_CREATE_H_INCLUDE +extern match_t MatchType; extern char *Prefix; extern char *Comment; extern char *Desc; diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c index 4869bfd5c49..1c3af294502 100644 --- a/usr.sbin/pkg_install/create/main.c +++ b/usr.sbin/pkg_install/create/main.c @@ -16,8 +16,9 @@ __FBSDID("$FreeBSD$"); #include "lib.h" #include "create.h" -static char Options[] = "YNORhjvyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:"; +static char Options[] = "EGYNORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:"; +match_t MatchType = MATCH_GLOB; char *Prefix = NULL; char *Comment = NULL; char *Desc = NULL; @@ -57,6 +58,18 @@ main(int argc, char **argv) Verbose = TRUE; break; + case 'x': + MatchType = MATCH_REGEX; + break; + + case 'E': + MatchType = MATCH_EREGEX; + break; + + case 'G': + MatchType = MATCH_EXACT; + break; + case 'N': AutoAnswer = NO; break; @@ -216,6 +229,6 @@ usage() " [-D displayfile] [-m mtreefile] [-o origin] ", " [-s srcdir] [-S basedir] ", " -c comment -d description -f packlist pkg-filename", -" pkg_create [-YNhvyzR] -b pkg-name [pkg-filename]"); +" pkg_create [-EGYNhvxyzR] -b pkg-name [pkg-filename]"); exit(1); } diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index 3f7ab47984f..51a3cfa4d74 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -81,9 +81,40 @@ pkg_perform(char **pkgs) suf = "tar"; if (InstalledPkg != NULL) { - if (!Recursive) - return (create_from_installed(InstalledPkg, pkg, suf)); - return (create_from_installed_recursive(pkg, suf)); + char *pkgglob[] = { InstalledPkg, NULL }; + char **matched, **pkgs; + int i, error; + + pkgs = pkgglob; + if (MatchType != MATCH_EXACT) { + matched = matchinstalled(MatchType, pkgs, &error); + if (!error && matched != NULL) + pkgs = matched; + else if (MatchType != MATCH_GLOB) + errx(1, "no packages match pattern"); + } + /* + * Is there is only one installed package matching the pattern, + * we need to respect the optional pkg-filename parameter. If, + * however, the pattern matches several packages, this parameter + * makes no sense and is ignored. + */ + if (pkgs[1] == NULL) { + if (pkg == InstalledPkg) + pkg = *pkgs; + InstalledPkg = *pkgs; + if (!Recursive) + return (create_from_installed(InstalledPkg, pkg, suf)); + return (create_from_installed_recursive(pkg, suf)); + } + for (i = 0; pkgs[i] != NULL; i++) { + InstalledPkg = pkg = pkgs[i]; + if (!Recursive) + create_from_installed(pkg, pkg, suf); + else + create_from_installed_recursive(pkg, suf); + } + return TRUE; } get_dash_string(&Comment); diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 index 62599ead73b..e7666cde524 100644 --- a/usr.sbin/pkg_install/create/pkg_create.1 +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -23,7 +23,7 @@ .\" [jkh] Took John's changes back and made some additional extensions for .\" better integration with FreeBSD's new ports collection. .\" -.Dd June 14, 2005 +.Dd November 8, 2005 .Dt PKG_CREATE 1 .Os .Sh NAME @@ -52,7 +52,7 @@ .Fl f Ar packlist .Ar pkg-filename .Nm -.Op Fl YNRhvy +.Op Fl EGYNRhvxy .Fl b Ar pkg-name .Op Ar pkg-filename .Sh DESCRIPTION @@ -341,6 +341,15 @@ also create package files for all packages required by Resulting archive(s) will be created in the current directory and named using name of the respective package with appropriate extraction suffix applied. +.It Fl x +Use basic regular expressions for +.Ar pkg-name . +.It Fl E +Use extended (modern) regular expressions for +.Ar pkg-name . +.It Fl G +Use exact matching for +.Ar pkg-name . .El .Sh PACKING LIST DETAILS The