+static void on_raw_finished(RawImport *import, int error, void *userdata) {
+ sd_event *event = userdata;
+ assert(import);
+
+ if (error == 0)
+ log_info("Operation completed successfully.");
+ else
+ log_info_errno(error, "Operation failed: %m");
+
+ sd_event_exit(event, error);
+}
+
+static int pull_raw(int argc, char *argv[], void *userdata) {
+ _cleanup_(raw_import_unrefp) RawImport *import = NULL;
+ _cleanup_event_unref_ sd_event *event = NULL;
+ const char *url, *local, *suffix;
+ int r;
+
+ url = argv[1];
+ if (!raw_url_is_valid(url)) {
+ log_error("URL '%s' is not valid.", url);
+ return -EINVAL;
+ }
+
+ if (argc >= 3)
+ local = argv[2];
+ else {
+ const char *e, *p;
+
+ e = url + strlen(url);
+ while (e > url && e[-1] == '/')
+ e--;
+
+ p = e;
+ while (p > url && p[-1] != '/')
+ p--;
+
+ local = strndupa(p, e - p);
+ }
+
+ if (isempty(local) || streq(local, "-"))
+ local = NULL;
+
+ if (local) {
+ const char *p;
+
+ suffix = endswith(local, ".raw.xz");
+ if (!suffix)
+ suffix = endswith(local, ".raw");
+ if (!suffix)
+ suffix = endswith(local, ".xz");
+ if (suffix)
+ local = strndupa(local, suffix - local);
+
+ if (!machine_name_is_valid(local)) {
+ log_error("Local image name '%s' is not valid.", local);
+ return -EINVAL;
+ }
+
+ p = strappenda(arg_image_root, "/", local, ".raw");
+ if (laccess(p, F_OK) >= 0) {
+ if (!arg_force) {
+ log_info("Image '%s' already exists.", local);
+ return 0;
+ }
+ } else if (errno != ENOENT)
+ return log_error_errno(errno, "Can't check if image '%s' already exists: %m", local);
+
+ log_info("Pulling '%s', saving as '%s'.", url, local);
+ } else
+ log_info("Pulling '%s'.", url);
+
+ r = sd_event_default(&event);
+ if (r < 0)
+ return log_error_errno(r, "Failed to allocate event loop: %m");
+
+ assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0);
+ sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
+ sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
+
+ r = raw_import_new(&import, event, arg_image_root, on_raw_finished, event);
+ if (r < 0)
+ return log_error_errno(r, "Failed to allocate importer: %m");
+
+ r = raw_import_pull(import, url, local, arg_force);
+ if (r < 0)
+ return log_error_errno(r, "Failed to pull image: %m");
+
+ r = sd_event_loop(event);
+ if (r < 0)
+ return log_error_errno(r, "Failed to run event loop: %m");
+
+ log_info("Exiting.");
+
+ return 0;
+}
+
+static void on_dkr_finished(DkrImport *import, int error, void *userdata) {