:-'Generic Commit'
This commit is contained in:
parent
f5e39a64eb
commit
e858ab18d1
@ -189,23 +189,33 @@ function build_arch() {
|
||||
CMAKE_BUILD_TYPE="Debug"
|
||||
fi
|
||||
|
||||
CC="${HOME}/.musl-cross/${ARCH}-linux-musl-cross/bin/${ARCH}-linux-musl-gcc"
|
||||
CXX="${HOME}/.musl-cross/${ARCH}-linux-musl-cross/bin/${ARCH}-linux-musl-g++"
|
||||
export CC="${HOME}/.musl-cross/${ARCH}-linux-musl-cross/bin/${ARCH}-linux-musl-gcc"
|
||||
export CXX="${HOME}/.musl-cross/${ARCH}-linux-musl-cross/bin/${ARCH}-linux-musl-g++"
|
||||
export SYSROOT="${HOME}/.musl-cross/${ARCH}-linux-musl-cross/${ARCH}-linux-musl/sysroot"
|
||||
export CFLAGS="--sysroot=$SYSROOT"
|
||||
export CXXFLAGS="--sysroot=$SYSROOT"
|
||||
export LDFLAGS="--sysroot=$SYSROOT"
|
||||
export MAKEFLAGS="-j${JOBS}"
|
||||
|
||||
cmake -B "${ARCH_BUILD_DIR}" -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_LINKER=mold \
|
||||
-DCMAKE_C_COMPILER="${CC}" \
|
||||
-DCMAKE_CXX_COMPILER="${CXX}"
|
||||
-DCMAKE_C_COMPILER_TARGET="${ARCH}-linux-musl" \
|
||||
-DCMAKE_CXX_COMPILER_TARGET="${ARCH}-linux-musl" \
|
||||
-DCMAKE_C_FLAGS="${CFLAGS}" \
|
||||
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
|
||||
-DCMAKE_LDFLAGS="${LDFLAGS}" \
|
||||
-DCMAKE_FIND_ROOT_PATH="${SYSROOT}" \
|
||||
-DCMAKE_SYSROOT="${SYSROOT}"
|
||||
cd "${ARCH_BUILD_DIR}" || exit 1
|
||||
ninja -j"${JOBS}"
|
||||
ninja -k0 -j"${JOBS}"
|
||||
|
||||
if [ "$RELEASE" -eq 1 ]; then
|
||||
upx "${ARCH_BUILD_DIR}/${EXECUTABLE_NAME}"
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d "${OUTPUT_DIR}" ]; then
|
||||
mkdir -p "${OUTPUT_DIR}"
|
||||
fi
|
||||
|
@ -102,3 +102,7 @@ set_target_properties(${PROJECT_EXE_NAME} PROPERTIES
|
||||
LINK_FLAGS "-static"
|
||||
)
|
||||
|
||||
find_package(OpenSSL REQUIRED)
|
||||
target_compile_definitions(${PROJECT_EXE_NAME} PRIVATE CPPHTTPLIB_OPENSSL_SUPPORT)
|
||||
target_link_libraries(${PROJECT_EXE_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
|
||||
|
||||
|
@ -6,11 +6,11 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "DropshellScriptManager.hpp"
|
||||
|
||||
namespace dropshelltool
|
||||
{
|
||||
|
||||
static const std::filesystem::path DROPSHELL_RC_PATH = std::filesystem::path(std::getenv("HOME")) / ".bashrc_dropshell_tool";
|
||||
const std::filesystem::path DROPSHELL_RC_PATH = std::filesystem::path(std::getenv("HOME")) / ".bashrc_dropshell_tool";
|
||||
static const std::filesystem::path BASHRC_PATH = std::filesystem::path(std::getenv("HOME")) / ".bashrc";
|
||||
|
||||
std::string removeWhitespace(const std::string &s)
|
||||
@ -92,10 +92,8 @@ namespace dropshelltool
|
||||
|
||||
if (!std::filesystem::exists(DROPSHELL_RC_PATH))
|
||||
{
|
||||
std::filesystem::create_directories(DROPSHELL_RC_PATH.parent_path());
|
||||
std::ofstream outfile(DROPSHELL_RC_PATH, std::ios::trunc);
|
||||
outfile << "echo 'Dropshell tools configured'" << std::endl;
|
||||
outfile.close();
|
||||
DropshellScriptManager scriptManager;
|
||||
scriptManager.ensureExists();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
namespace dropshelltool {
|
||||
|
||||
extern const std::filesystem::path DROPSHELL_RC_PATH;
|
||||
|
||||
class BashrcEditor {
|
||||
public:
|
||||
BashrcEditor();
|
||||
|
@ -2,35 +2,167 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
|
||||
DropshellScriptManager::DropshellScriptManager(const std::string& scriptPath) : scriptPath(scriptPath) {}
|
||||
namespace dropshelltool {
|
||||
extern const std::filesystem::path DROPSHELL_RC_PATH;
|
||||
}
|
||||
|
||||
DropshellScriptManager::DropshellScriptManager() {}
|
||||
|
||||
// Helper function to trim whitespace from both ends of a string
|
||||
static std::string trim(const std::string& s) {
|
||||
auto start = s.begin();
|
||||
while (start != s.end() && std::isspace(*start)) ++start;
|
||||
auto end = s.end();
|
||||
do { --end; } while (std::distance(start, end) > 0 && std::isspace(*end));
|
||||
return std::string(start, end + 1);
|
||||
}
|
||||
|
||||
void DropshellScriptManager::ensureExists() const {
|
||||
// TODO: Implement file existence check/creation
|
||||
if (!std::filesystem::exists(dropshelltool::DROPSHELL_RC_PATH)) {
|
||||
std::filesystem::create_directories(dropshelltool::DROPSHELL_RC_PATH.parent_path());
|
||||
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
|
||||
outfile << "# This file is managed by dropshell-tool. Do not edit manually!" << std::endl;
|
||||
outfile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void DropshellScriptManager::addToolEntry(const std::string& toolName, const std::string& toolDir) {
|
||||
// TODO: Implement tool entry addition
|
||||
ensureExists();
|
||||
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
std::string exportLine = "export PATH=\"" + toolDir + ":$PATH\" # dropshell-tool:" + toolName;
|
||||
bool found = false;
|
||||
while (std::getline(infile, line)) {
|
||||
if (line.find("# dropshell-tool:" + toolName) != std::string::npos) {
|
||||
found = true;
|
||||
lines.push_back(exportLine);
|
||||
} else {
|
||||
lines.push_back(line);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
if (!found) lines.push_back(exportLine);
|
||||
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
|
||||
for (const auto& l : lines) outfile << l << "\n";
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
void DropshellScriptManager::removeToolEntry(const std::string& toolName) {
|
||||
// TODO: Implement tool entry removal
|
||||
ensureExists();
|
||||
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
while (std::getline(infile, line)) {
|
||||
if (line.find("# dropshell-tool:" + toolName) == std::string::npos) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
|
||||
for (const auto& l : lines) outfile << l << "\n";
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
void DropshellScriptManager::addAlias(const std::string& alias, const std::string& toolName) {
|
||||
// TODO: Implement alias addition
|
||||
ensureExists();
|
||||
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
std::string aliasLine = "alias " + alias + "='" + toolName + "' # dropshell-alias:" + alias;
|
||||
bool found = false;
|
||||
while (std::getline(infile, line)) {
|
||||
if (line.find("# dropshell-alias:" + alias) != std::string::npos) {
|
||||
found = true;
|
||||
lines.push_back(aliasLine);
|
||||
} else {
|
||||
lines.push_back(line);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
if (!found) lines.push_back(aliasLine);
|
||||
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
|
||||
for (const auto& l : lines) outfile << l << "\n";
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
void DropshellScriptManager::addAutocomplete(const std::string& toolName) {
|
||||
// TODO: Implement autocomplete entry
|
||||
ensureExists();
|
||||
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
std::string funcName = "_" + toolName + "_autocomplete";
|
||||
std::string blockStart = "# DROPSHELL-AUTOCOMPLETE-START: " + toolName;
|
||||
std::string blockEnd = "# DROPSHELL-AUTOCOMPLETE-END: " + toolName;
|
||||
std::string funcDef;
|
||||
funcDef += blockStart + "\n";
|
||||
funcDef += funcName + "() {\n";
|
||||
funcDef += " COMPREPLY=($(" + toolName + " autocomplete \"${COMP_WORDS[@]:1}\"))\n";
|
||||
funcDef += "}\n";
|
||||
funcDef += blockEnd + "\n";
|
||||
std::string completeLine = "complete -F " + funcName + " " + toolName + " # dropshell-autocomplete:" + toolName;
|
||||
bool blockFound = false, completeFound = false;
|
||||
bool inBlock = false;
|
||||
while (std::getline(infile, line)) {
|
||||
if (!inBlock && trim(line) == blockStart) {
|
||||
blockFound = true;
|
||||
inBlock = true;
|
||||
continue;
|
||||
}
|
||||
if (inBlock) {
|
||||
if (trim(line) == blockEnd) {
|
||||
inBlock = false;
|
||||
lines.push_back(funcDef); // Add new function block
|
||||
}
|
||||
continue; // Skip all lines in the old block
|
||||
}
|
||||
if (line.find("# dropshell-autocomplete:" + toolName) != std::string::npos) {
|
||||
completeFound = true;
|
||||
lines.push_back(completeLine);
|
||||
} else {
|
||||
lines.push_back(line);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
if (!blockFound) lines.push_back(funcDef);
|
||||
if (!completeFound) lines.push_back(completeLine);
|
||||
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
|
||||
for (const auto& l : lines) outfile << l << "\n";
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
bool DropshellScriptManager::hasAlias(const std::string& alias) const {
|
||||
// TODO: Implement alias check
|
||||
ensureExists();
|
||||
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
|
||||
std::string line;
|
||||
while (std::getline(infile, line)) {
|
||||
if (line.find("# dropshell-alias:" + alias) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> DropshellScriptManager::listAliases() const {
|
||||
// TODO: Implement alias listing
|
||||
return {};
|
||||
ensureExists();
|
||||
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
|
||||
std::string line;
|
||||
std::vector<std::string> aliases;
|
||||
while (std::getline(infile, line)) {
|
||||
auto pos = line.find("# dropshell-alias:");
|
||||
if (pos != std::string::npos) {
|
||||
auto aliasStart = line.find("alias ");
|
||||
if (aliasStart != std::string::npos) {
|
||||
auto eq = line.find('=', aliasStart + 6);
|
||||
if (eq != std::string::npos) {
|
||||
std::string alias = line.substr(aliasStart + 6, eq - (aliasStart + 6));
|
||||
aliases.push_back(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return aliases;
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
|
||||
class DropshellScriptManager {
|
||||
public:
|
||||
DropshellScriptManager(const std::string& scriptPath);
|
||||
DropshellScriptManager();
|
||||
void ensureExists() const;
|
||||
void addToolEntry(const std::string& toolName, const std::string& toolDir);
|
||||
void removeToolEntry(const std::string& toolName);
|
||||
@ -12,6 +12,4 @@ public:
|
||||
void addAutocomplete(const std::string& toolName);
|
||||
bool hasAlias(const std::string& alias) const;
|
||||
std::vector<std::string> listAliases() const;
|
||||
private:
|
||||
std::string scriptPath;
|
||||
};
|
@ -1,19 +1,73 @@
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
#include "GetbinClient.hpp"
|
||||
#include "httplib.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
static constexpr const char* SERVER_HOST = "getbin.xyz";
|
||||
|
||||
GetbinClient::GetbinClient() {}
|
||||
|
||||
bool GetbinClient::download(const std::string& toolName, const std::string& arch, const std::string& outPath) {
|
||||
// TODO: Implement download logic
|
||||
return false;
|
||||
httplib::SSLClient cli(SERVER_HOST, 443);
|
||||
std::string object_path = "/object/" + toolName + ":" + arch;
|
||||
auto res = cli.Get(object_path.c_str());
|
||||
if (!res || res->status != 200) return false;
|
||||
std::ofstream ofs(outPath, std::ios::binary);
|
||||
if (!ofs) return false;
|
||||
ofs.write(res->body.data(), res->body.size());
|
||||
return ofs.good();
|
||||
}
|
||||
|
||||
bool GetbinClient::upload(const std::string& archivePath, std::string& outUrl, std::string& outHash, const std::string& token) {
|
||||
// TODO: Implement upload logic
|
||||
return false;
|
||||
httplib::SSLClient cli(SERVER_HOST, 443);
|
||||
httplib::MultipartFormDataItems items;
|
||||
// Read file
|
||||
std::ifstream ifs(archivePath, std::ios::binary);
|
||||
if (!ifs) return false;
|
||||
std::string file_content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
// Compose metadata (minimal, can be extended)
|
||||
json metadata = { {"labeltags", json::array()} };
|
||||
// Try to extract tool:arch from filename
|
||||
std::string filename = archivePath.substr(archivePath.find_last_of("/\\") + 1);
|
||||
size_t dot = filename.find('.');
|
||||
std::string labeltag = dot != std::string::npos ? filename.substr(0, dot) : filename;
|
||||
metadata["labeltags"].push_back(labeltag);
|
||||
items.push_back({"file", file_content, filename, "application/gzip"});
|
||||
items.push_back({"metadata", metadata.dump(), "", "application/json"});
|
||||
httplib::Headers headers = { {"Authorization", "Bearer " + token} };
|
||||
auto res = cli.Put("/upload", headers, items);
|
||||
if (!res || (res->status != 200 && res->status != 201)) return false;
|
||||
// Parse response for URL/hash
|
||||
try {
|
||||
auto resp_json = json::parse(res->body);
|
||||
if (resp_json.contains("url")) outUrl = resp_json["url"].get<std::string>();
|
||||
if (resp_json.contains("hash")) outHash = resp_json["hash"].get<std::string>();
|
||||
} catch (...) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetbinClient::getHash(const std::string& toolName, const std::string& arch, std::string& outHash) {
|
||||
// TODO: Implement hash retrieval logic
|
||||
httplib::SSLClient cli(SERVER_HOST, 443);
|
||||
std::string exists_path = "/exists/" + toolName + ":" + arch;
|
||||
auto res = cli.Get(exists_path.c_str());
|
||||
if (!res || res->status != 200) return false;
|
||||
// Try to parse hash from response body (assume plain text or JSON)
|
||||
try {
|
||||
// Try JSON
|
||||
auto resp_json = json::parse(res->body);
|
||||
if (resp_json.contains("hash")) {
|
||||
outHash = resp_json["hash"].get<std::string>();
|
||||
return true;
|
||||
}
|
||||
} catch (...) {
|
||||
// Not JSON, treat as plain text
|
||||
outHash = res->body;
|
||||
return !outHash.empty();
|
||||
}
|
||||
return false;
|
||||
}
|
10509
dropshell-tool/src/httplib.hpp
Normal file
10509
dropshell-tool/src/httplib.hpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user