Skip to content

Commit

Permalink
Implement uninstall command
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Apr 27, 2023
1 parent 86db1d6 commit 17be1be
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 2 deletions.
6 changes: 6 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CODESIGN_ID> /Library/Audio/Plug-Ins/HAL/roc_vad.driver
```
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions common/build_info.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions common/build_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions tool/cmd_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "cmd_device.hpp"
#include "cmd_info.hpp"
#include "cmd_logcat.hpp"
#include "cmd_uninstall.hpp"

using namespace rocvad;

Expand All @@ -20,4 +21,5 @@ CmdRoot::CmdRoot(CLI::App& parent)
register_subcommand(std::make_shared<CmdInfo>(parent));
register_subcommand(std::make_shared<CmdLogcat>(parent));
register_subcommand(std::make_shared<CmdDevice>(parent));
register_subcommand(std::make_shared<CmdUninstall>(parent));
}
60 changes: 60 additions & 0 deletions tool/cmd_uninstall.cpp
Original file line number Diff line number Diff line change
@@ -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 <fmt/core.h>
#include <spdlog/spdlog.h>

#include <unistd.h>
#include <filesystem>

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);
}
23 changes: 23 additions & 0 deletions tool/cmd_uninstall.hpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 17be1be

Please sign in to comment.