3 #include <boost/filesystem.hpp>
4 #include <boost/program_options.hpp>
6 #include "accumulator.h"
7 #include "authenticate.h"
11 #include "garage_tools_version.h"
12 #include "logging/logging.h"
13 #include "ostree_http_repo.h"
15 namespace po = boost::program_options;
17 int main(
int argc,
char **argv) {
21 std::string ostree_commit;
23 boost::filesystem::path fetch_cred;
24 boost::filesystem::path push_cred;
25 std::string hardwareids;
27 int max_curl_requests;
29 po::options_description desc(
"garage-deploy command line options");
32 (
"help",
"print usage")
33 (
"version",
"Current garage-deploy version")
34 (
"verbose,v", accumulator<int>(&verbosity),
"Verbose logging (use twice for more information)")
35 (
"quiet,q",
"Quiet mode")
36 (
"commit", po::value<std::string>(&ostree_commit)->required(),
"OSTree commit to deploy")
37 (
"name", po::value<std::string>(&name)->required(),
"Name of image")
38 (
"fetch-credentials,f", po::value<boost::filesystem::path>(&fetch_cred)->required(),
"path to source credentials")
39 (
"push-credentials,p", po::value<boost::filesystem::path>(&push_cred)->required(),
"path to destination credentials")
40 (
"hardwareids,h", po::value<std::string>(&hardwareids)->required(),
"list of hardware ids")
41 (
"cacert", po::value<std::string>(&cacerts),
"override path to CA root certificates, in the same format as curl --cacert")
42 (
"jobs", po::value<int>(&max_curl_requests)->default_value(30),
"maximum number of parallel requests")
43 (
"dry-run,n",
"check arguments and authenticate but don't upload");
49 po::store(po::parse_command_line(argc, reinterpret_cast<const char *const *>(argv), desc), vm);
51 if (vm.count(
"help") != 0u) {
55 if (vm.count(
"version") != 0) {
56 LOG_INFO <<
"Current garage-deploy version is: " << garage_tools_version();
60 }
catch (
const po::error &o) {
61 LOG_ERROR << o.what();
69 if (static_cast<int>(vm.count(
"quiet")) != 0) {
70 logger_set_threshold(boost::log::trivial::warning);
72 logger_set_threshold(boost::log::trivial::info);
74 }
else if (verbosity == 1) {
75 logger_set_threshold(boost::log::trivial::debug);
76 LOG_DEBUG <<
"Debug level debugging enabled";
77 }
else if (verbosity > 1) {
78 logger_set_threshold(boost::log::trivial::trace);
79 LOG_TRACE <<
"Trace level debugging enabled";
84 Utils::setUserAgent(std::string(
"garage-deploy/") + garage_tools_version());
86 if (vm.count(
"dry-run") != 0u) {
90 if (max_curl_requests < 1) {
91 LOG_FATAL <<
"--jobs must be greater than 0";
97 if (authenticate(cacerts, fetch_credentials, fetch_server) != EXIT_SUCCESS) {
98 LOG_FATAL <<
"Authentication with fetch server failed";
104 if (authenticate(cacerts, push_credentials, push_server) != EXIT_SUCCESS) {
105 LOG_FATAL <<
"Authentication with push server failed";
109 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeHttpRepo>(&fetch_server);
115 if (!UploadToTreehub(src_repo, push_server, commit, mode, max_curl_requests)) {
116 LOG_FATAL <<
"Upload to treehub failed";
121 if (!push_credentials.CanSignOffline()) {
122 LOG_FATAL <<
"Provided push credentials are missing required components to sign Targets metadata.";
125 if (!OfflineSignRepo(
ServerCredentials(push_credentials.GetPathOnDisk()), name, commit, hardwareids)) {
129 if (CheckRefValid(push_server, ostree_commit, mode, max_curl_requests) != EXIT_SUCCESS) {
130 LOG_FATAL <<
"Check if the ref is present on the server or in targets.json failed";
134 LOG_INFO <<
"Dry run. Not attempting offline signing.";
137 LOG_FATAL << e.what();