Safer uninstall
This commit is contained in:
+195
-140
@@ -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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,41 +413,73 @@ int SudoExec(char **argv)
|
|||||||
|
|
||||||
void Uninstall()
|
void Uninstall()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
OnWifiUninstall();
|
OnWifiUninstall();
|
||||||
|
|
||||||
StopService();
|
StopService();
|
||||||
DisableService();
|
DisableService();
|
||||||
silentSysExec(SYSTEMCTL_BIN " stop jack");
|
silentSysExec(SYSTEMCTL_BIN " stop jack");
|
||||||
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");
|
{
|
||||||
} catch (...) {}
|
std::filesystem::remove("/usr/bin/systemd/system/" OLD_SHUTDOWN_SERVICE ".service");
|
||||||
|
}
|
||||||
try {
|
catch (...)
|
||||||
std::filesystem::remove("/usr/bin/systemd/system/" ADMIN_SERVICE ".service");
|
{
|
||||||
} catch (...) {}
|
}
|
||||||
try {
|
|
||||||
std::filesystem::remove("/usr/bin/systemd/system/" PIPEDAL_P2PD_SERVICE ".service");
|
|
||||||
} catch (...) {}
|
|
||||||
|
|
||||||
try {
|
try
|
||||||
std::filesystem::remove("/usr/bin/systemd/system/" NATIVE_SERVICE ".service");
|
{
|
||||||
} catch (...) {}
|
std::filesystem::remove("/usr/bin/systemd/system/" ADMIN_SERVICE ".service");
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::filesystem::remove("/usr/bin/systemd/system/" PIPEDAL_P2PD_SERVICE ".service");
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try
|
||||||
std::filesystem::remove("/usr/bin/systemd/system/" JACK_SERVICE ".service");
|
{
|
||||||
} catch (...) {}
|
std::filesystem::remove("/usr/bin/systemd/system/" NATIVE_SERVICE ".service");
|
||||||
UninstallPamEnv();
|
}
|
||||||
UninstallLimits();
|
catch (...)
|
||||||
sysExec(SYSTEMCTL_BIN " daemon-reload");
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::filesystem::remove("/usr/bin/systemd/system/" JACK_SERVICE ".service");
|
||||||
|
}
|
||||||
|
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::random_device randdev;
|
||||||
|
|
||||||
|
|
||||||
std::string MakeUuid()
|
std::string MakeUuid()
|
||||||
{
|
{
|
||||||
uuid_t uuid;
|
uuid_t uuid;
|
||||||
@@ -458,7 +493,7 @@ static std::string RandomChars(int nchars)
|
|||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
|
||||||
std::uniform_int_distribution distr(0,26+26+10-1);
|
std::uniform_int_distribution distr(0, 26 + 26 + 10 - 1);
|
||||||
|
|
||||||
for (int i = 0; i < nchars; ++i)
|
for (int i = 0; i < nchars; ++i)
|
||||||
{
|
{
|
||||||
@@ -467,13 +502,18 @@ 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);
|
{
|
||||||
} else {
|
c = (char)('a' + v);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
v -= 26;
|
v -= 26;
|
||||||
c = (char)('A'+v);
|
c = (char)('A' + v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s << c;
|
s << c;
|
||||||
@@ -499,7 +539,7 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
|
|||||||
{
|
{
|
||||||
throw PiPedalException("Failed to create audio service group.");
|
throw PiPedalException("Failed to create audio service group.");
|
||||||
}
|
}
|
||||||
|
|
||||||
PrepareDeviceidFile();
|
PrepareDeviceidFile();
|
||||||
InstallJackService();
|
InstallJackService();
|
||||||
auto endpos = endpointAddress.find_last_of(':');
|
auto endpos = endpointAddress.find_last_of(':');
|
||||||
@@ -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,137 +696,151 @@ 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"
|
||||||
<< "\n"
|
<< "Copyright (c) 2022 Robin Davies. All rights reserved."
|
||||||
<< "See https://rerdavies.github.io/pipedal/Documentation.html for "
|
<< "\n"
|
||||||
<< "online documentation." << "\n"
|
<< "\n"
|
||||||
<< "\n"
|
<< "See https://rerdavies.github.io/pipedal/Documentation.html for "
|
||||||
<< "Syntax:" << "\n";
|
<< "online documentation."
|
||||||
pp << Indent(4)
|
<< "\n"
|
||||||
<< "pipedalconfig [Options...]" << "\n"
|
<< "\n"
|
||||||
<< "\n";
|
<< "Syntax:"
|
||||||
|
<< "\n";
|
||||||
|
pp << Indent(4)
|
||||||
|
<< "pipedalconfig [Options...]"
|
||||||
|
<< "\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"
|
||||||
<< "The --port option controls which port the web server uses."
|
<< "\n"
|
||||||
|
<< "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() << " --start\tStart the pipedal services."
|
||||||
<< HangingIndent() << " --stop\tStop the pipedal services." << "\n"
|
<< "\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< HangingIndent() << " --restart\tRestart the pipedal services." << "\n"
|
<< HangingIndent() << " --stop\tStop the pipedal services."
|
||||||
<< "\n"
|
<< "\n"
|
||||||
|
<< "\n"
|
||||||
|
<< HangingIndent() << " --restart\tRestart the pipedal services."
|
||||||
|
<< "\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."
|
||||||
<< "With no additional arguments, the P2P channel is enabled with most-recent settings."
|
<< "\n\n"
|
||||||
<< "\n\n"
|
<< "With no additional arguments, the P2P channel is enabled with most-recent settings."
|
||||||
<< "<country_code> is the 2-letter ISO-3166 country code for "
|
<< "\n\n"
|
||||||
"the country you are in. see below for further notes."
|
<< "<country_code> is the 2-letter ISO-3166 country code for "
|
||||||
<< "\n\n"
|
"the country you are in. see below for further notes."
|
||||||
<< "<ssid> is the name you see when connecting. "
|
<< "\n\n"
|
||||||
<< "\n\n"
|
<< "<ssid> is the name you see when connecting. "
|
||||||
<< "<pin> is an exactly-eight-digit pin number that you must "
|
<< "\n\n"
|
||||||
<< "enter when connecting to the hotspot. If you don't "
|
<< "<pin> is an exactly-eight-digit pin number that you must "
|
||||||
<< "provide a pin, pipedalconfig will generate and "
|
<< "enter when connecting to the hotspot. If you don't "
|
||||||
<< "display a random pin for you. The pin is a "
|
<< "provide a pin, pipedalconfig will generate and "
|
||||||
<< "so-called \"label\" pin, which is the same every "
|
<< "display a random pin for you. The pin is a "
|
||||||
<< "time you are asked to enter it (unlike a keypad pin "
|
<< "so-called \"label\" pin, which is the same every "
|
||||||
<< "which changes every time you need to enter it."
|
<< "time you are asked to enter it (unlike a keypad pin "
|
||||||
<< "\n\n"
|
<< "which changes every time you need to enter it."
|
||||||
<< "Consider attaching a label to the bottom of your device "
|
<< "\n\n"
|
||||||
<< "so you can can remember the pin if you wan't to connect a new "
|
<< "Consider attaching a label to the bottom of your device "
|
||||||
<< "device to PiPedal. (It's also available on the Settings page of PiPedal, if you have access to PiPedal UI on another device.)"
|
<< "so you can can remember the pin if you wan't to connect a new "
|
||||||
<< "\n\n"
|
<< "device to PiPedal. (It's also available on the Settings page of PiPedal, if you have access to PiPedal UI on another device.)"
|
||||||
<< "For best performance, the channel number should be 1, 6, or 11 (the Wifi Direct \"social\" channels). "
|
<< "\n\n"
|
||||||
<< "Channel number defaults to 1."
|
<< "For best performance, the channel number should be 1, 6, or 11 (the Wifi Direct \"social\" channels). "
|
||||||
<< "\n\n"
|
<< "Channel number defaults to 1."
|
||||||
|
<< "\n\n"
|
||||||
|
|
||||||
<< HangingIndent() << " --disable-p2p\tDisabled Wi-Fi Direct access."
|
<< HangingIndent() << " --disable-p2p\tDisabled Wi-Fi Direct access."
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
|
|
||||||
<< HangingIndent() << " --enable-legacy-ap\t <country_code> <ssid> <wep_password> <channel>\tEnable a legacy Wi-Fi access point."
|
<< HangingIndent() << " --enable-legacy-ap\t <country_code> <ssid> <wep_password> <channel>\tEnable a legacy Wi-Fi access point."
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
<< "Enable a legacy Wi-Fi access point. \n\n"
|
<< "Enable a legacy Wi-Fi access point. \n\n"
|
||||||
<< "country_code is the 2-letter ISO-3166 country code for "
|
<< "country_code is the 2-letter ISO-3166 country code for "
|
||||||
<< "the country you are in. see below for further notes."
|
<< "the country you are in. see below for further notes."
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
<< "See below for an explanation of when you might want to use a legacy Wi-Fi access point instead of Wifi-Direct access."
|
<< "See below for an explanation of when you might want to use a legacy Wi-Fi access point instead of Wifi-Direct access."
|
||||||
<< "an explanation of when you might want to use a legacy Access Point instead of "
|
<< "an explanation of when you might want to use a legacy Access Point instead of "
|
||||||
<< "a P2P (Wi-Fi Direct) connection. Generally, you should prefer a P2p connection "
|
<< "a P2P (Wi-Fi Direct) connection. Generally, you should prefer a P2p connection "
|
||||||
<< "to an ordinary Hotspot connection."
|
<< "to an ordinary Hotspot connection."
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
|
|
||||||
<< 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:"
|
||||||
|
<< "\n\n"
|
||||||
|
<< Indent(4)
|
||||||
|
<< "Country codes are used to determine Wi-Fi-regulatory regime - the "
|
||||||
|
<< "channels you are legally allowed to use, and the features which must "
|
||||||
|
<< "be enabled or disabled on the channels you can use. "
|
||||||
|
<< "\n\n"
|
||||||
|
<< "Without a country code, Wi-Fi must be restricted to channels 1 through 11 "
|
||||||
|
<< "with reduced amplitude and feature sets."
|
||||||
|
<< "\n\n"
|
||||||
|
<< "For the most part, Wi-Fi country codes are taken from the list of ISO 3661 "
|
||||||
|
<< "2-letter country codes; although there are a handful of exceptions for small "
|
||||||
|
<< "countries and islands. See the Alpha-2 code column of "
|
||||||
|
<< "\n\n"
|
||||||
|
<< Indent(8) << "https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes."
|
||||||
|
<< "\n\n"
|
||||||
|
|
||||||
<< Indent(0) << "Country codes:"
|
<< Indent(0) << "Legacy Wi-Fi Access Points:"
|
||||||
<< "\n\n"
|
<< "\n\n"
|
||||||
<< Indent(4)
|
<< Indent(4)
|
||||||
<< "Country codes are used to determine Wi-Fi-regulatory regime - the "
|
<< "Some older devices may not be able to connect to PiPedal using Wi-Fi Direct connections. "
|
||||||
<< "channels you are legally allowed to use, and the features which must "
|
"Old Apple devices, for example, do not support Wi-Fi Direct. In theory, Wi-Fi Direct should "
|
||||||
<< "be enabled or disabled on the channels you can use. "
|
"allow legacy Wi-Fi devices to connect to a Wi-Fi Direct access points as if it were an "
|
||||||
<< "\n\n"
|
"ordinary Access Point. If this turns out "
|
||||||
<< "Without a country code, Wi-Fi must be restricted to channels 1 through 11 "
|
"not to be the case, you can configure PiPedal to provide a legacy Wi-Fi access point instead. "
|
||||||
<< "with reduced amplitude and feature sets."
|
"\n\n"
|
||||||
<< "\n\n"
|
"Unlike Wi-Fi Direct connections, legacy Access Points will prevent both the connecting device "
|
||||||
<< "For the most part, Wi-Fi country codes are taken from the list of ISO 3661 "
|
"and the PiPedal host machine from connecting to the Internet over a simultanous Wi-Fi connection Access "
|
||||||
<< "2-letter country codes; although there are a handful of exceptions for small "
|
"Point. On a connecting Android device, you won't be able to use the data connection either when a legacy "
|
||||||
<< "countries and islands. See the Alpha-2 code column of "
|
"Wi-Fi connection is active."
|
||||||
<< "\n\n"
|
"\n\n"
|
||||||
<< Indent(8) << "https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes."
|
"Wi-Fi Direct connections are "
|
||||||
<< "\n\n"
|
"therefore preferrable under almost all circumstances.\n\n";
|
||||||
|
|
||||||
<< Indent(0) << "Legacy Wi-Fi Access Points:"
|
|
||||||
<< "\n\n"
|
|
||||||
<< Indent(4)
|
|
||||||
<< "Some older devices may not be able to connect to PiPedal using Wi-Fi Direct connections. "
|
|
||||||
"Old Apple devices, for example, do not support Wi-Fi Direct. In theory, Wi-Fi Direct should "
|
|
||||||
"allow legacy Wi-Fi devices to connect to a Wi-Fi Direct access points as if it were an "
|
|
||||||
"ordinary Access Point. If this turns out "
|
|
||||||
"not to be the case, you can configure PiPedal to provide a legacy Wi-Fi access point instead. "
|
|
||||||
"\n\n"
|
|
||||||
"Unlike Wi-Fi Direct connections, legacy Access Points will prevent both the connecting device "
|
|
||||||
"and the PiPedal host machine from connecting to the Internet over a simultanous Wi-Fi connection Access "
|
|
||||||
"Point. On a connecting Android device, you won't be able to use the data connection either when a legacy "
|
|
||||||
"Wi-Fi connection is active."
|
|
||||||
"\n\n"
|
|
||||||
"Wi-Fi Direct connections are "
|
|
||||||
"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)
|
||||||
{
|
{
|
||||||
@@ -961,7 +1016,7 @@ int main(int argc, char **argv)
|
|||||||
settings.valid_ = true;
|
settings.valid_ = true;
|
||||||
settings.enable_ = false;
|
settings.enable_ = false;
|
||||||
SetWifiDirectConfig(settings);
|
SetWifiDirectConfig(settings);
|
||||||
RestartService(true);
|
RestartService(true);
|
||||||
}
|
}
|
||||||
else if (enable_ap)
|
else if (enable_ap)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user