tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Adding pkg_admin unpack (ish)
On Saturday 13 Apr 2024, at 12:47, Greg Troxel wrote:
> Anthony Mallet <anthony.mallet%laas.fr@localhost> writes:
> > I actually implemented `pkg_add -x pkg.tgz`, it's only a few
> > lines diff, and for me it's the simplest solution, as by definition
> > pkg_add will be available on the host and it will have a consistent
> > behaviour.
>
> Feel free to send a patch for people to think about.
Here is the current draft (-p0 from inside pkgtools/pkg_install/files).
pkg_admin would seem like a better choice for the 'unpack' option, but
pkg_admin mostly deals with the pkgdb, so it does not have any of the
archive processing logic. So I patched pkg_add instead, adding a `-x'
option, which makes the diff short.
What the patch does is simply skipping the platform check and
dependency management part of pkg_do() in add/perform.c. So, for
instance, the signature, license and vulnerability checks remain
active. That might be important since the PLIST will be processed
(e.g. @exec). Skipping is done with 'goto', which I think is more
readable in this context.
Meta-data is extracted to '.'. The contents are also extracted to '.'
or to the directory specified in -P. So for instance, in my use case,
preparing the contents of a .deb package is just something like
`mkdir -p /tmproot/DEBIAN && cd /tmproot/DEBIAN && pkg_add -P /tmproot -x pkg.tgz`
That populates 'DEBIAN' with meta-data files (later used by some shell
script magic) and /tmproot with the contents.
There is currently an issue if specifying more than one package to
extract on the command line: meta-data will be incorrect, since no
<pkgname> prefix is used (that's on purpose for my use-case). I also
noticed that if a relative -P directory is given, this fails for the
second and next packages because pkg_do does chdir(2) (but this is an
issue already present in pkg_add).
Any feedback appreciated!
Best,
Anthony
diff --git pkgtools/pkg_install/dist/add/add.h pkgtools/pkg_install/dist/add/add.h
index a55f40bb5..fae545228 100644
--- add/add.h
+++ add/add.h
@@ -35,6 +35,7 @@ extern Boolean NoInstall;
extern Boolean NoRecord;
extern Boolean Force;
extern Boolean Automatic;
+extern Boolean Extract;
extern int LicenseCheck;
extern int Replace;
extern int ReplaceSame;
diff --git add/main.c add/main.c
index 8abf03e79..0a2290903 100644
--- add/main.c
+++ add/main.c
@@ -36,7 +36,7 @@ __RCSID("$NetBSD: main.c,v 1.32 2015/12/27 12:36:42 joerg Exp $");
#include "lib.h"
#include "add.h"
-static char Options[] = "AC:DIK:P:RVfhm:np:t:Uuv";
+static char Options[] = "AC:DIK:P:RVfhm:np:t:Uuvx";
char *Destdir = NULL;
char *OverrideMachine = NULL;
@@ -44,6 +44,7 @@ char *Prefix = NULL;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
Boolean Automatic = FALSE;
+Boolean Extract = FALSE;
Boolean ForceDepends = FALSE;
/*
* Normally, updating fails if the dependencies of a depending package
@@ -139,6 +140,13 @@ main(int argc, char **argv)
Verbose = TRUE;
break;
+ case 'x':
+ Extract = TRUE;
+ NoRecord = TRUE;
+ if (Destdir == NULL)
+ Destdir = ".";
+ break;
+
case 'h':
case '?':
default:
diff --git add/perform.c add/perform.c
index d4b2ebafc..fe5e855d6 100644
--- add/perform.c
+++ add/perform.c
@@ -1561,6 +1561,11 @@ pkg_do(const char *pkgpath, int mark_automatic, int top_level)
if (pkg->meta_data.meta_mtree != NULL)
warnx("mtree specification in pkg `%s' ignored", pkg->pkgname);
+ if (Extract) {
+ pkg->install_logdir = xstrdup(".");
+ goto extract;
+ }
+
pkg->logdir = xasprintf("%s/%s", config_pkg_dbdir, pkg->pkgname);
if (Destdir != NULL)
@@ -1643,9 +1648,18 @@ pkg_do(const char *pkgpath, int mark_automatic, int top_level)
if (run_install_script(pkg, "PRE-INSTALL"))
goto nuke_pkgdb;
+extract:
+ if (Extract && write_meta_data(pkg))
+ goto nuke_pkgdb;
+
if (extract_files(pkg))
goto nuke_pkg;
+ if (Extract) {
+ status = 0;
+ goto clean_memory;
+ }
+
if (run_install_script(pkg, "POST-INSTALL"))
goto nuke_pkg;
diff --git add/pkg_add.1 add/pkg_add.1
index 127a99f3c..ff55a399a 100644
--- add/pkg_add.1
+++ add/pkg_add.1
@@ -25,7 +25,7 @@
.Nd a utility for installing and upgrading software package distributions
.Sh SYNOPSIS
.Nm
-.Op Fl AfhInRUuVv
+.Op Fl AfhInRUuVvx
.Op Fl C Ar config
.Op Fl K Ar pkg_dbdir
.Op Fl m Ar machine
@@ -177,6 +177,14 @@ See below for a more detailed description of the process.
Print version number and exit.
.It Fl v
Turn on verbose output.
+.It Fl x
+Extract the files contained by the packages in the current directory, or in
+the directory specified by
+.Fl P .
+Meta-data files are written to the current directory (regardless of any
+directory specified by
+.Fl P ) .
+No other action is performed.
.El
.Pp
One or more
Home |
Main Index |
Thread Index |
Old Index