diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-02 15:36:25 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-02 15:36:25 -0500 |
commit | 43623d6ac1cf83e9a9e6a1848fd8825863afbdb3 (patch) | |
tree | ca1652aa618dda80b699ec99f26aa24cc33ca88f | |
parent | e94500bc8b7d7e33670774dff76ba4e9b1108659 (diff) | |
download | horizon-43623d6ac1cf83e9a9e6a1848fd8825863afbdb3.tar.gz horizon-43623d6ac1cf83e9a9e6a1848fd8825863afbdb3.tar.bz2 horizon-43623d6ac1cf83e9a9e6a1848fd8825863afbdb3.tar.xz horizon-43623d6ac1cf83e9a9e6a1848fd8825863afbdb3.zip |
Add Executor utility
-rw-r--r-- | CMakeLists.txt | 18 | ||||
-rw-r--r-- | executor/CMakeLists.txt | 6 | ||||
-rw-r--r-- | executor/executor.cc | 60 |
3 files changed, 77 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c423185..0345603 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,15 @@ IF(NOT HAVE_LINUX_WIRELESS_H) SET(INSTALL OFF) ENDIF(NOT HAVE_LINUX_WIRELESS_H) + +include_directories(.) + + +## Test stuff ## +find_program(RSPEC_EXECUTABLE NAMES rspec) +enable_testing() + + IF(INSTALL) add_definitions(-DHAS_INSTALL_ENV) pkg_check_modules(BLKID REQUIRED blkid) @@ -60,18 +69,13 @@ IF(INSTALL) pkg_check_modules(PARTED REQUIRED libparted) find_library(BCNM_LIBRARY REQUIRED wpactrl PATH_SUFFIXES bcnm) set(BUILD_SHARED_LIBS ON) + + add_subdirectory(executor) ELSE(INSTALL) set(BUILD_SHARED_LIBS OFF) ENDIF(INSTALL) -include_directories(.) - - -## Test stuff ## -find_program(RSPEC_EXECUTABLE NAMES rspec) -enable_testing() - add_subdirectory(hscript) IF(BUILD_TOOLS) add_subdirectory(tools) diff --git a/executor/CMakeLists.txt b/executor/CMakeLists.txt new file mode 100644 index 0000000..dbdcd3b --- /dev/null +++ b/executor/CMakeLists.txt @@ -0,0 +1,6 @@ +set(EXEC_SRCS + executor.cc +) +add_executable(hscript-executor ${EXEC_SRCS}) +target_link_libraries(hscript-executor hscript) +install(TARGETS hscript-executor DESTINATION bin) diff --git a/executor/executor.cc b/executor/executor.cc new file mode 100644 index 0000000..7d9c3bf --- /dev/null +++ b/executor/executor.cc @@ -0,0 +1,60 @@ +/* + * executor.cc - Implementation of the HorizonScript executor + * Project Horizon + * + * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#include <unistd.h> +#include "hscript/script.hh" +#include "util/output.hh" + +bool pretty = false; + +int main(void) { + const Horizon::Script *my_script; + Horizon::ScriptOptions opts; + int result_code = EXIT_SUCCESS; + using Horizon::ScriptOptionFlags; + + /* Default to pretty if we are using a TTY, unless -n specified. */ + if(isatty(1) && isatty(2)) { + pretty = true; /* LCOV_EXCL_LINE */ + } + + opts.set(ScriptOptionFlags::InstallEnvironment); + opts.set(ScriptOptionFlags::UseNetwork); + opts.set(ScriptOptionFlags::StrictMode); + + std::cout << "HorizonScript Executor version " << VERSTR; +#ifdef NON_LIBRE_FIRMWARE + colour_if_pretty(std::cout, "31"); + std::cout << " (supports non-free firmware)"; +#endif + reset_if_pretty(std::cout); + std::cout << std::endl; + std::cout << "Copyright (c) 2019 Adélie Linux and contributors. " + "AGPL-3.0 license." << std::endl; + std::cout << std::endl; + + my_script = Horizon::Script::load("/etc/horizon/installfile", opts); + if(my_script == nullptr) { + std::cout << "Could not load the specified script." << std::endl; + return EXIT_FAILURE; + } + + if(!my_script->execute()) { + output_error("installfile", "Script failed. Stop.", ""); + result_code = EXIT_FAILURE; + } else { + output_info("installfile", + "Adélie Linux has been successfully installed.", ""); + } + + delete my_script; + return result_code; +} |