Skip to content

Commit cb296b1

Browse files
evadotbapt
authored andcommitted
pkg_install: Add --register-only
This just register the package installaltion (and config file) in the database but do not extract any files. This will allow us to pkgbasify a system more easily. Sponsored by: Beckhoff Automation GmbH & Co. KG
1 parent d23ccf0 commit cb296b1

File tree

6 files changed

+87
-5
lines changed

6 files changed

+87
-5
lines changed

docs/pkg-install.8

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
.Nd install packages from remote repositories or local archives
2323
.Sh SYNOPSIS
2424
.Nm
25-
.Op Fl AfIMnFqRUy
25+
.Op Fl AfIMnFqRXUy
2626
.Op Fl r Ar reponame
2727
.Op Fl Cgix
2828
.Ar <pkg-origin|pkg-name|pkg-name-version> ...
2929
.Pp
3030
.Nm
31-
.Op Cm --{automatic,force,no-scripts,ignore-missing}
31+
.Op Cm --{automatic,force,no-scripts,ignore-missing,register-only}
3232
.Op Cm --{dry-run,fetch-only,quiet,recursive,no-repo-update,yes}
3333
.Op Cm --repository Ar reponame
3434
.Op Cm --{case-sensitive,glob,case-insensitive,regex}
@@ -133,6 +133,8 @@ If any installation scripts (pre-install or post-install) exist for a given
133133
package, do not execute them.
134134
When a package is updated, deinstallation
135135
scripts (pre-deinstall or post-deinstall) are not run either.
136+
.It Fl i , Cm --register-only
137+
Record the packages installation in the database but do not extract any files
136138
.It Fl i , Cm --case-insensitive
137139
Make the standard or the regular expression
138140
.Fl ( x )

libpkg/pkg.h.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ typedef enum _pkg_flags {
416416
PKG_FLAG_USE_IPV6 = (1U << 12),
417417
PKG_FLAG_UPGRADE_VULNERABLE = (1U << 13),
418418
PKG_FLAG_NOEXEC = (1U << 14),
419-
PKG_FLAG_KEEPFILES = (1U << 15)
419+
PKG_FLAG_KEEPFILES = (1U << 15),
420+
PKG_FLAG_REGISTER_ONLY = (1U << 16)
420421
} pkg_flags;
421422

422423
typedef enum _pkg_stats_t {
@@ -1054,6 +1055,7 @@ int pkg_add(struct pkgdb *db, const char *path, unsigned flags,
10541055
#define PKG_ADD_FORCE_MISSING (1U << 5)
10551056
#define PKG_ADD_SPLITTED_UPGRADE (1U << 6)
10561057
#define PKG_ADD_NOEXEC (1U << 7)
1058+
#define PKG_ADD_REGISTER_ONLY (1U << 8)
10571059

10581060
/**
10591061
* Allocate a new pkg_jobs.

libpkg/pkg_add.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,9 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
13511351
if (flags & PKG_ADD_AUTOMATIC)
13521352
pkg->automatic = true;
13531353

1354+
if (flags & PKG_ADD_REGISTER_ONLY)
1355+
extract = false;
1356+
13541357
/*
13551358
* Additional checks for non-remote package
13561359
*/
@@ -1453,7 +1456,8 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
14531456
/* Update configuration file content with db with newer versions */
14541457
pkgdb_update_config_file_content(pkg, db->sqlite);
14551458

1456-
retcode = pkg_extract_finalize(pkg, &tempdirs);
1459+
if (extract)
1460+
retcode = pkg_extract_finalize(pkg, &tempdirs);
14571461

14581462
pkgdb_register_finale(db, retcode, NULL);
14591463
openxact = false;

libpkg/pkg_jobs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,8 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j)
19891989
flags |= PKG_ADD_NOSCRIPT;
19901990
if ((j->flags & PKG_FLAG_FORCE_MISSING) == PKG_FLAG_FORCE_MISSING)
19911991
flags |= PKG_ADD_FORCE_MISSING;
1992+
if ((j->flags & PKG_FLAG_REGISTER_ONLY) == PKG_FLAG_REGISTER_ONLY)
1993+
flags |= PKG_ADD_REGISTER_ONLY;
19921994
if (ps->type != PKG_SOLVED_INSTALL) {
19931995
flags |= PKG_ADD_UPGRADE;
19941996
if (ps->type == PKG_SOLVED_UPGRADE_INSTALL)

src/install.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ exec_install(int argc, char **argv)
8888
{ "recursive", no_argument, NULL, 'R' },
8989
{ "no-repo-update", no_argument, NULL, 'U' },
9090
{ "regex", no_argument, NULL, 'x' },
91+
{ "register-only", no_argument, NULL, 'X' },
9192
{ "yes", no_argument, NULL, 'y' },
9293
{ NULL, 0, NULL, 0 },
9394
};
@@ -150,6 +151,9 @@ exec_install(int argc, char **argv)
150151
case 'x':
151152
match = MATCH_REGEX;
152153
break;
154+
case 'X':
155+
f |= PKG_FLAG_REGISTER_ONLY | PKG_FLAG_NOSCRIPT;
156+
break;
153157
case 'y':
154158
yes = true;
155159
break;

tests/frontend/install.sh

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ tests_init \
77
reinstall \
88
pre_script_fail \
99
post_script_ignored \
10-
install_missing_dep
10+
install_missing_dep \
11+
install_register_only
1112

1213
test_setup()
1314
{
@@ -191,3 +192,70 @@ EOF
191192
-s not-exit:0 \
192193
pkg -C "${TMPDIR}/pkg.conf" install -y test
193194
}
195+
196+
install_register_only_body()
197+
{
198+
test_setup
199+
200+
touch file1
201+
mkdir dir
202+
touch dir/file2
203+
204+
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "${TMPDIR}"
205+
cat << EOF >> test.ucl
206+
files: {
207+
${TMPDIR}/file1: "",
208+
${TMPDIR}/dir/file2: "",
209+
}
210+
EOF
211+
212+
mkdir repoconf
213+
cat << EOF > repoconf/repo.conf
214+
repo: {
215+
url: file:///$TMPDIR/repo,
216+
enabled: true
217+
}
218+
EOF
219+
220+
mkdir repo
221+
222+
atf_check \
223+
-o empty \
224+
-e empty \
225+
-s exit:0 \
226+
pkg create -M test.ucl -o repo
227+
228+
rm file1
229+
rm dir/file2
230+
rmdir dir
231+
232+
ls
233+
atf_check \
234+
-o ignore \
235+
-e empty \
236+
-s exit:0 \
237+
pkg repo repo
238+
239+
export REPOS_DIR="${TMPDIR}/repoconf"
240+
atf_check \
241+
-o ignore \
242+
-s exit:0 \
243+
pkg install -r repo -y --register-only test
244+
245+
atf_check \
246+
-o inline:"0\n" \
247+
-e empty \
248+
pkg query "%a" test
249+
250+
atf_check \
251+
-o ignore \
252+
-e ignore \
253+
-s exit:1 \
254+
test -f file1
255+
256+
atf_check \
257+
-o ignore \
258+
-e ignore \
259+
-s exit:1 \
260+
test -d dir
261+
}

0 commit comments

Comments
 (0)