summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
Diffstat (limited to 'hscript')
-rw-r--r--hscript/meta.cc34
-rw-r--r--hscript/meta.hh5
-rw-r--r--hscript/script.cc50
3 files changed, 89 insertions, 0 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 0248af9..b7da9d2 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -167,6 +167,40 @@ Key *PkgInstall::parseFromData(const std::string &data, int lineno, int *errors,
}
+Key *Firmware::parseFromData(const std::string &data, int lineno, int *errors,
+ int *warnings) {
+ bool value;
+ if(!BooleanKey::parse(data, "installfile:" + std::to_string(lineno),
+ "firmware", &value)) {
+ if(errors) *errors += 1;
+ return nullptr;
+ }
+
+ if(value) {
+#ifdef NON_LIBRE_FIRMWARE
+ output_warning("installfile:" + std::to_string(lineno),
+ "firmware: You have requested non-libre firmware. "
+ "This may cause security issues, system instability, "
+ "and many other issues. You should not enable this "
+ "option unless your system absolutely requires it.");
+#else
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "firmware: You have requested non-libre firmware, "
+ "but this version of Horizon does not support "
+ "non-libre firmware.", "Installation cannot proceed.");
+ return nullptr;
+#endif
+ }
+ return new Firmware(lineno, value);
+}
+
+bool Firmware::execute(ScriptOptions) const {
+ /* By itself, this does nothing. */
+ return true;
+}
+
+
/* LCOV_EXCL_START */
bool PkgInstall::validate(ScriptOptions) const {
/* Any validation errors would have occurred above. */
diff --git a/hscript/meta.hh b/hscript/meta.hh
index 035bb8a..8a50576 100644
--- a/hscript/meta.hh
+++ b/hscript/meta.hh
@@ -51,6 +51,11 @@ class Keymap : public StringKey {
};
class Firmware : public BooleanKey {
+private:
+ Firmware(int _line, bool _value) : BooleanKey(_line, _value) {}
+public:
+ static Key *parseFromData(const std::string &, int, int*, int*);
+ bool execute(ScriptOptions) const override;
};
class Timezone : public StringKey {
diff --git a/hscript/script.cc b/hscript/script.cc
index 0d1c10a..f9f16f5 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -11,6 +11,7 @@
*/
#include <algorithm>
+#include <assert.h>
#include <fstream>
#include <iostream>
#include <map>
@@ -103,6 +104,10 @@ struct Script::ScriptPrivate {
/*! Disk identification keys */
std::vector< std::unique_ptr<DiskId> > diskids;
+#ifdef NON_LIBRE_FIRMWARE
+ std::unique_ptr<Firmware> firmware;
+#endif
+
/*! Store +key_obj+ representing the key +key_name+.
* @param key_name The name of the key that is being stored.
* @param obj The Key object associated with the key.
@@ -120,6 +125,8 @@ struct Script::ScriptPrivate {
return store_pkginstall(obj, lineno, errors, warnings, opts);
} else if(key_name == "rootpw") {
return store_rootpw(obj, lineno, errors, warnings, opts);
+ } else if(key_name == "firmware") {
+ return store_firmware(obj, lineno, errors, warnings, opts);
} else if(key_name == "mount") {
std::unique_ptr<Mount> mount(dynamic_cast<Mount *>(obj));
this->mounts.push_back(std::move(mount));
@@ -217,6 +224,23 @@ struct Script::ScriptPrivate {
return true;
}
+ bool store_firmware(Keys::Key *obj, int lineno, int *errors, int *warnings,
+ ScriptOptions opts) {
+ std::unique_ptr<Firmware> f(dynamic_cast<Firmware *>(obj));
+#ifdef NON_LIBRE_FIRMWARE
+ if(this->firmware) {
+ DUPLICATE_ERROR(this->firmware, std::string("firmware"),
+ (this->firmware->test()) ? "true" : "false")
+ return false;
+ }
+ this->firmware = std::move(f);
+ return true;
+#else
+ assert(!f->test());
+ return true;
+#endif
+ }
+
bool store_username(Keys::Key *obj, int lineno, int *errors, int *warnings,
ScriptOptions opts) {
if(accounts.size() >= 255) {
@@ -532,6 +556,25 @@ bool Script::validate() const {
}
std::unique_ptr<Keys::Repository> user_repo(user_key);
this->internal->repos.push_back(std::move(user_repo));
+
+#ifdef NON_LIBRE_FIRMWARE
+ /* REQ: Runner.Execute.firmware.Repository */
+ if(this->internal->firmware && this->internal->firmware->test()) {
+ Keys::Repository *fw_key = dynamic_cast<Keys::Repository *>(
+ Horizon::Keys::Repository::parseFromData(
+ "https://distfiles.apkfission.net/adelie-stable/nonfree",
+ 0, nullptr, nullptr
+ )
+ );
+ if(!fw_key) {
+ output_error("internal",
+ "failed to create firmware repository");
+ return false;
+ }
+ std::unique_ptr<Keys::Repository> fw_repo(fw_key);
+ this->internal->repos.push_back(std::move(fw_repo));
+ }
+#endif
}
/* REQ: Runner.Validate.repository */
@@ -711,6 +754,13 @@ bool Script::execute() const {
return false;
}
}
+
+#ifdef NON_LIBRE_FIRMWARE
+ /* REQ: Runner.Execute.firmware */
+ if(this->internal->firmware && this->internal->firmware->test()) {
+ this->internal->packages.insert("linux-firmware");
+ }
+#endif
output_step_end("pre-metadata");
/**************** NETWORK ****************/