diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/Makefile b/Makefile index 18dade2..4f332e1 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,8 @@ -CXX := g++ -CXX_FLAGS := -Wall -Wextra -std=c++17 +CXX := g++ +CXX_FLAGS := -Wall -Wextra -std=c++17 -BIN := bin -SRC := src -INCLUDE := include +SRC := src +INCLUDE := include EXECUTABLE := passthrough diff --git a/README.md b/README.md index ac077ad..420369d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ## Automated Setup ###### Not well-tested. Only supports systemd init system. Installs packages, enables iommu and creates libvirt hooks for now. +###### Halted till December. +###### TODO: upstart, openrc, sysv support. Automatic VM creation and passthrough support. Libvirt script for window managers. ```sh make sudo ./passthrough diff --git a/include/shell.h b/include/shell.h index 11de708..f20cbeb 100644 --- a/include/shell.h +++ b/include/shell.h @@ -1,4 +1,8 @@ #include #include +#include std::string shell_cmd(char const *cmd); +void trim(std::string &s); +void rtrim(std::string &s); +void ltrim(std::string &s); \ No newline at end of file diff --git a/include/vm.h b/include/vm.h new file mode 100644 index 0000000..77bb53c --- /dev/null +++ b/include/vm.h @@ -0,0 +1,5 @@ +#include +#include + +void create_vm(); +void create_vm_with_libvirt(); \ No newline at end of file diff --git a/passthrough b/passthrough deleted file mode 100755 index ebdb0e2..0000000 Binary files a/passthrough and /dev/null differ diff --git a/src/main.cpp b/src/main.cpp index 3329714..09e09c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,10 @@ int main() { try { + std::string user = shell_cmd("echo $(whoami)"); + if (user != "root") + throw std::runtime_error("\033[1;31mYou need to run the tool as root.\033[0m"); + char cnf; configure_iommu(); diff --git a/src/shell.cpp b/src/shell.cpp index 64e67ef..32121fd 100644 --- a/src/shell.cpp +++ b/src/shell.cpp @@ -12,5 +12,27 @@ std::string shell_cmd(char const *cmd) { resp += buffer.data(); } + trim(resp); return resp; +} + +void ltrim(std::string &s) +{ + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); +} + +void rtrim(std::string &s) +{ + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(), + s.end()); +} + +void trim(std::string &s) +{ + ltrim(s); + rtrim(s); } \ No newline at end of file diff --git a/src/vm.cpp b/src/vm.cpp new file mode 100644 index 0000000..1c3bd1d --- /dev/null +++ b/src/vm.cpp @@ -0,0 +1,11 @@ +#include + +void create_vm() +{ + // TODO +} + +void create_vm_with_libvirt() +{ + // TODO +} \ No newline at end of file