- 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
This commit is contained in:
Maxim Sobolev 2001-10-08 17:01:35 +00:00
parent e5cef9b61f
commit 4bbe1f1cd4
5 changed files with 109 additions and 30 deletions

View file

@ -28,6 +28,7 @@ static const char rcsid[] =
#include "lib.h"
#include "add.h"
#include <libgen.h>
#include <signal.h>
#include <sys/wait.h>
@ -67,7 +68,7 @@ pkg_do(char *pkg)
char pkg_fullname[FILENAME_MAX];
char playpen[FILENAME_MAX];
char extract_contents[FILENAME_MAX];
char *where_to, *tmp, *extract;
char *where_to, *extract;
FILE *cfile;
int code;
PackingList p;
@ -356,7 +357,6 @@ pkg_do(char *pkg)
code = 1;
goto success; /* nothing to uninstall yet */
}
if (new_m) unlink(pre_script);
}
/* Now finally extract the entire show if we're not going direct */
@ -373,7 +373,6 @@ pkg_do(char *pkg)
if (vsystem("/usr/sbin/mtree -U -f %s -d -e -p %s >%s", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL))
warnx("mtree returned a non-zero status - continuing");
}
unlink(MTREE_FNAME);
}
/* Run the installation script one last time? */
@ -387,7 +386,6 @@ pkg_do(char *pkg)
code = 1;
goto fail;
}
unlink(post_script);
}
/* Time to record the deed? */
@ -415,12 +413,22 @@ pkg_do(char *pkg)
}
/* Make sure pkg_info can read the entry */
vsystem("chmod a+rx %s", LogDir);
move_file(".", DESC_FNAME, LogDir);
move_file(".", COMMENT_FNAME, LogDir);
if (fexists(INSTALL_FNAME))
move_file(".", INSTALL_FNAME, LogDir);
if (fexists(POST_INSTALL_FNAME))
move_file(".", POST_INSTALL_FNAME, LogDir);
if (fexists(DEINSTALL_FNAME))
move_file(".", DEINSTALL_FNAME, LogDir);
if (fexists(POST_DEINSTALL_FNAME))
move_file(".", POST_DEINSTALL_FNAME, LogDir);
if (fexists(REQUIRE_FNAME))
move_file(".", REQUIRE_FNAME, LogDir);
if (fexists(DISPLAY_FNAME))
move_file(".", DISPLAY_FNAME, LogDir);
if (fexists(MTREE_FNAME))
move_file(".", MTREE_FNAME, LogDir);
sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME);
cfile = fopen(contents, "w");
if (!cfile) {
@ -430,10 +438,6 @@ pkg_do(char *pkg)
}
write_plist(&Plist, cfile);
fclose(cfile);
move_file(".", DESC_FNAME, LogDir);
move_file(".", COMMENT_FNAME, LogDir);
if (fexists(DISPLAY_FNAME))
move_file(".", DISPLAY_FNAME, LogDir);
for (p = Plist.head; p ; p = p->next) {
if (p->type != PLIST_PKGDEP)
continue;

View file

@ -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;

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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