pull.c revision b5efdb8af40ea759a1ea584c1bc44ecc81dd00ce
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <getopt.h>
#include "sd-event.h"
#include "alloc-util.h"
#include "event-util.h"
#include "hostname-util.h"
#include "import-util.h"
#include "machine-image.h"
#include "parse-util.h"
#include "pull-dkr.h"
#include "pull-raw.h"
#include "pull-tar.h"
#include "signal-util.h"
#include "string-util.h"
#include "verbs.h"
#include "web-util.h"
static bool arg_force = false;
static const char *arg_image_root = "/var/lib/machines";
static const char* arg_dkr_index_url = DEFAULT_DKR_INDEX_URL;
static bool arg_settings = true;
static int interrupt_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
log_notice("Transfer aborted.");
return 0;
}
if (error == 0)
log_info("Operation completed successfully.");
}
int r;
if (!http_url_is_valid(url)) {
return -EINVAL;
}
if (argc >= 3)
else {
r = import_url_last_component(url, &l);
if (r < 0)
return log_error_errno(r, "Failed get final component of URL: %m");
local = l;
}
if (local) {
if (r < 0)
return log_oom();
if (!machine_name_is_valid(local)) {
return -EINVAL;
}
if (!arg_force) {
if (r < 0)
else if (r > 0) {
return -EEXIST;
}
}
} else
r = sd_event_default(&event);
if (r < 0)
return log_error_errno(r, "Failed to allocate event loop: %m");
if (r < 0)
return log_error_errno(r, "Failed to allocate puller: %m");
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 -r;
}
if (error == 0)
log_info("Operation completed successfully.");
}
int r;
if (!http_url_is_valid(url)) {
return -EINVAL;
}
if (argc >= 3)
else {
r = import_url_last_component(url, &l);
if (r < 0)
return log_error_errno(r, "Failed get final component of URL: %m");
local = l;
}
if (local) {
if (r < 0)
return log_oom();
if (!machine_name_is_valid(local)) {
return -EINVAL;
}
if (!arg_force) {
if (r < 0)
else if (r > 0) {
return -EEXIST;
}
}
} else
r = sd_event_default(&event);
if (r < 0)
return log_error_errno(r, "Failed to allocate event loop: %m");
if (r < 0)
return log_error_errno(r, "Failed to allocate puller: %m");
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 -r;
}
if (error == 0)
log_info("Operation completed successfully.");
}
int r;
if (!arg_dkr_index_url) {
log_error("Please specify an index URL with --dkr-index-url=");
return -EINVAL;
}
if (arg_verify != IMPORT_VERIFY_NO) {
log_error("Pulls from dkr do not support image verification, please pass --verify=no.");
return -EINVAL;
}
if (digest) {
} else {
if (reference) {
reference++;
} else {
reference = "latest";
}
}
if (!dkr_name_is_valid(name)) {
return -EINVAL;
}
if (!dkr_ref_is_valid(reference)) {
return -EINVAL;
}
if (argc >= 3)
else {
if (local)
local++;
else
}
if (local) {
if (!machine_name_is_valid(local)) {
return -EINVAL;
}
if (!arg_force) {
if (r < 0)
else if (r > 0) {
return -EEXIST;
}
}
} else
r = sd_event_default(&event);
if (r < 0)
return log_error_errno(r, "Failed to allocate event loop: %m");
if (r < 0)
return log_error_errno(r, "Failed to allocate puller: %m");
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 -r;
}
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Download container or virtual machine images.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --force Force creation of image\n"
" --verify=MODE Verify downloaded image, one of: 'no',\n"
" 'checksum', 'signature'\n"
" --settings=BOOL Download settings file with image\n"
" --image-root=PATH Image root directory\n"
" --dkr-index-url=URL Specify index URL to use for downloads\n\n"
"Commands:\n"
" tar URL [NAME] Download a TAR image\n"
" raw URL [NAME] Download a RAW image\n"
" dkr REMOTE [NAME] Download a DKR image\n",
return 0;
}
enum {
ARG_VERSION = 0x100,
};
{}
};
int c, r;
switch (c) {
case 'h':
case ARG_VERSION:
return version();
case ARG_FORCE:
arg_force = true;
break;
case ARG_DKR_INDEX_URL:
if (!http_url_is_valid(optarg)) {
return -EINVAL;
}
break;
case ARG_IMAGE_ROOT:
break;
case ARG_VERIFY:
if (arg_verify < 0) {
return -EINVAL;
}
break;
case ARG_SETTINGS:
r = parse_boolean(optarg);
if (r < 0)
arg_settings = r;
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
return 1;
}
{}
};
}
int r;
log_open();
if (r <= 0)
goto finish;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}