Compare commits
3 Commits
2025.0513.
...
2025.0514.
Author | SHA1 | Date | |
---|---|---|---|
47dcfca5f2 | |||
283b88effc | |||
97776b4642 |
29
build.sh
29
build.sh
@ -9,15 +9,11 @@ GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Parse command line arguments
|
||||
AUTO_INSTALL=false
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--auto-install)
|
||||
AUTO_INSTALL=true
|
||||
;;
|
||||
esac
|
||||
done
|
||||
JOBS=4
|
||||
# Determine number of CPU cores for parallel build
|
||||
if command -v nproc >/dev/null 2>&1; then
|
||||
JOBS=$(nproc)
|
||||
fi
|
||||
|
||||
|
||||
# Function to print status messages
|
||||
@ -79,7 +75,7 @@ cmake .. -DCMAKE_BUILD_TYPE=Debug
|
||||
|
||||
# Build the project
|
||||
print_status "Building project..."
|
||||
make -j$(nproc)
|
||||
make -j"$JOBS"
|
||||
|
||||
# Check if build was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
@ -90,8 +86,6 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if user wants to install
|
||||
if [ $AUTO_INSTALL = true ]; then
|
||||
print_status "Auto-installing dropshell..."
|
||||
sudo make install
|
||||
if [ $? -eq 0 ]; then
|
||||
@ -100,16 +94,7 @@ if [ $AUTO_INSTALL = true ]; then
|
||||
print_error "Installation failed!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
print_status "Installing dropshell..."
|
||||
sudo make install
|
||||
if [ $? -eq 0 ]; then
|
||||
print_status "Installation successful!"
|
||||
else
|
||||
print_error "Installation failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Return to original directory
|
||||
cd ..
|
||||
|
@ -8,6 +8,13 @@ set -e
|
||||
|
||||
rm -f build_amd64/dropshell build_arm64/dropshell build/dropshell.amd64 build/dropshell.arm64
|
||||
|
||||
# Determine number of CPU cores for parallel build
|
||||
if command -v nproc >/dev/null 2>&1; then
|
||||
JOBS=$(nproc)
|
||||
else
|
||||
JOBS=4 # fallback default
|
||||
fi
|
||||
|
||||
# Build for amd64 (musl)
|
||||
echo "Building for amd64 (musl)..."
|
||||
cmake -B build_amd64 -DCMAKE_BUILD_TYPE=Release \
|
||||
@ -15,7 +22,7 @@ cmake -B build_amd64 -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_CXX_COMPILER=x86_64-linux-musl-g++ \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-static" \
|
||||
-DCMAKE_CXX_FLAGS="-march=x86-64" .
|
||||
cmake --build build_amd64 --target dropshell --config Release
|
||||
cmake --build build_amd64 --target dropshell --config Release -j"$JOBS"
|
||||
mkdir -p build
|
||||
cp build_amd64/dropshell build/dropshell.amd64
|
||||
|
||||
@ -27,7 +34,7 @@ cmake -B build_arm64 -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-static" \
|
||||
-DCMAKE_CXX_FLAGS="-march=armv8-a" \
|
||||
-DCMAKE_SYSTEM_PROCESSOR=aarch64 .
|
||||
cmake --build build_arm64 --target dropshell --config Release
|
||||
cmake --build build_arm64 --target dropshell --config Release -j"$JOBS"
|
||||
mkdir -p build
|
||||
cp build_arm64/dropshell build/dropshell.arm64
|
||||
|
||||
|
@ -72,7 +72,7 @@ if [ -z "$RELEASE_ID" ]; then
|
||||
fi
|
||||
|
||||
# Upload binaries and install.sh
|
||||
for FILE in dropshell.amd64 dropshell.arm64 install.sh; do
|
||||
for FILE in dropshell.amd64 dropshell.arm64 install.sh server_autosetup.sh; do
|
||||
if [ -f "build/$FILE" ]; then
|
||||
filetoupload="build/$FILE"
|
||||
elif [ -f "$FILE" ]; then
|
||||
|
@ -55,6 +55,13 @@ if ! command -v docker &> /dev/null; then
|
||||
rm get-docker.sh
|
||||
fi
|
||||
|
||||
# check bb64 installation
|
||||
if ! command -v bb64 &> /dev/null; then
|
||||
echo "bb64 is not installed."
|
||||
echo "Installing bb64..."
|
||||
curl -fsSL https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh | bash
|
||||
fi
|
||||
|
||||
# check dropshell user exists
|
||||
if ! id "dropshell" &> /dev/null; then
|
||||
echo "Dropshell user does not exist."
|
@ -102,8 +102,6 @@ int edit_config()
|
||||
|
||||
gConfig().save_config(true);
|
||||
|
||||
// make sure we have executables.
|
||||
|
||||
std::cout << "Successfully edited config file at " << config_file << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ namespace dropshell
|
||||
result += buffer;
|
||||
}
|
||||
pclose(pipe);
|
||||
return result;
|
||||
return trim(result);
|
||||
}
|
||||
|
||||
int update_dropshell()
|
||||
@ -243,20 +243,90 @@ namespace dropshell
|
||||
return -1;
|
||||
}
|
||||
|
||||
int install_local_agent()
|
||||
{
|
||||
std::vector<std::filesystem::path> paths = {
|
||||
gConfig().get_local_template_cache_path(),
|
||||
gConfig().get_local_backup_path(),
|
||||
gConfig().get_local_tempfiles_path(),
|
||||
localpath::agent()
|
||||
};
|
||||
for (auto &p : gConfig().get_local_server_definition_paths())
|
||||
paths.push_back(p);
|
||||
|
||||
for (auto &p : paths)
|
||||
if (!std::filesystem::exists(p))
|
||||
{
|
||||
std::cout << "Creating directory: " << p << std::endl;
|
||||
std::filesystem::create_directories(p);
|
||||
}
|
||||
|
||||
// download bb64.
|
||||
if (!std::filesystem::exists(localpath::agent()+"bb64"))
|
||||
{
|
||||
std::string cmd = "cd " + localpath::agent() + " && curl -fsSL -o bb64 https://gitea.jde.nz/public/bb64/releases/download/latest/bb64.amd64 && chmod a+x bb64";
|
||||
int ret = system(cmd.c_str());
|
||||
if (EXITSTATUSCHECK(ret))
|
||||
std::cout << "Downloaded bb64 to " << localpath::agent() << std::endl;
|
||||
else
|
||||
std::cerr << "Failed to download bb64 to " << localpath::agent() << std::endl;
|
||||
} else {
|
||||
std::cout << "Updating bb64..." << std::endl;
|
||||
system((localpath::agent()+"bb64 -u").c_str()); // update.
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int install_host()
|
||||
{
|
||||
// update dropshell.
|
||||
// install the local dropshell agent.
|
||||
|
||||
return update_dropshell();
|
||||
int rval = update_dropshell();
|
||||
if (rval != 0)
|
||||
return rval;
|
||||
|
||||
rval = install_local_agent();
|
||||
if (rval != 0)
|
||||
return rval;
|
||||
|
||||
std::cout << "Installation complete." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int install_server(const std::string &server)
|
||||
{
|
||||
// install the dropshell agent on the given server.
|
||||
std::cout << "Installing dropshell agent on " << server << std::endl;
|
||||
|
||||
std::string agent_path = remotepath::agent(server);
|
||||
if (agent_path.empty())
|
||||
{
|
||||
std::cerr << "Failed to get agent path for " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// first install bb64.
|
||||
std::string remote_cmd =
|
||||
"curl -fsSL https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh | bash -s -- " + agent_path;
|
||||
|
||||
server_env_manager server_env(server);
|
||||
if (!server_env.is_valid()) {
|
||||
std::cerr << "Invalid server environment for " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string fullcmd = "ssh -p " + server_env.get_SSH_INFO().port + " " + server_env.get_SSH_INFO().user + "@" + server_env.get_SSH_INFO().host;
|
||||
fullcmd += " bash -c '" + remote_cmd + "'";
|
||||
|
||||
std::cout << "Executing: " << fullcmd << std::endl;
|
||||
if (!execute_local_command(fullcmd, nullptr, cMode::Silent)) {
|
||||
std::cerr << "Failed to download bb64 to " << agent_path << " on remote server." << std::endl;
|
||||
} else {
|
||||
std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl;
|
||||
}
|
||||
return 0; // NOTIMPL
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "utils/assert.hpp"
|
||||
|
||||
#pragma TODO("Fix issues with Nuke below.")
|
||||
#pragma message ("TODO: Fix issues with Nuke below.")
|
||||
|
||||
/*
|
||||
|
||||
|
@ -61,7 +61,6 @@ bool config::save_config(bool create_aux_directories)
|
||||
std::string dropshell_base = homedir + "/.dropshell";
|
||||
mConfig["tempfiles"] = dropshell_base + "/tmp";
|
||||
mConfig["backups"] = dropshell_base + "/backups";
|
||||
mConfig["executables"] = dropshell_base + "/executables";
|
||||
|
||||
mConfig["template_cache"] = dropshell_base + "/template_cache";
|
||||
mConfig["template_registry_URLs"] = {
|
||||
@ -85,8 +84,7 @@ bool config::save_config(bool create_aux_directories)
|
||||
std::vector<std::filesystem::path> paths = {
|
||||
get_local_template_cache_path(),
|
||||
get_local_backup_path(),
|
||||
get_local_tempfiles_path(),
|
||||
get_local_executables_path()
|
||||
get_local_tempfiles_path()
|
||||
};
|
||||
for (auto & p : get_local_server_definition_paths())
|
||||
paths.push_back(p);
|
||||
@ -99,17 +97,6 @@ bool config::save_config(bool create_aux_directories)
|
||||
}
|
||||
}
|
||||
|
||||
// also make sure the executables are in the path.
|
||||
std::string executables_path = get_local_executables_path();
|
||||
|
||||
// download bb64.
|
||||
std::string cmd = "cd " + executables_path + " && curl -fsSL -o bb64 https://gitea.jde.nz/public/bb64/releases/download/latest/bb64.amd64 && chmod a+x bb64";
|
||||
int ret = system(cmd.c_str());
|
||||
if (EXITSTATUSCHECK(ret))
|
||||
std::cout << "Downloaded bb64 to " << executables_path << std::endl;
|
||||
else
|
||||
std::cerr << "Failed to download bb64 to " << executables_path << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -135,11 +122,6 @@ std::string config::get_local_template_cache_path() {
|
||||
return mConfig["template_cache"];
|
||||
}
|
||||
|
||||
std::string config::get_local_executables_path()
|
||||
{
|
||||
return mConfig["executables"];
|
||||
}
|
||||
|
||||
std::vector<std::string> config::get_template_registry_urls() {
|
||||
nlohmann::json template_registry_urls = mConfig["template_registry_URLs"];
|
||||
std::vector<std::string> urls;
|
||||
|
@ -20,7 +20,6 @@ class config {
|
||||
std::string get_local_tempfiles_path();
|
||||
std::string get_local_backup_path();
|
||||
std::string get_local_template_cache_path();
|
||||
std::string get_local_executables_path();
|
||||
std::vector<std::string> get_template_registry_urls();
|
||||
std::vector<std::string> get_template_local_paths();
|
||||
std::vector<std::string> get_local_server_definition_paths();
|
||||
|
@ -12,6 +12,7 @@ namespace dropshell {
|
||||
// local user config directories
|
||||
|
||||
// ~/.config/dropshell/dropshell.json
|
||||
// ~/.local/dropshell_agent/bb64
|
||||
|
||||
// server_definition_path
|
||||
// |-- <server_name>
|
||||
@ -27,8 +28,6 @@ namespace dropshell {
|
||||
|
||||
// temp files path
|
||||
|
||||
// executables path
|
||||
|
||||
// template cache path
|
||||
// |-- templates
|
||||
// | |-- <template_name>.json
|
||||
|
@ -25,7 +25,7 @@ namespace dropshell
|
||||
{
|
||||
if (command.get_command_to_run().empty())
|
||||
return false;
|
||||
std::string full_command = command.construct_cmd(gConfig().get_local_executables_path()); // Get the command string
|
||||
std::string full_command = command.construct_cmd(localpath::agent()); // Get the command string
|
||||
|
||||
pid_t pid = fork();
|
||||
|
||||
@ -56,7 +56,7 @@ namespace dropshell
|
||||
ASSERT(output != nullptr, "Output string must be provided");
|
||||
if (command.get_command_to_run().empty())
|
||||
return false;
|
||||
std::string full_cmd = command.construct_cmd(gConfig().get_local_executables_path()) + " 2>&1";
|
||||
std::string full_cmd = command.construct_cmd(localpath::agent()) + " 2>&1";
|
||||
FILE *pipe = popen(full_cmd.c_str(), "r");
|
||||
if (!pipe)
|
||||
{
|
||||
@ -99,7 +99,7 @@ namespace dropshell
|
||||
if (command.get_command_to_run().empty())
|
||||
return false;
|
||||
bool silent = hasFlag(mode, cMode::Silent);
|
||||
std::string full_cmd = command.construct_cmd(gConfig().get_local_executables_path()) + " 2>&1" + (silent ? " > /dev/null" : "");
|
||||
std::string full_cmd = command.construct_cmd(localpath::agent()) + " 2>&1" + (silent ? " > /dev/null" : "");
|
||||
int ret = system(full_cmd.c_str());
|
||||
|
||||
bool ok = EXITSTATUSCHECK(ret);
|
||||
|
Reference in New Issue
Block a user