homectl: add a 'dry-run' mode for registering/creating users

Since this only covers user creation/registration for now, let's hide it
behind an env var. We might reconsider this eventually and make it a
proper switch one day, but who knows, it after all has this "debug tool"
wiff.
This commit is contained in:
Lennart Poettering
2025-03-07 18:14:14 +01:00
parent 87c81a34eb
commit 4f00011b68
2 changed files with 23 additions and 0 deletions
+5
View File
@@ -615,6 +615,11 @@ SYSTEMD_HOME_DEBUG_SUFFIX=foo \
there already exists at least one regular user on the system. If set to "0"
will make the tool skip any such query.
* `$SYSTEMD_HOME_DRY_RUN` – if set to "1" will make `homectl create` and
`homectl update` operate in a "dry-run" mode: the new user record is
assembled, and displayed in JSON format, but not actually passed to
`systemd-homed` for execution of the operation.
`kernel-install`:
* `$KERNEL_INSTALL_BYPASS` – If set to "1", execution of kernel-install is skipped
+18
View File
@@ -99,6 +99,7 @@ static char *arg_blob_dir = NULL;
static bool arg_blob_clear = false;
static Hashmap *arg_blob_files = NULL;
static char *arg_key_name = NULL;
static bool arg_dry_run = false;
STATIC_DESTRUCTOR_REGISTER(arg_identity_extra, sd_json_variant_unrefp);
STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_this_machine, sd_json_variant_unrefp);
@@ -1462,6 +1463,11 @@ static int create_home_common(sd_json_variant *input, bool show_enforce_password
log_warning_errno(r, "Specified password does not pass quality checks (%s), proceeding anyway.", bus_error_message(&error, r));
}
if (arg_dry_run) {
sd_json_variant_dump(hr->json, SD_JSON_FORMAT_COLOR_AUTO|SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_NEWLINE, stderr, /* prefix= */ NULL);
return 0;
}
r = acquire_bus(&bus);
if (r < 0)
return r;
@@ -1760,6 +1766,11 @@ static int update_home(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
if (arg_dry_run) {
sd_json_variant_dump(hr->json, SD_JSON_FORMAT_COLOR_AUTO|SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_NEWLINE, stderr, /* prefix= */ NULL);
return 0;
}
/* If we do multiple operations, let's output things more verbosely, since otherwise the repeated
* authentication might be confusing. */
@@ -3181,6 +3192,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
/* Eventually we should probably turn this into a proper --dry-run option, but as long as it is not hooked up everywhere let's make it an environment variable only. */
r = getenv_bool("SYSTEMD_HOME_DRY_RUN");
if (r >= 0)
arg_dry_run = r;
else if (r != -ENXIO)
log_debug_errno(r, "Unable to parse $SYSTEMD_HOME_DRY_RUN, ignoring: %m");
for (;;) {
int c;