Safer uninstall

This commit is contained in:
Robin Davies
2022-04-28 19:08:38 -04:00
parent c30bda9c77
commit 179ff9c276
+96 -41
View File
@@ -327,9 +327,12 @@ void InstallLimits()
if (!std::filesystem::exists(limitsConfig))
{
ofstream output(limitsConfig);
output << "# Realtime priority group used by pipedal/jack daemon" << "\n";
output << "@audio - rtprio 95" << "\n";
output << "@audio - memlock unlimited" << "\n";
output << "# Realtime priority group used by pipedal/jack daemon"
<< "\n";
output << "@audio - rtprio 95"
<< "\n";
output << "@audio - memlock unlimited"
<< "\n";
}
}
@@ -409,6 +412,8 @@ int SudoExec(char **argv)
}
void Uninstall()
{
try
{
OnWifiUninstall();
@@ -419,32 +424,62 @@ void Uninstall()
silentSysExec(SYSTEMCTL_BIN " disable jack");
OnWifiUninstall();
try {
try
{
std::filesystem::remove("/usr/bin/systemd/system/" OLD_SHUTDOWN_SERVICE ".service");
} catch (...) {}
}
catch (...)
{
}
try {
try
{
std::filesystem::remove("/usr/bin/systemd/system/" ADMIN_SERVICE ".service");
} catch (...) {}
try {
}
catch (...)
{
}
try
{
std::filesystem::remove("/usr/bin/systemd/system/" PIPEDAL_P2PD_SERVICE ".service");
} catch (...) {}
}
catch (...)
{
}
try {
try
{
std::filesystem::remove("/usr/bin/systemd/system/" NATIVE_SERVICE ".service");
} catch (...) {}
}
catch (...)
{
}
try {
try
{
std::filesystem::remove("/usr/bin/systemd/system/" JACK_SERVICE ".service");
} catch (...) {}
}
catch (...)
{
}
UninstallPamEnv();
UninstallLimits();
sysExec(SYSTEMCTL_BIN " daemon-reload");
}
catch (const std::exception &e)
{
// We should NEVER get here. But the consequences of failure are high (causes permanent apt installs/uninstall problems), so be safe.
cout << "ERROR: Unexpected error while uninstalling pipedal. (" << e.what() << ")" << endl;
}
catch (...)
{
// We should NEVER get here. But the consequences of failure are high (causes permanent apt installs/uninstall problems), so be safe.
cout << "ERROR: Unexpected error while uninstalling pipedal." << endl;
}
}
std::random_device randdev;
std::string MakeUuid()
{
uuid_t uuid;
@@ -467,11 +502,16 @@ static std::string RandomChars(int nchars)
if (v < 10)
{
c = (char)('0' + v);
} else {
}
else
{
v -= 10;
if (v < 26) {
if (v < 26)
{
c = (char)('a' + v);
} else {
}
else
{
v -= 26;
c = (char)('A' + v);
}
@@ -611,7 +651,8 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
}
}
cout << "Creating Systemd file." << "\n";
cout << "Creating Systemd file."
<< "\n";
std::map<string, string> map;
@@ -655,61 +696,77 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
sysExec(SYSTEMCTL_BIN " daemon-reload");
cout << "Starting services" << "\n";
cout << "Starting services"
<< "\n";
RestartService(false);
EnableService();
cout << "Complete" << "\n";
cout << "Complete"
<< "\n";
}
static void PrintHelp()
{
PrettyPrinter pp;
pp << "pipedalconfig - Command-line post-install configuration for PiPedal" << "\n"
<< "Copyright (c) 2022 Robin Davies. All rights reserved." << "\n"
pp << "pipedalconfig - Command-line post-install configuration for PiPedal"
<< "\n"
<< "Copyright (c) 2022 Robin Davies. All rights reserved."
<< "\n"
<< "\n"
<< "See https://rerdavies.github.io/pipedal/Documentation.html for "
<< "online documentation." << "\n"
<< "online documentation."
<< "\n"
<< "Syntax:" << "\n";
<< "\n"
<< "Syntax:"
<< "\n";
pp << Indent(4)
<< "pipedalconfig [Options...]" << "\n"
<< "pipedalconfig [Options...]"
<< "\n"
<< "\n";
pp.Indent(0)
<< "Options: " << "\n\n";
<< "Options: "
<< "\n\n";
pp.Indent(20);
pp
<< HangingIndent() << " -h --help\t"
<< "Display this message." << "\n"
<< "Display this message."
<< "\n"
<< "\n"
<< HangingIndent() << " --install [--port <port#>]\t"
<< "Install or re-install services and service accounts." << "\n"
<< "Install or re-install services and service accounts."
<< "\n"
<< "\n"
<< "The --port option controls which port the web server uses."
<< "\n\n"
<< HangingIndent() << " --uninstall\t"
<< "Remove installed services." << "\n"
<< "Remove installed services."
<< "\n"
<< "\n"
<< HangingIndent() << " --enable\t"
<< "Start the pipedal service at boot time." << "\n"
<< "Start the pipedal service at boot time."
<< "\n"
<< "\n"
<< HangingIndent() << " --disable\tDo not start the pipedal service at boot time." << "\n"
<< HangingIndent() << " --disable\tDo not start the pipedal service at boot time."
<< "\n"
<< HangingIndent() << " --start\tStart the pipedal services." << "\n"
<< "\n"
<< HangingIndent() << " --stop\tStop the pipedal services." << "\n"
<< HangingIndent() << " --start\tStart the pipedal services."
<< "\n"
<< "\n"
<< HangingIndent() << " --stop\tStop the pipedal services."
<< "\n"
<< "\n"
<< HangingIndent() << " --restart\tRestart the pipedal services."
<< "\n"
<< HangingIndent() << " --restart\tRestart the pipedal services." << "\n"
<< "\n"
<< HangingIndent() << " --enable-p2p [<country_code> <ssid> [[<pin>] <channel>] ]\t"
<< "Enable the P2P (Wi-Fi Direct) hotspot." << "\n\n"
<< "Enable the P2P (Wi-Fi Direct) hotspot."
<< "\n\n"
<< "With no additional arguments, the P2P channel is enabled with most-recent settings."
<< "\n\n"
<< "<country_code> is the 2-letter ISO-3166 country code for "
@@ -751,7 +808,6 @@ static void PrintHelp()
<< HangingIndent() << " --disable-legacy-ap\tDisabled the legacy Wi-Fi access point."
<< "\n\n"
<< Indent(0) << "Country codes:"
<< "\n\n"
<< Indent(4)
@@ -784,8 +840,7 @@ static void PrintHelp()
"Wi-Fi connection is active."
"\n\n"
"Wi-Fi Direct connections are "
"therefore preferrable under almost all circumstances.\n\n"
;
"therefore preferrable under almost all circumstances.\n\n";
}
int main(int argc, char **argv)
@@ -863,7 +918,8 @@ int main(int argc, char **argv)
}
if (portOption.size() != 0 && !install)
{
cout << "Error: -port option can only be specified with the -install option." << "\n";
cout << "Error: -port option can only be specified with the -install option."
<< "\n";
exit(EXIT_FAILURE);
}
@@ -953,7 +1009,6 @@ int main(int argc, char **argv)
settings.enable_ = true;
SetWifiDirectConfig(settings);
RestartService(true); // also have to retart web service so that it gets the correct device name.
}
else if (disable_p2p)
{