adding support for RPMs

This commit is contained in:
K. Isom 2024-02-04 07:00:46 +00:00
parent a0b6d45c8a
commit 37ca32f874
6 changed files with 158 additions and 4 deletions

View File

@ -46,13 +46,15 @@ add_compile_definitions(SCSL_DESKTOP_BUILD)
set(HEADERS
include/Debian.h
include/Utility.h
include/RPM.h
include/Generic.h
include/Utility.h
)
set(SOURCES
src/Debian.cc
src/Utility.cc
src/RPM.cc
src/Generic.cc
src/Utility.cc
)
file(GLOB SCRIPTS *.sh)

View File

@ -21,7 +21,7 @@ set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
if (LINUX)
set(CPACK_GENERATOR "DEB;STGZ;TGZ")
set(CPACK_GENERATOR "DEB;RPM;STGZ;TGZ")
elseif (APPLE)
set(CPACK_GENERATOR "productbuild")
elseif (MSVC OR MSYS OR MINGW)

33
include/RPM.h Normal file
View File

@ -0,0 +1,33 @@
///
/// \file RPM.h
/// \author K. Isom <kyle@imap.cc>
/// \date 2024-02-03
/// \brief Functionality for interacting with RPM packages on Gitea.
/// Copyright 2024 K. Isom <kyle@imap.cc>
///
/// Permission to use, copy, modify, and/or distribute this software for
/// any purpose with or without fee is hereby granted, provided that
/// the above copyright notice and this permission notice appear in all /// copies.
///
/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
/// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
/// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
/// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
/// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
/// PERFORMANCE OF THIS SOFTWARE.
///
#ifndef SC3DEV_RPM_H
#define SC3DEV_RPM_H
#include <string>
#include <vector>
bool rpmPackager(std::vector<std::string> args);
#endif// SC3DEV_RPM_H

View File

@ -86,7 +86,7 @@ install_redhat () {
$DNF_INSTALL ca-certificates gzip openssh tar \
clang clang-tools-extra cmake cppcheck doxygen \
gcc-c++ git graphviz libstdc++-devel make scdoc \
valgrind
valgrind fedora-packager rpmdevtools
}
install_unsupported () {

117
src/RPM.cc Normal file
View File

@ -0,0 +1,117 @@
///
/// \file RPM.cc
/// \author K. Isom <kyle@imap.cc>
/// \date 2024-02-03
/// \brief Functionality for interacting with RPM packages on Gitea.
///
/// Copyright 2024 K. Isom <kyle@imap.cc>
///
/// Permission to use, copy, modify, and/or distribute this software for
/// any purpose with or without fee is hereby granted, provided that
/// the above copyright notice and this permission notice appear in all /// copies.
///
/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
/// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
/// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
/// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
/// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
/// PERFORMANCE OF THIS SOFTWARE.
///
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <scsl/Commander.h>
#include <scsl/SimpleConfig.h>
#include <scsl/StringUtil.h>
#include "RPM.h"
#include "Utility.h"
namespace {
std::string
rpmEndpoint(std::string endpoint)
{
if (!endpoint.empty() && endpoint.at(0) != '/') {
endpoint.insert(endpoint.cbegin(), '/');
}
auto urlBase = "https://" + scsl::SimpleConfig::GetGlobal("server");
return urlBase + "/api/packages/" +
scsl::SimpleConfig::GetGlobal("owner", defaultOwner) +
"/rpm/" + endpoint;
}
std::string
endpointForPackage(std::string package)
{
const std::filesystem::path pkgAsPath(package);
auto stem = pkgAsPath.stem();
auto parts = scsl::scstring::SplitN(stem, "_", 3);
if (parts.size() != 3) {
return "";
}
return parts[0] + "/" + parts[1] + "/" + parts[2];
}
bool
putRPM(std::vector<std::string> args)
{
auto ok = true;
for (auto &arg: args) {
auto url = rpmEndpoint("upload");
auto result = PutFile(url, arg);
std::cout << "\t[*] PUT " << std::filesystem::path(arg).filename() << ": ";
std::cout << ResultToString(result) << "\n";
ok &= ResultSuccess(result);
}
return ok;
}
bool
deleteRPM(std::vector<std::string> args)
{
auto ok = true;
for (auto &arg: args) {
auto endpoint = endpointForPackage(arg);
if (endpoint.empty()) {
std::cerr << arg << ": invalid filename\n";
ok &= false;
continue;
}
auto url = rpmEndpoint(endpoint);
std::cerr << "URL: " << url << "\n";
auto result = DeleteFile(url);
std::cout << "\t[*] DELETE " << std::filesystem::path(arg).filename() << ": ";
std::cout << ResultToString(result) << "\n";
ok &= ResultSuccess(result);
}
return ok;
}
}// anonymous namespace
bool
rpmPackager(std::vector<std::string> args)
{
scsl::Commander commander;
commander.Register(scsl::Subcommand("del", 1, deleteRPM));
commander.Register(scsl::Subcommand("put", 1, putRPM));
auto command = args[0];
args.erase(args.cbegin());
return commander.Run(command, args) == scsl::Subcommand::Status::OK;
}

View File

@ -30,6 +30,7 @@
#include "Debian.h"
#include "Generic.h"
#include "RPM.h"
#include "Utility.h"
@ -105,6 +106,7 @@ main(int argc, char *argv[])
scsl::Commander commander;
commander.Register(scsl::Subcommand("debian", 2, debianPackager));
commander.Register(scsl::Subcommand("generic", 2, genericPackager));
commander.Register(scsl::Subcommand("rpm", 2, rpmPackager));
flags->GetString("--config", configFile);
if (std::filesystem::exists(std::filesystem::path(configFile))) {