From 17be1be81cb449073628848545f9b795ee6fda98 Mon Sep 17 00:00:00 2001 From: Victor Gaydov Date: Thu, 27 Apr 2023 10:39:45 +0400 Subject: [PATCH] Implement uninstall command --- HACKING.md | 6 ++++ README.md | 22 +++++++++++++-- common/build_info.cpp.in | 3 ++ common/build_info.hpp | 3 ++ tool/CMakeLists.txt | 1 + tool/cmd_root.cpp | 2 ++ tool/cmd_uninstall.cpp | 60 ++++++++++++++++++++++++++++++++++++++++ tool/cmd_uninstall.hpp | 23 +++++++++++++++ 8 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 tool/cmd_uninstall.cpp create mode 100644 tool/cmd_uninstall.hpp diff --git a/HACKING.md b/HACKING.md index 8f63247..dd1c8cd 100644 --- a/HACKING.md +++ b/HACKING.md @@ -87,3 +87,9 @@ There are two important reasons for this: By default, driver starts RPC server at `127.0.0.1:9712`. If you want to change this address, you can edit `DriverSocket` key in `/Library/Audio/Plug-Ins/HAL/roc_vad.driver/Contents/Info.plist` plist file. Both driver and command-line tool read socket address from that file. + +You may need to regenerate driver signature after changing that file: + +``` +$ sudo codesign --force -s /Library/Audio/Plug-Ins/HAL/roc_vad.driver +``` diff --git a/README.md b/README.md index 79df241..c567c83 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,25 @@ Compatible Roc Toolkit senders and receivers include: * [C library](https://roc-streaming.org/toolkit/docs/api.html) and [bindings for other languages](https://roc-streaming.org/toolkit/docs/api/bindings.html) (Go, Java) * [Android app](https://github.com/roc-streaming/roc-droid) -## Installation +## Install from binaries + +Install driver and command-line tool: + +``` +$ TODO +``` + +Then reboot your Mac. + +To **uninstall** everything, run: + +``` +$ sudo roc-vad uninstall +``` + +Then reboot your Mac. + +## Install from sources Prerequisites: @@ -129,7 +147,7 @@ $ roc-vad logcat ... ``` -Alternatively, use `syslog` makefile target. It streams logs that driver sends to system log. Basically they are the same logs as produced by `logcat` command, but in other format: +Alternatively, you can use `syslog` makefile target. It streams logs that driver sends to system log. Basically they are the same logs as produced by `logcat` command, but in slightly different format, and possibly truncated and deduplicated: ``` $ make syslog diff --git a/common/build_info.cpp.in b/common/build_info.cpp.in index 192249b..545b3f0 100644 --- a/common/build_info.cpp.in +++ b/common/build_info.cpp.in @@ -21,4 +21,7 @@ const char* BuildInfo::driver_bundle_path = const char* BuildInfo::driver_uuid = "${DRIVER_UUID}"; const char* BuildInfo::driver_socket = "${DRIVER_SOCKET}"; +const char* BuildInfo::tool_name = "${TOOL_NAME}"; +const char* BuildInfo::tool_path = "/usr/local/bin/${TOOL_NAME}"; + } // namespace rocvad diff --git a/common/build_info.hpp b/common/build_info.hpp index 567a264..31d8604 100644 --- a/common/build_info.hpp +++ b/common/build_info.hpp @@ -21,6 +21,9 @@ struct BuildInfo static const char* driver_bundle_path; static const char* driver_uuid; static const char* driver_socket; + + static const char* tool_name; + static const char* tool_path; }; } // namespace rocvad diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt index d511cb9..b7f41b9 100644 --- a/tool/CMakeLists.txt +++ b/tool/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable(${TOOL_NAME} "cmd_info.cpp" "cmd_logcat.cpp" "cmd_root.cpp" + "cmd_uninstall.cpp" "connector.cpp" "main.cpp" "parse.cpp" diff --git a/tool/cmd_root.cpp b/tool/cmd_root.cpp index 2b48200..929e6d6 100644 --- a/tool/cmd_root.cpp +++ b/tool/cmd_root.cpp @@ -10,6 +10,7 @@ #include "cmd_device.hpp" #include "cmd_info.hpp" #include "cmd_logcat.hpp" +#include "cmd_uninstall.hpp" using namespace rocvad; @@ -20,4 +21,5 @@ CmdRoot::CmdRoot(CLI::App& parent) register_subcommand(std::make_shared(parent)); register_subcommand(std::make_shared(parent)); register_subcommand(std::make_shared(parent)); + register_subcommand(std::make_shared(parent)); } diff --git a/tool/cmd_uninstall.cpp b/tool/cmd_uninstall.cpp new file mode 100644 index 0000000..9a412ac --- /dev/null +++ b/tool/cmd_uninstall.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) Roc Streaming authors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "cmd_uninstall.hpp" +#include "build_info.hpp" + +#include +#include + +#include +#include + +using namespace rocvad; + +CmdUninstall::CmdUninstall(CLI::App& parent) +{ + register_command(parent.add_subcommand("uninstall", "uninstall driver and tool")); +} + +bool CmdUninstall::execute(const Environment& env) +{ + if (geteuid() != 0) { + spdlog::error("should be run with root privileges\ntry \"sudo {} uninstall\"", + BuildInfo::tool_name); + return false; + } + + int n_ok = 0, n_warn = 0, n_err = 0; + + for (auto path : {BuildInfo::driver_bundle_path, BuildInfo::tool_path}) { + std::error_code err; + const auto n_removed = std::filesystem::remove_all(path, err); + + if (n_removed != 0 && !err) { + fmt::println("removed {}", path); + n_ok++; + } else if (n_removed == 0 && !err) { + spdlog::warn("can't remove \"{}\": Not found", path); + n_warn++; + } else if (err) { + spdlog::error("can't remove \"{}\": {}", path, err.message()); + n_err++; + } + } + + if (n_ok == 0) { + fmt::println("nothing removed"); + } else if (n_err == 0) { + fmt::println("everything removed"); + } else { + fmt::println("completed with errors"); + } + + return (n_err == 0); +} diff --git a/tool/cmd_uninstall.hpp b/tool/cmd_uninstall.hpp new file mode 100644 index 0000000..f0535b5 --- /dev/null +++ b/tool/cmd_uninstall.hpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) Roc Streaming authors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "cmd_base.hpp" + +namespace rocvad { + +class CmdUninstall : public CmdBase +{ +public: + CmdUninstall(CLI::App& parent); + + bool execute(const Environment& env) override; +}; + +} // namespace rocvad