Basic debian put. Unverified.
This commit is contained in:
parent
4f7c5519e2
commit
fd93a937a4
|
@ -53,7 +53,7 @@ include_directories(SYSTEM ${CURLPP_INCLUDE_DIRS})
|
||||||
### THE REAL TARGETS ###
|
### THE REAL TARGETS ###
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}-packager src/packager.cc ${SOURCES} ${HEADERS})
|
add_executable(${PROJECT_NAME}-packager src/packager.cc ${SOURCES} ${HEADERS})
|
||||||
target_link_libraries(${PROJECT_NAME}-packager ${SCSL_LIBRARIES})
|
target_link_libraries(${PROJECT_NAME}-packager ${SCSL_LIBRARIES} ${CURLPP_LIBRARIES})
|
||||||
|
|
||||||
### INCLUDES ###
|
### INCLUDES ###
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,21 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <curlpp/Easy.hpp>
|
||||||
|
#include <curlpp/Exception.hpp>
|
||||||
|
#include <curlpp/Options.hpp>
|
||||||
|
#include <curlpp/cURLpp.hpp>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <scsl/Commander.h>
|
#include <scsl/Commander.h>
|
||||||
#include <scsl/Flags.h>
|
#include <scsl/Flags.h>
|
||||||
#include <scsl/SimpleConfig.h>
|
#include <scsl/SimpleConfig.h>
|
||||||
|
|
||||||
|
|
||||||
|
const auto defaultOwner = std::string("sc");
|
||||||
|
const auto defaultDistribution = std::string("ubuntu");
|
||||||
|
const auto defaultComponent = std::string("main");
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(std::ostream &outs, int exc)
|
usage(std::ostream &outs, int exc)
|
||||||
{
|
{
|
||||||
|
@ -52,13 +62,82 @@ getDefaultConfigFile()
|
||||||
return userHome;
|
return userHome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static std::string
|
||||||
|
debianEndpoint(std::string endpoint)
|
||||||
|
{
|
||||||
|
if (!endpoint.empty() && endpoint.at(0) != '/') {
|
||||||
|
endpoint.insert(endpoint.cbegin(), '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
auto urlBase = scsl::SimpleConfig::GetGlobal("server");
|
||||||
|
return urlBase + "/api/packages/" +
|
||||||
|
scsl::SimpleConfig::GetGlobal("owner", defaultOwner) +
|
||||||
|
"/debian/pool/" +
|
||||||
|
scsl::SimpleConfig::GetGlobal("distribution", defaultDistribution) +
|
||||||
|
"/" +
|
||||||
|
scsl::SimpleConfig::GetGlobal("component", defaultComponent) +
|
||||||
|
endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string
|
||||||
|
getUserPass()
|
||||||
|
{
|
||||||
|
return scsl::SimpleConfig::GetGlobal("http_user") + ":" +
|
||||||
|
scsl::SimpleConfig::GetGlobal("http_password");
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
putDebian(std::vector<std::string> args)
|
putDebian(std::vector<std::string> args)
|
||||||
{
|
{
|
||||||
|
auto ok = true;
|
||||||
std::cout << "[+] put Debian package\n";
|
std::cout << "[+] put Debian package\n";
|
||||||
for (auto &arg: args) {
|
for (auto &arg: args) {
|
||||||
std::cout << "\t[*] " << arg << "\n";
|
std::cout << "\t[*] " << arg << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto url = debianEndpoint("upload");
|
||||||
|
auto userPass = getUserPass();
|
||||||
|
for (auto &arg: args) {
|
||||||
|
try {
|
||||||
|
std::list<std::string> header;
|
||||||
|
header.emplace_back("Content-Type: application/octet-stream");
|
||||||
|
|
||||||
|
curlpp::Cleanup cleaner;
|
||||||
|
curlpp::Easy request;
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(arg)) {
|
||||||
|
std::cerr << "[!] " << arg << " does not exist!\n";
|
||||||
|
ok &= false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto fileSize = static_cast<long>(std::filesystem::file_size(arg));
|
||||||
|
|
||||||
|
std::ifstream debFile(arg);
|
||||||
|
if (!debFile.good()) {
|
||||||
|
std::cerr << "[!] " << arg << " does not exist!\n";
|
||||||
|
ok &= false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.setOpt(new curlpp::options::Url(url));
|
||||||
|
request.setOpt(new curlpp::options::Verbose(true));
|
||||||
|
request.setOpt(new curlpp::options::UserPwd(userPass));
|
||||||
|
request.setOpt(new curlpp::Options::ReadStream(&debFile));
|
||||||
|
request.setOpt(new curlpp::Options::InfileSize(fileSize));
|
||||||
|
request.setOpt(new curlpp::Options::Upload(true));
|
||||||
|
request.perform();
|
||||||
|
} catch (curlpp::LogicError &e) {
|
||||||
|
std::cout << e.what() << "\n";
|
||||||
|
ok &= false;
|
||||||
|
} catch (curlpp::RuntimeError &e) {
|
||||||
|
std::cerr << e.what() << "\n";
|
||||||
|
ok &= false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "[+] " << std::filesystem::path(arg).filename() << ": OK\n";
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue