aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install/create
diff options
context:
space:
mode:
authorMaxim Sobolev <sobomax@FreeBSD.org>2001-10-08 17:01:35 +0000
committerMaxim Sobolev <sobomax@FreeBSD.org>2001-10-08 17:01:35 +0000
commit4bbe1f1cd479c455684f4da3b713475e23fc57a8 (patch)
tree79e92fcc3086b01f064048343f689fa337b95dbd /usr.sbin/pkg_install/create
parente5cef9b61ff942681308f74a59a445f33eb25c0a (diff)
downloadsrc-4bbe1f1cd479c455684f4da3b713475e23fc57a8.tar.gz
src-4bbe1f1cd479c455684f4da3b713475e23fc57a8.zip
- Allow package archive to be created from a locally installed package. This
allows for an easy way to backup old version of port prior to installing a new one; - silence compiler warnings by killing some unused variables and adding all includes necessary. MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=84670
Diffstat (limited to 'usr.sbin/pkg_install/create')
-rw-r--r--usr.sbin/pkg_install/create/create.h1
-rw-r--r--usr.sbin/pkg_install/create/main.c35
-rw-r--r--usr.sbin/pkg_install/create/perform.c66
-rw-r--r--usr.sbin/pkg_install/create/pkg_create.117
4 files changed, 97 insertions, 22 deletions
diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h
index 1b7143236aab..d85e28a759cb 100644
--- a/usr.sbin/pkg_install/create/create.h
+++ b/usr.sbin/pkg_install/create/create.h
@@ -38,6 +38,7 @@ extern char *ExcludeFrom;
extern char *Mtree;
extern char *Pkgdeps;
extern char *Origin;
+extern char *InstalledPkg;
extern char PlayPen[];
extern int Dereference;
extern int PlistOnly;
diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c
index 642069e44eec..a9c502da35a2 100644
--- a/usr.sbin/pkg_install/create/main.c
+++ b/usr.sbin/pkg_install/create/main.c
@@ -18,7 +18,7 @@ static const char rcsid[] =
#include "lib.h"
#include "create.h"
-static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:";
+static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:b:";
char *Prefix = NULL;
char *Comment = NULL;
@@ -35,6 +35,7 @@ char *ExcludeFrom = NULL;
char *Mtree = NULL;
char *Pkgdeps = NULL;
char *Origin = NULL;
+char *InstalledPkg = NULL;
char PlayPen[FILENAME_MAX];
int Dereference = FALSE;
int PlistOnly = FALSE;
@@ -46,8 +47,9 @@ int
main(int argc, char **argv)
{
int ch;
- char **pkgs, **start;
+ char **pkgs, **start, *tmp;
+ /*{int barrier = 1; while (barrier); }*/
pkgs = start = argv;
while ((ch = getopt(argc, argv, Options)) != -1)
switch(ch) {
@@ -139,6 +141,21 @@ main(int argc, char **argv)
UseBzip2 = TRUE;
break;
+ case 'b':
+ while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
+ *tmp++ = '\0';
+ /*
+ * If character after the '/' is alphanumeric, then we've
+ * found the package name. Otherwise we've come across
+ * a trailing '/' and need to continue our quest.
+ */
+ if (isalpha(*tmp)) {
+ InstalledPkg = tmp;
+ break;
+ }
+ }
+ break;
+
case '?':
default:
usage();
@@ -153,12 +170,15 @@ main(int argc, char **argv)
*pkgs++ = *argv++;
/* If no packages, yelp */
- if (pkgs == start)
+ if ((pkgs == start) && (InstalledPkg == NULL))
warnx("missing package name"), usage();
*pkgs = NULL;
- if (start[1])
- warnx("only one package name allowed ('%s' extraneous)", start[1]),
+ if ((start[0] != NULL) && (start[1] != NULL)) {
+ warnx("only one package name allowed ('%s' extraneous)", start[1]);
usage();
+ }
+ if (start[0] == NULL)
+ start[0] = InstalledPkg;
if (!pkg_perform(start)) {
if (Verbose)
warnx("package creation failed");
@@ -171,11 +191,12 @@ main(int argc, char **argv)
static void
usage()
{
- fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
+ fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
" [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ",
" [-t template] [-X excludefile] [-D displayfile] ",
" [-m mtreefile] [-o origin] -c comment -d description ",
-" -f packlist pkg-name");
+" -f packlist pkg-filename",
+" pkg_create [-YNhvy] -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 30678bbb2838..1dae50b783d8 100644
--- a/usr.sbin/pkg_install/create/perform.c
+++ b/usr.sbin/pkg_install/create/perform.c
@@ -35,6 +35,7 @@ static const char rcsid[] =
static void sanity_check(void);
static void make_dist(char *, char *, char *, Package *);
+static int create_from_installed(char *, char *);
static char *home;
@@ -50,21 +51,10 @@ pkg_perform(char **pkgs)
int compress = TRUE; /* default is to compress packages */
/* Preliminary setup */
- sanity_check();
+ if (InstalledPkg == NULL)
+ sanity_check();
if (Verbose && !PlistOnly)
printf("Creating package %s\n", pkg);
- get_dash_string(&Comment);
- get_dash_string(&Desc);
- if (!strcmp(Contents, "-"))
- pkg_in = stdin;
- else {
- pkg_in = fopen(Contents, "r");
- if (!pkg_in) {
- cleanup(0);
- errx(2, __FUNCTION__ ": unable to open contents file '%s' for input", Contents);
- }
- }
- plist.head = plist.tail = NULL;
/* chop suffix off if already specified, remembering if we want to compress */
len = strlen(pkg);
@@ -92,6 +82,22 @@ pkg_perform(char **pkgs)
else
suf = "tar";
+ if (InstalledPkg != NULL)
+ return (create_from_installed(pkg, suf));
+
+ get_dash_string(&Comment);
+ get_dash_string(&Desc);
+ if (!strcmp(Contents, "-"))
+ pkg_in = stdin;
+ else {
+ pkg_in = fopen(Contents, "r");
+ if (!pkg_in) {
+ cleanup(0);
+ errx(2, __FUNCTION__ ": unable to open contents file '%s' for input", Contents);
+ }
+ }
+ plist.head = plist.tail = NULL;
+
/* Add the origin if asked, at the top */
if (Origin)
add_plist(&plist, PLIST_COMMENT, strconcat("ORIGIN:", Origin));
@@ -392,3 +398,37 @@ cleanup(int sig)
if (sig)
exit(1);
}
+
+static int
+create_from_installed(char *pkg, char *suf)
+{
+ FILE *fp;
+ Package plist;
+ char home[MAXPATHLEN], log_dir[FILENAME_MAX];
+
+ snprintf(log_dir, sizeof(log_dir), "%s/%s", LOG_DIR, InstalledPkg);
+ if (!fexists(log_dir)) {
+ warnx("can't find package '%s' installed!", InstalledPkg);
+ return 1;
+ }
+ getcwd(home, sizeof(home));
+ if (chdir(log_dir) == FAIL) {
+ warnx("can't change directory to '%s'!", log_dir);
+ return 1;
+ }
+ /* Suck in the contents list */
+ plist.head = plist.tail = NULL;
+ fp = fopen(CONTENTS_FNAME, "r");
+ if (!fp) {
+ warnx("unable to open %s file", CONTENTS_FNAME);
+ return 1;
+ }
+ /* If we have a prefix, add it now */
+ read_plist(&plist, fp);
+ fclose(fp);
+
+ make_dist(home, pkg, suf, &plist);
+
+ free_plist(&plist);
+ return TRUE;
+}
diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1
index c7d61ae7b00a..42c78aeb7cf3 100644
--- a/usr.sbin/pkg_install/create/pkg_create.1
+++ b/usr.sbin/pkg_install/create/pkg_create.1
@@ -49,7 +49,11 @@
.Fl c Ar comment
.Fl d Ar description
.Fl f Ar packlist
-.Ar pkg-name
+.Ar pkg-filename
+.Nm
+.Op Fl YNhvy
+.Fl b Ar pkg-name
+.Op Ar pkg-filename
.Sh DESCRIPTION
The
.Nm
@@ -263,13 +267,22 @@ utility to compress package tarball instead of
.Xr gzip 1 .
Please note that this option is no-op if format of the resulting
archive is explicitly specified by the recognizeable suffix of
-.Ar pkg-name .
+.Ar pkg-filename .
Currently
.Nm
recognizes the following suffixes:
.Pa .tgz , .tar
and
.Pa .tbz2 .
+.It Fl b Ar pkg-name
+Create package file from a locally installed package named
+.Ar pkg-name .
+If the
+.Ar pkg-filename
+is not specified, then resulting archive will be created in the
+current directory and named
+.Ar pkg-name
+with an appropriate extraction suffix applied.
.El
.Sh PACKING LIST DETAILS
The