summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-03-24 07:36:25 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-03-24 07:36:25 -0500
commit1f67d2793e2abb7c833172a0a1966d76b1b9a06a (patch)
tree2a61a6a2a8bb5d5370cae8e8192ab48a12a4d4a4 /image
parentedad6721912ddedea21150f74cbb52a98f3910ee (diff)
downloadhorizon-1f67d2793e2abb7c833172a0a1966d76b1b9a06a.tar.gz
horizon-1f67d2793e2abb7c833172a0a1966d76b1b9a06a.tar.bz2
horizon-1f67d2793e2abb7c833172a0a1966d76b1b9a06a.tar.xz
horizon-1f67d2793e2abb7c833172a0a1966d76b1b9a06a.zip
Add the beginnings of the Image Creation utility
Diffstat (limited to 'image')
-rw-r--r--image/CMakeLists.txt9
-rw-r--r--image/backends/README.rst89
-rw-r--r--image/creator.cc98
3 files changed, 196 insertions, 0 deletions
diff --git a/image/CMakeLists.txt b/image/CMakeLists.txt
new file mode 100644
index 0000000..c978ce6
--- /dev/null
+++ b/image/CMakeLists.txt
@@ -0,0 +1,9 @@
+find_package(Boost REQUIRED COMPONENTS program_options)
+include_directories(${Boost_INCLUDE_DIR})
+
+set(IMG_SRCS
+ creator.cc
+)
+add_executable(hscript-image ${IMG_SRCS})
+target_link_libraries(hscript-image hscript ${Boost_LIBRARIES})
+install(TARGETS hscript-image DESTINATION bin)
diff --git a/image/backends/README.rst b/image/backends/README.rst
new file mode 100644
index 0000000..ca510b9
--- /dev/null
+++ b/image/backends/README.rst
@@ -0,0 +1,89 @@
+======================================================
+ README for Project Horizon - Image Creation Backends
+======================================================
+:Authors:
+ * **A. Wilcox**, principal author, project manager
+:Status:
+ Development
+:Copyright:
+ © 2020 Adélie Linux.
+ Code: AGPL-3.0 license.
+ Documentation: CC BY-NC-SA open source license.
+
+
+Introduction
+============
+
+This directory contains the various backends for creating images using
+Project Horizon.
+
+
+License
+```````
+Development documentation for Project Horizon is licensed under the
+Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
+
+You should have received a copy of the license along with this
+work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
+
+Code is licensed under the Affero GPL (AGPL) 3 license.
+
+
+Changes
+```````
+Any changes to this repository must be reviewed before being pushed to the
+master branch.
+
+
+
+Design
+======
+
+Image creation backends shall derive from the Horizon::Image::BasicBackend
+class. Concrete backends can exist in any namespace. To be used with the
+Image Creation utility, the backend must be registered in the ``backends.hh``
+file along with a unique Type Code. This Type Code can then be passed to
+the Image Creation utility with the ``-t`` parameter for use.
+
+The Horizon::Image::BasicBackend is an abstract (pure virtual) class that
+has a single method that you must implement: ``create()``. This will be
+called on a constructed object of your concrete backend class, with two
+parameters: ``std::string ir_dir``, which is the base directory for the
+installed system (like ``/target`` during a normal installation), and
+``std::string out_path``, which is the user's desired output path and file
+name.
+
+
+
+Repository Layout
+=================
+
+Each backend has its own .cc/.hh file. The special ``backends.hh`` file
+contains the table used by the Image Creation utility for determining
+supported types and backends.
+
+
+
+Contributing
+============
+
+See the CONTIRIBUTING.rst_ file in the roort directory of the Project Horizon
+repository more details on how to contribute your own backend.
+
+.. _CONTRIBUTING.rst: https://code.foxkit.us/adelie/horizon/blob/master/CONTRIBUTING.rst
+
+
+
+Reporting Issues
+================
+
+If you have an issue using Project Horizon, you may view our BTS_. You may
+also `submit an issue`_ directly.
+
+For general discussion, questions, or to submit a patch, please use the
+`Horizon mailing list`_.
+
+.. _BTS: https://bts.adelielinux.org/buglist.cgi?product=Horizon&resolution=---
+.. _`submit an issue`: https://bts.adelielinux.org/enter_bug.cgi?product=Horizon
+.. _`Horizon mailing list`: https://lists.adelielinux.org/postorius/lists/horizon.lists.adelielinux.org/
+
diff --git a/image/creator.cc b/image/creator.cc
new file mode 100644
index 0000000..3b145de
--- /dev/null
+++ b/image/creator.cc
@@ -0,0 +1,98 @@
+/*
+ * creator.cc - Implementation of the HorizonScript image creator
+ * image, the image processing utilities for
+ * Project Horizon
+ *
+ * Copyright (c) 2020 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 <boost/program_options.hpp>
+#include <cstdlib> /* EXIT_* */
+#include <string>
+#include "hscript/script.hh"
+#include "util/output.hh"
+
+bool pretty = true;
+
+#define DESCR_TEXT "Usage: hscript-image [OPTION]... [INSTALLFILE]\n"\
+ "Write an operating system image configured per INSTALLFILE"
+
+int main(int argc, char *argv[]) {
+ using namespace boost::program_options;
+ bool needs_help{}, disable_pretty{};
+ int exit_code = EXIT_SUCCESS;
+ std::string if_path{"/etc/horizon/installfile"}, ir_dir{"/target"};
+
+ options_description ui{DESCR_TEXT};
+ options_description general{"General options"};
+ general.add_options()
+ ("help,h", bool_switch(&needs_help), "Display this message.")
+ ("no-colour,n", bool_switch(&disable_pretty), "Do not 'prettify' output")
+ ;
+ options_description target{"Target control options"};
+ target.add_options()
+ ("output,o", value<std::string>()->default_value("image.tar"), "Desired filename for the output file.")
+ ("type,t", value<std::string>()->default_value("tar"), "Type of output file to generate. Use 'list' for a list of supported types.")
+ ("ir-dir,i", value<std::string>()->default_value("/target"), "Where to store intermediate files.")
+ ;
+ ui.add(general).add(target);
+
+ options_description all;
+ all.add(ui).add_options()("installfile", value<std::string>()->default_value(if_path), "The HorizonScript to use for configuring the image.");
+
+ positional_options_description positional;
+ positional.add("installfile", 1);
+
+ command_line_parser parser{argc, argv};
+ parser.options(all);
+ parser.positional(positional);
+
+ variables_map vm;
+ try {
+ auto result = parser.run();
+ store(result, vm);
+ notify(vm);
+ } catch(const std::exception &ex) {
+ std::cerr << ex.what() << std::endl;
+ exit_code = EXIT_FAILURE;
+ needs_help = true;
+ }
+
+ /* --help, or usage failure */
+ if(needs_help) {
+ std::cout << ui << std::endl;
+ return exit_code;
+ }
+
+ /* -n/--no-colour, or logging to file */
+ if(disable_pretty || !isatty(1)) {
+ pretty = false;
+ }
+
+ if(!vm["installfile"].empty()) {
+ if_path = vm["installfile"].as<std::string>();
+ }
+
+ Horizon::Script *my_script;
+ if(if_path == "-") {
+ my_script = Horizon::Script::load(std::cin);
+ } else {
+ my_script = Horizon::Script::load(if_path);
+ }
+
+ /* if an error occurred during parsing, bail out now */
+ if(!my_script) {
+ return EXIT_FAILURE;
+ }
+
+ if(!vm["ir-dir"].empty()) {
+ my_script->setTargetDirectory(vm["ir-dir"].as<std::string>());
+ }
+
+ delete my_script;
+ return exit_code;
+}