Safer uninstall
This commit is contained in:
+96
-41
@@ -327,9 +327,12 @@ void InstallLimits()
|
|||||||
if (!std::filesystem::exists(limitsConfig))
|
if (!std::filesystem::exists(limitsConfig))
|
||||||
{
|
{
|
||||||
ofstream output(limitsConfig);
|
ofstream output(limitsConfig);
|
||||||
output << "# Realtime priority group used by pipedal/jack daemon" << "\n";
|
output << "# Realtime priority group used by pipedal/jack daemon"
|
||||||
output << "@audio - rtprio 95" << "\n";
|
<< "\n";
|
||||||
output << "@audio - memlock unlimited" << "\n";
|
output << "@audio - rtprio 95"
|
||||||
|
<< "\n";
|
||||||
|
output << "@audio - memlock unlimited"
|
||||||
|
<< "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,6 +412,8 @@ int SudoExec(char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Uninstall()
|
void Uninstall()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
OnWifiUninstall();
|
OnWifiUninstall();
|
||||||
@@ -419,32 +424,62 @@ void Uninstall()
|
|||||||
silentSysExec(SYSTEMCTL_BIN " disable jack");
|
silentSysExec(SYSTEMCTL_BIN " disable jack");
|
||||||
OnWifiUninstall();
|
OnWifiUninstall();
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
std::filesystem::remove("/usr/bin/systemd/system/" OLD_SHUTDOWN_SERVICE ".service");
|
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");
|
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");
|
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");
|
std::filesystem::remove("/usr/bin/systemd/system/" NATIVE_SERVICE ".service");
|
||||||
} catch (...) {}
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
std::filesystem::remove("/usr/bin/systemd/system/" JACK_SERVICE ".service");
|
std::filesystem::remove("/usr/bin/systemd/system/" JACK_SERVICE ".service");
|
||||||
} catch (...) {}
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
UninstallPamEnv();
|
UninstallPamEnv();
|
||||||
UninstallLimits();
|
UninstallLimits();
|
||||||
sysExec(SYSTEMCTL_BIN " daemon-reload");
|
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::random_device randdev;
|
||||||
|
|
||||||
|
|
||||||
std::string MakeUuid()
|
std::string MakeUuid()
|
||||||
{
|
{
|
||||||
uuid_t uuid;
|
uuid_t uuid;
|
||||||
@@ -467,11 +502,16 @@ static std::string RandomChars(int nchars)
|
|||||||
if (v < 10)
|
if (v < 10)
|
||||||
{
|
{
|
||||||
c = (char)('0' + v);
|
c = (char)('0' + v);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
v -= 10;
|
v -= 10;
|
||||||
if (v < 26) {
|
if (v < 26)
|
||||||
|
{
|
||||||
c = (char)('a' + v);
|
c = (char)('a' + v);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
v -= 26;
|
v -= 26;
|
||||||
c = (char)('A' + v);
|
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;
|
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");
|
sysExec(SYSTEMCTL_BIN " daemon-reload");
|
||||||
|
|
||||||
cout << "Starting services" << "\n";
|
cout << "Starting services"
|
||||||
|
<< "\n";
|
||||||
RestartService(false);
|
RestartService(false);
|
||||||
EnableService();
|
EnableService();
|
||||||
|
|
||||||
|
cout << "Complete"
|
||||||
cout << "Complete" << "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PrintHelp()
|
static void PrintHelp()
|
||||||
{
|
{
|
||||||
PrettyPrinter pp;
|
PrettyPrinter pp;
|
||||||
pp << "pipedalconfig - Command-line post-install configuration for PiPedal" << "\n"
|
pp << "pipedalconfig - Command-line post-install configuration for PiPedal"
|
||||||
<< "Copyright (c) 2022 Robin Davies. All rights reserved." << "\n"
|
<< "\n"
|
||||||
|
<< "Copyright (c) 2022 Robin Davies. All rights reserved."
|
||||||
|
<< "\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "See https://rerdavies.github.io/pipedal/Documentation.html for "
|
<< "See https://rerdavies.github.io/pipedal/Documentation.html for "
|
||||||
<< "online documentation." << "\n"
|
<< "online documentation."
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "Syntax:" << "\n";
|
<< "\n"
|
||||||
|
<< "Syntax:"
|
||||||
|
<< "\n";
|
||||||
pp << Indent(4)
|
pp << Indent(4)
|
||||||
<< "pipedalconfig [Options...]" << "\n"
|
<< "pipedalconfig [Options...]"
|
||||||
|
<< "\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
pp.Indent(0)
|
pp.Indent(0)
|
||||||
<< "Options: " << "\n\n";
|
<< "Options: "
|
||||||
|
<< "\n\n";
|
||||||
pp.Indent(20);
|
pp.Indent(20);
|
||||||
|
|
||||||
pp
|
pp
|
||||||
<< HangingIndent() << " -h --help\t"
|
<< HangingIndent() << " -h --help\t"
|
||||||
<< "Display this message." << "\n"
|
<< "Display this message."
|
||||||
|
<< "\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
|
|
||||||
<< HangingIndent() << " --install [--port <port#>]\t"
|
<< HangingIndent() << " --install [--port <port#>]\t"
|
||||||
<< "Install or re-install services and service accounts." << "\n"
|
<< "Install or re-install services and service accounts."
|
||||||
|
<< "\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "The --port option controls which port the web server uses."
|
<< "The --port option controls which port the web server uses."
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
|
|
||||||
<< HangingIndent() << " --uninstall\t"
|
<< HangingIndent() << " --uninstall\t"
|
||||||
<< "Remove installed services." << "\n"
|
<< "Remove installed services."
|
||||||
|
<< "\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
|
|
||||||
<< HangingIndent() << " --enable\t"
|
<< HangingIndent() << " --enable\t"
|
||||||
<< "Start the pipedal service at boot time." << "\n"
|
<< "Start the pipedal service at boot time."
|
||||||
|
<< "\n"
|
||||||
<< "\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"
|
<< "\n"
|
||||||
<< HangingIndent() << " --start\tStart the pipedal services." << "\n"
|
|
||||||
<< "\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"
|
<< "\n"
|
||||||
<< HangingIndent() << " --restart\tRestart the pipedal services." << "\n"
|
|
||||||
<< "\n"
|
<< "\n"
|
||||||
|
|
||||||
<< HangingIndent() << " --enable-p2p [<country_code> <ssid> [[<pin>] <channel>] ]\t"
|
<< 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."
|
<< "With no additional arguments, the P2P channel is enabled with most-recent settings."
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
<< "<country_code> is the 2-letter ISO-3166 country code for "
|
<< "<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."
|
<< HangingIndent() << " --disable-legacy-ap\tDisabled the legacy Wi-Fi access point."
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
|
|
||||||
|
|
||||||
<< Indent(0) << "Country codes:"
|
<< Indent(0) << "Country codes:"
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
<< Indent(4)
|
<< Indent(4)
|
||||||
@@ -784,8 +840,7 @@ static void PrintHelp()
|
|||||||
"Wi-Fi connection is active."
|
"Wi-Fi connection is active."
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"Wi-Fi Direct connections are "
|
"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)
|
int main(int argc, char **argv)
|
||||||
@@ -863,7 +918,8 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (portOption.size() != 0 && !install)
|
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);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -953,7 +1009,6 @@ int main(int argc, char **argv)
|
|||||||
settings.enable_ = true;
|
settings.enable_ = true;
|
||||||
SetWifiDirectConfig(settings);
|
SetWifiDirectConfig(settings);
|
||||||
RestartService(true); // also have to retart web service so that it gets the correct device name.
|
RestartService(true); // also have to retart web service so that it gets the correct device name.
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (disable_p2p)
|
else if (disable_p2p)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user