|
|
|
@ -1,54 +1,54 @@
|
|
|
|
|
/*
|
|
|
|
|
dropshell-tool
|
|
|
|
|
getpkg
|
|
|
|
|
|
|
|
|
|
dropshell-tool install <tool_name>
|
|
|
|
|
- confirms dropshell-tool is fully initialised:
|
|
|
|
|
- adds a line to the user's .bashrc file to source the dropshell-tool ~/.bashrc_dropshell_tool script, if it doesn't exist
|
|
|
|
|
getpkg <tool_name>
|
|
|
|
|
- confirms getpkg is fully initialised:
|
|
|
|
|
- adds a line to the user's .bashrc file to source the getpkg ~/.bashrc_dropshell_tool script, if it doesn't exist
|
|
|
|
|
- creates an empty ~/.bashrc_dropshell_tool script if it doesn't exist
|
|
|
|
|
- creates the ~/.config/dropshell-tool directory, if it does not exist
|
|
|
|
|
- creates the ~/.local/bin/dropshell-tool directory, if it does not exist
|
|
|
|
|
- creates the ~/.config/getpkg directory, if it does not exist
|
|
|
|
|
- creates the ~/.local/bin/getpkg directory, if it does not exist
|
|
|
|
|
|
|
|
|
|
- removes the tool from the user's system if it is already installed, and the tool's entries in the ~/.bashrc_dropshell_tool script
|
|
|
|
|
- downloads the tool archive (tgz) from tools.dropshell.app (tool_name:ARCH), where ARCH is the architecture of the user's system, and unpacks it to the new tool directory: ~/.local/bin/dropshell-tool/<tool_name>/
|
|
|
|
|
- downloads the tool archive (tgz) from tools.dropshell.app (tool_name:ARCH), where ARCH is the architecture of the user's system, and unpacks it to the new tool directory: ~/.local/bin/getpkg/<tool_name>/
|
|
|
|
|
- sets the PATH to include the tool directory, by modifying the ~/.bashrc_dropshell_tool script
|
|
|
|
|
- adds an entry for autocompletion for the tool to the ~/.bashrc_dropshell_tool script, where autocomplete just runs <tool_name> autocomplete <args>
|
|
|
|
|
- creates a ~/.config/dropshell-tool/tool_name.json file, which contains the tool's name, version (by running <tool_name> version), hash from tools.dropshell.app, and architecture
|
|
|
|
|
- reads the json file from the tgz called dropshell-tool-config.json:
|
|
|
|
|
- creates a ~/.config/getpkg/tool_name.json file, which contains the tool's name, version (by running <tool_name> version), hash from tools.dropshell.app, and architecture
|
|
|
|
|
- reads the json file from the tgz called getpkg-config.json:
|
|
|
|
|
- for each alias in the aliases array:
|
|
|
|
|
- check if another command is using the alias, and continue only if not
|
|
|
|
|
- check that the alias is not already in the ~/.bashrc_dropshell_tool script and continue only if not
|
|
|
|
|
- add an entry to the ~/.bashrc_dropshell_tool script to run the tool via the alias
|
|
|
|
|
- if the json file has a setup_script entry, run the script named in the entry in the tool directory - using sudo if the entry has sudo set to true.
|
|
|
|
|
|
|
|
|
|
dropshell-tool publish <tool_name:ARCH> <folder>
|
|
|
|
|
- checks that dropshell-tool-config.json exists in the folder, and is valid (see above)
|
|
|
|
|
getpkg publish <tool_name:ARCH> <folder>
|
|
|
|
|
- checks that getpkg-config.json exists in the folder, and is valid (see above)
|
|
|
|
|
- creates a tgz archive of the folder, and uploads it to tools.dropshell.app, a simple object server.
|
|
|
|
|
- prints the URL and hash of the uploaded archive
|
|
|
|
|
- uses the token from env variable SOS_WRITE_TOKEN to write to tools.dropshell.app
|
|
|
|
|
|
|
|
|
|
dropshell-tool update <tool_name>
|
|
|
|
|
- compares the hash from the ~/.config/dropshell-tool/tool_name.json file with the hash from tools.dropshell.app (tool_name:ARCH), and continues only if they are different
|
|
|
|
|
- checks the version from the ~/.config/dropshell-tool/tool_name.json file with the version from tools.dropshell.app (tool_name:ARCH), and continues only if the remote version is newer (installed is older)
|
|
|
|
|
getpkg update <tool_name>
|
|
|
|
|
- compares the hash from the ~/.config/getpkg/tool_name.json file with the hash from tools.dropshell.app (tool_name:ARCH), and continues only if they are different
|
|
|
|
|
- checks the version from the ~/.config/getpkg/tool_name.json file with the version from tools.dropshell.app (tool_name:ARCH), and continues only if the remote version is newer (installed is older)
|
|
|
|
|
- installs the tool as per the install command
|
|
|
|
|
|
|
|
|
|
dropshell-tool update all
|
|
|
|
|
getpkg update all
|
|
|
|
|
- runs update on all installed tools
|
|
|
|
|
|
|
|
|
|
dropshell-tool autocomplete <args>
|
|
|
|
|
- shows autocomplete for dropshell-tool, and then exits
|
|
|
|
|
getpkg autocomplete <args>
|
|
|
|
|
- shows autocomplete for getpkg, and then exits
|
|
|
|
|
- the tool list to choose from when calling install is hard coded in the autocomplete function
|
|
|
|
|
|
|
|
|
|
dropshell-tool version
|
|
|
|
|
- prints the version of dropshell-tool
|
|
|
|
|
getpkg version
|
|
|
|
|
- prints the version of getpkg
|
|
|
|
|
|
|
|
|
|
dropshell-tool create <tool_name> <directory_name>
|
|
|
|
|
getpkg create <tool_name> <directory_name>
|
|
|
|
|
- creates a new tool source directory in relative path <directory_name> if it doesn't exist
|
|
|
|
|
- creates a dropshell-tool-config.json file in the tool source directory if it doesn't exist, with the following entries:
|
|
|
|
|
- creates a getpkg-config.json file in the tool source directory if it doesn't exist, with the following entries:
|
|
|
|
|
- aliases: an array of aliases for the tool
|
|
|
|
|
- setup_script: the name of the setup script to run (setup_script.sh)
|
|
|
|
|
- creates a setup_script.sh file in the tool source directory if it doesn't exist, that just prints a completion message and exits
|
|
|
|
|
|
|
|
|
|
dropshell-tool help
|
|
|
|
|
getpkg help
|
|
|
|
|
- shows this help message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -85,14 +85,14 @@ std::string get_home() {
|
|
|
|
|
|
|
|
|
|
int install_tool(int argc, char* argv[]) {
|
|
|
|
|
if (argc < 3) {
|
|
|
|
|
std::cerr << "Usage: dropshell-tool install <tool_name>" << std::endl;
|
|
|
|
|
std::cerr << "Usage: getpkg install <tool_name>" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
std::string toolName = argv[2];
|
|
|
|
|
std::string arch = get_arch();
|
|
|
|
|
std::string home = get_home();
|
|
|
|
|
std::filesystem::path configDir = std::filesystem::path(home) / ".config/dropshell-tool";
|
|
|
|
|
std::filesystem::path binDir = std::filesystem::path(home) / ".local/bin/dropshell-tool" / toolName;
|
|
|
|
|
std::filesystem::path configDir = std::filesystem::path(home) / ".config/getpkg";
|
|
|
|
|
std::filesystem::path binDir = std::filesystem::path(home) / ".local/bin/getpkg" / toolName;
|
|
|
|
|
std::filesystem::path archivePath = configDir / (toolName + ".tgz");
|
|
|
|
|
std::filesystem::create_directories(configDir);
|
|
|
|
|
std::filesystem::create_directories(binDir);
|
|
|
|
@ -153,7 +153,7 @@ int install_tool(int argc, char* argv[]) {
|
|
|
|
|
std::system(cmd.c_str());
|
|
|
|
|
}
|
|
|
|
|
} catch (...) {
|
|
|
|
|
std::cerr << "Warning: failed to parse dropshell-tool-config.json" << std::endl;
|
|
|
|
|
std::cerr << "Warning: failed to parse getpkg-config.json" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::cout << "Installed " << toolName << " successfully." << std::endl;
|
|
|
|
@ -162,15 +162,15 @@ int install_tool(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
|
|
int publish_tool(int argc, char* argv[]) {
|
|
|
|
|
if (argc < 4) {
|
|
|
|
|
std::cerr << "Usage: dropshell-tool publish <tool_name:ARCH> <folder>" << std::endl;
|
|
|
|
|
std::cerr << "Usage: getpkg publish <tool_name:ARCH> <folder>" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
std::string labeltag = argv[2];
|
|
|
|
|
std::string folder = argv[3];
|
|
|
|
|
std::string home = get_home();
|
|
|
|
|
std::filesystem::path configPath = std::filesystem::path(folder) / "dropshell-tool-config.json";
|
|
|
|
|
std::filesystem::path configPath = std::filesystem::path(folder) / "getpkg-config.json";
|
|
|
|
|
if (!std::filesystem::exists(configPath)) {
|
|
|
|
|
std::cerr << "dropshell-tool-config.json not found in " << folder << std::endl;
|
|
|
|
|
std::cerr << "getpkg-config.json not found in " << folder << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
std::filesystem::path archivePath = std::filesystem::path(home) / ".tmp" / (labeltag + ".tgz");
|
|
|
|
@ -205,12 +205,12 @@ int publish_tool(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
|
|
int update_tool(int argc, char* argv[]) {
|
|
|
|
|
if (argc < 3) {
|
|
|
|
|
std::cerr << "Usage: dropshell-tool update <tool_name|all>" << std::endl;
|
|
|
|
|
std::cerr << "Usage: getpkg update <tool_name|all>" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
std::string toolName = argv[2];
|
|
|
|
|
std::string home = get_home();
|
|
|
|
|
std::filesystem::path configDir = std::filesystem::path(home) / ".config/dropshell-tool";
|
|
|
|
|
std::filesystem::path configDir = std::filesystem::path(home) / ".config/getpkg";
|
|
|
|
|
if (toolName == "all") {
|
|
|
|
|
for (const auto& entry : std::filesystem::directory_iterator(configDir)) {
|
|
|
|
|
if (entry.path().extension() == ".json") {
|
|
|
|
@ -247,7 +247,7 @@ int update_tool(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
|
|
int create_tool(int argc, char* argv[]) {
|
|
|
|
|
if (argc < 4) {
|
|
|
|
|
std::cerr << "Usage: dropshell-tool create <tool_name> <directory_name>" << std::endl;
|
|
|
|
|
std::cerr << "Usage: getpkg create <tool_name> <directory_name>" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
std::string toolName = argv[2];
|
|
|
|
@ -259,7 +259,7 @@ int create_tool(int argc, char* argv[]) {
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "Directory already exists: " << toolDir << std::endl;
|
|
|
|
|
}
|
|
|
|
|
std::filesystem::path configPath = toolDir / "dropshell-tool-config.json";
|
|
|
|
|
std::filesystem::path configPath = toolDir / "getpkg-config.json";
|
|
|
|
|
if (!std::filesystem::exists(configPath)) {
|
|
|
|
|
nlohmann::json config = {
|
|
|
|
|
{"aliases", nlohmann::json::array()},
|
|
|
|
@ -289,7 +289,7 @@ int create_tool(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
if (argc < 2) {
|
|
|
|
|
std::cout << "Usage: dropshell-tool <command> [args...]" << std::endl;
|
|
|
|
|
std::cout << "Usage: getpkg <command> [args...]" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
std::string command = argv[1];
|
|
|
|
@ -313,7 +313,7 @@ help
|
|
|
|
|
} else if (command == "create") {
|
|
|
|
|
return create_tool(argc, argv);
|
|
|
|
|
} else if (command == "help") {
|
|
|
|
|
std::cout << "Usage: dropshell-tool <command> [args...]" << std::endl;
|
|
|
|
|
std::cout << "Usage: getpkg <command> [args...]" << std::endl;
|
|
|
|
|
std::cout << "Commands:" << std::endl;
|
|
|
|
|
std::cout << " install <tool_name>" << std::endl;
|
|
|
|
|
std::cout << " publish <tool_name:ARCH> <folder>" << std::endl;
|
|
|
|
|