static bool arg_force = false;
static const char *arg_image_root = "/var/lib/machines";
-
+static ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
static const char* arg_dkr_index_url = DEFAULT_DKR_INDEX_URL;
static void on_tar_finished(TarImport *import, int error, void *userdata) {
if (error == 0)
log_info("Operation completed successfully.");
- else
- log_error_errno(error, "Operation failed: %m");
- sd_event_exit(event, error);
+ sd_event_exit(event, EXIT_FAILURE);
}
static int strip_tar_suffixes(const char *name, char **ret) {
char *s;
e = endswith(name, ".tar");
+ if (!e)
+ e = endswith(name, ".tar.xz");
if (!e)
e = endswith(name, ".tar.gz");
if (!e)
- e = endswith(name, ".tar.xz");
+ e = endswith(name, ".tar.bz2");
if (!e)
e = endswith(name, ".tgz");
if (!e)
if (r < 0)
return log_error_errno(r, "Failed to allocate importer: %m");
- r = tar_import_pull(import, url, local, arg_force);
+ r = tar_import_pull(import, url, local, arg_force, arg_verify);
if (r < 0)
return log_error_errno(r, "Failed to pull image: %m");
log_info("Exiting.");
- return 0;
+ return r;
}
static void on_raw_finished(RawImport *import, int error, void *userdata) {
if (error == 0)
log_info("Operation completed successfully.");
- else
- log_error_errno(error, "Operation failed: %m");
- sd_event_exit(event, error);
+ sd_event_exit(event, EXIT_FAILURE);
}
static int strip_raw_suffixes(const char *p, char **ret) {
static const char suffixes[] =
".xz\0"
+ ".gz\0"
+ ".bz2\0"
".raw\0"
".qcow2\0"
- ".img\0";
+ ".img\0"
+ ".bin\0";
_cleanup_free_ char *q = NULL;
if (r < 0)
return log_error_errno(r, "Failed to allocate importer: %m");
- r = raw_import_pull(import, url, local, arg_force);
+ r = raw_import_pull(import, url, local, arg_force, arg_verify);
if (r < 0)
return log_error_errno(r, "Failed to pull image: %m");
log_info("Exiting.");
- return 0;
+ return r;
}
static void on_dkr_finished(DkrImport *import, int error, void *userdata) {
if (error == 0)
log_info("Operation completed successfully.");
- else
- log_error_errno(error, "Operation failed: %m");
- sd_event_exit(event, error);
+ sd_event_exit(event, EXIT_FAILURE);
}
static int pull_dkr(int argc, char *argv[], void *userdata) {
return -EINVAL;
}
+ if (arg_verify != IMPORT_VERIFY_NO) {
+ log_error("Imports from dkr do not support image verification, please pass --verify=no.");
+ return -EINVAL;
+ }
+
tag = strchr(argv[1], ':');
if (tag) {
name = strndupa(argv[1], tag - argv[1]);
local = NULL;
if (local) {
- const char *p;
-
if (!machine_name_is_valid(local)) {
log_error("Local image name '%s' is not valid.", local);
return -EINVAL;
}
- p = strappenda(arg_image_root, "/", local);
- if (laccess(p, F_OK) >= 0) {
- if (!arg_force) {
- log_info("Image '%s' already exists.", local);
- return 0;
+ if (!arg_force) {
+ r = image_find(local, NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
+ else if (r > 0) {
+ log_error_errno(EEXIST, "Image '%s' already exists.", local);
+ return -EEXIST;
}
- } else if (errno != ENOENT)
- return log_error_errno(errno, "Can't check if image '%s' already exists: %m", local);
+ }
log_info("Pulling '%s' with tag '%s', saving as '%s'.", name, tag, local);
} else
" -h --help Show this help\n"
" --version Show package version\n"
" --force Force creation of image\n"
+ " --verify= Verify downloaded image, one of: 'no', 'sum'\n"
+ " 'signature'.\n"
" --image-root= Image root directory\n"
" --dkr-index-url=URL Specify index URL to use for downloads\n\n"
"Commands:\n"
ARG_FORCE,
ARG_DKR_INDEX_URL,
ARG_IMAGE_ROOT,
+ ARG_VERIFY,
};
static const struct option options[] = {
{ "force", no_argument, NULL, ARG_FORCE },
{ "dkr-index-url", required_argument, NULL, ARG_DKR_INDEX_URL },
{ "image-root", required_argument, NULL, ARG_IMAGE_ROOT },
+ { "verify", required_argument, NULL, ARG_VERIFY },
{}
};
break;
case ARG_DKR_INDEX_URL:
- if (!dkr_url_is_valid(optarg)) {
+ if (!http_url_is_valid(optarg)) {
log_error("Index URL is not valid: %s", optarg);
return -EINVAL;
}
arg_image_root = optarg;
break;
+ case ARG_VERIFY:
+ arg_verify = import_verify_from_string(optarg);
+ if (arg_verify < 0) {
+ log_error("Invalid verification setting '%s'", optarg);
+ return -EINVAL;
+ }
+
+ break;
+
case '?':
return -EINVAL;