summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-05-24 20:35:14 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-05-24 20:35:14 -0500
commit9c9e400b68f9cfb2270434fb8a16cc0df906ab8b (patch)
tree051470d7c3d29401462e3563bca34b11e58af5c5 /hscript/meta.cc
parentb9980223dd469f24359d969ab24c3694507897e5 (diff)
downloadhorizon-9c9e400b68f9cfb2270434fb8a16cc0df906ab8b.tar.gz
horizon-9c9e400b68f9cfb2270434fb8a16cc0df906ab8b.tar.bz2
horizon-9c9e400b68f9cfb2270434fb8a16cc0df906ab8b.tar.xz
horizon-9c9e400b68f9cfb2270434fb8a16cc0df906ab8b.zip
hscript: Implement 'svcenable' key and tests
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 9b0eb83..d43e58e 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -656,3 +656,47 @@ bool SigningKey::execute() const {
#endif /* HAS_INSTALL_ENV */
return true; /* LCOV_EXCL_LINE */
}
+
+Key *SvcEnable::parseFromData(const std::string &data, int lineno, int *errors,
+ int *, const Script *script) {
+ const static std::string valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.-_";
+
+ if(data.find_first_not_of(valid_chars) != std::string::npos) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "svcenable: invalid service name", data);
+ return nullptr;
+ }
+
+ return new SvcEnable(script, lineno, data);
+}
+
+bool SvcEnable::execute() const {
+ const std::string target = script->targetDirectory() +
+ "/etc/runlevels/default/" + _value;
+ const std::string initd = "/etc/init.d/" + _value;
+ output_info("installfile:" + std::to_string(line),
+ "svcenable: enabling service " + _value);
+
+ if(script->options().test(Simulate)) {
+ std::cout << "ln -s " << initd << " " << target << std::endl;
+ return true;
+ }
+
+#ifdef HAS_INSTALL_ENV
+ error_code ec;
+ if(!fs::exists(script->targetDirectory() + initd, ec)) {
+ output_warning("installfile:" + std::to_string(line),
+ "svcenable: service '" + _value + "' may be missing");
+ }
+
+ fs::create_symlink(initd, target, ec);
+ if(ec) {
+ output_error("installfile:" + std::to_string(line),
+ "svcenable: could not enable service " + _value,
+ ec.message());
+ return false;
+ }
+#endif /* HAS_INSTALL_ENV */
+ return true; /* LCOV_EXCL_LINE */
+}