uninstall!

This commit is contained in:
Your Name
2025-04-25 12:08:37 +12:00
parent 61fabac1f0
commit ed8bc0dca6
6 changed files with 100 additions and 9 deletions

View File

@ -30,6 +30,7 @@ void print_help() {
std::cout << std::endl;
std::cout << " install SERVER [SERVICE] Install/Update service(s)." << std::endl;
std::cout << " backup SERVER [SERVICE] Backup service(s)." << std::endl;
std::cout << " uninstall SERVER [SERVICE] Uninstall service(s)." << std::endl;
std::cout << " COMMAND SERVER [SERVICE] Run a custom command on service(s)." << std::endl;
std::cout << std::endl;
}
@ -120,7 +121,7 @@ int main(int argc, char* argv[]) {
commands.insert("init");
if (cfg->is_config_set())
commands.merge(std::set<std::string>{
"servers","templates","install","backup"
"servers","templates","install","uninstall","backup"
});
for (const auto& command : commands) {
@ -181,11 +182,11 @@ int main(int argc, char* argv[]) {
return 0;
}
if (cmd == "install") {
if (cmd == "install" || cmd == "uninstall") {
std::string server_name;
std::vector<dropshell::ServiceInfo> servicelist;
if (!parseargs(safearg(argc, argv, 2), safearg(argc, argv, 3), server_name, servicelist)) {
std::cerr << "Error: install command requires server name and optionally service name" << std::endl;
std::cerr << "Error: " << cmd << " command requires server name and optionally service name" << std::endl;
return 1;
}
for (const auto& service_info : servicelist) {
@ -194,9 +195,9 @@ int main(int argc, char* argv[]) {
std::cerr << "Error: Failed to initialize service" << std::endl;
return 1;
}
if (!service.install()) {
std::cerr << "Error: Failed to install service" << std::endl;
bool success = ((cmd=="install") ? service.install() : service.uninstall());
if (!success) {
std::cerr << "Error: Failed to " << cmd << " service" << std::endl;
return 1;
}
}